/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "UTTest_dm_device_state_manager.h" #include #include "dm_log.h" #include "dm_constants.h" #include "dm_adapter_manager.h" #include "ipc_notify_device_state_req.h" #include "ipc_notify_auth_result_req.h" #include "ipc_notify_verify_auth_result_req.h" #include "dm_device_state_manager.h" #include "ipc_notify_device_found_req.h" #include "ipc_notify_discover_result_req.h" #include "hichain_connector.h" #include "device_manager_service_listener.h" namespace OHOS { namespace DistributedHardware { void DmDeviceStateManagerTest::SetUp() { } void DmDeviceStateManagerTest::TearDown() { } void DmDeviceStateManagerTest::SetUpTestCase() { } void DmDeviceStateManagerTest::TearDownTestCase() { } namespace { std::shared_ptr hiChainConnector_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); std::shared_ptr dmDeviceStateManager = std::make_shared(softbusConnector, listener_, hiChainConnector_); /** * @tc.name: DmDeviceStateManager_001 * @tc.desc: set DmDeviceStateManager to tne new pointer, and it's not nullptr * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, DmDeviceStateManager_001, testing::ext::TestSize.Level0) { std::shared_ptr p = std::make_shared(softbusConnector, listener_, hiChainConnector_); ASSERT_NE(p, nullptr); } /** * @tc.name: DmDeviceStateManager_002 * @tc.desc: set DmDeviceStateManager to tne new pointer,it's not nullptr and delete it * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, DmDeviceStateManager_002, testing::ext::TestSize.Level0) { std::shared_ptr p = std::make_shared(softbusConnector, listener_, hiChainConnector_); p.reset(); EXPECT_EQ(p, nullptr); } /** * @tc.name: OnDeviceOnline_001 * @tc.desc: set info.deviceId to some para, and return it * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, OnDeviceOnline_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; DmDeviceInfo info; strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); dmDeviceStateManager->OnDeviceOnline(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo dminfo; if (pReq == nullptr) { strcpy_s(dminfo.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); } else { dminfo = pReq->GetDeviceInfo(); } int result = strcmp(info.deviceId, dminfo.deviceId); EXPECT_EQ(result, 0); } /** * @tc.name: OnDeviceChanged_001 * @tc.desc: set info.deviceId to some para, and return it * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, OnDeviceChanged_001, testing::ext::TestSize.Level0) { std::string pkgName = "111"; DmDeviceInfo info; strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); dmDeviceStateManager->OnDeviceChanged(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo dminfo; if (pReq == nullptr) { strcpy_s(dminfo.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); } else { dminfo = pReq->GetDeviceInfo(); } int result = strcmp(info.deviceId, dminfo.deviceId); EXPECT_EQ(result, 0); } /** * @tc.name: OnDeviceReady_001 * @tc.desc: set info.deviceId to some para, and return it * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, OnDbReady_001, testing::ext::TestSize.Level0) { std::string pkgName; std::string deviceId; DmDeviceInfo info; strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); dmDeviceStateManager->OnDbReady(pkgName, deviceId); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo dminfo; if (pReq == nullptr) { strcpy_s(dminfo.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); } else { dminfo = pReq->GetDeviceInfo(); } int result = strcmp(info.deviceId, dminfo.deviceId); EXPECT_EQ(result, 0); } /** * @tc.name: OnDeviceReady_001 * @tc.desc: set info.deviceId to 123, and call OnDeviceReady ,change info.deviceId to 4 * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, OnDeviceReady_001, testing::ext::TestSize.Level0) { std::string pkgName; DmDeviceInfo info; strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); dmDeviceStateManager->OnDeviceReady(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo dminfo; if (pReq == nullptr) { strcpy_s(dminfo.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); } else { dminfo = pReq->GetDeviceInfo(); } int result = strcmp(info.deviceId, dminfo.deviceId); EXPECT_EQ(result, 0); } /** * @tc.name: OnDeviceChanged_002 * @tc.desc: set info.deviceId to 123, and call OnDeviceChanged ,change info.deviceId to 4 * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, OnDeviceChanged_002, testing::ext::TestSize.Level0) { std::string pkgName; DmDeviceInfo info; strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); dmDeviceStateManager->OnDeviceChanged(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo dminfo; if (pReq == nullptr) { strcpy_s(dminfo.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); } else { dminfo = pReq->GetDeviceInfo(); } int result = strcmp(info.deviceId, dminfo.deviceId); EXPECT_EQ(result, 0); } /** * @tc.name: RegisterSoftbusStateCallback_001 * @tc.desc: call RegisterSoftbusStateCallback and return DM_OK * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, RegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0) { int ret = dmDeviceStateManager->RegisterSoftbusStateCallback(); EXPECT_EQ(ret, DM_OK); } /** * @tc.name: PostDeviceOnline_001 * @tc.desc: call PostDeviceOnline * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, PostDeviceOnline_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; DmDeviceInfo info = { .deviceId = "123", .deviceName = "asda", .deviceTypeId = 1, }; dmDeviceStateManager->PostDeviceOnline(pkgName, info); } /** * @tc.name: PostDeviceOffline_001 * @tc.desc: call PostDeviceOffline * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, PostDeviceOffline_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; DmDeviceInfo info = { .deviceId = "123", .deviceName = "asda", .deviceTypeId = 1, }; dmDeviceStateManager->PostDeviceOffline(pkgName, info); } /** * @tc.name: RegisterDevStateCallback_001 * @tc.desc: call RegisterDevStateCallback * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, RegisterDevStateCallback_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; std::string extra = "ahaha"; dmDeviceStateManager->RegisterDevStateCallback(pkgName, extra); } /** * @tc.name: UnRegisterDevStateCallback_001 * @tc.desc: call UnRegisterDevStateCallback * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, UnRegisterDevStateCallback_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; std::string extra; dmDeviceStateManager->UnRegisterDevStateCallback(pkgName, extra); } /** * @tc.name: RegisterOffLineTimer_001 * @tc.desc: call RegisterOffLineTimer * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DmDeviceStateManagerTest, RegisterOffLineTimer_001, testing::ext::TestSize.Level0) { DmDeviceInfo info = { .deviceId = "123", .deviceName = "asda", .deviceTypeId = 1, }; dmDeviceStateManager->RegisterOffLineTimer(info); } /** * @tc.name: SaveOnlineDeviceInfo_001 * @tc.desc: call SaveOnlineDeviceInfo * @tc.type: FUNC */ HWTEST_F(DmDeviceStateManagerTest, SaveOnlineDeviceInfo_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; DmDeviceInfo info = { .deviceId = "123", .deviceName = "asda", .deviceTypeId = 1, }; dmDeviceStateManager->SaveOnlineDeviceInfo(pkgName, info); } /** * @tc.name: DeleteOfflineDeviceInfo_001 * @tc.desc: call DeleteOfflineDeviceInfo * @tc.type: FUNC */ HWTEST_F(DmDeviceStateManagerTest, DeleteOfflineDeviceInfo_001, testing::ext::TestSize.Level0) { std::string pkgName = "123"; DmDeviceInfo info = { .deviceId = "123", .deviceName = "asda", .deviceTypeId = 1, }; dmDeviceStateManager->DeleteOfflineDeviceInfo(pkgName, info); } } // namespace } // namespace DistributedHardware } // namespace OHOS