• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
28 namespace OHOS {
29 namespace PowerMgr {
30 class RunningLockTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
TearDownTestCase(void)33     static void TearDownTestCase(void) {}
SetUp()34     void SetUp() {}
TearDown()35     void TearDown() {}
36 
TestRunningLockInnerExisit(sptr<IRemoteObject> & token,RunningLockInfo & runningLockInfo)37     void TestRunningLockInnerExisit(sptr<IRemoteObject>& token, RunningLockInfo& runningLockInfo)
38     {
39         auto lockMap = runningLockMgr_->GetRunningLockMap();
40         auto iterator = lockMap.find(token);
41         ASSERT_TRUE(iterator != lockMap.end());
42         auto runningLockInner = iterator->second;
43         ASSERT_TRUE(runningLockInner != nullptr);
44         ASSERT_TRUE(runningLockInner->GetRunningLockInfo().type == runningLockInfo.type);
45         ASSERT_TRUE((runningLockInfo.name).compare(runningLockInner->GetRunningLockName()) == 0);
46     }
47 
TestRunningLockInnerNoExisit(sptr<IRemoteObject> & token)48     void TestRunningLockInnerNoExisit(sptr<IRemoteObject>& token)
49     {
50         auto lockMap = runningLockMgr_->GetRunningLockMap();
51         auto iterator = lockMap.find(token);
52         ASSERT_TRUE(iterator == lockMap.end());
53     }
54 
DumpRunningLockInfo()55     inline void DumpRunningLockInfo()
56     {
57         system("hidumper -s 3301 -a -runninglock");
58     }
59 
60     static std::shared_ptr<RunningLockMgr> runningLockMgr_;
61     static sptr<PowerMgrService> pmsTest_;
62 };
63 } // namespace PowerMgr
64 } // namespace OHOS
65 #endif // POWERMGR_RUNNING_LOCK_TEST_H
66