• 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 <unordered_map>
17 #include <vector>
18 
19 #include "gtest/gtest.h"
20 #include "interfaces/native/native_gesture.h"
21 #include "interfaces/native/native_interface.h"
22 #include "interfaces/native/native_node.h"
23 #include "interfaces/native/native_type.h"
24 #include "interfaces/native/node/gesture_impl.h"
25 
26 #define private public
27 #include "core/components_ng/gestures/rotation_gesture.h"
28 #include "core/components_ng/gestures/recognizers/rotation_recognizer.h"
29 #include "core/gestures/gesture_info.h"
30 #include "frameworks/core/interfaces/arkoala/arkoala_api.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 
35 namespace OHOS::Ace {
36 
37 class NativeRotationGestureTest : public testing::Test {
38 public:
39     static ArkUI_NativeGestureAPI_1* NATIVE_GESTURE_API;
SetUpTestCase()40     static void SetUpTestCase()
41     {
42         NATIVE_GESTURE_API = reinterpret_cast<ArkUI_NativeGestureAPI_1*>(
43             OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1"));
44         ASSERT_NE(NATIVE_GESTURE_API, nullptr);
45     };
TearDownTestCase()46     static void TearDownTestCase()
47     {
48         NATIVE_GESTURE_API = nullptr;
49     };
50 };
51 ArkUI_NativeGestureAPI_1* NativeRotationGestureTest::NATIVE_GESTURE_API = nullptr;
52 
53 /**
54  * @tc.name: NativeRotationGestureTest001
55  * @tc.desc: Test Native Api create RotationGesture handle fingerNum parameter,
56  * fingerNum must in range in [2, 5], when out of this range the default value is 2.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(NativeRotationGestureTest, NativeRotationGestureTest001, TestSize.Level1)
60 {
61     std::unordered_map<int32_t, int32_t> fingerCountTestCases = {
62         { -1, -1 }, //in native api -1 will retain the original value
63         { 1, 1 }, //in native api 1 will retain the original value
64         { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 },
65         { 6, 6 }, //in native api 6 will retain the original value
66         { 7, 7 }, //in native api 7 will retain the original value
67         { 8, 8 }, //in native api 8 will retain the original value
68         { 9, 9 }, //in native api 9 will retain the original value
69         { 10, 10 } //in native api 10 will retain the original value
70     };
71 
72     constexpr static double DEFAULT_ROTATION_ANGLE_NUM = 10;
73 
74     for (auto iter = fingerCountTestCases.begin(); iter != fingerCountTestCases.end(); iter++) {
75         auto inputValue = iter->first;
76         auto expectValue = iter->second;
77 
78         ArkUI_GestureRecognizer* rotationGestureRecognizer =
79             NATIVE_GESTURE_API->createRotationGesture(inputValue, DEFAULT_ROTATION_ANGLE_NUM);
80         ASSERT_NE(rotationGestureRecognizer, nullptr);
81         ASSERT_EQ(rotationGestureRecognizer->type, ArkUI_GestureRecognizerType::ROTATION_GESTURE);
82 
83         Ace::NG::RotationGesture* rotationGesture = reinterpret_cast<Ace::NG::RotationGesture*>
84             (rotationGestureRecognizer->gesture);
85         EXPECT_EQ(rotationGesture->GetFingers(), expectValue);
86 
87         NATIVE_GESTURE_API->dispose(rotationGestureRecognizer);
88     }
89 }
90 
91 /**
92  * @tc.name: NativeRotationGestureTest002
93  * @tc.desc: Test Native Api create RotationGesture handle angleNum parameter, angleNum must be positive,
94  * Default value: 1,If this parameter is set to a value less than or equal to 0 or greater than 360,
95  * the default value 1 is used.
96  * @tc.type: FUNC
97 */
98 HWTEST_F(NativeRotationGestureTest, NativeRotationGestureTest002, TestSize.Level1)
99 {
100     std::unordered_map<double, double> angleNumTestCases = { { -10.0, 1.0 }, { 0.0, 1.0 }, { 5.0, 5.0 },
101         { 15.0, 15.0 }, { 400.0, 1.0 } };
102     constexpr static int32_t DEFAULT_FINGER_NUM = 2;
103 
104     for (auto iter = angleNumTestCases.begin(); iter != angleNumTestCases.end(); iter++) {
105         auto inputValue = iter->first;
106         auto expectValue = iter->second;
107 
108         ArkUI_GestureRecognizer* rotationGestureRecognizer =
109             NATIVE_GESTURE_API->createRotationGesture(DEFAULT_FINGER_NUM, inputValue);
110         ASSERT_NE(rotationGestureRecognizer, nullptr);
111         ASSERT_EQ(rotationGestureRecognizer->type, ArkUI_GestureRecognizerType::ROTATION_GESTURE);
112 
113         Ace::NG::RotationGesture* rotationGesture = reinterpret_cast<Ace::NG::RotationGesture*>
114             (rotationGestureRecognizer->gesture);
115         EXPECT_DOUBLE_EQ(rotationGesture->angle_, expectValue);
116 
117         NATIVE_GESTURE_API->dispose(rotationGestureRecognizer);
118     }
119 }
120 
121 } // namespace OHOS::Ace