1bc03f14fSopenharmony_ci/*
2bc03f14fSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License.
5bc03f14fSopenharmony_ci * You may obtain a copy of the License at
6bc03f14fSopenharmony_ci *
7bc03f14fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc03f14fSopenharmony_ci *
9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc03f14fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and
13bc03f14fSopenharmony_ci * limitations under the License.
14bc03f14fSopenharmony_ci */
15bc03f14fSopenharmony_ci
16bc03f14fSopenharmony_ci#include <gtest/gtest.h>
17bc03f14fSopenharmony_ci
18bc03f14fSopenharmony_ci#include "device/dm_adapter.h"
19bc03f14fSopenharmony_ci#include "distributed_clip.h"
20bc03f14fSopenharmony_ci#include "pasteboard_error.h"
21bc03f14fSopenharmony_ci
22bc03f14fSopenharmony_cinamespace OHOS::MiscServices {
23bc03f14fSopenharmony_ciusing namespace testing::ext;
24bc03f14fSopenharmony_ciclass DMAdapterTest : public testing::Test {
25bc03f14fSopenharmony_cipublic:
26bc03f14fSopenharmony_ci    static void SetUpTestCase(void);
27bc03f14fSopenharmony_ci    static void TearDownTestCase(void);
28bc03f14fSopenharmony_ci    void SetUp();
29bc03f14fSopenharmony_ci    void TearDown();
30bc03f14fSopenharmony_ci};
31bc03f14fSopenharmony_ci
32bc03f14fSopenharmony_civoid DMAdapterTest::SetUpTestCase(void) {}
33bc03f14fSopenharmony_ci
34bc03f14fSopenharmony_civoid DMAdapterTest::TearDownTestCase(void) {}
35bc03f14fSopenharmony_ci
36bc03f14fSopenharmony_civoid DMAdapterTest::SetUp(void) {}
37bc03f14fSopenharmony_ci
38bc03f14fSopenharmony_civoid DMAdapterTest::TearDown(void) {}
39bc03f14fSopenharmony_ci
40bc03f14fSopenharmony_ci/**
41bc03f14fSopenharmony_ci* @tc.name: GetLocalDeviceUdid
42bc03f14fSopenharmony_ci* @tc.desc: Get the local device udid.
43bc03f14fSopenharmony_ci* @tc.type: FUNC
44bc03f14fSopenharmony_ci* @tc.require:
45bc03f14fSopenharmony_ci* @tc.author:
46bc03f14fSopenharmony_ci*/
47bc03f14fSopenharmony_ciHWTEST_F(DMAdapterTest, GetLocalDeviceUdid, TestSize.Level0)
48bc03f14fSopenharmony_ci{
49bc03f14fSopenharmony_ci    std::string bundleName = "com.example.myapplication";
50bc03f14fSopenharmony_ci    bool res = DMAdapter::GetInstance().Initialize(bundleName);
51bc03f14fSopenharmony_ci    ASSERT_FALSE(res);
52bc03f14fSopenharmony_ci    std::string device = "deviceTestName";
53bc03f14fSopenharmony_ci    auto fromDevice = DMAdapter::GetInstance().GetDeviceName(device);
54bc03f14fSopenharmony_ci    ASSERT_FALSE(fromDevice.empty());
55bc03f14fSopenharmony_ci    auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
56bc03f14fSopenharmony_ci    ASSERT_FALSE(udid.empty());
57bc03f14fSopenharmony_ci}
58bc03f14fSopenharmony_ci
59bc03f14fSopenharmony_ci/**
60bc03f14fSopenharmony_ci* @tc.name: GetLocalNetworkId
61bc03f14fSopenharmony_ci* @tc.desc: Get the local network id.
62bc03f14fSopenharmony_ci* @tc.type: FUNC
63bc03f14fSopenharmony_ci* @tc.require:
64bc03f14fSopenharmony_ci* @tc.author:
65bc03f14fSopenharmony_ci*/
66bc03f14fSopenharmony_ciHWTEST_F(DMAdapterTest, GetLocalNetworkId, TestSize.Level0)
67bc03f14fSopenharmony_ci{
68bc03f14fSopenharmony_ci    std::string bundleName = "com.example.myapplication";
69bc03f14fSopenharmony_ci    bool res = DMAdapter::GetInstance().Initialize(bundleName);
70bc03f14fSopenharmony_ci    ASSERT_FALSE(res);
71bc03f14fSopenharmony_ci    auto networkId = DMAdapter::GetInstance().GetLocalNetworkId();
72bc03f14fSopenharmony_ci    ASSERT_FALSE(networkId.empty());
73bc03f14fSopenharmony_ci}
74bc03f14fSopenharmony_ci
75bc03f14fSopenharmony_ci/**
76bc03f14fSopenharmony_ci* @tc.name: DistributedClipRegister
77bc03f14fSopenharmony_ci* @tc.desc: DistributedClip Register and Unregister.
78bc03f14fSopenharmony_ci* @tc.type: FUNC
79bc03f14fSopenharmony_ci* @tc.require:
80bc03f14fSopenharmony_ci* @tc.author:
81bc03f14fSopenharmony_ci*/
82bc03f14fSopenharmony_ciHWTEST_F(DMAdapterTest, DistributedClipRegister, TestSize.Level0)
83bc03f14fSopenharmony_ci{
84bc03f14fSopenharmony_ci    DistributedClip *observer = new DistributedClip();
85bc03f14fSopenharmony_ci    DMAdapter::GetInstance().Register(observer);
86bc03f14fSopenharmony_ci    DMAdapter::GetInstance().Unregister(observer);
87bc03f14fSopenharmony_ci    ASSERT_TRUE(true);
88bc03f14fSopenharmony_ci}
89bc03f14fSopenharmony_ci
90bc03f14fSopenharmony_ci/**
91bc03f14fSopenharmony_ci* @tc.name: GetRemoteDeviceInfo
92bc03f14fSopenharmony_ci* @tc.desc: Get the remote device info.
93bc03f14fSopenharmony_ci* @tc.type: FUNC
94bc03f14fSopenharmony_ci* @tc.require:
95bc03f14fSopenharmony_ci* @tc.author:
96bc03f14fSopenharmony_ci*/
97bc03f14fSopenharmony_ciHWTEST_F(DMAdapterTest, GetRemoteDeviceInfo, TestSize.Level0)
98bc03f14fSopenharmony_ci{
99bc03f14fSopenharmony_ci#ifdef PB_DEVICE_MANAGER_ENABLE
100bc03f14fSopenharmony_ci    DmDeviceInfo remoteDevice;
101bc03f14fSopenharmony_ci    auto ret = DMAdapter::GetInstance().GetRemoteDeviceInfo("", remoteDevice);
102bc03f14fSopenharmony_ci    ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::NO_TRUST_DEVICE_ERROR));
103bc03f14fSopenharmony_ci#else
104bc03f14fSopenharmony_ci    ASSERT_TRUE(true);
105bc03f14fSopenharmony_ci#endif
106bc03f14fSopenharmony_ci}
107bc03f14fSopenharmony_ci
108bc03f14fSopenharmony_ci/**
109bc03f14fSopenharmony_ci* @tc.name: GetUdidByNetworkId
110bc03f14fSopenharmony_ci* @tc.desc: Get Udid By NetworkId.
111bc03f14fSopenharmony_ci* @tc.type: FUNC
112bc03f14fSopenharmony_ci* @tc.require:
113bc03f14fSopenharmony_ci* @tc.author:
114bc03f14fSopenharmony_ci*/
115bc03f14fSopenharmony_ciHWTEST_F(DMAdapterTest, GetUdidByNetworkId, TestSize.Level0)
116bc03f14fSopenharmony_ci{
117bc03f14fSopenharmony_ci    auto udid = DMAdapter::GetInstance().GetUdidByNetworkId("");
118bc03f14fSopenharmony_ci    ASSERT_TRUE(udid.empty());
119bc03f14fSopenharmony_ci}
120bc03f14fSopenharmony_ci
121bc03f14fSopenharmony_ci/**
122bc03f14fSopenharmony_ci* @tc.name: IsSameAccount
123bc03f14fSopenharmony_ci* @tc.desc: is same account.
124bc03f14fSopenharmony_ci* @tc.type: FUNC
125bc03f14fSopenharmony_ci* @tc.require:
126bc03f14fSopenharmony_ci* @tc.author:
127bc03f14fSopenharmony_ci*/
128bc03f14fSopenharmony_ciHWTEST_F(DMAdapterTest, IsSameAccount, TestSize.Level0)
129bc03f14fSopenharmony_ci{
130bc03f14fSopenharmony_ci    std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
131bc03f14fSopenharmony_ci    bool ret = DMAdapter::GetInstance().IsSameAccount(networkId);
132bc03f14fSopenharmony_ci    ASSERT_FALSE(ret);
133bc03f14fSopenharmony_ci}
134bc03f14fSopenharmony_ci} // namespace OHOS::MiscServices
135