• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 
18 #include "dcamera_source_callback_proxy.h"
19 #include "dcamera_source_callback.h"
20 #include "distributed_camera_errno.h"
21 #include "distributed_camera_constants.h"
22 #include "distributed_camera_source_proxy.h"
23 #include "distributed_hardware_log.h"
24 #include "if_system_ability_manager.h"
25 #include "iservice_registry.h"
26 
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 class DcameraSourceCallbackProxyTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35     void SetUp();
36     void TearDown();
37 };
38 
39 namespace {
40 const std::string TEST_DEVICE_ID = "bb536a637105409e904d4da83790a4a7";
41 const std::string TEST_CAMERA_DH_ID_0 = "camera_0";
42 const std::string TEST_REQID = "bb536a637105409e904d4da83790a4a7";
43 std::string TEST_ATTRS = "";
44 }
45 
SetUpTestCase(void)46 void DcameraSourceCallbackProxyTest::SetUpTestCase(void)
47 {
48     DHLOGI("DcameraSourceCallbackProxyTest::SetUpTestCase");
49 }
50 
TearDownTestCase(void)51 void DcameraSourceCallbackProxyTest::TearDownTestCase(void)
52 {
53     DHLOGI("DcameraSourceCallbackProxyTest::TearDownTestCase");
54 }
55 
SetUp(void)56 void DcameraSourceCallbackProxyTest::SetUp(void)
57 {
58     DHLOGI("DcameraSourceCallbackProxyTest::SetUp");
59 }
60 
TearDown(void)61 void DcameraSourceCallbackProxyTest::TearDown(void)
62 {
63     DHLOGI("DcameraSourceCallbackProxyTest::TearDown");
64 }
65 
66 /**
67  * @tc.name: dcamera_source_callback_proxy_test_001
68  * @tc.desc: Verify the OnNotifyRegResult OnNotifyUnregResult function.
69  * @tc.type: FUNC
70  * @tc.require: issue
71  */
72 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_001, TestSize.Level1)
73 {
74     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_001");
75     sptr<ISystemAbilityManager> samgr =
76         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
77     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
78     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
79     EXPECT_EQ(false, callbackProxy == nullptr);
80 
81     const std::string devId = "";
82     int32_t status = 0;
83     int32_t ret = callbackProxy->OnNotifyRegResult(devId, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
84     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
85 
86     ret = callbackProxy->OnNotifyUnregResult(devId, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
87     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
88 }
89 
90 /**
91  * @tc.name: dcamera_source_callback_proxy_test_002
92  * @tc.desc: Verify the OnNotifyRegResult OnNotifyUnregResult function.
93  * @tc.type: FUNC
94  * @tc.require: issue
95  */
96 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_002, TestSize.Level1)
97 {
98     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_002");
99     sptr<ISystemAbilityManager> samgr =
100         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
101     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
102     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
103     EXPECT_EQ(false, callbackProxy == nullptr);
104 
105     const std::string reqId = "";
106     int32_t status = 0;
107     int32_t ret = callbackProxy->OnNotifyRegResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, reqId, status, TEST_ATTRS);
108     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
109 
110     ret = callbackProxy->OnNotifyUnregResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, reqId, status, TEST_ATTRS);
111     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
112 }
113 
114 /**
115  * @tc.name: dcamera_source_callback_proxy_test_003
116  * @tc.desc: Verify the OnNotifyRegResult OnNotifyUnregResult function.
117  * @tc.type: FUNC
118  * @tc.require: issue
119  */
120 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_003, TestSize.Level1)
121 {
122     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_003");
123     sptr<ISystemAbilityManager> samgr =
124         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
125     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
126     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
127     EXPECT_EQ(false, callbackProxy == nullptr);
128 
129     int32_t status = 0;
130     int32_t ret = callbackProxy->OnNotifyRegResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
131     EXPECT_EQ(DCAMERA_OK, status);
132 
133     ret = callbackProxy->OnNotifyUnregResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
134     EXPECT_EQ(DCAMERA_OK, status);
135 }
136 
137 /**
138  * @tc.name: dcamera_source_callback_proxy_test_004
139  * @tc.desc: Verify the OnNotifyRegResult function.
140  * @tc.type: FUNC
141  * @tc.require: issue
142  */
143 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_004, TestSize.Level1)
144 {
145     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_004");
146     sptr<ISystemAbilityManager> samgr =
147         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
148     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
149     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
150     EXPECT_EQ(false, callbackProxy == nullptr);
151 
152     int32_t status = 0;
153     const std::string maxdirstr(257, '1');
154     const std::string testemptystr = "";
155     const std::string teststr = "TESTSTR";
156     std::string maxdirstr1(50 * 1024 * 1024 + 1, '1');
157     std::string emptystr = "";
158 
159     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
160         testemptystr, testemptystr, testemptystr, status, emptystr));
161     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
162         maxdirstr, testemptystr, testemptystr, status, emptystr));
163     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
164         teststr, testemptystr, testemptystr, status, emptystr));
165     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
166         teststr, maxdirstr, testemptystr, status, emptystr));
167     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
168         teststr, teststr, testemptystr, status, emptystr));
169     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
170         teststr, teststr, maxdirstr, status, emptystr));
171     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnNotifyRegResult(
172         teststr, teststr, teststr, status, maxdirstr1));
173 }
174 
175 /**
176  * @tc.name: CheckParams_001
177  * @tc.desc: Verify the CheckParams function.
178  * @tc.type: FUNC
179  * @tc.require: issue
180  */
181 HWTEST_F(DcameraSourceCallbackProxyTest, CheckParams_001, TestSize.Level1)
182 {
183     DHLOGI("DcameraSourceCallbackProxyTest::CheckParams_001");
184     sptr<ISystemAbilityManager> samgr =
185         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
186     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
187     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
188 
189     EXPECT_EQ(false, callbackProxy->CheckParams("", "dhId", 0));
190     EXPECT_EQ(false, callbackProxy->CheckParams("devId", "", 0));
191 
192     std::string devId(257, '1');
193     EXPECT_EQ(false, callbackProxy->CheckParams(devId, "dhId", 0));
194 
195     std::string dhId(257, '1');
196     EXPECT_EQ(false, callbackProxy->CheckParams("devId", dhId, 0));
197 
198     EXPECT_EQ(false, callbackProxy->CheckParams("devId", "dhId", -1));
199     EXPECT_EQ(true, callbackProxy->CheckParams("devId", "dhId", 0));
200 }
201 
202 /**
203  * @tc.name: OnDataSyncTrigger_001
204  * @tc.desc: Verify the OnDataSyncTrigger function.
205  * @tc.type: FUNC
206  * @tc.require: issue
207  */
208 HWTEST_F(DcameraSourceCallbackProxyTest, OnDataSyncTrigger_001, TestSize.Level1)
209 {
210     DHLOGI("DcameraSourceCallbackProxyTest::OnDataSyncTrigger_001");
211     sptr<ISystemAbilityManager> samgr =
212         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
213     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
214     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
215 
216     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnDataSyncTrigger(""));
217     std::string devId(257, '1');
218     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnDataSyncTrigger(devId));
219 }
220 
221 /**
222  * @tc.name: OnDataSyncTrigger_002
223  * @tc.desc: Verify the OnDataSyncTrigger function.
224  * @tc.type: FUNC
225  * @tc.require: issue
226  */
227 HWTEST_F(DcameraSourceCallbackProxyTest, OnDataSyncTrigger_002, TestSize.Level1)
228 {
229     DHLOGI("DcameraSourceCallbackProxyTest::OnDataSyncTrigger_002");
230 
231     sptr<DCameraSourceCallback> remoteObject = sptr<DCameraSourceCallback>(new DCameraSourceCallback());
232     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
233 
234     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnDataSyncTrigger(TEST_DEVICE_ID));
235 }
236 
237 /**
238  * @tc.name: OnHardwareStateChanged_001
239  * @tc.desc: Verify the OnHardwareStateChanged function.
240  * @tc.type: FUNC
241  * @tc.require: issue
242  */
243 HWTEST_F(DcameraSourceCallbackProxyTest, OnHardwareStateChanged_001, TestSize.Level1)
244 {
245     DHLOGI("DcameraSourceCallbackProxyTest::OnHardwareStateChanged_001");
246     sptr<ISystemAbilityManager> samgr =
247         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
248     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
249     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
250 
251     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnHardwareStateChanged("", "", -1));
252 }
253 
254 /**
255  * @tc.name: OnHardwareStateChanged_002
256  * @tc.desc: Verify the OnHardwareStateChanged function.
257  * @tc.type: FUNC
258  * @tc.require: issue
259  */
260 HWTEST_F(DcameraSourceCallbackProxyTest, OnHardwareStateChanged_002, TestSize.Level1)
261 {
262     DHLOGI("DcameraSourceCallbackProxyTest::OnHardwareStateChanged_002");
263 
264     sptr<DCameraSourceCallback> remoteObject = sptr<DCameraSourceCallback>(new DCameraSourceCallback());
265     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
266 
267     EXPECT_EQ(DCAMERA_BAD_VALUE, callbackProxy->OnHardwareStateChanged(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, 0));
268 }
269 } // namespace DistributedHardware
270 } // namespace OHOS