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