• 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 #define LOG_TAG "DevManagerTest"
17 #include <gtest/gtest.h>
18 
19 #include "dev_manager.h"
20 #include "types.h"
21 #include "log_print.h"
22 namespace OHOS::Test {
23 using namespace testing::ext;
24 using namespace OHOS::DistributedKv;
25 
26 class DevManagerTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30 
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void DevManagerTest::SetUpTestCase(void)
36 {}
37 
TearDownTestCase(void)38 void DevManagerTest::TearDownTestCase(void)
39 {}
40 
SetUp(void)41 void DevManagerTest::SetUp(void)
42 {}
43 
TearDown(void)44 void DevManagerTest::TearDown(void)
45 {}
46 
47 /**
48 * @tc.name: GetLocalDevice
49 * @tc.desc: Get local device's infomation
50 * @tc.type: FUNC
51 * @tc.require:
52 * @tc.author: taoyuxin
53 */
54 HWTEST_F(DevManagerTest, GetLocalDevice, TestSize.Level1)
55 {
56     ZLOGI("GetLocalDevice begin.");
57     auto devInfo = DevManager::GetInstance().GetLocalDevice();
58     EXPECT_NE(devInfo.networkId, "");
59     EXPECT_NE(devInfo.uuid, "");
60 }
61 
62 /**
63 * @tc.name: ToUUID
64 * @tc.desc: Get uuid from networkId
65 * @tc.type: FUNC
66 * @tc.require:
67 * @tc.author: taoyuxin
68 */
69 HWTEST_F(DevManagerTest, ToUUID, TestSize.Level1)
70 {
71     ZLOGI("ToUUID begin.");
72     auto &devMgr = DevManager::GetInstance();
73     auto devInfo = devMgr.GetLocalDevice();
74     EXPECT_NE(devInfo.networkId, "");
75     auto uuid = devMgr.ToUUID(devInfo.networkId);
76     EXPECT_NE(uuid, "");
77     EXPECT_EQ(uuid, devInfo.uuid);
78 }
79 
80 /**
81 * @tc.name: ToNetworkId
82 * @tc.desc: Get networkId from uuid
83 * @tc.type: FUNC
84 * @tc.require:
85 * @tc.author: zuojiangjiang
86 */
87 HWTEST_F(DevManagerTest, ToNetworkId, TestSize.Level1)
88 {
89     auto &devMgr = DevManager::GetInstance();
90     auto devInfo = devMgr.GetLocalDevice();
91     EXPECT_NE(devInfo.uuid, "");
92     auto networkId = devMgr.ToNetworkId(devInfo.uuid);
93     EXPECT_NE(networkId, "");
94     EXPECT_EQ(networkId, devInfo.networkId);
95 }
96 
97 /**
98 * @tc.name: GetRemoteDevices
99 * @tc.desc: Get remote devices
100 * @tc.type: FUNC
101 * @tc.require:
102 * @tc.author: taoyuxin
103 */
104 HWTEST_F(DevManagerTest, GetRemoteDevices, TestSize.Level1)
105 {
106     ZLOGI("GetRemoteDevices begin.");
107     DevManager &devManager = OHOS::DistributedKv::DevManager::GetInstance();
108     auto devInfos = devManager.GetRemoteDevices();
109     EXPECT_EQ(devInfos.size(), 0);
110 }
111 } // namespace OHOS::Test