1d9f0492fSopenharmony_ci/* 2d9f0492fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3d9f0492fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4d9f0492fSopenharmony_ci * you may not use this file except in compliance with the License. 5d9f0492fSopenharmony_ci * You may obtain a copy of the License at 6d9f0492fSopenharmony_ci * 7d9f0492fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8d9f0492fSopenharmony_ci * 9d9f0492fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10d9f0492fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11d9f0492fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d9f0492fSopenharmony_ci * See the License for the specific language governing permissions and 13d9f0492fSopenharmony_ci * limitations under the License. 14d9f0492fSopenharmony_ci */ 15d9f0492fSopenharmony_ci#include <gtest/gtest.h> 16d9f0492fSopenharmony_ci 17d9f0492fSopenharmony_ci#include "if_system_ability_manager.h" 18d9f0492fSopenharmony_ci#include "param_stub.h" 19d9f0492fSopenharmony_ci#include "iservice_registry.h" 20d9f0492fSopenharmony_ci#include "iwatcher.h" 21d9f0492fSopenharmony_ci#include "iwatcher_manager.h" 22d9f0492fSopenharmony_ci#include "message_parcel.h" 23d9f0492fSopenharmony_ci#include "param_message.h" 24d9f0492fSopenharmony_ci#include "init_param.h" 25d9f0492fSopenharmony_ci#include "param_utils.h" 26d9f0492fSopenharmony_ci#include "parcel.h" 27d9f0492fSopenharmony_ci#include "securec.h" 28d9f0492fSopenharmony_ci#include "system_ability_definition.h" 29d9f0492fSopenharmony_ci#include "string_ex.h" 30d9f0492fSopenharmony_ci#include "watcher.h" 31d9f0492fSopenharmony_ci#include "watcher_manager.h" 32d9f0492fSopenharmony_ci#include "watcher_proxy.h" 33d9f0492fSopenharmony_ci#include "watcher_utils.h" 34d9f0492fSopenharmony_ci 35d9f0492fSopenharmony_ciusing namespace testing::ext; 36d9f0492fSopenharmony_ciusing namespace std; 37d9f0492fSopenharmony_ciusing namespace OHOS; 38d9f0492fSopenharmony_ciusing namespace OHOS::init_param; 39d9f0492fSopenharmony_ci 40d9f0492fSopenharmony_ciclass TestWatcher final : public Watcher { 41d9f0492fSopenharmony_cipublic: 42d9f0492fSopenharmony_ci TestWatcher() {} 43d9f0492fSopenharmony_ci ~TestWatcher() = default; 44d9f0492fSopenharmony_ci 45d9f0492fSopenharmony_ci void OnParameterChange(const std::string &prefix, const std::string &name, const std::string &value) override 46d9f0492fSopenharmony_ci { 47d9f0492fSopenharmony_ci printf("TestWatcher::OnParameterChange name %s %s \n", name.c_str(), value.c_str()); 48d9f0492fSopenharmony_ci } 49d9f0492fSopenharmony_ci}; 50d9f0492fSopenharmony_ci 51d9f0492fSopenharmony_ciusing WatcherManagerPtr = WatcherManager *; 52d9f0492fSopenharmony_ciclass WatcherProxyUnitTest : public ::testing::Test { 53d9f0492fSopenharmony_cipublic: 54d9f0492fSopenharmony_ci WatcherProxyUnitTest() {} 55d9f0492fSopenharmony_ci virtual ~WatcherProxyUnitTest() {} 56d9f0492fSopenharmony_ci 57d9f0492fSopenharmony_ci void SetUp() 58d9f0492fSopenharmony_ci { 59d9f0492fSopenharmony_ci if (GetParamSecurityLabel() != nullptr) { 60d9f0492fSopenharmony_ci GetParamSecurityLabel()->cred.uid = 0; 61d9f0492fSopenharmony_ci GetParamSecurityLabel()->cred.gid = 0; 62d9f0492fSopenharmony_ci } 63d9f0492fSopenharmony_ci SetTestPermissionResult(0); 64d9f0492fSopenharmony_ci } 65d9f0492fSopenharmony_ci void TearDown() {} 66d9f0492fSopenharmony_ci void TestBody() {} 67d9f0492fSopenharmony_ci 68d9f0492fSopenharmony_ci int TestAddRemoteWatcher(uint32_t agentId, uint32_t &watcherId) 69d9f0492fSopenharmony_ci { 70d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 71d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager"); 72d9f0492fSopenharmony_ci MessageParcel data; 73d9f0492fSopenharmony_ci MessageParcel reply; 74d9f0492fSopenharmony_ci MessageOption option; 75d9f0492fSopenharmony_ci 76d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 77d9f0492fSopenharmony_ci sptr<IWatcher> watcher = new TestWatcher(); 78d9f0492fSopenharmony_ci bool ret = data.WriteRemoteObject(watcher->AsObject()); 79d9f0492fSopenharmony_ci WATCHER_CHECK(ret, return 0, "Can not get remote"); 80d9f0492fSopenharmony_ci data.WriteUint32(agentId); 81d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 82d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::ADD_REMOTE_AGENT), data, reply, option); 83d9f0492fSopenharmony_ci watcherId = reply.ReadUint32(); 84d9f0492fSopenharmony_ci EXPECT_NE(watcherId, 0); 85d9f0492fSopenharmony_ci 86d9f0492fSopenharmony_ci auto remoteWatcher = watcherManager->GetRemoteWatcher(watcherId); 87d9f0492fSopenharmony_ci if (remoteWatcher != nullptr) { 88d9f0492fSopenharmony_ci EXPECT_EQ(remoteWatcher->GetAgentId(), agentId); 89d9f0492fSopenharmony_ci } else { 90d9f0492fSopenharmony_ci EXPECT_EQ(0, agentId); 91d9f0492fSopenharmony_ci } 92d9f0492fSopenharmony_ci return 0; 93d9f0492fSopenharmony_ci } 94d9f0492fSopenharmony_ci 95d9f0492fSopenharmony_ci int TestDelRemoteWatcher(uint32_t watcherId) 96d9f0492fSopenharmony_ci { 97d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 98d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager"); 99d9f0492fSopenharmony_ci MessageParcel data; 100d9f0492fSopenharmony_ci MessageParcel reply; 101d9f0492fSopenharmony_ci MessageOption option; 102d9f0492fSopenharmony_ci 103d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 104d9f0492fSopenharmony_ci data.WriteUint32(watcherId); 105d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 106d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::DEL_REMOTE_AGENT), data, reply, option); 107d9f0492fSopenharmony_ci EXPECT_EQ(reply.ReadInt32(), 0); 108d9f0492fSopenharmony_ci EXPECT_EQ(watcherManager->GetRemoteWatcher(watcherId) == nullptr, 1); 109d9f0492fSopenharmony_ci return 0; 110d9f0492fSopenharmony_ci } 111d9f0492fSopenharmony_ci 112d9f0492fSopenharmony_ci int TestAddWatcher(const std::string &keyPrefix, uint32_t watcherId) 113d9f0492fSopenharmony_ci { 114d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 115d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager"); 116d9f0492fSopenharmony_ci MessageParcel data; 117d9f0492fSopenharmony_ci MessageParcel reply; 118d9f0492fSopenharmony_ci MessageOption option; 119d9f0492fSopenharmony_ci 120d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 121d9f0492fSopenharmony_ci data.WriteString(keyPrefix); 122d9f0492fSopenharmony_ci data.WriteUint32(watcherId); 123d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 124d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::ADD_WATCHER), data, reply, option); 125d9f0492fSopenharmony_ci EXPECT_EQ(reply.ReadInt32(), 0); 126d9f0492fSopenharmony_ci EXPECT_EQ(watcherManager->GetWatcherGroup(keyPrefix) != nullptr, 1); 127d9f0492fSopenharmony_ci return 0; 128d9f0492fSopenharmony_ci } 129d9f0492fSopenharmony_ci 130d9f0492fSopenharmony_ci int TestRefreshWatcher(const std::string &keyPrefix, uint32_t watcherId) 131d9f0492fSopenharmony_ci { 132d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 133d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager"); 134d9f0492fSopenharmony_ci MessageParcel data; 135d9f0492fSopenharmony_ci MessageParcel reply; 136d9f0492fSopenharmony_ci MessageOption option; 137d9f0492fSopenharmony_ci 138d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 139d9f0492fSopenharmony_ci data.WriteString(keyPrefix); 140d9f0492fSopenharmony_ci data.WriteUint32(watcherId); 141d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 142d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::REFRESH_WATCHER), data, reply, option); 143d9f0492fSopenharmony_ci EXPECT_EQ(reply.ReadInt32(), 0); 144d9f0492fSopenharmony_ci EXPECT_EQ(watcherManager->GetWatcherGroup(keyPrefix) != nullptr, 1); 145d9f0492fSopenharmony_ci return 0; 146d9f0492fSopenharmony_ci } 147d9f0492fSopenharmony_ci 148d9f0492fSopenharmony_ci int TestDelWatcher(const std::string &keyPrefix, uint32_t watcherId) 149d9f0492fSopenharmony_ci { 150d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 151d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager"); 152d9f0492fSopenharmony_ci MessageParcel data; 153d9f0492fSopenharmony_ci MessageParcel reply; 154d9f0492fSopenharmony_ci MessageOption option; 155d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 156d9f0492fSopenharmony_ci data.WriteString(keyPrefix); 157d9f0492fSopenharmony_ci data.WriteUint32(watcherId); 158d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 159d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::DEL_WATCHER), data, reply, option); 160d9f0492fSopenharmony_ci EXPECT_EQ(reply.ReadInt32(), 0); 161d9f0492fSopenharmony_ci return 0; 162d9f0492fSopenharmony_ci } 163d9f0492fSopenharmony_ci 164d9f0492fSopenharmony_ci int TestProcessWatcherMessage(const std::string &name, uint32_t watcherId) 165d9f0492fSopenharmony_ci { 166d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 167d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager"); 168d9f0492fSopenharmony_ci const std::string value("test.value"); 169d9f0492fSopenharmony_ci uint32_t msgSize = sizeof(ParamMessage) + sizeof(ParamMsgContent) + value.size(); 170d9f0492fSopenharmony_ci msgSize = PARAM_ALIGN(msgSize); // align 171d9f0492fSopenharmony_ci std::vector<char> buffer(msgSize, 0); 172d9f0492fSopenharmony_ci ParamMessage *msg = reinterpret_cast<ParamMessage *>(buffer.data()); 173d9f0492fSopenharmony_ci WATCHER_CHECK(msg != nullptr, return -1, "Invalid msg"); 174d9f0492fSopenharmony_ci msg->type = MSG_NOTIFY_PARAM; 175d9f0492fSopenharmony_ci msg->msgSize = msgSize; 176d9f0492fSopenharmony_ci msg->id.watcherId = watcherId; 177d9f0492fSopenharmony_ci int ret = memcpy_s(msg->key, sizeof(msg->key), name.c_str(), name.size()); 178d9f0492fSopenharmony_ci WATCHER_CHECK(ret == 0, return -1, "Failed to fill value"); 179d9f0492fSopenharmony_ci uint32_t offset = 0; 180d9f0492fSopenharmony_ci ret = FillParamMsgContent(msg, &offset, PARAM_VALUE, value.c_str(), value.size()); 181d9f0492fSopenharmony_ci WATCHER_CHECK(ret == 0, return -1, "Failed to fill value"); 182d9f0492fSopenharmony_ci watcherManager->ProcessWatcherMessage(msg); 183d9f0492fSopenharmony_ci return 0; 184d9f0492fSopenharmony_ci } 185d9f0492fSopenharmony_ci 186d9f0492fSopenharmony_ci int TestWatchProxy(const std::string &name, const std::string &value) 187d9f0492fSopenharmony_ci { 188d9f0492fSopenharmony_ci sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 189d9f0492fSopenharmony_ci EXPECT_NE(systemMgr, nullptr); 190d9f0492fSopenharmony_ci sptr<IRemoteObject> remoteObj = systemMgr->GetSystemAbility(PARAM_WATCHER_DISTRIBUTED_SERVICE_ID); 191d9f0492fSopenharmony_ci EXPECT_NE(remoteObj, nullptr); 192d9f0492fSopenharmony_ci WatcherProxy *watcher = new WatcherProxy(remoteObj); 193d9f0492fSopenharmony_ci if (watcher != nullptr) { 194d9f0492fSopenharmony_ci watcher->OnParameterChange(name, name, value); 195d9f0492fSopenharmony_ci delete watcher; 196d9f0492fSopenharmony_ci } 197d9f0492fSopenharmony_ci return 0; 198d9f0492fSopenharmony_ci } 199d9f0492fSopenharmony_ci 200d9f0492fSopenharmony_ci int TestWatchAgentDump(const std::string &keyPrefix) 201d9f0492fSopenharmony_ci { 202d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 203d9f0492fSopenharmony_ci // dump watcher 204d9f0492fSopenharmony_ci std::vector<std::u16string> args = {}; 205d9f0492fSopenharmony_ci watcherManager->Dump(STDOUT_FILENO, args); 206d9f0492fSopenharmony_ci // dump parameter 207d9f0492fSopenharmony_ci args.push_back(Str8ToStr16("-h")); 208d9f0492fSopenharmony_ci watcherManager->Dump(STDOUT_FILENO, args); 209d9f0492fSopenharmony_ci args.clear(); 210d9f0492fSopenharmony_ci args.push_back(Str8ToStr16("-k")); 211d9f0492fSopenharmony_ci args.push_back(Str8ToStr16(keyPrefix.c_str())); 212d9f0492fSopenharmony_ci watcherManager->Dump(STDOUT_FILENO, args); 213d9f0492fSopenharmony_ci return 0; 214d9f0492fSopenharmony_ci } 215d9f0492fSopenharmony_ci 216d9f0492fSopenharmony_ci int TestWatchAgentDied(uint32_t watcherId) 217d9f0492fSopenharmony_ci { 218d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 219d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to get manager"); 220d9f0492fSopenharmony_ci auto remoteWatcher = watcherManager->GetRemoteWatcher(watcherId); 221d9f0492fSopenharmony_ci WATCHER_CHECK(remoteWatcher != nullptr, return -1, "Failed to get remote watcher"); 222d9f0492fSopenharmony_ci if (watcherManager->GetDeathRecipient() != nullptr) { 223d9f0492fSopenharmony_ci watcherManager->GetDeathRecipient()->OnRemoteDied(remoteWatcher->GetWatcher()->AsObject()); 224d9f0492fSopenharmony_ci } 225d9f0492fSopenharmony_ci EXPECT_EQ(watcherManager->GetRemoteWatcher(watcherId) == nullptr, 1); 226d9f0492fSopenharmony_ci return 0; 227d9f0492fSopenharmony_ci } 228d9f0492fSopenharmony_ci 229d9f0492fSopenharmony_ci int TestInvalid(const std::string &keyPrefix) 230d9f0492fSopenharmony_ci { 231d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 232d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to get manager"); 233d9f0492fSopenharmony_ci MessageParcel data; 234d9f0492fSopenharmony_ci MessageParcel reply; 235d9f0492fSopenharmony_ci MessageOption option; 236d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 237d9f0492fSopenharmony_ci data.WriteString(keyPrefix); 238d9f0492fSopenharmony_ci data.WriteUint32(0); 239d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 240d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::REFRESH_WATCHER) + 1, data, reply, option); 241d9f0492fSopenharmony_ci 242d9f0492fSopenharmony_ci data.WriteInterfaceToken(IWatcherManager::GetDescriptor()); 243d9f0492fSopenharmony_ci data.WriteString(keyPrefix); 244d9f0492fSopenharmony_ci watcherManager->OnRemoteRequest( 245d9f0492fSopenharmony_ci static_cast<uint32_t> (ParamWatcherInterfaceCode::REFRESH_WATCHER) + 1, data, reply, option); 246d9f0492fSopenharmony_ci return 0; 247d9f0492fSopenharmony_ci } 248d9f0492fSopenharmony_ci 249d9f0492fSopenharmony_ci int TestStop() 250d9f0492fSopenharmony_ci { 251d9f0492fSopenharmony_ci WatcherManagerPtr watcherManager = GetWatcherManager(); 252d9f0492fSopenharmony_ci WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to get manager"); 253d9f0492fSopenharmony_ci watcherManager->OnStop(); 254d9f0492fSopenharmony_ci watcherManager->Clear(); 255d9f0492fSopenharmony_ci return 0; 256d9f0492fSopenharmony_ci } 257d9f0492fSopenharmony_ci 258d9f0492fSopenharmony_ci WatcherManagerPtr GetWatcherManager() 259d9f0492fSopenharmony_ci { 260d9f0492fSopenharmony_ci static WatcherManagerPtr watcherManager_ = nullptr; 261d9f0492fSopenharmony_ci if (watcherManager_ == nullptr) { 262d9f0492fSopenharmony_ci watcherManager_ = new WatcherManager(0, true); 263d9f0492fSopenharmony_ci if (watcherManager_ == nullptr) { 264d9f0492fSopenharmony_ci return nullptr; 265d9f0492fSopenharmony_ci } 266d9f0492fSopenharmony_ci watcherManager_->OnStart(); 267d9f0492fSopenharmony_ci } 268d9f0492fSopenharmony_ci return watcherManager_; 269d9f0492fSopenharmony_ci } 270d9f0492fSopenharmony_ci}; 271d9f0492fSopenharmony_ci 272d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestAddWatcher_001, TestSize.Level0) 273d9f0492fSopenharmony_ci{ 274d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 275d9f0492fSopenharmony_ci uint32_t watcherId = 0; 276d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 277d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.test1", watcherId); 278d9f0492fSopenharmony_ci test.TestRefreshWatcher("test.permission.watcher.test1", watcherId); 279d9f0492fSopenharmony_ci test.TestProcessWatcherMessage("test.permission.watcher.test1", watcherId); 280d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.permission.watcher.test1"); 281d9f0492fSopenharmony_ci} 282d9f0492fSopenharmony_ci 283d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestAddWatcher_002, TestSize.Level0) 284d9f0492fSopenharmony_ci{ 285d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 286d9f0492fSopenharmony_ci uint32_t watcherId = 0; 287d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 288d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.test2", watcherId); 289d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.test2", watcherId); 290d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.test2", watcherId); 291d9f0492fSopenharmony_ci test.TestRefreshWatcher("test.permission.watcher.test2", watcherId); 292d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.permission.watcher.test2"); 293d9f0492fSopenharmony_ci} 294d9f0492fSopenharmony_ci 295d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestAddWatcher_003, TestSize.Level0) 296d9f0492fSopenharmony_ci{ 297d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 298d9f0492fSopenharmony_ci uint32_t watcherId = 0; 299d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 300d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.test3", watcherId); 301d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.permission.watcher.test3"); 302d9f0492fSopenharmony_ci} 303d9f0492fSopenharmony_ci 304d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestAddWatcher_004, TestSize.Level0) 305d9f0492fSopenharmony_ci{ 306d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 307d9f0492fSopenharmony_ci uint32_t watcherId = 0; 308d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 309d9f0492fSopenharmony_ci SystemWriteParam("test.watcher.test4", "1101"); 310d9f0492fSopenharmony_ci SystemWriteParam("test.watcher.test4.test", "1102"); 311d9f0492fSopenharmony_ci test.TestAddWatcher("test.watcher.test4*", watcherId); 312d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.watcher.test4*"); 313d9f0492fSopenharmony_ci} 314d9f0492fSopenharmony_ci 315d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestAddWatcher_005, TestSize.Level0) 316d9f0492fSopenharmony_ci{ 317d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 318d9f0492fSopenharmony_ci uint32_t watcherId = 0; 319d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 320d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.test5", watcherId); 321d9f0492fSopenharmony_ci SystemWriteParam("test.permission.watcher.test5", "1101"); 322d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.permission.watcher.test5"); 323d9f0492fSopenharmony_ci} 324d9f0492fSopenharmony_ci 325d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestDelWatcher_001, TestSize.Level0) 326d9f0492fSopenharmony_ci{ 327d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 328d9f0492fSopenharmony_ci uint32_t watcherId = 0; 329d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 330d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.testDel", watcherId); 331d9f0492fSopenharmony_ci test.TestDelWatcher("test.permission.watcher.testDel", watcherId); 332d9f0492fSopenharmony_ci test.TestDelRemoteWatcher(watcherId); 333d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.permission.watcher.testDel"); 334d9f0492fSopenharmony_ci} 335d9f0492fSopenharmony_ci 336d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestDiedWatcher_001, TestSize.Level0) 337d9f0492fSopenharmony_ci{ 338d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 339d9f0492fSopenharmony_ci uint32_t watcherId = 0; 340d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 341d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.testdied", watcherId); 342d9f0492fSopenharmony_ci test.TestDelWatcher("test.permission.watcher.testdied", watcherId); 343d9f0492fSopenharmony_ci test.TestWatchAgentDied(watcherId); 344d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.permission.watcher.testdied"); 345d9f0492fSopenharmony_ci} 346d9f0492fSopenharmony_ci 347d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestSendLocalChange_001, TestSize.Level0) 348d9f0492fSopenharmony_ci{ 349d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 350d9f0492fSopenharmony_ci uint32_t watcherId = 0; 351d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 352d9f0492fSopenharmony_ci test.TestAddWatcher("test.watcher*", watcherId); 353d9f0492fSopenharmony_ci test.TestAddWatcher("test.watcher.", watcherId); 354d9f0492fSopenharmony_ci test.TestWatchAgentDump("test.watcher."); 355d9f0492fSopenharmony_ci} 356d9f0492fSopenharmony_ci 357d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestWatchProxy_001, TestSize.Level0) 358d9f0492fSopenharmony_ci{ 359d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 360d9f0492fSopenharmony_ci test.TestWatchProxy("test.permission.watcher.test1", "watcherId"); 361d9f0492fSopenharmony_ci} 362d9f0492fSopenharmony_ci 363d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestInvalid_001, TestSize.Level0) 364d9f0492fSopenharmony_ci{ 365d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 366d9f0492fSopenharmony_ci test.TestInvalid("test.permission.watcher.test1"); 367d9f0492fSopenharmony_ci} 368d9f0492fSopenharmony_ci 369d9f0492fSopenharmony_ciHWTEST_F(WatcherProxyUnitTest, Init_TestStop_001, TestSize.Level0) 370d9f0492fSopenharmony_ci{ 371d9f0492fSopenharmony_ci WatcherProxyUnitTest test; 372d9f0492fSopenharmony_ci uint32_t watcherId = 0; 373d9f0492fSopenharmony_ci test.TestAddRemoteWatcher(getpid(), watcherId); 374d9f0492fSopenharmony_ci test.TestAddWatcher("test.permission.watcher.stop", watcherId); 375d9f0492fSopenharmony_ci test.TestStop(); 376d9f0492fSopenharmony_ci}