1094332d3Sopenharmony_ci
2094332d3Sopenharmony_ci/*
3094332d3Sopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
4094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
5094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
6094332d3Sopenharmony_ci * You may obtain a copy of the License at
7094332d3Sopenharmony_ci *
8094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
9094332d3Sopenharmony_ci *
10094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
11094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
12094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
14094332d3Sopenharmony_ci * limitations under the License.
15094332d3Sopenharmony_ci */
16094332d3Sopenharmony_ci#include "offline_stream_test.h"
17094332d3Sopenharmony_ci
18094332d3Sopenharmony_ciusing namespace OHOS;
19094332d3Sopenharmony_ciusing namespace std;
20094332d3Sopenharmony_ciusing namespace testing::ext;
21094332d3Sopenharmony_ciusing namespace OHOS::Camera;
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_civoid OfflineStreamTest::SetUpTestCase(void) {}
24094332d3Sopenharmony_civoid OfflineStreamTest::TearDownTestCase(void) {}
25094332d3Sopenharmony_civoid OfflineStreamTest::SetUp(void)
26094332d3Sopenharmony_ci{
27094332d3Sopenharmony_ci    Test_ = std::make_shared<OHOS::Camera::Test>();
28094332d3Sopenharmony_ci    Test_->Init();
29094332d3Sopenharmony_ci    Test_->Open();
30094332d3Sopenharmony_ci}
31094332d3Sopenharmony_civoid OfflineStreamTest::TearDown(void)
32094332d3Sopenharmony_ci{
33094332d3Sopenharmony_ci    Test_->Close();
34094332d3Sopenharmony_ci}
35094332d3Sopenharmony_ci
36094332d3Sopenharmony_ci/**
37094332d3Sopenharmony_ci  * @tc.name: OfflineStream
38094332d3Sopenharmony_ci  * @tc.desc: Preview and still_capture streams, Change still_capture To OfflineStream, excepted success.
39094332d3Sopenharmony_ci  * @tc.size: MediumTest
40094332d3Sopenharmony_ci  * @tc.type: Function
41094332d3Sopenharmony_ci  */
42094332d3Sopenharmony_ciHWTEST_F(OfflineStreamTest, Camera_Offline_0001, TestSize.Level0)
43094332d3Sopenharmony_ci{
44094332d3Sopenharmony_ci    std::cout << "==========[test log]Preview and still_capture streams, ";
45094332d3Sopenharmony_ci    std::cout << " Change still_capture To OfflineStream, excepted success." << std::endl;
46094332d3Sopenharmony_ci    // Configure two streams of information
47094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
48094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
49094332d3Sopenharmony_ci    // Capture preview stream
50094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
51094332d3Sopenharmony_ci    // Capture the photo stream, continuous capture
52094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
53094332d3Sopenharmony_ci    sleep(3); // sleep for 3 seconds
54094332d3Sopenharmony_ci    // Convert to offline stream
55094332d3Sopenharmony_ci    Test_->CreateOfflineStreamOperatorCallback();
56094332d3Sopenharmony_ci    std::vector<int> offlineIds;
57094332d3Sopenharmony_ci    offlineIds.push_back(Test_->streamId_capture);
58094332d3Sopenharmony_ci    Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
59094332d3Sopenharmony_ci        offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
60094332d3Sopenharmony_ci    ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
61094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline: ChangeToOfflineStream rc = " << Test_->rc << std::endl;
62094332d3Sopenharmony_ci    EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
63094332d3Sopenharmony_ci    if (Test_->rc == Camera::NO_ERROR) {
64094332d3Sopenharmony_ci        std::cout << "==========[test log]Check offline stream: offline StreamOperator != nullptr" << std::endl;
65094332d3Sopenharmony_ci    } else {
66094332d3Sopenharmony_ci        std::cout << "==========[test log]Check offline stream: offline StreamOperator == nullptr" << std::endl;
67094332d3Sopenharmony_ci    }
68094332d3Sopenharmony_ci    // Post-processing of the original stream
69094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
70094332d3Sopenharmony_ci    Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
71094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
72094332d3Sopenharmony_ci    // Post-processing of offline streams
73094332d3Sopenharmony_ci    Test_->cameraDevice->Close();
74094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline stream: Pretend to wait 5s for callback..." << std::endl;
75094332d3Sopenharmony_ci    sleep(2);
76094332d3Sopenharmony_ci    Test_->StopOfflineStream(Test_->captureId_capture);
77094332d3Sopenharmony_ci}
78094332d3Sopenharmony_ci
79094332d3Sopenharmony_ci/**
80094332d3Sopenharmony_ci  * @tc.name: OfflineStream
81094332d3Sopenharmony_ci  * @tc.desc: Preview and still_capture streams, Change Preview To OfflineStream, excepted fail.
82094332d3Sopenharmony_ci  * @tc.size: MediumTest
83094332d3Sopenharmony_ci  * @tc.type: Function
84094332d3Sopenharmony_ci  */
85094332d3Sopenharmony_ciHWTEST_F(OfflineStreamTest, Camera_Offline_0002, TestSize.Level2)
86094332d3Sopenharmony_ci{
87094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline stream: Preview and still_capture streams, ";
88094332d3Sopenharmony_ci    std::cout << " Change Preview To OfflineStream, excepted fail." << std::endl;
89094332d3Sopenharmony_ci    // Configure two streams of information
90094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
91094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
92094332d3Sopenharmony_ci    // Capture preview stream
93094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
94094332d3Sopenharmony_ci    // Capture the photo stream, continuous capture
95094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
96094332d3Sopenharmony_ci    sleep(2);
97094332d3Sopenharmony_ci    // Convert to offline stream
98094332d3Sopenharmony_ci    Test_->CreateOfflineStreamOperatorCallback();
99094332d3Sopenharmony_ci    std::vector<int> offlineIds;
100094332d3Sopenharmony_ci    offlineIds.push_back(Test_->streamId_preview);
101094332d3Sopenharmony_ci    Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
102094332d3Sopenharmony_ci        offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
103094332d3Sopenharmony_ci    ASSERT_EQ(Test_->rc, Camera::METHOD_NOT_SUPPORTED);
104094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline: ChangeToOfflineStream rc = " << Test_->rc << std::endl;
105094332d3Sopenharmony_ci    ASSERT_EQ(true, Test_->offlineStreamOperator == nullptr);
106094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline stream: offline StreamOperator == nullptr." << std::endl;
107094332d3Sopenharmony_ci    // Post-processing of the original stream
108094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
109094332d3Sopenharmony_ci    Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
110094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
111094332d3Sopenharmony_ci}
112094332d3Sopenharmony_ci
113094332d3Sopenharmony_ci/**
114094332d3Sopenharmony_ci  * @tc.name: OfflineStream
115094332d3Sopenharmony_ci  * @tc.desc: Preview and video streams, Change video To OfflineStream, excepted fail.
116094332d3Sopenharmony_ci  * @tc.size: MediumTest
117094332d3Sopenharmony_ci  * @tc.type: Function
118094332d3Sopenharmony_ci  */
119094332d3Sopenharmony_ciHWTEST_F(OfflineStreamTest, Camera_Offline_0003, TestSize.Level2)
120094332d3Sopenharmony_ci{
121094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline stream: Preview and video streams, ";
122094332d3Sopenharmony_ci    std::cout << "Change video To OfflineStream, excepted fail." << std::endl;
123094332d3Sopenharmony_ci    // Configure two streams of information
124094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
125094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
126094332d3Sopenharmony_ci    // Capture preview stream
127094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
128094332d3Sopenharmony_ci    // Capture the photo stream, continuous capture
129094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
130094332d3Sopenharmony_ci    sleep(2);
131094332d3Sopenharmony_ci    // Convert to offline stream
132094332d3Sopenharmony_ci    Test_->CreateOfflineStreamOperatorCallback();
133094332d3Sopenharmony_ci    std::vector<int> offlineIds;
134094332d3Sopenharmony_ci    offlineIds.push_back(Test_->streamId_video);
135094332d3Sopenharmony_ci    Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
136094332d3Sopenharmony_ci        offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
137094332d3Sopenharmony_ci    ASSERT_EQ(Test_->rc, Camera::METHOD_NOT_SUPPORTED);
138094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline: ChangeToOfflineStream rc = " << Test_->rc << std::endl;
139094332d3Sopenharmony_ci    ASSERT_EQ(Test_->offlineStreamOperator, nullptr);
140094332d3Sopenharmony_ci    std::cout << "==========[test log]Check offline stream: offline StreamOperator == nullptr." << std::endl;
141094332d3Sopenharmony_ci    // Post-processing of the original stream
142094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
143094332d3Sopenharmony_ci    Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
144094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
145094332d3Sopenharmony_ci}