1/*
2 * Copyright (c) 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_manager_linux_test.h"
17
18#include <unistd.h>
19
20#include "dm_constants.h"
21#include "dm_device_info.h"
22
23namespace OHOS {
24namespace DistributedHardware {
25void DeviceManagerImplTest::SetUp()
26{
27}
28
29void DeviceManagerImplTest::TearDown()
30{
31}
32
33void DeviceManagerImplTest::SetUpTestCase()
34{
35}
36
37void DeviceManagerImplTest::TearDownTestCase()
38{
39}
40
41HWTEST_F(DeviceManagerImplTest, InitDeviceManager001, testing::ext::TestSize.Level0)
42{
43    std::string packName = "com.ohos.helloworld";
44    std::shared_ptr<DmInitCallbackTest> callback = std::make_shared<DmInitCallbackTest>();
45    int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback);
46    EXPECT_EQ(ret, DM_OK);
47}
48
49HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback001, testing::ext::TestSize.Level0)
50{
51    std::string packName = "com.ohos.helloworld";
52    std::string extra = "";
53    std::shared_ptr<DmDeviceStateCallbackTest> callback = std::make_shared<DmDeviceStateCallbackTest>();
54    int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra, callback);
55    EXPECT_EQ(ret, DM_OK);
56}
57
58HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery001, testing::ext::TestSize.Level0)
59{
60    std::string packName = "com.ohos.helloworld";
61    std::string extra = "{\"findDeviceMode\":1}";
62    uint64_t subscribeId = 1000;
63    std::shared_ptr<DiscoveryCallbackTest> callback = std::make_shared<DiscoveryCallbackTest>();
64    int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeId, extra, callback);
65    EXPECT_EQ(ret, DM_OK);
66}
67
68HWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery001, testing::ext::TestSize.Level0)
69{
70    std::string packName = "com.ohos.helloworld";
71    uint64_t subscribeId = 1000;
72    int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(subscribeId, packName);
73    EXPECT_EQ(ret, DM_OK);
74}
75
76HWTEST_F(DeviceManagerImplTest, GetTrustDeviceList001, testing::ext::TestSize.Level0)
77{
78    std::string packName = "com.ohos.helloworld";
79    std::string extra = "";
80    std::vector<DmDeviceInfo> deviceList;
81    int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList);
82    EXPECT_EQ(ret, DM_OK);
83}
84
85HWTEST_F(DeviceManagerImplTest, RequestCredential001, testing::ext::TestSize.Level0)
86{
87    std::string packName = "com.ohos.helloworld";
88    std::string returnJsonStr;
89    int32_t ret = DeviceManager::GetInstance().RequestCredential(packName, returnJsonStr);
90    EXPECT_EQ(ret, DM_OK);
91}
92
93HWTEST_F(DeviceManagerImplTest, CheckCredential001, testing::ext::TestSize.Level0)
94{
95    std::string packName = "com.ohos.helloworld";
96    std::string reqJsonStr = R"({})";
97    std::string returnJsonStr;
98    int32_t ret = DeviceManager::GetInstance().CheckCredential(packName, reqJsonStr, returnJsonStr);
99    EXPECT_EQ(ret, DM_OK);
100}
101
102HWTEST_F(DeviceManagerImplTest, ImportCredential001, testing::ext::TestSize.Level0)
103{
104    std::string packName = "com.ohos.helloworld";
105    std::string reqJsonStr = R"(
106    {
107        "processType": 1,
108        "authType": 1,
109        "userId": "123",
110        "credentialData":
111        [
112            {
113                "credentialType": 1,
114                "credentialId": "104",
115                "authCode": "10F9F0576E61730193D2052B7F771887124A68F1607EFCF7796C1491F834CD92",
116                "serverPk": "",
117                "pkInfoSignature": "",
118                "pkInfo": "",
119                "peerDeviceId": ""
120            }
121        ]
122    }
123    )";
124    std::string returnJsonStr;
125    int32_t ret = DeviceManager::GetInstance().ImportCredential(packName, reqJsonStr, returnJsonStr);
126    EXPECT_EQ(ret, DM_OK);
127}
128
129HWTEST_F(DeviceManagerImplTest, DeleteCredential001, testing::ext::TestSize.Level0)
130{
131    std::string packName = "com.ohos.helloworld";
132    std::string reqJsonStr = R"({"isDeleteAll:true"})";
133    std::string returnJsonStr;
134    int32_t ret = DeviceManager::GetInstance().DeleteCredential(packName, reqJsonStr, returnJsonStr);
135    EXPECT_EQ(ret, DM_OK);
136}
137
138HWTEST_F(DeviceManagerImplTest, GetAvailableDeviceList001, testing::ext::TestSize.Level0)
139{
140    std::string packName = "com.ohos.helloworld";
141    std::vector<DmDeviceBasicInfo> deviceList;
142    int32_t ret = DeviceManager::GetInstance().GetAvailableDeviceList(packName, deviceList);
143    EXPECT_EQ(ret, DM_OK);
144}
145
146HWTEST_F(DeviceManagerImplTest, GetLocalDeviceNetWorkId001, testing::ext::TestSize.Level0)
147{
148    std::string packName = "com.ohos.helloworld";
149    std::string networkId;
150    int32_t ret = DeviceManager::GetInstance().GetLocalDeviceNetWorkId(packName, networkId);
151    EXPECT_EQ(ret, DM_OK);
152}
153
154HWTEST_F(DeviceManagerImplTest, GetLocalDeviceId001, testing::ext::TestSize.Level0)
155{
156    std::string packName = "com.ohos.helloworld";
157    std::string deviceId;
158    int32_t ret = DeviceManager::GetInstance().GetLocalDeviceId(packName, deviceId);
159    EXPECT_EQ(ret, DM_OK);
160}
161
162HWTEST_F(DeviceManagerImplTest, GetLocalDeviceName001, testing::ext::TestSize.Level0)
163{
164    std::string packName = "com.ohos.helloworld";
165    std::string deviceName;
166    int32_t ret = DeviceManager::GetInstance().GetLocalDeviceName(packName, deviceName);
167    EXPECT_EQ(ret, DM_OK);
168}
169
170HWTEST_F(DeviceManagerImplTest, GetLocalDeviceType001, testing::ext::TestSize.Level0)
171{
172    std::string packName = "com.ohos.helloworld";
173    int32_t deviceType;
174    int32_t ret = DeviceManager::GetInstance().GetLocalDeviceType(packName, deviceType);
175    EXPECT_EQ(ret, DM_OK);
176}
177
178HWTEST_F(DeviceManagerImplTest, GetDeviceName001, testing::ext::TestSize.Level0)
179{
180    std::string packName = "com.ohos.helloworld";
181    std::string deviceName;
182    std::string networkId = "109008080809";
183    int32_t ret = DeviceManager::GetInstance().GetDeviceName(packName, networkId, deviceName);
184    EXPECT_EQ(ret, DM_OK);
185}
186
187HWTEST_F(DeviceManagerImplTest, GetDeviceType001, testing::ext::TestSize.Level0)
188{
189    std::string packName = "com.ohos.helloworld";
190    int32_t deviceType;
191    std::string networkId = "109008080809";
192    int32_t ret = DeviceManager::GetInstance().GetDeviceType(packName, networkId, deviceType);
193    EXPECT_EQ(ret, DM_OK);
194}
195
196HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback001, testing::ext::TestSize.Level0)
197{
198    std::string packName = "com.ohos.helloworld";
199    int32_t ret = DeviceManager::GetInstance().UnRegisterDevStatusCallback(packName);
200    EXPECT_EQ(ret, DM_OK);
201}
202
203HWTEST_F(DeviceManagerImplTest, UnInitDeviceManager001, testing::ext::TestSize.Level0)
204{
205    std::string packName = "com.ohos.helloworld";
206    int32_t ret = DeviceManager::GetInstance().UnInitDeviceManager(packName);
207    EXPECT_EQ(ret, DM_OK);
208}
209} // namespace DistributedHardware
210} // namespace OHOS
211