• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #include <gtest/gtest.h>
17 
18 #include "dcamera_source_callback_proxy.h"
19 #include "distributed_camera_errno.h"
20 #include "distributed_camera_constants.h"
21 #include "distributed_camera_source_proxy.h"
22 #include "distributed_hardware_log.h"
23 #include "if_system_ability_manager.h"
24 #include "iservice_registry.h"
25 
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 class DcameraSourceCallbackProxyTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36 };
37 
38 namespace {
39 const std::string TEST_DEVICE_ID = "bb536a637105409e904d4da83790a4a7";
40 const std::string TEST_CAMERA_DH_ID_0 = "camera_0";
41 const std::string TEST_REQID = "bb536a637105409e904d4da83790a4a7";
42 std::string TEST_ATTRS = "";
43 }
44 
SetUpTestCase(void)45 void DcameraSourceCallbackProxyTest::SetUpTestCase(void)
46 {
47     DHLOGI("DcameraSourceCallbackProxyTest::SetUpTestCase");
48 }
49 
TearDownTestCase(void)50 void DcameraSourceCallbackProxyTest::TearDownTestCase(void)
51 {
52     DHLOGI("DcameraSourceCallbackProxyTest::TearDownTestCase");
53 }
54 
SetUp(void)55 void DcameraSourceCallbackProxyTest::SetUp(void)
56 {
57     DHLOGI("DcameraSourceCallbackProxyTest::SetUp");
58 }
59 
TearDown(void)60 void DcameraSourceCallbackProxyTest::TearDown(void)
61 {
62     DHLOGI("DcameraSourceCallbackProxyTest::TearDown");
63 }
64 
65 /**
66  * @tc.name: dcamera_source_callback_proxy_test_001
67  * @tc.desc: Verify the OnNotifyRegResult OnNotifyUnregResult function.
68  * @tc.type: FUNC
69  * @tc.require: issue
70  */
71 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_001, TestSize.Level1)
72 {
73     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_001");
74     sptr<ISystemAbilityManager> samgr =
75         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
76     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
77     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
78     EXPECT_EQ(false, callbackProxy == nullptr);
79 
80     const std::string devId = "";
81     int32_t status = 0;
82     int32_t ret = callbackProxy->OnNotifyRegResult(devId, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
83     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
84 
85     ret = callbackProxy->OnNotifyUnregResult(devId, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
86     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
87 }
88 
89 /**
90  * @tc.name: dcamera_source_callback_proxy_test_002
91  * @tc.desc: Verify the OnNotifyRegResult OnNotifyUnregResult function.
92  * @tc.type: FUNC
93  * @tc.require: issue
94  */
95 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_002, TestSize.Level1)
96 {
97     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_002");
98     sptr<ISystemAbilityManager> samgr =
99         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
100     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
101     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
102     EXPECT_EQ(false, callbackProxy == nullptr);
103 
104     const std::string reqId = "";
105     int32_t status = 0;
106     int32_t ret = callbackProxy->OnNotifyRegResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, reqId, status, TEST_ATTRS);
107     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
108 
109     ret = callbackProxy->OnNotifyUnregResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, reqId, status, TEST_ATTRS);
110     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
111 }
112 
113 /**
114  * @tc.name: dcamera_source_callback_proxy_test_003
115  * @tc.desc: Verify the OnNotifyRegResult OnNotifyUnregResult function.
116  * @tc.type: FUNC
117  * @tc.require: issue
118  */
119 HWTEST_F(DcameraSourceCallbackProxyTest, dcamera_source_callback_proxy_test_003, TestSize.Level1)
120 {
121     DHLOGI("DcameraSourceCallbackProxyTest::dcamera_source_callback_proxy_test_003");
122     sptr<ISystemAbilityManager> samgr =
123         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
124     sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID);
125     sptr<DCameraSourceCallbackProxy> callbackProxy(new DCameraSourceCallbackProxy(remoteObject));
126     EXPECT_EQ(false, callbackProxy == nullptr);
127 
128     int32_t status = 0;
129     int32_t ret = callbackProxy->OnNotifyRegResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
130     EXPECT_EQ(DCAMERA_OK, status);
131 
132     ret = callbackProxy->OnNotifyUnregResult(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, TEST_REQID, status, TEST_ATTRS);
133     EXPECT_EQ(DCAMERA_OK, status);
134 }
135 } // namespace DistributedHardware
136 } // namespace OHOS