• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include <gtest/gtest.h>
17 #include <memory>
18 
19 #include "anonymous_string.h"
20 #include "distributed_hardware_log.h"
21 
22 #define private public
23 #include "dcamera_sink_access_control.h"
24 #include "dcamera_sink_controller.h"
25 #include "dcamera_sink_dev.h"
26 #undef private
27 
28 #include "dcamera_sink_callback.h"
29 #include "dcamera_handler.h"
30 #include "dcamera_utils_tools.h"
31 #include "distributed_camera_errno.h"
32 #include "mock_dcamera_sink_controller.h"
33 
34 
35 using namespace testing::ext;
36 
37 namespace OHOS {
38 namespace DistributedHardware {
39 class DCameraSinkDevTest : public testing::Test {
40 public:
41     static void SetUpTestCase(void);
42     static void TearDownTestCase(void);
43     void SetUp();
44     void TearDown();
45 
46     std::shared_ptr<DCameraSinkDev> dev_;
47 };
48 
49 const int32_t TEST_TWENTY_MS = 20000;
50 const std::string TEST_PARAMETER = "";
51 std::string g_testCameraInfo = "";
52 
53 std::string g_testChannelInfoDevContinue = R"({
54     "Type": "OPERATION",
55     "dhId": "camrea_0",
56     "Command": "CHANNEL_NEG",
57     "Value": {"SourceDevId": "TestDevId",
58     "Detail": [{"DataSessionFlag": "dataContinue", "StreamType": 0}]}
59 })";
60 
61 std::string g_testOpenInfoDev = R"({
62     "Type": "OPERATION",
63     "dhId": "camrea_0",
64     "Command": "OPEN_CHANNEL",
65     "Value": {"SourceDevId": "TestDevId"}
66 })";
67 
68 std::string g_testChannelInfoDevEmpty = "";
69 std::string g_testOpenInfoDevEmpty = "";
70 
SetUpTestCase(void)71 void DCameraSinkDevTest::SetUpTestCase(void)
72 {
73 }
74 
TearDownTestCase(void)75 void DCameraSinkDevTest::TearDownTestCase(void)
76 {
77 }
78 
SetUp(void)79 void DCameraSinkDevTest::SetUp(void)
80 {
81     DCameraHandler::GetInstance().Initialize();
82     std::vector<std::string> cameras = DCameraHandler::GetInstance().GetCameras();
83     sptr<IDCameraSinkCallback> sinkCallback(new DCameraSinkCallback());
84     dev_ = std::make_shared<DCameraSinkDev>(cameras[0], sinkCallback);
85 
86     dev_->accessControl_ = std::make_shared<DCameraSinkAccessControl>();
87     dev_->controller_ = std::make_shared<MockDCameraSinkController>(dev_->accessControl_);
88 }
89 
TearDown(void)90 void DCameraSinkDevTest::TearDown(void)
91 {
92     usleep(TEST_TWENTY_MS);
93     dev_ = nullptr;
94 }
95 
96 /**
97  * @tc.name: dcamera_sink_dev_test_001
98  * @tc.desc: Verify the Init and UnInit function.
99  * @tc.type: FUNC
100  * @tc.require: AR000GK6MV
101  */
102 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_001, TestSize.Level1)
103 {
104     int32_t ret = dev_->Init();
105     EXPECT_EQ(DCAMERA_OK, ret);
106     EXPECT_EQ(true, dev_->isInit_);
107 
108     ret = dev_->UnInit();
109     EXPECT_EQ(DCAMERA_OK, ret);
110     EXPECT_EQ(false, dev_->isInit_);
111 }
112 
113 /**
114  * @tc.name: dcamera_sink_dev_test_002
115  * @tc.desc: Verify the SubscribeLocalHardware function.
116  * @tc.type: FUNC
117  * @tc.require: AR000GK6MT
118  */
119 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_002, TestSize.Level1)
120 {
121     int32_t ret = dev_->SubscribeLocalHardware(TEST_PARAMETER);
122     EXPECT_EQ(DCAMERA_OK, ret);
123 }
124 
125 /**
126  * @tc.name: dcamera_sink_dev_test_003
127  * @tc.desc: Verify the UnsubscribeLocalHardware function.
128  * @tc.type: FUNC
129  * @tc.require: AR000GK6MT
130  */
131 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_003, TestSize.Level1)
132 {
133     int32_t ret = dev_->UnsubscribeLocalHardware();
134     EXPECT_EQ(DCAMERA_OK, ret);
135 }
136 
137 /**
138  * @tc.name: dcamera_sink_dev_test_004
139  * @tc.desc: Verify the GetCameraInfo function.
140  * @tc.type: FUNC
141  * @tc.require: AR000GK6MT
142  */
143 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_004, TestSize.Level1)
144 {
145     int32_t ret = dev_->GetCameraInfo(g_testCameraInfo);
146     EXPECT_EQ(DCAMERA_OK, ret);
147     DHLOGI("DCameraSinkDevTest::GetCameraInfo cameraInfo is %s", GetAnonyString(g_testCameraInfo).c_str());
148 }
149 
150 /**
151  * @tc.name: dcamera_sink_dev_test_005
152  * @tc.desc: Verify the ChannelNeg function.
153  * @tc.type: FUNC
154  * @tc.require: AR000GK6MT
155  */
156 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_005, TestSize.Level1)
157 {
158     int32_t ret = dev_->ChannelNeg(g_testChannelInfoDevEmpty);
159     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
160 }
161 
162 /**
163  * @tc.name: dcamera_sink_dev_test_006
164  * @tc.desc: Verify the ChannelNeg function.
165  * @tc.type: FUNC
166  * @tc.require: AR000GK6MT
167  */
168 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_006, TestSize.Level1)
169 {
170     int32_t ret = dev_->ChannelNeg(g_testChannelInfoDevContinue);
171     EXPECT_EQ(DCAMERA_OK, ret);
172 }
173 
174 /**
175  * @tc.name: dcamera_sink_dev_test_007
176  * @tc.desc: Verify the StopCapture function.
177  * @tc.type: FUNC
178  * @tc.require: AR000GK6N1
179  */
180 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_007, TestSize.Level1)
181 {
182     int32_t ret = dev_->StopCapture();
183     EXPECT_EQ(DCAMERA_OK, ret);
184 }
185 
186 /**
187  * @tc.name: dcamera_sink_dev_test_008
188  * @tc.desc: Verify the OpenChannel function.
189  * @tc.type: FUNC
190  * @tc.require: AR000GK6N1
191  */
192 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_008, TestSize.Level1)
193 {
194     int32_t ret = dev_->OpenChannel(g_testOpenInfoDevEmpty);
195     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
196 }
197 
198 /**
199  * @tc.name: dcamera_sink_dev_test_009
200  * @tc.desc: Verify the OpenChannel function.
201  * @tc.type: FUNC
202  * @tc.require: AR000GK6N1
203  */
204 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_009, TestSize.Level1)
205 {
206     int32_t ret = dev_->OpenChannel(g_testOpenInfoDev);
207     EXPECT_EQ(DCAMERA_OK, ret);
208 }
209 
210 /**
211  * @tc.name: dcamera_sink_dev_test_010
212  * @tc.desc: Verify the CloseChannel function.
213  * @tc.type: FUNC
214  * @tc.require: AR000GK6N1
215  */
216 HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_010, TestSize.Level1)
217 {
218     int32_t ret = dev_->CloseChannel();
219     EXPECT_EQ(DCAMERA_OK, ret);
220 }
221 } // namespace DistributedHardware
222 } // namespace OHOS