uv_queue_work change to napi_send_event

Signed-off-by: libo429 <libo429@huawei.com>
This commit is contained in:
libo429 2024-11-19 20:15:19 +08:00
parent cdde0846c2
commit 51395a7352
5 changed files with 96 additions and 177 deletions

View File

@ -851,27 +851,30 @@ int ExtBackupJs::CallJsMethod(const std::string &funcName,
work->data = reinterpret_cast<void *>(param.get());
HILOGI("Will execute current js method");
int ret = uv_queue_work(
loop, work.get(), [](uv_work_t *work) {},
[](uv_work_t *work, int status) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
do {
if (param == nullptr) {
HILOGE("failed to get CallJsParam.");
break;
}
HILOGI("Start call current js method");
if (DoCallJsMethod(param) != ERR_OK) {
HILOGE("failed to call DoCallJsMethod.");
}
} while (false);
HILOGI("will notify current thread info");
std::unique_lock<std::mutex> lock(param->backupOperateMutex);
param->isReady.store(true);
param->backupOperateCondition.notify_all();
});
if (ret != 0) {
HILOGE("failed to exec uv_queue_work.");
auto task = [work {work.get()}]() {
if (work == nullptr) {
HILOGE("failed to get work.");
return;
}
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
do {
if (param == nullptr) {
HILOGE("failed to get CallJsParam.");
break;
}
HILOGI("Start call current js method");
if (DoCallJsMethod(param) != ERR_OK) {
HILOGE("failed to call DoCallJsMethod.");
}
} while (false);
HILOGI("will notify current thread info");
std::unique_lock<std::mutex> lock(param->backupOperateMutex);
param->isReady.store(true);
param->backupOperateCondition.notify_all();
};
auto ret = napi_send_event(jsRuntime.GetNapiEnv(), task, napi_eprio_high);
if (ret != napi_status::napi_ok) {
HILOGE("failed to napi_send_event, ret:%{public}d.", ret);
return EINVAL;
}
HILOGI("Wait execute current js method");

View File

@ -49,15 +49,18 @@ BackupRestoreCallback::~BackupRestoreCallback()
}
work->data = static_cast<void *>(ctx_);
int ret = uv_queue_work(
loop, work.get(), [](uv_work_t *work) {},
[](uv_work_t *work, int status) {
LibN::NAsyncContextCallback *ctx = static_cast<LibN::NAsyncContextCallback *>(work->data);
delete ctx;
delete work;
});
if (ret) {
HILOGE("Failed to call uv_queue_work %{public}d", status);
auto task = [work {work.get()}]() {
if (work == nullptr) {
HILOGE("failed to get work.");
return;
}
LibN::NAsyncContextCallback *ctx = static_cast<LibN::NAsyncContextCallback *>(work->data);
delete ctx;
delete work;
};
auto ret = napi_send_event(env_, task, napi_eprio_high);
if (ret != napi_status::napi_ok) {
HILOGE("Failed to call napi_send_event, ret:%{public}d, status:%{public}d", ret, status);
return;
}
ptr.release();
@ -124,28 +127,29 @@ void BackupRestoreCallback::CallJsMethod(InputArgsParser argParser)
workArgs->argParser = argParser;
work->data = reinterpret_cast<void *>(workArgs.get());
HILOGI("Will execute current js method");
int ret = uv_queue_work(
loop, work.get(), [](uv_work_t *work) {
HILOGI("Enter, %{public}zu", (size_t)work);
},
[](uv_work_t *work, int status) {
HILOGI("AsyncWork Enter, %{public}zu", (size_t)work);
auto workArgs = reinterpret_cast<WorkArgs *>(work->data);
do {
if (workArgs == nullptr) {
HILOGE("failed to get workArgs.");
break;
}
DoCallJsMethod(workArgs->ptr->env_, workArgs->ptr->ctx_, workArgs->argParser);
} while (false);
HILOGI("will notify current thread info");
std::unique_lock<std::mutex> lock(workArgs->callbackMutex);
workArgs->isReady.store(true);
workArgs->callbackCondition.notify_all();
delete work;
});
if (ret != 0) {
HILOGE("failed to exec uv_queue_work.");
auto task = [work {work.get()}]() {
if (work == nullptr) {
HILOGE("failed to get work.");
return;
}
HILOGI("AsyncWork Enter, %{public}zu", (size_t)work);
auto workArgs = reinterpret_cast<WorkArgs *>(work->data);
do {
if (workArgs == nullptr) {
HILOGE("failed to get workArgs.");
break;
}
DoCallJsMethod(workArgs->ptr->env_, workArgs->ptr->ctx_, workArgs->argParser);
} while (false);
HILOGI("will notify current thread info");
std::unique_lock<std::mutex> lock(workArgs->callbackMutex);
workArgs->isReady.store(true);
workArgs->callbackCondition.notify_all();
delete work;
};
auto ret = napi_send_event(env_, task, napi_eprio_high);
if (ret != napi_status::napi_ok) {
HILOGE("failed to napi_send_event, ret:%{public}d.", ret);
work.reset();
return;
}

View File

@ -36,7 +36,7 @@ public:
= 0;
virtual napi_status napi_get_reference_value(napi_env, napi_ref, napi_value*) = 0;
virtual napi_status napi_get_named_property(napi_env, napi_value, const char*, napi_value*) = 0;
virtual int uv_queue_work(uv_loop_t*, uv_work_t*, uv_work_cb, uv_after_work_cb) = 0;
virtual napi_status napi_send_event(napi_env, const std::function<void()>, napi_event_priority) = 0;
virtual napi_status napi_get_value_int32(napi_env, napi_value, int32_t*) = 0;
virtual napi_status napi_get_value_int64(napi_env, napi_value, int64_t*) = 0;
virtual napi_status napi_create_string_utf8(napi_env, const char*, size_t, napi_value*) = 0;
@ -72,7 +72,7 @@ public:
napi_value*));
MOCK_METHOD3(napi_get_reference_value, napi_status(napi_env, napi_ref, napi_value*));
MOCK_METHOD4(napi_get_named_property, napi_status(napi_env, napi_value, const char*, napi_value*));
MOCK_METHOD4(uv_queue_work, int(uv_loop_t*, uv_work_t*, uv_work_cb, uv_after_work_cb));
MOCK_METHOD3(napi_send_event, napi_status(napi_env, const std::function<void()>, napi_event_priority));
MOCK_METHOD3(napi_get_value_int32, napi_status(napi_env, napi_value, int32_t*));
MOCK_METHOD3(napi_get_value_int64, napi_status(napi_env, napi_value, int64_t*));
MOCK_METHOD3(napi_create_int64, napi_status(napi_env, int64_t, napi_value*));

View File

@ -16,9 +16,9 @@
#include "napi_mock.h"
#include "uv.h"
int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb)
napi_status napi_send_event(napi_env env, const std::function<void()> cb, napi_event_priority priority)
{
return OHOS::FileManagement::Backup::Napi::napi->uv_queue_work(loop, req, work_cb, after_work_cb);
return OHOS::FileManagement::Backup::Napi::napi->napi_send_event(env, cb, priority);
}
napi_status napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop)

View File

@ -822,21 +822,11 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsMethod_0100, testing::ext::Tes
auto ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr);
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(Return(1));
ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr);
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(DoAll(WithArgs<1, 3>(Invoke(
[](uv_work_t* req, uv_after_work_cb after_work_cb) {
after_work_cb(req, 0);
})), Return(0)));
EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJsMethod("", *jsRuntime, extBackupJs->jsObj_.get(), nullptr, nullptr);
EXPECT_EQ(ret, ERR_OK);
EXPECT_EQ(ret, EINVAL);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ExtBackupJsTest-an exception occurred by CallJsMethod.";
@ -1075,28 +1065,20 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackupEx_0100, testing::ext:
EXPECT_EQ(ret, EINVAL);
extBackupJs->callbackInfoEx_ = std::make_shared<CallbackInfoEx>([](ErrCode, std::string){});
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJsOnBackupEx();
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _))
.WillOnce(DoAll(SetArgPointee<ARG_INDEX_FIRST>(true), Return(napi_ok)));
EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJsOnBackupEx();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1127,12 +1109,7 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackupEx_0200, testing::ext:
EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
int value = 0;
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, reinterpret_cast<napi_value>(&value));
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
auto ret = extBackupJs->CallJsOnBackupEx();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1161,27 +1138,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackup_0100, testing::ext::T
EXPECT_EQ(ret, EINVAL);
extBackupJs->callbackInfo_ = std::make_shared<CallbackInfo>([](ErrCode, std::string){});
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJsOnBackup();
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _))
.WillOnce(DoAll(SetArgPointee<ARG_INDEX_FIRST>(true), Return(napi_ok)));
EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJsOnBackup();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1212,12 +1181,7 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJsOnBackup_0200, testing::ext::T
EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
int value = 0;
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, reinterpret_cast<napi_value>(&value));
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
auto ret = extBackupJs->CallJsOnBackup();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1246,28 +1210,20 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestoreEx_0100, testing::ext::
EXPECT_EQ(ret, EINVAL);
extBackupJs->callbackInfoEx_ = std::make_shared<CallbackInfoEx>([](ErrCode, std::string){});
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJSRestoreEx();
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _))
.WillOnce(DoAll(SetArgPointee<ARG_INDEX_FIRST>(true), Return(napi_ok)));
EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJSRestoreEx();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1298,12 +1254,7 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestoreEx_0200, testing::ext::
EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
int value = 0;
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, reinterpret_cast<napi_value>(&value));
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
auto ret = extBackupJs->CallJSRestoreEx();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1332,27 +1283,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestore_0100, testing::ext::Te
EXPECT_EQ(ret, EINVAL);
extBackupJs->callbackInfo_ = std::make_shared<CallbackInfo>([](ErrCode, std::string){});
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJSRestore();
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _))
.WillOnce(DoAll(SetArgPointee<ARG_INDEX_FIRST>(true), Return(napi_ok)));
EXPECT_CALL(*napiMock, napi_get_and_clear_last_exception(_, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->CallJSRestore();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1383,12 +1326,7 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_CallJSRestore_0200, testing::ext::Te
EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
int value = 0;
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, reinterpret_cast<napi_value>(&value));
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
auto ret = extBackupJs->CallJSRestore();
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1418,14 +1356,10 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_GetBackupInfo_0100, testing::ext::Te
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1450,15 +1384,11 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_GetBackupInfo_0200, testing::ext::Te
try {
extBackupJs->jsObj_ = make_unique<NativeReferenceMock>();
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_ok))
.WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
auto ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
@ -1469,12 +1399,7 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_GetBackupInfo_0200, testing::ext::Te
EXPECT_CALL(*napiMock, napi_open_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_close_handle_scope(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
int value = 0;
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, reinterpret_cast<napi_value>(&value));
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->GetBackupInfo([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1503,15 +1428,11 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_OnProcess_0100, testing::ext::TestSi
auto ret = extBackupJs->OnProcess([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_invalid_arg));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->OnProcess([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
} catch (...) {
@ -1534,28 +1455,19 @@ HWTEST_F(ExtBackupJsTest, SUB_backup_ext_js_OnProcess_0200, testing::ext::TestSi
{
GTEST_LOG_(INFO) << "ExtBackupJsTest-begin SUB_backup_ext_js_OnProcess_0200";
try {
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_get_value_string_utf8(_, _, _, _, _)).WillOnce(Return(napi_ok))
.WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, nullptr);
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
auto ret = extBackupJs->OnProcess([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr));
EXPECT_CALL(*extBackupMock, GetNapiEnv()).WillOnce(Return(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(*napiMock, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, napi_is_exception_pending(_, _)).WillOnce(Return(napi_ok));
EXPECT_CALL(*napiMock, uv_queue_work(_, _, _, _)).WillOnce(WithArgs<1>(Invoke([](uv_work_t* work) {
int value = 0;
CallJsParam *param = reinterpret_cast<CallJsParam *>(work->data);
param->retParser(nullptr, reinterpret_cast<napi_value>(&value));
return -1;
})));
EXPECT_CALL(*napiMock, napi_send_event(_, _, _)).WillOnce(Return(napi_invalid_arg));
ret = extBackupJs->OnProcess([](ErrCode, std::string){});
EXPECT_EQ(ret, EINVAL);
} catch (...) {