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 "../ui_input_event_test.h" 17 18 using namespace testing; 19 using namespace testing::ext; 20 21 namespace OHOS::Ace { 22 23 /** 24 * @tc.name: OH_ArkUI_PointerEvent_SetStopPropagation001 25 * @tc.desc: Test OH_ArkUI_PointerEvent_SetStopPropagation with null event pointer 26 * @tc.type: FUNC 27 */ 28 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation001, TestSize.Level0) 29 { 30 auto result = OH_ArkUI_PointerEvent_SetStopPropagation(nullptr, true); 31 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_PARAM_INVALID); 32 } 33 34 /** 35 * @tc.name: OH_ArkUI_PointerEvent_SetStopPropagation002 36 * @tc.desc: Test OH_ArkUI_PointerEvent_SetStopPropagation with unsupported event type 37 * @tc.type: FUNC 38 */ 39 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation002, TestSize.Level0) 40 { 41 ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, AXIS_EVENT_ID, nullptr }; 42 auto result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, true); 43 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_PARAM_INVALID); 44 } 45 46 /** 47 * @tc.name: OH_ArkUI_PointerEvent_SetStopPropagation101 48 * @tc.desc: Test OH_ArkUI_PointerEvent_SetStopPropagation with C_TOUCH_EVENT_ID type 49 * @tc.type: FUNC 50 */ 51 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation101, TestSize.Level0) 52 { 53 // Prepare test data 54 ArkUITouchEvent touchEvent; 55 ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_TOUCH_EVENT_ID, &touchEvent }; 56 57 // Test stop propagation true 58 auto result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, true); 59 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_NO_ERROR); 60 EXPECT_TRUE(touchEvent.stopPropagation); 61 62 // Test stop propagation false 63 result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, false); 64 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_NO_ERROR); 65 EXPECT_FALSE(touchEvent.stopPropagation); 66 } 67 68 /** 69 * @tc.name: OH_ArkUI_PointerEvent_SetStopPropagation102 70 * @tc.desc: Test OH_ArkUI_PointerEvent_SetStopPropagation with C_MOUSE_EVENT_ID type 71 * @tc.type: FUNC 72 */ 73 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation102, TestSize.Level0) 74 { 75 // Prepare test data 76 ArkUIMouseEvent mouseEvent; 77 ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_MOUSE_EVENT_ID, &mouseEvent }; 78 79 // Test stop propagation true 80 auto result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, true); 81 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_NO_ERROR); 82 EXPECT_TRUE(mouseEvent.stopPropagation); 83 84 // Test stop propagation false 85 result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, false); 86 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_NO_ERROR); 87 EXPECT_FALSE(mouseEvent.stopPropagation); 88 } 89 90 /** 91 * @tc.name: OH_ArkUI_PointerEvent_SetStopPropagation103 92 * @tc.desc: Test OH_ArkUI_PointerEvent_SetStopPropagation with C_HOVER_EVENT_ID type 93 * @tc.type: FUNC 94 */ 95 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation103, TestSize.Level0) 96 { 97 // Prepare test data 98 ArkUIHoverEvent hoverEvent; 99 ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_HOVER_EVENT_ID, &hoverEvent }; 100 101 // Test stop propagation true 102 auto result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, true); 103 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_NO_ERROR); 104 EXPECT_TRUE(hoverEvent.stopPropagation); 105 106 // Test stop propagation false 107 result = OH_ArkUI_PointerEvent_SetStopPropagation(&event, false); 108 EXPECT_EQ(result, OHOS::Ace::ERROR_CODE_NO_ERROR); 109 EXPECT_FALSE(hoverEvent.stopPropagation); 110 } 111 112 } // namespace OHOS::Ace