!38827 【NDK】customdialog问题修改与TDD新增

Merge pull request !38827 from yyuanche/ndk_dialog_tdd
This commit is contained in:
openharmony_ci 2024-07-29 08:09:33 +00:00 committed by Gitee
commit db0cdab7f2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 75 additions and 6 deletions

View File

@ -167,8 +167,6 @@ void ParseDialogProperties(DialogProperties& dialogProperties, ArkUIDialogHandle
controllerHandler->onWillDismissCallByNDK(&event);
return event.BlockDismiss;
};
} else {
dialogProperties.onWillDismissCallByNDK = nullptr;
}
if (controllerHandler->enableCustomAnimation && !dialogProperties.openAnimation.has_value()) {

View File

@ -242,7 +242,7 @@ typedef struct {
* <b>true</b> means to block the system behavior, and <b>false</b> means the opposite.
* @since 12
*/
void ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss);
void OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss);
/**
* @brief Obtains the pointer to user data in a dialog box dismiss event object.
@ -252,7 +252,7 @@ void ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* ev
* @return Returns the pointer to user data.
* @since 12
*/
void* ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event);
void* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event);
/**
* @brief Obtains the c from a dialog box dismiss event object.
@ -267,7 +267,7 @@ void* ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event);
* {@link DIALOG_DISMISS_SLIDE_DOWN}: sliding down.
* @since 12
*/
int32_t ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event);
int32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event);
#ifdef __cplusplus
};

View File

@ -189,7 +189,7 @@ int32_t RegisterOnWillDismissWithUserData(
ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event))
{
auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
if (!impl || !handle || !callback) {
if (!impl || !handle) {
return ERROR_CODE_PARAM_INVALID;
}
int result = impl->getDialogAPI()->registerOnWillDismissWithUserData(handle->controller, userData, callback);

View File

@ -491,4 +491,75 @@ HWTEST_F(DialogModelTest, DialogModelTest033, TestSize.Level1)
ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
Dispose(nativeDialogHandle);
nativeDialogHandle = nullptr;
}
/**
* @tc.name: DialogModelTest034
* @tc.desc: Test RegisterOnWillDismissWithUserData function.
* @tc.type: FUNC
*/
HWTEST_F(DialogModelTest, DialogModelTest034, TestSize.Level1)
{
ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
ArkUI_NativeDialogHandle nativeDialogHandle = Create();
ASSERT_NE(nativeDialogHandle, nullptr);
ArkUI_DialogDismissEvent nEvent;
int32_t ret =
RegisterOnWillDismissWithUserData(nativeDialogHandle, nEvent.userData, [](ArkUI_DialogDismissEvent* event) {});
ASSERT_EQ(ret, 0);
ret = RegisterOnWillDismissWithUserData(nullptr, nullptr, nullptr);
ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
Dispose(nativeDialogHandle);
nativeDialogHandle = nullptr;
}
/**
* @tc.name: DialogModelTest035
* @tc.desc: Test ArkUI_DialogDismissEvent_SetShouldBlockDismiss function.
* @tc.type: FUNC
*/
HWTEST_F(DialogModelTest, DialogModelTest035, TestSize.Level1)
{
ArkUI_DialogDismissEvent* nEvent = new ArkUI_DialogDismissEvent({ nullptr, 0, false });
OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(nEvent, true);
ASSERT_TRUE(nEvent->BlockDismiss);
nEvent = nullptr;
OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(nEvent, true);
ASSERT_TRUE(nEvent == nullptr);
}
/**
* @tc.name: DialogModelTest036
* @tc.desc: Test ArkUI_DialogDismissEvent_GetUserData function.
* @tc.type: FUNC
*/
HWTEST_F(DialogModelTest, DialogModelTest036, TestSize.Level1)
{
struct ArkUICustomData {
float id;
int index;
};
auto customData = new ArkUICustomData { 12, 1 };
ArkUI_DialogDismissEvent* nEvent = new ArkUI_DialogDismissEvent({ nullptr, 0, false });
nEvent->userData = customData;
void* ret = OH_ArkUI_DialogDismissEvent_GetUserData(nEvent);
ASSERT_EQ(ret, nEvent->userData);
nEvent = nullptr;
ret = OH_ArkUI_DialogDismissEvent_GetUserData(nEvent);
ASSERT_TRUE(ret == nullptr);
}
/**
* @tc.name: DialogModelTest037
* @tc.desc: Test ArkUI_DialogDismissEvent_GetUserData function.
* @tc.type: FUNC
*/
HWTEST_F(DialogModelTest, DialogModelTest037, TestSize.Level1)
{
ArkUI_DialogDismissEvent* nEvent = new ArkUI_DialogDismissEvent({ nullptr, 0, false });
int32_t ret = OH_ArkUI_DialogDismissEvent_GetDismissReason(nEvent);
ASSERT_EQ(ret, nEvent->reason);
nEvent = nullptr;
ret = OH_ArkUI_DialogDismissEvent_GetDismissReason(nEvent);
ASSERT_EQ(ret, -1);
}