1 /* 2 * Copyright (c) 2024 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 #include <cstdint> 16 #include <iostream> 17 18 #include "gtest/gtest.h" 19 #define private public 20 #define protected public 21 #include "drag_and_drop.h" 22 #include "event_converter.h" 23 #include "native_interface.h" 24 #include "native_node.h" 25 #include "native_type.h" 26 #include "node_model.h" 27 #include "test/mock/base/mock_task_executor.h" 28 #include "test/mock/core/common/mock_container.h" 29 #include "test/mock/core/common/mock_theme_manager.h" 30 #include "test/mock/core/pipeline/mock_pipeline_context.h" 31 32 using namespace testing; 33 using namespace testing::ext; 34 namespace OHOS::Ace { 35 namespace { 36 const float WINDOW_X = 1.0f; 37 const float WINDOW_Y = 1.0f; 38 const float TOUCH_POINT_X = 1.0f; 39 const float TOUCH_POINT_Y = 1.0f; 40 const float PREVIEW_RECT_WIDTH = 1.0f; 41 const float PREVIEW_RECT_HEIGHT = 1.0f; 42 const float DISPLAY_X = 1.0f; 43 const float DISPLAY_Y = 1.0f; 44 const float VELOCITY_X = 1.0f; 45 const float VELOCITY_Y = 1.0f; 46 const float VELOCITY = 1.0f; 47 } // namespace 48 class DragAndDropTest : public testing::Test { 49 public: SetUpTestSuite()50 static void SetUpTestSuite() 51 { 52 NG::MockPipelineContext::SetUp(); 53 MockContainer::SetUp(); 54 MockContainer::Current()->pipelineContext_ = NG::MockPipelineContext::GetCurrent(); 55 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>(); 56 MockContainer::Current()->pipelineContext_->taskExecutor_ = MockContainer::Current()->taskExecutor_; 57 auto themeManager = AceType::MakeRefPtr<MockThemeManager>(); 58 PipelineBase::GetCurrentContext()->SetThemeManager(themeManager); 59 } TearDownTestSuite()60 static void TearDownTestSuite() 61 { 62 NG::MockPipelineContext::TearDown(); 63 MockContainer::TearDown(); 64 } 65 }; 66 67 /** 68 * @tc.name: DragAndDropTest001 69 * @tc.desc: Test the DragAction for C-API. 70 * @tc.type: FUNC 71 */ 72 HWTEST_F(DragAndDropTest, DragAndDropTest001, TestSize.Level1) 73 { 74 /** 75 * @tc.steps: step1.create dragAction. 76 */ 77 auto nodeAPI = reinterpret_cast<ArkUI_NativeNodeAPI_1*>( 78 OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); 79 auto rootNode = nodeAPI->createNode(ARKUI_NODE_STACK); 80 auto rootFrameNode = reinterpret_cast<ArkUI_Node*>(rootNode); 81 auto frameNode = reinterpret_cast<NG::FrameNode*>(rootFrameNode->uiNodeHandle); 82 auto context = NG::MockPipelineContext::GetCurrent(); 83 frameNode->context_ = AceType::RawPtr(context); 84 auto* dragAction = OH_ArkUI_CreateDragActionWithNode(rootNode); 85 EXPECT_NE(dragAction, nullptr); 86 EXPECT_EQ(OH_ArkUI_DragAction_SetPointerId(dragAction, 0), ARKUI_ERROR_CODE_NO_ERROR); 87 EXPECT_EQ(OH_ArkUI_DragAction_SetTouchPointX(dragAction, 1.0), ARKUI_ERROR_CODE_NO_ERROR); 88 EXPECT_EQ(OH_ArkUI_DragAction_SetTouchPointY(dragAction, 1.0), ARKUI_ERROR_CODE_NO_ERROR); 89 auto* interalDragAction = reinterpret_cast<ArkUIDragAction*>(dragAction); 90 EXPECT_EQ(interalDragAction->pointerId, 0); 91 EXPECT_EQ(interalDragAction->touchPointX, 1.0); 92 EXPECT_EQ(interalDragAction->touchPointY, 1.0); 93 OH_ArkUI_DragAction_RegisterStatusListener( __anonf90abb4c0202(ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData) 94 dragAction, nullptr, [](ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData) -> void { 95 EXPECT_NE( 96 OH_ArkUI_DragAndDropInfo_GetDragStatus(dragAndDropInfo), ArkUI_DragStatus::ARKUI_DRAG_STATUS_UNKNOWN); 97 EXPECT_NE(OH_ArkUI_DragAndDropInfo_GetDragEvent(dragAndDropInfo), nullptr); 98 }); 99 OH_ArkUI_DragAction_UnregisterStatusListener(dragAction); 100 EXPECT_EQ(OH_ArkUI_StartDrag(dragAction), ARKUI_ERROR_CODE_NO_ERROR); 101 OH_ArkUI_DragAction_Dispose(dragAction); 102 } 103 104 /** 105 * @tc.name: DragAndDropTest002 106 * @tc.desc: Test the DragAction for C-API. 107 * @tc.type: FUNC 108 */ 109 HWTEST_F(DragAndDropTest, DragAndDropTest002, TestSize.Level1) 110 { 111 /** 112 * @tc.steps: step1.create dragAction. 113 */ 114 auto uiContext = new ArkUI_Context({ .id = 1 }); 115 auto dragAction = OH_ArkUI_CreateDragActionWithContext(uiContext); 116 EXPECT_NE(dragAction, nullptr); 117 EXPECT_EQ(OH_ArkUI_DragAction_SetPointerId(dragAction, 0), ARKUI_ERROR_CODE_NO_ERROR); 118 EXPECT_EQ(OH_ArkUI_DragAction_SetTouchPointX(dragAction, 1.0), ARKUI_ERROR_CODE_NO_ERROR); 119 EXPECT_EQ(OH_ArkUI_DragAction_SetTouchPointY(dragAction, 1.0), ARKUI_ERROR_CODE_NO_ERROR); 120 auto* interalDragAction = reinterpret_cast<ArkUIDragAction*>(dragAction); 121 EXPECT_EQ(interalDragAction->pointerId, 0); 122 EXPECT_EQ(interalDragAction->touchPointX, 1.0); 123 EXPECT_EQ(interalDragAction->touchPointY, 1.0); 124 OH_ArkUI_DragAction_RegisterStatusListener( __anonf90abb4c0302(ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData) 125 dragAction, nullptr, [](ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData) -> void { 126 EXPECT_NE( 127 OH_ArkUI_DragAndDropInfo_GetDragStatus(dragAndDropInfo), ArkUI_DragStatus::ARKUI_DRAG_STATUS_UNKNOWN); 128 EXPECT_NE(OH_ArkUI_DragAndDropInfo_GetDragEvent(dragAndDropInfo), nullptr); 129 }); 130 OH_ArkUI_DragAction_UnregisterStatusListener(dragAction); 131 EXPECT_EQ(OH_ArkUI_StartDrag(dragAction), ARKUI_ERROR_CODE_NO_ERROR); 132 OH_ArkUI_DragAction_Dispose(dragAction); 133 } 134 135 /** 136 * @tc.name: DragAndDropTest003 137 * @tc.desc: test OH_ArkUI_NodeEvent_GetDragEvent function; 138 * @tc.type: FUNC 139 */ 140 HWTEST_F(DragAndDropTest, DragAndDropTest003, TestSize.Level1) 141 { 142 ArkUI_NodeEvent event = { 0, -1 }; 143 auto eventType = OH_ArkUI_NodeEvent_GetDragEvent(&event); 144 EXPECT_EQ(eventType, nullptr); 145 } 146 147 /** 148 * @tc.name: DragAndDropTest004 149 * @tc.desc: test NodeDrag function; 150 * @tc.type: FUNC 151 */ 152 HWTEST_F(DragAndDropTest, DragAndDropTest004, TestSize.Level1) 153 { 154 /** 155 * @tc.steps: step1.create FrameNode is not null, related function is called. 156 */ 157 auto nodeAPI = reinterpret_cast<ArkUI_NativeNodeAPI_1*>( 158 OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); 159 auto textNode = new ArkUI_Node({ ARKUI_NODE_TEXT, nullptr, true }); 160 auto areaNode = new ArkUI_Node({ ARKUI_NODE_TEXT_AREA, nullptr, true }); 161 162 /** 163 * @tc.expected: Return expected results. 164 */ 165 EXPECT_EQ(nodeAPI->registerNodeEvent(textNode, NODE_ON_PRE_DRAG, 0, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 166 EXPECT_EQ(nodeAPI->registerNodeEvent(textNode, NODE_ON_DRAG_START, 1, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 167 EXPECT_EQ(nodeAPI->registerNodeEvent(textNode, NODE_ON_DRAG_ENTER, 2, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 168 EXPECT_EQ(nodeAPI->registerNodeEvent(textNode, NODE_ON_DRAG_MOVE, 3, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 169 EXPECT_EQ(nodeAPI->registerNodeEvent(textNode, NODE_ON_DRAG_LEAVE, 4, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 170 EXPECT_EQ(nodeAPI->registerNodeEvent(areaNode, NODE_ON_DROP, 5, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 171 EXPECT_EQ(nodeAPI->registerNodeEvent(textNode, NODE_ON_DRAG_END, 6, nullptr), ARKUI_ERROR_CODE_NO_ERROR); 172 } 173 174 /** 175 * @tc.name: DragAndDropTest005 176 * @tc.desc: Test the OH_ArkUI_NodeEvent_GetPreDragStatus. 177 * @tc.type: FUNC 178 */ 179 HWTEST_F(DragAndDropTest, DragAndDropTest005, TestSize.Level1) 180 { 181 /** 182 * @tc.steps: step1.create ArkUI_NodeEvent, related function is called. 183 */ 184 ArkUI_NodeEvent nodeEvent; 185 ArkUINodeEvent event; 186 event.kind = ArkUIEventCategory::COMPONENT_ASYNC_EVENT; 187 event.componentAsyncEvent.subKind = ON_PRE_DRAG; 188 event.componentAsyncEvent.data[0].i32 = 189 static_cast<ArkUI_Int32>(OHOS::Ace::PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION); 190 nodeEvent.origin = &event; 191 nodeEvent.category = NodeEventCategory::NODE_EVENT_CATEGORY_COMPONENT_EVENT; 192 auto ret1 = OH_ArkUI_NodeEvent_GetPreDragStatus(&nodeEvent); 193 194 /** 195 * @tc.steps: step2.set DragEvent is nullptr, related function is called. 196 */ 197 auto ret2 = OH_ArkUI_NodeEvent_GetPreDragStatus(nullptr); 198 199 /** 200 * @tc.steps: step3.set category to other type, related function is called. 201 */ 202 nodeEvent.category = NodeEventCategory::NODE_EVENT_CATEGORY_INPUT_EVENT; 203 auto ret3 = OH_ArkUI_NodeEvent_GetPreDragStatus(&nodeEvent); 204 205 /** 206 * @tc.steps: step4.set origin to nullptr, related function is called. 207 */ 208 nodeEvent.category = NodeEventCategory::NODE_EVENT_CATEGORY_COMPONENT_EVENT; 209 nodeEvent.origin = nullptr; 210 auto ret4 = OH_ArkUI_NodeEvent_GetPreDragStatus(&nodeEvent); 211 212 /** 213 * @tc.expected: Return expected results. 214 */ 215 EXPECT_EQ(ret1, ArkUI_PreDragStatus::ARKUI_PRE_DRAG_STATUS_READY_TO_TRIGGER_DRAG); 216 EXPECT_EQ(ret2, ArkUI_PreDragStatus::ARKUI_PRE_DRAG_STATUS_UNKNOWN); 217 EXPECT_EQ(ret3, ArkUI_PreDragStatus::ARKUI_PRE_DRAG_STATUS_UNKNOWN); 218 EXPECT_EQ(ret4, ArkUI_PreDragStatus::ARKUI_PRE_DRAG_STATUS_UNKNOWN); 219 } 220 221 /** 222 * @tc.name: DragAndDropTest006 223 * @tc.desc: Test the OH_ArkUI_DragEvent_DisableDefaultDropAnimation. 224 * @tc.type: FUNC 225 */ 226 HWTEST_F(DragAndDropTest, DragAndDropTest006, TestSize.Level1) 227 { 228 /** 229 * @tc.steps: step1.create DragEvent, related function is called. 230 */ 231 ArkUIDragEvent dragEvent; 232 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 233 auto ret1 = OH_ArkUI_DragEvent_DisableDefaultDropAnimation(drag_Event, true); 234 235 /** 236 * @tc.steps: step2.set DragEvent is nullptr, related function is called. 237 */ 238 auto ret2 = OH_ArkUI_DragEvent_DisableDefaultDropAnimation(nullptr, false); 239 240 /** 241 * @tc.expected: Return expected results. 242 */ 243 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 244 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 245 EXPECT_EQ(dragEvent.useCustomDropAnimation, true); 246 } 247 248 /** 249 * @tc.name: DragAndDropTest007 250 * @tc.desc: Test the OH_ArkUI_SetNodeDraggable. 251 * @tc.type: FUNC 252 */ 253 HWTEST_F(DragAndDropTest, DragAndDropTest007, TestSize.Level1) 254 { 255 /** 256 * @tc.steps: step1.create DragEvent, related function is called. 257 */ 258 auto textNode = new ArkUI_Node({ ARKUI_NODE_TEXT, nullptr, true }); 259 auto ret1 = OH_ArkUI_SetNodeDraggable(textNode, true); 260 261 /** 262 * @tc.steps: step2.set DragEvent is nullptr, related function is called. 263 */ 264 auto ret2 = OH_ArkUI_SetNodeDraggable(nullptr, false); 265 266 /** 267 * @tc.expected: Return expected results. 268 */ 269 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 270 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 271 } 272 273 /** 274 * @tc.name: DragAndDropTest008 275 * @tc.desc: Test the OH_ArkUI_CreateDragPreviewOption. 276 * @tc.type: FUNC 277 */ 278 HWTEST_F(DragAndDropTest, DragAndDropTest008, TestSize.Level1) 279 { 280 /** 281 * @tc.steps: step1.create ArkUI_DragPreviewOption. 282 * @tc.expected: Return expected results. 283 */ 284 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 285 EXPECT_NE(dragPreviewOption, nullptr); 286 287 /** 288 * @tc.steps: step2.create ArkUI_DragPreviewOption. 289 * @tc.expected: Return expected results. 290 */ 291 OH_ArkUI_DragPreviewOption_Dispose(dragPreviewOption); 292 dragPreviewOption = nullptr; 293 EXPECT_EQ(dragPreviewOption, nullptr); 294 } 295 296 /** 297 * @tc.name: DragAndDropTest009 298 * @tc.desc: Test the OH_ArkUI_DragPreviewOption_SetScaleMode. 299 * @tc.type: FUNC 300 */ 301 HWTEST_F(DragAndDropTest, DragAndDropTest009, TestSize.Level1) 302 { 303 /** 304 * @tc.steps: step1.create dragPreviewOption and set scaleMode. 305 * @tc.expected: Return expected results. 306 */ 307 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 308 auto ret1 = OH_ArkUI_DragPreviewOption_SetScaleMode( 309 dragPreviewOption, ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_AUTO); 310 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 311 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 312 EXPECT_TRUE(option->isScaleEnabled); 313 EXPECT_FALSE(option->isDefaultShadowEnabled); 314 EXPECT_FALSE(option->isDefaultRadiusEnabled); 315 316 /** 317 * @tc.steps: step2.set preview option with nullptr. 318 * @tc.expected: Return expected results. 319 */ 320 auto ret2 = 321 OH_ArkUI_DragPreviewOption_SetScaleMode(nullptr, ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_AUTO); 322 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 323 } 324 325 /** 326 * @tc.name: DragAndDropTest010 327 * @tc.desc: Test the OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled. 328 * @tc.type: FUNC 329 */ 330 HWTEST_F(DragAndDropTest, DragAndDropTest010, TestSize.Level1) 331 { 332 /** 333 * @tc.steps: step1.create dragPreviewOption and call related function. 334 * @tc.expected: Return expected results. 335 */ 336 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 337 auto ret1 = OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(dragPreviewOption, true); 338 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 339 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 340 EXPECT_TRUE(option->isDefaultShadowEnabled); 341 342 /** 343 * @tc.steps: step2.set preview option with nullptr. 344 * @tc.expected: Return expected results. 345 */ 346 auto ret2 = OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(nullptr, true); 347 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 348 } 349 350 /** 351 * @tc.name: DragAndDropTest011 352 * @tc.desc: Test the OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled. 353 * @tc.type: FUNC 354 */ 355 HWTEST_F(DragAndDropTest, DragAndDropTest011, TestSize.Level1) 356 { 357 /** 358 * @tc.steps: step1.create dragPreviewOption and call related function. 359 * @tc.expected: Return expected results. 360 */ 361 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 362 auto ret1 = OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(dragPreviewOption, true); 363 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 364 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 365 EXPECT_TRUE(option->isDefaultRadiusEnabled); 366 367 /** 368 * @tc.steps: step2.set preview option with nullptr. 369 * @tc.expected: Return expected results. 370 */ 371 auto ret2 = OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(nullptr, true); 372 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 373 } 374 375 /** 376 * @tc.name: DragAndDropTest012 377 * @tc.desc: Test the OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled. 378 * @tc.type: FUNC 379 */ 380 HWTEST_F(DragAndDropTest, DragAndDropTest012, TestSize.Level1) 381 { 382 /** 383 * @tc.steps: step1.create dragPreviewOption and call related function. 384 * @tc.expected: Return expected results. 385 */ 386 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 387 auto ret1 = OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(dragPreviewOption, true); 388 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 389 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 390 EXPECT_FALSE(option->isNumberBadgeEnabled); 391 EXPECT_TRUE(option->isShowBadge); 392 393 /** 394 * @tc.steps: step2.set preview option with nullptr. 395 * @tc.expected: Return expected results. 396 */ 397 auto ret2 = OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(nullptr, true); 398 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 399 } 400 401 /** 402 * @tc.name: DragAndDropTest013 403 * @tc.desc: Test the OH_ArkUI_DragPreviewOption_SetBadgeNumber. 404 * @tc.type: FUNC 405 */ 406 HWTEST_F(DragAndDropTest, DragAndDropTest013, TestSize.Level1) 407 { 408 /** 409 * @tc.steps: step1.create dragPreviewOption and call related function. 410 * @tc.expected: Return expected results. 411 */ 412 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 413 auto ret1 = OH_ArkUI_DragPreviewOption_SetBadgeNumber(dragPreviewOption, 2); 414 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 415 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 416 EXPECT_TRUE(option->isNumberBadgeEnabled); 417 EXPECT_EQ(option->badgeNumber, 2); 418 419 /** 420 * @tc.steps: step2.set preview option with nullptr. 421 * @tc.expected: Return expected results. 422 */ 423 auto ret2 = OH_ArkUI_DragPreviewOption_SetBadgeNumber(nullptr, true); 424 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 425 } 426 427 /** 428 * @tc.name: DragAndDropTest014 429 * @tc.desc: Test the OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled. 430 * @tc.type: FUNC 431 */ 432 HWTEST_F(DragAndDropTest, DragAndDropTest014, TestSize.Level1) 433 { 434 /** 435 * @tc.steps: step1.create dragPreviewOption and call related function. 436 * @tc.expected: Return expected results. 437 */ 438 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 439 auto ret1 = OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(dragPreviewOption, true); 440 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 441 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 442 EXPECT_TRUE(option->defaultAnimationBeforeLifting); 443 444 /** 445 * @tc.steps: step2.set preview option with nullptr. 446 * @tc.expected: Return expected results. 447 */ 448 auto ret2 = OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(nullptr, true); 449 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 450 } 451 452 /** 453 * @tc.name: DragAndDropTest015 454 * @tc.desc: Test the preview option mix setting. 455 * @tc.type: FUNC 456 */ 457 HWTEST_F(DragAndDropTest, DragAndDropTest015, TestSize.Level1) 458 { 459 /** 460 * @tc.steps: step1.create dragPreviewOption and call mix related function. 461 * @tc.expected: Return expected results. 462 */ 463 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 464 OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(dragPreviewOption, true); 465 OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(dragPreviewOption, true); 466 OH_ArkUI_DragPreviewOption_SetScaleMode( 467 dragPreviewOption, ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_AUTO); 468 auto* option = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(dragPreviewOption); 469 EXPECT_TRUE(option->isScaleEnabled); 470 EXPECT_FALSE(option->isDefaultShadowEnabled); 471 EXPECT_FALSE(option->isDefaultRadiusEnabled); 472 } 473 474 /** 475 * @tc.name: DragAndDropTest016 476 * @tc.desc: Test OH_ArkUI_SetNodeDragPreviewOption. 477 * @tc.type: FUNC 478 */ 479 HWTEST_F(DragAndDropTest, DragAndDropTest016, TestSize.Level1) 480 { 481 /** 482 * @tc.steps: step1.create dragPreviewOption and call mix related function. 483 * @tc.expected: Return expected results. 484 */ 485 auto* dragPreviewOption = OH_ArkUI_CreateDragPreviewOption(); 486 OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(dragPreviewOption, true); 487 OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(dragPreviewOption, true); 488 OH_ArkUI_DragPreviewOption_SetScaleMode( 489 dragPreviewOption, ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_AUTO); 490 auto textNode = new ArkUI_Node({ ARKUI_NODE_TEXT, nullptr, true }); 491 auto ret1 = OH_ArkUI_SetNodeDragPreviewOption(textNode, dragPreviewOption); 492 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 493 494 /** 495 * @tc.steps: step2.set preview option with nullptr. 496 * @tc.expected: Return expected results. 497 */ 498 auto ret2 = OH_ArkUI_SetNodeDragPreviewOption(nullptr, dragPreviewOption); 499 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 500 } 501 502 /** 503 * @tc.name: DragAndDropTest0017 504 * @tc.desc: test set DragEvent property function; 505 * @tc.type: FUNC 506 */ 507 HWTEST_F(DragAndDropTest, DragAndDropTest0017, TestSize.Level1) 508 { 509 /** 510 *@tc.steps : step1.create and set property. 511 */ 512 ArkUIDragEvent dragEvent; 513 dragEvent.windowX = WINDOW_X; 514 dragEvent.windowY = WINDOW_Y; 515 dragEvent.displayX = DISPLAY_X; 516 dragEvent.displayY = DISPLAY_Y; 517 dragEvent.touchPointX = TOUCH_POINT_X; 518 dragEvent.touchPointY = TOUCH_POINT_Y; 519 520 dragEvent.previewRectWidth = PREVIEW_RECT_WIDTH; 521 dragEvent.previewRectHeight = PREVIEW_RECT_HEIGHT; 522 dragEvent.velocityX = VELOCITY_X; 523 dragEvent.velocityY = VELOCITY_Y; 524 dragEvent.velocity = VELOCITY; 525 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 526 527 /** 528 * @tc.expected: Return expected results. 529 */ 530 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointXToWindow(drag_Event), WINDOW_X); 531 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointYToWindow(drag_Event), WINDOW_Y); 532 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewTouchPointX(drag_Event), TOUCH_POINT_X); 533 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewTouchPointY(drag_Event), TOUCH_POINT_Y); 534 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointXToDisplay(drag_Event), DISPLAY_X); 535 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointYToDisplay(drag_Event), DISPLAY_Y); 536 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewRectWidth(drag_Event), PREVIEW_RECT_WIDTH); 537 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewRectHeight(drag_Event), PREVIEW_RECT_HEIGHT); 538 EXPECT_EQ(OH_ArkUI_DragEvent_GetVelocityX(drag_Event), VELOCITY_X); 539 EXPECT_EQ(OH_ArkUI_DragEvent_GetVelocityY(drag_Event), VELOCITY_Y); 540 EXPECT_EQ(OH_ArkUI_DragEvent_GetVelocity(drag_Event), VELOCITY); 541 } 542 543 /** 544 * @tc.name: DragAndDropTest0018 545 * @tc.desc: test set DragEvent property function; 546 * @tc.type: FUNC 547 */ 548 HWTEST_F(DragAndDropTest, DragAndDropTest0018, TestSize.Level1) 549 { 550 /** 551 * @tc.expected: Return expected results. 552 */ 553 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointXToWindow(nullptr), 0.0f); 554 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointYToWindow(nullptr), 0.0f); 555 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewTouchPointX(nullptr), 0.0f); 556 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewTouchPointY(nullptr), 0.0f); 557 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointXToDisplay(nullptr), 0.0f); 558 EXPECT_EQ(OH_ArkUI_DragEvent_GetTouchPointYToDisplay(nullptr), 0.0f); 559 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewRectWidth(nullptr), 0.0f); 560 EXPECT_EQ(OH_ArkUI_DragEvent_GetPreviewRectHeight(nullptr), 0.0f); 561 EXPECT_EQ(OH_ArkUI_DragEvent_GetVelocityX(nullptr), 0.0f); 562 EXPECT_EQ(OH_ArkUI_DragEvent_GetVelocityY(nullptr), 0.0f); 563 EXPECT_EQ(OH_ArkUI_DragEvent_GetVelocity(nullptr), 0.0f); 564 } 565 566 /** 567 * @tc.name: DragAndDropTest0019 568 * @tc.desc: test ConvertOriginEventType function for drag event. 569 * @tc.type: FUNC 570 */ 571 HWTEST_F(DragAndDropTest, DragAndDropTest019, TestSize.Level1) 572 { 573 int32_t ret; 574 int32_t nodeType = static_cast<int32_t>(NODE_ON_PRE_DRAG); 575 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_PRE_DRAG, nodeType); 576 EXPECT_EQ(ret, static_cast<int32_t>(ON_PRE_DRAG)); 577 578 nodeType = static_cast<int32_t>(NODE_ON_DRAG_START); 579 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_DRAG_START, nodeType); 580 EXPECT_EQ(ret, static_cast<int32_t>(ON_DRAG_START)); 581 582 nodeType = static_cast<int32_t>(NODE_ON_DRAG_ENTER); 583 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_DRAG_ENTER, nodeType); 584 EXPECT_EQ(ret, static_cast<int32_t>(ON_DRAG_ENTER)); 585 586 nodeType = static_cast<int32_t>(NODE_ON_DRAG_MOVE); 587 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_DRAG_MOVE, nodeType); 588 EXPECT_EQ(ret, static_cast<int32_t>(ON_DRAG_MOVE)); 589 590 nodeType = static_cast<int32_t>(NODE_ON_DRAG_LEAVE); 591 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_DRAG_LEAVE, nodeType); 592 EXPECT_EQ(ret, static_cast<int32_t>(ON_DRAG_LEAVE)); 593 594 nodeType = static_cast<int32_t>(NODE_ON_DROP); 595 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_DROP, nodeType); 596 EXPECT_EQ(ret, static_cast<int32_t>(ON_DRAG_DROP)); 597 598 nodeType = static_cast<int32_t>(NODE_ON_DRAG_END); 599 ret = OHOS::Ace::NodeModel::ConvertOriginEventType(NODE_ON_DRAG_END, nodeType); 600 EXPECT_EQ(ret, static_cast<int32_t>(ON_DRAG_END)); 601 } 602 603 /** 604 * @tc.name: DragAndDropTest0020 605 * @tc.desc: test ConvertToNodeEventType function for drag event. 606 * @tc.type: FUNC 607 */ 608 HWTEST_F(DragAndDropTest, DragAndDropTest020, TestSize.Level1) 609 { 610 int32_t ret; 611 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_PRE_DRAG); 612 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_PRE_DRAG)); 613 614 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_START); 615 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_DRAG_START)); 616 617 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_ENTER); 618 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_DRAG_ENTER)); 619 620 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_MOVE); 621 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_DRAG_MOVE)); 622 623 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_LEAVE); 624 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_DRAG_LEAVE)); 625 626 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_DROP); 627 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_DROP)); 628 629 ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_END); 630 EXPECT_EQ(ret, static_cast<int32_t>(NODE_ON_DRAG_END)); 631 } 632 633 /** 634 * @tc.name: DragAndDropTest0021 635 * @tc.desc: test OH_ArkUI_DragEvent_GetDropOperation. 636 * @tc.type: FUNC 637 */ 638 HWTEST_F(DragAndDropTest, DragAndDropTest021, TestSize.Level1) 639 { 640 /** 641 *@tc.steps : step1.create and set property. 642 */ 643 ArkUIDragEvent dragEvent; 644 dragEvent.dragBehavior = ArkUI_DropOperation::ARKUI_DROP_OPERATION_MOVE; 645 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 646 ArkUI_DropOperation operation; 647 auto ret = OH_ArkUI_DragEvent_GetDropOperation(drag_Event, &operation); 648 649 /** 650 * @tc.expected: Return expected results. 651 */ 652 EXPECT_EQ(ret, ARKUI_ERROR_CODE_NO_ERROR); 653 EXPECT_EQ(operation, ArkUI_DropOperation::ARKUI_DROP_OPERATION_MOVE); 654 EXPECT_EQ(OH_ArkUI_DragEvent_GetDropOperation(nullptr, &operation), ARKUI_ERROR_CODE_PARAM_INVALID); 655 EXPECT_EQ(OH_ArkUI_DragEvent_GetDropOperation(drag_Event, nullptr), ARKUI_ERROR_CODE_PARAM_INVALID); 656 } 657 658 /** 659 * @tc.name: DragAndDropTest0022 660 * @tc.desc: Test the OH_ArkUI_DragEvent_GetModifierKeyStates. 661 * @tc.type: FUNC 662 */ 663 HWTEST_F(DragAndDropTest, DragAndDropTest0022, TestSize.Level1) 664 { 665 /** 666 * @tc.steps: step1.create DragEvent, related function is called. 667 */ 668 uint64_t pressedKeys = 0; 669 ArkUIDragEvent dragEvent; 670 dragEvent.modifierKeyState = (1 << 0); 671 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 672 auto ret1 = OH_ArkUI_DragEvent_GetModifierKeyStates(drag_Event, &pressedKeys); 673 674 /** 675 * @tc.steps: step2.set DragEvent is nullptr, related function is called. 676 */ 677 auto ret2 = OH_ArkUI_DragEvent_GetModifierKeyStates(nullptr, nullptr); 678 679 /** 680 * @tc.expected: Return expected results. 681 */ 682 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 683 EXPECT_EQ(pressedKeys, (1 << 0)); 684 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 685 } 686 687 /** 688 * @tc.name: DragAndDropTest0023 689 * @tc.desc: Test the OH_ArkUI_DragEvent_GetDataTypeCount. 690 * @tc.type: FUNC 691 */ 692 HWTEST_F(DragAndDropTest, DragAndDropTest0023, TestSize.Level1) 693 { 694 /** 695 * @tc.steps: step1.create DragEvent, related function is called. 696 */ 697 int32_t count = 0; 698 ArkUIDragEvent dragEvent; 699 dragEvent.dataTypesCount = 2; 700 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 701 auto ret1 = OH_ArkUI_DragEvent_GetDataTypeCount(drag_Event, &count); 702 703 /** 704 * @tc.steps: step2.set DragEvent is nullptr, related function is called. 705 */ 706 auto ret2 = OH_ArkUI_DragEvent_GetDataTypeCount(nullptr, nullptr); 707 708 /** 709 * @tc.expected: Return expected results. 710 */ 711 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 712 EXPECT_EQ(count, 2); 713 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 714 } 715 716 /** 717 * @tc.name: DragAndDropTest0024 718 * @tc.desc: Test the OH_ArkUI_DragEvent_GetDataTypes. 719 * @tc.type: FUNC 720 */ 721 HWTEST_F(DragAndDropTest, DragAndDropTest0024, TestSize.Level1) 722 { 723 /** 724 * @tc.steps: step1.create DragEvent is nullptr, related function is called. 725 */ 726 int32_t length = 2; 727 int32_t maxStrLen = 128; 728 auto ret2 = OH_ArkUI_DragEvent_GetDataTypes(nullptr, nullptr, length, maxStrLen); 729 730 /** 731 * @tc.expected: Return expected results. 732 */ 733 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 734 } 735 736 /** 737 * @tc.name: DragAndDropTest0025 738 * @tc.desc: Test the OH_ArkUI_CreateDragActionWithNode. 739 * @tc.type: FUNC 740 */ 741 HWTEST_F(DragAndDropTest, DragAndDropTest0025, TestSize.Level1) 742 { 743 /** 744 * @tc.steps: step1.set null ArkUI_NodeHandle, related function is called. 745 */ 746 auto* dragAction = OH_ArkUI_CreateDragActionWithNode(nullptr); 747 748 /** 749 * @tc.expected: Return expected results. 750 */ 751 EXPECT_EQ(dragAction, nullptr); 752 } 753 754 /** 755 * @tc.name: DragAndDropTest0026 756 * @tc.desc: Test the OH_ArkUI_CreateDragActionWithContext. 757 * @tc.type: FUNC 758 */ 759 HWTEST_F(DragAndDropTest, DragAndDropTest0026, TestSize.Level1) 760 { 761 /** 762 * @tc.steps: step1.set null ArkUI_ContextHandle, related function is called. 763 */ 764 auto* dragAction = OH_ArkUI_CreateDragActionWithContext(nullptr); 765 OH_ArkUI_DragAction_Dispose(dragAction); 766 EXPECT_EQ(OH_ArkUI_DragAction_SetTouchPointX(dragAction, 1.0), ARKUI_ERROR_CODE_PARAM_INVALID); 767 EXPECT_EQ(OH_ArkUI_DragAction_SetTouchPointY(dragAction, 1.0), ARKUI_ERROR_CODE_PARAM_INVALID); 768 769 /** 770 * @tc.expected: Return expected results. 771 */ 772 EXPECT_EQ(dragAction, nullptr); 773 } 774 775 /** 776 * @tc.name: DragAndDropTest0027 777 * @tc.desc: Test the OH_ArkUI_CreateDragActionWithContext. 778 * @tc.type: FUNC 779 */ 780 HWTEST_F(DragAndDropTest, DragAndDropTest0027, TestSize.Level1) 781 { 782 /** 783 * @tc.steps: step1.create dragAction. 784 */ 785 auto uiContext = new ArkUI_Context({ .id = 1 }); 786 auto dragAction = OH_ArkUI_CreateDragActionWithContext(uiContext); 787 EXPECT_NE(dragAction, nullptr); 788 789 /** 790 * @tc.steps: step2.set pointer is smaller than MIN_POINTID, related function is called. 791 */ 792 auto ret1 = OH_ArkUI_DragAction_SetPointerId(dragAction, -1); 793 794 /** 795 * @tc.steps: step2.set dragAction is null, related function is called. 796 */ 797 auto ret2 = OH_ArkUI_DragAction_SetPointerId(nullptr, 1); 798 799 /** 800 * @tc.expected: Return expected results. 801 */ 802 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 803 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 804 } 805 806 /** 807 * @tc.name: DragAndDropTest0028 808 * @tc.desc: Test the OH_ArkUI_DragAction_SetDragPreviewOption. 809 * @tc.type: FUNC 810 */ 811 HWTEST_F(DragAndDropTest, DragAndDropTest0028, TestSize.Level1) 812 { 813 /** 814 * @tc.steps: step1.create dragAction. 815 */ 816 auto uiContext = new ArkUI_Context({ .id = 1 }); 817 auto dragAction = OH_ArkUI_CreateDragActionWithContext(uiContext); 818 EXPECT_NE(dragAction, nullptr); 819 auto *previewOptions = OH_ArkUI_CreateDragPreviewOption(); 820 OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(previewOptions, true); 821 auto ret1 = OH_ArkUI_DragAction_SetDragPreviewOption(dragAction, previewOptions); 822 823 /** 824 * @tc.steps: step2.set dragAction is null, related function is called. 825 */ 826 auto ret2 = OH_ArkUI_DragAction_SetDragPreviewOption(nullptr, previewOptions); 827 828 /** 829 * @tc.expected: Return expected results. 830 */ 831 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_NO_ERROR); 832 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_PARAM_INVALID); 833 } 834 835 /** 836 * @tc.name: DragAndDropTest0029 837 * @tc.desc: Test the OH_ArkUI_DragAction_RegisterStatusListener. 838 * @tc.type: FUNC 839 */ 840 HWTEST_F(DragAndDropTest, DragAndDropTest0029, TestSize.Level1) 841 { 842 /** 843 * @tc.steps: step1.set dragAction is null, related function is called. 844 */ 845 auto ret = OH_ArkUI_DragAction_RegisterStatusListener( __anonf90abb4c0402(ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData) 846 nullptr, nullptr, [](ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData) -> void { 847 EXPECT_NE( 848 OH_ArkUI_DragAndDropInfo_GetDragStatus(dragAndDropInfo), ArkUI_DragStatus::ARKUI_DRAG_STATUS_UNKNOWN); 849 EXPECT_NE(OH_ArkUI_DragAndDropInfo_GetDragEvent(dragAndDropInfo), nullptr); 850 }); 851 OH_ArkUI_DragAction_UnregisterStatusListener(nullptr); 852 853 /** 854 * @tc.expected: Return expected results. 855 */ 856 EXPECT_EQ(ret, ARKUI_ERROR_CODE_PARAM_INVALID); 857 } 858 859 /** 860 * @tc.name: DragAndDropTest0030 861 * @tc.desc: Test the OH_ArkUI_DragAndDropInfo_GetDragStatus. 862 * @tc.type: FUNC 863 */ 864 HWTEST_F(DragAndDropTest, DragAndDropTest0030, TestSize.Level1) 865 { 866 /** 867 * @tc.steps: step1.set dragAction is null, related function is called. 868 */ 869 auto ret1 = OH_ArkUI_DragAndDropInfo_GetDragStatus(nullptr); 870 auto ret2 = OH_ArkUI_DragAndDropInfo_GetDragEvent(nullptr); 871 872 /** 873 * @tc.expected: Return expected results. 874 */ 875 EXPECT_EQ(ret1, ArkUI_DragStatus::ARKUI_DRAG_STATUS_UNKNOWN); 876 EXPECT_EQ(ret2, nullptr); 877 } 878 879 /** 880 * @tc.name: DragAndDropTest0031 881 * @tc.desc: Test the OH_ArkUI_SetNodeDragPreview. 882 * @tc.type: FUNC 883 */ 884 HWTEST_F(DragAndDropTest, DragAndDropTest0031, TestSize.Level1) 885 { 886 /** 887 * @tc.steps: step1.set ArkUI_NodeHandle is null, related function is called. 888 */ 889 auto ret1 = OH_ArkUI_SetNodeDragPreview(nullptr, nullptr); 890 891 /** 892 * @tc.expected: Return expected results. 893 */ 894 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 895 } 896 897 /** 898 * @tc.name: DragAndDropTest0032 899 * @tc.desc: Test the OH_ArkUI_SetNodeAllowedDropDataTypes. 900 * @tc.type: FUNC 901 */ 902 HWTEST_F(DragAndDropTest, DragAndDropTest0032, TestSize.Level1) 903 { 904 /** 905 * @tc.steps: step1.set ArkUI_NodeHandle is null, related function is called. 906 */ 907 auto ret1 = OH_ArkUI_SetNodeAllowedDropDataTypes(nullptr, nullptr, -1); 908 909 /** 910 * @tc.steps: step1.set ArkUI_NodeHandle and typesArray, related function is called. 911 */ 912 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 913 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 914 auto dragNode = nodeAPI->createNode(ARKUI_NODE_COLUMN); 915 std::vector<const char *> strlist; 916 strlist.push_back("general.text"); 917 strlist.push_back("general.plain-text"); 918 auto ret2 = OH_ArkUI_SetNodeAllowedDropDataTypes(dragNode, strlist.data(), strlist.size()); 919 920 /** 921 * @tc.expected: Return expected results. 922 */ 923 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 924 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 925 } 926 927 /** 928 * @tc.name: DragAndDropTest0033 929 * @tc.desc: Test the OH_ArkUI_SetDragEventStrictReportWithNode. 930 * @tc.type: FUNC 931 */ 932 HWTEST_F(DragAndDropTest, DragAndDropTest0033, TestSize.Level1) 933 { 934 /** 935 * @tc.steps: step1.set ArkUI_NodeHandle is null, related function is called. 936 */ 937 auto ret1 = OH_ArkUI_SetDragEventStrictReportWithNode(nullptr, false); 938 939 /** 940 * @tc.steps: step1.set ArkUI_NodeHandle and typesArray, related function is called. 941 */ 942 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 943 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 944 auto dragNode = nodeAPI->createNode(ARKUI_NODE_COLUMN); 945 auto ret2 = OH_ArkUI_SetDragEventStrictReportWithNode(dragNode, true); 946 947 /** 948 * @tc.expected: Return expected results. 949 */ 950 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 951 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 952 } 953 954 /** 955 * @tc.name: DragAndDropTest0034 956 * @tc.desc: Test the OH_ArkUI_SetDragEventStrictReportWithContext. 957 * @tc.type: FUNC 958 */ 959 HWTEST_F(DragAndDropTest, DragAndDropTest0034, TestSize.Level1) 960 { 961 /** 962 * @tc.steps: step1.set ArkUI_NodeHandle is null, related function is called. 963 */ 964 auto ret1 = OH_ArkUI_SetDragEventStrictReportWithContext(nullptr, false); 965 966 /** 967 * @tc.steps: step1.set ArkUI_NodeHandle and typesArray, related function is called. 968 */ 969 auto uiContext = new ArkUI_Context({ .id = 1 }); 970 auto ret2 = OH_ArkUI_SetDragEventStrictReportWithContext(uiContext, true); 971 972 /** 973 * @tc.expected: Return expected results. 974 */ 975 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 976 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 977 } 978 979 /** 980 * @tc.name: DragAndDropTest0035 981 * @tc.desc: Test the OH_ArkUI_DisallowNodeAnyDropDataTypes. 982 * @tc.type: FUNC 983 */ 984 HWTEST_F(DragAndDropTest, DragAndDropTest0035, TestSize.Level1) 985 { 986 /** 987 * @tc.steps: step1.set ArkUI_ContextHandle is null, related function is called. 988 */ 989 auto ret1 = OH_ArkUI_DisallowNodeAnyDropDataTypes(nullptr); 990 991 /** 992 * @tc.steps: step1.set ArkUI_ContextHandle, related function is called. 993 */ 994 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 995 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 996 auto dragNode = nodeAPI->createNode(ARKUI_NODE_COLUMN); 997 auto ret2 = OH_ArkUI_DisallowNodeAnyDropDataTypes(dragNode); 998 999 /** 1000 * @tc.expected: Return expected results. 1001 */ 1002 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1003 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 1004 } 1005 1006 /** 1007 * @tc.name: DragAndDropTest0036 1008 * @tc.desc: Test the OH_ArkUI_AllowNodeAllDropDataTypes. 1009 * @tc.type: FUNC 1010 */ 1011 HWTEST_F(DragAndDropTest, DragAndDropTest0036, TestSize.Level1) 1012 { 1013 /** 1014 * @tc.steps: step1.set ArkUI_ContextHandle is null, related function is called. 1015 */ 1016 auto ret1 = OH_ArkUI_AllowNodeAllDropDataTypes(nullptr); 1017 1018 /** 1019 * @tc.steps: step1.set ArkUI_ContextHandle, related function is called. 1020 */ 1021 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 1022 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 1023 auto dragNode = nodeAPI->createNode(ARKUI_NODE_COLUMN); 1024 auto ret2 = OH_ArkUI_AllowNodeAllDropDataTypes(dragNode); 1025 1026 /** 1027 * @tc.expected: Return expected results. 1028 */ 1029 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1030 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 1031 } 1032 1033 /** 1034 * @tc.name: DragAndDropTest0037 1035 * @tc.desc: Test the OH_ArkUI_DragEvent_GetDragResult. 1036 * @tc.type: FUNC 1037 */ 1038 HWTEST_F(DragAndDropTest, DragAndDropTest0037, TestSize.Level1) 1039 { 1040 /** 1041 * @tc.steps: step1.set ArkUI_DragEvent is null, related function is called. 1042 */ 1043 auto ret1 = OH_ArkUI_DragEvent_GetDragResult(nullptr, nullptr); 1044 1045 /** 1046 * @tc.steps: step1.set ArkUI_DragEvent and DragResult, related function is called. 1047 */ 1048 ArkUIDragEvent dragEvent; 1049 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 1050 ArkUI_DragResult result; 1051 auto ret2 = OH_ArkUI_DragEvent_GetDragResult(drag_Event, &result); 1052 1053 /** 1054 * @tc.expected: Return expected results. 1055 */ 1056 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1057 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 1058 } 1059 1060 /** 1061 * @tc.name: DragAndDropTest0038 1062 * @tc.desc: Test the OH_ArkUI_DragEvent_SetDragResult. 1063 * @tc.type: FUNC 1064 */ 1065 HWTEST_F(DragAndDropTest, DragAndDropTest0038, TestSize.Level1) 1066 { 1067 /** 1068 * @tc.steps: step1.set ArkUI_DragEvent is null, related function is called. 1069 */ 1070 auto ret1 = OH_ArkUI_DragEvent_SetDragResult(nullptr, ArkUI_DragResult::ARKUI_DRAG_RESULT_SUCCESSFUL); 1071 1072 /** 1073 * @tc.steps: step1.set ArkUI_DragEvent and DragResult, related function is called. 1074 */ 1075 ArkUIDragEvent dragEvent; 1076 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 1077 auto ret2 = OH_ArkUI_DragEvent_SetDragResult(drag_Event, ArkUI_DragResult::ARKUI_DRAG_RESULT_SUCCESSFUL); 1078 1079 /** 1080 * @tc.expected: Return expected results. 1081 */ 1082 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1083 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 1084 } 1085 1086 /** 1087 * @tc.name: DragAndDropTest0039 1088 * @tc.desc: Test the OH_ArkUI_DragEvent_SetSuggestedDropOperation. 1089 * @tc.type: FUNC 1090 */ 1091 HWTEST_F(DragAndDropTest, DragAndDropTest0039, TestSize.Level1) 1092 { 1093 /** 1094 * @tc.steps: step1.set ArkUI_DragEvent is null, related function is called. 1095 */ 1096 auto ret1 = OH_ArkUI_DragEvent_SetSuggestedDropOperation(nullptr, 1097 ArkUI_DropOperation::ARKUI_DROP_OPERATION_COPY); 1098 1099 /** 1100 * @tc.steps: step1.set ArkUI_DragEvent and DropOperation, related function is called. 1101 */ 1102 ArkUIDragEvent dragEvent; 1103 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 1104 auto ret2 = OH_ArkUI_DragEvent_SetSuggestedDropOperation(drag_Event, 1105 ArkUI_DropOperation::ARKUI_DROP_OPERATION_COPY); 1106 1107 /** 1108 * @tc.expected: Return expected results. 1109 */ 1110 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1111 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 1112 } 1113 1114 /** 1115 * @tc.name: DragAndDropTest0040 1116 * @tc.desc: Test the OH_ArkUI_CancelDataLoading. 1117 * @tc.type: FUNC 1118 */ 1119 HWTEST_F(DragAndDropTest, DragAndDropTest0040, TestSize.Level1) 1120 { 1121 /** 1122 * @tc.steps: step1.set ArkUI_ContextHandle is null, related function is called. 1123 */ 1124 const char* key = "testKey"; 1125 auto ret1 = OH_ArkUI_CancelDataLoading(nullptr, key); 1126 1127 /** 1128 * @tc.expected: Return expected results. 1129 */ 1130 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1131 } 1132 1133 /** 1134 * @tc.name: DragAndDropTest0041 1135 * @tc.desc: Test the OH_ArkUI_DisableDropDataPrefetchOnNode. 1136 * @tc.type: FUNC 1137 */ 1138 HWTEST_F(DragAndDropTest, DragAndDropTest0041, TestSize.Level1) 1139 { 1140 /** 1141 * @tc.steps: step1.set ArkUI_NodeHandle is null, related function is called. 1142 */ 1143 auto ret1 = OH_ArkUI_DisableDropDataPrefetchOnNode(nullptr, false); 1144 1145 /** 1146 * @tc.steps: step1.set ArkUI_NodeHandle, related function is called. 1147 */ 1148 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 1149 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 1150 auto dragNode = nodeAPI->createNode(ARKUI_NODE_COLUMN); 1151 auto ret2 = OH_ArkUI_DisableDropDataPrefetchOnNode(dragNode, false); 1152 1153 /** 1154 * @tc.expected: Return expected results. 1155 */ 1156 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1157 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_NO_ERROR); 1158 } 1159 1160 /** 1161 * @tc.name: DragAndDropTest0042 1162 * @tc.desc: Test the OH_ArkUI_DragEvent_RequestDragEndPending. 1163 * @tc.type: FUNC 1164 */ 1165 HWTEST_F(DragAndDropTest, DragAndDropTest0042, TestSize.Level1) 1166 { 1167 /** 1168 * @tc.steps: step1.set ArkUI_DragEvent is null, related function is called. 1169 */ 1170 auto ret1 = OH_ArkUI_DragEvent_RequestDragEndPending(nullptr, nullptr); 1171 1172 /** 1173 * @tc.steps: step1.set ArkUI_DragEvent and requestIdentify, related function is called. 1174 */ 1175 ArkUIDragEvent dragEvent; 1176 auto* drag_Event = reinterpret_cast<ArkUI_DragEvent*>(&dragEvent); 1177 int32_t requestIdentify = 0; 1178 auto ret2 = OH_ArkUI_DragEvent_RequestDragEndPending(drag_Event, &requestIdentify); 1179 1180 /** 1181 * @tc.expected: Return expected results. 1182 */ 1183 EXPECT_EQ(ret1, ARKUI_ERROR_CODE_PARAM_INVALID); 1184 EXPECT_EQ(ret2, ARKUI_ERROR_CODE_DRAG_DROP_OPERATION_NOT_ALLOWED); 1185 EXPECT_EQ(dragEvent.isDragEndPending, false); 1186 } 1187 } // namespace OHOS::Ace