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