1 /*
2 * Copyright (c) 2023 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 #ifdef MULTIMODALINPUT_INPUT_ENABLE
16 #include "active_key_event_test.h"
17 #include <ctime>
18 #include <memory>
19 #include <vector>
20 #include <string>
21
22 #define private public
23 #define protected public
24 #include "active_key_event.h"
25 #include "log_store_ex.h"
26 #include "hiview_platform.h"
27 #include "sysevent_source.h"
28 using namespace testing::ext;
29 using namespace OHOS::HiviewDFX;
30
31 namespace OHOS {
32 namespace HiviewDFX {
33 SysEventSource source;
SetUp()34 void ActiveKeyEventTest::SetUp()
35 {
36 printf("SetUp.\n");
37 }
38
TearDown()39 void ActiveKeyEventTest::TearDown()
40 {
41 printf("TearDown.\n");
42 }
43
SetUpTestCase()44 void ActiveKeyEventTest::SetUpTestCase()
45 {
46 HiviewPlatform platform;
47 source.SetHiviewContext(&platform);
48 source.OnLoad();
49 }
50
TearDownTestCase()51 void ActiveKeyEventTest::TearDownTestCase()
52 {
53 source.OnUnload();
54 }
55
56 /**
57 * @tc.name: ActiveKeyEventTest_001
58 * @tc.desc: ActiveKeyEventTest CombinationKeyHandle
59 * @tc.type: FUNC
60 */
61 HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_001, TestSize.Level0)
62 {
63 std::string logStorePath = "/data/test/";
64 std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
65 auto ret = logStoreEx->Init();
66 EXPECT_EQ(ret, true);
67 std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
68 activeKeyEvent->Init(logStoreEx);
69 activeKeyEvent->triggeringTime_ = 0;
70 auto keyEvent = OHOS::MMI::KeyEvent::Create();
71 activeKeyEvent->CombinationKeyHandle(keyEvent);
72 sleep(1);
73 }
74
75 /**
76 * @tc.name: ActiveKeyEventTest_002
77 * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
78 * @tc.type: FUNC
79 */
80 HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_002, TestSize.Level3)
81 {
82 std::string logStorePath = "/data/test/";
83 std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
84 auto ret = logStoreEx->Init();
85 EXPECT_EQ(ret, true);
86 std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
87 activeKeyEvent->Init(logStoreEx);
88 activeKeyEvent->triggeringTime_ = 0;
89 auto keyEvent = OHOS::MMI::KeyEvent::Create();
90 activeKeyEvent->CombinationKeyCallback(keyEvent);
91 sleep(1);
92 }
93
94 /**
95 * @tc.name: ActiveKeyEventTest_003
96 * @tc.desc: ActiveKeyEventTest Init
97 * @tc.type: FUNC
98 */
99 HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_003, TestSize.Level3)
100 {
101 std::string logStorePath = "/data/test/";
102 std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
103 auto ret = logStoreEx->Init();
104 EXPECT_EQ(ret, true);
105 std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
106 std::set<int32_t> preKeys;
107 preKeys.insert(OHOS::MMI::KeyEvent::KEYCODE_VOLUME_UP);
108 activeKeyEvent->InitSubscribe(preKeys, OHOS::MMI::KeyEvent::KEYCODE_VOLUME_DOWN, 5, 500);
109 sleep(1);
110 }
111
112 /**
113 * @tc.name: ActiveKeyEventTest_004
114 * @tc.desc: ActiveKeyEventTest InitSubscribe
115 * @tc.type: FUNC
116 */
117 HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_004, TestSize.Level3)
118 {
119 std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
120 activeKeyEvent->triggeringTime_ = (uint64_t)ActiveKeyEvent::SystemTimeMillisecond();
121 EXPECT_TRUE(activeKeyEvent->triggeringTime_ > 0);
122 std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
123 activeKeyEvent->CombinationKeyCallback(keyEvent);
124 std::set<int32_t> preKeys;
125 preKeys.insert(OHOS::MMI::KeyEvent::KEYCODE_VOLUME_UP);
126 activeKeyEvent->InitSubscribe(preKeys, OHOS::MMI::KeyEvent::KEYCODE_VOLUME_DOWN, 5, 500);
127 sleep(1);
128 }
129
130 /**
131 * @tc.name: ActiveKeyEventTest_005
132 * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
133 * @tc.type: FUNC
134 */
135 HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_005, TestSize.Level3)
136 {
137 std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
138 activeKeyEvent->triggeringTime_ = (uint64_t)ActiveKeyEvent::SystemTimeMillisecond();
139 EXPECT_TRUE(activeKeyEvent->triggeringTime_ > 0);
140 std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
141 activeKeyEvent->CombinationKeyCallback(keyEvent);
142 sleep(1);
143 }
144
145 /**
146 * @tc.name: ActiveKeyEventTest_006
147 * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
148 * @tc.type: FUNC
149 */
150 HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_006, TestSize.Level3)
151 {
152 std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
153 activeKeyEvent->triggeringTime_ = 0;
154 EXPECT_TRUE(activeKeyEvent->triggeringTime_ == 0);
155 auto keyEvent = OHOS::MMI::KeyEvent::Create();
156 activeKeyEvent->CombinationKeyCallback(keyEvent);
157 sleep(1);
158 }
159 } // namespace HiviewDFX
160 } // namespace OHOS
161 #endif // MULTIMODALINPUT_INPUT_ENABLE
162
163