• 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 #include "running_lock_hub_native_test.h"
17 
18 #include <fcntl.h>
19 #include <ipc_skeleton.h>
20 
21 #include <datetime_ex.h>
22 #include <input_manager.h>
23 #include <securec.h>
24 
25 #include "actions/irunning_lock_action.h"
26 #include "running_lock_hub.h"
27 #include "suspend_controller.h"
28 
29 using namespace testing::ext;
30 using namespace OHOS::PowerMgr;
31 using namespace OHOS;
32 using namespace std;
33 
SetUpTestCase()34 void RunningLockHubNativeTest::SetUpTestCase()
35 {
36 }
37 
38 namespace {
RunningSuspendCallback()39 void RunningSuspendCallback()
40 {
41 }
42 
43 /**
44  * @tc.name: RunningLockNative001
45  * @tc.desc: test Acquire and Release inrunningLockMgr
46  * @tc.type: FUNC
47  */
48 HWTEST_F(RunningLockHubNativeTest, RunningLockNative001, TestSize.Level0)
49 {
50     auto sc = std::make_shared<Suspend::SuspendController>();
51     auto runningLockHub = std::make_shared<Suspend::RunningLockHub>(sc);
52     runningLockHub->Acquire("777");
53     EXPECT_FALSE(runningLockHub->runningLockMap_.empty());
54     runningLockHub->Release("777");
55     runningLockHub->lockFd_ = static_cast<UniqueFd>(UNFD);
56     runningLockHub->Acquire("777");
57     runningLockHub->Release("777");
58     runningLockHub->Release("333");
59     EXPECT_TRUE(runningLockHub->runningLockMap_.empty());
60 }
61 
62 /**
63  * @tc.name: RunningLockNative001
64  * @tc.desc: test Suspend inrunningLockMgr
65  * @tc.type: FUNC
66  */
67 HWTEST_F(RunningLockHubNativeTest, RunningLockNative002, TestSize.Level0)
68 {
69     auto SuspendController = std::make_shared<Suspend::SuspendController>();
70     SuspendController->Wakeup();
71     SuspendController->Suspend(RunningSuspendCallback, RunningSuspendCallback, false);
72     SuspendController->Suspend(RunningSuspendCallback, RunningSuspendCallback, false);
73     EXPECT_FALSE(SuspendController->suspend_->WriteWakeupCount("77"));
74     SuspendController->suspend_->wakeupCountFd = static_cast<UniqueFd>(FD);
75     EXPECT_TRUE(SuspendController->suspend_->WriteWakeupCount("77"));
76     SuspendController->suspend_->wakeupCountFd =
77         UniqueFd(TEMP_FAILURE_RETRY(open(Suspend::RunningLockHub::LOCK_PATH, O_RDWR | O_CLOEXEC)));
78     EXPECT_TRUE(SuspendController->suspend_->WriteWakeupCount("77"));
79     SuspendController->IncSuspendBlockCounter();
80     SuspendController->IncSuspendBlockCounter();
81     SuspendController->DecSuspendBlockCounter();
82     SuspendController->DecSuspendBlockCounter();
83 }
84 } // namespace