• 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 "event/ui_input_event_impl.h"
18 #include "node/node_model.h"
19 
20 #include "core/interfaces/arkoala/arkoala_api.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS::Ace {
26 
27 /**
28  * @tc.name: OH_ArkUI_PointerEvent_CreateClonedEvent001
29  * @tc.desc: Test with null event pointer
30  * @tc.type: FUNC
31  */
32 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_CreateClonedEvent001, TestSize.Level0)
33 {
34     ArkUI_UIInputEvent* clonedEvent = nullptr;
35     auto result = OH_ArkUI_PointerEvent_CreateClonedEvent(nullptr, &clonedEvent);
36     EXPECT_EQ(result, ARKUI_ERROR_CODE_PARAM_INVALID);
37     EXPECT_EQ(clonedEvent, nullptr);
38 }
39 
40 /**
41  * @tc.name: OH_ArkUI_PointerEvent_CreateClonedEvent002
42  * @tc.desc: Test with null clonedEvent pointer
43  * @tc.type: FUNC
44  */
45 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_CreateClonedEvent002, TestSize.Level0)
46 {
47     ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_TOUCH_EVENT_ID, nullptr, false };
48     auto result = OH_ArkUI_PointerEvent_CreateClonedEvent(&event, nullptr);
49     EXPECT_EQ(result, ARKUI_ERROR_CODE_PARAM_INVALID);
50 }
51 
52 /**
53  * @tc.name: OH_ArkUI_PointerEvent_CreateClonedEvent003
54  * @tc.desc: Test with null inputEvent in source event
55  * @tc.type: FUNC
56  */
57 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_CreateClonedEvent003, TestSize.Level0)
58 {
59     // Test all unsupported event types
60     std::vector<std::pair<ArkUI_UIInputEvent_Type, ArkUIEventTypeId>> unsupportedEventTypes = {
61         { ARKUI_UIINPUTEVENT_TYPE_AXIS, AXIS_EVENT_ID },            // AXIS_EVENT_ID = 0
62         { ARKUI_UIINPUTEVENT_TYPE_MOUSE, C_MOUSE_EVENT_ID },        // C_MOUSE_EVENT_ID = 3
63         { ARKUI_UIINPUTEVENT_TYPE_AXIS, C_AXIS_EVENT_ID },          // C_AXIS_EVENT_ID = 4
64         { ARKUI_UIINPUTEVENT_TYPE_KEY, C_KEY_EVENT_ID },            // C_KEY_EVENT_ID = 5
65         { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_FOCUS_AXIS_EVENT_ID }, // C_FOCUS_AXIS_EVENT_ID = 6
66         { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_CLICK_EVENT_ID },      // C_CLICK_EVENT_ID = 7
67         { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_HOVER_EVENT_ID },      // C_HOVER_EVENT_ID = 8
68     };
69 
70     for (const auto& [inputType, eventTypeId] : unsupportedEventTypes) {
71         ArkUITouchEvent inputEvent;
72         ArkUI_UIInputEvent event = { inputType, eventTypeId, &inputEvent, false };
73         ArkUI_UIInputEvent* clonedEvent = nullptr;
74 
75         auto result = OH_ArkUI_PointerEvent_CreateClonedEvent(&event, &clonedEvent);
76         EXPECT_EQ(result, ARKUI_ERROR_CODE_NO_ERROR);
77         ASSERT_EQ(clonedEvent, nullptr) << "Failed for event type: " << static_cast<int>(eventTypeId);
78     }
79 }
80 
81 /**
82  * @tc.name: OH_ArkUI_PointerEvent_CreateClonedEvent004
83  * @tc.desc: Test with unsupported event types
84  * @tc.type: FUNC
85  */
86 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_CreateClonedEvent004, TestSize.Level0)
87 {
88     ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, TOUCH_EVENT_ID, nullptr, false };
89     ArkUI_UIInputEvent* clonedEvent = nullptr;
90     auto result = OH_ArkUI_PointerEvent_CreateClonedEvent(&event, &clonedEvent);
91     EXPECT_EQ(result, ARKUI_ERROR_CODE_PARAM_INVALID);
92     ASSERT_EQ(clonedEvent, nullptr);
93 
94     ArkUI_UIInputEvent event2 = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_TOUCH_EVENT_ID, nullptr, false };
95     ArkUI_UIInputEvent* clonedEvent2 = nullptr;
96     auto result2 = OH_ArkUI_PointerEvent_CreateClonedEvent(&event2, &clonedEvent2);
97     EXPECT_EQ(result2, ARKUI_ERROR_CODE_PARAM_INVALID);
98     ASSERT_EQ(clonedEvent2, nullptr);
99 }
100 
101 /**
102  * @tc.name: OH_ArkUI_PointerEvent_CreateClonedEvent101
103  * @tc.desc: Test successful creation of cloned touch event
104  * @tc.type: FUNC
105  */
106 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_CreateClonedEvent101, TestSize.Level0)
107 {
108     // Test all unsupported event types
109     std::vector<std::pair<ArkUI_UIInputEvent_Type, ArkUIEventTypeId>> unsupportedEventTypes = {
110         { ARKUI_UIINPUTEVENT_TYPE_TOUCH, TOUCH_EVENT_ID },   // TOUCH_EVENT_ID = 1
111         { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_TOUCH_EVENT_ID }, // C_TOUCH_EVENT_ID = 2
112     };
113 
114     for (const auto& [inputType, eventTypeId] : unsupportedEventTypes) {
115         ArkUI_UIInputEvent event = { inputType, eventTypeId, nullptr, false };
116         ArkUI_UIInputEvent* clonedEvent = nullptr;
117         auto result = OH_ArkUI_PointerEvent_CreateClonedEvent(&event, &clonedEvent);
118         EXPECT_EQ(result, ARKUI_ERROR_CODE_PARAM_INVALID);
119         ASSERT_EQ(clonedEvent, nullptr) << "Failed for event type: " << static_cast<int>(eventTypeId);
120     }
121 }
122 
123 /**
124  * @tc.name: OH_ArkUI_PointerEvent_CreateClonedEvent102
125  * @tc.desc: Test with different touch event types
126  * @tc.type: FUNC
127  */
128 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_CreateClonedEvent102, TestSize.Level0)
129 {
130     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
131     // Test all unsupported event types
132     std::vector<std::pair<ArkUI_UIInputEvent_Type, ArkUIEventTypeId>> unsupportedEventTypes = {
133         { ARKUI_UIINPUTEVENT_TYPE_TOUCH, TOUCH_EVENT_ID },   // TOUCH_EVENT_ID = 1
134         { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_TOUCH_EVENT_ID }, // C_TOUCH_EVENT_ID = 2
135     };
136 
137     for (const auto& [inputType, eventTypeId] : unsupportedEventTypes) {
138         ArkUITouchEvent inputEvent;
139         ArkUI_UIInputEvent event = { inputType, eventTypeId, &inputEvent, false };
140         ArkUI_UIInputEvent* clonedEvent = nullptr;
141         auto result = OH_ArkUI_PointerEvent_CreateClonedEvent(&event, &clonedEvent);
142         EXPECT_EQ(result, ARKUI_ERROR_CODE_NO_ERROR);
143         ASSERT_NE(clonedEvent, nullptr) << "Failed for event type: " << static_cast<int>(eventTypeId);
144         OH_ArkUI_PointerEvent_DestroyClonedEvent(clonedEvent);
145     }
146 }
147 } // namespace OHOS::Ace