• 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 "../ui_input_event_test.h"
17 #include "interfaces/native/event/ui_input_event_impl.h"
18 #include "interfaces/native/ui_input_event.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS::Ace {
23 
24 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation_NullEvent, TestSize.Level0)
25 {
26     int32_t result = OH_ArkUI_PointerEvent_SetStopPropagation(nullptr, true);
27     EXPECT_EQ(result, ERROR_CODE_PARAM_INVALID)
28         << "event is nullptr, expected ERROR_CODE_PARAM_INVALID, got " << result;
29 }
30 
31 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation_UnsupportedType, TestSize.Level0)
32 {
33     ArkUITouchEvent touchEvent = {};
34     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_AXIS_EVENT_ID, &touchEvent };
35     int32_t result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, true);
36     EXPECT_EQ(result, ERROR_CODE_PARAM_INVALID)
37         << "Unsupported eventTypeId, expected ERROR_CODE_PARAM_INVALID, got " << result;
38 }
39 
40 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation_TouchEvent, TestSize.Level0)
41 {
42     ArkUITouchEvent touchEvent = {};
43     touchEvent.stopPropagation = false;
44     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_TOUCH_EVENT_ID, &touchEvent };
45     int32_t result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, true);
46     EXPECT_EQ(result, ERROR_CODE_NO_ERROR) << "C_TOUCH_EVENT_ID, expected ERROR_CODE_NO_ERROR, got " << result;
47     EXPECT_TRUE(touchEvent.stopPropagation) << "stopPropagation should be set to true";
48 
49     result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, false);
50     EXPECT_EQ(result, ERROR_CODE_NO_ERROR) << "C_TOUCH_EVENT_ID, expected ERROR_CODE_NO_ERROR, got " << result;
51     EXPECT_FALSE(touchEvent.stopPropagation) << "stopPropagation should be set to false";
52 }
53 
54 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation_MouseEvent, TestSize.Level0)
55 {
56     ArkUIMouseEvent mouseEvent = {};
57     mouseEvent.stopPropagation = false;
58     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_MOUSE, C_MOUSE_EVENT_ID, &mouseEvent };
59     int32_t result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, true);
60     EXPECT_EQ(result, ERROR_CODE_NO_ERROR) << "C_MOUSE_EVENT_ID, expected ERROR_CODE_NO_ERROR, got " << result;
61     EXPECT_TRUE(mouseEvent.stopPropagation) << "stopPropagation should be set to true";
62 
63     result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, false);
64     EXPECT_EQ(result, ERROR_CODE_NO_ERROR) << "C_MOUSE_EVENT_ID, expected ERROR_CODE_NO_ERROR, got " << result;
65     EXPECT_FALSE(mouseEvent.stopPropagation) << "stopPropagation should be set to false";
66 }
67 
68 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_SetStopPropagation_HoverEvent, TestSize.Level0)
69 {
70     ArkUIHoverEvent hoverEvent = {};
71     hoverEvent.stopPropagation = false;
72     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_MOUSE, C_HOVER_EVENT_ID, &hoverEvent };
73     int32_t result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, true);
74     EXPECT_EQ(result, ERROR_CODE_NO_ERROR) << "C_HOVER_EVENT_ID, expected ERROR_CODE_NO_ERROR, got " << result;
75     EXPECT_TRUE(hoverEvent.stopPropagation) << "stopPropagation should be set to true";
76 
77     result = OH_ArkUI_PointerEvent_SetStopPropagation(&inputEvent, false);
78     EXPECT_EQ(result, ERROR_CODE_NO_ERROR) << "C_HOVER_EVENT_ID, expected ERROR_CODE_NO_ERROR, got " << result;
79     EXPECT_FALSE(hoverEvent.stopPropagation) << "stopPropagation should be set to false";
80 }
81 
82 } // namespace OHOS::Ace
83