179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#include "device_manager_linux_test.h" 1779a732c7Sopenharmony_ci 1879a732c7Sopenharmony_ci#include <unistd.h> 1979a732c7Sopenharmony_ci 2079a732c7Sopenharmony_ci#include "dm_constants.h" 2179a732c7Sopenharmony_ci#include "dm_device_info.h" 2279a732c7Sopenharmony_ci 2379a732c7Sopenharmony_cinamespace OHOS { 2479a732c7Sopenharmony_cinamespace DistributedHardware { 2579a732c7Sopenharmony_civoid DeviceManagerImplTest::SetUp() 2679a732c7Sopenharmony_ci{ 2779a732c7Sopenharmony_ci} 2879a732c7Sopenharmony_ci 2979a732c7Sopenharmony_civoid DeviceManagerImplTest::TearDown() 3079a732c7Sopenharmony_ci{ 3179a732c7Sopenharmony_ci} 3279a732c7Sopenharmony_ci 3379a732c7Sopenharmony_civoid DeviceManagerImplTest::SetUpTestCase() 3479a732c7Sopenharmony_ci{ 3579a732c7Sopenharmony_ci} 3679a732c7Sopenharmony_ci 3779a732c7Sopenharmony_civoid DeviceManagerImplTest::TearDownTestCase() 3879a732c7Sopenharmony_ci{ 3979a732c7Sopenharmony_ci} 4079a732c7Sopenharmony_ci 4179a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, InitDeviceManager001, testing::ext::TestSize.Level0) 4279a732c7Sopenharmony_ci{ 4379a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 4479a732c7Sopenharmony_ci std::shared_ptr<DmInitCallbackTest> callback = std::make_shared<DmInitCallbackTest>(); 4579a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); 4679a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 4779a732c7Sopenharmony_ci} 4879a732c7Sopenharmony_ci 4979a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback001, testing::ext::TestSize.Level0) 5079a732c7Sopenharmony_ci{ 5179a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 5279a732c7Sopenharmony_ci std::string extra = ""; 5379a732c7Sopenharmony_ci std::shared_ptr<DmDeviceStateCallbackTest> callback = std::make_shared<DmDeviceStateCallbackTest>(); 5479a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra, callback); 5579a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 5679a732c7Sopenharmony_ci} 5779a732c7Sopenharmony_ci 5879a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery001, testing::ext::TestSize.Level0) 5979a732c7Sopenharmony_ci{ 6079a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 6179a732c7Sopenharmony_ci std::string extra = "{\"findDeviceMode\":1}"; 6279a732c7Sopenharmony_ci uint64_t subscribeId = 1000; 6379a732c7Sopenharmony_ci std::shared_ptr<DiscoveryCallbackTest> callback = std::make_shared<DiscoveryCallbackTest>(); 6479a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeId, extra, callback); 6579a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 6679a732c7Sopenharmony_ci} 6779a732c7Sopenharmony_ci 6879a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery001, testing::ext::TestSize.Level0) 6979a732c7Sopenharmony_ci{ 7079a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 7179a732c7Sopenharmony_ci uint64_t subscribeId = 1000; 7279a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(subscribeId, packName); 7379a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 7479a732c7Sopenharmony_ci} 7579a732c7Sopenharmony_ci 7679a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetTrustDeviceList001, testing::ext::TestSize.Level0) 7779a732c7Sopenharmony_ci{ 7879a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 7979a732c7Sopenharmony_ci std::string extra = ""; 8079a732c7Sopenharmony_ci std::vector<DmDeviceInfo> deviceList; 8179a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList); 8279a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 8379a732c7Sopenharmony_ci} 8479a732c7Sopenharmony_ci 8579a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, RequestCredential001, testing::ext::TestSize.Level0) 8679a732c7Sopenharmony_ci{ 8779a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 8879a732c7Sopenharmony_ci std::string returnJsonStr; 8979a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().RequestCredential(packName, returnJsonStr); 9079a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 9179a732c7Sopenharmony_ci} 9279a732c7Sopenharmony_ci 9379a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, CheckCredential001, testing::ext::TestSize.Level0) 9479a732c7Sopenharmony_ci{ 9579a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 9679a732c7Sopenharmony_ci std::string reqJsonStr = R"({})"; 9779a732c7Sopenharmony_ci std::string returnJsonStr; 9879a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().CheckCredential(packName, reqJsonStr, returnJsonStr); 9979a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 10079a732c7Sopenharmony_ci} 10179a732c7Sopenharmony_ci 10279a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, ImportCredential001, testing::ext::TestSize.Level0) 10379a732c7Sopenharmony_ci{ 10479a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 10579a732c7Sopenharmony_ci std::string reqJsonStr = R"( 10679a732c7Sopenharmony_ci { 10779a732c7Sopenharmony_ci "processType": 1, 10879a732c7Sopenharmony_ci "authType": 1, 10979a732c7Sopenharmony_ci "userId": "123", 11079a732c7Sopenharmony_ci "credentialData": 11179a732c7Sopenharmony_ci [ 11279a732c7Sopenharmony_ci { 11379a732c7Sopenharmony_ci "credentialType": 1, 11479a732c7Sopenharmony_ci "credentialId": "104", 11579a732c7Sopenharmony_ci "authCode": "10F9F0576E61730193D2052B7F771887124A68F1607EFCF7796C1491F834CD92", 11679a732c7Sopenharmony_ci "serverPk": "", 11779a732c7Sopenharmony_ci "pkInfoSignature": "", 11879a732c7Sopenharmony_ci "pkInfo": "", 11979a732c7Sopenharmony_ci "peerDeviceId": "" 12079a732c7Sopenharmony_ci } 12179a732c7Sopenharmony_ci ] 12279a732c7Sopenharmony_ci } 12379a732c7Sopenharmony_ci )"; 12479a732c7Sopenharmony_ci std::string returnJsonStr; 12579a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().ImportCredential(packName, reqJsonStr, returnJsonStr); 12679a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 12779a732c7Sopenharmony_ci} 12879a732c7Sopenharmony_ci 12979a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, DeleteCredential001, testing::ext::TestSize.Level0) 13079a732c7Sopenharmony_ci{ 13179a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 13279a732c7Sopenharmony_ci std::string reqJsonStr = R"({"isDeleteAll:true"})"; 13379a732c7Sopenharmony_ci std::string returnJsonStr; 13479a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().DeleteCredential(packName, reqJsonStr, returnJsonStr); 13579a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 13679a732c7Sopenharmony_ci} 13779a732c7Sopenharmony_ci 13879a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetAvailableDeviceList001, testing::ext::TestSize.Level0) 13979a732c7Sopenharmony_ci{ 14079a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 14179a732c7Sopenharmony_ci std::vector<DmDeviceBasicInfo> deviceList; 14279a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetAvailableDeviceList(packName, deviceList); 14379a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 14479a732c7Sopenharmony_ci} 14579a732c7Sopenharmony_ci 14679a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetLocalDeviceNetWorkId001, testing::ext::TestSize.Level0) 14779a732c7Sopenharmony_ci{ 14879a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 14979a732c7Sopenharmony_ci std::string networkId; 15079a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetLocalDeviceNetWorkId(packName, networkId); 15179a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 15279a732c7Sopenharmony_ci} 15379a732c7Sopenharmony_ci 15479a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetLocalDeviceId001, testing::ext::TestSize.Level0) 15579a732c7Sopenharmony_ci{ 15679a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 15779a732c7Sopenharmony_ci std::string deviceId; 15879a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetLocalDeviceId(packName, deviceId); 15979a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 16079a732c7Sopenharmony_ci} 16179a732c7Sopenharmony_ci 16279a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetLocalDeviceName001, testing::ext::TestSize.Level0) 16379a732c7Sopenharmony_ci{ 16479a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 16579a732c7Sopenharmony_ci std::string deviceName; 16679a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetLocalDeviceName(packName, deviceName); 16779a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 16879a732c7Sopenharmony_ci} 16979a732c7Sopenharmony_ci 17079a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetLocalDeviceType001, testing::ext::TestSize.Level0) 17179a732c7Sopenharmony_ci{ 17279a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 17379a732c7Sopenharmony_ci int32_t deviceType; 17479a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetLocalDeviceType(packName, deviceType); 17579a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 17679a732c7Sopenharmony_ci} 17779a732c7Sopenharmony_ci 17879a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetDeviceName001, testing::ext::TestSize.Level0) 17979a732c7Sopenharmony_ci{ 18079a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 18179a732c7Sopenharmony_ci std::string deviceName; 18279a732c7Sopenharmony_ci std::string networkId = "109008080809"; 18379a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetDeviceName(packName, networkId, deviceName); 18479a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 18579a732c7Sopenharmony_ci} 18679a732c7Sopenharmony_ci 18779a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, GetDeviceType001, testing::ext::TestSize.Level0) 18879a732c7Sopenharmony_ci{ 18979a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 19079a732c7Sopenharmony_ci int32_t deviceType; 19179a732c7Sopenharmony_ci std::string networkId = "109008080809"; 19279a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().GetDeviceType(packName, networkId, deviceType); 19379a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 19479a732c7Sopenharmony_ci} 19579a732c7Sopenharmony_ci 19679a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback001, testing::ext::TestSize.Level0) 19779a732c7Sopenharmony_ci{ 19879a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 19979a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().UnRegisterDevStatusCallback(packName); 20079a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 20179a732c7Sopenharmony_ci} 20279a732c7Sopenharmony_ci 20379a732c7Sopenharmony_ciHWTEST_F(DeviceManagerImplTest, UnInitDeviceManager001, testing::ext::TestSize.Level0) 20479a732c7Sopenharmony_ci{ 20579a732c7Sopenharmony_ci std::string packName = "com.ohos.helloworld"; 20679a732c7Sopenharmony_ci int32_t ret = DeviceManager::GetInstance().UnInitDeviceManager(packName); 20779a732c7Sopenharmony_ci EXPECT_EQ(ret, DM_OK); 20879a732c7Sopenharmony_ci} 20979a732c7Sopenharmony_ci} // namespace DistributedHardware 21079a732c7Sopenharmony_ci} // namespace OHOS 211