• 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 #include "UTTest_softbus_listener.h"
16 
17 #include <securec.h>
18 #include <unistd.h>
19 #include <cstdlib>
20 #include <thread>
21 
22 #include "dm_anonymous.h"
23 #include "dm_constants.h"
24 #include "dm_device_info.h"
25 #include "dm_log.h"
26 #include "parameter.h"
27 #include "system_ability_definition.h"
28 
29 namespace OHOS {
30 namespace DistributedHardware {
SetUp()31 void SoftbusListenerTest::SetUp()
32 {
33 }
TearDown()34 void SoftbusListenerTest::TearDown()
35 {
36 }
SetUpTestCase()37 void SoftbusListenerTest::SetUpTestCase()
38 {
39 }
TearDownTestCase()40 void SoftbusListenerTest::TearDownTestCase()
41 {
42 }
43 
44 namespace {
45     std::shared_ptr<SoftbusListener> softbusListener = std::make_shared<SoftbusListener>();
46 
47 /**
48  * @tc.name: ConvertNodeBasicInfoToDmDevice_001
49  * @tc.desc: go to the correct case and return DM_OK
50  * @tc.type: FUNC
51  * @tc.require: AR000GHSJK
52  */
53 HWTEST_F(SoftbusListenerTest, ConvertNodeBasicInfoToDmDevice_001, testing::ext::TestSize.Level0)
54 {
55     NodeBasicInfo nodeBasicInfo;
56     DmDeviceInfo dmDeviceInfo;
57     int32_t ret = softbusListener->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo);
58     EXPECT_EQ(ret, DM_OK);
59 }
60 
61 /**
62  * @tc.name: OnParameterChgCallback_001
63  * @tc.desc: return true
64  * @tc.type: FUNC
65  * @tc.require: AR000GHSJK
66  */
67 HWTEST_F(SoftbusListenerTest, OnParameterChgCallback_001, testing::ext::TestSize.Level0)
68 {
69     const char *key = "123";
70     const char *value = "1";
71     void *context = nullptr;
72     softbusListener->OnParameterChgCallback(key, value, context);
73     NodeBasicInfo *info = nullptr;
74     softbusListener->OnSoftBusDeviceOnline(info);
75     softbusListener->OnSoftbusDeviceOffline(info);
76     EXPECT_EQ(softbusListener->publishStatus, SoftbusListener::STATUS_UNKNOWN);
77 }
78 
79 /**
80  * @tc.name: ShiftLNNGear_001
81  * @tc.desc: return DM_OK
82  * @tc.type: FUNC
83  */
84 HWTEST_F(SoftbusListenerTest, ShiftLNNGear_001, testing::ext::TestSize.Level0)
85 {
86     EXPECT_NE(softbusListener->ShiftLNNGear(), DM_OK);
87 }
88 
89 /**
90  * @tc.name: OnParameterChgCallback_002
91  * @tc.desc: return true
92  * @tc.type: FUNC
93  * @tc.require: AR000GHSJK
94  */
95 HWTEST_F(SoftbusListenerTest, OnParameterChgCallback_002, testing::ext::TestSize.Level0)
96 {
97     const char *key = "222";
98     const char *value = "0";
99     void *context = nullptr;
100     softbusListener->OnParameterChgCallback(key, value, context);
101     NodeBasicInfo info = {
102             .networkId = "123456",
103             .deviceName = "123456",
104             .deviceTypeId = 1
105         };
106     softbusListener->OnSoftBusDeviceOnline(&info);
107     softbusListener->OnSoftbusDeviceOffline(&info);
108     sleep(1);
109     EXPECT_EQ(softbusListener->publishStatus, SoftbusListener::STATUS_UNKNOWN);
110 }
111 
112 /**
113  * @tc.name: GetAvailableDeviceList_001
114  * @tc.desc: return ERR_DM_FAILED
115  * @tc.type: FUNC
116  */
117 HWTEST_F(SoftbusListenerTest, GetAvailableDeviceList_001, testing::ext::TestSize.Level0)
118 {
119     std::vector<DmDeviceBasicInfo> deviceBasicInfoList;
120     int32_t ret = softbusListener->GetAvailableDeviceList(deviceBasicInfoList);
121     EXPECT_EQ(ret, ERR_DM_FAILED);
122 }
123 
124 /**
125  * @tc.name: GetLocalDeviceNetworkId_001
126  * @tc.desc: return ERR_DM_FAILED
127  * @tc.type: FUNC
128  */
129 HWTEST_F(SoftbusListenerTest, GetLocalDeviceNetworkId_001, testing::ext::TestSize.Level0)
130 {
131     std::string networkId;
132     int32_t ret = softbusListener->GetLocalDeviceNetworkId(networkId);
133     EXPECT_EQ(ret, ERR_DM_FAILED);
134 }
135 
136 /**
137  * @tc.name: GetLocalDeviceName_001
138  * @tc.desc: return ERR_DM_FAILED
139  * @tc.type: FUNC
140  */
141 HWTEST_F(SoftbusListenerTest, GetLocalDeviceName_001, testing::ext::TestSize.Level0)
142 {
143     std::string deviceName;
144     int32_t ret = softbusListener->GetLocalDeviceName(deviceName);
145     EXPECT_EQ(ret, ERR_DM_FAILED);
146 }
147 
148 /**
149  * @tc.name: GetLocalDeviceType_001
150  * @tc.desc: return ERR_DM_FAILED
151  * @tc.type: FUNC
152  */
153 HWTEST_F(SoftbusListenerTest, GetLocalDeviceType_001, testing::ext::TestSize.Level0)
154 {
155     int32_t deviceType = 0;
156     int32_t ret = softbusListener->GetLocalDeviceType(deviceType);
157     EXPECT_EQ(ret, ERR_DM_FAILED);
158 }
159 
160 /**
161  * @tc.name: ConvertNodeBasicInfoToDmDevice_002
162  * @tc.desc: return DM_OK
163  * @tc.type: FUNC
164  */
165 HWTEST_F(SoftbusListenerTest, ConvertNodeBasicInfoToDmDevice_002, testing::ext::TestSize.Level0)
166 {
167     NodeBasicInfo nodeBasicInfo;
168     DmDeviceBasicInfo dmDevicdeviceNameeInfo;
169     int32_t ret = softbusListener->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDevicdeviceNameeInfo);
170     EXPECT_EQ(ret, DM_OK);
171 }
172 } // namespace
173 } // namespace DistributedHardware
174 } // namespace OHOS