• 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 #include <securec.h>
18 
19 #include "bus_center_info_key.h"
20 #include "lnn_connection_mock.h"
21 #include "lnn_devicename_info.h"
22 #include "lnn_net_builder_deps_mock.h"
23 #include "lnn_node_info.h"
24 #include "lnn_net_ledger_mock.h"
25 #include "lnn_p2p_info.h"
26 #include "lnn_service_mock.h"
27 #include "lnn_settingdata_event_monitor.h"
28 #include "message_handler.h"
29 #include "softbus_common.h"
30 #include "softbus_errcode.h"
31 
32 NodeInfo *info = {0};
33 constexpr char *DEVICE_NAME1 = nullptr;
34 constexpr char DEVICE_NAME2[] = "ABCDEFG";
35 
36 namespace OHOS {
37 using namespace testing;
38 using namespace testing::ext;
39 
40 class LnnDeviceNameInfoTest : public testing::Test {
41 public:
42     static void SetUpTestCase();
43     static void TearDownTestCase();
44     void SetUp();
45     void TearDown();
46 };
47 
SetUpTestCase()48 void LnnDeviceNameInfoTest::SetUpTestCase()
49 {
50 }
51 
TearDownTestCase()52 void LnnDeviceNameInfoTest::TearDownTestCase()
53 {
54 }
55 
SetUp()56 void LnnDeviceNameInfoTest::SetUp()
57 {
58 }
59 
TearDown()60 void LnnDeviceNameInfoTest::TearDown()
61 {
62 }
63 
64 /*
65 * @tc.name: LNN_UPDATE_DEVICE_NAME_TEST_001
66 * @tc.desc: no retry
67 * @tc.type: FUNC
68 * @tc.require:
69 */
70 HWTEST_F(LnnDeviceNameInfoTest, LNN_UPDATE_DEVICE_NAME_TEST_001, TestSize.Level1)
71 {
72     NiceMock<NetBuilderDepsInterfaceMock> netbuilderMock;
73     NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
74     NiceMock<LnnServicetInterfaceMock> serviceMock;
75     NiceMock<LnnConnectInterfaceMock> connMock;
76     LooperInit();
77     EXPECT_CALL(netbuilderMock, LnnGetSettingDeviceName).WillRepeatedly(
78         NetBuilderDepsInterfaceMock::ActionOfLnnGetSettingDeviceName);
79     EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
80     EXPECT_CALL(ledgerMock, LnnGetAllOnlineAndMetaNodeInfo).WillRepeatedly(Return(SOFTBUS_OK));
81     EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillRepeatedly(Return(info));
82     EXPECT_CALL(ledgerMock, LnnGetDeviceName).WillRepeatedly(Return(DEVICE_NAME1));
83     EXPECT_CALL(ledgerMock, LnnGetDeviceName).WillRepeatedly(Return(DEVICE_NAME2));
84     EXPECT_CALL(serviceMock, LnnInitGetDeviceName).WillRepeatedly(
85         LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName);
86     EXPECT_CALL(serviceMock, RegisterNameMonitor).WillRepeatedly(Return());
87     EXPECT_CALL(connMock, DiscDeviceInfoChanged).WillRepeatedly(Return());
88     UpdateDeviceName(nullptr);
89     LnnDeviceNameHandler HandlerGetDeviceName = LnnServicetInterfaceMock::g_deviceNameHandler;
90     HandlerGetDeviceName();
91     LooperDeinit();
92 }
93 
94 /*
95 * @tc.name: LNN_UPDATE_DEVICE_NAME_TEST_002
96 * @tc.desc: looper is null
97 * @tc.type: FUNC
98 * @tc.require:
99 */
100 HWTEST_F(LnnDeviceNameInfoTest, LNN_UPDATE_DEVICE_NAME_TEST_002, TestSize.Level1)
101 {
102     NiceMock<NetBuilderDepsInterfaceMock> netbuilderMock;
103     NiceMock<LnnServicetInterfaceMock> serviceMock;
104     EXPECT_CALL(serviceMock, LnnInitGetDeviceName).WillRepeatedly(
105         LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName);
106     EXPECT_CALL(netbuilderMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_ERR));
107     UpdateDeviceName(nullptr);
108 }
109 } // namespace OHOS
110