1 /*
2 * Copyright (c) 2024 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 <unistd.h>
18
19 #include "app_device_handler.h"
20 #include "app_types.h"
21
22 using namespace testing::ext;
23 using namespace OHOS::ObjectStore;
24 using namespace OHOS;
25 using namespace std;
26 using namespace testing;
27
28 namespace {
29 class AppDeviceHandlerTest : public testing::Test {
30 public:
31 static void SetUpTestCase(void);
32 static void TearDownTestCase(void);
33 void SetUp();
34 void TearDown();
35 };
36
SetUpTestCase(void)37 void AppDeviceHandlerTest::SetUpTestCase(void)
38 {
39 // input testsuit setup step,setup invoked before all testcases
40 }
41
TearDownTestCase(void)42 void AppDeviceHandlerTest::TearDownTestCase(void)
43 {
44 // input testsuit teardown step,teardown invoked after all testcases
45 }
46
SetUp(void)47 void AppDeviceHandlerTest::SetUp(void)
48 {
49 // input testcase setup step,setup invoked before each testcases
50 }
51
TearDown(void)52 void AppDeviceHandlerTest::TearDown(void)
53 {
54 // input testcase teardown step,teardown invoked after each testcases
55 }
56
57 /**
58 * @tc.name: GetLocalBasicInfo_001
59 * @tc.desc: Normal test for GetLocalBasicInfo
60 * @tc.type: FUNC
61 */
62
63 HWTEST_F(AppDeviceHandlerTest, GetLocalBasicInfo_001, TestSize.Level1)
64 {
65 AppDeviceHandler appDeviceHandler;
66 appDeviceHandler.softbusAdapter_ = std::make_shared<SoftBusAdapter>();
67 ObjectStore::DeviceInfo ret = appDeviceHandler.GetLocalBasicInfo();
68 auto ret2 = appDeviceHandler.softbusAdapter_->GetLocalBasicInfo();
69 EXPECT_EQ(ret.deviceId, ret2.deviceId);
70 EXPECT_EQ(ret.deviceName, ret2.deviceName);
71 EXPECT_EQ(ret.deviceType, ret2.deviceType);
72 }
73
74 /**
75 * @tc.name: GetRemoteNodesBasicInfo_001
76 * @tc.desc: Normal test for GetRemoteNodesBasicInfo
77 * @tc.type: FUNC
78 */
79
80 HWTEST_F(AppDeviceHandlerTest, GetRemoteNodesBasicInfo_001, TestSize.Level1)
81 {
82 AppDeviceHandler appDeviceHandler;
83 appDeviceHandler.softbusAdapter_ = std::make_shared<SoftBusAdapter>();
84 std::vector<ObjectStore::DeviceInfo> ret = appDeviceHandler.GetRemoteNodesBasicInfo();
85 auto ret2 = appDeviceHandler.softbusAdapter_->GetRemoteNodesBasicInfo();
86 EXPECT_TRUE(ret.size() == ret2.size());
87 }
88
89 /**
90 * @tc.name: GetUuidByNodeId_001
91 * @tc.desc: Normal test for GetUuidByNodeId
92 * @tc.type: FUNC
93 */
94
95 HWTEST_F(AppDeviceHandlerTest, GetUuidByNodeId_001, TestSize.Level1)
96 {
97 std::string nodeId = "123";
98 AppDeviceHandler appDeviceHandler;
99 appDeviceHandler.devManager_ = DevManager::GetInstance();
100 std::string ret = appDeviceHandler.GetUuidByNodeId(nodeId);
101 EXPECT_EQ(ret, appDeviceHandler.devManager_->GetUuidByNodeId(nodeId));
102 }
103 }
104