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 #ifndef TEST_UNITTEST_CORE_MANAGER_DRAG_DROP_DRAG_DROP_SPRING_LOADING_TEST_NG_H 17 #define TEST_UNITTEST_CORE_MANAGER_DRAG_DROP_DRAG_DROP_SPRING_LOADING_TEST_NG_H 18 19 #include "gtest/gtest.h" 20 #include "test/mock/base/mock_task_executor.h" 21 #include "test/unittest/core/manager/drag_drop_manager_test_ng.h" 22 23 #include "core/components_ng/manager/drag_drop/drag_drop_spring_loading/drag_drop_spring_loading_state_base.h" 24 #include "core/components_ng/manager/drag_drop/drag_drop_spring_loading/drag_drop_spring_loading_state_machine.h" 25 26 namespace OHOS::Ace::NG { 27 const Point DEFAULT_POINT(50, 50); 28 const std::string DROP_INFO("DragSpringLoadingTestNg"); 29 30 enum class DragDropSpringLoadingReceivedInput { 31 NOTIFY_MOVE = 1 << 0, 32 NOTIFY_INTERCEPT = 1 << 1, 33 THRESHOLD = 1 << 2, 34 INTERCEPT = 1 << 3, 35 BEGIN_ON_ENTER = 1 << 4, 36 UPDATE_ON_ENTER = 1 << 5, 37 END_ON_ENTER = 1 << 6, 38 CANCEL_ON_ENTER = 1 << 7, 39 IDLE_ON_ENTER = 1 << 8, 40 }; 41 42 constexpr int32_t DRAG_DROP_SPRING_LOADING_DETECTOR_SET_USERCONFIG = 240; 43 44 struct SpringLoadingParamsTestCase { 45 bool hasFrameNode = true; 46 bool hasEventHub = true; 47 SpringLoadingParamsTestCaseSpringLoadingParamsTestCase48 SpringLoadingParamsTestCase(bool hasFrameNode, bool hasEventHub) 49 : hasFrameNode(hasFrameNode), hasEventHub(hasEventHub) 50 {} 51 }; 52 53 struct SpringLoadingPreInfoTestCase { 54 bool hasPreTimeStamp = false; 55 bool hasPreMovePoint = false; 56 SpringLoadingPreInfoTestCaseSpringLoadingPreInfoTestCase57 SpringLoadingPreInfoTestCase(bool hasPreTimeStamp, bool hasPreMovePoint) 58 : hasPreTimeStamp(hasPreTimeStamp), hasPreMovePoint(hasPreMovePoint) 59 {} 60 }; 61 62 struct SpringLoadingMachineTestCase { 63 bool transitionFailed = false; 64 bool isAllowedTransition = false; 65 bool isAllowedTransitionFind = true; 66 67 SpringLoadingMachineTestCase(bool transitionFailed, bool isAllowedTransition, bool isAllowedTransitionFind = true) transitionFailedSpringLoadingMachineTestCase68 : transitionFailed(transitionFailed), isAllowedTransition(isAllowedTransition), 69 isAllowedTransitionFind(isAllowedTransitionFind) 70 {} 71 }; 72 73 struct DragDropSpringLoadingStateTestCase { 74 DragDropSpringLoadingState originStatus = DragDropSpringLoadingState::IDLE; 75 DragDropSpringLoadingReceivedInput receivedInput = DragDropSpringLoadingReceivedInput::NOTIFY_MOVE; 76 DragDropSpringLoadingState expectStatus = DragDropSpringLoadingState::IDLE; 77 bool hasCallback = true; 78 std::string extraInfo = DROP_INFO; 79 DragDropSpringLoadingStateTestCase(DragDropSpringLoadingReceivedInput receivedInput, 80 DragDropSpringLoadingState originStatus, DragDropSpringLoadingState expectStatus, bool hasCallback, 81 std::string extraInfo = DROP_INFO) originStatusDragDropSpringLoadingStateTestCase82 : originStatus(originStatus), receivedInput(receivedInput), expectStatus(expectStatus), 83 hasCallback(hasCallback), extraInfo(extraInfo) 84 {} 85 }; 86 87 struct DragDropSpringLoadingDetectorTestCase : public DragDropSpringLoadingStateTestCase { 88 int32_t notifySequence = 0; 89 Point movePoint; 90 bool isMovementExceedThreshold = false; 91 bool hasDefaultFrameNode = false; 92 SpringLoadingParamsTestCase paramsTestCase; 93 SpringLoadingPreInfoTestCase preInfoTestCase; 94 DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput receivedInput, 95 DragDropSpringLoadingState originStatus, DragDropSpringLoadingState expectStatus, int32_t notifySequence, 96 Point movePoint = DEFAULT_POINT, bool hasCallback = true, bool isMovementExceedThreshold = false, 97 bool hasDefaultFrameNode = false, 98 SpringLoadingParamsTestCase paramsTestCase = SpringLoadingParamsTestCase(true, true), 99 SpringLoadingPreInfoTestCase preInfoTestCase = SpringLoadingPreInfoTestCase(false, false)) DragDropSpringLoadingStateTestCaseDragDropSpringLoadingDetectorTestCase100 : DragDropSpringLoadingStateTestCase(receivedInput, originStatus, expectStatus, hasCallback), 101 notifySequence(notifySequence), movePoint(movePoint), isMovementExceedThreshold(isMovementExceedThreshold), 102 hasDefaultFrameNode(hasDefaultFrameNode), paramsTestCase(paramsTestCase), preInfoTestCase(preInfoTestCase) 103 {} 104 }; 105 106 struct DragDropSpringLoadingStateHandler : public DragDropSpringLoadingStateTestCase { 107 int32_t notifySequence = 0; 108 bool abort = false; 109 SpringLoadingMachineTestCase springLoadingMachineTestCase = { false, false }; 110 int32_t updateNotifyCount = DEFAULT_UPDATE_NOTIFY_COUNT; 111 DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput receivedInput, 112 DragDropSpringLoadingState originStatus, DragDropSpringLoadingState expectStatus, bool hasCallback, 113 int32_t notifySequence, bool abort = false, 114 SpringLoadingMachineTestCase springLoadingMachineTestCase = { false, false }, 115 int32_t updateNotifyCount = DEFAULT_UPDATE_NOTIFY_COUNT) DragDropSpringLoadingStateTestCaseDragDropSpringLoadingStateHandler116 : DragDropSpringLoadingStateTestCase(receivedInput, originStatus, expectStatus, hasCallback), 117 notifySequence(notifySequence), abort(abort), springLoadingMachineTestCase(springLoadingMachineTestCase), 118 updateNotifyCount(updateNotifyCount) 119 {} 120 }; 121 122 class DragSpringLoadingTestNg : public testing::Test { 123 public: 124 static void SetUpTestCase(); 125 static void TearDownTestCase(); 126 void SetUp(); TearDown()127 void TearDown() {}; 128 129 protected: 130 RefPtr<FrameNode> dragFrameNode_; 131 RefPtr<FrameNode> dropFrameNode_; 132 RefPtr<DragDropSpringLoadingDetector> detector_; 133 uint64_t curTimeStamp_ = 0; 134 135 static testing::AssertionResult CheckDragDropSpringLoadingStatus( 136 int32_t caseNum, DragDropSpringLoadingState dragStatus, DragDropSpringLoadingState expectStatus); 137 static testing::AssertionResult CheckDragDropSpringLoadingNotifySequence( 138 int32_t caseNum, int32_t notifySequence, int32_t expectNotifySequence); 139 140 void HandleMoveInput(const DragDropSpringLoadingDetectorTestCase& testCase); 141 void HandleNotifyInterceptInput(const DragDropSpringLoadingDetectorTestCase& testCase); 142 void HandleThresholdInput(const DragDropSpringLoadingDetectorTestCase& testCase); 143 void SetupTestCaseConditions(const DragDropSpringLoadingStateHandler& testCase); 144 }; 145 } // namespace OHOS::Ace::NG 146 #endif 147