179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2022-2024 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 "UTTest_ipc_server_stub.h" 1779a732c7Sopenharmony_ci 1879a732c7Sopenharmony_ci#include <algorithm> 1979a732c7Sopenharmony_ci#include <thread> 2079a732c7Sopenharmony_ci#include <unistd.h> 2179a732c7Sopenharmony_ci 2279a732c7Sopenharmony_ci#include "device_manager_ipc_interface_code.h" 2379a732c7Sopenharmony_ci#include "device_manager_service.h" 2479a732c7Sopenharmony_ci#include "dm_device_info.h" 2579a732c7Sopenharmony_ci#include "ipc_remote_broker.h" 2679a732c7Sopenharmony_ci#include "ipc_server_stub.h" 2779a732c7Sopenharmony_ci#include "device_manager_impl.h" 2879a732c7Sopenharmony_ci#include "dm_constants.h" 2979a732c7Sopenharmony_ci#include "if_system_ability_manager.h" 3079a732c7Sopenharmony_ci#include "ipc_cmd_register.h" 3179a732c7Sopenharmony_ci#include "ipc_skeleton.h" 3279a732c7Sopenharmony_ci#include "ipc_types.h" 3379a732c7Sopenharmony_ci#include "iservice_registry.h" 3479a732c7Sopenharmony_ci#include "string_ex.h" 3579a732c7Sopenharmony_ci#include "system_ability_definition.h" 3679a732c7Sopenharmony_ci 3779a732c7Sopenharmony_cinamespace OHOS { 3879a732c7Sopenharmony_cinamespace DistributedHardware { 3979a732c7Sopenharmony_civoid IpcServerStubTest::SetUp() 4079a732c7Sopenharmony_ci{ 4179a732c7Sopenharmony_ci} 4279a732c7Sopenharmony_ci 4379a732c7Sopenharmony_civoid IpcServerStubTest::TearDown() 4479a732c7Sopenharmony_ci{ 4579a732c7Sopenharmony_ci} 4679a732c7Sopenharmony_ci 4779a732c7Sopenharmony_civoid IpcServerStubTest::SetUpTestCase() 4879a732c7Sopenharmony_ci{ 4979a732c7Sopenharmony_ci} 5079a732c7Sopenharmony_ci 5179a732c7Sopenharmony_civoid IpcServerStubTest::TearDownTestCase() 5279a732c7Sopenharmony_ci{ 5379a732c7Sopenharmony_ci} 5479a732c7Sopenharmony_ci 5579a732c7Sopenharmony_cinamespace { 5679a732c7Sopenharmony_ci/** 5779a732c7Sopenharmony_ci * @tc.name: OnStop_001 5879a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub OnStop 5979a732c7Sopenharmony_ci * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 6079a732c7Sopenharmony_ci * @tc.type: FUNC 6179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 6279a732c7Sopenharmony_ci */ 6379a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnStop_001, testing::ext::TestSize.Level0) 6479a732c7Sopenharmony_ci{ 6579a732c7Sopenharmony_ci // 1. Call IpcServerStub OnStop 6679a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnStop(); 6779a732c7Sopenharmony_ci // 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 6879a732c7Sopenharmony_ci ASSERT_EQ(ServiceRunningState::STATE_NOT_START, IpcServerStub::GetInstance().state_); 6979a732c7Sopenharmony_ci ASSERT_EQ(IpcServerStub::GetInstance().registerToService_, false); 7079a732c7Sopenharmony_ci} 7179a732c7Sopenharmony_ci 7279a732c7Sopenharmony_ci/** 7379a732c7Sopenharmony_ci * @tc.name: OnStart_001 7479a732c7Sopenharmony_ci * @tc.desc: 1. set IpcServerStub state is ServiceRunningState::STATE_RUNNING 7579a732c7Sopenharmony_ci * 2. Call IpcServerStub OnStart 7679a732c7Sopenharmony_ci * 3. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 7779a732c7Sopenharmony_ci * @tc.type: FUNC 7879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 7979a732c7Sopenharmony_ci */ 8079a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnStart_001, testing::ext::TestSize.Level0) 8179a732c7Sopenharmony_ci{ 8279a732c7Sopenharmony_ci // 1. set IpcServerStub state is ServiceRunningState::STATE_RUNNING 8379a732c7Sopenharmony_ci IpcServerStub::GetInstance().state_ = ServiceRunningState::STATE_RUNNING; 8479a732c7Sopenharmony_ci // 2. Call IpcServerStub OnStart 8579a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnStart(); 8679a732c7Sopenharmony_ci // 3. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 8779a732c7Sopenharmony_ci ASSERT_EQ(ServiceRunningState::STATE_RUNNING, IpcServerStub::GetInstance().state_); 8879a732c7Sopenharmony_ci} 8979a732c7Sopenharmony_ci 9079a732c7Sopenharmony_ci/** 9179a732c7Sopenharmony_ci * @tc.name: OnStart_002 9279a732c7Sopenharmony_ci * @tc.desc: 1. Set initial state to STATE_NOT_START 9379a732c7Sopenharmony_ci * 2. Call OnStart to start the service 9479a732c7Sopenharmony_ci * 3. Call OnStop to stop the service 9579a732c7Sopenharmony_ci * 4. Check the final state is STATE_NOT_START 9679a732c7Sopenharmony_ci * @tc.type: FUNC 9779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 9879a732c7Sopenharmony_ci */ 9979a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnStart_002, testing::ext::TestSize.Level0) 10079a732c7Sopenharmony_ci{ 10179a732c7Sopenharmony_ci IpcServerStub::GetInstance().state_ = ServiceRunningState::STATE_NOT_START; 10279a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnStart(); 10379a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnStop(); 10479a732c7Sopenharmony_ci ASSERT_EQ(ServiceRunningState::STATE_NOT_START, IpcServerStub::GetInstance().state_); 10579a732c7Sopenharmony_ci} 10679a732c7Sopenharmony_ci 10779a732c7Sopenharmony_ci/** 10879a732c7Sopenharmony_ci * @tc.name: Init_001 10979a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub OnStart 11079a732c7Sopenharmony_ci * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 11179a732c7Sopenharmony_ci * @tc.type: FUNC 11279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 11379a732c7Sopenharmony_ci */ 11479a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, Init_001, testing::ext::TestSize.Level0) 11579a732c7Sopenharmony_ci{ 11679a732c7Sopenharmony_ci IpcServerStub::GetInstance().registerToService_=true; 11779a732c7Sopenharmony_ci bool result = IpcServerStub::GetInstance().Init(); 11879a732c7Sopenharmony_ci // 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 11979a732c7Sopenharmony_ci ASSERT_EQ(result, true); 12079a732c7Sopenharmony_ci} 12179a732c7Sopenharmony_ci 12279a732c7Sopenharmony_ci/** 12379a732c7Sopenharmony_ci * @tc.name: OnRemoteRequest_001 12479a732c7Sopenharmony_ci * @tc.desc: 1. Set Code = 999 12579a732c7Sopenharmony_ci * 2. Call IpcServerStub OnRemoteRequest with param 12679a732c7Sopenharmony_ci * 3. check ret not DM_OK 12779a732c7Sopenharmony_ci * @tc.type: FUNC 12879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 12979a732c7Sopenharmony_ci */ 13079a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0) 13179a732c7Sopenharmony_ci{ 13279a732c7Sopenharmony_ci // 1. Set Code = 999 13379a732c7Sopenharmony_ci uint32_t code = 999; 13479a732c7Sopenharmony_ci MessageParcel data; 13579a732c7Sopenharmony_ci MessageParcel reply; 13679a732c7Sopenharmony_ci MessageOption option; 13779a732c7Sopenharmony_ci int ret = 0; 13879a732c7Sopenharmony_ci // 2. Call IpcServerStub OnRemoteRequest with param 13979a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option); 14079a732c7Sopenharmony_ci // 3. check ret not DM_OK 14179a732c7Sopenharmony_ci ASSERT_NE(ret, DM_OK); 14279a732c7Sopenharmony_ci} 14379a732c7Sopenharmony_ci 14479a732c7Sopenharmony_ci/** 14579a732c7Sopenharmony_ci * @tc.name: OnRemoteRequest_002 14679a732c7Sopenharmony_ci * @tc.desc: 1. Set Code = 999 14779a732c7Sopenharmony_ci * 2. Call IpcServerStub OnRemoteRequest with param 14879a732c7Sopenharmony_ci * 3. check ret not DM_OK 14979a732c7Sopenharmony_ci * @tc.type: FUNC 15079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 15179a732c7Sopenharmony_ci */ 15279a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) 15379a732c7Sopenharmony_ci{ 15479a732c7Sopenharmony_ci // 1. Set Code is SERVER_DEVICE_STATE_NOTIFY 15579a732c7Sopenharmony_ci uint32_t code = SERVER_DEVICE_STATE_NOTIFY; 15679a732c7Sopenharmony_ci MessageParcel data; 15779a732c7Sopenharmony_ci MessageParcel reply; 15879a732c7Sopenharmony_ci MessageOption option; 15979a732c7Sopenharmony_ci int ret = 0; 16079a732c7Sopenharmony_ci // 2. Call IpcServerStub OnRemoteRequest with param 16179a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option); 16279a732c7Sopenharmony_ci // 3. check ret not ERR_DM_IPC_READ_FAILED 16379a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_IPC_READ_FAILED); 16479a732c7Sopenharmony_ci} 16579a732c7Sopenharmony_ci 16679a732c7Sopenharmony_ci/** 16779a732c7Sopenharmony_ci * @tc.name: SendCmd_001 16879a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub SendCmd 16979a732c7Sopenharmony_ci * 2. check ret is DM_OK 17079a732c7Sopenharmony_ci * @tc.type: FUNC 17179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 17279a732c7Sopenharmony_ci */ 17379a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, SendCmd_001, testing::ext::TestSize.Level0) 17479a732c7Sopenharmony_ci{ 17579a732c7Sopenharmony_ci int result = 305; 17679a732c7Sopenharmony_ci int32_t cmdCode = -1; 17779a732c7Sopenharmony_ci std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>(); 17879a732c7Sopenharmony_ci std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>(); 17979a732c7Sopenharmony_ci // 1. Call IpcServerStub SendCmd 18079a732c7Sopenharmony_ci int32_t ret = IpcServerStub::GetInstance().SendCmd(cmdCode, req, rsp); 18179a732c7Sopenharmony_ci // 2. check ret is DM_OK 18279a732c7Sopenharmony_ci ASSERT_EQ(ret, result); 18379a732c7Sopenharmony_ci} 18479a732c7Sopenharmony_ci 18579a732c7Sopenharmony_ci/** 18679a732c7Sopenharmony_ci * @tc.name: SendCmd_002 18779a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub SendCmd 18879a732c7Sopenharmony_ci * 2. check ret is ERR_DM_INPUT_PARA_INVALID 18979a732c7Sopenharmony_ci * @tc.type: FUNC 19079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 19179a732c7Sopenharmony_ci */ 19279a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, SendCmd_002, testing::ext::TestSize.Level0) 19379a732c7Sopenharmony_ci{ 19479a732c7Sopenharmony_ci int result = 305; 19579a732c7Sopenharmony_ci int32_t cmdCode = IPC_MSG_BUTT; 19679a732c7Sopenharmony_ci std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>(); 19779a732c7Sopenharmony_ci std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>(); 19879a732c7Sopenharmony_ci // 1. Call IpcServerStub SendCmd 19979a732c7Sopenharmony_ci int32_t ret = IpcServerStub::GetInstance().SendCmd(cmdCode, req, rsp); 20079a732c7Sopenharmony_ci // 2. check ret is DM_OK 20179a732c7Sopenharmony_ci ASSERT_EQ(ret, result); 20279a732c7Sopenharmony_ci} 20379a732c7Sopenharmony_ci 20479a732c7Sopenharmony_ci/** 20579a732c7Sopenharmony_ci * @tc.name: QueryServiceState_001 20679a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub QueryServiceState 20779a732c7Sopenharmony_ci * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 20879a732c7Sopenharmony_ci * @tc.type: FUNC 20979a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 21079a732c7Sopenharmony_ci */ 21179a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, QueryServiceState_001, testing::ext::TestSize.Level0) 21279a732c7Sopenharmony_ci{ 21379a732c7Sopenharmony_ci IpcServerStub::GetInstance().state_ = ServiceRunningState::STATE_NOT_START; 21479a732c7Sopenharmony_ci // 1. Call IpcServerStub QueryServiceState 21579a732c7Sopenharmony_ci ServiceRunningState state = IpcServerStub::GetInstance().QueryServiceState(); 21679a732c7Sopenharmony_ci // 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 21779a732c7Sopenharmony_ci ASSERT_EQ(state, ServiceRunningState::STATE_NOT_START); 21879a732c7Sopenharmony_ci} 21979a732c7Sopenharmony_ci 22079a732c7Sopenharmony_ci/** 22179a732c7Sopenharmony_ci * @tc.name: RegisterDeviceManagerListener_001 22279a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener 22379a732c7Sopenharmony_ci * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 22479a732c7Sopenharmony_ci * @tc.type: FUNC 22579a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 22679a732c7Sopenharmony_ci */ 22779a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_001, testing::ext::TestSize.Level0) 22879a732c7Sopenharmony_ci{ 22979a732c7Sopenharmony_ci std::string pkgName = ""; 23079a732c7Sopenharmony_ci int ret = 0; 23179a732c7Sopenharmony_ci sptr<IpcRemoteBroker> listener = nullptr; 23279a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 23379a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_POINT_NULL); 23479a732c7Sopenharmony_ci} 23579a732c7Sopenharmony_ci 23679a732c7Sopenharmony_ci/** 23779a732c7Sopenharmony_ci * @tc.name: RegisterDeviceManagerListener_002 23879a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener 23979a732c7Sopenharmony_ci * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 24079a732c7Sopenharmony_ci * @tc.type: FUNC 24179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 24279a732c7Sopenharmony_ci */ 24379a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_002, testing::ext::TestSize.Level0) 24479a732c7Sopenharmony_ci{ 24579a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 24679a732c7Sopenharmony_ci int ret = 0; 24779a732c7Sopenharmony_ci sptr<IpcRemoteBroker> listener = sptr<IpcClientStub>(new IpcClientStub()); 24879a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 24979a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 25079a732c7Sopenharmony_ci} 25179a732c7Sopenharmony_ci 25279a732c7Sopenharmony_ci/** 25379a732c7Sopenharmony_ci * @tc.name: RegisterDeviceManagerListener_003 25479a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener 25579a732c7Sopenharmony_ci * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING 25679a732c7Sopenharmony_ci * @tc.type: FUNC 25779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 25879a732c7Sopenharmony_ci */ 25979a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_003, testing::ext::TestSize.Level0) 26079a732c7Sopenharmony_ci{ 26179a732c7Sopenharmony_ci std::string pkgName = ""; 26279a732c7Sopenharmony_ci int ret = 0; 26379a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 26479a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 26579a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_POINT_NULL); 26679a732c7Sopenharmony_ci} 26779a732c7Sopenharmony_ci 26879a732c7Sopenharmony_ci/** 26979a732c7Sopenharmony_ci * @tc.name: RegisterDeviceManagerListener_004 27079a732c7Sopenharmony_ci * @tc.desc: 1. Set PkgName is com.ohos.test 27179a732c7Sopenharmony_ci * 2. Call IpcServerStub RegisterDeviceManagerListener with param 27279a732c7Sopenharmony_ci * 3. check ret is DM_OK 27379a732c7Sopenharmony_ci * @tc.type: FUNC 27479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 27579a732c7Sopenharmony_ci */ 27679a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_004, testing::ext::TestSize.Level0) 27779a732c7Sopenharmony_ci{ 27879a732c7Sopenharmony_ci // 1. Set PkgName is com.ohos.test 27979a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 28079a732c7Sopenharmony_ci int ret = 0; 28179a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 28279a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 28379a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 28479a732c7Sopenharmony_ci // 3. check ret is DM_OK 28579a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 28679a732c7Sopenharmony_ci} 28779a732c7Sopenharmony_ci 28879a732c7Sopenharmony_ci/** 28979a732c7Sopenharmony_ci * @tc.name: RegisterDeviceManagerListener_005 29079a732c7Sopenharmony_ci * @tc.desc: 1. Set PkgName is com.ohos.test 29179a732c7Sopenharmony_ci * 2. Call IpcServerStub RegisterDeviceManagerListener with param 29279a732c7Sopenharmony_ci * 3. check ret is DM_OK 29379a732c7Sopenharmony_ci * 4. Call IpcServerStub RegisterDeviceManagerListener with same pkgName another listener 29479a732c7Sopenharmony_ci * 5. check result is DM_OK 29579a732c7Sopenharmony_ci * 6. earse pkgName for appRecipient_ 29679a732c7Sopenharmony_ci * 7. check result is DM_OK 29779a732c7Sopenharmony_ci * @tc.type: FUNC 29879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 29979a732c7Sopenharmony_ci */ 30079a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_005, testing::ext::TestSize.Level0) 30179a732c7Sopenharmony_ci{ 30279a732c7Sopenharmony_ci // 1. Set PkgName is com.ohos.test 30379a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 30479a732c7Sopenharmony_ci int ret = 0; 30579a732c7Sopenharmony_ci int result = 0; 30679a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 30779a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 30879a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 30979a732c7Sopenharmony_ci // 3. check ret is DM_OK 31079a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 31179a732c7Sopenharmony_ci sptr<IpcClientStub> listener2 = sptr<IpcClientStub>(new IpcClientStub()); 31279a732c7Sopenharmony_ci // 4. Call IpcServerStub RegisterDeviceManagerListener with same pkgName another listener 31379a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener2); 31479a732c7Sopenharmony_ci // 5. check result is DM_OK 31579a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 31679a732c7Sopenharmony_ci sptr<IpcClientStub> listener3 = sptr<IpcClientStub>(new IpcClientStub()); 31779a732c7Sopenharmony_ci // 6. earse pkgName for appRecipient_ 31879a732c7Sopenharmony_ci IpcServerStub::GetInstance().appRecipient_.erase(pkgName); 31979a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener3); 32079a732c7Sopenharmony_ci // 7. check result is DM_OK 32179a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 32279a732c7Sopenharmony_ci} 32379a732c7Sopenharmony_ci 32479a732c7Sopenharmony_ci/** 32579a732c7Sopenharmony_ci * @tc.name: UnRegisterDeviceManagerListener_001 32679a732c7Sopenharmony_ci * @tc.desc: 1. Call IpcServerStub UnRegisterDeviceManagerListener 32779a732c7Sopenharmony_ci * 2. check ret is ERR_DM_INPUT_PARA_INVALID 32879a732c7Sopenharmony_ci * @tc.type: FUNC 32979a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 33079a732c7Sopenharmony_ci */ 33179a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_001, testing::ext::TestSize.Level0) 33279a732c7Sopenharmony_ci{ 33379a732c7Sopenharmony_ci std::string pkgName; 33479a732c7Sopenharmony_ci int ret = 0; 33579a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); 33679a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); 33779a732c7Sopenharmony_ci} 33879a732c7Sopenharmony_ci 33979a732c7Sopenharmony_ci/** 34079a732c7Sopenharmony_ci * @tc.name: UnRegisterDeviceManagerListener_002 34179a732c7Sopenharmony_ci * @tc.desc: 1. Set PkgName is com.ohos.test 34279a732c7Sopenharmony_ci * 2. Call IpcServerStub RegisterDeviceManagerListener with param 34379a732c7Sopenharmony_ci * 3. check ret is DM_OK 34479a732c7Sopenharmony_ci * 4. Call IpcServerStub UnRegisterDeviceManagerListener 34579a732c7Sopenharmony_ci * 5. check ret is DM_OK 34679a732c7Sopenharmony_ci * @tc.type: FUNC 34779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 34879a732c7Sopenharmony_ci */ 34979a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_002, testing::ext::TestSize.Level0) 35079a732c7Sopenharmony_ci{ 35179a732c7Sopenharmony_ci // 1. Set PkgName is com.ohos.test 35279a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 35379a732c7Sopenharmony_ci int ret = 0; 35479a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 35579a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 35679a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 35779a732c7Sopenharmony_ci // 3. check ret is DM_OK 35879a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 35979a732c7Sopenharmony_ci int result = 0; 36079a732c7Sopenharmony_ci // 4. Call IpcServerStub UnRegisterDeviceManagerListener 36179a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); 36279a732c7Sopenharmony_ci // 5. check ret is DM_OK 36379a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 36479a732c7Sopenharmony_ci} 36579a732c7Sopenharmony_ci 36679a732c7Sopenharmony_ci/** 36779a732c7Sopenharmony_ci * @tc.name: UnRegisterDeviceManagerListener_003 36879a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.test 36979a732c7Sopenharmony_ci * 2. Call IpcServerStub UnRegisterDeviceManagerListener 37079a732c7Sopenharmony_ci * 3. check ret is DM_OK 37179a732c7Sopenharmony_ci * @tc.type: FUNC 37279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 37379a732c7Sopenharmony_ci */ 37479a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_003, testing::ext::TestSize.Level0) 37579a732c7Sopenharmony_ci{ 37679a732c7Sopenharmony_ci // 1. Set pkgName is com.ohos.test 37779a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 37879a732c7Sopenharmony_ci int ret = 0; 37979a732c7Sopenharmony_ci // 2. Call IpcServerStub UnRegisterDeviceManagerListener 38079a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); 38179a732c7Sopenharmony_ci // 3. check ret is DM_OK 38279a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 38379a732c7Sopenharmony_ci} 38479a732c7Sopenharmony_ci 38579a732c7Sopenharmony_ci/** 38679a732c7Sopenharmony_ci * @tc.name: UnRegisterDeviceManagerListener_004 38779a732c7Sopenharmony_ci * @tc.desc: 1. Set PkgName is com.ohos.test 38879a732c7Sopenharmony_ci * 2. Call IpcServerStub RegisterDeviceManagerListener with param 38979a732c7Sopenharmony_ci * 3. check ret is DM_OK 39079a732c7Sopenharmony_ci * 4. Call IpcServerStub UnRegisterDeviceManagerListener 39179a732c7Sopenharmony_ci * 5. check ret is DM_OK 39279a732c7Sopenharmony_ci * @tc.type: FUNC 39379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 39479a732c7Sopenharmony_ci */ 39579a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_004, testing::ext::TestSize.Level0) 39679a732c7Sopenharmony_ci{ 39779a732c7Sopenharmony_ci // 1. Set PkgName is com.ohos.test 39879a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test1"; 39979a732c7Sopenharmony_ci int ret = 0; 40079a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 40179a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 40279a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 40379a732c7Sopenharmony_ci // 3. check ret is DM_OK 40479a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 40579a732c7Sopenharmony_ci int result = 0; 40679a732c7Sopenharmony_ci // 4. Call IpcServerStub UnRegisterDeviceManagerListener 40779a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); 40879a732c7Sopenharmony_ci // 5. check ret is DM_OK 40979a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 41079a732c7Sopenharmony_ci sptr<IpcRemoteBroker> dmListener = IpcServerStub::GetInstance().dmListener_[pkgName]; 41179a732c7Sopenharmony_ci ASSERT_EQ(dmListener, nullptr); 41279a732c7Sopenharmony_ci} 41379a732c7Sopenharmony_ci 41479a732c7Sopenharmony_ci/** 41579a732c7Sopenharmony_ci * @tc.name: UnRegisterDeviceManagerListener_005 41679a732c7Sopenharmony_ci * @tc.desc: 1. Set PkgName is com.ohos.test 41779a732c7Sopenharmony_ci * 2. Call IpcServerStub RegisterDeviceManagerListener with param 41879a732c7Sopenharmony_ci * 3. check ret is DM_OK 41979a732c7Sopenharmony_ci * 4. Call IpcServerStub UnRegisterDeviceManagerListener 42079a732c7Sopenharmony_ci * 5. check ret is DM_OK 42179a732c7Sopenharmony_ci * 6. Call IpcServerStub UnRegisterDeviceManagerListener 42279a732c7Sopenharmony_ci * 7. check ret is DM_OK 42379a732c7Sopenharmony_ci * @tc.type: FUNC 42479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 42579a732c7Sopenharmony_ci */ 42679a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_005, testing::ext::TestSize.Level0) 42779a732c7Sopenharmony_ci{ 42879a732c7Sopenharmony_ci // 1. Set PkgName is com.ohos.test 42979a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test2"; 43079a732c7Sopenharmony_ci int ret = 0; 43179a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 43279a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 43379a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 43479a732c7Sopenharmony_ci // 3. check ret is DM_OK 43579a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 43679a732c7Sopenharmony_ci int result = 0; 43779a732c7Sopenharmony_ci // 4. Call IpcServerStub UnRegisterDeviceManagerListener 43879a732c7Sopenharmony_ci std::string testPkgName = "com.test"; 43979a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(testPkgName); 44079a732c7Sopenharmony_ci // 5. check ret is DM_OK 44179a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 44279a732c7Sopenharmony_ci IpcServerStub::GetInstance().appRecipient_.erase(pkgName); 44379a732c7Sopenharmony_ci // 6. Call IpcServerStub UnRegisterDeviceManagerListener 44479a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); 44579a732c7Sopenharmony_ci // 7. check ret is DM_OK 44679a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 44779a732c7Sopenharmony_ci} 44879a732c7Sopenharmony_ci 44979a732c7Sopenharmony_ci/** 45079a732c7Sopenharmony_ci * @tc.name: SendALL_001 45179a732c7Sopenharmony_ci * @tc.desc: 1. Set PkgName1 is com.ohos.SendALL_001 45279a732c7Sopenharmony_ci * 2. Set PkgName2 is com.ohos.SendALL_002 45379a732c7Sopenharmony_ci * 3. Add listener1 (nullptr) to dmListener_ with key pkgName1 45479a732c7Sopenharmony_ci * 4. Add listener2 to dmListener_ with key listener2 45579a732c7Sopenharmony_ci * 5. Call IpcServerStub::SendALL with cmdCode, req, rsp 45679a732c7Sopenharmony_ci * 6. Check result is DM_OK 45779a732c7Sopenharmony_ci * @tc.type: FUNC 45879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 45979a732c7Sopenharmony_ci */ 46079a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, SendALL_001, testing::ext::TestSize.Level0) 46179a732c7Sopenharmony_ci{ 46279a732c7Sopenharmony_ci int32_t cmdCode = -1; 46379a732c7Sopenharmony_ci std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>(); 46479a732c7Sopenharmony_ci std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>(); 46579a732c7Sopenharmony_ci std::string pkgName1 = "com.ohos.SendALL_001"; 46679a732c7Sopenharmony_ci std::string pkgName2 = "com.ohos.SendALL_002"; 46779a732c7Sopenharmony_ci sptr<IpcClientStub> listener1 = nullptr; 46879a732c7Sopenharmony_ci sptr<IpcClientStub> listener2 = sptr<IpcClientStub>(new IpcClientStub()); 46979a732c7Sopenharmony_ci IpcServerStub::GetInstance().dmListener_[pkgName1] = listener1; 47079a732c7Sopenharmony_ci IpcServerStub::GetInstance().dmListener_[pkgName2] = listener2; 47179a732c7Sopenharmony_ci int32_t result = IpcServerStub::GetInstance().SendALL(cmdCode, req, rsp); 47279a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 47379a732c7Sopenharmony_ci IpcServerStub::GetInstance().dmListener_.clear(); 47479a732c7Sopenharmony_ci} 47579a732c7Sopenharmony_ci 47679a732c7Sopenharmony_ci/** 47779a732c7Sopenharmony_ci * @tc.name: GetDmListenerPkgName_001 47879a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.GetDmListenerPkgName_001 47979a732c7Sopenharmony_ci * 2. Create listener and add it to dmListener_ with key pkgName 48079a732c7Sopenharmony_ci * 3. Call IpcServerStub::GetDmListenerPkgName with remote object 48179a732c7Sopenharmony_ci * 4. Check the result is not empty 48279a732c7Sopenharmony_ci * @tc.type: FUNC 48379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 48479a732c7Sopenharmony_ci */ 48579a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetDmListenerPkgName_001, testing::ext::TestSize.Level0) 48679a732c7Sopenharmony_ci{ 48779a732c7Sopenharmony_ci sptr<IRemoteObject> remote(new IpcClientStub()); 48879a732c7Sopenharmony_ci std::string pkgName = "com.ohos.GetDmListenerPkgName_001"; 48979a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 49079a732c7Sopenharmony_ci IpcServerStub::GetInstance().dmListener_[pkgName] = listener; 49179a732c7Sopenharmony_ci std::string ret = IpcServerStub::GetInstance().GetDmListenerPkgName(remote); 49279a732c7Sopenharmony_ci EXPECT_TRUE(ret.empty() || (ret == pkgName)); 49379a732c7Sopenharmony_ci IpcServerStub::GetInstance().dmListener_.clear(); 49479a732c7Sopenharmony_ci} 49579a732c7Sopenharmony_ci 49679a732c7Sopenharmony_ci/** 49779a732c7Sopenharmony_ci * @tc.name: GetDmListener_001 49879a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.test 49979a732c7Sopenharmony_ci * 2. Call IpcServerStub GetDmListener 50079a732c7Sopenharmony_ci * 3. check ret is DM_OK 50179a732c7Sopenharmony_ci * @tc.type: FUNC 50279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 50379a732c7Sopenharmony_ci */ 50479a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetDmListener_001, testing::ext::TestSize.Level0) 50579a732c7Sopenharmony_ci{ 50679a732c7Sopenharmony_ci // 1. Set pkgName is com.ohos.test 50779a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 50879a732c7Sopenharmony_ci sptr<IpcRemoteBroker> ret = nullptr; 50979a732c7Sopenharmony_ci // 2. Call IpcServerStub UnRegisterDeviceManagerListener 51079a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().GetDmListener(pkgName); 51179a732c7Sopenharmony_ci // 3. check ret is DM_OK 51279a732c7Sopenharmony_ci ASSERT_EQ(ret, nullptr); 51379a732c7Sopenharmony_ci} 51479a732c7Sopenharmony_ci 51579a732c7Sopenharmony_ci/** 51679a732c7Sopenharmony_ci * @tc.name: GetDmListener_002 51779a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.test 51879a732c7Sopenharmony_ci * 2. Call IpcServerStub GetDmListener 51979a732c7Sopenharmony_ci * 3. check ret is DM_OK 52079a732c7Sopenharmony_ci * @tc.type: FUNC 52179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 52279a732c7Sopenharmony_ci */ 52379a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetDmListener_002, testing::ext::TestSize.Level0) 52479a732c7Sopenharmony_ci{ 52579a732c7Sopenharmony_ci // 1. Set pkgName is com.ohos.test 52679a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 52779a732c7Sopenharmony_ci int result = 0; 52879a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 52979a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 53079a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 53179a732c7Sopenharmony_ci // 3. check ret is DM_OK 53279a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 53379a732c7Sopenharmony_ci sptr<IpcRemoteBroker> ret = nullptr; 53479a732c7Sopenharmony_ci // 2. Call IpcServerStub UnRegisterDeviceManagerListener 53579a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().GetDmListener(pkgName); 53679a732c7Sopenharmony_ci // 3. check ret is DM_OK 53779a732c7Sopenharmony_ci ASSERT_NE(ret, nullptr); 53879a732c7Sopenharmony_ci} 53979a732c7Sopenharmony_ci 54079a732c7Sopenharmony_ci/** 54179a732c7Sopenharmony_ci * @tc.name: GetDmListener_003 54279a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.test 54379a732c7Sopenharmony_ci * 2. Call IpcServerStub GetDmListener 54479a732c7Sopenharmony_ci * 3. check ret is DM_OK 54579a732c7Sopenharmony_ci * @tc.type: FUNC 54679a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 54779a732c7Sopenharmony_ci */ 54879a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetDmListener_003, testing::ext::TestSize.Level0) 54979a732c7Sopenharmony_ci{ 55079a732c7Sopenharmony_ci // 1. Set pkgName is com.ohos.test 55179a732c7Sopenharmony_ci std::string pkgName = "com.ohos.test"; 55279a732c7Sopenharmony_ci int result = 0; 55379a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 55479a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 55579a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 55679a732c7Sopenharmony_ci // 3. check ret is DM_OK 55779a732c7Sopenharmony_ci ASSERT_EQ(result, DM_OK); 55879a732c7Sopenharmony_ci sptr<IpcRemoteBroker> ret = nullptr; 55979a732c7Sopenharmony_ci // 2. Call IpcServerStub UnRegisterDeviceManagerListener 56079a732c7Sopenharmony_ci std::string testPkgName = "test"; 56179a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().GetDmListener(testPkgName); 56279a732c7Sopenharmony_ci // 3. check ret is DM_OK 56379a732c7Sopenharmony_ci ASSERT_EQ(ret, nullptr); 56479a732c7Sopenharmony_ci} 56579a732c7Sopenharmony_ci 56679a732c7Sopenharmony_ci/** 56779a732c7Sopenharmony_ci * @tc.name: GetDmListener_004 56879a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.test 56979a732c7Sopenharmony_ci * 2. Call IpcServerStub GetDmListener 57079a732c7Sopenharmony_ci * 3. check ret is ERR_DM_POINT_NULL 57179a732c7Sopenharmony_ci * @tc.type: FUNC 57279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 57379a732c7Sopenharmony_ci */ 57479a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetDmListener_004, testing::ext::TestSize.Level0) 57579a732c7Sopenharmony_ci{ 57679a732c7Sopenharmony_ci // 1. Set pkgName is null 57779a732c7Sopenharmony_ci std::string pkgName = ""; 57879a732c7Sopenharmony_ci int result = 0; 57979a732c7Sopenharmony_ci sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub()); 58079a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 58179a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 58279a732c7Sopenharmony_ci // 3. check ret is ERR_DM_POINT_NULL 58379a732c7Sopenharmony_ci ASSERT_EQ(result, ERR_DM_POINT_NULL); 58479a732c7Sopenharmony_ci sptr<IpcRemoteBroker> ret = nullptr; 58579a732c7Sopenharmony_ci // 2. Call IpcServerStub UnRegisterDeviceManagerListener 58679a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().GetDmListener(pkgName); 58779a732c7Sopenharmony_ci // 3. check ret is nullptr 58879a732c7Sopenharmony_ci ASSERT_EQ(ret, nullptr); 58979a732c7Sopenharmony_ci} 59079a732c7Sopenharmony_ci 59179a732c7Sopenharmony_ci/** 59279a732c7Sopenharmony_ci * @tc.name: GetDmListener_005 59379a732c7Sopenharmony_ci * @tc.desc: 1. Set pkgName is com.ohos.test 59479a732c7Sopenharmony_ci * 2. Call IpcServerStub GetDmListener 59579a732c7Sopenharmony_ci * 3. check ret is ERR_DM_POINT_NULL 59679a732c7Sopenharmony_ci * @tc.type: FUNC 59779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 59879a732c7Sopenharmony_ci */ 59979a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetDmListener_005, testing::ext::TestSize.Level0) 60079a732c7Sopenharmony_ci{ 60179a732c7Sopenharmony_ci // 1. Set pkgName is null 60279a732c7Sopenharmony_ci std::string pkgName = "com.test.ohos"; 60379a732c7Sopenharmony_ci int result = 0; 60479a732c7Sopenharmony_ci sptr<IpcClientStub> listener = nullptr; 60579a732c7Sopenharmony_ci // 2. Call IpcServerStub RegisterDeviceManagerListener with param 60679a732c7Sopenharmony_ci result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); 60779a732c7Sopenharmony_ci // 3. check ret is ERR_DM_POINT_NULL 60879a732c7Sopenharmony_ci ASSERT_EQ(result, ERR_DM_POINT_NULL); 60979a732c7Sopenharmony_ci sptr<IpcRemoteBroker> ret = nullptr; 61079a732c7Sopenharmony_ci // 2. Call IpcServerStub UnRegisterDeviceManagerListener 61179a732c7Sopenharmony_ci ret = IpcServerStub::GetInstance().GetDmListener(pkgName); 61279a732c7Sopenharmony_ci // 3. check ret is nullptr 61379a732c7Sopenharmony_ci ASSERT_EQ(ret, nullptr); 61479a732c7Sopenharmony_ci} 61579a732c7Sopenharmony_ci 61679a732c7Sopenharmony_ci/** 61779a732c7Sopenharmony_ci * @tc.name: OnRemoveSystemAbility_001 61879a732c7Sopenharmony_ci * @tc.type: FUNC 61979a732c7Sopenharmony_ci */ 62079a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnRemoveSystemAbility_001, testing::ext::TestSize.Level0) 62179a732c7Sopenharmony_ci{ 62279a732c7Sopenharmony_ci int32_t systemAbilityId = SOFTBUS_SERVER_SA_ID; 62379a732c7Sopenharmony_ci std::string deviceId; 62479a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnRemoveSystemAbility(systemAbilityId, deviceId); 62579a732c7Sopenharmony_ci ASSERT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); 62679a732c7Sopenharmony_ci} 62779a732c7Sopenharmony_ci 62879a732c7Sopenharmony_ci/** 62979a732c7Sopenharmony_ci * @tc.name: OnRemoveSystemAbility_002 63079a732c7Sopenharmony_ci * @tc.type: FUNC 63179a732c7Sopenharmony_ci */ 63279a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnRemoveSystemAbility_002, testing::ext::TestSize.Level0) 63379a732c7Sopenharmony_ci{ 63479a732c7Sopenharmony_ci int32_t systemAbilityId = DISTRIBUTED_HARDWARE_SA_ID; 63579a732c7Sopenharmony_ci std::string deviceId; 63679a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnRemoveSystemAbility(systemAbilityId, deviceId); 63779a732c7Sopenharmony_ci ASSERT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); 63879a732c7Sopenharmony_ci} 63979a732c7Sopenharmony_ci 64079a732c7Sopenharmony_ci/** 64179a732c7Sopenharmony_ci * @tc.name: OnAddSystemAbility_001 64279a732c7Sopenharmony_ci * @tc.type: FUNC 64379a732c7Sopenharmony_ci */ 64479a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnAddSystemAbility_001, testing::ext::TestSize.Level0) 64579a732c7Sopenharmony_ci{ 64679a732c7Sopenharmony_ci int32_t systemAbilityId = SOFTBUS_SERVER_SA_ID; 64779a732c7Sopenharmony_ci std::string deviceId; 64879a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId); 64979a732c7Sopenharmony_ci ASSERT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); 65079a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnRemoveSystemAbility(systemAbilityId, deviceId); 65179a732c7Sopenharmony_ci} 65279a732c7Sopenharmony_ci 65379a732c7Sopenharmony_ci/** 65479a732c7Sopenharmony_ci * @tc.name: OnAddSystemAbility_002 65579a732c7Sopenharmony_ci * @tc.type: FUNC 65679a732c7Sopenharmony_ci */ 65779a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, OnAddSystemAbility_002, testing::ext::TestSize.Level0) 65879a732c7Sopenharmony_ci{ 65979a732c7Sopenharmony_ci int32_t systemAbilityId = 9999; 66079a732c7Sopenharmony_ci std::string deviceId; 66179a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId); 66279a732c7Sopenharmony_ci EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); 66379a732c7Sopenharmony_ci 66479a732c7Sopenharmony_ci systemAbilityId = SOFTBUS_SERVER_SA_ID; 66579a732c7Sopenharmony_ci IpcServerStub::GetInstance().registerToService_ = false; 66679a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId); 66779a732c7Sopenharmony_ci EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); 66879a732c7Sopenharmony_ci 66979a732c7Sopenharmony_ci DeviceManagerService::GetInstance().softbusListener_ = nullptr; 67079a732c7Sopenharmony_ci systemAbilityId = SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN; 67179a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId); 67279a732c7Sopenharmony_ci EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); 67379a732c7Sopenharmony_ci 67479a732c7Sopenharmony_ci systemAbilityId = SCREENLOCK_SERVICE_ID; 67579a732c7Sopenharmony_ci IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId); 67679a732c7Sopenharmony_ci EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); 67779a732c7Sopenharmony_ci} 67879a732c7Sopenharmony_ci 67979a732c7Sopenharmony_ci/** 68079a732c7Sopenharmony_ci * @tc.name: GetAllPkgName_001 68179a732c7Sopenharmony_ci * @tc.type: FUNC 68279a732c7Sopenharmony_ci */ 68379a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, GetAllPkgName_001, testing::ext::TestSize.Level0) 68479a732c7Sopenharmony_ci{ 68579a732c7Sopenharmony_ci std::vector<std::string> pkgName; 68679a732c7Sopenharmony_ci pkgName = IpcServerStub::GetInstance().GetAllPkgName(); 68779a732c7Sopenharmony_ci ASSERT_EQ(pkgName.empty(), false); 68879a732c7Sopenharmony_ci} 68979a732c7Sopenharmony_ci 69079a732c7Sopenharmony_ci/** 69179a732c7Sopenharmony_ci * @tc.name: Dump_001 69279a732c7Sopenharmony_ci * @tc.type: FUNC 69379a732c7Sopenharmony_ci */ 69479a732c7Sopenharmony_ciHWTEST_F(IpcServerStubTest, Dump_001, testing::ext::TestSize.Level0) 69579a732c7Sopenharmony_ci{ 69679a732c7Sopenharmony_ci int32_t fd = 0; 69779a732c7Sopenharmony_ci std::vector<std::u16string> args; 69879a732c7Sopenharmony_ci int32_t ret = IpcServerStub::GetInstance().Dump(fd, args); 69979a732c7Sopenharmony_ci ASSERT_NE(ret, DM_OK); 70079a732c7Sopenharmony_ci} 70179a732c7Sopenharmony_ci} // namespace 70279a732c7Sopenharmony_ci} // namespace DistributedHardware 70379a732c7Sopenharmony_ci} // namespace OHOS 704