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_ = false;
99 EXPECT_NO_FATAL_FAILURE(displayEventMonitor.InitCommonEventSubscriber());
100 displayEventMonitor.hasInit_ = true;
101 EXPECT_NO_FATAL_FAILURE(displayEventMonitor.InitCommonEventSubscriber());
102 }
103
104 /**
105 * @tc.name: DisplayEventMonitorTest_IsCommonEventSubscriberInit_001
106 * @tc.desc: Test the funcation IsCommonEventSubscriberInit
107 * @tc.type: FUNC
108 * @tc.require:
109 */
110 HWTEST_F(DisplayEventMonitorTest, DisplayEventMonitorTest_IsCommonEventSubscriberInit_001, TestSize.Level1)
111 {
112 CALL_TEST_DEBUG;
113 DisplayEventMonitor displayEventMonitor;
114 displayEventMonitor.hasInit_ = true;
115 EXPECT_NO_FATAL_FAILURE(displayEventMonitor.IsCommonEventSubscriberInit());
116 displayEventMonitor.hasInit_ = false;
117 EXPECT_NO_FATAL_FAILURE(displayEventMonitor.IsCommonEventSubscriberInit());
118 }
119 } // namespace MMI
120 } // namespace OHOS