From b9fd92363310b45f733cafd81a0b8c5e0a3aeaf8 Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Wed, 16 Feb 2022 17:37:43 +0800 Subject: [PATCH 1/3] add user file manager TDD test code Signed-off-by: zhaoshuai --- bundle.json | 3 + services/test/BUILD.gn | 266 +++++++++ .../test/client/file_manager_proxy_test.cpp | 156 ++++++ services/test/client/fms_manager_proxy_mock.h | 58 ++ .../test/fileoper/media_file_oper_test.cpp | 212 ++++++++ .../test/fileoper/media_file_oper_test_cb.cpp | 30 ++ .../test/fileoper/media_file_oper_test_cb.h | 33 ++ .../test/fileoper/media_file_utils_test.cpp | 508 ++++++++++++++++++ services/test/fileoper/oper_factory_test.cpp | 114 ++++ .../server/file_manager_service_stub_test.cpp | 331 ++++++++++++ .../test/server/file_manager_service_test.cpp | 112 ++++ 11 files changed, 1823 insertions(+) create mode 100644 services/test/BUILD.gn create mode 100644 services/test/client/file_manager_proxy_test.cpp create mode 100644 services/test/client/fms_manager_proxy_mock.h create mode 100644 services/test/fileoper/media_file_oper_test.cpp create mode 100644 services/test/fileoper/media_file_oper_test_cb.cpp create mode 100644 services/test/fileoper/media_file_oper_test_cb.h create mode 100644 services/test/fileoper/media_file_utils_test.cpp create mode 100644 services/test/fileoper/oper_factory_test.cpp create mode 100644 services/test/server/file_manager_service_stub_test.cpp create mode 100644 services/test/server/file_manager_service_test.cpp diff --git a/bundle.json b/bundle.json index 13fe41a7..95dbc537 100644 --- a/bundle.json +++ b/bundle.json @@ -36,6 +36,9 @@ "//foundation/filemanagement/user_file_service/services:fms", "//foundation/filemanagement/user_file_service/services/sa_profile:filemanager_service_sa_profile", "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" + ], + "test": [ + "//foundation/filemanagement/user_file_service/services/test:user_file_manager_test" ] } } diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn new file mode 100644 index 00000000..d663e3b1 --- /dev/null +++ b/services/test/BUILD.gn @@ -0,0 +1,266 @@ +# 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. + +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" + + sources = [ "client/file_manager_proxy_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", + "//third_party/googletest/googlemock/include/gmock", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock_main", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +ohos_unittest("media_file_oper_test") { + module_out_path = "storage_manager/user_file_manager" + + sources = [ + "fileoper/media_file_oper_test.cpp", + "fileoper/media_file_oper_test_cb.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", + "//utils/native/base:utils", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + ] + + 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 = "storage_manager/user_file_manager" + + sources = [ + "fileoper/media_file_oper_test_cb.cpp", + "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", + "//utils/native/base:utils", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + ] + + 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" + + sources = [ "fileoper/oper_factory_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/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +ohos_unittest("file_manager_service_stub_test") { + module_out_path = "storage_manager/user_file_manager" + + sources = [ + "fileoper/media_file_oper_test_cb.cpp", + "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", + "//utils/native/base:utils", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + ] + + 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" + + sources = [ "server/file_manager_service_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/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +group("user_file_manager_test") { + testonly = true + + deps = [ + ":file_manager_proxy_test", + ":media_file_oper_test", + ":media_file_utils_test", + ":oper_factory_test", + ":file_manager_service_stub_test", + ":file_manager_service_test", + ] +} diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp new file mode 100644 index 00000000..b51de72e --- /dev/null +++ b/services/test/client/file_manager_proxy_test.cpp @@ -0,0 +1,156 @@ +/* + * 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 "ifms_client.h" +#include "file_manager_proxy.h" +#include "fms_manager_proxy_mock.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class FileManagerProxyTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "FileManagerProxyTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp(); + void TearDown() {}; + std::shared_ptr proxy_ = nullptr; + sptr mock_ = nullptr; +}; + +void FileManagerProxyTest::SetUp() +{ + mock_ = new OHOS::FileManagerService::FmsManagerProxyMock(); + proxy_ = std::make_shared(mock_); +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetRoot_0000 + * @tc.name: File_Manager_Proxy_GetRoot_0000 + * @tc.desc: Test function of GetRoot interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetRoot_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetRoot_0000"; + CmdOptions option; + std::vector> fileRes; + int ret = proxy_->GetRoot(option, fileRes); + ASSERT_TRUE(ret == 0); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetRoot_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetFmsInstance_0000 + * @tc.name: File_Manager_Proxy_GetFmsInstance_0000 + * @tc.desc: Test function of GetFmsInstance interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetFmsInstance_0000"; + try { + IFmsClient* result = IFmsClient::GetFmsInstance(); + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerProxyTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetFmsInstance_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_Mkdir_0000 + * @tc.name: File_Manager_Proxy_Mkdir_0000 + * @tc.desc: Test function of Mkdir interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_Mkdir_0000"; + std::string name = "File_Manager_Proxy_Mkdir_0000"; + std::string path = "dataability:///album"; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->Mkdir(name, path); + EXPECT_TRUE(ret == ERR_NONE); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_ListFile_0000 + * @tc.name: File_Manager_Proxy_ListFile_0000 + * @tc.desc: Test function of ListFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_ListFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_ListFile_0000"; + std::string type = "file"; + std::string path = "dataability:///album"; + CmdOptions option; + std::vector> fileRes; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->ListFile(type, path, option, fileRes); + ASSERT_TRUE(ret == ERR_NONE); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_ListFile_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_CreateFile_0000 + * @tc.name: File_Manager_Proxy_CreateFile_0000 + * @tc.desc: Test function of CreateFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_CreateFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_CreateFile_0000"; + std::string path = "dataability:///album"; + std::string fileName = "FMS_File_ManagerProxy_Mkdir_0000"; + CmdOptions option; + std::string uri; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->CreateFile(path, fileName, option, uri); + ASSERT_TRUE(ret == ERR_NONE); + 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 new file mode 100644 index 00000000..ae04272a --- /dev/null +++ b/services/test/client/fms_manager_proxy_mock.h @@ -0,0 +1,58 @@ +/* + * 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 FMS_MANAGER_PROXY_MOCK_H +#define FMS_MANAGER_PROXY_MOCK_H +#include +#include "gmock/gmock.h" +#include "iremote_stub.h" +#include "iremote_proxy.h" +#include "ifms_client.h" + +namespace OHOS { +namespace FileManagerService { +class FmsManagerProxyMock : public IRemoteStub, public IFmsClient { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"FmsManagerProxyMock"); + FmsManagerProxyMock() {} + virtual ~FmsManagerProxyMock() {} + MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) + { + return ERR_NONE; + } + virtual int Mkdir(const std::string &name, const std::string &path) override + { + return ERR_NONE; + } + virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, + std::vector> &fileRes) override + { + return ERR_NONE; + } + virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) override + { + return ERR_NONE; + } + virtual int CreateFile(const std::string &path, const std::string &fileName, + const CmdOptions &option, std::string &uri) override + { + return ERR_NONE; + } +}; +} // namespace FileManagerService +} // namespace OHOS + +#endif // FMS_MANAGER_PROXY_MOCK_H \ No newline at end of file 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 00000000..2ba4f365 --- /dev/null +++ b/services/test/fileoper/media_file_oper_test.cpp @@ -0,0 +1,212 @@ +/* + * 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 "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; + int64_t id = 1; + int errCode = ERR_NONE; + Media::RdbHelper::DeleteRdbStore(Media::MEDIA_DATA_ABILITY_DB_NAME); + Media::RdbStoreConfig config(Media::MEDIA_DATA_ABILITY_DB_NAME); + MediaFileOperTestCb callback; + std::shared_ptr store = Media::RdbHelper::GetRdbStore(config, 1, callback, errCode); + NativeRdb::ValuesBucket values; + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/1.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("1.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + int ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/2.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("2.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/3.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("3.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + } + 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("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); + } + cout << reply.ReadInt32() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.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("Media_file_Oper_OperProcess_0003.txt"); + data.WriteString("dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/8"); + 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 00000000..e3ea4e93 --- /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 00000000..937ac758 --- /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 00000000..68ec3428 --- /dev/null +++ b/services/test/fileoper/media_file_utils_test.cpp @@ -0,0 +1,508 @@ +/* + * 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; + int64_t id = 1; + int errCode = ERR_NONE; + Media::RdbHelper::DeleteRdbStore(Media::MEDIA_DATA_ABILITY_DB_NAME); + Media::RdbStoreConfig config(Media::MEDIA_DATA_ABILITY_DB_NAME); + MediaFileOperTestCb callback; + std::shared_ptr store = Media::RdbHelper::GetRdbStore(config, 1, callback, errCode); + NativeRdb::ValuesBucket values; + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/1.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("1.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + int ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/2.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("2.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + } + 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_PushFileInfo_0000 + * @tc.name: Media_File_Utils_PushFileInfo_0000 + * @tc.desc: Test function of PushFileInfo interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_PushFileInfo_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_PushFileInfo_0000"; + try { + shared_ptr result; + MessageParcel reply; + int result1; + result1 = MediaFileUtils::PushFileInfo(result, reply); + EXPECT_EQ(result1, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_PushFileInfo_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_PopFileInfo_0000 + * @tc.name: Media_File_Utils_PopFileInfo_0000 + * @tc.desc: Test function of PopFileInfo interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_PopFileInfo_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_PopFileInfo_0000"; + try { + FileInfo file; + MessageParcel reply; + int result; + result = MediaFileUtils::PopFileInfo(file, reply); + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_PopFileInfo_0000"; +} + +/** + * @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; + MessageParcel reply; + int result1; + result1 = MediaFileUtils::GetFileInfoFromResult(result, reply, 1); + EXPECT_EQ(result1, 0); + } 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; + MessageParcel reply; + int result1; + result1 = MediaFileUtils::GetFileInfoFromResult(result, reply, -1); + 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/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp new file mode 100644 index 00000000..2dcc3a1c --- /dev/null +++ b/services/test/fileoper/oper_factory_test.cpp @@ -0,0 +1,114 @@ +/* + * 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 "file_manager_service_def.h" +#include "file_manager_service_stub.h" +#include "media_data_ability_const.h" +#include "abs_shared_result_set.h" +#include "media_file_utils.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class OperFactoryTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "OperFactoryTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0000 + * @tc.name: oper_factory_GetFileOper_0000 + * @tc.desc: Test function of GetFileOper interface for SUCCESS which INTERNAL_STORAGE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0000"; + try { + OperFactory *oper = new OperFactory(); + std::unique_ptr result; + if (oper != nullptr) { + result = oper->GetFileOper(Equipment::INTERNAL_STORAGE); + } + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0000"; +} + +/** + * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0001 + * @tc.name: oper_factory_GetFileOper_0001 + * @tc.desc: Test function of GetFileOper for SUCCESS which EXTERNAL_STORAGE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0001"; + try { + OperFactory *oper = new OperFactory(); + std::unique_ptr result; + if (oper != nullptr) { + result = oper->GetFileOper(Equipment::EXTERNAL_STORAGE); + } + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0001"; +} + +/** + * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0002 + * @tc.name: oper_factory_GetFileOper_0002 + * @tc.desc: Test function of GetFileOper interface for SUCCESS wich default. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0002"; + try { + OperFactory *oper = new OperFactory(); + std::unique_ptr result; + if (oper != nullptr) { + result = oper->GetFileOper(3); + } + EXPECT_EQ(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0002"; +} +} // 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 00000000..3a521223 --- /dev/null +++ b/services/test/server/file_manager_service_stub_test.cpp @@ -0,0 +1,331 @@ +/* + * 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 << "FMS code test" << endl; + int64_t id = 1; + int errCode = ERR_NONE; + Media::RdbHelper::DeleteRdbStore(Media::MEDIA_DATA_ABILITY_DB_NAME); + Media::RdbStoreConfig config(Media::MEDIA_DATA_ABILITY_DB_NAME); + MediaFileOperTestCb callback; + std::shared_ptr store = Media::RdbHelper::GetRdbStore(config, 1, callback, errCode); + NativeRdb::ValuesBucket values; + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/1.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("1.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + int ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/2.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("2.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/3.pdf")); + values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); + values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("3.pdf")); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); + values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); + ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); + values.Clear(); + } + 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("file"); + 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); + } + cout << reply.ReadInt32() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadString() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + cout << reply.ReadInt32() << endl; + 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 diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp new file mode 100644 index 00000000..7cb42744 --- /dev/null +++ b/services/test/server/file_manager_service_test.cpp @@ -0,0 +1,112 @@ +/* + * 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 "ifms_client.h" +#include "file_info.h" +#include "media_file_oper.h" +#include "file_manager_service_stub.h" +#include "media_data_ability_const.h" +#include "file_manager_service_def.h" +#include "abs_shared_result_set.h" +#include "file_manager_service.h" +#include "media_file_utils.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class FileManagerServiceTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "FileManagerServiceTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_file_Manager_Service_OnDump_0000 + * @tc.name: file_Manager_Service_OnDump_0000 + * @tc.desc: Test function of OnDump interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnDump_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnDump_0000"; + try { + OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); + if (service != nullptr) { + service->OnDump(); + } + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnDump_0000"; +} + +/** + * @tc.number: SUB_STORAGE_file_Manager_Service_OnStart_0000 + * @tc.name: file_Manager_Service_OnStart_0000 + * @tc.desc: Test function of OnStart interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnStart_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStart_0000"; + try { + OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); + if (service != nullptr) { + service->OnStart(); + } + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStart_0000"; +} + +/** + * @tc.number: SUB_STORAGE_file_Manager_Service_OnStop_0000 + * @tc.name: file_Manager_Service_OnStop_0000 + * @tc.desc: Test function of OnStop interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceTest, Ffile_Manager_Service_OnStop_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStop_0000"; + try { + OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); + if (service != nullptr) { + service->OnStop(); + } + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStop_0000"; +} +} // namespace \ No newline at end of file -- Gitee From 80e056b818abaa4e403e37aefc28a7eca23907f6 Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Wed, 16 Feb 2022 18:18:58 +0800 Subject: [PATCH 2/3] add user_file_manager TDD test code Signed-off-by: zhaoshuai --- services/test/BUILD.gn | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index d663e3b1..1701c6c4 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -50,7 +50,7 @@ ohos_unittest("file_manager_proxy_test") { ohos_unittest("media_file_oper_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ + sources = [ "fileoper/media_file_oper_test.cpp", "fileoper/media_file_oper_test_cb.cpp", ] @@ -79,8 +79,8 @@ ohos_unittest("media_file_oper_test") { "$FMS_BASE_DIR:fms_server", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//utils/native/base:utils", ] external_deps = [ @@ -96,7 +96,7 @@ ohos_unittest("media_file_oper_test") { ohos_unittest("media_file_utils_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ + sources = [ "fileoper/media_file_oper_test_cb.cpp", "fileoper/media_file_utils_test.cpp", ] @@ -125,8 +125,8 @@ ohos_unittest("media_file_utils_test") { "$FMS_BASE_DIR:fms_server", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//utils/native/base:utils", ] external_deps = [ @@ -176,7 +176,7 @@ ohos_unittest("oper_factory_test") { ohos_unittest("file_manager_service_stub_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ + sources = [ "fileoper/media_file_oper_test_cb.cpp", "server/file_manager_service_stub_test.cpp", ] @@ -205,8 +205,8 @@ ohos_unittest("file_manager_service_stub_test") { "$FMS_BASE_DIR:fms_server", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//utils/native/base:utils", ] external_deps = [ @@ -257,10 +257,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", - ":file_manager_service_stub_test", - ":file_manager_service_test", ] } -- Gitee From 1e255e1ff6f7641cb0718d9db8ac6709a7ef7d2d Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Thu, 17 Feb 2022 16:42:32 +0800 Subject: [PATCH 3/3] remove Media library related TDD tests code Signed-off-by: zhaoshuai --- services/test/BUILD.gn | 141 ----- .../test/fileoper/media_file_oper_test.cpp | 212 -------- .../test/fileoper/media_file_oper_test_cb.cpp | 30 -- .../test/fileoper/media_file_oper_test_cb.h | 33 -- .../test/fileoper/media_file_utils_test.cpp | 508 ------------------ .../server/file_manager_service_stub_test.cpp | 331 ------------ 6 files changed, 1255 deletions(-) delete mode 100644 services/test/fileoper/media_file_oper_test.cpp delete mode 100644 services/test/fileoper/media_file_oper_test_cb.cpp delete mode 100644 services/test/fileoper/media_file_oper_test_cb.h delete mode 100644 services/test/fileoper/media_file_utils_test.cpp delete mode 100644 services/test/server/file_manager_service_stub_test.cpp diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index 1701c6c4..97862562 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -47,98 +47,6 @@ ohos_unittest("file_manager_proxy_test") { ] } -ohos_unittest("media_file_oper_test") { - module_out_path = "storage_manager/user_file_manager" - - sources = [ - "fileoper/media_file_oper_test.cpp", - "fileoper/media_file_oper_test_cb.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 = "storage_manager/user_file_manager" - - sources = [ - "fileoper/media_file_oper_test_cb.cpp", - "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" @@ -173,52 +81,6 @@ ohos_unittest("oper_factory_test") { ] } -ohos_unittest("file_manager_service_stub_test") { - module_out_path = "storage_manager/user_file_manager" - - sources = [ - "fileoper/media_file_oper_test_cb.cpp", - "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" @@ -257,10 +119,7 @@ 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/fileoper/media_file_oper_test.cpp b/services/test/fileoper/media_file_oper_test.cpp deleted file mode 100644 index 2ba4f365..00000000 --- a/services/test/fileoper/media_file_oper_test.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * 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 "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; - int64_t id = 1; - int errCode = ERR_NONE; - Media::RdbHelper::DeleteRdbStore(Media::MEDIA_DATA_ABILITY_DB_NAME); - Media::RdbStoreConfig config(Media::MEDIA_DATA_ABILITY_DB_NAME); - MediaFileOperTestCb callback; - std::shared_ptr store = Media::RdbHelper::GetRdbStore(config, 1, callback, errCode); - NativeRdb::ValuesBucket values; - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/1.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("1.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - int ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/2.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("2.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/3.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("3.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - } - 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("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); - } - cout << reply.ReadInt32() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.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("Media_file_Oper_OperProcess_0003.txt"); - data.WriteString("dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/8"); - 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 deleted file mode 100644 index e3ea4e93..00000000 --- a/services/test/fileoper/media_file_oper_test_cb.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 deleted file mode 100644 index 937ac758..00000000 --- a/services/test/fileoper/media_file_oper_test_cb.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 deleted file mode 100644 index 68ec3428..00000000 --- a/services/test/fileoper/media_file_utils_test.cpp +++ /dev/null @@ -1,508 +0,0 @@ -/* - * 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; - int64_t id = 1; - int errCode = ERR_NONE; - Media::RdbHelper::DeleteRdbStore(Media::MEDIA_DATA_ABILITY_DB_NAME); - Media::RdbStoreConfig config(Media::MEDIA_DATA_ABILITY_DB_NAME); - MediaFileOperTestCb callback; - std::shared_ptr store = Media::RdbHelper::GetRdbStore(config, 1, callback, errCode); - NativeRdb::ValuesBucket values; - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/1.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("1.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - int ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/2.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("2.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - } - 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_PushFileInfo_0000 - * @tc.name: Media_File_Utils_PushFileInfo_0000 - * @tc.desc: Test function of PushFileInfo interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(MediaFileUtilsTest, Media_File_Utils_PushFileInfo_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_PushFileInfo_0000"; - try { - shared_ptr result; - MessageParcel reply; - int result1; - result1 = MediaFileUtils::PushFileInfo(result, reply); - EXPECT_EQ(result1, 0); - } catch (...) { - GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_PushFileInfo_0000"; -} - -/** - * @tc.number: SUB_STORAGE_Media_File_Utils_PopFileInfo_0000 - * @tc.name: Media_File_Utils_PopFileInfo_0000 - * @tc.desc: Test function of PopFileInfo interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(MediaFileUtilsTest, Media_File_Utils_PopFileInfo_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_PopFileInfo_0000"; - try { - FileInfo file; - MessageParcel reply; - int result; - result = MediaFileUtils::PopFileInfo(file, reply); - EXPECT_EQ(result, 0); - } catch (...) { - GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "MediaFileUtilsTest-end Media_File_Utils_PopFileInfo_0000"; -} - -/** - * @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; - MessageParcel reply; - int result1; - result1 = MediaFileUtils::GetFileInfoFromResult(result, reply, 1); - EXPECT_EQ(result1, 0); - } 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; - MessageParcel reply; - int result1; - result1 = MediaFileUtils::GetFileInfoFromResult(result, reply, -1); - 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 deleted file mode 100644 index 3a521223..00000000 --- a/services/test/server/file_manager_service_stub_test.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* - * 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 << "FMS code test" << endl; - int64_t id = 1; - int errCode = ERR_NONE; - Media::RdbHelper::DeleteRdbStore(Media::MEDIA_DATA_ABILITY_DB_NAME); - Media::RdbStoreConfig config(Media::MEDIA_DATA_ABILITY_DB_NAME); - MediaFileOperTestCb callback; - std::shared_ptr store = Media::RdbHelper::GetRdbStore(config, 1, callback, errCode); - NativeRdb::ValuesBucket values; - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/1.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("1.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - int ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/2.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("2.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, std::string("/data/media/3.pdf")); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, Media::MEDIA_TYPE_FILE); - values.PutString(Media::MEDIA_DATA_DB_NAME, std::string("3.pdf")); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "/data/media"); - values.PutString(Media::MEDIA_DATA_DB_URI, "dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file"); - ret = store->Insert(id, Media::MEDIALIBRARY_TABLE, values); - values.Clear(); - } - 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("file"); - 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); - } - cout << reply.ReadInt32() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadString() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - cout << reply.ReadInt32() << endl; - 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 -- Gitee