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