• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <gtest/gtest.h>
17 
18 #include "device_event_monitor.h"
19 #include "mmi_log.h"
20 #include "common_event_data.h"
21 #include "common_event_manager.h"
22 #include "want.h"
23 
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "DeviceEventMonitorTest"
26 
27 namespace OHOS {
28 namespace MMI {
29 namespace {
30 using namespace testing::ext;
31 } // namespace
32 
33 class DeviceEventMonitorTest : public testing::Test {
34 public:
SetUpTestCase(void)35     static void SetUpTestCase(void) {}
TearDownTestCase(void)36     static void TearDownTestCase(void) {}
SetUp()37     void SetUp() {}
TearDown()38     void TearDown() {}
39 };
40 
41 
42 /**
43  * @tc.name: InitCommonEventSubscriber_001
44  * @tc.desc: Test the funcation InitCommonEventSubscriber
45  * @tc.type: FUNC
46  * @tc.require:
47  */
48 HWTEST_F(DeviceEventMonitorTest, InitCommonEventSubscriber_001, TestSize.Level1)
49 {
50     CALL_TEST_DEBUG;
51     DeviceEventMonitor deviceEventMonitor;
52     deviceEventMonitor.hasInit_ = true;
53     EXPECT_NO_FATAL_FAILURE(deviceEventMonitor.InitCommonEventSubscriber());
54 }
55 /**
56  * @tc.name: InitCommonEventSubscriber_002
57  * @tc.desc: Test the funcation InitCommonEventSubscriber
58  * @tc.type: FUNC
59  * @tc.require:
60  */
61 HWTEST_F(DeviceEventMonitorTest, InitCommonEventSubscriber_002, TestSize.Level1)
62 {
63     CALL_TEST_DEBUG;
64     DeviceEventMonitor deviceEventMonitor;
65     deviceEventMonitor.hasInit_ = false;
66     EXPECT_NO_FATAL_FAILURE(deviceEventMonitor.InitCommonEventSubscriber());
67 }
68 /**
69  * @tc.name: SetCallState_001
70  * @tc.desc: Test the funcation SetCallState
71  * @tc.type: FUNC
72  * @tc.require:
73  */
74 HWTEST_F(DeviceEventMonitorTest, SetCallState_001, TestSize.Level1)
75 {
76     CALL_TEST_DEBUG;
77     DeviceEventMonitor deviceEventMonitor;
78     EventFwk::CommonEventData ced;
79     EventFwk::Want want;
80     want.SetParam("slotId", 1);
81     want.SetParam("state", 1);
82     ced.SetWant(want);
83     deviceEventMonitor.hasHandleRingMute_ = true;
84     deviceEventMonitor.SetCallState(ced, 1);
85     ASSERT_EQ(deviceEventMonitor.callState_, -1);
86     want.SetParam("state", 4);
87     ced.SetWant(want);
88     EXPECT_NO_FATAL_FAILURE(deviceEventMonitor.SetCallState(ced, 1));
89     want.SetParam("state", 6);
90     ced.SetWant(want);
91     EXPECT_NO_FATAL_FAILURE(deviceEventMonitor.SetCallState(ced, 1));
92     deviceEventMonitor.hasHandleRingMute_ = false;
93     EXPECT_NO_FATAL_FAILURE(deviceEventMonitor.SetCallState(ced, 1));
94 }
95 
96 /**
97  * @tc.name: SetCallState_002
98  * @tc.desc: Test the funcation SetCallState
99  * @tc.type: FUNC
100  * @tc.require:
101  */
102 HWTEST_F(DeviceEventMonitorTest, SetCallState_002, TestSize.Level1)
103 {
104     CALL_TEST_DEBUG;
105     DeviceEventMonitor deviceEventMonitor;
106     EventFwk::CommonEventData ced;
107     EventFwk::Want want;
108     deviceEventMonitor.hasHandleRingMute_ = true;
109     want.SetParam("state", 1);
110     ced.SetWant(want);
111     deviceEventMonitor.SetCallState(ced, 1);
112     ASSERT_EQ(deviceEventMonitor.callState_, 1);
113 
114     want.SetParam("state", 5);
115     ced.SetWant(want);
116     deviceEventMonitor.SetCallState(ced, 1);
117     ASSERT_EQ(deviceEventMonitor.callState_, 5);
118 
119     want.SetParam("state", 4);
120     ced.SetWant(want);
121     deviceEventMonitor.SetCallState(ced, 1);
122     ASSERT_EQ(deviceEventMonitor.callState_, 4);
123 }
124 /**
125  * @tc.name: SetCallState_005
126  * @tc.desc: Test the funcation SetCallState
127  * @tc.type: FUNC
128  * @tc.require:
129  */
130 HWTEST_F(DeviceEventMonitorTest, SetCallState_005, TestSize.Level1)
131 {
132     CALL_TEST_DEBUG;
133     DeviceEventMonitor deviceEventMonitor;
134     EventFwk::CommonEventData ced;
135     EventFwk::Want want;
136     deviceEventMonitor.hasHandleRingMute_ = false;
137     want.SetParam("state", 4);
138     ced.SetWant(want);
139     deviceEventMonitor.SetCallState(ced, 1);
140     ASSERT_EQ(deviceEventMonitor.callState_, 4);
141     want.SetParam("state", 5);
142     ced.SetWant(want);
143     deviceEventMonitor.SetCallState(ced, 1);
144     ASSERT_EQ(deviceEventMonitor.callState_, 5);
145 }
146 
147 /**
148  * @tc.name: SetCallState_006
149  * @tc.desc: Test the funcation SetCallState
150  * @tc.type: FUNC
151  * @tc.require:
152  */
153 HWTEST_F(DeviceEventMonitorTest, SetCallState_006, TestSize.Level1)
154 {
155     CALL_TEST_DEBUG;
156     DeviceEventMonitor deviceEventMonitor;
157     EventFwk::CommonEventData ced;
158     EventFwk::Want want;
159     deviceEventMonitor.hasHandleRingMute_ = true;
160     want.SetParam("state", 1);
161     ced.SetWant(want);
162     deviceEventMonitor.SetCallState(ced, 1);
163     ASSERT_EQ(deviceEventMonitor.callState_, 1);
164     deviceEventMonitor.hasHandleRingMute_ = false;
165     deviceEventMonitor.SetCallState(ced, 1);
166 }
167 /**
168  * @tc.name: SetCallState_003
169  * @tc.desc: Test the funcation SetCallState
170  * @tc.type: FUNC
171  * @tc.require:
172  */
173 HWTEST_F(DeviceEventMonitorTest, SetCallState_003, TestSize.Level1)
174 {
175     CALL_TEST_DEBUG;
176     DeviceEventMonitor deviceEventMonitor;
177     deviceEventMonitor.hasHandleRingMute_ = true;
178     EventFwk::CommonEventData ced;
179     EventFwk::Want want;
180     want.SetParam("slotId", 1);
181     ced.SetWant(want);
182     deviceEventMonitor.SetCallState(ced, 1);
183     ASSERT_EQ(deviceEventMonitor.callState_, -1);
184 }
185 
186 } // namespace MMI
187 } // namespace OHOS