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_IsNumLockOn001, TestSize.Level0) 25 { 26 EXPECT_EQ(OH_ArkUI_KeyEvent_IsNumLockOn(nullptr, nullptr), ARKUI_ERROR_CODE_PARAM_INVALID); 27 } 28 29 HWTEST_F(KeyEventTest, KeyEvent_IsNumLockOn002, TestSize.Level0) 30 { 31 bool state = false; 32 ArkUI_UIInputEvent event = { .inputEvent = nullptr }; 33 EXPECT_EQ(OH_ArkUI_KeyEvent_IsNumLockOn(&event, &state), ARKUI_ERROR_CODE_PARAM_INVALID); 34 } 35 36 HWTEST_F(KeyEventTest, KeyEvent_IsNumLockOn003, TestSize.Level0) 37 { 38 std::vector<bool> testValues = { true, false }; 39 int count = 0; 40 for (bool val : testValues) { 41 ArkUIKeyEvent keyEvent { .isNumLockOn = val }; 42 ArkUI_UIInputEvent event = { 43 .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY, 44 .eventTypeId = C_KEY_EVENT_ID, 45 .inputEvent = &keyEvent, 46 .isCloned = false, 47 .apiVersion = 0, 48 }; 49 bool resultState = !val; 50 auto result = OH_ArkUI_KeyEvent_IsNumLockOn(&event, &resultState); 51 EXPECT_EQ(result, ARKUI_ERROR_CODE_NO_ERROR); 52 EXPECT_EQ(resultState, val) << "index = " << count; 53 count++; 54 } 55 } 56 57 HWTEST_F(KeyEventTest, KeyEvent_IsNumLockOn004, TestSize.Level0) 58 { 59 ArkUI_UIInputEvent event = { 60 .inputType = ARKUI_UIINPUTEVENT_TYPE_KEY, 61 .eventTypeId = AXIS_EVENT_ID, 62 .inputEvent = nullptr, 63 .isCloned = false, 64 .apiVersion = 0, 65 }; 66 bool state = false; 67 EXPECT_EQ(OH_ArkUI_KeyEvent_IsNumLockOn(&event, &state), ARKUI_ERROR_CODE_PARAM_INVALID); 68 } 69 } // namespace OHOS::Ace 70