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_GetKeyIntentionCode001, TestSize.Level0) 25 { 26 auto result = OH_ArkUI_KeyEvent_GetKeyIntensionCode(nullptr); 27 EXPECT_EQ(result, static_cast<ArkUI_KeyIntension>(-1)); 28 } 29 30 HWTEST_F(KeyEventTest, KeyEvent_GetKeyIntentionCode002, 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_GetKeyIntensionCode(&event); 40 EXPECT_EQ(result, static_cast<ArkUI_KeyIntension>(-1)); 41 } 42 43 HWTEST_F(KeyEventTest, KeyEvent_GetKeyIntentionCode003, TestSize.Level0) 44 { 45 std::vector<ArkUI_KeyIntension> intensions = { 46 ARKUI_KEY_INTENSION_UP, 47 ARKUI_KEY_INTENSION_LEFT, 48 ARKUI_KEY_INTENTION_MEDIA_PLAY_PAUSE, 49 ARKUI_KEY_INTENTION_VOLUME_DOWN, 50 ARKUI_KEY_INTENTION_CAMERA 51 }; 52 53 int count = 0; 54 for (auto intention : intensions) { 55 ArkUIKeyEvent keyEvent { .intentionCode = static_cast<int32_t>(intention) }; 56 ArkUI_UIInputEvent event = { 57 .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY, 58 .eventTypeId = C_KEY_EVENT_ID, 59 .inputEvent = &keyEvent, 60 .isCloned = false, 61 .apiVersion = 0, 62 }; 63 auto result = OH_ArkUI_KeyEvent_GetKeyIntensionCode(&event); 64 EXPECT_EQ(result, intention) << "index = " << count << " : expected intention = " << intention; 65 count++; 66 } 67 } 68 69 HWTEST_F(KeyEventTest, KeyEvent_GetKeyIntentionCode004, TestSize.Level0) 70 { 71 ArkUI_UIInputEvent event = { 72 .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY, 73 .eventTypeId = AXIS_EVENT_ID, 74 .inputEvent = nullptr, 75 .isCloned = false, 76 .apiVersion = 0, 77 }; 78 auto result = OH_ArkUI_KeyEvent_GetKeyIntensionCode(&event); 79 EXPECT_EQ(result, static_cast<ArkUI_KeyIntension>(-1)); 80 } 81 } // namespace OHOS::Ace 82