• 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 "key_event_test.h"
17 
18 #include "frameworks/core/common/ace_application_info.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS::Ace {
23 
24 HWTEST_F(KeyEventTest, KeyEvent_GetKeyCode001, TestSize.Level0)
25 {
26     auto result = OH_ArkUI_KeyEvent_GetKeyCode(nullptr);
27     EXPECT_EQ(result, -1);
28 }
29 
30 HWTEST_F(KeyEventTest, KeyEvent_GetKeyCode002, TestSize.Level0)
31 {
32     ArkUI_UIInputEvent event = {
33         .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY,
34         .eventTypeId = C_KEY_EVENT_ID,
35         .inputEvent = nullptr,
36         .isCloned = false,
37         .apiVersion = 0,
38     };
39     auto result = OH_ArkUI_KeyEvent_GetKeyCode(&event);
40     EXPECT_EQ(result, -1);
41 }
42 
43 HWTEST_F(KeyEventTest, KeyEvent_GetKeyCode003, TestSize.Level0)
44 {
45     std::vector<int32_t> testKeyCodes = { 0, 1, 13, 255 };
46     int count = 0;
47     for (int32_t code : testKeyCodes) {
48         ArkUIKeyEvent keyEvent { .type = ARKUI_KEY_EVENT_DOWN, .keyCode = code };
49         ArkUI_UIInputEvent event = {
50             .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY,
51             .eventTypeId = C_KEY_EVENT_ID,
52             .inputEvent = &keyEvent,
53             .isCloned = false,
54             .apiVersion = 0,
55         };
56         auto result = OH_ArkUI_KeyEvent_GetKeyCode(&event);
57         EXPECT_EQ(result, code) << "index = " << count << " : expected keyCode = " << code;
58         count++;
59     }
60 }
61 
62 HWTEST_F(KeyEventTest, KeyEvent_GetKeyCode004, TestSize.Level0)
63 {
64     ArkUI_UIInputEvent event = {
65         .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY,
66         .eventTypeId = AXIS_EVENT_ID,
67         .inputEvent = nullptr,
68         .isCloned = false,
69         .apiVersion = 0,
70     };
71     auto result = OH_ArkUI_KeyEvent_GetKeyCode(&event);
72     EXPECT_EQ(result, -1);
73 }
74 } // namespace OHOS::Ace
75