• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "lnn_init_monitor.c"
17 #include "lnn_init_monitor.h"
18 #include <cstring>
19 #include <gtest/gtest.h>
20 #include <securec.h>
21 
22 namespace OHOS {
23 using namespace testing::ext;
24 
25 class LNNInitMonitorTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase()33 void LNNInitMonitorTest::SetUpTestCase() { }
34 
TearDownTestCase()35 void LNNInitMonitorTest::TearDownTestCase() { }
36 
SetUp()37 void LNNInitMonitorTest::SetUp()
38 {
39     LnnInitMonitorInit();
40 }
41 
TearDown()42 void LNNInitMonitorTest::TearDown() { }
43 
LNNTestSetMonitorInitSuc(void)44 void LNNTestSetMonitorInitSuc(void)
45 {
46     for (uint32_t depModule = 0; depModule < INIT_DEPS_MODULE_BUTT; depModule++) {
47         LnnInitModuleStatusSet(depModule, DEPS_STATUS_SUCCESS);
48     }
49     for (uint32_t depLeger = 0; depLeger < LEDGER_INFO_BUTT; depLeger++) {
50         LnnInitDeviceInfoStatusSet(depLeger, DEPS_STATUS_SUCCESS);
51     }
52 }
LnnInitMonitorCallbackSuc(void)53 int32_t LnnInitMonitorCallbackSuc(void)
54 {
55     return SOFTBUS_OK;
56 }
57 
LnnInitMonitorCallbackFailed(void)58 int32_t LnnInitMonitorCallbackFailed(void)
59 {
60     return SOFTBUS_ERR;
61 }
62 /*
63  * @tc.name: LnnInitMonitor_Test_001
64  * @tc.desc: status set test
65  * @tc.type: FUNC
66  * @tc.require: I5RHYE
67  */
68 HWTEST_F(LNNInitMonitorTest, LnnInitMonitor_Test_001, TestSize.Level0)
69 {
70     InitDepsStatus status;
71 
72     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
73     EXPECT_EQ(status, DEPS_STATUS_NOT_INIT);
74     status = LnnInitDeviceInfoStatusGet(LEDGER_INFO_DEVICE_NAME);
75     EXPECT_EQ(status, DEPS_STATUS_NOT_INIT);
76 
77 
78     LnnInitModuleReturnSet(INIT_DEPS_DEVICE_PROFILE, SOFTBUS_OK);
79     LnnInitModuleStatusSet(INIT_DEPS_DEVICE_PROFILE, DEPS_STATUS_SUCCESS);
80     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
81     EXPECT_EQ(status, DEPS_STATUS_SUCCESS);
82 
83     LnnInitDeviceInfoStatusSet(LEDGER_INFO_DEVICE_NAME, DEPS_STATUS_SUCCESS);
84     status = LnnInitDeviceInfoStatusGet(LEDGER_INFO_DEVICE_NAME);
85     EXPECT_EQ(status, DEPS_STATUS_SUCCESS);
86 
87     status = LnnInitDeviceInfoStatusGet(LEDGER_INFO_BUTT);
88     EXPECT_EQ(status, DEPS_STATUS_NOT_INIT);
89 }
90 /*
91  * @tc.name: LnnInitMonitor_Test_002
92  * @tc.desc: status get test
93  * @tc.type: FUNC
94  * @tc.require: I5RHYE
95  */
96 HWTEST_F(LNNInitMonitorTest, LnnInitMonitor_Test_002, TestSize.Level0)
97 {
98     InitDepsStatus status;
99     uint32_t ret;
100 
101     ret = IsLnnInitCheckSucceed(MONITOR_WIFI_NET);
102     EXPECT_EQ(ret, false);
103     ret = IsLnnInitCheckSucceed(MONITOR_BLE_NET);
104     EXPECT_EQ(ret, false);
105 
106     LNNTestSetMonitorInitSuc();
107     LnnModuleInitMonitorCheckStart();
108 
109     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
110     EXPECT_EQ(status, DEPS_STATUS_SUCCESS);
111 }
112 
113 /*
114  * @tc.name: LnnModuleInitMonitorCheckStart_Test_001
115  * @tc.desc: LnnInitModuleNotify API test
116  * @tc.type: FUNC
117  * @tc.require: I5RHYE
118  */
119 HWTEST_F(LNNInitMonitorTest, LnnInitMonitor_Test_003, TestSize.Level0)
120 {
121     InitDepsStatus status;
122     bool ret;
123 
124     LNNTestSetMonitorInitSuc();
125     LnnInitModuleStatusSet(INIT_DEPS_DEVICE_PROFILE, DEPS_STATUS_FAILED);
126     LnnInitDeviceInfoStatusSet(LEDGER_INFO_DEVICE_NAME, DEPS_STATUS_FAILED);
127     LnnModuleInitMonitorCheckStart();
128 
129     LnnInitModuleStatusSet(INIT_DEPS_DEVICE_PROFILE, DEPS_STATUS_SUCCESS);
130     LnnInitDeviceInfoStatusSet(LEDGER_INFO_DEVICE_NAME, DEPS_STATUS_SUCCESS);
131     SoftBusSleepMs(1000);
132     LnnInitSetDeviceInfoReady();
133     LnnInitMonitorInitComplete(nullptr);
134     ret = IsLnnInitCheckSucceed(MONITOR_WIFI_NET);
135     EXPECT_EQ(ret, true);
136 
137     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
138     EXPECT_EQ(status, DEPS_STATUS_SUCCESS);
139 }
140 
141 /*
142  * @tc.name: LnnModuleInitMonitorCheckStart_Test_001
143  * @tc.desc: LnnInitModuleNotifyWithRetry API test
144  * @tc.type: FUNC
145  * @tc.require: I5RHYE
146  */
147 HWTEST_F(LNNInitMonitorTest, LnnInitMonitor_Test_004, TestSize.Level0)
148 {
149     InitDepsStatus status;
150     uint32_t ret;
151 
152     ret = LnnInitModuleNotifyWithRetryAsync(INIT_DEPS_MODULE_BUTT, nullptr, 0, 0, false);
153     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
154 
155     ret = LnnInitModuleNotifyWithRetryAsync(INIT_DEPS_DEVICE_PROFILE, LnnInitMonitorCallbackFailed, 3, 0, false);
156     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
157 
158     ret = LnnInitModuleNotifyWithRetryAsync(INIT_DEPS_DEVICE_PROFILE, LnnInitMonitorCallbackSuc, 0, 0, false);
159     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
160     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
161     EXPECT_EQ(status, DEPS_STATUS_FAILED);
162 }
163 
164 /*
165  * @tc.name: LnnModuleInitMonitorCheckStart_Test_001
166  * @tc.desc: LnnInitModuleNotifyWithRetry API test
167  * @tc.type: FUNC
168  * @tc.require: I5RHYE
169  */
170 HWTEST_F(LNNInitMonitorTest, LnnInitMonitor_Test_005, TestSize.Level0)
171 {
172     InitDepsStatus status;
173     uint32_t ret;
174 
175     ret = LnnInitModuleNotifyWithRetrySync(INIT_DEPS_MODULE_BUTT, nullptr, 0, 0);
176     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
177 
178     ret = LnnInitModuleNotifyWithRetrySync(INIT_DEPS_DEVICE_PROFILE, LnnInitMonitorCallbackFailed, 3, 0);
179     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
180     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
181     EXPECT_EQ(status, DEPS_STATUS_FAILED);
182 
183     ret = LnnInitModuleNotifyWithRetrySync(INIT_DEPS_DEVICE_PROFILE, LnnInitMonitorCallbackSuc, 0, 0);
184     EXPECT_EQ(ret, SOFTBUS_OK);
185     status = LnnInitModuleStatusGet(INIT_DEPS_DEVICE_PROFILE);
186     EXPECT_EQ(status, DEPS_STATUS_SUCCESS);
187 }
188 } // namespace OHOS