• 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 <securec.h>
19 
20 #include "bus_center_event.h"
21 #include "bus_center_manager.h"
22 #include "lnn_decision_center.h"
23 #include "lnn_heartbeat_ctrl.h"
24 #include "message_handler.h"
25 #include "softbus_access_token_test.h"
26 #include "softbus_bus_center.h"
27 #include "softbus_error_code.h"
28 
29 namespace OHOS {
30 using namespace testing::ext;
31 
32 static constexpr char TEST_PKG_NAME1[] = "com.softbus.test";
33 static constexpr char TEST_PKG_NAME2[] = "com.softbus.test1";
34 
35 class BusCenterHeartbeatSdkTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase()43 void BusCenterHeartbeatSdkTest::SetUpTestCase()
44 {
45     SetAccessTokenPermission("busCenterTest");
46     LnnInitLnnLooper();
47     LooperInit();
48     LnnInitBusCenterEvent();
49     LnnInitHeartbeat();
50 }
51 
TearDownTestCase()52 void BusCenterHeartbeatSdkTest::TearDownTestCase()
53 {
54     LnnDeinitHeartbeat();
55     LnnDeinitBusCenterEvent();
56     LooperDeinit();
57     LnnDeinitLnnLooper();
58 }
59 
SetUp()60 void BusCenterHeartbeatSdkTest::SetUp() { }
61 
TearDown()62 void BusCenterHeartbeatSdkTest::TearDown() { }
63 
64 /*
65  * @tc.name: Shift_Lnn_Gear_Test_001
66  * @tc.desc: heart beat parameter adjust test
67  * @tc.type: FUNC
68  * @tc.require: I5HMXC
69  */
70 HWTEST_F(BusCenterHeartbeatSdkTest, Shift_Lnn_Gear_Test_001, TestSize.Level1)
71 {
72     char networkId1[] = "012345678B987654321001234A678998";
73     char networkId2[] = "012345678B987654321001234A67899876543210012E4567899876543210012FFFFFFFFF012345678B9876";
74     const char *callerId1 = "1";
75     const char *callerId2 = "2";
76     const char *callerId3 = "3";
77     const char *callerId4 = "4";
78     const char *callerId5 = "5";
79     const char *callerId6 = "";
80     const char *callerId7 = "012345678B987654321001234A67899876543210012E4567899876543210012FFFFFFFFF012345678B9876"
81                             "54321001234A67899876543210012E4567899876543210012FFFFFFFFF";
82     GearMode mode1 = { .cycle = MID_FREQ_CYCLE, .duration = DEFAULT_DURATION, .wakeupFlag = false };
83     GearMode mode2 = { .cycle = HIGH_FREQ_CYCLE, .duration = DEFAULT_DURATION, .wakeupFlag = true };
84     GearMode mode3 = { .cycle = LOW_FREQ_CYCLE, .duration = LONG_DURATION, .wakeupFlag = true };
85     GearMode mode4 = { .cycle = HIGH_FREQ_CYCLE, .duration = NORMAL_DURATION, .wakeupFlag = true };
86     GearMode mode5 = { .cycle = MID_FREQ_CYCLE, .duration = LONG_DURATION, .wakeupFlag = false };
87 
88     int32_t ret = ShiftLNNGear(TEST_PKG_NAME1, callerId1, nullptr, &mode1);
89     if (ret != SOFTBUS_NOT_IMPLEMENT) {
90         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId1, networkId1, &mode1), SOFTBUS_INVALID_PARAM);
91         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId1, networkId2, &mode1), SOFTBUS_INVALID_PARAM);
92         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId1, nullptr, &mode1), SOFTBUS_OK);
93         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME2, callerId1, nullptr, &mode1), SOFTBUS_OK);
94         EXPECT_EQ(ShiftLNNGear(nullptr, callerId1, nullptr, &mode1), SOFTBUS_INVALID_PARAM);
95         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId1, nullptr, nullptr), SOFTBUS_INVALID_PARAM);
96 
97         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId1, nullptr, &mode2), SOFTBUS_OK);
98         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId2, nullptr, &mode2), SOFTBUS_OK);
99         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId3, nullptr, &mode3), SOFTBUS_OK);
100         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId4, nullptr, &mode4), SOFTBUS_OK);
101         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId5, nullptr, &mode5), SOFTBUS_OK);
102         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId6, nullptr, &mode5), SOFTBUS_INVALID_PARAM);
103         EXPECT_EQ(ShiftLNNGear(TEST_PKG_NAME1, callerId7, nullptr, &mode5), SOFTBUS_INVALID_PARAM);
104     }
105 }
106 } // namespace OHOS
107