• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "display_event_monitor.h"
20 #include "mmi_log.h"
21 #include "mock.h"
22 
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "DisplayEventMonitorTest"
25 
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 using namespace testing::ext;
30 using namespace testing;
31 } // namespace
32 
33 class DisplayEventMonitorTest : public testing::Test {
34 public:
35     static void SetUpTestCase(void);
36     static void TearDownTestCase(void);
37 
38     static inline std::shared_ptr<MessageParcelMock> messageParcelMock_ = nullptr;
39 };
40 
SetUpTestCase(void)41 void DisplayEventMonitorTest::SetUpTestCase(void)
42 {
43     messageParcelMock_ = std::make_shared<MessageParcelMock>();
44     MessageParcelMock::messageParcel = messageParcelMock_;
45 }
TearDownTestCase()46 void DisplayEventMonitorTest::TearDownTestCase()
47 {
48     MessageParcelMock::messageParcel = nullptr;
49     messageParcelMock_ = nullptr;
50 }
51 
52 /**
53  * @tc.name: DisplayEventMonitorTest_UpdateShieldStatusOnScreenOn_001
54  * @tc.desc: Test the funcation UpdateShieldStatusOnScreenOn
55  * @tc.type: FUNC
56  * @tc.require:
57  */
58 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_UpdateShieldStatusOnScreenOn_001, TestSize.Level1)
59 {
60     CALL_TEST_DEBUG;
61     DisplayEventMonitor displayEventMonitor;
62     displayEventMonitor.shieldModeBeforeSreenOff_ = 0;
63     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.UpdateShieldStatusOnScreenOn());
64     displayEventMonitor.shieldModeBeforeSreenOff_ = 1;
65     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.UpdateShieldStatusOnScreenOn());
66     displayEventMonitor.shieldModeBeforeSreenOff_ = -1;
67     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.UpdateShieldStatusOnScreenOn());
68 }
69 
70 /**
71  * @tc.name: DisplayEventMonitorTest_UpdateShieldStatusOnScreenOff_001
72  * @tc.desc: Test the funcation UpdateShieldStatusOnScreenOff
73  * @tc.type: FUNC
74  * @tc.require:
75  */
76 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_UpdateShieldStatusOnScreenOff_001, TestSize.Level1)
77 {
78     CALL_TEST_DEBUG;
79     DisplayEventMonitor displayEventMonitor;
80     displayEventMonitor.shieldModeBeforeSreenOff_ = 10;
81     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.UpdateShieldStatusOnScreenOff());
82     displayEventMonitor.shieldModeBeforeSreenOff_ = 5;
83     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.UpdateShieldStatusOnScreenOff());
84     displayEventMonitor.shieldModeBeforeSreenOff_ = -1;
85     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.UpdateShieldStatusOnScreenOff());
86 }
87 
88 /**
89  * @tc.name: DisplayEventMonitorTest_InitCommonEventSubscriber_001
90  * @tc.desc: Test the funcation InitCommonEventSubscriber
91  * @tc.type: FUNC
92  * @tc.require:
93  */
94 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_InitCommonEventSubscriber_001, TestSize.Level1)
95 {
96     CALL_TEST_DEBUG;
97     DisplayEventMonitor displayEventMonitor;
98     displayEventMonitor.hasInit_ = true;
99     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.InitCommonEventSubscriber());
100 }
101 
102 /**
103  * @tc.name: DisplayEventMonitorTest_InitCommonEventSubscriber_002
104  * @tc.desc: Test the funcation InitCommonEventSubscriber
105  * @tc.type: FUNC
106  * @tc.require:
107  */
108 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_InitCommonEventSubscriber_002, TestSize.Level1)
109 {
110     CALL_TEST_DEBUG;
111     DisplayEventMonitor displayEventMonitor;
112     displayEventMonitor.hasInit_ = false;
113     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.InitCommonEventSubscriber());
114     ASSERT_TRUE(displayEventMonitor.hasInit_);
115 }
116 
117 /**
118  * @tc.name: DisplayEventMonitorTest_IsCommonEventSubscriberInit_001
119  * @tc.desc: Test the funcation IsCommonEventSubscriberInit
120  * @tc.type: FUNC
121  * @tc.require:
122  */
123 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_IsCommonEventSubscriberInit_001, TestSize.Level1)
124 {
125     CALL_TEST_DEBUG;
126     DisplayEventMonitor displayEventMonitor;
127     displayEventMonitor.hasInit_ = true;
128     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.IsCommonEventSubscriberInit());
129     displayEventMonitor.hasInit_ = false;
130     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.IsCommonEventSubscriberInit());
131 }
132 
133 /**
134  * @tc.name: DisplayEventMonitorTest_SendCancelEventWhenLock_001
135  * @tc.desc: Test the funcation InitCommonEventSubscriber
136  * @tc.type: FUNC
137  * @tc.require:
138  */
139 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_SendCancelEventWhenLock_001, TestSize.Level1)
140 {
141     CALL_TEST_DEBUG;
142     DisplayEventMonitor displayEventMonitor;
143     EXPECT_NO_FATAL_FAILURE(displayEventMonitor.SendCancelEventWhenLock());
144 }
145 } // namespace MMI
146 } // namespace OHOS