• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 "running_lock_test.h"
17 
18 #include <ipc_skeleton.h>
19 
20 #include "actions/irunning_lock_action.h"
21 #include "power_mgr_service.h"
22 #include "running_lock_mgr.h"
23 #include "power_log.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS::PowerMgr;
27 using namespace OHOS;
28 using namespace std;
29 
30 namespace {
31 constexpr int32_t US_PER_MS = 1000;
32 constexpr int32_t app0Uid = 8;
33 constexpr int32_t app1Uid = 9;
34 }
35 
36 namespace {
37 /**
38  * @tc.name: RunningLockTest001
39  * @tc.desc: Test RunningLockInnerKit function, connect PowerMgrService and call member function.
40  * @tc.type: FUNC
41  */
42 HWTEST_F (RunningLockTest, RunningLockTest001, TestSize.Level0)
43 {
44     POWER_HILOGI(LABEL_TEST, "RunningLockTest001 start");
45     auto& powerMgrClient = PowerMgrClient::GetInstance();
46     auto runningLock1 = powerMgrClient.CreateRunningLock("runninglock1", RunningLockType::RUNNINGLOCK_SCREEN);
47     ASSERT_TRUE(runningLock1 != nullptr);
48 
49     ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
50     runningLock1->Lock();
51     ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true";
52 
53     runningLock1->UnLock();
54     ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
55     POWER_HILOGI(LABEL_TEST, "RunningLockTest001 end");
56 }
57 
58 /**
59  * @tc.name: RunningLockTest002
60  * @tc.desc: Test RunningLockInnerKit function, timeout lock.
61  * @tc.type: FUNC
62  */
63 HWTEST_F (RunningLockTest, RunningLockTest002, TestSize.Level1)
64 {
65     POWER_HILOGI(LABEL_TEST, "RunningLockTest002 start");
66     auto& powerMgrClient = PowerMgrClient::GetInstance();
67     auto runningLock1 = powerMgrClient.CreateRunningLock("runninglock1", RunningLockType::RUNNINGLOCK_SCREEN);
68     ASSERT_TRUE(runningLock1 != nullptr);
69     ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
70     runningLock1->Lock();
71     ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true";
72     runningLock1->UnLock();
73     ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
74     POWER_HILOGI(LABEL_TEST, "RunningLockTest002 1");
75     // lock 50ms
76     runningLock1->Lock(50);
77     usleep(4000);
78     POWER_HILOGI(LABEL_TEST, "RunningLockTest002 2");
79     ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true";
80     usleep(1000);
81     POWER_HILOGI(LABEL_TEST, "RunningLockTest002 3");
82     ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true";
83     // wait 100ms
84     usleep(100000);
85     POWER_HILOGI(LABEL_TEST, "RunningLockTest002 end");
86 }
87 
88 /**
89  * @tc.name: RunningLockTest003
90  * @tc.desc: Test RunningLockInnerKit function, timeout lock.
91  * @tc.type: FUNC
92  */
93 HWTEST_F (RunningLockTest, RunningLockTest003, TestSize.Level1)
94 {
95     POWER_HILOGI(LABEL_TEST, "RunningLockTest003 start");
96     if (false) {
97         auto& powerMgrClient = PowerMgrClient::GetInstance();
98         auto runningLock1 = powerMgrClient.CreateRunningLock("runninglock005",
99             RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL);
100         ASSERT_TRUE(runningLock1 != nullptr);
101         ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
102         // after 8ms unlock
103         runningLock1->Lock(30);
104         runningLock1->Lock(80);
105         POWER_HILOGI(LABEL_TEST, "RunningLockTest003 1");
106         usleep(50000);
107         ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true";
108         usleep(50000);
109         ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
110         // no unlock
111         POWER_HILOGI(LABEL_TEST, "RunningLockTest003 2");
112         runningLock1->Lock(2);
113         runningLock1->Lock(3);
114         runningLock1->Lock();
115         POWER_HILOGI(LABEL_TEST, "RunningLockTest003 3");
116         usleep(8000);
117         ASSERT_TRUE(runningLock1->IsUsed()) << "runningLock1->IsUsed() != true";
118         // after 3ms unlock
119         runningLock1->Lock(30);
120         POWER_HILOGI(LABEL_TEST, "RunningLockTest003 4");
121         usleep(50000);
122         ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
123         runningLock1->Lock(5);
124         runningLock1->UnLock();
125         ASSERT_TRUE(!runningLock1->IsUsed()) << "runningLock1->IsUsed() != false";
126         POWER_HILOGI(LABEL_TEST, "RunningLockTest003 end");
127     }
128     POWER_HILOGI(LABEL_TEST, "RunningLockTest003 end");
129 }
130 
131 /**
132  * @tc.name: RunningLockTest004
133  * @tc.desc: Test CreateRunningLock function.
134  * @tc.type: FUNC
135  * @tc.require: issueI6NWQD
136  */
137 HWTEST_F (RunningLockTest, RunningLockTest004, TestSize.Level1)
138 {
139     POWER_HILOGI(LABEL_TEST, "RunningLockTest004 start");
140     auto& powerMgrClient = PowerMgrClient::GetInstance();
141     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
142         "background", RunningLockType::RUNNINGLOCK_BACKGROUND);
143     EXPECT_NE(runningLock, nullptr);
144 
145     runningLock = powerMgrClient.CreateRunningLock("backgroudPhone", RunningLockType::RUNNINGLOCK_BACKGROUND_PHONE);
146     EXPECT_NE(runningLock, nullptr);
147 
148     runningLock = powerMgrClient.CreateRunningLock(
149         "backgroudNatification", RunningLockType::RUNNINGLOCK_BACKGROUND_NOTIFICATION);
150     EXPECT_NE(runningLock, nullptr);
151 
152     runningLock = powerMgrClient.CreateRunningLock("backgroudAudio", RunningLockType::RUNNINGLOCK_BACKGROUND_AUDIO);
153     EXPECT_NE(runningLock, nullptr);
154 
155     runningLock = powerMgrClient.CreateRunningLock("backgroudSport", RunningLockType::RUNNINGLOCK_BACKGROUND_SPORT);
156     EXPECT_NE(runningLock, nullptr);
157 
158     runningLock = powerMgrClient.CreateRunningLock(
159         "backgroudNavigation", RunningLockType::RUNNINGLOCK_BACKGROUND_NAVIGATION);
160     EXPECT_NE(runningLock, nullptr);
161 
162     runningLock = powerMgrClient.CreateRunningLock("backgroudTask", RunningLockType::RUNNINGLOCK_BACKGROUND_TASK);
163     EXPECT_NE(runningLock, nullptr);
164 
165     runningLock = powerMgrClient.CreateRunningLock("butt", RunningLockType::RUNNINGLOCK_BUTT);
166     EXPECT_EQ(runningLock, nullptr);
167     POWER_HILOGI(LABEL_TEST, "RunningLockTest004 end");
168 }
169 
170 /**
171  * @tc.name: RunningLockTest005
172  * @tc.desc: Test ProxyRunningLock function.
173  * @tc.type: FUNC
174  * @tc.require: issueI6S0YY
175  */
176 HWTEST_F (RunningLockTest, RunningLockTest005, TestSize.Level1)
177 {
178     POWER_HILOGI(LABEL_TEST, "RunningLockTest005 start");
179     auto& powerMgrClient = PowerMgrClient::GetInstance();
180     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
181         "background.test005", RunningLockType::RUNNINGLOCK_BACKGROUND);
182     ASSERT_NE(runningLock, nullptr);
183 
184     pid_t curUid = getuid();
185     pid_t curPid = getpid();
186     runningLock->Lock();
187     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
188     EXPECT_FALSE(runningLock->IsUsed());
189     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
190     runningLock->UnLock();
191     POWER_HILOGI(LABEL_TEST, "RunningLockTest005 end");
192 }
193 
194 /**
195  * @tc.name: RunningLockTest006
196  * @tc.desc: Test ProxyRunningLock function.
197  * @tc.type: FUNC
198  * @tc.require: issueI6S0YY
199  */
200 HWTEST_F (RunningLockTest, RunningLockTest006, TestSize.Level1)
201 {
202     POWER_HILOGI(LABEL_TEST, "RunningLockTest006 start");
203     auto& powerMgrClient = PowerMgrClient::GetInstance();
204     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
205         "background.test006", RunningLockType::RUNNINGLOCK_SCREEN);
206     ASSERT_NE(runningLock, nullptr);
207 
208     pid_t curUid = getuid();
209     pid_t curPid = getpid();
210 
211     runningLock->Lock(-1);
212     EXPECT_TRUE(runningLock->IsUsed());
213 
214     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
215     EXPECT_FALSE(runningLock->IsUsed());
216 
217     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
218     EXPECT_TRUE(runningLock->IsUsed());
219     runningLock->UnLock();
220     POWER_HILOGI(LABEL_TEST, "RunningLockTest006 end");
221 }
222 
223 /**
224  * @tc.name: RunningLockTest007
225  * @tc.desc: Test ProxyRunningLock function.
226  * @tc.type: FUNC
227  * @tc.require: issueI6S0YY
228  */
229 HWTEST_F (RunningLockTest, RunningLockTest007, TestSize.Level1)
230 {
231     POWER_HILOGI(LABEL_TEST, "RunningLockTest007 start");
232     auto& powerMgrClient = PowerMgrClient::GetInstance();
233     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
234         "background.test007", RunningLockType::RUNNINGLOCK_SCREEN);
235     ASSERT_NE(runningLock, nullptr);
236 
237     pid_t curUid = getuid();
238     pid_t curPid = getpid();
239     int32_t timeoutMs = 1000;
240 
241     runningLock->Lock(timeoutMs);
242     EXPECT_TRUE(runningLock->IsUsed());
243 
244     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
245     EXPECT_FALSE(runningLock->IsUsed());
246 
247     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
248     runningLock->UnLock();
249     EXPECT_FALSE(runningLock->IsUsed());
250     POWER_HILOGI(LABEL_TEST, "RunningLockTest007 end");
251 }
252 
253 /**
254  * @tc.name: RunningLockTest008
255  * @tc.desc: Test ProxyRunningLock function, create runninglock first, then proxy
256  * @tc.type: FUNC
257  * @tc.require: issueI6S0YY
258  */
259 HWTEST_F (RunningLockTest, RunningLockTest008, TestSize.Level1)
260 {
261     POWER_HILOGI(LABEL_TEST, "RunningLockTest008 start");
262     auto& powerMgrClient = PowerMgrClient::GetInstance();
263 
264     pid_t curUid = getuid();
265     pid_t curPid = getpid();
266     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
267 
268     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
269         "background.test008", RunningLockType::RUNNINGLOCK_BACKGROUND);
270     ASSERT_NE(runningLock, nullptr);
271     runningLock->Lock();
272     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
273     runningLock->UnLock();
274     POWER_HILOGI(LABEL_TEST, "RunningLockTest008 end");
275 }
276 
277 /**
278  * @tc.name: RunningLockTest009
279  * @tc.desc: Test ProxyRunningLock function.
280  * @tc.type: FUNC
281  * @tc.require: issueI6S0YY
282  */
283 HWTEST_F (RunningLockTest, RunningLockTest009, TestSize.Level1)
284 {
285     POWER_HILOGI(LABEL_TEST, "RunningLockTest009 start");
286     auto& powerMgrClient = PowerMgrClient::GetInstance();
287     std::shared_ptr<RunningLock> screenRunningLock = powerMgrClient.CreateRunningLock(
288         "screen.test009", RunningLockType::RUNNINGLOCK_SCREEN);
289     ASSERT_NE(screenRunningLock, nullptr);
290 #ifdef HAS_SENSORS_SENSOR_PART
291     std::shared_ptr<RunningLock> proximityRunningLock = powerMgrClient.CreateRunningLock(
292         "proximity.test009", RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL);
293     ASSERT_NE(proximityRunningLock, nullptr);
294 #endif
295 
296     pid_t curUid = getuid();
297     pid_t curPid = getpid();
298     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
299 
300     screenRunningLock->Lock();
301     EXPECT_TRUE(screenRunningLock->IsUsed());
302     screenRunningLock->UnLock();
303 
304 #ifdef HAS_SENSORS_SENSOR_PART
305     proximityRunningLock->Lock();
306     EXPECT_TRUE(proximityRunningLock->IsUsed());
307     proximityRunningLock->UnLock();
308 #endif
309 
310     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
311     POWER_HILOGI(LABEL_TEST, "RunningLockTest009 end");
312 }
313 
314 /**
315  * @tc.name: RunningLockTest010
316  * @tc.desc: Test ProxyRunningLock function, pid is invalid
317  * @tc.type: FUNC
318  * @tc.require: issueI6S0YY
319  */
320 HWTEST_F (RunningLockTest, RunningLockTest010, TestSize.Level1)
321 {
322     POWER_HILOGI(LABEL_TEST, "RunningLockTest010 start");
323     pid_t curUid = 1;
324     pid_t curPid = -1;
325     auto& powerMgrClient = PowerMgrClient::GetInstance();
326     EXPECT_FALSE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
327     EXPECT_FALSE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
328     POWER_HILOGI(LABEL_TEST, "RunningLockTest010 end");
329 }
330 
331 /**
332  * @tc.name: RunningLockTest011
333  * @tc.desc: Test RunningLockProxt AddRunningLock function
334  * @tc.type: FUNC
335  * @tc.require: issueI7405P
336  */
337 HWTEST_F (RunningLockTest, RunningLockTest011, TestSize.Level1)
338 {
339     POWER_HILOGI(LABEL_TEST, "RunningLockTest011 start");
340     auto runninglockProxy = std::make_shared<RunningLockProxy>();
341     pid_t pid = 1;
342     pid_t uid = -1;
343     sptr<IRemoteObject> remoteObj = new RunningLockTokenStub();
344     runninglockProxy->AddRunningLock(0, 0, remoteObj);
345     EXPECT_TRUE(runninglockProxy->IncreaseProxyCnt(pid, uid));
346     EXPECT_TRUE(runninglockProxy->DecreaseProxyCnt(pid, uid));
347     POWER_HILOGI(LABEL_TEST, "RunningLockTest011 end");
348 }
349 
350 /**
351  * @tc.name: RunningLockTest012
352  * @tc.desc: Test RunningLockProxt RemoveRunningLock function
353  * @tc.type: FUNC
354  * @tc.require: issueI7405P
355  */
356 HWTEST_F (RunningLockTest, RunningLockTest012, TestSize.Level1)
357 {
358     POWER_HILOGI(LABEL_TEST, "RunningLockTest012 start");
359     auto runninglockProxy = std::make_shared<RunningLockProxy>();
360     pid_t pid = 1;
361     pid_t uid = -1;
362     sptr<IRemoteObject> remoteObj = new RunningLockTokenStub();
363     sptr<IRemoteObject> remoteObj2 = nullptr;
364     runninglockProxy->AddRunningLock(pid, uid, remoteObj);
365     runninglockProxy->RemoveRunningLock(pid, uid, remoteObj2);
366     EXPECT_TRUE(runninglockProxy->IncreaseProxyCnt(0, 0));
367     EXPECT_TRUE(runninglockProxy->DecreaseProxyCnt(0, 0));
368     POWER_HILOGI(LABEL_TEST, "RunningLockTest012 end");
369 }
370 
371 /**
372  * @tc.name: RunningLockTest013
373  * @tc.desc: Test RunningLockProxt RemoveRunningLock function
374  * @tc.type: FUNC
375  * @tc.require: issueI7405P
376  */
377 HWTEST_F (RunningLockTest, RunningLockTest013, TestSize.Level1)
378 {
379     POWER_HILOGI(LABEL_TEST, "RunningLockTest013 start");
380     auto runninglockProxy = std::make_shared<RunningLockProxy>();
381     pid_t pid = 1;
382     pid_t uid = -1;
383     sptr<IRemoteObject> remoteObj = new RunningLockTokenStub();
384     runninglockProxy->RemoveRunningLock(pid, uid, remoteObj);
385     EXPECT_TRUE(runninglockProxy->IncreaseProxyCnt(pid, uid));
386     POWER_HILOGI(LABEL_TEST, "RunningLockTest013 end");
387 }
388 
389 /**
390  * @tc.name: RunningLockTest014
391  * @tc.desc: Test ProxyRunningLocks function
392  * @tc.type: FUNC
393  * @tc.require: issueI7MNRN
394  */
395 HWTEST_F(RunningLockTest, RunningLockTest014, TestSize.Level1)
396 {
397     POWER_HILOGI(LABEL_TEST, "RunningLockTest014 start");
398     pid_t curUid = getuid();
399     pid_t curPid = getpid();
400     std::vector<std::pair<pid_t, pid_t>> processInfos;
401     processInfos.push_back(std::pair<pid_t, pid_t>(curPid, curUid));
402     auto& powerMgrClient = PowerMgrClient::GetInstance();
403     EXPECT_TRUE(powerMgrClient.ProxyRunningLocks(true, processInfos));
404     POWER_HILOGI(LABEL_TEST, "RunningLockTest014 end");
405 }
406 
407 /**
408  * @tc.name: RunningLockTest015
409  * @tc.desc: Test Recover function
410  * @tc.type: FUNC
411  * @tc.require:
412  */
413 HWTEST_F(RunningLockTest, RunningLockTest015, TestSize.Level1)
414 {
415     POWER_HILOGI(LABEL_TEST, "RunningLockTest015 start");
416     auto& powerMgrClient = PowerMgrClient::GetInstance();
417     auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
418     pms->OnStart();
419     auto runningLockMgr = pms->GetRunningLockMgr();
420     sptr<IPowerMgr> ptr;
421     ptr.ForceSetRefPtr(static_cast<IPowerMgr*>(pms.GetRefPtr()));
422     pms.GetRefPtr()->IncStrongRef(pms.GetRefPtr());
423     RunningLock runninglock1(ptr, "runninglock_recover_test", RunningLockType::RUNNINGLOCK_SCREEN);
424     runninglock1.Init();
425     const auto& infos = runningLockMgr->GetRunningLockMap();
__anon6a96eb380302(const auto& pair) 426     const auto iter = std::find_if(infos.begin(), infos.end(), [](const auto& pair) {
427         return pair.second->GetName() == "runninglock_recover_test";
428     });
429     EXPECT_TRUE(iter != infos.end());
430     const sptr<IRemoteObject> token = iter->first;
431     runningLockMgr->ReleaseLock(token);
432     EXPECT_TRUE(infos.count(token) == 0);
433     runninglock1.Recover(ptr);
434     EXPECT_TRUE(infos.count(token) > 0);
435     POWER_HILOGI(LABEL_TEST, "RunningLockTest015 end");
436 }
437 
438 /**
439  * @tc.name: RunningLockTest016
440  * @tc.desc: Test ProxyRunningLock function
441  * @tc.type: FUNC
442  * @tc.require
443  */
444 HWTEST_F (RunningLockTest, RunningLockTest016, TestSize.Level1)
445 {
446     POWER_HILOGI(LABEL_TEST, "RunningLockTest016 start");
447     auto& powerMgrClient = PowerMgrClient::GetInstance();
448 
449     pid_t curUid = getuid();
450     pid_t curPid = getpid();
451 
452     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
453         "background.test016", RunningLockType::RUNNINGLOCK_BACKGROUND);
454     ASSERT_NE(runningLock, nullptr);
455     runningLock->Lock();
456     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, curUid));
457     EXPECT_FALSE(runningLock->IsUsed());
458     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, curUid));
459     EXPECT_TRUE(runningLock->IsUsed());
460     runningLock->UnLock();
461     POWER_HILOGI(LABEL_TEST, "RunningLockTest016 end");
462 }
463 
464 /**
465  * @tc.name: RunningLockTest017
466  * @tc.desc: Test UpdateWorkSource function
467  * @tc.type: FUNC
468  * @tc.require
469  */
470 HWTEST_F (RunningLockTest, RunningLockTest017, TestSize.Level1)
471 {
472     POWER_HILOGI(LABEL_TEST, "RunningLockTest017 start");
473     auto& powerMgrClient = PowerMgrClient::GetInstance();
474 
475     pid_t curUid = getuid();
476     pid_t curPid = getpid();
477 
478     std::shared_ptr<RunningLock> runningLock = powerMgrClient.CreateRunningLock(
479         "background.test017", RunningLockType::RUNNINGLOCK_BACKGROUND);
480     ASSERT_NE(runningLock, nullptr);
481     runningLock->Lock();
482     std::vector<int32_t> workSource { 0 };
483     EXPECT_TRUE(runningLock->UpdateWorkSource(workSource) == 0);
484     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(true, curPid, 0));
485     EXPECT_FALSE(runningLock->IsUsed());
486     EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, 0));
487     EXPECT_TRUE(runningLock->IsUsed());
488     runningLock->UnLock();
489     POWER_HILOGI(LABEL_TEST, "RunningLockTest017 end");
490 }
491 
492 /**
493  * @tc.name: RunningLockTest018
494  * @tc.desc: Test UpdateWorkSource function
495  * @tc.type: FUNC
496  * @tc.require
497  */
498 HWTEST_F (RunningLockTest, RunningLockTest018, TestSize.Level1)
499 {
500     POWER_HILOGI(LABEL_TEST, "RunningLockTest018 start");
501     auto runninglockProxy = std::make_shared<RunningLockProxy>();
502     pid_t pid = 1;
503     pid_t uid = -1;
504     sptr<IRemoteObject> remoteObj = new RunningLockTokenStub();
505     sptr<IRemoteObject> remoteObj2 = nullptr;
506     runninglockProxy->AddRunningLock(pid, uid, remoteObj);
507     runninglockProxy->RemoveRunningLock(pid, uid, remoteObj2);
508 
509     EXPECT_TRUE(runninglockProxy->UpdateWorkSource(pid, uid, remoteObj, {{0, {"test", false}}}));
510     runninglockProxy->RemoveRunningLock(pid, uid, remoteObj);
511     EXPECT_TRUE(runninglockProxy->IncreaseProxyCnt(pid, uid));
512     EXPECT_TRUE(runninglockProxy->DecreaseProxyCnt(pid, uid));
513     POWER_HILOGI(LABEL_TEST, "RunningLockTest018 end");
514 }
515 
516 /**
517  * @tc.name: RunningLockTest019
518  * @tc.desc: Test UpdateWorkSource function
519  * @tc.type: FUNC
520  * @tc.require
521  */
522 HWTEST_F (RunningLockTest, RunningLockTest019, TestSize.Level1)
523 {
524     POWER_HILOGI(LABEL_TEST, "RunningLockTest019 start");
525     auto runninglockProxy = std::make_shared<RunningLockProxy>();
526     pid_t pid = 1;
527     pid_t uid = -1;
528     sptr<IRemoteObject> remoteObj = new RunningLockTokenStub();
529     sptr<IRemoteObject> remoteObj2 = nullptr;
530     runninglockProxy->AddRunningLock(pid, uid, remoteObj);
531     runninglockProxy->RemoveRunningLock(pid, uid, remoteObj2);
532 
533     EXPECT_TRUE(runninglockProxy->UpdateWorkSource(pid, uid, remoteObj, {{0, {"test019", false}}}));
534     EXPECT_TRUE(runninglockProxy->UpdateProxyState(pid, uid, remoteObj, true));
535     EXPECT_TRUE(runninglockProxy->UpdateProxyState(pid, uid, remoteObj, false));
536     runninglockProxy->RemoveRunningLock(pid, uid, remoteObj);
537     EXPECT_TRUE(runninglockProxy->IncreaseProxyCnt(pid, uid));
538     EXPECT_TRUE(runninglockProxy->DecreaseProxyCnt(pid, uid));
539     POWER_HILOGI(LABEL_TEST, "RunningLockTest019 end");
540 }
541 } // namespace