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