• 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/ui_input_event.h"
18 #include "interfaces/native/event/ui_input_event_impl.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS::Ace {
23 
24 HWTEST_F(UIInputEventTest, OH_ArkUI_MouseEvent_GetRawDeltaX_NullEvent, TestSize.Level0)
25 {
26     float result = OH_ArkUI_MouseEvent_GetRawDeltaX(nullptr);
27     EXPECT_FLOAT_EQ(result, 0.0f) << "Input event is nullptr, expected 0.0f, got " << result;
28 }
29 
30 HWTEST_F(UIInputEventTest, OH_ArkUI_MouseEvent_GetRawDeltaX_EventTypeNotMouse, TestSize.Level0)
31 {
32     ArkUIMouseEvent mouseEvent = {};
33     mouseEvent.rawDeltaX = 1.23f;
34     ArkUI_UIInputEvent inputEvent = {
35         ARKUI_UIINPUTEVENT_TYPE_MOUSE,
36         C_CLICK_EVENT_ID,
37         &mouseEvent
38     };
39     float result = OH_ArkUI_MouseEvent_GetRawDeltaX(&inputEvent);
40     EXPECT_FLOAT_EQ(result, 0.0f) << "eventTypeId != C_MOUSE_EVENT_ID, expected 0.0f, got " << result;
41 }
42 
43 HWTEST_F(UIInputEventTest, OH_ArkUI_MouseEvent_GetRawDeltaX_NullInputEvent, TestSize.Level0)
44 {
45     ArkUI_UIInputEvent inputEvent = {
46         ARKUI_UIINPUTEVENT_TYPE_MOUSE,
47         C_MOUSE_EVENT_ID,
48         nullptr
49     };
50     float result = OH_ArkUI_MouseEvent_GetRawDeltaX(&inputEvent);
51     EXPECT_FLOAT_EQ(result, 0.0f) << "inputEvent is nullptr, expected 0.0f, got " << result;
52 }
53 
54 HWTEST_F(UIInputEventTest, OH_ArkUI_MouseEvent_GetRawDeltaX_Normal, TestSize.Level0)
55 {
56     ArkUIMouseEvent mouseEvent = {};
57     mouseEvent.rawDeltaX = 5.67f;
58     ArkUI_UIInputEvent inputEvent = {
59         ARKUI_UIINPUTEVENT_TYPE_MOUSE,
60         C_MOUSE_EVENT_ID,
61         &mouseEvent
62     };
63     float result = OH_ArkUI_MouseEvent_GetRawDeltaX(&inputEvent);
64     EXPECT_FLOAT_EQ(result, mouseEvent.rawDeltaX)
65         << "C_MOUSE_EVENT_ID, expect rawDeltaX=" << mouseEvent.rawDeltaX << ", actual=" << result;
66 }
67 
68 HWTEST_F(UIInputEventTest, OH_ArkUI_MouseEvent_GetRawDeltaX_Variants, TestSize.Level0)
69 {
70     struct DeltaXTestCase {
71         float value;
72         const char* desc;
73     };
74     std::vector<DeltaXTestCase> cases = {
75         { 0.0f, "rawDeltaX = 0.0f" },
76         { -10.0f, "rawDeltaX = -10.0f" },
77         { 10000.123f, "rawDeltaX = 10000.123f" }
78     };
79 
80     ArkUIMouseEvent mouseEvent = {};
81     ArkUI_UIInputEvent inputEvent = {
82         ARKUI_UIINPUTEVENT_TYPE_MOUSE,
83         C_MOUSE_EVENT_ID,
84         &mouseEvent
85     };
86     int count = 0;
87     for (const auto& testCase : cases) {
88         mouseEvent.rawDeltaX = testCase.value;
89         float result = OH_ArkUI_MouseEvent_GetRawDeltaX(&inputEvent);
90         EXPECT_FLOAT_EQ(result, testCase.value)
91             << "index = " << count << " : " << testCase.desc << ", actual = " << result;
92         count++;
93     }
94 }
95 
96 } // namespace OHOS::Ace
97