1 /*
2  * Copyright (c) 2021-2023 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 #ifndef POWERMGR_RUNNING_LOCK_TEST_H
17 #define POWERMGR_RUNNING_LOCK_TEST_H
18 
19 #include <map>
20 #include <memory>
21 #include <stdlib.h>
22 
23 #include <gtest/gtest.h>
24 
25 #include "power_mgr_client.h"
26 #include "power_mgr_service.h"
27 #include "running_lock_proxy.h"
28 #include "running_lock_token_stub.h"
29 
30 namespace OHOS {
31 namespace PowerMgr {
32 class RunningLockTest : public testing::Test {
33 public:
TestRunningLockInnerExisit(sptr<IRemoteObject> & token,RunningLockInfo & runningLockInfo)34     void TestRunningLockInnerExisit(sptr<IRemoteObject>& token, RunningLockInfo& runningLockInfo)
35     {
36         auto lockMap = runningLockMgr_->GetRunningLockMap();
37         auto iterator = lockMap.find(token);
38         ASSERT_TRUE(iterator != lockMap.end());
39         auto runningLockInner = iterator->second;
40         ASSERT_TRUE(runningLockInner != nullptr);
41         ASSERT_TRUE(runningLockInner->GetType() == runningLockInfo.type);
42         ASSERT_TRUE((runningLockInfo.name).compare(runningLockInner->GetName()) == 0);
43     }
44 
TestRunningLockInnerNoExisit(sptr<IRemoteObject> & token)45     void TestRunningLockInnerNoExisit(sptr<IRemoteObject>& token)
46     {
47         auto lockMap = runningLockMgr_->GetRunningLockMap();
48         auto iterator = lockMap.find(token);
49         ASSERT_TRUE(iterator == lockMap.end());
50     }
51 
DumpRunningLockInfo()52     inline void DumpRunningLockInfo()
53     {
54         system("hidumper -s 3301 -a -runninglock");
55     }
56 
57     static std::shared_ptr<RunningLockMgr> runningLockMgr_;
58     static sptr<PowerMgrService> pmsTest_;
59 };
60 } // namespace PowerMgr
61 } // namespace OHOS
62 #endif // POWERMGR_RUNNING_LOCK_TEST_H
63