• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "device/dm_adapter.h"
17 #include "distributed_clip.h"
18 #include <gtest/gtest.h>
19 
20 namespace OHOS::MiscServices {
21 using namespace testing::ext;
22 class DMAdapterTest : public testing::Test {
23 public:
24     static void SetUpTestCase(void);
25     static void TearDownTestCase(void);
26     void SetUp();
27     void TearDown();
28 };
29 
SetUpTestCase(void)30 void DMAdapterTest::SetUpTestCase(void)
31 {
32 }
33 
TearDownTestCase(void)34 void DMAdapterTest::TearDownTestCase(void)
35 {
36 }
37 
SetUp(void)38 void DMAdapterTest::SetUp(void)
39 {
40 }
41 
TearDown(void)42 void DMAdapterTest::TearDown(void)
43 {
44 }
45 
46 /**
47 * @tc.name: GetLocalDeviceUdid
48 * @tc.desc: Get the local device udid.
49 * @tc.type: FUNC
50 * @tc.require:
51 * @tc.author:
52 */
53 HWTEST_F(DMAdapterTest, GetLocalDeviceUdid, TestSize.Level0)
54 {
55     std::string bundleName = "com.example.myapplication";
56     bool res = DMAdapter::GetInstance().Initialize(bundleName);
57     ASSERT_FALSE(res);
58     std::string device = "deviceTestName";
59     auto fromDevice = DMAdapter::GetInstance().GetDeviceName(device);
60     ASSERT_FALSE(fromDevice.empty());
61     auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
62     ASSERT_TRUE(udid.empty());
63 }
64 
65 /**
66 * @tc.name: GetLocalNetworkId
67 * @tc.desc: Get the local network id.
68 * @tc.type: FUNC
69 * @tc.require:
70 * @tc.author:
71 */
72 HWTEST_F(DMAdapterTest, GetLocalNetworkId, TestSize.Level0)
73 {
74     std::string bundleName = "com.example.myapplication";
75     bool res = DMAdapter::GetInstance().Initialize(bundleName);
76     ASSERT_FALSE(res);
77     auto networkId = DMAdapter::GetInstance().GetLocalNetworkId();
78     ASSERT_FALSE(networkId.empty());
79 }
80 
81 /**
82 * @tc.name: DistributedClipRegister
83 * @tc.desc: DistributedClip Register and Unregister.
84 * @tc.type: FUNC
85 * @tc.require:
86 * @tc.author:
87 */
88 HWTEST_F(DMAdapterTest, DistributedClipRegister, TestSize.Level0)
89 {
90     DistributedClip *observer = new DistributedClip();
91     DMAdapter::GetInstance().Register(observer);
92     DMAdapter::GetInstance().Unregister(observer);
93     ASSERT_TRUE(true);
94 }
95 
96 /**
97 * @tc.name: GetRemoteDeviceInfo
98 * @tc.desc: Get the remote device info.
99 * @tc.type: FUNC
100 * @tc.require:
101 * @tc.author:
102 */
103 HWTEST_F(DMAdapterTest, GetRemoteDeviceInfo, TestSize.Level0)
104 {
105 #ifdef PB_DEVICE_MANAGER_ENABLE
106     DmDeviceInfo remoteDevice;
107     auto ret = DMAdapter::GetInstance().GetRemoteDeviceInfo("", remoteDevice);
108     ASSERT_TRUE(ret == -1);
109 #else
110     ASSERT_TRUE(true);
111 #endif
112 }
113 
114 /**
115 * @tc.name: GetUdidByNetworkId
116 * @tc.desc: Get Udid By NetworkId.
117 * @tc.type: FUNC
118 * @tc.require:
119 * @tc.author:
120 */
121 HWTEST_F(DMAdapterTest, GetUdidByNetworkId, TestSize.Level0)
122 {
123     auto udid = DMAdapter::GetInstance().GetUdidByNetworkId("");
124     ASSERT_TRUE(udid.empty());
125 }
126 }
127