1
2/*
3 * Copyright (c) 2020 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "offline_stream_test.h"
17
18using namespace OHOS;
19using namespace std;
20using namespace testing::ext;
21using namespace OHOS::Camera;
22
23void OfflineStreamTest::SetUpTestCase(void) {}
24void OfflineStreamTest::TearDownTestCase(void) {}
25void OfflineStreamTest::SetUp(void)
26{
27    Test_ = std::make_shared<OHOS::Camera::Test>();
28    Test_->Init();
29    Test_->Open();
30}
31void OfflineStreamTest::TearDown(void)
32{
33    Test_->Close();
34}
35
36/**
37  * @tc.name: OfflineStream
38  * @tc.desc: Preview and still_capture streams, Change still_capture To OfflineStream, excepted success.
39  * @tc.size: MediumTest
40  * @tc.type: Function
41  */
42HWTEST_F(OfflineStreamTest, Camera_Offline_0001, TestSize.Level0)
43{
44    std::cout << "==========[test log]Preview and still_capture streams, ";
45    std::cout << " Change still_capture To OfflineStream, excepted success." << std::endl;
46    // Configure two streams of information
47    Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
48    Test_->StartStream(Test_->intents);
49    // Capture preview stream
50    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
51    // Capture the photo stream, continuous capture
52    Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
53    sleep(3); // sleep for 3 seconds
54    // Convert to offline stream
55    Test_->CreateOfflineStreamOperatorCallback();
56    std::vector<int> offlineIds;
57    offlineIds.push_back(Test_->streamId_capture);
58    Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
59        offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
60    ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
61    std::cout << "==========[test log]Check offline: ChangeToOfflineStream rc = " << Test_->rc << std::endl;
62    EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
63    if (Test_->rc == Camera::NO_ERROR) {
64        std::cout << "==========[test log]Check offline stream: offline StreamOperator != nullptr" << std::endl;
65    } else {
66        std::cout << "==========[test log]Check offline stream: offline StreamOperator == nullptr" << std::endl;
67    }
68    // Post-processing of the original stream
69    Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
70    Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
71    Test_->StopStream(Test_->captureIds, Test_->streamIds);
72    // Post-processing of offline streams
73    Test_->cameraDevice->Close();
74    std::cout << "==========[test log]Check offline stream: Pretend to wait 5s for callback..." << std::endl;
75    sleep(2);
76    Test_->StopOfflineStream(Test_->captureId_capture);
77}
78
79/**
80  * @tc.name: OfflineStream
81  * @tc.desc: Preview and still_capture streams, Change Preview To OfflineStream, excepted fail.
82  * @tc.size: MediumTest
83  * @tc.type: Function
84  */
85HWTEST_F(OfflineStreamTest, Camera_Offline_0002, TestSize.Level2)
86{
87    std::cout << "==========[test log]Check offline stream: Preview and still_capture streams, ";
88    std::cout << " Change Preview To OfflineStream, excepted fail." << std::endl;
89    // Configure two streams of information
90    Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
91    Test_->StartStream(Test_->intents);
92    // Capture preview stream
93    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
94    // Capture the photo stream, continuous capture
95    Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
96    sleep(2);
97    // Convert to offline stream
98    Test_->CreateOfflineStreamOperatorCallback();
99    std::vector<int> offlineIds;
100    offlineIds.push_back(Test_->streamId_preview);
101    Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
102        offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
103    ASSERT_EQ(Test_->rc, Camera::METHOD_NOT_SUPPORTED);
104    std::cout << "==========[test log]Check offline: ChangeToOfflineStream rc = " << Test_->rc << std::endl;
105    ASSERT_EQ(true, Test_->offlineStreamOperator == nullptr);
106    std::cout << "==========[test log]Check offline stream: offline StreamOperator == nullptr." << std::endl;
107    // Post-processing of the original stream
108    Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
109    Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
110    Test_->StopStream(Test_->captureIds, Test_->streamIds);
111}
112
113/**
114  * @tc.name: OfflineStream
115  * @tc.desc: Preview and video streams, Change video To OfflineStream, excepted fail.
116  * @tc.size: MediumTest
117  * @tc.type: Function
118  */
119HWTEST_F(OfflineStreamTest, Camera_Offline_0003, TestSize.Level2)
120{
121    std::cout << "==========[test log]Check offline stream: Preview and video streams, ";
122    std::cout << "Change video To OfflineStream, excepted fail." << std::endl;
123    // Configure two streams of information
124    Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
125    Test_->StartStream(Test_->intents);
126    // Capture preview stream
127    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
128    // Capture the photo stream, continuous capture
129    Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
130    sleep(2);
131    // Convert to offline stream
132    Test_->CreateOfflineStreamOperatorCallback();
133    std::vector<int> offlineIds;
134    offlineIds.push_back(Test_->streamId_video);
135    Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
136        offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
137    ASSERT_EQ(Test_->rc, Camera::METHOD_NOT_SUPPORTED);
138    std::cout << "==========[test log]Check offline: ChangeToOfflineStream rc = " << Test_->rc << std::endl;
139    ASSERT_EQ(Test_->offlineStreamOperator, nullptr);
140    std::cout << "==========[test log]Check offline stream: offline StreamOperator == nullptr." << std::endl;
141    // Post-processing of the original stream
142    Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
143    Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
144    Test_->StopStream(Test_->captureIds, Test_->streamIds);
145}