diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index 978625629eeb3104d8df1d8a325d933d45038eb0..cf54806b75fb01add97dd8e45e04cc032def0aa6 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -14,7 +14,7 @@ import("//build/test.gni") FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" ohos_unittest("file_manager_proxy_test") { - module_out_path = "storage_manager/user_file_manager" + module_out_path = "filemanagement/user_file_service" sources = [ "client/file_manager_proxy_test.cpp" ] @@ -47,8 +47,98 @@ ohos_unittest("file_manager_proxy_test") { ] } +ohos_unittest("media_file_oper_test") { + module_out_path = "filemanagement/user_file_service" + + sources = [ + "fileoper/media_file_oper_test.cpp", + ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//foundation/appexecfwk/standard/kits/appkit/native/app/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/test/unittest/mediathumbnail_test/include", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "native_appdatamgr:native_dataability", + "native_appdatamgr:native_rdb", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +ohos_unittest("media_file_utils_test") { + module_out_path = "filemanagement/user_file_service" + + sources = [ + "fileoper/media_file_utils_test.cpp", + ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//foundation/appexecfwk/standard/kits/appkit/native/app/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/test/unittest/mediathumbnail_test/include", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "native_appdatamgr:native_dataability", + "native_appdatamgr:native_rdb", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + ohos_unittest("oper_factory_test") { - module_out_path = "storage_manager/user_file_manager" + module_out_path = "filemanagement/user_file_service" sources = [ "fileoper/oper_factory_test.cpp" ] @@ -81,8 +171,53 @@ ohos_unittest("oper_factory_test") { ] } +ohos_unittest("file_manager_service_stub_test") { + module_out_path = "filemanagement/user_file_service" + + sources = [ + "server/file_manager_service_stub_test.cpp", + ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//foundation/appexecfwk/standard/kits/appkit/native/app/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/test/unittest/mediathumbnail_test/include", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "native_appdatamgr:native_dataability", + "native_appdatamgr:native_rdb", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + ohos_unittest("file_manager_service_test") { - module_out_path = "storage_manager/user_file_manager" + module_out_path = "filemanagement/user_file_service" sources = [ "server/file_manager_service_test.cpp" ] @@ -119,7 +254,10 @@ group("user_file_manager_test") { deps = [ ":file_manager_proxy_test", + ":file_manager_service_stub_test", ":file_manager_service_test", + ":media_file_oper_test", + ":media_file_utils_test", ":oper_factory_test", ] } diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp index 5b6e3fda7a5dfcb8a03205693dfb9b205a894c24..a19e33f68417e9c69871df5f0fd032b6837a43b7 100644 --- a/services/test/client/file_manager_proxy_test.cpp +++ b/services/test/client/file_manager_proxy_test.cpp @@ -57,8 +57,11 @@ HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetRoot_0000, testing::ext::Te { GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetRoot_0000"; CmdOptions option; + DevInfo dev("local", ""); + option.SetDevInfo(dev); std::vector> fileRes; - int ret = proxy_->GetRoot(option, fileRes); + IFmsClient* result = IFmsClient::GetFmsInstance(); + int ret = result->GetRoot(option, fileRes); ASSERT_TRUE(ret == 0); GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetRoot_0000"; } @@ -102,7 +105,7 @@ HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::Test .Times(1) .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); int ret = proxy_->Mkdir(name, path); - EXPECT_TRUE(ret == ERR_NONE); + EXPECT_EQ(ret, 1); GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000"; } @@ -126,7 +129,7 @@ HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_ListFile_0000, testing::ext::T .Times(1) .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); int ret = proxy_->ListFile(type, path, option, fileRes); - ASSERT_TRUE(ret == ERR_NONE); + EXPECT_EQ(ret, 0); GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_ListFile_0000"; } @@ -150,7 +153,7 @@ HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_CreateFile_0000, testing::ext: .Times(1) .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); int ret = proxy_->CreateFile(path, fileName, option, uri); - ASSERT_TRUE(ret == ERR_NONE); + EXPECT_EQ(ret, 0); GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_CreateFile_0000"; } } // namespace \ No newline at end of file diff --git a/services/test/client/fms_manager_proxy_mock.h b/services/test/client/fms_manager_proxy_mock.h index 4b1aed9611ad42a50a7605efbee8ce5496402755..811807ed6f0d52ebdc692ea00dbe1545fb69ab72 100644 --- a/services/test/client/fms_manager_proxy_mock.h +++ b/services/test/client/fms_manager_proxy_mock.h @@ -20,6 +20,7 @@ #include "iremote_stub.h" #include "iremote_proxy.h" #include "ifms_client.h" +#include "cmd_response.h" namespace OHOS { namespace FileManagerService { @@ -31,6 +32,8 @@ public: MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + sptr cmdResponse = new CmdResponse(); + reply.WriteParcelable(cmdResponse); return ERR_NONE; } virtual int Mkdir(const std::string &name, const std::string &path) override diff --git a/services/test/fileoper/media_file_oper_test.cpp b/services/test/fileoper/media_file_oper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..212938d8f72c4eec74c6442843f48800df5e679e --- /dev/null +++ b/services/test/fileoper/media_file_oper_test.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "media_data_ability_const.h" +#include "medialibrary_data_ability.h" + +#include "cmd_response.h" +#include "file_manager_service_def.h" +#include "file_info.h" +#include "media_file_oper.h" +#include "media_file_oper_test_cb.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class MediaFileOperTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "MediaFileOperTest code test" << endl; + // system("touch /storage/media/1.pdf"); + // system("touch /storage/media/2.pdf"); + // system("touch /storage/media/3.pdf"); + // system("touch /storage/media/100/local/files/1.pdf"); + // system("mkdir /storage/media/100/local/files/camera"); + // system("cp /storage/media/100/local/files/01.mp4 /storage/media/100/local/files/camera/01.mp4"); + // system("killall com.ohos.medialibrary.MediaScannerAbilityA"); + // system("aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA"); + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_Media_file_Oper_OperProcess_0000 + * @tc.name: media_file_Oper_OperProcess_0000 + * @tc.desc: Test function of OperProcess interface for SUCCESS which MAKE_DIR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileOperTest-begin Media_file_Oper_OperProcess_0000"; + try { + MediaFileOper *oper = new MediaFileOper(); + MessageParcel data; + data.WriteString("Media_file_Oper_OperProcess_0000"); + data.WriteString("dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/8"); + MessageParcel reply; + int result; + if (oper != nullptr) { + result = oper->OperProcess(FileManagerService::Operation::MAKE_DIR, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileOperTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileOperTest-end Media_file_Oper_OperProcess_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Media_file_Oper_OperProcess_0001 + * @tc.name: Media_file_Oper_OperProcess_0001 + * @tc.desc: Test function of OperProcess interface for SUCCESS which LIST_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileOperTest-begin Media_file_Oper_OperProcess_0001"; + try { + MediaFileOper *oper = new MediaFileOper(); + MessageParcel data; + data.WriteString(""); + data.WriteString(""); + data.WriteString("file"); + data.WriteString("dataability:///album"); + data.WriteInt32(0); + data.WriteInt32(2); + MessageParcel reply; + int result; + if (oper != nullptr) { + result = oper->OperProcess(FileManagerService::Operation::LIST_FILE, data, reply); + } + sptr cmdResponse = reply.ReadParcelable(); + Parcel parcel; + cmdResponse->Marshalling(parcel); + cout << parcel.ReadInt32() << endl; + cout << parcel.ReadString() << endl; + cout << parcel.ReadInt32() << endl; + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileOperTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileOperTest-end Media_file_Oper_OperProcess_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Media_file_Oper_OperProcess_0002 + * @tc.name: Media_file_Oper_OperProcess_0002 + * @tc.desc: Test function of OperProcess interface for SUCCESS which CREATE_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileOperTest-begin Media_file_Oper_OperProcess_0002"; + try { + MediaFileOper *oper = new MediaFileOper(); + MessageParcel data; + data.WriteString("Media_file_Oper_OperProcess_0002"); + data.WriteString("dataability:///album"); + MessageParcel reply; + int result; + if (oper != nullptr) { + result = oper->OperProcess(FileManagerService::Operation::CREATE_FILE, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileOperTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileOperTest-end Media_file_Oper_OperProcess_0002"; +} + +/** + * @tc.number: SUB_STORAGE_Media_file_Oper_OperProcess_0003 + * @tc.name: Media_file_Oper_OperProcess_0003 + * @tc.desc: Test function of OperProcess interface for Logic ERROR which not exist options. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileOperTest-begin Media_file_Oper_OperProcess_0003"; + try { + MediaFileOper *oper = new MediaFileOper(); + MessageParcel data; + data.WriteString("c.txt"); + data.WriteString("dataability:///album"); + MessageParcel reply; + int result; + if (oper != nullptr) { + result = oper->OperProcess(FileManagerService::Operation::GET_ROOT, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileOperTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileOperTest-end Media_file_Oper_OperProcess_0003"; +} +} // namespace \ No newline at end of file diff --git a/services/test/fileoper/media_file_oper_test_cb.cpp b/services/test/fileoper/media_file_oper_test_cb.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e3ea4e935e147969d1a6fcd0ebb1e9b1ae473fbd --- /dev/null +++ b/services/test/fileoper/media_file_oper_test_cb.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "media_file_oper_test_cb.h" + +namespace OHOS { +namespace FileManagerService { +int MediaFileOperTestCb::OnCreate(Media::RdbStore &store) +{ + return store.ExecuteSql(Media::CREATE_MEDIA_TABLE); +} + +int MediaFileOperTestCb::OnUpgrade(Media::RdbStore &store, int oldVersion, int newVersion) +{ + return 0; +} +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/test/fileoper/media_file_oper_test_cb.h b/services/test/fileoper/media_file_oper_test_cb.h new file mode 100644 index 0000000000000000000000000000000000000000..937ac758d94f7dd2e711796cf5feb70b81958fa5 --- /dev/null +++ b/services/test/fileoper/media_file_oper_test_cb.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MEDIA_FILE_OPER_TEST_CB_H +#define MEDIA_FILE_OPER_TEST_CB_H + +#include "gtest/gtest.h" +#include "medialibrary_thumbnail.h" +#include "media_data_ability_const.h" +#include "medialibrary_data_ability.h" + +namespace OHOS { +namespace FileManagerService { +class MediaFileOperTestCb : public OHOS::NativeRdb::RdbOpenCallback { +public: + int OnCreate(Media::RdbStore &rdbStore) override; + int OnUpgrade(Media::RdbStore &rdbStore, int oldVersion, int newVersion) override; +}; +} // namespace FileManagerService +} // namespace OHOS +#endif // MEDIA_FILE_OPER_TEST_CB_H \ No newline at end of file diff --git a/services/test/fileoper/media_file_utils_test.cpp b/services/test/fileoper/media_file_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9fbd8b353a23ffde41825d0ca6e1bfd1bb1cbd9 --- /dev/null +++ b/services/test/fileoper/media_file_utils_test.cpp @@ -0,0 +1,437 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "media_data_ability_const.h" +#include "medialibrary_data_ability.h" +#include "media_file_oper_test_cb.h" +#include "file_manager_service_def.h" +#include "abs_shared_result_set.h" + +#include "media_file_utils.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class MediaFileUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "MediaFileUtilsTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0000 + * @tc.name: Media_File_Utils_DoListFile_0000 + * @tc.desc: Test function of DoListFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0000"; + try { + shared_ptr result; + std::string type = "file"; + std::string path = "dataability:///album"; + int offset = 0; + int count = 2; + int result1; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + result->GoToFirstRow(); + string value; + int columnIndex = 0; + result->GetColumnIndex("uri", columnIndex); + result->GetString(columnIndex, value); + cout << value << endl; + result->GetColumnIndex("display_name", columnIndex); + result->GetString(columnIndex, value); + cout << value << endl; + result->GoToNextRow(); + result->GetColumnIndex("uri", columnIndex); + result->GetString(columnIndex, value); + cout << value << endl; + result->GetColumnIndex("display_name", columnIndex); + result->GetString(columnIndex, value); + cout << value << endl; + EXPECT_EQ(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoListFile_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0001 + * @tc.name: Media_File_Utils_DoListFile_0001 + * @tc.desc: Test function of DoListFile interface for args ERROR which special characters path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0001"; + try { + std::shared_ptr result = std::make_shared(); + int result1; + std::string type = "file"; + std::string path = "dataability:///album/##"; + int offset = 0; + int count = 2; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + EXPECT_NE(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoListFile_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0002 + * @tc.name: Media_File_Utils_DoListFile_0002 + * @tc.desc: Test function of DoListFile interface for args ERROR which offest. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0002"; + try { + std::shared_ptr result = std::make_shared(); + int result1; + std::string type = "file"; + std::string path = "dataability:///album"; + int offset = -1; + int count = 2; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + EXPECT_EQ(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoListFile_0002"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0003 + * @tc.name: Media_File_Utils_DoListFile_0003 + * @tc.desc: Test function of DoListFile interface for args ERROR which count. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0003"; + try { + std::shared_ptr result = std::make_shared(); + int result1; + std::string type = "file"; + std::string path = "dataability:///album"; + int offset = 0; + int count = -1; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + EXPECT_EQ(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoListFile_0003"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0004 + * @tc.name: Media_File_Utils_DoListFile_0004 + * @tc.desc: Test function of DoListFile interface for args ERROR which type. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0004"; + try { + std::shared_ptr result = std::make_shared(); + int result1; + std::string type = "test"; + std::string path = "dataability:///album"; + int offset = 0; + int count = 2; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + EXPECT_NE(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoListFile_0004"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0005 + * @tc.name: Media_File_Utils_DoListFile_0005 + * @tc.desc: Test function of DoListFile interface for args ERROR which translate characters path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0005"; + try { + std::shared_ptr result = std::make_shared(); + int result1; + std::string type = "file"; + std::string path = "dataability:///album/%d%s"; + int offset = 0; + int count = 2; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + EXPECT_NE(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoListFile_0005"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoQuery_0000 + * @tc.name: Media_File_Utils_DoQuery_0000 + * @tc.desc: Test function of DoQuery interface for SUCCESS whcih type is file. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoQuery_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoQuery_0000"; + try { + std::string selection; + vector selectionArgs; + selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; + selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; + selectionArgs = { + "dataability:///album", "1", "8" + }; + std::shared_ptr result=nullptr; + result = MediaFileUtils::DoQuery(selection, selectionArgs); + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoQuery_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoQuery_0001 + * @tc.name: Media_File_Utils_DoQuery_0001 + * @tc.desc: Test function of DoQuery interface for SUCCESS which type is not file. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoQuery_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoQuery_0001"; + try { + string selection = Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; + vector selectionArgs = {"3"}; + shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); + vector album; + int count = 0; + result->GetRowCount(count); + result->GoToFirstRow(); + int32_t columnIndex; + int ret = result->GetColumnIndex(Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); + for (int i = 0; i < count; i++) { + string path; + ret = result->GetString(columnIndex, path); + auto it = find(album.begin(), album.end(), path); + if (it == album.end()) { + album.emplace_back(path); + } + result->GoToNextRow(); + } + result = MediaFileUtils::DoQuery(selection, selectionArgs); + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoQuery_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoInsert_0000 + * @tc.name: Media_File_Utils_DoInsert_0000 + * @tc.desc: Test function of DoInsert interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoInsert_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoInsert_0000"; + try { + int result; + std::string uri; + std::string name = "Media_File_Utils_DoInsert_0000.txt"; + std::string path = "dataability:///album"; + std::string type = "file"; + result = MediaFileUtils::DoInsert(name, path, type, uri); + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoInsert_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoInsert_0001 + * @tc.name: Media_File_Utils_DoInsert_0001 + * @tc.desc: Test function of DoInsert interface for args ERROR which translate characters path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoInsert_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoInsert_0001"; + try { + int result; + std::string uri; + std::string name = "Media_File_Utils_DoInsert_0001.txt"; + std::string path = "dataability:///album/%d%s"; + std::string type = "file"; + result = MediaFileUtils::DoInsert(name, path, type, uri); + EXPECT_NE(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoInsert_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoInsert_0002 + * @tc.name: Media_File_Utils_DoInsert_0002 + * @tc.desc: Test function of DoInsert interface for args ERROR which Special characters path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoInsert_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoInsert_0002"; + try { + std::string uri; + std::string name = "Media_File_Utils_DoInsert_0002.txt"; + std::string path = "dataability:///album/##"; + std::string type = "file"; + int result; + result = MediaFileUtils::DoInsert(name, path, type, uri); + EXPECT_NE(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoInsert_0002"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoInsert_0003 + * @tc.name: Media_File_Utils_DoInsert_0003 + * @tc.desc: Test function of DoInsert interface for args ERROR which type. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoInsert_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoInsert_0003"; + try { + std::string uri; + std::string name = "Media_File_Utils_DoInsert_0003.txt"; + std::string path = "dataability:///album"; + std::string type = "test"; + int result; + result = MediaFileUtils::DoInsert(name, path, type, uri); + EXPECT_NE(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_DoInsert_0003"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_GetFileInfoFromResult_0000 + * @tc.name: Media_File_Utils_GetFileInfoFromResult_0000 + * @tc.desc: Test function of GetFileInfoFromResult interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_GetFileInfoFromResult_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_GetFileInfoFromResult_0000"; + try { + shared_ptr result; + std::vector> fileList; + EXPECT_TRUE(MediaFileUtils::GetFileInfoFromResult(result, fileList)); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_GetFileInfoFromResult_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_GetFileInfoFromResult_0001 + * @tc.name: Media_File_Utils_GetFileInfoFromResult_0001 + * @tc.desc: Test function of GetFileInfoFromResult interface for args ERROR which res. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_GetFileInfoFromResult_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_GetFileInfoFromResult_0001"; + try { + shared_ptr result; + std::vector> fileList; + int result1; + result1 = MediaFileUtils::GetFileInfoFromResult(result, fileList); + EXPECT_EQ(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_GetFileInfoFromResult_0001"; +} +} // namespace \ No newline at end of file diff --git a/services/test/server/file_manager_service_stub_test.cpp b/services/test/server/file_manager_service_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..146a08935f0f918c2c1189fee2b8f750d65fd015 --- /dev/null +++ b/services/test/server/file_manager_service_stub_test.cpp @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "media_data_ability_const.h" +#include "medialibrary_data_ability.h" + +#include "../fileoper/media_file_oper_test_cb.h" +#include "file_manager_service_def.h" +#include "file_manager_service_stub.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class FileManagerServiceStubTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "FileManagerServiceStubTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OperProcess_0000 + * @tc.name: File_Manager_service_stub_OperProcess_0000 + * @tc.desc: Test function of OperProcess interface for SUCCESS which MAKE_DIR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OperProcess_0000"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OperProcess_0000"); + data.WriteString("dataability:///album"); + MessageParcel reply; + int result; + if (stub != nullptr) { + result = stub->OperProcess(FileManagerService::Operation::MAKE_DIR, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OperProcess_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OperProcess_0001 + * @tc.name: File_Manager_service_stub_OperProcess_0001 + * @tc.desc: Test function of OperProcess interface for SUCCESS which LIST_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OperProcess_0001"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("image"); + data.WriteString("dataability:///album"); + data.WriteInt32(0); + data.WriteInt32(2); + MessageParcel reply; + int result; + if (stub != nullptr) { + result = stub->OperProcess(FileManagerService::Operation::LIST_FILE, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OperProcess_0001"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OperProcess_0002 + * @tc.name: File_Manager_service_stub_OperProcess_0002 + * @tc.desc: Test function of OperProcess interface for SUCCESS which CREATE_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OperProcess_0002"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OperProcess_0002.txt"); + data.WriteString("dataability:///album"); + MessageParcel reply; + int result; + if (stub != nullptr) { + result = stub->OperProcess(FileManagerService::Operation::CREATE_FILE, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OperProcess_0002"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OperProcess_0003 + * @tc.name: File_Manager_service_stub_OperProcess_0003 + * @tc.desc: Test function of OperProcess interface for Logic ERROR which not exist options. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OperProcess_0003"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OperProcess_0003"); + data.WriteString("dataability:///album"); + MessageParcel reply; + int result; + if (stub != nullptr) { + result = stub->OperProcess(FileManagerService::Operation::GET_ROOT, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OperProcess_0003"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OnRemoteRequest_0000 + * @tc.name: File_Manager_service_stub_OnRemoteRequest_0000 + * @tc.desc: Test function of OnRemoteRequest interface for SUCCESS which MAKE_DIR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OnRemoteRequest_0000"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OnRemoteRequest_0000"); + data.WriteString("dataability:///album"); + MessageParcel reply; + MessageOption option; + int result; + if (stub != nullptr) { + result = stub->OnRemoteRequest(FileManagerService::Operation::MAKE_DIR, data, reply, option); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OnRemoteRequest_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OnRemoteRequest_0001 + * @tc.name: File_Manager_service_stub_OnRemoteRequest_0001 + * @tc.desc: Test function of OnRemoteRequest interface for SUCCESS which LIST_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OnRemoteRequest_0001"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("file"); + data.WriteString("dataability:///album"); + MessageParcel reply; + MessageOption option; + int result; + if (stub != nullptr) { + result = stub->OnRemoteRequest(FileManagerService::Operation::LIST_FILE, data, reply, option); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OnRemoteRequest_0001"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OnRemoteRequest_0002 + * @tc.name: File_Manager_service_stub_OnRemoteRequest_0002 + * @tc.desc: Test function of OnRemoteRequest interface for SUCCESS which CREATE_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OnRemoteRequest_0002"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OnRemoteRequest_0002.txt"); + data.WriteString("dataability:///album"); + MessageParcel reply; + MessageOption option; + int result; + if (stub != nullptr) { + result = stub->OnRemoteRequest(FileManagerService::Operation::CREATE_FILE, data, reply, option); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OnRemoteRequest_0002"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OnRemoteRequest_0003 + * @tc.name: File_Manager_service_stub_OnRemoteRequest_0003 + * @tc.desc: Test function of OnRemoteRequest interface for Logic ERROR which not exist options. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OnRemoteRequest_0003"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OnRemoteRequest_0003"); + data.WriteString("dataability:///album"); + MessageParcel reply; + MessageOption option; + int result; + if (stub != nullptr) { + result = stub->OnRemoteRequest(FileManagerService::Operation::GET_ROOT, data, reply, option); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OnRemoteRequest_0003"; +} +} // namespace \ No newline at end of file