From 4432e9eb59f7a57dcda787aba8132f6763ecafda Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Fri, 21 Jan 2022 11:06:31 +0800 Subject: [PATCH 1/4] 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 From 687a37d1861e59bd92c9b2b26c071db9aab2c2a4 Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Fri, 21 Jan 2022 11:13:47 +0800 Subject: [PATCH 2/4] add user_file_manager TDD test code Signed-off-by: zhaoshuai --- services/test/client/file_manager_proxy_test.cpp | 3 +-- services/test/fileoper/media_file_utils_test.cpp | 1 + services/test/fileoper/oper_factory_test.cpp | 1 + services/test/server/file_manager_service_test.cpp | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp index 8c7d46c4..f745c39b 100644 --- a/services/test/client/file_manager_proxy_test.cpp +++ b/services/test/client/file_manager_proxy_test.cpp @@ -1,4 +1,4 @@ - /* +/* * 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. @@ -21,7 +21,6 @@ #include "file_manager_proxy.h" #include "fms_manager_proxy_mock.h" - namespace { using namespace std; using namespace OHOS; diff --git a/services/test/fileoper/media_file_utils_test.cpp b/services/test/fileoper/media_file_utils_test.cpp index a9b6e911..54b797d5 100644 --- a/services/test/fileoper/media_file_utils_test.cpp +++ b/services/test/fileoper/media_file_utils_test.cpp @@ -227,6 +227,7 @@ HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoQuery_0000, testing::ext::TestSi } 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 diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp index 4036b73b..934a03e8 100644 --- a/services/test/fileoper/oper_factory_test.cpp +++ b/services/test/fileoper/oper_factory_test.cpp @@ -87,6 +87,7 @@ HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize. } GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0001"; } + /** * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0002 * @tc.name: oper_factory_GetFileOper_0002 diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp index 5e4b07a4..fa3cfa20 100644 --- a/services/test/server/file_manager_service_test.cpp +++ b/services/test/server/file_manager_service_test.cpp @@ -40,6 +40,7 @@ public: void SetUp(){}; void TearDown() {}; }; + /** * @tc.number: SUB_STORAGE_file_Manager_Service_OnDump_0000 * @tc.name: file_Manager_Service_OnDump_0000 -- Gitee From 9241ab012330dfa02c5771687026f411bd55a71e Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Fri, 21 Jan 2022 14:46:31 +0800 Subject: [PATCH 3/4] add user_file_manager TDD test code Signed-off-by: zhaoshuai --- services/test/client/fms_manager_proxy_mock.h | 2 +- .../test/fileoper/media_file_oper_test.cpp | 11 +++++------ .../test/fileoper/media_file_utils_test.cpp | 7 +++---- services/test/fileoper/oper_factory_test.cpp | 11 +++++------ .../server/file_manager_service_stub_test.cpp | 19 +++++++++---------- .../test/server/file_manager_service_test.cpp | 12 ++++++------ 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/services/test/client/fms_manager_proxy_mock.h b/services/test/client/fms_manager_proxy_mock.h index b45851e9..15fa87ae 100644 --- a/services/test/client/fms_manager_proxy_mock.h +++ b/services/test/client/fms_manager_proxy_mock.h @@ -23,7 +23,7 @@ namespace OHOS { namespace FileManagerService { -class FmsManagerProxyMock : public IRemoteStub ,public IFmsClient{ +class FmsManagerProxyMock : public IRemoteStub, public IFmsClient { public: DECLARE_INTERFACE_DESCRIPTOR(u"FmsManagerProxyMock"); FmsManagerProxyMock() {} diff --git a/services/test/fileoper/media_file_oper_test.cpp b/services/test/fileoper/media_file_oper_test.cpp index 4f20ce5d..eac8348b 100644 --- a/services/test/fileoper/media_file_oper_test.cpp +++ b/services/test/fileoper/media_file_oper_test.cpp @@ -32,8 +32,7 @@ public: cout << "MediaFileOperTest code test" << endl; } static void TearDownTestCase() {}; - - void SetUp(){}; + void SetUp() {}; void TearDown() {}; }; @@ -56,7 +55,7 @@ HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0000, testing::ext::Test data.WriteString("dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/8"); MessageParcel reply; int result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->OperProcess(Operation::MAKE_DIR, data, reply); } EXPECT_EQ(result, 0); @@ -87,7 +86,7 @@ HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0001, testing::ext::Test data.WriteInt32(2); MessageParcel reply; int result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->OperProcess(Operation::LIST_FILE, data, reply); } EXPECT_EQ(result, 0); @@ -116,7 +115,7 @@ HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0002, testing::ext::Test data.WriteString("dataability:///album"); MessageParcel reply; int result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->OperProcess(Operation::CREATE_FILE, data, reply); } EXPECT_EQ(result, 0); @@ -145,7 +144,7 @@ HWTEST_F(MediaFileOperTest, Media_file_Oper_OperProcess_0003, testing::ext::Test data.WriteString("dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/8"); MessageParcel reply; int result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->OperProcess(Operation::GET_ROOT, data, reply); } EXPECT_EQ(result, 0); diff --git a/services/test/fileoper/media_file_utils_test.cpp b/services/test/fileoper/media_file_utils_test.cpp index 54b797d5..9dd460c9 100644 --- a/services/test/fileoper/media_file_utils_test.cpp +++ b/services/test/fileoper/media_file_utils_test.cpp @@ -32,9 +32,8 @@ public: cout << "MediaFileUtilsTest code test" << endl; } static void TearDownTestCase() {}; - void SetUp(){}; + void SetUp() {}; void TearDown() {}; - }; /** @@ -77,7 +76,7 @@ HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0001, testing::ext::Tes { GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0001"; try { - std::shared_ptr result = std::make_shared(); + std::shared_ptr result = std::make_shared(); int result1; std::string type = "file"; std::string path = "dataability:///album/##"; @@ -185,7 +184,7 @@ HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoListFile_0005, testing::ext::Tes { GTEST_LOG_(INFO) << "MediaFileUtilsTest-begin Media_File_Utils_DoListFile_0005"; try { - std::shared_ptr result = std::make_shared(); + std::shared_ptr result = std::make_shared(); int result1; std::string type = "file"; std::string path = "dataability:///album/%d%s"; diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp index 934a03e8..714f1067 100644 --- a/services/test/fileoper/oper_factory_test.cpp +++ b/services/test/fileoper/oper_factory_test.cpp @@ -33,9 +33,8 @@ public: cout << "OperFactoryTest code test" << endl; } static void TearDownTestCase() {}; - void SetUp(){}; - void TearDown() {}; - + void SetUp() {}; + void TearDown() {}; }; /** @@ -53,7 +52,7 @@ HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0000, testing::ext::TestSize. try { OperFactory *oper = new OperFactory(); std::unique_ptr result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->GetFileOper(Equipment::INTERNAL_STORAGE); } EXPECT_NE(result, nullptr); @@ -78,7 +77,7 @@ HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize. try { OperFactory *oper = new OperFactory(); std::unique_ptr result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->GetFileOper(Equipment::EXTERNAL_STORAGE); } EXPECT_EQ(result, nullptr); @@ -103,7 +102,7 @@ HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0002, testing::ext::TestSize. try { OperFactory *oper = new OperFactory(); std::unique_ptr result; - if (oper != nullptr){ + if (oper != nullptr) { result = oper->GetFileOper(3); } EXPECT_EQ(result, nullptr); diff --git a/services/test/server/file_manager_service_stub_test.cpp b/services/test/server/file_manager_service_stub_test.cpp index 6ed05e9c..c11ecc12 100644 --- a/services/test/server/file_manager_service_stub_test.cpp +++ b/services/test/server/file_manager_service_stub_test.cpp @@ -31,8 +31,7 @@ public: cout << "FMS code test" << endl; } static void TearDownTestCase() {}; - - void SetUp(){}; + void SetUp() {}; void TearDown() {}; }; @@ -55,7 +54,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0000, data.WriteString("dataability:///album"); MessageParcel reply; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OperProcess(Operation::MAKE_DIR, data, reply); } EXPECT_EQ(result, 0); @@ -86,7 +85,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0001, data.WriteInt32(2); MessageParcel reply; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OperProcess(Operation::LIST_FILE, data, reply); } EXPECT_EQ(result, 0); @@ -115,7 +114,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0002, data.WriteString("dataability:///album"); MessageParcel reply; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OperProcess(Operation::CREATE_FILE, data, reply); } EXPECT_EQ(result, 0); @@ -144,7 +143,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OperProcess_0003, data.WriteString("dataability:///album"); MessageParcel reply; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OperProcess(Operation::GET_ROOT, data, reply); } EXPECT_EQ(result, 0); @@ -174,7 +173,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0 MessageParcel reply; MessageOption option; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OnRemoteRequest(Operation::MAKE_DIR, data, reply, option); } EXPECT_EQ(result, 0); @@ -204,7 +203,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0 MessageParcel reply; MessageOption option; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OnRemoteRequest(Operation::LIST_FILE, data, reply, option); } EXPECT_EQ(result, 0); @@ -234,7 +233,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0 MessageParcel reply; MessageOption option; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OnRemoteRequest(Operation::CREATE_FILE, data, reply, option); } EXPECT_EQ(result, 0); @@ -264,7 +263,7 @@ HWTEST_F(FileManagerServiceStubTest, File_Manager_service_stub_OnRemoteRequest_0 MessageParcel reply; MessageOption option; int result; - if (stub != nullptr){ + if (stub != nullptr) { result = stub->OnRemoteRequest(Operation::GET_ROOT, data, reply, option); } EXPECT_EQ(result, 0); diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp index fa3cfa20..7cb42744 100644 --- a/services/test/server/file_manager_service_test.cpp +++ b/services/test/server/file_manager_service_test.cpp @@ -37,7 +37,7 @@ public: cout << "FileManagerServiceTest code test" << endl; } static void TearDownTestCase() {}; - void SetUp(){}; + void SetUp() {}; void TearDown() {}; }; @@ -55,7 +55,7 @@ HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnDump_0000, testing::ext: GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnDump_0000"; try { OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr){ + if (service != nullptr) { service->OnDump(); } } catch (...) { @@ -78,8 +78,8 @@ HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnStart_0000, testing::ext 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(); + if (service != nullptr) { + service->OnStart(); } } catch (...) { GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; @@ -101,9 +101,9 @@ HWTEST_F(FileManagerServiceTest, Ffile_Manager_Service_OnStop_0000, testing::ext GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStop_0000"; try { OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr){ + if (service != nullptr) { service->OnStop(); - } + } } catch (...) { GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; } -- Gitee From ebb27ad979708c9c650c5378fd9068e10c4b4774 Mon Sep 17 00:00:00 2001 From: zhaoshuai Date: Fri, 21 Jan 2022 15:16:05 +0800 Subject: [PATCH 4/4] add user_file_manager TDD test code Signed-off-by: zhaoshuai --- services/test/BUILD.gn | 81 +++++++------------ .../test/fileoper/media_file_utils_test.cpp | 12 +-- services/test/fileoper/oper_factory_test.cpp | 2 +- 3 files changed, 35 insertions(+), 60 deletions(-) diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index 8ea4c85a..7368ee0c 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -11,15 +11,12 @@ # 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" - ] + sources = [ "client/file_manager_proxy_test.cpp" ] include_dirs = [ "//third_party/json/include", @@ -31,15 +28,13 @@ ohos_unittest("file_manager_proxy_test") { "//third_party/googletest/googlemock/include/gmock", ] - configs = [ - "//build/config/compiler:exceptions", - ] + 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", + "//utils/native/base:utils", ] external_deps = [ @@ -53,9 +48,7 @@ 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" - ] + sources = [ "fileoper/media_file_oper_test.cpp" ] include_dirs = [ "//third_party/json/include", @@ -68,14 +61,12 @@ ohos_unittest("media_file_oper_test") { "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", ] - configs = [ - "//build/config/compiler:exceptions", - ] + configs = [ "//build/config/compiler:exceptions" ] deps = [ "$FMS_BASE_DIR:fms_server", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils" + "//utils/native/base:utils", ] external_deps = [ @@ -89,9 +80,7 @@ ohos_unittest("media_file_oper_test") { ohos_unittest("media_file_utils_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ - "fileoper/media_file_utils_test.cpp" - ] + sources = [ "fileoper/media_file_utils_test.cpp" ] include_dirs = [ "//third_party/json/include", @@ -104,16 +93,14 @@ ohos_unittest("media_file_utils_test") { "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", ] - configs = [ - "//build/config/compiler:exceptions", - ] + 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", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", ] external_deps = [ @@ -127,9 +114,7 @@ ohos_unittest("media_file_utils_test") { ohos_unittest("oper_factory_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ - "fileoper/oper_factory_test.cpp" - ] + sources = [ "fileoper/oper_factory_test.cpp" ] include_dirs = [ "//third_party/json/include", @@ -142,16 +127,14 @@ ohos_unittest("oper_factory_test") { "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", ] - configs = [ - "//build/config/compiler:exceptions", - ] + 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", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", ] external_deps = [ @@ -165,9 +148,7 @@ ohos_unittest("oper_factory_test") { ohos_unittest("file_manager_service_stub_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ - "server/file_manager_service_stub_test.cpp" - ] + sources = [ "server/file_manager_service_stub_test.cpp" ] include_dirs = [ "//third_party/json/include", @@ -180,14 +161,12 @@ ohos_unittest("file_manager_service_stub_test") { "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", ] - configs = [ - "//build/config/compiler:exceptions", - ] + configs = [ "//build/config/compiler:exceptions" ] deps = [ "$FMS_BASE_DIR:fms_server", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils" + "//utils/native/base:utils", ] external_deps = [ @@ -201,9 +180,7 @@ ohos_unittest("file_manager_service_stub_test") { ohos_unittest("file_manager_service_test") { module_out_path = "storage_manager/user_file_manager" - sources = [ - "server/file_manager_service_test.cpp" - ] + sources = [ "server/file_manager_service_test.cpp" ] include_dirs = [ "//third_party/json/include", @@ -216,15 +193,13 @@ ohos_unittest("file_manager_service_test") { "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", ] - configs = [ - "//build/config/compiler:exceptions", - ] - deps = [ + 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", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", ] external_deps = [ @@ -238,12 +213,12 @@ ohos_unittest("file_manager_service_test") { group("user_file_manager_test") { testonly = true - deps = [ + 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 + ":media_file_oper_test", + ":media_file_utils_test", + ":oper_factory_test", + ] +} diff --git a/services/test/fileoper/media_file_utils_test.cpp b/services/test/fileoper/media_file_utils_test.cpp index 9dd460c9..bbfbad2b 100644 --- a/services/test/fileoper/media_file_utils_test.cpp +++ b/services/test/fileoper/media_file_utils_test.cpp @@ -257,7 +257,7 @@ HWTEST_F(MediaFileUtilsTest, Media_File_Utils_DoQuery_0001, testing::ext::TestSi album.emplace_back(path); } result->GoToNextRow(); - } + } result = MediaFileUtils::DoQuery(selection, selectionArgs); EXPECT_NE(result, nullptr); } catch (...) { @@ -383,11 +383,11 @@ HWTEST_F(MediaFileUtilsTest, Media_File_Utils_PushFileInfo_0000, testing::ext::T { 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); + shared_ptr result; + MessageParcel reply; + int result1; + result1 = MediaFileUtils::PushFileInfo(result, reply); + EXPECT_EQ(result1, 0); } catch (...) { GTEST_LOG_(INFO) << "MediaFileUtilsTest-an exception occurred."; } diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp index 714f1067..951f1510 100644 --- a/services/test/fileoper/oper_factory_test.cpp +++ b/services/test/fileoper/oper_factory_test.cpp @@ -34,7 +34,7 @@ public: } static void TearDownTestCase() {}; void SetUp() {}; - void TearDown() {}; + void TearDown() {}; }; /** -- Gitee