diff --git a/bundle.json b/bundle.json index 13fe41a79b126bf7d5553657d85f841393a5af99..95dbc537d0a3d2fcb80f4ae861bdfb655108e715 100644 --- a/bundle.json +++ b/bundle.json @@ -36,6 +36,9 @@ "//foundation/filemanagement/user_file_service/services:fms", "//foundation/filemanagement/user_file_service/services/sa_profile:filemanager_service_sa_profile", "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" + ], + "test": [ + "//foundation/filemanagement/user_file_service/services/test:user_file_manager_test" ] } } diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..978625629eeb3104d8df1d8a325d933d45038eb0 --- /dev/null +++ b/services/test/BUILD.gn @@ -0,0 +1,125 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" +ohos_unittest("file_manager_proxy_test") { + module_out_path = "storage_manager/user_file_manager" + + sources = [ "client/file_manager_proxy_test.cpp" ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//third_party/googletest/googlemock/include/gmock", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock_main", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +ohos_unittest("oper_factory_test") { + module_out_path = "storage_manager/user_file_manager" + + sources = [ "fileoper/oper_factory_test.cpp" ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +ohos_unittest("file_manager_service_test") { + module_out_path = "storage_manager/user_file_manager" + + sources = [ "server/file_manager_service_test.cpp" ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "//foundation/multimedia/medialibrary_standard/interfaces/innerkits/native/include", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb/include", + ] + + configs = [ "//build/config/compiler:exceptions" ] + deps = [ + "$FMS_BASE_DIR:fms_server", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_appdatafwk:native_appdatafwk", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +group("user_file_manager_test") { + testonly = true + + deps = [ + ":file_manager_proxy_test", + ":file_manager_service_test", + ":oper_factory_test", + ] +} diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b51de72e2a9db592d6e870a9905e192c9c3a097b --- /dev/null +++ b/services/test/client/file_manager_proxy_test.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "ifms_client.h" +#include "file_manager_proxy.h" +#include "fms_manager_proxy_mock.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class FileManagerProxyTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "FileManagerProxyTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp(); + void TearDown() {}; + std::shared_ptr proxy_ = nullptr; + sptr mock_ = nullptr; +}; + +void FileManagerProxyTest::SetUp() +{ + mock_ = new OHOS::FileManagerService::FmsManagerProxyMock(); + proxy_ = std::make_shared(mock_); +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetRoot_0000 + * @tc.name: File_Manager_Proxy_GetRoot_0000 + * @tc.desc: Test function of GetRoot interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetRoot_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetRoot_0000"; + CmdOptions option; + std::vector> fileRes; + int ret = proxy_->GetRoot(option, fileRes); + ASSERT_TRUE(ret == 0); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetRoot_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetFmsInstance_0000 + * @tc.name: File_Manager_Proxy_GetFmsInstance_0000 + * @tc.desc: Test function of GetFmsInstance interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetFmsInstance_0000"; + try { + IFmsClient* result = IFmsClient::GetFmsInstance(); + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerProxyTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetFmsInstance_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_Mkdir_0000 + * @tc.name: File_Manager_Proxy_Mkdir_0000 + * @tc.desc: Test function of Mkdir interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_Mkdir_0000"; + std::string name = "File_Manager_Proxy_Mkdir_0000"; + std::string path = "dataability:///album"; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->Mkdir(name, path); + EXPECT_TRUE(ret == ERR_NONE); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_ListFile_0000 + * @tc.name: File_Manager_Proxy_ListFile_0000 + * @tc.desc: Test function of ListFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_ListFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_ListFile_0000"; + std::string type = "file"; + std::string path = "dataability:///album"; + CmdOptions option; + std::vector> fileRes; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->ListFile(type, path, option, fileRes); + ASSERT_TRUE(ret == ERR_NONE); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_ListFile_0000"; +} + +/** + * @tc.number: SUB_STORAGE_File_Manager_Proxy_CreateFile_0000 + * @tc.name: File_Manager_Proxy_CreateFile_0000 + * @tc.desc: Test function of CreateFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_CreateFile_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_CreateFile_0000"; + std::string path = "dataability:///album"; + std::string fileName = "FMS_File_ManagerProxy_Mkdir_0000"; + CmdOptions option; + std::string uri; + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); + int ret = proxy_->CreateFile(path, fileName, option, uri); + ASSERT_TRUE(ret == ERR_NONE); + GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_CreateFile_0000"; +} +} // namespace \ No newline at end of file diff --git a/services/test/client/fms_manager_proxy_mock.h b/services/test/client/fms_manager_proxy_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..ae04272a4e479446055e7e9fbedbad656ddc762c --- /dev/null +++ b/services/test/client/fms_manager_proxy_mock.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FMS_MANAGER_PROXY_MOCK_H +#define FMS_MANAGER_PROXY_MOCK_H +#include +#include "gmock/gmock.h" +#include "iremote_stub.h" +#include "iremote_proxy.h" +#include "ifms_client.h" + +namespace OHOS { +namespace FileManagerService { +class FmsManagerProxyMock : public IRemoteStub, public IFmsClient { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"FmsManagerProxyMock"); + FmsManagerProxyMock() {} + virtual ~FmsManagerProxyMock() {} + MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) + { + return ERR_NONE; + } + virtual int Mkdir(const std::string &name, const std::string &path) override + { + return ERR_NONE; + } + virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, + std::vector> &fileRes) override + { + return ERR_NONE; + } + virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) override + { + return ERR_NONE; + } + virtual int CreateFile(const std::string &path, const std::string &fileName, + const CmdOptions &option, std::string &uri) override + { + return ERR_NONE; + } +}; +} // namespace FileManagerService +} // namespace OHOS + +#endif // FMS_MANAGER_PROXY_MOCK_H \ No newline at end of file diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2dcc3a1c9690eb53b92853121bd20db2e55a42b7 --- /dev/null +++ b/services/test/fileoper/oper_factory_test.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "file_manager_service_def.h" +#include "file_manager_service_stub.h" +#include "media_data_ability_const.h" +#include "abs_shared_result_set.h" +#include "media_file_utils.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class OperFactoryTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "OperFactoryTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0000 + * @tc.name: oper_factory_GetFileOper_0000 + * @tc.desc: Test function of GetFileOper interface for SUCCESS which INTERNAL_STORAGE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0000"; + try { + OperFactory *oper = new OperFactory(); + std::unique_ptr result; + if (oper != nullptr) { + result = oper->GetFileOper(Equipment::INTERNAL_STORAGE); + } + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0000"; +} + +/** + * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0001 + * @tc.name: oper_factory_GetFileOper_0001 + * @tc.desc: Test function of GetFileOper for SUCCESS which EXTERNAL_STORAGE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0001"; + try { + OperFactory *oper = new OperFactory(); + std::unique_ptr result; + if (oper != nullptr) { + result = oper->GetFileOper(Equipment::EXTERNAL_STORAGE); + } + EXPECT_NE(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0001"; +} + +/** + * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0002 + * @tc.name: oper_factory_GetFileOper_0002 + * @tc.desc: Test function of GetFileOper interface for SUCCESS wich default. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0002"; + try { + OperFactory *oper = new OperFactory(); + std::unique_ptr result; + if (oper != nullptr) { + result = oper->GetFileOper(3); + } + EXPECT_EQ(result, nullptr); + } catch (...) { + GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0002"; +} +} // namespace \ No newline at end of file diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7cb427447b66eefd64bf54c9b5e19bc051247a3c --- /dev/null +++ b/services/test/server/file_manager_service_test.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "ifms_client.h" +#include "file_info.h" +#include "media_file_oper.h" +#include "file_manager_service_stub.h" +#include "media_data_ability_const.h" +#include "file_manager_service_def.h" +#include "abs_shared_result_set.h" +#include "file_manager_service.h" +#include "media_file_utils.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace FileManagerService; +class FileManagerServiceTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "FileManagerServiceTest code test" << endl; + } + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_file_Manager_Service_OnDump_0000 + * @tc.name: file_Manager_Service_OnDump_0000 + * @tc.desc: Test function of OnDump interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnDump_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnDump_0000"; + try { + OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); + if (service != nullptr) { + service->OnDump(); + } + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnDump_0000"; +} + +/** + * @tc.number: SUB_STORAGE_file_Manager_Service_OnStart_0000 + * @tc.name: file_Manager_Service_OnStart_0000 + * @tc.desc: Test function of OnStart interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnStart_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStart_0000"; + try { + OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); + if (service != nullptr) { + service->OnStart(); + } + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStart_0000"; +} + +/** + * @tc.number: SUB_STORAGE_file_Manager_Service_OnStop_0000 + * @tc.name: file_Manager_Service_OnStop_0000 + * @tc.desc: Test function of OnStop interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000GJ9T3 + */ +HWTEST_F(FileManagerServiceTest, Ffile_Manager_Service_OnStop_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStop_0000"; + try { + OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); + if (service != nullptr) { + service->OnStop(); + } + } catch (...) { + GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStop_0000"; +} +} // namespace \ No newline at end of file