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