• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "active_key_event_test.h"
16 
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 "event_thread_pool.h"
26 #include "log_store_ex.h"
27 using namespace testing::ext;
28 using namespace OHOS::HiviewDFX;
29 
SetUp()30 void ActiveKeyEventTest::SetUp()
31 {
32     printf("SetUp.\n");
33 }
34 
TearDown()35 void ActiveKeyEventTest::TearDown()
36 {
37     printf("TearDown.\n");
38 }
39 
SetUpTestCase()40 void ActiveKeyEventTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void ActiveKeyEventTest::TearDownTestCase()
45 {
46 }
47 
48 /**
49  * @tc.name: ActiveKeyEventTest_001
50  * @tc.desc: ActiveKeyEventTest CombinationKeyHandle
51  * @tc.type: FUNC
52  */
53 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_001, TestSize.Level3)
54 {
55     std::shared_ptr<EventThreadPool> eventPool = std::make_shared<EventThreadPool>(5, "EventThreadPool");
56     EXPECT_TRUE(eventPool != nullptr);
57     std::string logStorePath = "/data/log/test/";
58     std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
59     auto ret = logStoreEx->Init();
60     EXPECT_EQ(ret, true);
61     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
62     activeKeyEvent->Init(eventPool, logStoreEx);
63     activeKeyEvent->triggeringTime_ = 0;
64     auto keyEvent = OHOS::MMI::KeyEvent::Create();
65     activeKeyEvent->CombinationKeyHandle(keyEvent);
66 }
67 
68 /**
69  * @tc.name: ActiveKeyEventTest_002
70  * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
71  * @tc.type: FUNC
72  */
73 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_002, TestSize.Level3)
74 {
75     std::shared_ptr<EventThreadPool> eventPool = nullptr;
76     EXPECT_TRUE(eventPool == nullptr);
77     std::string logStorePath = "/data/log/test/";
78     std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
79     auto ret = logStoreEx->Init();
80     EXPECT_EQ(ret, true);
81     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
82     activeKeyEvent->Init(eventPool, logStoreEx);
83     activeKeyEvent->triggeringTime_ = 0;
84     auto keyEvent = OHOS::MMI::KeyEvent::Create();
85     activeKeyEvent->CombinationKeyCallback(keyEvent);
86 }
87 
88 /**
89  * @tc.name: ActiveKeyEventTest_003
90  * @tc.desc: ActiveKeyEventTest Init
91  * @tc.type: FUNC
92  */
93 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_003, TestSize.Level3)
94 {
95     std::string logStorePath = "/data/log/test/";
96     std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
97     auto ret = logStoreEx->Init();
98     EXPECT_EQ(ret, true);
99     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
100     std::set<int32_t> preKeys;
101     preKeys.insert(OHOS::MMI::KeyEvent::KEYCODE_VOLUME_UP);
102     activeKeyEvent->InitSubscribe(preKeys, OHOS::MMI::KeyEvent::KEYCODE_VOLUME_DOWN, 5, 500);
103 }
104 
105 /**
106  * @tc.name: ActiveKeyEventTest_004
107  * @tc.desc: ActiveKeyEventTest InitSubscribe
108  * @tc.type: FUNC
109  */
110 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_004, TestSize.Level3)
111 {
112     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
113     activeKeyEvent->triggeringTime_ = (uint64_t)ActiveKeyEvent::SystemTimeMillisecond();
114     std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
115     activeKeyEvent->CombinationKeyCallback(keyEvent);
116     std::set<int32_t> preKeys;
117     preKeys.insert(OHOS::MMI::KeyEvent::KEYCODE_VOLUME_UP);
118     activeKeyEvent->InitSubscribe(preKeys, OHOS::MMI::KeyEvent::KEYCODE_VOLUME_DOWN, 5, 500);
119 }
120 
121 /**
122  * @tc.name: ActiveKeyEventTest_005
123  * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
124  * @tc.type: FUNC
125  */
126 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_005, TestSize.Level3)
127 {
128     std::shared_ptr<EventThreadPool> eventPool = std::make_shared<EventThreadPool>(5, "EventThreadPool");
129     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
130     activeKeyEvent->eventPool_ = eventPool;
131     activeKeyEvent->triggeringTime_ = (uint64_t)ActiveKeyEvent::SystemTimeMillisecond();
132     std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
133     activeKeyEvent->CombinationKeyCallback(keyEvent);
134 }
135 
136 /**
137  * @tc.name: ActiveKeyEventTest_006
138  * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
139  * @tc.type: FUNC
140  */
141 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_006, TestSize.Level3)
142 {
143     std::shared_ptr<EventThreadPool> eventPool = nullptr;
144     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
145     activeKeyEvent->eventPool_ = eventPool;
146     activeKeyEvent->triggeringTime_ = 0;
147     auto keyEvent = OHOS::MMI::KeyEvent::Create();
148     activeKeyEvent->CombinationKeyCallback(keyEvent);
149 }
150 
151 /**
152  * @tc.name: ActiveKeyEventTest_007
153  * @tc.desc: ActiveKeyEventTest CombinationKeyCallback
154  * @tc.type: FUNC
155  */
156 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_007, TestSize.Level3)
157 {
158     std::shared_ptr<EventThreadPool> eventPool = std::make_shared<EventThreadPool>(5, "EventThreadPool");
159     std::string logStorePath = "/data/log/test/";
160     std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
161     logStoreEx->Init();
162     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
163     activeKeyEvent->Init(eventPool, logStoreEx);
164     activeKeyEvent->triggeringTime_ = 0;
165     auto keyEvent = OHOS::MMI::KeyEvent::Create();
166     activeKeyEvent->CombinationKeyCallback(keyEvent);
167 }
168 
169 /**
170  * @tc.name: ActiveKeyEventTest_008
171  * @tc.desc: ActiveKeyEventTest CombinationKeyHandle
172  * @tc.type: FUNC
173  */
174 static HWTEST_F(ActiveKeyEventTest, ActiveKeyEventTest_008, TestSize.Level3)
175 {
176     std::shared_ptr<EventThreadPool> eventPool = nullptr;
177     std::string logStorePath = "/data/log/test/";
178     std::shared_ptr<LogStoreEx> logStoreEx = std::make_shared<LogStoreEx>(logStorePath, true);
179     logStoreEx->Init();
180     std::shared_ptr<ActiveKeyEvent> activeKeyEvent = std::make_shared<ActiveKeyEvent>();
181     activeKeyEvent->Init(eventPool, logStoreEx);
182     activeKeyEvent->triggeringTime_ = 0;
183     auto keyEvent = OHOS::MMI::KeyEvent::Create();
184     activeKeyEvent->CombinationKeyHandle(keyEvent);
185 }
186 
187