From 4432e9eb59f7a57dcda787aba8132f6763ecafda Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Fri, 21 Jan 2022 11:06:31 +0800 Subject: [PATCH] add user_file_manager TDD test code Signed-off-by: zhaoshuai --- ohos.build | 10 +- services/test/BUILD.gn | 249 ++++++++++ .../test/client/file_manager_proxy_test.cpp | 157 ++++++ services/test/client/fms_manager_proxy_mock.h | 57 +++ .../test/fileoper/media_file_oper_test.cpp | 157 ++++++ .../test/fileoper/media_file_utils_test.cpp | 468 ++++++++++++++++++ services/test/fileoper/oper_factory_test.cpp | 114 +++++ .../server/file_manager_service_stub_test.cpp | 276 +++++++++++ .../test/server/file_manager_service_test.cpp | 111 +++++ 9 files changed, 1598 insertions(+), 1 deletion(-) 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_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/ohos.build b/ohos.build index 0fb5d5ff..0440f0ac 100644 --- a/ohos.build +++ b/ohos.build @@ -6,7 +6,15 @@ "//foundation/filemanagement/user_file_service/services:fms", "//foundation/filemanagement/user_file_service/sa_profile:filemanager_service_sa_profile", "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" + ], + "test_list": [ + "//foundation/filemanagement/user_file_service/services/test:file_manager_proxy_test", + "//foundation/filemanagement/user_file_service/services/test:media_file_oper_test", + "//foundation/filemanagement/user_file_service/services/test:file_manager_service_stub_test", + "//foundation/filemanagement/user_file_service/services/test:oper_factory_test", + "//foundation/filemanagement/user_file_service/services/test:media_file_utils_test", + "//foundation/filemanagement/user_file_service/services/test:file_manager_service_test" ] } } -} +} \ No newline at end of file diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn new file mode 100644 index 00000000..8ea4c85a --- /dev/null +++ b/services/test/BUILD.gn @@ -0,0 +1,249 @@ +# 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", + ] + + configs = [ + "//build/config/compiler:exceptions", + ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + "//third_party/googletest:gmock_main", + ] + + 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" + ] + + 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/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("media_file_utils_test") { + module_out_path = "storage_manager/user_file_manager" + + sources = [ + "fileoper/media_file_utils_test.cpp" + ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//foundation/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/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "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/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + ] + + 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 = [ + "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/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/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_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/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + ] + + 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", + ":file_manager_service_stub_test", + ":oper_factory_test", + ":file_manager_service_test", + ":media_file_utils_test" + ] +} \ No newline at end of file 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..8c7d46c4 --- /dev/null +++ b/services/test/client/file_manager_proxy_test.cpp @@ -0,0 +1,157 @@ + /* + * 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"; + std::string devName = "File_Manager_Proxy_GetRoot_0000"; + std::vector fileRes; + int ret = proxy_->GetRoot(devName, 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"; + int off = 0; + int count = 2; + 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, off, count, 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 name = "FMS_File_ManagerProxy_Mkdir_0000"; + std::string path = "dataability:///album"; + std::string uri; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->CreateFile(name, path, 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..b45851e9 --- /dev/null +++ b/services/test/client/fms_manager_proxy_mock.h @@ -0,0 +1,57 @@ +/* + * 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, + int off, int count, std::vector &fileRes) override + { + return ERR_NONE; + } + virtual int GetRoot(const std::string &devName, std::vector &fileRes) const + { + return ERR_NONE; + } + virtual int CreateFile(const std::string &name, const std::string &path, 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..4f20ce5d --- /dev/null +++ b/services/test/fileoper/media_file_oper_test.cpp @@ -0,0 +1,157 @@ +/* + * 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_info.h" +#include "media_file_oper.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; + } + 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(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(Operation::LIST_FILE, data, reply); + } + 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(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(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_utils_test.cpp b/services/test/fileoper/media_file_utils_test.cpp new file mode 100644 index 00000000..a9b6e911 --- /dev/null +++ b/services/test/fileoper/media_file_utils_test.cpp @@ -0,0 +1,468 @@ +/* + * 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 "file_manager_service_def.h" +#include "abs_shared_result_set.h" +#include "media_file_utils.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class MediaFileUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "MediaFileUtilsTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp(){}; + void TearDown() {}; + +}; + +/** + * @tc.number: SUB_STORAGE_Media_File_Utils_DoListFile_0000 + * @tc.name: Media_File_Utils_DoListFile_0000 + * @tc.desc: Test function of DoListFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0000"; + try { + shared_ptr result; + std::string type = "file"; + std::string path = "dataability:///album"; + int offset = 0; + int count = 2; + int result1; + result1 = MediaFileUtils::DoListFile(type, path, offset, count, result); + 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..4036b73b --- /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_EQ(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..6ed05e9c --- /dev/null +++ b/services/test/server/file_manager_service_stub_test.cpp @@ -0,0 +1,276 @@ +/* + * 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" + +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; + } + 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(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(Operation::LIST_FILE, data, reply); + } + EXPECT_EQ(result, 0); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-end File_Manager_service_stub_OperProcess_0001"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_service_stub_OperProcess_0002 + * @tc.name: File_Manager_service_stub_OperProcess_0002 + * @tc.desc: Test function of OperProcess interface for SUCCESS which CREATE_FILE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceStubTest-begin File_Manager_service_stub_OperProcess_0002"; + try { + FileManagerServiceStub *stub = new FileManagerServiceStub(); + MessageParcel data; + data.WriteString("File_Manager_service_stub_OperProcess_0002.txt"); + data.WriteString("dataability:///album"); + MessageParcel reply; + int result; + if (stub != nullptr){ + result = stub->OperProcess(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(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(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(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(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(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..5e4b07a4 --- /dev/null +++ b/services/test/server/file_manager_service_test.cpp @@ -0,0 +1,111 @@ +/* + * 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