From d014237fc6f53154189f0d714bca43fa35849f28 Mon Sep 17 00:00:00 2001 From: zhaoyongjin1 Date: Tue, 5 Mar 2024 15:18:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Etdd=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaoyongjin1 --- .../js_file_access_ext_ability_test.cpp | 551 ++++++++++++++++++ 1 file changed, 551 insertions(+) diff --git a/test/unittest/js_file_access_ext_ability_test.cpp b/test/unittest/js_file_access_ext_ability_test.cpp index b6cd7080..3193b2c0 100644 --- a/test/unittest/js_file_access_ext_ability_test.cpp +++ b/test/unittest/js_file_access_ext_ability_test.cpp @@ -1666,4 +1666,555 @@ HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_Rename_0003, tes } GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_Rename_0003"; } + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_CopyFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_CopyFile_0000"; + try { + Uri sourceUri(""); + Uri destUri(""); + string fileName(""); + Uri newFileUri(""); + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->CopyFile(sourceUri, destUri, fileName, newFileUri); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_CopyFile_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_CopyFile_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_CopyFile_0001"; + try { + napi_value rslt; + Uri sourceUri(""); + Uri destUri(""); + string fileName(""); + Uri newFileUri(""); + ability->jsObj_ = make_shared(); + + // 模拟获取srcNativeUri为空 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)).WillOnce(Return(napi_ok)) + .WillOnce(Return(napi_ok)).WillOnce(Return(napi_ok)); + auto result = ability->CopyFile(sourceUri, destUri, fileName, newFileUri); + EXPECT_EQ(result, E_GETRESULT); + + // 模拟获取dstNativeUri为空 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))) + .WillOnce(Return(napi_ok)).WillOnce(Return(napi_ok)); + result = ability->CopyFile(sourceUri, destUri, fileName, newFileUri); + EXPECT_EQ(result, E_GETRESULT); + + // 模拟获取fileName为空 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))) + .WillOnce(Return(napi_ok)); + result = ability->CopyFile(sourceUri, destUri, fileName, newFileUri); + EXPECT_EQ(result, E_GETRESULT); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_CopyFile_0001"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_CopyFile_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_CopyFile_0002"; + try { + napi_value rslt; + Uri sourceUri(""); + Uri destUri(""); + string fileName(""); + Uri newFileUri(""); + ability->jsObj_ = make_shared(); + + // 模拟获取value->code失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))) + .WillOnce(Return(napi_ok)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_value_string_utf8(_, _, _, _, _)) + .WillOnce(Return(napi_ok)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, napi_get_value_int32(_, _, _)).WillOnce(DoAll(SetArgPointee<2>(E_IPCS), Return(napi_ok))); + auto result = ability->CopyFile(sourceUri, destUri, fileName, newFileUri); + EXPECT_EQ(result, E_IPCS); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_CopyFile_0002"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_ListFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_ListFile_0000"; + try { + FileInfo fileInfo{}; + FileFilter filter{}; + int64_t offset = 0; + int64_t maxCount = 0; + vector fileInfoVec; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_ListFile_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_ListFile_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_ListFile_0001"; + try { + napi_value rslt; + FileInfo fileInfo{}; + FileFilter filter{}; + int64_t offset = 0; + int64_t maxCount = 0; + vector fileInfoVec; + + // 模拟valu为null + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + auto result = ability->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_ListFile_0001"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_ListFile_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_ListFile_0002"; + try { + napi_value rslt; + FileInfo fileInfo{}; + FileFilter filter{}; + int64_t offset = 0; + int64_t maxCount = 0; + vector fileInfoVec; + + // 模拟value->code失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_value_int32(_, _, _)).WillOnce(DoAll(SetArgPointee<2>(E_IPCS), Return(napi_ok))); + auto result = ability->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_ListFile_0002"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_ScanFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_ScanFile_0000"; + try { + FileInfo fileInfo{}; + FileFilter filter{}; + int64_t offset = 0; + int64_t maxCount = 0; + vector fileInfoVec; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_ListFile_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_ScanFile_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_ScanFile_0001"; + try { + napi_value rslt; + FileInfo fileInfo{}; + FileFilter filter{}; + int64_t offset = 0; + int64_t maxCount = 0; + vector fileInfoVec; + + // 模拟valu为null + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + auto result = ability->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_ListFile_0001"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_ScanFile_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_ScanFile_0002"; + try { + napi_value rslt; + FileInfo fileInfo{}; + FileFilter filter{}; + int64_t offset = 0; + int64_t maxCount = 0; + vector fileInfoVec; + + // 模拟value->code失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_value_int32(_, _, _)).WillOnce(DoAll(SetArgPointee<2>(E_IPCS), Return(napi_ok))); + auto result = ability->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_ListFile_0002"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_GetRoots_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetRoots_0000"; + try { + vector rootInfoVec; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->GetRoots(rootInfoVec); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetRoots_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_Access_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_Access_0000"; + try { + Uri uri(""); + bool isExist = false; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->Access(uri, isExist); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_Access_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_Access_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_Access_0002"; + try { + napi_value rslt; + Uri uri(""); + bool isExist = false; + + // 模拟value->code失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_value_int32(_, _, _)).WillOnce(DoAll(SetArgPointee<2>(E_IPCS), Return(napi_ok))); + auto result = ability->Access(uri, isExist); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_Access_0002"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_Query_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_Query_0000"; + try { + Uri uri(""); + vector columns; + vector results; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->Query(uri, columns, results); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_Query_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_GetFileInfoFromUri_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetFileInfoFromUri_0000"; + try { + Uri selectFile(""); + FileInfo fileInfo{}; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->GetFileInfoFromUri(selectFile, fileInfo); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetFileInfoFromUri_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_GetFileInfoFromUri_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetFileInfoFromUri_0001"; + try { + Uri selectFile(""); + FileInfo fileInfo{}; + + // 模拟获取nativeUri为空 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)).WillOnce(Return(napi_ok)); + auto result = ability->GetFileInfoFromUri(selectFile, fileInfo); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetFileInfoFromUri_0001"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_GetFileInfoFromUri_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetFileInfoFromUri_0003"; + try { + napi_value rslt; + Uri selectFile(""); + FileInfo fileInfo{}; + + // 模拟获取napi_get_named_property失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_value_int32(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(E_IPCS), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_ok)); + auto result = ability->GetFileInfoFromUri(selectFile, fileInfo); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetFileInfoFromUri_0003"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_RelativePath_1, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetFileInfoFromRelativePath_0001"; + try { + string selectFileRealtivePath(""); + FileInfo fileInfo{}; + + // 模拟获取nativeUri为空 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)).WillOnce(Return(napi_ok)); + auto result = ability->GetFileInfoFromRelativePath(selectFileRealtivePath, fileInfo); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetFileInfoFromRelativePath_0001"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_RelativePath_2, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetFileInfoFromRelativePath_0002"; + try { + napi_value rslt; + string selectFileRealtivePath(""); + FileInfo fileInfo{}; + + // 模拟获取napi_get_named_property失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_reference_value(_, _, _)) + .WillOnce(DoAll(SetArgPointee<2>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_call_function(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgPointee<5>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_escape_handle(_, _, _, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(reinterpret_cast(&rslt)), Return(napi_ok))); + EXPECT_CALL(*insMoc, napi_get_named_property(_, _, _, _)).WillOnce(Return(napi_ok)); + auto result = ability->GetFileInfoFromRelativePath(selectFileRealtivePath, fileInfo); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetFileInfoFromRelativePath_0002"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_RelativePath_0, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_GetFileInfoFromRelativePath_0000"; + try { + string selectFileRealtivePath(""); + FileInfo fileInfo{}; + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->GetFileInfoFromRelativePath(selectFileRealtivePath, fileInfo); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_GetFileInfoFromRelativePath_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_StartWatcher_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_StartWatcher_0000"; + try { + Uri uri(""); + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->StartWatcher(uri); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_StartWatcher_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_StartWatcher_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_StartWatcher_0001"; + try { + Uri uri(""); + // 模拟获取nativeUri为空 + + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)).WillOnce(Return(napi_ok)).WillOnce(Return(napi_ok)); + auto result = ability->StartWatcher(uri); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_StartWatcher_0001"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_StopWatcher_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_StopWatcher_0000"; + try { + Uri uri(""); + + // 模拟调用CallJsMethod失败 + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_invalid_arg)); + auto result = ability->StopWatcher(uri); + EXPECT_EQ(result, EINVAL); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_StopWatcher_0000"; +} + +HWTEST_F(JsFileAccessExtAbilityTest, js_file_access_ext_ability_StopWatcher_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-begin js_file_access_ext_ability_StopWatcher_0001"; + try { + Uri uri(""); + // 模拟获取nativeUri为空 + + EXPECT_CALL(*insMoc, napi_get_uv_event_loop(_, _)).WillOnce(Return(napi_ok)); + EXPECT_CALL(*insMoc, uv_queue_work(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMoc, napi_create_string_utf8(_, _, _, _)) + .WillOnce(Return(napi_ok)); + auto result = ability->StopWatcher(uri); + EXPECT_EQ(result, ERR_OK); + } catch (...) { + GTEST_LOG_(ERROR) << "JsFileAccessExtAbilityTest occurs an exception."; + } + GTEST_LOG_(INFO) << "JsFileAccessExtAbilityTest-end js_file_access_ext_ability_StopWatcher_0001"; +} + } \ No newline at end of file -- Gitee