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 #include "gtest/gtest.h"
16 #include <securec.h>
17
18 #include "bus_center_event.h"
19 #include "g_enhance_adapter_func.h"
20 #include "lnn_sle_monitor.c"
21 #include "lnn_event_monitor_impl.h"
22 #include "network_mock.h"
23 #include "softbus_error_code.h"
24
25 namespace OHOS {
26 using namespace testing::ext;
27 using namespace testing;
28 class SoftbusSleMonitorTest : public testing::Test {
29 protected:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 void SetUp();
33 void TearDown();
34 };
SetUpTestCase(void)35 void SoftbusSleMonitorTest::SetUpTestCase(void)
36 {
37 AdapterEnhanceFuncList *pfnAdapterFuncList = AdapterEnhanceFuncListGet();
38 pfnAdapterFuncList->softBusAddSleStateListener = SoftBusAddSleStateListener;
39 pfnAdapterFuncList->isSleEnabled = IsSleEnabled;
40 pfnAdapterFuncList->softBusRemoveSleStateListener = SoftBusRemoveSleStateListener;
41 }
TearDownTestCase(void)42 void SoftbusSleMonitorTest::TearDownTestCase(void) { }
SetUp()43 void SoftbusSleMonitorTest::SetUp() { }
TearDown()44 void SoftbusSleMonitorTest::TearDown() { }
45
46 /*
47 * @tc.name: LnnInitSle
48 * @tc.desc: softbus network test
49 * @tc.type: FUNC
50 * @tc.require:
51 */
52 HWTEST_F(SoftbusSleMonitorTest, LnnInitSleTest001, TestSize.Level1)
53 {
54 NiceMock<NetworkInterfaceMock> networkMock;
55 EXPECT_CALL(networkMock, LnnAsyncCallbackHelper).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
56 EXPECT_CALL(networkMock, SoftBusAddSleStateListener)
57 .WillOnce(Return(SOFTBUS_INVALID_PARAM))
58 .WillRepeatedly(DoAll(SetArgPointee<1>(1), Return(SOFTBUS_OK)));
59
60 int32_t ret = LnnInitSle();
61 EXPECT_TRUE(ret != SOFTBUS_OK);
62 EXPECT_CALL(networkMock, IsSleEnabled).WillOnce(Return(false)).WillRepeatedly(Return(true));
63 ret = LnnInitSle();
64 EXPECT_TRUE(ret == SOFTBUS_OK);
65 EXPECT_CALL(networkMock, SoftBusRemoveSleStateListener) .WillOnce(Return());
66 EXPECT_NO_FATAL_FAILURE(LnnDeinitSle());
67 EXPECT_NO_FATAL_FAILURE(LnnOnSleStateChanged(SOFTBUS_SLE_UNKNOWN));
68 }
69
70 } // namespace OHOS