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