• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
RunningLockTest()34     RunningLockTest()
35     {
36         sptr<PowerMgrService> service = DelayedSpSingleton<PowerMgrService>::GetInstance();
37         service->OnStart();
38         stub_ = static_cast<PowerMgrStub*>(service);
39     }
40 
41     ~RunningLockTest() = default;
42 
TestRunningLockInnerExisit(sptr<IRemoteObject> & token,RunningLockInfo & runningLockInfo)43     void TestRunningLockInnerExisit(sptr<IRemoteObject>& token, RunningLockInfo& runningLockInfo)
44     {
45         auto lockMap = runningLockMgr_->GetRunningLockMap();
46         auto iterator = lockMap.find(token);
47         ASSERT_TRUE(iterator != lockMap.end());
48         auto runningLockInner = iterator->second;
49         ASSERT_TRUE(runningLockInner != nullptr);
50         ASSERT_TRUE(runningLockInner->GetType() == runningLockInfo.type);
51         ASSERT_TRUE((runningLockInfo.name).compare(runningLockInner->GetName()) == 0);
52     }
53 
TestRunningLockInnerNoExisit(sptr<IRemoteObject> & token)54     void TestRunningLockInnerNoExisit(sptr<IRemoteObject>& token)
55     {
56         auto lockMap = runningLockMgr_->GetRunningLockMap();
57         auto iterator = lockMap.find(token);
58         ASSERT_TRUE(iterator == lockMap.end());
59     }
60 
DumpRunningLockInfo()61     inline void DumpRunningLockInfo()
62     {
63         std::system("hidumper -s 3301 -a -runninglock");
64     }
65 
66     static std::shared_ptr<RunningLockMgr> runningLockMgr_;
67 protected:
68     sptr<PowerMgrStub> stub_ {nullptr};
69 };
70 } // namespace PowerMgr
71 } // namespace OHOS
72 #endif // POWERMGR_RUNNING_LOCK_TEST_H
73