From c98a3a4590020036368c8132f041a25b335af890 Mon Sep 17 00:00:00 2001 From: zhuhongtao66 Date: Thu, 1 Dec 2022 17:43:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=9B=9E=E5=90=88master=E3=80=91Add?= =?UTF-8?q?=20TDD=20testcases=20for=20storage=5Fservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuhongtao66 --- bundle.json | 3 + .../storage_manager/native/storage_stats.h | 4 +- services/storage_daemon/client/test/BUILD.gn | 60 +++ .../test/storage_daemon_client_test.cpp | 203 ++++++++ .../ipc/test/storage_daemon_proxy_test.cpp | 193 ++++++++ .../ipc/test/storage_daemon_stub_test.cpp | 455 +++++++++++++++++- .../ipc/test/storage_daemon_test.cpp | 129 +++++ services/storage_daemon/volume/test/BUILD.gn | 33 ++ .../volume/test/external_volume_info_test.cpp | 152 +++--- .../volume/test/process_test.cpp | 75 +++ .../volume/test/volume_info_test.cpp | 209 +++++++- .../volume/test/volume_manager_test.cpp | 157 ++++++ .../client/storage_manager_client.cpp | 4 +- services/storage_manager/client/test/BUILD.gn | 57 +++ .../client/test/get_self_permissions.cpp | 62 +++ .../client/test/get_self_permissions.h | 31 ++ .../test/storage_manager_client_test.cpp | 271 +++++++++++ services/storage_manager/crypto/test/BUILD.gn | 55 +++ .../crypto/test/filesystem_crypto_test.cpp | 314 ++++++++++++ .../disk/test/disk_manager_service_test.cpp | 187 ++++++- .../include/client/storage_manager_client.h | 4 +- .../innerkits_impl/test/BUILD.gn | 32 ++ .../innerkits_impl/test/bundle_stats_test.cpp | 83 ++++ .../test/storage_stats_test.cpp | 98 ++++ services/storage_manager/ipc/test/BUILD.gn | 101 +++- .../ipc/test/storage_manager_stub_mock.h | 67 +++ .../test/storage_manager_stub_noper_test.cpp | 99 ++++ .../ipc/test/storage_manager_stub_test.cpp | 335 +++++++++++++ .../storage_manager/storage/test/BUILD.gn | 45 +- .../storage_total_status_service_test.cpp | 68 ++- .../volume_storage_status_service_test.cpp | 77 +++ .../storage_daemon_communication_test.cpp | 33 +- .../test/multi_user_manager_service_test.cpp | 3 +- .../test/volume_manager_service_test.cpp | 98 +++- 34 files changed, 3630 insertions(+), 167 deletions(-) create mode 100644 services/storage_daemon/client/test/BUILD.gn create mode 100644 services/storage_daemon/client/test/storage_daemon_client_test.cpp create mode 100644 services/storage_daemon/volume/test/process_test.cpp create mode 100644 services/storage_manager/client/test/BUILD.gn create mode 100644 services/storage_manager/client/test/get_self_permissions.cpp create mode 100644 services/storage_manager/client/test/get_self_permissions.h create mode 100644 services/storage_manager/client/test/storage_manager_client_test.cpp create mode 100644 services/storage_manager/crypto/test/BUILD.gn create mode 100644 services/storage_manager/crypto/test/filesystem_crypto_test.cpp create mode 100644 services/storage_manager/innerkits_impl/test/bundle_stats_test.cpp create mode 100644 services/storage_manager/innerkits_impl/test/storage_stats_test.cpp create mode 100644 services/storage_manager/ipc/test/storage_manager_stub_mock.h create mode 100644 services/storage_manager/ipc/test/storage_manager_stub_noper_test.cpp create mode 100644 services/storage_manager/ipc/test/storage_manager_stub_test.cpp create mode 100644 services/storage_manager/storage/test/volume_storage_status_service_test.cpp diff --git a/bundle.json b/bundle.json index b5d201f1..2e8c7a47 100644 --- a/bundle.json +++ b/bundle.json @@ -79,6 +79,7 @@ } ], "test": [ + "//foundation/filemanagement/storage_service/services/storage_daemon/client/test:storage_daemon_client_test", "//foundation/filemanagement/storage_service/services/storage_daemon/crypto/test:crypto_test", "//foundation/filemanagement/storage_service/services/storage_daemon/disk/test:storage_daemon_disk_test", "//foundation/filemanagement/storage_service/services/storage_daemon/file_sharing/test:file_sharing_test", @@ -87,6 +88,8 @@ "//foundation/filemanagement/storage_service/services/storage_daemon/user/test:storage_daemon_user_test", "//foundation/filemanagement/storage_service/services/storage_daemon/utils/test:storage_daemon_utils_test", "//foundation/filemanagement/storage_service/services/storage_daemon/volume/test:storage_daemon_volume_test", + "//foundation/filemanagement/storage_service/services/storage_manager/client/test:storage_manager_client_test", + "//foundation/filemanagement/storage_service/services/storage_manager/crypto/test:storage_manager_crypto_test", "//foundation/filemanagement/storage_service/services/storage_manager/ipc/test:storage_manager_ipc_test", "//foundation/filemanagement/storage_service/services/storage_manager/storage/test:storage_manager_storage_test", "//foundation/filemanagement/storage_service/services/storage_manager/storage_daemon_communication/test:storage_manager_communication_test", diff --git a/interfaces/innerkits/storage_manager/native/storage_stats.h b/interfaces/innerkits/storage_manager/native/storage_stats.h index a2d8dc88..d78c0bc2 100644 --- a/interfaces/innerkits/storage_manager/native/storage_stats.h +++ b/interfaces/innerkits/storage_manager/native/storage_stats.h @@ -23,8 +23,8 @@ namespace StorageManager { class StorageStats final : public Parcelable { public: StorageStats() {} - StorageStats(int64_t total, int64_t audio, int64_t video, int64_t file, int64_t app) - : total_(total), audio_(audio), video_(video), file_(file), app_(app) {} + StorageStats(int64_t total, int64_t audio, int64_t video, int64_t image, int64_t file, int64_t app) + : total_(total), audio_(audio), video_(video), image_(image), file_(file), app_(app) {} ~StorageStats() {} int64_t total_ {0}; diff --git a/services/storage_daemon/client/test/BUILD.gn b/services/storage_daemon/client/test/BUILD.gn new file mode 100644 index 00000000..13c1e563 --- /dev/null +++ b/services/storage_daemon/client/test/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2022 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") + +ROOT_DIR = "//foundation/filemanagement/storage_service/services/storage_daemon" + +ohos_unittest("storage_daemon_clt_test") { + module_out_path = "filemanagement/storage_service/storage_daemon" + + defines = [ + "STORAGE_LOG_TAG = \"StorageDaemon\"", + "LOG_DOMAIN = 0xD004301", + ] + + include_dirs = [ + "$ROOT_DIR/include", + "$ROOT_DIR/client/include", + "$ROOT_DIR/utils/test/common", + "//foundation/filemanagement/storage_service/services/common/include", + "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/systemabilitymgr/samgr/utils/native/include", + ] + + sources = [ + "$ROOT_DIR/client/storage_daemon_client.cpp", + "$ROOT_DIR/client/test/storage_daemon_client_test.cpp", + "$ROOT_DIR/utils/test/common/help_utils.cpp", + ] + + deps = [ + "//foundation/filemanagement/storage_service/services/storage_daemon:storage_common_utils", + "//foundation/filemanagement/storage_service/services/storage_daemon/libfscrypt:libfscryptutils", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] +} + +group("storage_daemon_client_test") { + testonly = true + deps = [ ":storage_daemon_clt_test" ] +} diff --git a/services/storage_daemon/client/test/storage_daemon_client_test.cpp b/services/storage_daemon/client/test/storage_daemon_client_test.cpp new file mode 100644 index 00000000..55fae1fd --- /dev/null +++ b/services/storage_daemon/client/test/storage_daemon_client_test.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2022 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 "storage_daemon_client.h" +#include "ipc/istorage_daemon.h" +#include "storage_service_errno.h" +#include "storage_service_log.h" +#include "help_utils.h" +namespace OHOS { +namespace StorageDaemon { +using namespace testing::ext; + +class StorageDaemonClientTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp(); + void TearDown(); + + StorageDaemonClient* storageDaemonClient_; +}; + +void StorageDaemonClientTest::SetUp() +{ + storageDaemonClient_ = new StorageDaemonClient(); +} + +void StorageDaemonClientTest::TearDown(void) +{ + StorageTest::StorageTestUtils::ClearTestResource(); + if (storageDaemonClient_ != nullptr) { + delete storageDaemonClient_; + storageDaemonClient_ = nullptr; + } +} + +/** + * @tc.name: Storage_Service_StorageDaemonClientTest_PrepareUserDirs_001 + * @tc.desc: Verify the PrepareUserDirs function when args are normal. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_PrepareUserDirs_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_PrepareUserDirs_001 start"; + + ASSERT_TRUE(storageDaemonClient_ != nullptr); + + int32_t userid = 103; + int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL2; + int32_t ret = storageDaemonClient_->PrepareUserDirs(userid, flags); + EXPECT_TRUE(ret == E_OK); + + ret = storageDaemonClient_->DestroyUserDirs(userid, flags); + EXPECT_TRUE(ret == E_OK); + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_PrepareUserDirs_001 end"; +} + +/** + * @tc.name: Storage_Service_StorageDaemonClientTest_StartUser_001 + * @tc.desc: check the StartUser function when args are normal + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_StartUser_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_StartUser_001 start"; + + ASSERT_TRUE(storageDaemonClient_ != nullptr); + + int32_t userid = 104; + int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL2; + int32_t ret = storageDaemonClient_->PrepareUserDirs(userid, flags); + EXPECT_TRUE(ret == E_OK) << "PrepareUserDirs error"; + ret = storageDaemonClient_->StartUser(userid); + EXPECT_TRUE(ret == E_OK) << "StartUser error"; + + ret = storageDaemonClient_->StopUser(userid); + EXPECT_TRUE(ret == E_OK) << "check StopUser error"; + + storageDaemonClient_->DestroyUserDirs(userid, flags); + EXPECT_TRUE(ret == E_OK); + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_StartUser_001 end"; +} + +/** + * @tc.name: Storage_Service_StorageDaemonClientTest_PrepareUserSpace_001 + * @tc.desc: Verify the PrepareUserSpace function when args are normal. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_PrepareUserSpace_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_PrepareUserSpace_001 start"; + + ASSERT_TRUE(storageDaemonClient_ != nullptr); + + int32_t userid = 105; + std::string volId = "vol-1-1"; + int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL2; + int32_t ret = storageDaemonClient_->PrepareUserSpace(userid, volId, flags); + EXPECT_TRUE(ret == E_OK); + + storageDaemonClient_->DestroyUserSpace(userid, volId, flags); + EXPECT_TRUE(ret == E_OK); + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_PrepareUserSpace_001 end"; +} + +/** + * @tc.name: Storage_Service_StorageDaemonClientTest_ActiveUserKey_001 + * @tc.desc: Verify the ActiveUserKey function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_ActiveUserKey_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_ActiveUserKey_001 start"; + + ASSERT_TRUE(storageDaemonClient_ != nullptr); + + int32_t userid = 108; + int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL2; + int32_t ret = storageDaemonClient_->GenerateUserKeys(userid, flags); + ASSERT_TRUE(ret == E_OK); + + ret = storageDaemonClient_->ActiveUserKey(userid, {}, {}); + EXPECT_TRUE(ret == E_OK); + + ret = storageDaemonClient_->InactiveUserKey(userid); + EXPECT_TRUE(ret == E_OK); + + storageDaemonClient_->DeleteUserKeys(userid); + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_ActiveUserKey_001 end"; +} + +/** + * @tc.name: Storage_Service_StorageDaemonClientTest_UpdateUserAuth_001 + * @tc.desc: Verify the UpdateUserAuth function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_UpdateUserAuth_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_UpdateUserAuth_001 start"; + + ASSERT_TRUE(storageDaemonClient_ != nullptr); + + int32_t userid = 109; + int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL2; + int32_t ret = storageDaemonClient_->PrepareUserDirs(userid, flags); + ret = storageDaemonClient_->StartUser(userid); + EXPECT_TRUE(ret == E_OK) << "StartUser error"; + + ret = storageDaemonClient_->UpdateUserAuth(userid, {}, {}, {}); + EXPECT_TRUE(ret == E_OK) << "UpdateUserAuth error"; + + ret = storageDaemonClient_->StopUser(userid); + storageDaemonClient_->DestroyUserDirs(userid, flags); + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_UpdateUserAuth_001 end"; +} + +/** + * @tc.name: Storage_Service_StorageDaemonClientTest_UpdateKeyContext_001 + * @tc.desc: Verify the UpdateKeyContext function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonClientTest, Storage_Service_StorageDaemonClientTest_UpdateKeyContext_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_UpdateKeyContext_001 start"; + + ASSERT_TRUE(storageDaemonClient_ != nullptr); + + int32_t userid = 110; + int32_t flags = IStorageDaemon::CRYPTO_FLAG_EL2; + int32_t ret = storageDaemonClient_->GenerateUserKeys(userid, flags); + ASSERT_TRUE(ret == E_OK); + + ret = storageDaemonClient_->UpdateUserAuth(userid, {}, {}, {}); + EXPECT_TRUE(ret == E_OK) << "UpdateUserAuth error"; + + ret = storageDaemonClient_->UpdateKeyContext(userid); + EXPECT_TRUE(ret == E_OK); + + storageDaemonClient_->DeleteUserKeys(userid); + GTEST_LOG_(INFO) << "Storage_Service_StorageDaemonClientTest_UpdateKeyContext_001 end"; +} +} +} \ No newline at end of file diff --git a/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp b/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp index 79abe3a2..2d326109 100644 --- a/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp +++ b/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp @@ -150,6 +150,114 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_StopUser_001, TestSize.L GTEST_LOG_(INFO) << "StorageDaemonProxyTest_StopUser_001 end"; } +/** + * @tc.name: StorageDaemonProxyTest_Mount_001 + * @tc.desc: Verify the Mount function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_Mount_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Mount_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + string volId = "vol-0-1"; + uint32_t flag = 1; + int32_t ret = proxy_->Mount(volId, flag); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::MOUNT == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Mount_001 end"; +} + +/** + * @tc.name: StorageDaemonProxyTest_UMount_001 + * @tc.desc: Verify the UMount function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_UMount_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_UMount_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + string volId = "vol-0-2"; + int32_t ret = proxy_->UMount(volId); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::UMOUNT == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_UMount_001 end"; +} + +/** + * @tc.name: StorageDaemonProxyTest_Check_001 + * @tc.desc: Verify the Check function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_Check_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Check_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + string volId = "vol-0-3"; + int32_t ret = proxy_->Check(volId); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::CHECK == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Check_001 end"; +} + +/** + * @tc.name: StorageDaemonProxyTest_Format_001 + * @tc.desc: Verify the Format function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_Format_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Format_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + string volId = "vol-0-4"; + string fsType = "exfat"; + int32_t ret = proxy_->Format(volId, fsType); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::FORMAT == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Format_001 end"; +} + +/** + * @tc.name: StorageDaemonProxyTest_Partition_001 + * @tc.desc: Verify the Partition function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_Partition_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Partition_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + string diskId = "disk-0-1"; + int32_t type = 0; + int32_t ret = proxy_->Partition(diskId, type); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::PARTITION == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_Partition_001 end"; +} + /** * @tc.name: StorageDaemonProxyTest_SetVolumeDescription_001 * @tc.desc: Verify the SetVolumeDescription function. @@ -167,6 +275,7 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_SetVolumeDescription_001 string description = "description-1"; int32_t ret = proxy_->SetVolumeDescription(volId, description); ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::SET_VOL_DESC == mock_->code_); GTEST_LOG_(INFO) << "StorageDaemonProxyTest_SetVolumeDescription_001 end"; } @@ -186,6 +295,7 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_InitGlobalKey_001, TestS .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); int32_t ret = proxy_->InitGlobalKey(); ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::INIT_GLOBAL_KEY == mock_->code_); GTEST_LOG_(INFO) << "StorageDaemonProxyTest_InitGlobalKey_001 end"; } @@ -205,6 +315,7 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_InitGlobalUserKeys_001, .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); int32_t ret = proxy_->InitGlobalUserKeys(); ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::INIT_GLOBAL_USER_KEYS == mock_->code_); GTEST_LOG_(INFO) << "StorageDaemonProxyTest_InitGlobalUserKeys_001 end"; } @@ -224,10 +335,71 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_GenerateUserKeys_001, Te .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); int32_t ret = proxy_->GenerateUserKeys(USER_ID1, IStorageDaemon::CRYPTO_FLAG_EL1); ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::CREATE_USER_KEYS == mock_->code_); GTEST_LOG_(INFO) << "StorageDaemonProxyTest_GenerateUserKeys_001 end"; } +/** + * @tc.name: StorageDaemonProxyTest_DeleteUserKeys_001 + * @tc.desc: Verify the DeleteUserKeys function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_DeleteUserKeys_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_DeleteUserKeys_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + int32_t ret = proxy_->DeleteUserKeys(USER_ID1); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::DELETE_USER_KEYS == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_DeleteUserKeys_001 end"; +} + +/** + * @tc.name: StorageDaemonProxyTest_UpdateUserAuth_001 + * @tc.desc: Verify the UpdateUserAuth function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_UpdateUserAuth_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_UpdateUserAuth_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + int32_t ret = proxy_->UpdateUserAuth(USER_ID1, {}, {}, {}); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::UPDATE_USER_AUTH == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_UpdateUserAuth_001 end"; +} + +/** + * @tc.name: StorageDaemonProxyTest_ActiveUserKey_001 + * @tc.desc: Verify the ActiveUserKey function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_ActiveUserKey_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_ActiveUserKey_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + int32_t ret = proxy_->ActiveUserKey(USER_ID1, {}, {}); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::ACTIVE_USER_KEY == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_ActiveUserKey_001 end"; +} + /** * @tc.name: StorageDaemonProxyTest_InactiveUserKey_001 * @tc.desc: Verify the InactiveUserKey function. @@ -243,8 +415,29 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_InactiveUserKey_001, Tes .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); int32_t ret = proxy_->InactiveUserKey(USER_ID1); ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::INACTIVE_USER_KEY == mock_->code_); GTEST_LOG_(INFO) << "StorageDaemonProxyTest_InactiveUserKey_001 end"; } + +/** + * @tc.name: StorageDaemonProxyTest_UpdateKeyContext_001 + * @tc.desc: Verify the UpdateKeyContext function. + * @tc.type: FUNC + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_UpdateKeyContext_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_UpdateKeyContext_001 start"; + + EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest)); + int32_t ret = proxy_->UpdateKeyContext(USER_ID1); + ASSERT_TRUE(ret == E_OK); + ASSERT_TRUE(IStorageDaemon::UPDATE_KEY_CONTEXT == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_UpdateKeyContext_001 end"; +} } // STORAGE_DAEMON } // OHOS \ No newline at end of file diff --git a/services/storage_daemon/ipc/test/storage_daemon_stub_test.cpp b/services/storage_daemon/ipc/test/storage_daemon_stub_test.cpp index 26de4745..c8f6651e 100644 --- a/services/storage_daemon/ipc/test/storage_daemon_stub_test.cpp +++ b/services/storage_daemon/ipc/test/storage_daemon_stub_test.cpp @@ -32,6 +32,27 @@ using namespace testing::ext; namespace { const int ERROR_CODE = 99999; + int g_code[] = { + IStorageDaemon::SHUTDOWN, + IStorageDaemon::MOUNT, + IStorageDaemon::UMOUNT, + IStorageDaemon::CHECK, + IStorageDaemon::FORMAT, + IStorageDaemon::PARTITION, + IStorageDaemon::SET_VOL_DESC, + IStorageDaemon::PREPARE_USER_DIRS, + IStorageDaemon::DESTROY_USER_DIRS, + IStorageDaemon::START_USER, + IStorageDaemon::STOP_USER, + IStorageDaemon::INIT_GLOBAL_KEY, + IStorageDaemon::INIT_GLOBAL_USER_KEYS, + IStorageDaemon::CREATE_USER_KEYS, + IStorageDaemon::DELETE_USER_KEYS, + IStorageDaemon::UPDATE_USER_AUTH, + IStorageDaemon::ACTIVE_USER_KEY, + IStorageDaemon::INACTIVE_USER_KEY, + IStorageDaemon::UPDATE_KEY_CONTEXT + }; } class StorageDaemonStubTest : public testing::Test { @@ -101,30 +122,29 @@ HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonStubTest_OnRemoteRe { GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonStubTest_OnRemoteRequest_003 start"; - int code[] = { - IStorageDaemon::SHUTDOWN, - IStorageDaemon::MOUNT, - IStorageDaemon::UMOUNT, - IStorageDaemon::CHECK, - IStorageDaemon::FORMAT, - IStorageDaemon::PREPARE_USER_DIRS, - IStorageDaemon::DESTROY_USER_DIRS, - IStorageDaemon::START_USER, - IStorageDaemon::STOP_USER - }; - StorageDaemonStubMock mock; EXPECT_CALL(mock, Shutdown()).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Mount(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, UMount(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Check(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Format(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Partition(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, SetVolumeDescription(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, PrepareUserDirs(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, DestroyUserDirs(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, StartUser(testing::_)).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, StopUser(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, InitGlobalKey()).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, InitGlobalUserKeys()).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, GenerateUserKeys(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DeleteUserKeys(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, UpdateUserAuth(testing::_, testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, ActiveUserKey(testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, InactiveUserKey(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, UpdateKeyContext(testing::_)).WillOnce(testing::Return(E_OK)); - for (auto c : code) { - if (c >= IStorageDaemon::MOUNT && c <= IStorageDaemon::FORMAT) { - continue; - } + for (auto c : g_code) { MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); @@ -292,5 +312,408 @@ HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleSetVolDe GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleSetVolDesc_001 end"; } + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleMount_001 + * @tc.desc: Verify the HandleMount function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleMount_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleMount_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, Mount(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleMount(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, Mount(testing::_, testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleMount(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleMount_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleUMount_001 + * @tc.desc: Verify the HandleUMount function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleUMount_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleUMount_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, UMount(testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleUMount(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, UMount(testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleUMount(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleUMount_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleCheck_001 + * @tc.desc: Verify the HandleCheck function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleCheck_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleCheck_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, Check(testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleCheck(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, Check(testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleCheck(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleCheck_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandlePartition_001 + * @tc.desc: Verify the HandlePartition function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandlePartition_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandlePartition_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, Partition(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandlePartition(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, Partition(testing::_, testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandlePartition(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandlePartition_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleFormat_001 + * @tc.desc: Verify the HandleFormat function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleFormat_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleFormat_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, Format(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleFormat(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, Format(testing::_, testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleFormat(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleFormat_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleInitGlobalKey_001 + * @tc.desc: Verify the HandleInitGlobalKey function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleInitGlobalKey_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleInitGlobalKey_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, InitGlobalKey()).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleInitGlobalKey(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, InitGlobalKey()).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleInitGlobalKey(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleInitGlobalKey_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleInitGlobalUserKeys_001 + * @tc.desc: Verify the HandleInitGlobalUserKeys function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleInitGlobalUserKeys_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleInitGlobalUserKeys_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, InitGlobalUserKeys()).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleInitGlobalUserKeys(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, InitGlobalUserKeys()).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleInitGlobalUserKeys(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleInitGlobalUserKeys_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleGenerateUserKeys_001 + * @tc.desc: Verify the HandleGenerateUserKeys function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleGenerateUserKeys_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleGenerateUserKeys_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, GenerateUserKeys(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleGenerateUserKeys(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, GenerateUserKeys(testing::_, testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleGenerateUserKeys(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleGenerateUserKeys_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleDeleteUserKeys_001 + * @tc.desc: Verify the HandleDeleteUserKeys function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleDeleteUserKeys_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleDeleteUserKeys_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, DeleteUserKeys(testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleDeleteUserKeys(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, DeleteUserKeys(testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleDeleteUserKeys(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleDeleteUserKeys_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleUpdateUserAuth_001 + * @tc.desc: Verify the HandleUpdateUserAuth function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleUpdateUserAuth_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleUpdateUserAuth_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, UpdateUserAuth(testing::_, testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleUpdateUserAuth(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, UpdateUserAuth(testing::_, testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleUpdateUserAuth(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleUpdateUserAuth_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleActiveUserKey_001 + * @tc.desc: Verify the HandleActiveUserKey function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleActiveUserKey_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleActiveUserKey_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, ActiveUserKey(testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleActiveUserKey(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, ActiveUserKey(testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleActiveUserKey(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleActiveUserKey_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleInactiveUserKey_001 + * @tc.desc: Verify the HandleInactiveUserKey function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleInactiveUserKey_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleInactiveUserKey_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, InactiveUserKey(testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleInactiveUserKey(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, InactiveUserKey(testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleInactiveUserKey(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleInactiveUserKey_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_HandleUpdateKeyContext_001 + * @tc.desc: Verify the HandleUpdateKeyContext function. + * @tc.type: FUNC + * @tc.require: AR000H09L6 + */ +HWTEST_F(StorageDaemonStubTest, Storage_Manager_StorageDaemonTest_HandleUpdateKeyContext_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleUpdateKeyContext_001 start"; + + StorageDaemonStubMock mock; + + MessageParcel data1; + MessageParcel reply1; + EXPECT_CALL(mock, UpdateKeyContext(testing::_)).WillOnce(testing::Return(E_OK)); + int32_t ret = mock.HandleUpdateKeyContext(data1, reply1); + EXPECT_TRUE(ret == E_OK); + int32_t err = reply1.ReadInt32(); + EXPECT_TRUE(err == E_OK); + + MessageParcel data2; + MessageParcel reply2; + EXPECT_CALL(mock, UpdateKeyContext(testing::_)).WillOnce(testing::Return(E_ERR)); + ret = mock.HandleUpdateKeyContext(data2, reply2); + EXPECT_TRUE(ret == E_OK); + err = reply2.ReadInt32(); + EXPECT_TRUE(err == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_HandleUpdateKeyContext_001 end"; +} } // STORAGE_DAEMON } // OHOS diff --git a/services/storage_daemon/ipc/test/storage_daemon_test.cpp b/services/storage_daemon/ipc/test/storage_daemon_test.cpp index 875c96b9..6bc92209 100644 --- a/services/storage_daemon/ipc/test/storage_daemon_test.cpp +++ b/services/storage_daemon/ipc/test/storage_daemon_test.cpp @@ -274,5 +274,134 @@ HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_StopUser_003, Test storageDaemon_->DestroyUserDirs(StorageTest::StorageTestUtils::USER_ID3, flags); GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_StopUser_003 end"; } + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_Shutdown_001 + * @tc.desc: check the StopUser function normal + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Shutdown_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Shutdown_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + auto ret = storageDaemon_->Shutdown(); + EXPECT_TRUE(ret == E_OK); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Shutdown_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_Mount_001 + * @tc.desc: check the Mount function when volume not exist + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Mount_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Mount_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + std::string volId = "vol-1-1"; + uint32_t flag = 0; + auto ret = storageDaemon_->Mount(volId, flag); + EXPECT_TRUE(ret == E_NON_EXIST); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Mount_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_UMount_001 + * @tc.desc: check the UMount function when volume not exist + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_UMount_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_UMount_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + std::string volId = "vol-1-2"; + auto ret = storageDaemon_->UMount(volId); + EXPECT_TRUE(ret == E_NON_EXIST); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_UMount_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_Check_001 + * @tc.desc: check the Check function when volume not exist + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Check_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Check_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + std::string volId = "vol-1-3"; + auto ret = storageDaemon_->Check(volId); + EXPECT_TRUE(ret == E_NON_EXIST); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Check_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_Format_001 + * @tc.desc: check the Format function when volume not exist + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Format_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Format_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + std::string volId = "vol-1-4"; + std::string fsType = "exfat"; + auto ret = storageDaemon_->Format(volId, fsType); + EXPECT_TRUE(ret == E_NON_EXIST); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Format_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_Partition_001 + * @tc.desc: check the Partition function when disk not exist + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_Partition_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Partition_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + std::string diskId = "disk-1-0"; + int32_t type = 0; + auto ret = storageDaemon_->Partition(diskId, type); + EXPECT_TRUE(ret == E_NON_EXIST); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_Partition_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageDaemonTest_SetVolumeDescription_001 + * @tc.desc: check the SetVolumeDescription function when volume not exist + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageDaemonTest, Storage_Manager_StorageDaemonTest_SetVolumeDescription_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_SetVolumeDescription_001 start"; + + ASSERT_TRUE(storageDaemon_ != nullptr); + + std::string volId = "vol-1-5"; + std::string des = "des"; + auto ret = storageDaemon_->SetVolumeDescription(volId, des); + EXPECT_TRUE(ret == E_NON_EXIST); + GTEST_LOG_(INFO) << "Storage_Manager_StorageDaemonTest_SetVolumeDescription_001 end"; +} } // STORAGE_DAEMON } // OHOS diff --git a/services/storage_daemon/volume/test/BUILD.gn b/services/storage_daemon/volume/test/BUILD.gn index 31fd137b..60b5fc86 100644 --- a/services/storage_daemon/volume/test/BUILD.gn +++ b/services/storage_daemon/volume/test/BUILD.gn @@ -47,6 +47,38 @@ ohos_unittest("external_volume_info_test") { ] } +ohos_unittest("process_test") { + module_out_path = "filemanagement/storage_service/storage_daemon" + + defines = [ "STORAGE_LOG_TAG = \"StorageDaemon\"" ] + + include_dirs = [ + "$ROOT_DIR/storage_daemon/include", + "$ROOT_DIR/storage_daemon/include/volume", + "$ROOT_DIR/common/include", + ] + + sources = [ + "$ROOT_DIR/storage_daemon/volume/src/external_volume_info.cpp", + "$ROOT_DIR/storage_daemon/volume/src/process.cpp", + "$ROOT_DIR/storage_daemon/volume/src/volume_info.cpp", + "$ROOT_DIR/storage_daemon/volume/test/process_test.cpp", + ] + + deps = [ + "//foundation/filemanagement/storage_service/services/storage_daemon:storage_common_utils", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + ] +} + ohos_unittest("volume_info_test") { module_out_path = "filemanagement/storage_service/storage_daemon" @@ -123,6 +155,7 @@ group("storage_daemon_volume_test") { testonly = true deps = [ ":external_volume_info_test", + ":process_test", ":volume_info_test", ":volume_manager_test", ] diff --git a/services/storage_daemon/volume/test/external_volume_info_test.cpp b/services/storage_daemon/volume/test/external_volume_info_test.cpp index 7628d388..4e1155e0 100644 --- a/services/storage_daemon/volume/test/external_volume_info_test.cpp +++ b/services/storage_daemon/volume/test/external_volume_info_test.cpp @@ -42,16 +42,13 @@ HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoCreate { GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoCreate_001 start"; - ExternalVolumeInfoMock mock; + ExternalVolumeInfo vol; dev_t device = MKDEV(156, 300); - EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); - auto ret = mock.DoCreate(device); - EXPECT_TRUE(ret == E_OK); - - device = MKDEV(156, 301); - EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_ERR)); - ret = mock.DoCreate(device); - EXPECT_TRUE(ret == E_ERR); + std::string diskId = "disk-156-300"; + std::string volId = "vol-156-301"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + ret = vol.Destroy(); GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoCreate_001 end"; } @@ -66,14 +63,14 @@ HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoDestro { GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoDestroy_001 start"; - ExternalVolumeInfoMock mock; - EXPECT_CALL(mock, DoDestroy()).Times(1).WillOnce(testing::Return(E_OK)); - auto ret = mock.DoDestroy(); - EXPECT_TRUE(ret == E_OK); - - EXPECT_CALL(mock, DoDestroy()).Times(1).WillOnce(testing::Return(E_ERR)); - ret = mock.DoDestroy(); - EXPECT_TRUE(ret == E_ERR); + ExternalVolumeInfo vol; + dev_t device = MKDEV(156, 400); + std::string diskId = "disk-156-400"; + std::string volId = "vol-156-401"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + ret = vol.Destroy(); + EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoDestroy_001 end"; } @@ -138,19 +135,16 @@ HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoCheck_ { GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoCheck_001 start"; - ExternalVolumeInfoMock mock; - - EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_ERR)); - auto ret = mock.DoCheck(); - EXPECT_TRUE(ret == E_ERR); - - EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_NOT_SUPPORT)); - ret = mock.DoCheck(); - EXPECT_TRUE(ret == E_NOT_SUPPORT); - - EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); - ret = mock.DoCheck(); - EXPECT_TRUE(ret == E_OK); + ExternalVolumeInfo vol; + dev_t device = MKDEV(156, 600); + std::string diskId = "disk-156-600"; + std::string volId = "vol-156-601"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + ret = vol.Check(); + EXPECT_EQ(ret, E_ERR); + ret = vol.Destroy(); + EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoCheck_001 end"; } @@ -164,23 +158,68 @@ HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoFormat { GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoFormat_001 start"; - ExternalVolumeInfoMock mock; - std::string type = "ext2"; - - EXPECT_CALL(mock, DoFormat(testing::_)).Times(1).WillOnce(testing::Return(E_NOT_SUPPORT)); - auto ret = mock.DoFormat(type); - EXPECT_TRUE(ret == E_NOT_SUPPORT); - - EXPECT_CALL(mock, DoFormat(testing::_)).Times(1).WillOnce(testing::Return(E_ERR)); - ret = mock.DoFormat(type); - EXPECT_TRUE(ret == E_ERR); - - EXPECT_CALL(mock, DoFormat(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); - ret = mock.DoFormat(type); - EXPECT_TRUE(ret == E_OK); + ExternalVolumeInfo vol; + dev_t device = MKDEV(156, 700); + std::string diskId = "disk-156-700"; + std::string volId = "vol-156-701"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + std::string flag = "exfat"; + ret = vol.Format(flag); + EXPECT_EQ(ret, E_OK); + ret = vol.Destroy(); + EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoFormat_001 end"; } +/** + * @tc.name: Storage_Service_ExternalVolumeInfoTest_DoFormat_002 + * @tc.desc: Verify the DoFormat function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoFormat_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoFormat_002 start"; + + ExternalVolumeInfo vol; + dev_t device = MKDEV(156, 701); + std::string diskId = "disk-156-701"; + std::string volId = "vol-156-702"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + std::string flag = "vfat"; + ret = vol.Format(flag); + EXPECT_EQ(ret, E_OK); + ret = vol.Destroy(); + EXPECT_EQ(ret, E_OK); + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoFormat_002 end"; +} + +/** + * @tc.name: Storage_Service_ExternalVolumeInfoTest_DoFormat_003 + * @tc.desc: Verify the DoFormat function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoFormat_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoFormat_003 start"; + + ExternalVolumeInfo vol; + dev_t device = MKDEV(156, 702); + std::string diskId = "disk-156-702"; + std::string volId = "vol-156-703"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + std::string flag = "ntfs"; + ret = vol.Format(flag); + EXPECT_EQ(ret, E_NOT_SUPPORT); + ret = vol.Destroy(); + EXPECT_EQ(ret, E_OK); + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoFormat_003 end"; +} + /** * @tc.name: Storage_Service_ExternalVolumeInfoTest_DoSetVolDesc_001 * @tc.desc: Verify the DoSetVolDesc function. @@ -191,20 +230,17 @@ HWTEST_F(ExternalVolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_DoSetVol { GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoSetVolDesc_001 start"; - ExternalVolumeInfoMock mock; - std::string description = "description-1"; - - EXPECT_CALL(mock, DoSetVolDesc(testing::_)).Times(1).WillOnce(testing::Return(E_NOT_SUPPORT)); - auto ret = mock.DoSetVolDesc(description); - EXPECT_TRUE(ret == E_NOT_SUPPORT); - - EXPECT_CALL(mock, DoSetVolDesc(testing::_)).Times(1).WillOnce(testing::Return(E_ERR)); - ret = mock.DoSetVolDesc(description); - EXPECT_TRUE(ret == E_ERR); - - EXPECT_CALL(mock, DoSetVolDesc(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); - ret = mock.DoSetVolDesc(description); - EXPECT_TRUE(ret == E_OK); + ExternalVolumeInfo vol; + dev_t device = MKDEV(156, 800); + std::string diskId = "disk-156-800"; + std::string volId = "vol-156-801"; + int32_t ret = vol.Create(volId, diskId, device); + EXPECT_EQ(ret, E_OK); + std::string des = "label1"; + ret = vol.SetVolumeDescription(des); + EXPECT_EQ(ret, E_NOT_SUPPORT); + ret = vol.Destroy(); + EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_DoSetVolDesc_001 end"; } diff --git a/services/storage_daemon/volume/test/process_test.cpp b/services/storage_daemon/volume/test/process_test.cpp new file mode 100644 index 00000000..e81a7eb9 --- /dev/null +++ b/services/storage_daemon/volume/test/process_test.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 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 +#include "external_volume_info.h" +#include "process.h" +#include "external_volume_info_mock.h" + +#include "storage_service_errno.h" +#include "storage_service_log.h" + +namespace OHOS { +namespace StorageDaemon { +using namespace testing::ext; + +class ProcessTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Storage_Service_ProcessTest_GetPath_001 + * @tc.desc: Verify the GetPath function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(ProcessTest, Storage_Service_ProcessTest_GetXXX_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_ProcessTest_GetXXX_001 start"; + + std::string volId = "vol-1-1"; + std::string diskId = "disk-1-1"; + dev_t device = MKDEV(1, 1); // 1 is major device number, 1 is minor device number + uint32_t mountFlags = 0; + ExternalVolumeInfoMock mock; + EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoMount(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + + auto ret = mock.Create(volId, diskId, device); + EXPECT_TRUE(ret == E_OK); + + ret = mock.Check(); + EXPECT_TRUE(ret == E_OK); + + ret = mock.Mount(mountFlags); + EXPECT_TRUE(ret == E_OK); + + auto mountPath = mock.GetMountPath(); + Process ps(mountPath); + ps.UpdatePidByPath(); + EXPECT_TRUE(ps.GetPath() == mountPath); + ps.GetPids(); + + GTEST_LOG_(INFO) << "Storage_Service_ProcessTest_GetXXX_001 end"; +} +} // STORAGE_DAEMON +} // OHOS diff --git a/services/storage_daemon/volume/test/volume_info_test.cpp b/services/storage_daemon/volume/test/volume_info_test.cpp index 7b1f987e..73506f1f 100644 --- a/services/storage_daemon/volume/test/volume_info_test.cpp +++ b/services/storage_daemon/volume/test/volume_info_test.cpp @@ -112,6 +112,45 @@ HWTEST_F(VolumeInfoTest, Storage_Service_VolumeInfoTest_Destroy_002, TestSize.Le GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_Destroy_002 end"; } +/** + * @tc.name: Storage_Service_VolumeInfoTest_Destroy_003 + * @tc.desc: Verify the Destroy function when DoDestroy() return error. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeInfoTest, Storage_Service_VolumeInfoTest_Destroy_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_Destroy_003 start"; + + VolumeInfoMock mock; + std::string volId = "vol-1-5"; + std::string diskId = "disk-1-5"; + dev_t device = MKDEV(1, 5); // 1 is major device number, 5 is minor device number + EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoMount(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoUMount(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoDestroy()).Times(1).WillOnce(testing::Return(E_OK)); + + auto ret = mock.Create(volId, diskId, device); + EXPECT_TRUE(ret == E_OK); + + ret = mock.Check(); + EXPECT_TRUE(ret == E_OK); + + uint32_t mountFlags = 0; + ret = mock.Mount(mountFlags); + EXPECT_TRUE(ret == E_OK); + + ret = mock.Destroy(); + EXPECT_TRUE(ret == E_OK); + ret = mock.Destroy(); + EXPECT_TRUE(ret == E_OK); + + StorageTestUtils::RmDirRecurse("/mnt/external/" + volId); + GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_Destroy_003 end"; +} + /** * @tc.name: Storage_Service_VolumeInfoTest_Mount_001 * @tc.desc: Verify the Mount function when mount state is incorrect. @@ -192,6 +231,40 @@ HWTEST_F(VolumeInfoTest, Storage_Service_VolumeInfoTest_Mount_003, TestSize.Leve GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_Mount_003 end"; } +/** + * @tc.name: Storage_Service_VolumeInfoTest_Mount_004 + * @tc.desc: Verify the Mount function when args are normal. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeInfoTest, Storage_Service_VolumeInfoTest_Mount_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_Mount_004 start"; + + VolumeInfoMock mock; + std::string volId = "vol-1-8"; + std::string diskId = "disk-1-8"; + dev_t device = MKDEV(1, 8); // 1 is major device number, 8 is minor device number + EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoMount(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + + auto ret = mock.Create(volId, diskId, device); + EXPECT_TRUE(ret == E_OK); + + ret = mock.Check(); + EXPECT_TRUE(ret == E_OK); + + uint32_t mountFlags = 0; + ret = mock.Mount(mountFlags); + EXPECT_TRUE(ret == E_OK); + ret = mock.Mount(mountFlags); + EXPECT_TRUE(ret == E_OK); + + StorageTestUtils::RmDirRecurse("/mnt/external/" + volId); + GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_Mount_004 end"; +} + /** * @tc.name: Storage_Service_ExternalVolumeInfoTest_UMount_001 * @tc.desc: Verify the UMount function when mount state is incorrect. @@ -225,9 +298,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_UMount_002, Test GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_UMount_002 start"; VolumeInfoMock mock; - std::string volId = "vol-1-8"; - std::string diskId = "disk-1-8"; - dev_t device = MKDEV(1, 8); // 1 is major device number, 8 is minor device number + std::string volId = "vol-1-9"; + std::string diskId = "disk-1-9"; + dev_t device = MKDEV(1, 9); // 1 is major device number, 9 is minor device number uint32_t mountFlags = 0; bool force = true; @@ -250,6 +323,75 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_UMount_002, Test GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_UMount_002 end"; } +/** + * @tc.name: Storage_Service_ExternalVolumeInfoTest_UMount_003 + * @tc.desc: Verify the UMount function when args are normal. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_UMount_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_UMount_003 start"; + + VolumeInfoMock mock; + std::string volId = "vol-1-10"; + std::string diskId = "disk-1-10"; + dev_t device = MKDEV(1, 10); // 1 is major device number, 10 is minor device number + bool force = true; + + EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); + + auto ret = mock.Create(volId, diskId, device); + EXPECT_TRUE(ret == E_OK); + ret = mock.Check(); + EXPECT_TRUE(ret == E_OK); + + ret = mock.UMount(force); + EXPECT_TRUE(ret == E_OK); + + ret = mock.UMount(force); + EXPECT_TRUE(ret == E_OK); + + StorageTestUtils::RmDirRecurse("/mnt/external/" + volId); + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_UMount_003 end"; +} + +/** + * @tc.name: Storage_Service_ExternalVolumeInfoTest_UMount_003 + * @tc.desc: Verify the UMount function when args are normal. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_UMount_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_UMount_004 start"; + + VolumeInfoMock mock; + std::string volId = "vol-1-11"; + std::string diskId = "disk-1-11"; + dev_t device = MKDEV(1, 11); // 1 is major device number, 11 is minor device number + bool force = false; + + EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoMount(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoUMount(testing::_)).Times(1).WillOnce(testing::Return(E_ERR)); + + auto ret = mock.Create(volId, diskId, device); + EXPECT_TRUE(ret == E_OK); + ret = mock.Check(); + EXPECT_TRUE(ret == E_OK); + ret = mock.Mount(force); + EXPECT_TRUE(ret == E_OK); + + ret = mock.UMount(force); + EXPECT_TRUE(ret == E_ERR); + + StorageTestUtils::RmDirRecurse("/mnt/external/" + volId); + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_UMount_004 end"; +} + /** * @tc.name: Storage_Service_ExternalVolumeInfoTest_Check_001 * @tc.desc: Verify the Check function when mount state is incorrect. @@ -282,9 +424,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_Check_002, TestS GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_Check_002 start"; VolumeInfoMock mock; - std::string volId = "vol-1-9"; - std::string diskId = "disk-1-9"; - dev_t device = MKDEV(1, 9); // 1 is major device number, 9 is minor device number + std::string volId = "vol-1-12"; + std::string diskId = "disk-1-12"; + dev_t device = MKDEV(1, 12); // 1 is major device number, 12 is minor device number EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); @@ -297,6 +439,31 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_Check_002, TestS GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_Check_002 end"; } +/** + * @tc.name: Storage_Service_ExternalVolumeInfoTest_Check_003 + * @tc.desc: Verify the Check function when args are normal. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_Check_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_Check_003 start"; + + VolumeInfoMock mock; + std::string volId = "vol-1-13"; + std::string diskId = "disk-1-13"; + dev_t device = MKDEV(1, 13); // 1 is major device number, 13 is minor device number + + EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_ERR)); + + auto ret = mock.Create(volId, diskId, device); + EXPECT_TRUE(ret == E_OK); + ret = mock.Check(); + EXPECT_TRUE(ret == E_ERR); + + GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_Check_003 end"; +} /** * @tc.name: Storage_Service_ExternalVolumeInfoTest_Format_001 * @tc.desc: Verify the Format function when mount state is incorrect. @@ -308,9 +475,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_Format_001, Test GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_Format_001 start"; LOGI("Storage_Service_ExternalVolumeInfoTest_Format_001 start"); VolumeInfoMock mock; - std::string volId = "vol-1-10"; - std::string diskId = "disk-1-10"; - dev_t device = MKDEV(1, 10); // 1 is major device number, 10 is minor device number + std::string volId = "vol-1-14"; + std::string diskId = "disk-1-14"; + dev_t device = MKDEV(1, 14); // 1 is major device number, 14 is minor device number EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); @@ -338,9 +505,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_Format_002, Test GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_Format_002 start"; VolumeInfoMock mock; - std::string volId = "vol-1-11"; - std::string diskId = "disk-1-11"; - dev_t device = MKDEV(1, 11); // 1 is major device number, 11 is minor device number + std::string volId = "vol-1-15"; + std::string diskId = "disk-1-15"; + dev_t device = MKDEV(1, 15); // 1 is major device number, 15 is minor device number std::string type = "ext2"; EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); @@ -365,9 +532,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_ExternalVolumeInfoTest_GetXXX_001, Test GTEST_LOG_(INFO) << "Storage_Service_ExternalVolumeInfoTest_GetXXX_001 start"; VolumeInfoMock mock; - std::string volId = "vol-1-12"; - std::string diskId = "disk-1-12"; - dev_t device = MKDEV(1, 12); // 1 is major device number, 12 is minor device number + std::string volId = "vol-1-16"; + std::string diskId = "disk-1-16"; + dev_t device = MKDEV(1, 16); // 1 is major device number, 16 is minor device number EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); auto ret = mock.Create(volId, diskId, device); @@ -391,9 +558,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_VolumeInfoTest_SetVolumeDescription_001 { GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_SetVolumeDescription_001 start"; VolumeInfoMock mock; - std::string volId = "vol-1-13"; - std::string diskId = "disk-1-13"; - dev_t device = MKDEV(1, 13); // 1 is major device number, 13 is minor device number + std::string volId = "vol-1-17"; + std::string diskId = "disk-1-17"; + dev_t device = MKDEV(1, 17); // 1 is major device number, 17 is minor device number EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, DoCheck()).Times(1).WillOnce(testing::Return(E_OK)); @@ -420,9 +587,9 @@ HWTEST_F(VolumeInfoTest, Storage_Service_VolumeInfoTest_SetVolumeDescription_002 { GTEST_LOG_(INFO) << "Storage_Service_VolumeInfoTest_SetVolumeDescription_002 start"; VolumeInfoMock mock; - std::string volId = "vol-1-14"; - std::string diskId = "disk-1-14"; - dev_t device = MKDEV(1, 14); // 1 is major device number, 14 is minor device number + std::string volId = "vol-1-18"; + std::string diskId = "disk-1-18"; + dev_t device = MKDEV(1, 18); // 1 is major device number, 18 is minor device number EXPECT_CALL(mock, DoCreate(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); EXPECT_CALL(mock, DoSetVolDesc(testing::_)).Times(1).WillOnce(testing::Return(E_OK)); diff --git a/services/storage_daemon/volume/test/volume_manager_test.cpp b/services/storage_daemon/volume/test/volume_manager_test.cpp index 06de7111..39ea4a2d 100644 --- a/services/storage_daemon/volume/test/volume_manager_test.cpp +++ b/services/storage_daemon/volume/test/volume_manager_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include +#include #include @@ -20,6 +21,7 @@ #include "storage_service_errno.h" #include "storage_service_log.h" #include "volume/volume_manager.h" +#include "volume_info_mock.h" namespace OHOS { namespace StorageDaemon { @@ -91,6 +93,30 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_CreateVolume_001, GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_CreateVolume_001 end"; } +/** + * @tc.name: Storage_Service_VolumeManagerTest_CreateVolume_002 + * @tc.desc: Verify the CreateVolume function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_CreateVolume_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_CreateVolume_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string diskId = "diskId-1-1"; + dev_t device = MKDEV(1, 1); // 1 is major device number, 1 is minor device number + std::string result = volumeManager->CreateVolume(diskId, device); + std::string res = volumeManager->CreateVolume(diskId, device); + GTEST_LOG_(INFO) << result; + EXPECT_TRUE(res.empty()); + volumeManager->DestroyVolume(result); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_CreateVolume_002 end"; +} + /** * @tc.name: Storage_Service_VolumeManagerTest_DestroyVolume_001 * @tc.desc: Verify the DestroyVolume function. @@ -113,6 +139,26 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_DestroyVolume_001, GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_DestroyVolume_001 end"; } +/** + * @tc.name: Storage_Service_VolumeManagerTest_DestroyVolume_002 + * @tc.desc: Verify the DestroyVolume function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_DestroyVolume_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_DestroyVolume_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string volId = "vol-2-1"; + int32_t result = volumeManager->DestroyVolume(volId); + EXPECT_EQ(result, E_NON_EXIST); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_DestroyVolume_002 end"; +} + /** * @tc.name: Storage_Service_VolumeManagerTest_Check_001 * @tc.desc: Verify the Check function. @@ -137,6 +183,26 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_Check_001, TestSiz GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Check_001 end"; } +/** + * @tc.name: Storage_Service_VolumeManagerTest_Check_002 + * @tc.desc: Verify the Check function not existing situation. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_Check_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Check_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string volId = "vol-2-2"; + int32_t result = volumeManager->Check(volId); + EXPECT_EQ(result, E_NON_EXIST); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Check_002 end"; +} + /** * @tc.name: Storage_Service_VolumeManagerTest_Mount_001 * @tc.desc: Verify the Mount function. @@ -162,6 +228,27 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_Mount_001, TestSiz GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Mount_001 end"; } +/** + * @tc.name: Storage_Service_VolumeManagerTest_Mount_002 + * @tc.desc: Verify the Mount function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_Mount_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Mount_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string volId = "vol-2-3"; + uint32_t flags = 1; // disk type + int32_t result = volumeManager->Mount(volId, flags); + EXPECT_EQ(result, E_NON_EXIST); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Mount_002 end"; +} + /** * @tc.name: Storage_Service_VolumeManagerTest_UMount_001 * @tc.desc: Verify the UMount function. @@ -188,6 +275,30 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_UMount_001, TestSi GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_UMount_001 end"; } +/** + * @tc.name: Storage_Service_VolumeManagerTest_UMount_002 + * @tc.desc: Verify the UMount function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_UMount_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_UMount_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string volId = "vol-2-4"; + uint32_t flags = 1; // disk type + volumeManager->Mount(volId, flags); + int32_t result = volumeManager->UMount(volId); + EXPECT_EQ(result, E_NON_EXIST); + + volumeManager->DestroyVolume(volId); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_UMount_002 end"; +} + /** * @tc.name: Storage_Service_VolumeManagerTest_Format_001 * @tc.desc: Verify the Format function. @@ -213,6 +324,29 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_Format_001, TestSi GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Format_001 end"; } +/** + * @tc.name: Storage_Service_VolumeManagerTest_Format_002 + * @tc.desc: Verify the Format function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_Format_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Format_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string volId = "vol-2-5"; + std::string fsType = "ext2"; + int32_t result = volumeManager->Format(volId, fsType); + EXPECT_EQ(result, E_NON_EXIST); + + volumeManager->DestroyVolume(volId); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_Format_002 end"; +} + /** * @tc.name: Storage_Service_VolumeManagerTest_SetVolumeDescription_001 * @tc.desc: Verify the SetVolumeDescription function. @@ -237,5 +371,28 @@ HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_SetVolumeDescripti GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_SetVolumeDescription_001 end"; } + +/** + * @tc.name: Storage_Service_VolumeManagerTest_SetVolumeDescription_002 + * @tc.desc: Verify the SetVolumeDescription function. + * @tc.type: FUNC + * @tc.require: SR000GGUOT + */ +HWTEST_F(VolumeManagerTest, Storage_Service_VolumeManagerTest_SetVolumeDescription_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_SetVolumeDescription_002 start"; + + VolumeManager *volumeManager = VolumeManager::Instance(); + ASSERT_TRUE(volumeManager != nullptr); + + std::string volId = "vol-2-6"; + string description = "description-1"; + int32_t result = volumeManager->SetVolumeDescription(volId, description); + EXPECT_EQ(result, E_NON_EXIST); + + volumeManager->DestroyVolume(volId); + + GTEST_LOG_(INFO) << "Storage_Service_VolumeManagerTest_SetVolumeDescription_002 end"; +} } // STORAGE_DAEMON } // OHOS diff --git a/services/storage_manager/client/storage_manager_client.cpp b/services/storage_manager/client/storage_manager_client.cpp index 04466f44..280d6260 100644 --- a/services/storage_manager/client/storage_manager_client.cpp +++ b/services/storage_manager/client/storage_manager_client.cpp @@ -39,7 +39,7 @@ sptr StorageManagerClient::GetStorageManagerProxy(void) return iface_cast(object); } -int32_t StorageManagerClient::PrepareAddUser(uint32_t userId, const std::string &volumId, uint32_t flags) +int32_t StorageManagerClient::PrepareAddUser(uint32_t userId, uint32_t flags) { sptr client = GetStorageManagerProxy(); if (client == nullptr) { @@ -50,7 +50,7 @@ int32_t StorageManagerClient::PrepareAddUser(uint32_t userId, const std::string return client->PrepareAddUser(userId, flags); } -int32_t StorageManagerClient::RemoveUser(uint32_t userId, const std::string &volumId, uint32_t flags) +int32_t StorageManagerClient::RemoveUser(uint32_t userId, uint32_t flags) { sptr client = GetStorageManagerProxy(); if (client == nullptr) { diff --git a/services/storage_manager/client/test/BUILD.gn b/services/storage_manager/client/test/BUILD.gn new file mode 100644 index 00000000..4dbfc84c --- /dev/null +++ b/services/storage_manager/client/test/BUILD.gn @@ -0,0 +1,57 @@ +# Copyright (C) 2022 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") + +ROOT_DIR = "//foundation/filemanagement/storage_service/services" + +ohos_unittest("storage_manager_clt_test") { + module_out_path = "filemanagement/storage_service/storage_manager" + + sources = [ + "$ROOT_DIR/storage_manager/client/storage_manager_client.cpp", + "$ROOT_DIR/storage_manager/client/test/get_self_permissions.cpp", + "$ROOT_DIR/storage_manager/client/test/storage_manager_client_test.cpp", + ] + + include_dirs = [ + "$ROOT_DIR/storage_manager/include", + "$ROOT_DIR/common/include", + "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", + "//foundation/systemabilitymgr/samgr/utils/native/include", + ] + + defines = [ + "STORAGE_LOG_TAG = \"StorageManager\"", + "LOG_DOMAIN = 0xD004300", + ] + + deps = [ "//third_party/googletest:gtest_main" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] +} + +group("storage_manager_client_test") { + testonly = true + deps = [ ":storage_manager_clt_test" ] +} diff --git a/services/storage_manager/client/test/get_self_permissions.cpp b/services/storage_manager/client/test/get_self_permissions.cpp new file mode 100644 index 00000000..721e31b8 --- /dev/null +++ b/services/storage_manager/client/test/get_self_permissions.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 "get_self_permissions.h" + +#include + +#include "accesstoken_kit.h" +#include "storage_service_log.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" + +namespace OHOS { +namespace StorageManager { +void PermissionUtilsTest::SetAccessTokenPermission(const std::string &processName, + const std::vector &permission, uint64_t &tokenId) +{ + auto perms = std::make_unique(permission.size()); + for (size_t i = 0; i < permission.size(); i++) { + perms[i] = permission[i].c_str(); + } + + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = permission.size(), + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms.get(), + .acls = nullptr, + .processName = processName.c_str(), + .aplStr = "system_basic", + }; + tokenId = GetAccessTokenId(&infoInstance); + if (tokenId == 0) { + LOGE("Get Acess Token Id Failed"); + return; + } + int ret = SetSelfTokenID(tokenId); + if (ret != 0) { + LOGE("Set Acess Token Id Failed"); + return; + } + ret = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); + if (ret < 0) { + LOGE("Reload Native Token Info Failed"); + return; + } +} +} // namespace StorageManager +} // namespace OHOS + diff --git a/services/storage_manager/client/test/get_self_permissions.h b/services/storage_manager/client/test/get_self_permissions.h new file mode 100644 index 00000000..d248d073 --- /dev/null +++ b/services/storage_manager/client/test/get_self_permissions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 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 GET_SELF_PERMISSIONS_H +#define GET_SELF_PERMISSIONS_H + +#include +#include + +namespace OHOS { +namespace StorageManager { +class PermissionUtilsTest { +public: + static void SetAccessTokenPermission(const std::string &processName, + const std::vector &permission, uint64_t &tokenId); +}; +} // namespace StorageManager +} // namespace OHOS +#endif // GET_SELF_PERMISSIONS_H diff --git a/services/storage_manager/client/test/storage_manager_client_test.cpp b/services/storage_manager/client/test/storage_manager_client_test.cpp new file mode 100644 index 00000000..8a0e8302 --- /dev/null +++ b/services/storage_manager/client/test/storage_manager_client_test.cpp @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2022 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 "client/storage_manager_client.h" +#include "get_self_permissions.h" +#include "ipc/storage_manager.h" +#include "storage_service_errno.h" +#include "storage_service_log.h" +namespace OHOS { +namespace StorageManager { +using namespace std; +using namespace testing::ext; + +class StorageManagerClientTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp(); + void TearDown(); + + StorageManagerClient* storageManagerClient_; +}; + +void StorageManagerClientTest::SetUp() +{ + storageManagerClient_ = new StorageManagerClient(); +} + +void StorageManagerClientTest::TearDown(void) +{ + if (storageManagerClient_ != nullptr) { + delete storageManagerClient_; + storageManagerClient_ = nullptr; + } +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_service_PrepareAddUser_0000 + * @tc.name: Client_manager_service_PrepareAddUser_0000 + * @tc.desc: Test function of PrepareAddUser interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_PrepareAddUser_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_PrepareAddUser_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + vector perms; + perms.push_back("ohos.permission.STORAGE_MANAGER"); + uint64_t tokenId = 0; + PermissionUtilsTest::SetAccessTokenPermission("StorageManagerClientTest", perms, tokenId); + ASSERT_TRUE(tokenId != 0); + + uint32_t userId = 101; + int32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->PrepareAddUser(userId, flag); + GTEST_LOG_(INFO) << ret; + EXPECT_TRUE(ret == E_OK); + + storageManagerClient_->RemoveUser(userId, flag); + GTEST_LOG_(INFO) << "Client_manager_service_PrepareAddUser_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_service_RemoveUser_0000 + * @tc.name: Client_manager_service_RemoveUser_0000 + * @tc.desc: Test function of RemoveUser interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_RemoveUser_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_RemoveUser_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 102; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->PrepareAddUser(userId, flag); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->RemoveUser(userId, flag); + EXPECT_TRUE(ret == E_OK); + GTEST_LOG_(INFO) << "Client_manager_service_RemoveUser_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_service_GenerateUserKeys_0000 + * @tc.name: Client_manager_service_GenerateUserKeys_0000 + * @tc.desc: Test function of GenerateUserKeys interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_GenerateUserKeys_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_GenerateUserKeys_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 103; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->GenerateUserKeys(userId, flag); + EXPECT_TRUE(ret == E_OK); + + storageManagerClient_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "Client_manager_service_GenerateUserKeys_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_service_DeleteUserKeys_0000 + * @tc.name: Client_manager_service_DeleteUserKeys_0000 + * @tc.desc: Test function of DeleteUserKeys interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_DeleteUserKeys_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_DeleteUserKeys_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 104; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->GenerateUserKeys(userId, flag); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->DeleteUserKeys(userId); + EXPECT_TRUE(ret == E_OK); + GTEST_LOG_(INFO) << "Client_manager_service_DeleteUserKeys_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_service_UpdateUserAuth_0000 + * @tc.name: Client_manager_service_UpdateUserAuth_0000 + * @tc.desc: Test function of UpdateUserAuth interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_UpdateUserAuth_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_UpdateUserAuth_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 105; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->PrepareAddUser(userId, flag); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->UpdateUserAuth(userId, {}, {}, {}); + EXPECT_TRUE(ret == E_OK) << "UpdateUserAuth error"; + + storageManagerClient_->RemoveUser(userId, flag); + GTEST_LOG_(INFO) << "Client_manager_service_UpdateUserAuth_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_serviceActiveUserKey_0000 + * @tc.name: Client_manager_service_ActiveUserKey_0000 + * @tc.desc: Test function of ActiveUserKey interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_ActiveUserKey_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_ActiveUserKey_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 106; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->GenerateUserKeys(userId, flag); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->ActiveUserKey(userId, {}, {}); + EXPECT_TRUE(ret == E_OK); + + storageManagerClient_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "Client_manager_service_ActiveUserKey_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_InactiveUserKey_0000 + * @tc.name: Client_manager_service_InactiveUserKey_0000 + * @tc.desc: Test function of InactiveUserKey interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_InactiveUserKey_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_InactiveUserKey_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 107; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->GenerateUserKeys(userId, flag); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->ActiveUserKey(userId, {}, {}); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->InactiveUserKey(userId); + EXPECT_TRUE(ret == E_OK); + + storageManagerClient_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "Client_manager_service_InactiveUserKey_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Client_manager_UpdateKeyContext_0000 + * @tc.name: Client_manager_service_UpdateKeyContext_0000 + * @tc.desc: Test function of UpdateKeyContext interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(StorageManagerClientTest, Client_manager_service_UpdateKeyContext_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageManagerClientTest-begin Client_manager_service_UpdateKeyContext_0000"; + + ASSERT_TRUE(storageManagerClient_ != nullptr); + + uint32_t userId = 108; + uint32_t flag = CRYPTO_FLAG_EL2; + int32_t ret = storageManagerClient_->GenerateUserKeys(userId, flag); + EXPECT_TRUE(ret == E_OK); + + ret = storageManagerClient_->UpdateUserAuth(userId, {}, {}, {}); + EXPECT_TRUE(ret == E_OK) << "UpdateUserAuth error"; + + ret = storageManagerClient_->UpdateKeyContext(userId); + EXPECT_TRUE(ret == E_OK); + + storageManagerClient_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "Client_manager_service_UpdateKeyContext_0000 end"; +} +} +} diff --git a/services/storage_manager/crypto/test/BUILD.gn b/services/storage_manager/crypto/test/BUILD.gn new file mode 100644 index 00000000..371c2778 --- /dev/null +++ b/services/storage_manager/crypto/test/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (C) 2022 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") + +ROOT_DIR = + "//foundation/filemanagement/storage_service/services/storage_manager" + +ohos_unittest("crypto_manager_service_test") { + module_out_path = "filemanagement/storage_service/storage_manager" + + sources = [ + "$ROOT_DIR/crypto/filesystem_crypto.cpp", + "$ROOT_DIR/crypto/test/filesystem_crypto_test.cpp", + "$ROOT_DIR/storage_daemon_communication/src/storage_daemon_communication.cpp", + ] + + include_dirs = [ + "$ROOT_DIR/include", + "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", + "//foundation/filemanagement/storage_service/services/common/include", + "//foundation/filemanagement/storage_service/services/storage_daemon/include", + ] + + defines = [ + "STORAGE_LOG_TAG = \"StorageManager\"", + "LOG_DOMAIN = 0xD004300", + ] + + deps = [ "//third_party/googletest:gtest_main" ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] +} + +group("storage_manager_crypto_test") { + testonly = true + deps = [ ":crypto_manager_service_test" ] +} diff --git a/services/storage_manager/crypto/test/filesystem_crypto_test.cpp b/services/storage_manager/crypto/test/filesystem_crypto_test.cpp new file mode 100644 index 00000000..27d70447 --- /dev/null +++ b/services/storage_manager/crypto/test/filesystem_crypto_test.cpp @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2022 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 "crypto/filesystem_crypto.h" +#include "storage_service_errno.h" +#include "storage_service_log.h" +namespace OHOS { +namespace StorageManager { +using namespace testing::ext; + +class FileSystemCryptoTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_GenerateUserKeys_0000 + * @tc.name: Storage_manager_crypto_GenerateUserKeys_0000 + * @tc.desc: Test function of GenerateUserKeys interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_GenerateUserKeys_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_GenerateUserKeys_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 108; + uint32_t flags = 2; // UserKeys type + uint32_t result = fileSystemCrypto_->GenerateUserKeys(userId, flags); + EXPECT_EQ(result, E_OK); + + fileSystemCrypto_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_GenerateUserKeys_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_GenerateUserKeys_0001 + * @tc.name: Storage_manager_crypto_GenerateUserKeys_0001 + * @tc.desc: Test function of GenerateUserKeys interface for Parameters ERROR which userId not in [101, 1099]. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_GenerateUserKeys_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_GenerateUserKeys_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 9999; + uint32_t flags = 2; // UserKeys type + uint32_t ret = fileSystemCrypto_->GenerateUserKeys(userId, flags); + EXPECT_EQ(ret, E_USERID_RANGE); + + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_GenerateUserKeys_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_DeleteUserKeys_0000 + * @tc.name: Storage_manager_crypto_DeleteUserKeys_0000 + * @tc.desc: Test function of DeleteUserKeys interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_DeleteUserKeys_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_DeleteUserKeys_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 109; + uint32_t flags = 2; // UserKeys type + uint32_t result = fileSystemCrypto_->GenerateUserKeys(userId, flags); + EXPECT_EQ(result, E_OK); + + fileSystemCrypto_->DeleteUserKeys(userId); + EXPECT_EQ(result, E_OK); + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_DeleteUserKeys_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_DeleteUserKeys_0001 + * @tc.name: Storage_manager_crypto_DeleteUserKeys_0001 + * @tc.desc: Test function of DeleteUserKeys interface for Parameters ERROR which userId not in [101, 1099]. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_DeleteUserKeys_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_DeleteUserKeys_0001"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 9999; + uint32_t ret = fileSystemCrypto_->DeleteUserKeys(userId); + EXPECT_EQ(ret, E_USERID_RANGE); + + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_DeleteUserKeys_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_UpdateUserAuth_0000 + * @tc.name: Storage_manager_crypto_UpdateUserAuth_0000 + * @tc.desc: Test function of UpdateUserAuth interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_UpdateUserAuth_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_UpdateUserAuth_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 110; + uint32_t flags = 2; // UserKeys type + uint32_t result = fileSystemCrypto_->GenerateUserKeys(userId, flags); + EXPECT_EQ(result, E_OK); + result = fileSystemCrypto_->UpdateUserAuth(userId, {}, {}, {}); + EXPECT_EQ(result, E_OK); + + fileSystemCrypto_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_UpdateUserAuth_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_UpdateUserAuth_0001 + * @tc.name: Storage_manager_crypto_UpdateUserAuth_0001 + * @tc.desc: Test function of UpdateUserAuth interface for Parameters ERROR which userId not in [101, 1099]. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_UpdateUserAuth_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_UpdateUserAuth_0001"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 9999; + uint32_t ret = fileSystemCrypto_->UpdateUserAuth(userId, {}, {}, {}); + EXPECT_EQ(ret, E_USERID_RANGE); + + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_UpdateUserAuth_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_ActiveUserKey_0000 + * @tc.name: Storage_manager_crypto_ActiveUserKey_0000 + * @tc.desc: Test function of ActiveUserKey interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_ActiveUserKey_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_ActiveUserKey_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 111; + uint32_t flags = 2; // UserKeys type + uint32_t result = fileSystemCrypto_->GenerateUserKeys(userId, flags); + EXPECT_EQ(result, E_OK); + result = fileSystemCrypto_->ActiveUserKey(userId, {}, {}); + EXPECT_EQ(result, E_OK); + + fileSystemCrypto_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_ActiveUserKey_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_ActiveUserKey_0001 + * @tc.name: Storage_manager_crypto_ActiveUserKey_0001 + * @tc.desc: Test function of ActiveUserKey interface for Parameters ERROR which userId not in [101, 1099]. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_ActiveUserKey_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_ActiveUserKey_0001"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 9999; + uint32_t ret = fileSystemCrypto_->ActiveUserKey(userId, {}, {}); + EXPECT_EQ(ret, E_USERID_RANGE); + + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_ActiveUserKey_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_InactiveUserKey_0000 + * @tc.name: Storage_manager_crypto_InactiveUserKey_0000 + * @tc.desc: Test function of InactiveUserKey interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_InactiveUserKey_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_InactiveUserKey_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + int32_t userId = 112; + int32_t flags = 2; // UserKeys type + int32_t ret = fileSystemCrypto_->GenerateUserKeys(userId, flags); + ASSERT_EQ(ret, E_OK); + + ret = fileSystemCrypto_->ActiveUserKey(userId, {}, {}); + EXPECT_EQ(ret, E_OK); + + ret = fileSystemCrypto_->InactiveUserKey(userId); + EXPECT_EQ(ret, E_OK); + + fileSystemCrypto_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_InactiveUserKey_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_InactiveUserKey_0001 + * @tc.name: Storage_manager_crypto_InactiveUserKey_0001 + * @tc.desc: Test function of InactiveUserKey interface for Parameters ERROR which userId not in [101, 1099]. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_InactiveUserKey_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_InactiveUserKey_0001"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 9999; + uint32_t ret = fileSystemCrypto_->InactiveUserKey(userId); + EXPECT_EQ(ret, E_USERID_RANGE); + + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_InactiveUserKey_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_UpdateKeyContext_0000 + * @tc.name: Storage_manager_crypto_UpdateKeyContext_0000 + * @tc.desc: Test function of UpdateKeyContext interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_UpdateKeyContext_0000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_UpdateKeyContext_0000"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + int32_t userId = 113; + int32_t flags = 2; // UserKeys type + int32_t ret = fileSystemCrypto_->GenerateUserKeys(userId, flags); + ASSERT_EQ(ret, E_OK); + + ret = fileSystemCrypto_->UpdateUserAuth(userId, {}, {}, {}); + EXPECT_EQ(ret, E_OK); + + ret = fileSystemCrypto_->UpdateKeyContext(userId); + EXPECT_EQ(ret, E_OK); + + fileSystemCrypto_->DeleteUserKeys(userId); + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_UpdateKeyContext_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_manager_crypto_UpdateKeyContext_0001 + * @tc.name: Storage_manager_crypto_UpdateKeyContext_0001 + * @tc.desc: Test function of UpdateKeyContext interface for Parameters ERROR which userId not in [101, 1099]. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(FileSystemCryptoTest, Storage_manager_crypto_UpdateKeyContext_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileSystemCryptoTest-start Storage_manager_crypto_UpdateKeyContext_0001"; + std::shared_ptr fileSystemCrypto_ = + DelayedSingleton::GetInstance(); + uint32_t userId = 9999; + uint32_t ret = fileSystemCrypto_->UpdateKeyContext(userId); + EXPECT_EQ(ret, E_USERID_RANGE); + + GTEST_LOG_(INFO) << "FileSystemCryptoTest-end Storage_manager_crypto_UpdateKeyContext_0001"; +} +} +} \ No newline at end of file diff --git a/services/storage_manager/disk/test/disk_manager_service_test.cpp b/services/storage_manager/disk/test/disk_manager_service_test.cpp index 5eabd7b0..75ab411d 100644 --- a/services/storage_manager/disk/test/disk_manager_service_test.cpp +++ b/services/storage_manager/disk/test/disk_manager_service_test.cpp @@ -17,7 +17,8 @@ #include #include "disk/disk_manager_service.h" - +#include "storage_service_errno.h" +#include "storage_service_log.h" namespace { using namespace std; using namespace OHOS; @@ -49,13 +50,50 @@ HWTEST_F(DiskManagerServiceTest, Disk_manager_service_OnDiskCreated_0000, testin std::string sysPath = "/"; std::string vendor = "vendor-1"; int32_t flag = 1; + std::shared_ptr result; Disk disk(diskId, sizeBytes, sysPath, vendor, flag); if (dmService != nullptr) { dmService->OnDiskCreated(disk); + result = dmService->GetDiskById(diskId); + dmService->OnDiskDestroyed(diskId); } + + EXPECT_NE(result, nullptr); GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_OnDiskCreated_0000"; } +/** + * @tc.number: SUB_STORAGE_Disk_manager_service_OnDiskCreated_0001 + * @tc.name: Disk_manager_service_OnDiskCreated_0001 + * @tc.desc: Test function of OnDiskCreated interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(DiskManagerServiceTest, Disk_manager_service_OnDiskCreated_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_OnDiskCreated_0001"; + std::shared_ptr dmService = + DelayedSingleton::GetInstance(); + std::string diskId = "diskId-1-2"; + int64_t sizeBytes = 1024; + std::string sysPath = "/"; + std::string vendor = "vendor-2"; + int32_t flag = 1; + std::shared_ptr result; + Disk disk(diskId, sizeBytes, sysPath, vendor, flag); + if (dmService != nullptr) { + dmService->OnDiskCreated(disk); + dmService->OnDiskCreated(disk); + result = dmService->GetDiskById(diskId); + dmService->OnDiskDestroyed(diskId); + } + + EXPECT_NE(result, nullptr); + GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_OnDiskCreated_0001"; +} + /** * @tc.number: SUB_STORAGE_Disk_manager_service_OnDiskDestroyed_0000 * @tc.name: Disk_manager_service_OnDiskDestroyed_0000 @@ -70,16 +108,52 @@ HWTEST_F(DiskManagerServiceTest, Disk_manager_service_OnDiskDestroyed_0000, test GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_OnDiskDestroyed_0000"; std::shared_ptr dmService = DelayedSingleton::GetInstance(); - std::string diskId = "diskId-1-2"; + std::string diskId = "diskId-1-3"; int64_t sizeBytes = 1024; std::string sysPath = "/"; - std::string vendor = "vendor-2"; + std::string vendor = "vendor-3"; int32_t flag = 1; + std::shared_ptr result; Disk disk(diskId, sizeBytes, sysPath, vendor, flag); if (dmService != nullptr) { dmService->OnDiskCreated(disk); + result = dmService->GetDiskById(diskId); + EXPECT_NE(result, nullptr); dmService->OnDiskDestroyed(diskId); + result = dmService->GetDiskById(diskId); } + + EXPECT_EQ(result, nullptr); + GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_OnDiskDestroyed_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Disk_manager_service_OnDiskDestroyed_0001 + * @tc.name: Disk_manager_service_OnDiskDestroyed_0001 + * @tc.desc: Test function of OnDiskDestroyed interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(DiskManagerServiceTest, Disk_manager_service_OnDiskDestroyed_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_OnDiskDestroyed_0000"; + std::shared_ptr dmService = + DelayedSingleton::GetInstance(); + std::string diskId = "diskId-1-4"; + int64_t sizeBytes = 1024; + std::string sysPath = "/"; + std::string vendor = "vendor-4"; + int32_t flag = 1; + std::shared_ptr result; + Disk disk(diskId, sizeBytes, sysPath, vendor, flag); + if (dmService != nullptr) { + dmService->OnDiskDestroyed(diskId); + result = dmService->GetDiskById(diskId); + } + + EXPECT_EQ(result, nullptr); GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_OnDiskDestroyed_0000"; } @@ -97,21 +171,81 @@ HWTEST_F(DiskManagerServiceTest, Disk_manager_service_GetDiskById_0000, testing: GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_GetDiskById_0000"; std::shared_ptr dmService = DelayedSingleton::GetInstance(); - std::string diskId = "diskId-1-3"; + std::string diskId = "diskId-1-5"; int64_t sizeBytes = 1024; std::string sysPath = "/"; - std::string vendor = "vendor-3"; + std::string vendor = "vendor-5"; int32_t flag = 1; std::shared_ptr result; Disk disk(diskId, sizeBytes, sysPath, vendor, flag); if (dmService != nullptr) { dmService->OnDiskCreated(disk); result = dmService->GetDiskById(diskId); + dmService->OnDiskDestroyed(diskId); } EXPECT_NE(result, nullptr); GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_GetDiskById_0000"; } +/** + * @tc.number: SUB_STORAGE_Disk_manager_service_GetDiskById_0001 + * @tc.name: Disk_manager_service_GetDiskById_0001 + * @tc.desc: Test function of GetDiskById interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(DiskManagerServiceTest, Disk_manager_service_GetDiskById_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_GetDiskById_0001"; + std::shared_ptr dmService = + DelayedSingleton::GetInstance(); + std::string diskId = "diskId-1-6"; + int64_t sizeBytes = 1024; + std::string sysPath = "/"; + std::string vendor = "vendor-6"; + int32_t flag = 1; + int32_t result; + Disk disk(diskId, sizeBytes, sysPath, vendor, flag); + if (dmService != nullptr) { + dmService->OnDiskCreated(disk); + result = dmService->GetDiskById(diskId, disk); + dmService->OnDiskDestroyed(diskId); + } + EXPECT_EQ(result, E_OK); + GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_GetDiskById_0001"; +} + +/** + * @tc.number: SUB_STORAGE_Disk_manager_service_GetDiskById_0002 + * @tc.name: Disk_manager_service_GetDiskById_0002 + * @tc.desc: Test function of GetDiskById interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(DiskManagerServiceTest, Disk_manager_service_GetDiskById_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_GetDiskById_0002"; + std::shared_ptr dmService = + DelayedSingleton::GetInstance(); + std::string diskId = "diskId-1-7"; + std::string diskId_1 = "diskId-1-11"; + int64_t sizeBytes = 1024; + std::string sysPath = "/"; + std::string vendor = "vendor-7"; + int32_t flag = 1; + int32_t result; + Disk disk(diskId, sizeBytes, sysPath, vendor, flag); + if (dmService != nullptr) { + result = dmService->GetDiskById(diskId_1, disk); + } + EXPECT_EQ(result, E_NON_EXIST); + GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_GetDiskById_0002"; +} + /** * @tc.number: SUB_STORAGE_Disk_manager_service_Partition_0000 * @tc.name: Disk_manager_service_Partition_0000 @@ -126,10 +260,10 @@ HWTEST_F(DiskManagerServiceTest, Disk_manager_service_Partition_0000, testing::e GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_Partition_0000"; std::shared_ptr dmService = DelayedSingleton::GetInstance(); - std::string diskId = "diskId-1-4"; + std::string diskId = "diskId-1-8"; int64_t sizeBytes = 1024; std::string sysPath = "/"; - std::string vendor = "vendor-4"; + std::string vendor = "vendor-8"; int32_t flag = 1; int32_t type = 1; int32_t result; @@ -137,11 +271,41 @@ HWTEST_F(DiskManagerServiceTest, Disk_manager_service_Partition_0000, testing::e if (dmService != nullptr) { dmService->OnDiskCreated(disk); result = dmService->Partition(diskId, type); + dmService->OnDiskDestroyed(diskId); } - EXPECT_EQ(0, 0); + EXPECT_EQ(result, E_NON_EXIST); GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_Partition_0000"; } +/** + * @tc.number: SUB_STORAGE_Disk_manager_service_Partition_0001 + * @tc.name: Disk_manager_service_Partition_0001 + * @tc.desc: Test function of Partition interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(DiskManagerServiceTest, Disk_manager_service_Partition_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_Partition_0001"; + std::shared_ptr dmService = + DelayedSingleton::GetInstance(); + std::string diskId = "diskId-1-9"; + int64_t sizeBytes = 1024; + std::string sysPath = "/"; + std::string vendor = "vendor-9"; + int32_t flag = 1; + int32_t type = 1; + int32_t result; + Disk disk(diskId, sizeBytes, sysPath, vendor, flag); + if (dmService != nullptr) { + result = dmService->Partition(diskId, type); + } + EXPECT_EQ(result, E_NON_EXIST); + GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service_Partition_0001"; +} + /** * @tc.number: SUB_STORAGE_Disk_manager_service_GetAllDisks_0000 * @tc.name: Disk_manager_service_GetAllDisks_0000 @@ -156,23 +320,24 @@ HWTEST_F(DiskManagerServiceTest, Disk_manager_service_GetAllDisks_0000, testing: GTEST_LOG_(INFO) << "DiskManagerServiceTest-begin Disk_manager_service_GetAllDisks_0000"; std::shared_ptr dmService = DelayedSingleton::GetInstance(); - std::string diskId = "diskId-1-5"; + std::string diskId = "diskId-1-10"; int64_t sizeBytes = 1024; std::string sysPath = "/"; - std::string vendor = "vendor-5"; + std::string vendor = "vendor-10"; int32_t flag = 1; Disk disk(diskId, sizeBytes, sysPath, vendor, flag); dmService->OnDiskCreated(disk); vector result = dmService->GetAllDisks(); if (result.size() > 0) { - GTEST_LOG_(INFO) << result[0]. GetSizeBytes(); + GTEST_LOG_(INFO) << result[0].GetSizeBytes(); GTEST_LOG_(INFO) << result[0].GetDiskId(); GTEST_LOG_(INFO) << result[0].GetSysPath(); GTEST_LOG_(INFO) << result[0].GetVendor(); GTEST_LOG_(INFO) << result[0].GetFlag(); } EXPECT_GE(result.size(), 0); + dmService->OnDiskDestroyed(diskId); GTEST_LOG_(INFO) << "DiskManagerServiceTest-end Disk_manager_service__0000"; } } // namespace diff --git a/services/storage_manager/include/client/storage_manager_client.h b/services/storage_manager/include/client/storage_manager_client.h index 2d6791b0..12f2a119 100644 --- a/services/storage_manager/include/client/storage_manager_client.h +++ b/services/storage_manager/include/client/storage_manager_client.h @@ -25,8 +25,8 @@ namespace OHOS { namespace StorageManager { class StorageManagerClient { public: - static int32_t PrepareAddUser(uint32_t userId, const std::string &volumId, uint32_t flags); - static int32_t RemoveUser(uint32_t userId, const std::string &volumId, uint32_t flags); + static int32_t PrepareAddUser(uint32_t userId, uint32_t flags); + static int32_t RemoveUser(uint32_t userId, uint32_t flags); static int32_t GenerateUserKeys(uint32_t userId, uint32_t flags); static int32_t DeleteUserKeys(uint32_t userId); static int32_t UpdateUserAuth(uint32_t userId, diff --git a/services/storage_manager/innerkits_impl/test/BUILD.gn b/services/storage_manager/innerkits_impl/test/BUILD.gn index 3d3189ed..c5bcc6cb 100644 --- a/services/storage_manager/innerkits_impl/test/BUILD.gn +++ b/services/storage_manager/innerkits_impl/test/BUILD.gn @@ -104,10 +104,42 @@ ohos_unittest("volume_external_test") { ] } +ohos_unittest("storage_stats_test") { + module_out_path = "filemanagement/storage_service/storage_manager" + + sources = [ + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/bundle_stats.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/storage_stats.cpp", + "bundle_stats_test.cpp", + "storage_stats_test.cpp", + ] + + include_dirs = [ + "//foundation/filemanagement/storage_service/services/storage_daemon/include", + "//foundation/filemanagement/storage_service/services/storage_manager/include", + "//foundation/filemanagement/storage_service/utils/include", + "include", + "//utils/system/safwk/native/include", + "//commonlibrary/c_utils/base/include", + "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", + ] + + deps = [ "//third_party/googletest:gtest_main" ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + group("storage_manager_innerkits_test") { testonly = true deps = [ ":disk_test", + ":storage_stats_test", ":volume_core_test", ":volume_external_test", ] diff --git a/services/storage_manager/innerkits_impl/test/bundle_stats_test.cpp b/services/storage_manager/innerkits_impl/test/bundle_stats_test.cpp new file mode 100644 index 00000000..4dfa42a6 --- /dev/null +++ b/services/storage_manager/innerkits_impl/test/bundle_stats_test.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 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 "bundle_stats.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace StorageManager; +class BundleStatsTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_BUNDLE_STATS_Marshalling_0000 + * @tc.name: Bundle_Stats_Marshalling_0000 + * @tc.desc: Test function of Marshalling interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(BundleStatsTest, Bundle_Stats_Marshalling_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BundleStatsTest-begin Bundle_Stats_Marshalling_0000"; + int64_t appSize = 1001; + int64_t cacheSize = 1002; + int64_t dataSize = 1003; + BundleStats bs(appSize, cacheSize, dataSize); + Parcel parcel; + bs.Marshalling(parcel); + EXPECT_EQ(parcel.ReadInt64(), appSize); + EXPECT_EQ(parcel.ReadInt64(), cacheSize); + EXPECT_EQ(parcel.ReadInt64(), dataSize); + GTEST_LOG_(INFO) << "BundleStatsTest-end Bundle_Stats_Marshalling_0000"; +} + +/** + * @tc.number: SUB_STORAGE_BUNDLE_STATS_Unmarshalling_0000 + * @tc.name: Bundle_Stats_Unmarshalling_0000 + * @tc.desc: Test function of Unmarshalling interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(BundleStatsTest, Bundle_Stats_Unmarshalling_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BundleStatsTest-begin Bundle_Stats_Unmarshalling_0000"; + int64_t appSize = 2001; + int64_t cacheSize = 2002; + int64_t dataSize = 2003; + Parcel parcel; + parcel.WriteInt64(appSize); + parcel.WriteInt64(cacheSize); + parcel.WriteInt64(dataSize); + BundleStats res; + res = *BundleStats::Unmarshalling(parcel); + EXPECT_EQ(res.appSize_, appSize); + EXPECT_EQ(res.cacheSize_, cacheSize); + EXPECT_EQ(res.dataSize_, dataSize); + GTEST_LOG_(INFO) << "BundleStatsTest-end Bundle_Stats_Unmarshalling_0000"; +} +} diff --git a/services/storage_manager/innerkits_impl/test/storage_stats_test.cpp b/services/storage_manager/innerkits_impl/test/storage_stats_test.cpp new file mode 100644 index 00000000..a04a13eb --- /dev/null +++ b/services/storage_manager/innerkits_impl/test/storage_stats_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 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 "storage_stats.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace StorageManager; +class StorageStatsTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_STORAGE_STATS_Marshalling_0000 + * @tc.name: Storage_Stats_Marshalling_0000 + * @tc.desc: Test function of Marshalling interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(StorageStatsTest, Storage_Stats_Marshalling_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageStatsTest-begin Storage_Stats_Marshalling_0000"; + int64_t totalSize = 1001; + int64_t audioSize = 1002; + int64_t videoSize = 1003; + int64_t imageSize = 1004; + int64_t fileSize = 1005; + int64_t appSize = 1006; + StorageStats res(totalSize, audioSize, videoSize, imageSize, fileSize, appSize); + Parcel parcel; + res.Marshalling(parcel); + EXPECT_EQ(parcel.ReadInt64(), totalSize); + EXPECT_EQ(parcel.ReadInt64(), audioSize); + EXPECT_EQ(parcel.ReadInt64(), videoSize); + EXPECT_EQ(parcel.ReadInt64(), imageSize); + EXPECT_EQ(parcel.ReadInt64(), fileSize); + EXPECT_EQ(parcel.ReadInt64(), appSize); + GTEST_LOG_(INFO) << "StorageStatsTest-end Storage_Stats_Marshalling_0000"; +} + +/** + * @tc.number: SUB_STORAGE_STORAGE_STATS_Unmarshalling_0000 + * @tc.name: Storage_Stats_Unmarshalling_0000 + * @tc.desc: Test function of Unmarshalling interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPG + */ +HWTEST_F(StorageStatsTest, Storage_Stats_Unmarshalling_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageStatsTest-begin Storage_Stats_Unmarshalling_0000"; + int64_t totalSize = 2001; + int64_t audioSize = 2002; + int64_t videoSize = 2003; + int64_t imageSize = 2004; + int64_t fileSize = 2005; + int64_t appSize = 2006; + Parcel parcel; + parcel.WriteInt64(totalSize); + parcel.WriteInt64(audioSize); + parcel.WriteInt64(videoSize); + parcel.WriteInt64(imageSize); + parcel.WriteInt64(fileSize); + parcel.WriteInt64(appSize); + StorageStats res; + res = *StorageStats::Unmarshalling(parcel); + EXPECT_EQ(res.total_, totalSize); + EXPECT_EQ(res.audio_, audioSize); + EXPECT_EQ(res.video_, videoSize); + EXPECT_EQ(res.image_, imageSize); + EXPECT_EQ(res.file_, fileSize); + EXPECT_EQ(res.app_, appSize); + GTEST_LOG_(INFO) << "StorageStatsTest-end Storage_Stats_Unmarshalling_0000"; +} +} diff --git a/services/storage_manager/ipc/test/BUILD.gn b/services/storage_manager/ipc/test/BUILD.gn index ee130a20..fbf4243d 100644 --- a/services/storage_manager/ipc/test/BUILD.gn +++ b/services/storage_manager/ipc/test/BUILD.gn @@ -59,7 +59,106 @@ ohos_unittest("storage_manager_proxy_test") { ] } +ohos_unittest("storage_manager_stub_test") { + module_out_path = "filemanagement/storage_service/storage_manager" + + defines = [ + "STORAGE_LOG_TAG = \"StorageManager\"", + "LOG_DOMAIN = 0xD004300", + ] + + include_dirs = [ + "//foundation/filemanagement/storage_service/services/storage_manager/client/test", + "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", + "//foundation/filemanagement/storage_service/services/storage_manager/include", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/test/", + "//foundation/filemanagement/storage_service/services/common/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "//foundation/communication/ipc/interfaces/innerkits/libdbinder/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + + sources = [ + "//foundation/filemanagement/storage_service/services/storage_manager/client/test/get_self_permissions.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/bundle_stats.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/disk.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/storage_stats.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/volume_core.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/volume_external.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/src/storage_manager_proxy.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/src/storage_manager_stub.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/test/storage_manager_stub_test.cpp", + ] + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +ohos_unittest("storage_manager_stub_nonpermission_test") { + module_out_path = "filemanagement/storage_service/storage_manager" + + defines = [ + "STORAGE_LOG_TAG = \"StorageManager\"", + "LOG_DOMAIN = 0xD004300", + ] + + include_dirs = [ + "//foundation/filemanagement/storage_service/services/storage_manager/client/test", + "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", + "//foundation/filemanagement/storage_service/services/storage_manager/include", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/test/", + "//foundation/filemanagement/storage_service/services/common/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "//foundation/communication/ipc/interfaces/innerkits/libdbinder/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + + sources = [ + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/bundle_stats.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/disk.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/storage_stats.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/volume_core.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/src/volume_external.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/src/storage_manager_proxy.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/src/storage_manager_stub.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/ipc/test/storage_manager_stub_noper_test.cpp", + ] + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + group("storage_manager_ipc_test") { testonly = true - deps = [ ":storage_manager_proxy_test" ] + deps = [ + ":storage_manager_proxy_test", + ":storage_manager_stub_nonpermission_test", + ":storage_manager_stub_test", + ] } diff --git a/services/storage_manager/ipc/test/storage_manager_stub_mock.h b/services/storage_manager/ipc/test/storage_manager_stub_mock.h new file mode 100644 index 00000000..e64cbe5a --- /dev/null +++ b/services/storage_manager/ipc/test/storage_manager_stub_mock.h @@ -0,0 +1,67 @@ +/* + * 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 MOCK_STORAGE_MANAGER_STUB_H +#define MOCK_STORAGE_MANAGER_STUB_H + +#include "gmock/gmock.h" + +#include "ipc/storage_manager_stub.h" + +namespace OHOS { +namespace StorageManager { +class StorageManagerStubMock : public StorageManagerStub { +public: + MOCK_METHOD2(PrepareAddUser, int32_t(int32_t, uint32_t)); + MOCK_METHOD2(RemoveUser, int32_t(int32_t, uint32_t)); + MOCK_METHOD1(PrepareStartUser, int32_t(int32_t)); + MOCK_METHOD1(StopUser, int32_t(int32_t)); + + MOCK_METHOD1(GetFreeSizeOfVolume, int64_t(std::string)); + MOCK_METHOD1(GetTotalSizeOfVolume, int64_t(std::string)); + MOCK_METHOD1(GetBundleStats, BundleStats(std::string)); + MOCK_METHOD0(GetSystemSize, int64_t()); + MOCK_METHOD0(GetTotalSize, int64_t()); + MOCK_METHOD0(GetFreeSize, int64_t()); + MOCK_METHOD0(GetUserStorageStats, StorageStats()); + MOCK_METHOD1(GetUserStorageStats, StorageStats(int32_t)); + MOCK_METHOD0(GetCurrentBundleStats, BundleStats()); + + MOCK_METHOD1(NotifyVolumeCreated, int32_t(VolumeCore)); + MOCK_METHOD5(NotifyVolumeMounted, int32_t(std::string, int32_t, std::string, std::string, std::string)); + MOCK_METHOD1(NotifyVolumeDestroyed, int32_t(std::string)); + MOCK_METHOD1(Mount, int32_t(std::string)); + MOCK_METHOD1(Unmount, int32_t(std::string)); + MOCK_METHOD0(GetAllVolumes, std::vector()); + MOCK_METHOD1(NotifyDiskCreated, int32_t(Disk)); + MOCK_METHOD1(NotifyDiskDestroyed, int32_t(std::string)); + MOCK_METHOD2(Partition, int32_t(std::string, int32_t)); + MOCK_METHOD0(GetAllDisks, std::vector()); + MOCK_METHOD2(GetVolumeByUuid, int32_t(std::string, VolumeExternal &)); + MOCK_METHOD2(GetVolumeById, int32_t(std::string, VolumeExternal &)); + MOCK_METHOD2(SetVolumeDescription, int32_t(std::string, std::string)); + MOCK_METHOD2(Format, int32_t(std::string, std::string)); + MOCK_METHOD2(GetDiskById, int32_t(std::string, Disk &)); + + MOCK_METHOD2(GenerateUserKeys, int32_t(uint32_t, uint32_t)); + MOCK_METHOD1(DeleteUserKeys, int32_t(uint32_t)); + MOCK_METHOD4(UpdateUserAuth, int32_t(uint32_t, const std::vector &, + const std::vector &, const std::vector &)); + MOCK_METHOD3(ActiveUserKey, int32_t(uint32_t, const std::vector &, const std::vector &)); + MOCK_METHOD1(InactiveUserKey, int32_t(uint32_t)); + MOCK_METHOD1(UpdateKeyContext, int32_t(uint32_t)); +}; +} // namespace StorageManager +} // namespace OHOS +#endif /* MOCK_STORAGE_MANAGER_STUB_H */ \ No newline at end of file diff --git a/services/storage_manager/ipc/test/storage_manager_stub_noper_test.cpp b/services/storage_manager/ipc/test/storage_manager_stub_noper_test.cpp new file mode 100644 index 00000000..adbbb962 --- /dev/null +++ b/services/storage_manager/ipc/test/storage_manager_stub_noper_test.cpp @@ -0,0 +1,99 @@ +/* + * 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 "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "ipc/storage_manager_proxy.h" +#include "ipc/storage_manager_stub.h" +#include "storage_manager_stub_mock.h" + +#include "storage_service_errno.h" +#include "storage_service_log.h" + +namespace OHOS { +namespace StorageManager { +using namespace testing::ext; + +class StorageManagerStubTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 + * @tc.desc: Verify the OnRemoteRequest function. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 start"; + + int code[] = { + IStorageManager::PREPARE_ADD_USER, + IStorageManager::REMOVE_USER, + IStorageManager::PREPARE_START_USER, + IStorageManager::STOP_USER, + IStorageManager::NOTIFY_VOLUME_CREATED, + IStorageManager::NOTIFY_VOLUME_MOUNTED, + IStorageManager::NOTIFY_VOLUME_DESTROYED, + IStorageManager::MOUNT, + IStorageManager::UNMOUNT, + IStorageManager::NOTIFY_DISK_CREATED, + IStorageManager::NOTIFY_DISK_DESTROYED, + IStorageManager::PARTITION, + IStorageManager::CREATE_USER_KEYS, + IStorageManager::DELETE_USER_KEYS, + IStorageManager::UPDATE_USER_AUTH, + IStorageManager::ACTIVE_USER_KEY, + IStorageManager::INACTIVE_USER_KEY, + IStorageManager::UPDATE_KEY_CONTEXT, + IStorageManager::GET_VOL_BY_UUID, + IStorageManager::GET_VOL_BY_ID, + IStorageManager::SET_VOL_DESC, + IStorageManager::FORMAT, + IStorageManager::GET_DISK_BY_ID, + IStorageManager::GET_TOTAL, + IStorageManager::GET_FREE, + IStorageManager::GET_SYSTEM_SIZE, + IStorageManager::GET_TOTAL_SIZE, + IStorageManager::GET_FREE_SIZE, + IStorageManager::GET_BUNDLE_STATUS, + IStorageManager::GET_CURR_USER_STATS, + IStorageManager::GET_USER_STATS, + IStorageManager::GET_ALL_VOLUMES, + IStorageManager::GET_ALL_DISKS, + }; + + StorageManagerStubMock mock; + + for (auto c : code) { + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + bool bRet = data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet) << "write token error"; + int32_t ret = mock.OnRemoteRequest(c, data, reply, option); + EXPECT_EQ(ret, E_PERMISSION_DENIED); + } + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 end"; +} +} // STORAGE_MANAGER +} // OHOS diff --git a/services/storage_manager/ipc/test/storage_manager_stub_test.cpp b/services/storage_manager/ipc/test/storage_manager_stub_test.cpp new file mode 100644 index 00000000..c4b095f0 --- /dev/null +++ b/services/storage_manager/ipc/test/storage_manager_stub_test.cpp @@ -0,0 +1,335 @@ +/* + * 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 "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "ipc/storage_manager_proxy.h" +#include "ipc/storage_manager_stub.h" +#include "storage_manager_stub_mock.h" +#include "get_self_permissions.h" + +#include "storage_service_errno.h" +#include "storage_service_log.h" + +namespace OHOS { +namespace StorageManager { +using namespace testing::ext; + +namespace { + const int ERROR_CODE = 99999; + int g_code[] = { + IStorageManager::PREPARE_ADD_USER, + IStorageManager::REMOVE_USER, + IStorageManager::PREPARE_START_USER, + IStorageManager::STOP_USER, + IStorageManager::NOTIFY_VOLUME_CREATED, + IStorageManager::NOTIFY_VOLUME_MOUNTED, + IStorageManager::NOTIFY_VOLUME_DESTROYED, + IStorageManager::MOUNT, + IStorageManager::UNMOUNT, + IStorageManager::NOTIFY_DISK_CREATED, + IStorageManager::NOTIFY_DISK_DESTROYED, + IStorageManager::PARTITION, + IStorageManager::CREATE_USER_KEYS, + IStorageManager::DELETE_USER_KEYS, + IStorageManager::UPDATE_USER_AUTH, + IStorageManager::ACTIVE_USER_KEY, + IStorageManager::INACTIVE_USER_KEY, + IStorageManager::UPDATE_KEY_CONTEXT, + IStorageManager::GET_VOL_BY_UUID, + IStorageManager::GET_VOL_BY_ID, + IStorageManager::SET_VOL_DESC, + IStorageManager::FORMAT, + IStorageManager::GET_DISK_BY_ID, + }; + int g_codes[] = { + IStorageManager::GET_TOTAL, + IStorageManager::GET_FREE, + IStorageManager::GET_SYSTEM_SIZE, + IStorageManager::GET_TOTAL_SIZE, + IStorageManager::GET_FREE_SIZE, + IStorageManager::GET_BUNDLE_STATUS, + IStorageManager::GET_CURR_BUNDLE_STATS, + IStorageManager::GET_CURR_USER_STATS, + IStorageManager::GET_USER_STATS, + }; +} + +class StorageManagerStubTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 + * @tc.desc: Verify the OnRemoteRequest function with error descriptor. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 start"; + + std::vector perms; + perms.push_back("ohos.permission.STORAGE_MANAGER"); + perms.push_back("ohos.permission.MOUNT_UNMOUNT_MANAGER"); + perms.push_back("ohos.permission.MOUNT_FORMAT_MANAGER"); + uint64_t tokenId = 0; + PermissionUtilsTest::SetAccessTokenPermission("StorageManagerPxyTest", perms, tokenId); + ASSERT_TRUE(tokenId != 0); + + StorageManagerStubMock mock; + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + bool bRet = data.WriteInterfaceToken(u"error descriptor"); + EXPECT_TRUE(bRet) << "write token error"; + + int32_t ret = mock.OnRemoteRequest(IStorageManager::PREPARE_ADD_USER, data, reply, option); + EXPECT_TRUE(ret == E_PERMISSION_DENIED) << "descriptor error"; + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 end"; +} + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_002 + * @tc.desc: Verify the OnRemoteRequest function with error code. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_002 start"; + + StorageManagerStubMock mock; + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + bool bRet = data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet) << "write token error"; + + int32_t ret = mock.OnRemoteRequest(ERROR_CODE, data, reply, option); + EXPECT_TRUE(ret != E_OK) << "request code error"; + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_002 end"; +} + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_003 + * @tc.desc: Verify the OnRemoteRequest function. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_003 start"; + + StorageManagerStubMock mock; + + EXPECT_CALL(mock, PrepareAddUser(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, RemoveUser(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, PrepareStartUser(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, StopUser(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, NotifyVolumeCreated(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, NotifyVolumeMounted(testing::_, testing::_, testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, NotifyVolumeDestroyed(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Mount(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Unmount(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, NotifyDiskCreated(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, NotifyDiskDestroyed(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Partition(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, GetVolumeByUuid(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, GetVolumeById(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, SetVolumeDescription(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, Format(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, GetDiskById(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, GenerateUserKeys(testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, DeleteUserKeys(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, UpdateUserAuth(testing::_, testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, ActiveUserKey(testing::_, testing::_, testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, InactiveUserKey(testing::_)).WillOnce(testing::Return(E_OK)); + EXPECT_CALL(mock, UpdateKeyContext(testing::_)).WillOnce(testing::Return(E_OK)); + + for (auto c : g_code) { + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + bool bRet = data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet) << "write token error"; + int32_t ret = mock.OnRemoteRequest(c, data, reply, option); + EXPECT_TRUE(ret == E_OK); + EXPECT_TRUE(reply.ReadInt32() == E_OK); + } + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_003 end"; +} + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_004 + * @tc.desc: Verify the OnRemoteRequest function. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_004 start"; + + StorageManagerStubMock mock; + + int64_t bytes = 1024; + BundleStats bs(100, 101, 102); + StorageStats ss(100, 101, 102, 103, 104, 105); + EXPECT_CALL(mock, GetFreeSizeOfVolume(testing::_)).WillOnce(testing::Return(bytes)); + EXPECT_CALL(mock, GetTotalSizeOfVolume(testing::_)).WillOnce(testing::Return(bytes)); + EXPECT_CALL(mock, GetSystemSize()).WillOnce(testing::Return(bytes)); + EXPECT_CALL(mock, GetTotalSize()).WillOnce(testing::Return(bytes)); + EXPECT_CALL(mock, GetFreeSize()).WillOnce(testing::Return(bytes)); + EXPECT_CALL(mock, GetBundleStats(testing::_)).WillOnce(testing::Return(bs)); + EXPECT_CALL(mock, GetCurrentBundleStats()).WillOnce(testing::Return(bs)); + EXPECT_CALL(mock, GetUserStorageStats()).WillOnce(testing::Return(ss)); + EXPECT_CALL(mock, GetUserStorageStats(testing::_)).WillOnce(testing::Return(ss)); + + for (auto c : g_codes) { + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + bool bRet = data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet) << "write token error"; + int32_t ret = mock.OnRemoteRequest(c, data, reply, option); + EXPECT_TRUE(ret == E_OK); + if (c == IStorageManager::GET_BUNDLE_STATUS || c == IStorageManager::GET_CURR_BUNDLE_STATS) { + auto res = *BundleStats::Unmarshalling(reply); + EXPECT_EQ(res.appSize_, bs.appSize_); + EXPECT_EQ(res.cacheSize_, bs.cacheSize_); + EXPECT_EQ(res.dataSize_, bs.dataSize_); + } else if (c == IStorageManager::GET_CURR_USER_STATS || c == IStorageManager::GET_USER_STATS) { + auto res = *StorageStats::Unmarshalling(reply); + EXPECT_EQ(res.total_, ss.total_); + EXPECT_EQ(res.audio_, ss.audio_); + EXPECT_EQ(res.video_, ss.video_); + EXPECT_EQ(res.image_, ss.image_); + EXPECT_EQ(res.file_, ss.file_); + EXPECT_EQ(res.app_, ss.app_); + } else { + EXPECT_TRUE(reply.ReadInt32() == bytes); + } + } + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_004 end"; +} + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_005 + * @tc.desc: Verify the OnRemoteRequest function. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_005 start"; + + StorageManagerStubMock mock; + + VolumeExternal ve; + ve.SetFsType(EXFAT); + std::vector vec1 = {ve}; + std::string diskId = "disk-1-1"; + int64_t size = 0; + std::string sysPath = "/dev/block/sda"; + std::string vendor = "unknown"; + int32_t flag = 0; + Disk disk(diskId, size, sysPath, vendor, flag); + std::vector vec2 = {disk}; + EXPECT_CALL(mock, GetAllVolumes()).WillOnce(testing::Return(vec1)); + EXPECT_CALL(mock, GetAllDisks()).WillOnce(testing::Return(vec2)); + + MessageParcel data1; + MessageParcel reply1; + MessageOption option1(MessageOption::TF_SYNC); + bool bRet1 = data1.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet1) << "write token error"; + int32_t ret1 = mock.OnRemoteRequest(IStorageManager::GET_ALL_VOLUMES, data1, reply1, option1); + EXPECT_TRUE(ret1 == E_OK); + uint32_t size1 = reply1.ReadUint32(); + EXPECT_EQ(size1, 1); + auto res1 = *VolumeExternal::Unmarshalling(reply1); + EXPECT_EQ(ve.GetFsType(), res1.GetFsType()); + + MessageParcel data2; + MessageParcel reply2; + MessageOption option2(MessageOption::TF_SYNC); + bool bRet2 = data2.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet2) << "write token error"; + int32_t ret2 = mock.OnRemoteRequest(IStorageManager::GET_ALL_DISKS, data2, reply2, option2); + EXPECT_TRUE(ret2 == E_OK); + uint32_t size2 = reply2.ReadUint32(); + EXPECT_EQ(size2, 1); + auto res2 = *Disk::Unmarshalling(reply2); + EXPECT_EQ(disk.GetDiskId(), res2.GetDiskId()); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_005 end"; +} + +/** + * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_006 + * @tc.desc: Verify the OnRemoteRequest function. + * @tc.type: FUNC + * @tc.require: AR000GK4HB + */ +HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_006, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_006 start"; + + StorageManagerStubMock mock; + + VolumeExternal ve; + ve.SetFsType(EXFAT); + std::vector vec1; + std::vector vec2; + EXPECT_CALL(mock, GetAllVolumes()).WillOnce(testing::Return(vec1)); + EXPECT_CALL(mock, GetAllDisks()).WillOnce(testing::Return(vec2)); + + MessageParcel data1; + MessageParcel reply1; + MessageOption option1(MessageOption::TF_SYNC); + bool bRet1 = data1.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet1) << "write token error"; + int32_t ret1 = mock.OnRemoteRequest(IStorageManager::GET_ALL_VOLUMES, data1, reply1, option1); + EXPECT_TRUE(ret1 == E_OK); + uint32_t size1 = reply1.ReadUint32(); + EXPECT_EQ(size1, 0); + + MessageParcel data2; + MessageParcel reply2; + MessageOption option2(MessageOption::TF_SYNC); + bool bRet2 = data2.WriteInterfaceToken(StorageManagerProxy::GetDescriptor()); + EXPECT_TRUE(bRet2) << "write token error"; + int32_t ret2 = mock.OnRemoteRequest(IStorageManager::GET_ALL_DISKS, data2, reply2, option2); + EXPECT_TRUE(ret2 == E_OK); + uint32_t size2 = reply2.ReadUint32(); + EXPECT_EQ(size2, 0); + + GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_006 end"; +} +} // STORAGE_MANAGER +} // OHOS diff --git a/services/storage_manager/storage/test/BUILD.gn b/services/storage_manager/storage/test/BUILD.gn index 599e6dd4..00c91912 100644 --- a/services/storage_manager/storage/test/BUILD.gn +++ b/services/storage_manager/storage/test/BUILD.gn @@ -30,10 +30,6 @@ ohos_unittest("storage_total_status_service_test") { "//foundation/filemanagement/storage_service/services/storage_daemon/include", "//foundation/filemanagement/storage_service/services/storage_manager/include", "//foundation/filemanagement/storage_service/utils/include", - "include", - "//third_party/googletest/googlemock/include/gmock", - "//utils/system/safwk/native/include", - "//commonlibrary/c_utils/base/include", ] defines = [ @@ -43,7 +39,6 @@ ohos_unittest("storage_total_status_service_test") { deps = [ "//foundation/bundlemanager/bundle_framework/services/bundlemgr:libbms", - "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -64,7 +59,45 @@ ohos_unittest("storage_total_status_service_test") { ] } +ohos_unittest("volume_storage_status_service_test") { + module_out_path = "filemanagement/storage_service/storage_manager" + + sources = [ + "//foundation/filemanagement/storage_service/services/storage_manager/storage/src/storage_status_service.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/storage/src/volume_storage_status_service.cpp", + "//foundation/filemanagement/storage_service/services/storage_manager/volume/src/volume_manager_service.cpp", + "volume_storage_status_service_test.cpp", + ] + include_dirs = [ + "//foundation/bundlemanager/bundle_framework/services/bundlemgr/include", + "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", + "//foundation/filemanagement/storage_service/services/common/include", + "//foundation/filemanagement/storage_service/services/storage_daemon/include", + "//foundation/filemanagement/storage_service/services/storage_manager/include", + ] + defines = [ + "STORAGE_LOG_TAG = \"StorageManager\"", + "LOG_DOMAIN = 0xD004300", + ] + + deps = [ "//third_party/googletest:gtest_main" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] +} + group("storage_manager_storage_test") { testonly = true - deps = [ ":storage_total_status_service_test" ] + deps = [ + ":storage_total_status_service_test", + ":volume_storage_status_service_test", + ] } diff --git a/services/storage_manager/storage/test/storage_total_status_service_test.cpp b/services/storage_manager/storage/test/storage_total_status_service_test.cpp index 8937553b..4474d70a 100644 --- a/services/storage_manager/storage/test/storage_total_status_service_test.cpp +++ b/services/storage_manager/storage/test/storage_total_status_service_test.cpp @@ -23,7 +23,7 @@ namespace { using namespace std; using namespace OHOS; using namespace StorageManager; -class storage_total_status_service_test : public testing::Test { +class StorageTotalStatusServiceTest : public testing::Test { public: static void SetUpTestCase(void) {}; static void TearDownTestCase() {}; @@ -40,13 +40,13 @@ public: * @tc.level Level 1 * @tc.require: SR000H0372 */ -HWTEST_F(storage_total_status_service_test, Storage_total_status_GetSystemSize_0000, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_GetSystemSize_0000, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_total_status_service_GetSystemSize_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_service_GetSystemSize_0000"; std::shared_ptr service = DelayedSingleton::GetInstance(); int64_t result = service->GetSystemSize(); EXPECT_GE(result, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_total_status_service_GetSystemSize_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_service_GetSystemSize_0000"; } /** @@ -58,13 +58,13 @@ HWTEST_F(storage_total_status_service_test, Storage_total_status_GetSystemSize_0 * @tc.level Level 1 * @tc.require: SR000H0371 */ -HWTEST_F(storage_total_status_service_test, Storage_total_status_GetTotalSize_0000, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_GetTotalSize_0000, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_total_status_service_GetTotalSize_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_service_GetTotalSize_0000"; std::shared_ptr service = DelayedSingleton::GetInstance(); int64_t result = service->GetTotalSize(); EXPECT_GE(result, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_total_status_service_GetTotalSize_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_service_GetTotalSize_0000"; } /** @@ -76,13 +76,13 @@ HWTEST_F(storage_total_status_service_test, Storage_total_status_GetTotalSize_00 * @tc.level Level 1 * @tc.require: SR000H0371 */ -HWTEST_F(storage_total_status_service_test, Storage_total_status_GetFreeSize_0000, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_GetFreeSize_0000, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_total_status_service_GetFreeSize_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_service_GetFreeSize_0000"; std::shared_ptr service = DelayedSingleton::GetInstance(); int64_t result = service->GetFreeSize(); EXPECT_GE(result, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_total_status_service_GetFreeSize_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_service_GetFreeSize_0000"; } /** @@ -94,9 +94,9 @@ HWTEST_F(storage_total_status_service_test, Storage_total_status_GetFreeSize_000 * @tc.level Level 1 * @tc.require: SR000H0371 */ -HWTEST_F(storage_total_status_service_test, Storage_status_GetUserStorageStats_0000, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetUserStorageStats_0000, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_status_service_GetUserStorageStats_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetUserStorageStats_0000"; std::shared_ptr service = DelayedSingleton::GetInstance(); StorageStats result = service->GetUserStorageStats(); EXPECT_GE(result.total_, 0); @@ -105,7 +105,7 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetUserStorageStats_0 EXPECT_GE(result.image_, 0); EXPECT_GE(result.file_, 0); EXPECT_GE(result.app_, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_status_service_GetUserStorageStats_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetUserStorageStats_0000"; } /** @@ -117,9 +117,9 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetUserStorageStats_0 * @tc.level Level 1 * @tc.require: SR000H0371 */ -HWTEST_F(storage_total_status_service_test, Storage_status_GetUserStorageStats_0001, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetUserStorageStats_0001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_status_service_GetUserStorageStats_0001"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetUserStorageStats_0001"; std::shared_ptr service = DelayedSingleton::GetInstance(); int32_t userId = 200; StorageStats result = service->GetUserStorageStats(userId); @@ -129,7 +129,7 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetUserStorageStats_0 EXPECT_GE(result.image_, 0); EXPECT_GE(result.file_, 0); EXPECT_GE(result.app_, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_status_service_GetUserStorageStats_0001"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetUserStorageStats_0001"; } /** @@ -141,9 +141,9 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetUserStorageStats_0 * @tc.level Level 1 * @tc.require: AR000H0F7I */ -HWTEST_F(storage_total_status_service_test, Storage_status_GetBundleStats_0000, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetBundleStats_0000, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_status_service_GetBundleStats_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetBundleStats_0000"; std::shared_ptr service = DelayedSingleton::GetInstance(); string pkgName = "com.test"; BundleStats result = service->GetBundleStats(pkgName); @@ -153,7 +153,7 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetBundleStats_0000, EXPECT_EQ(result.appSize_, 0); EXPECT_EQ(result.cacheSize_, 0); EXPECT_EQ(result.dataSize_, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_status_service_GetBundleStats_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetBundleStats_0000"; } /** @@ -165,9 +165,9 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetBundleStats_0000, * @tc.level Level 1 * @tc.require: AR000H0F7I */ -HWTEST_F(storage_total_status_service_test, Storage_status_GetBundleStats_0001, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetBundleStats_0001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_status_service_GetBundleStats_0001"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetBundleStats_0001"; std::shared_ptr service = DelayedSingleton::GetInstance(); int userId = 100; string pkgName = "com.test"; @@ -178,7 +178,7 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetBundleStats_0001, EXPECT_EQ(result.appSize_, 0); EXPECT_EQ(result.cacheSize_, 0); EXPECT_EQ(result.dataSize_, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_status_service_GetBundleStats_0001"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetBundleStats_0001"; } /** @@ -190,9 +190,9 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetBundleStats_0001, * @tc.level Level 1 * @tc.require: AR000H0F7I */ -HWTEST_F(storage_total_status_service_test, Storage_status_GetCurrentBundleStats_0000, testing::ext::TestSize.Level1) +HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetCurrentBundleStats_0000, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "storage_total_status_service_test-begin Storage_status_service_GetCurrentBundleStats_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetCurrentBundleStats_0000"; std::shared_ptr service = DelayedSingleton::GetInstance(); BundleStats result = service->GetCurrentBundleStats(); GTEST_LOG_(INFO) << result.appSize_; @@ -201,6 +201,24 @@ HWTEST_F(storage_total_status_service_test, Storage_status_GetCurrentBundleStats EXPECT_EQ(result.appSize_, 0); EXPECT_EQ(result.cacheSize_, 0); EXPECT_EQ(result.dataSize_, 0); - GTEST_LOG_(INFO) << "storage_total_status_service_test-end Storage_status_service_GetCurrentBundleStats_0000"; + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetCurrentBundleStats_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Storage_status_service_ResetBundleMgrProxy_0000 + * @tc.name: Storage_total_status_ResetBundleMgrProxy_0000 + * @tc.desc: Test function of ResetBundleMgrProxy interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0F7I + */ +HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_ResetBundleMgrProxy_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_ResetBundleMgrProxy_0000"; + std::shared_ptr service = DelayedSingleton::GetInstance(); + int64_t result = service->ResetBundleMgrProxy(); + EXPECT_GE(result, 0); + GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_ResetBundleMgrProxy_0000"; } } // namespace diff --git a/services/storage_manager/storage/test/volume_storage_status_service_test.cpp b/services/storage_manager/storage/test/volume_storage_status_service_test.cpp new file mode 100644 index 00000000..da5f14d3 --- /dev/null +++ b/services/storage_manager/storage/test/volume_storage_status_service_test.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 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 "storage/volume_storage_status_service.h" + +#include "storage_service_errno.h" +#include "storage/volume_storage_status_service.h" + +namespace { +using namespace std; +using namespace OHOS; +using namespace StorageManager; + +class VolumeStorageStatusServiceTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_STORAGE_Volume_storage_status_service_GetFreeSizeOfVolume_0000 + * @tc.name: Volume_storage_status_service_GetFreeSizeOfVolume_0000 + * @tc.desc: Test function of GetFreeSizeOfVolume interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H0372 + */ +HWTEST_F(VolumeStorageStatusServiceTest, + Volume_storage_status_service_GetFreeSizeOfVolume_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Volume_storage_status_service_GetFreeSizeOfVolume_0000 start"; + std::shared_ptr service = DelayedSingleton::GetInstance(); + string volumeUuid =""; + int64_t result = service->GetFreeSizeOfVolume(volumeUuid); + + EXPECT_EQ(result, E_ERR); + GTEST_LOG_(INFO) << "Volume_storage_status_service_GetFreeSizeOfVolume_0000 end"; +} + +/** + * @tc.number: SUB_STORAGE_Volume_storage_status_service_GetTotalSizeOfVolume_0000 + * @tc.name: Volume_storage_status_service_GetTotalSizeOfVolume_0000 + * @tc.desc: Test function of GetTotalSizeOfVolume interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H0372 + */ +HWTEST_F(VolumeStorageStatusServiceTest, + Volume_storage_status_service_GetTotalSizeOfVolume_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Volume_storage_status_service_GetTotalSizeOfVolume_0000 start"; + std::shared_ptr service = DelayedSingleton::GetInstance(); + string volumeUuid =""; + int64_t result = service->GetTotalSizeOfVolume(volumeUuid); + + EXPECT_EQ(result, E_ERR); + GTEST_LOG_(INFO) << "Volume_storage_status_service_GetTotalSizeOfVolume_0000 end"; +} +} \ No newline at end of file diff --git a/services/storage_manager/storage_daemon_communication/test/storage_daemon_communication_test.cpp b/services/storage_manager/storage_daemon_communication/test/storage_daemon_communication_test.cpp index 7e288144..e9cde000 100644 --- a/services/storage_manager/storage_daemon_communication/test/storage_daemon_communication_test.cpp +++ b/services/storage_manager/storage_daemon_communication/test/storage_daemon_communication_test.cpp @@ -31,7 +31,8 @@ class StorageDaemonCommunicationTest : public testing::Test { public: static void SetUpTestCase(void) { - if (system::GetBoolParameter(FSCRYPT_POLICY_KEY, false)) { + std::string res = system::GetParameter(FSCRYPT_POLICY_KEY, ""); + if (!res.empty()) { g_fscryptEnable = true; } } @@ -425,4 +426,34 @@ HWTEST_F(StorageDaemonCommunicationTest, Daemon_communication_UpdateKeyContext_0 } GTEST_LOG_(INFO) << "StorageDaemonCommunicationTest-end Daemon_communication_UpdateKeyContext_0000 SUCCESS"; } + +/** + * @tc.number: SUB_STORAGE_Daemon_communication_InactiveUserKey_0000 + * @tc.name: Daemon_communication_InactiveUserKey_0000 + * @tc.desc: Test function of InactiveUserKey interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000H0FG3 + */ +HWTEST_F(StorageDaemonCommunicationTest, Daemon_communication_InactiveUserKey_0000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StorageDaemonCommunicationTest-begin Daemon_communication_InactiveUserKey_0000 SUCCESS"; + std::shared_ptr sdCommunication = + DelayedSingleton::GetInstance(); + int32_t result = -1; + uint32_t userId = 109; + if (sdCommunication != nullptr) { + int32_t flags = 3; + result = sdCommunication->PrepareAddUser(userId, flags); + EXPECT_EQ(result, E_OK); + result = sdCommunication->ActiveUserKey(userId, {}, {}); + EXPECT_EQ(result, E_OK); + result = sdCommunication->InactiveUserKey(userId); + EXPECT_EQ(result, E_OK); + sdCommunication->RemoveUser(userId, flags); + } + EXPECT_EQ(result, E_OK); + GTEST_LOG_(INFO) << "StorageDaemonCommunicationTest-end Daemon_communication_InactiveUserKey_0000 SUCCESS"; +} } // namespace \ No newline at end of file diff --git a/services/storage_manager/user/test/multi_user_manager_service_test.cpp b/services/storage_manager/user/test/multi_user_manager_service_test.cpp index e7136867..8786abdb 100644 --- a/services/storage_manager/user/test/multi_user_manager_service_test.cpp +++ b/services/storage_manager/user/test/multi_user_manager_service_test.cpp @@ -31,7 +31,8 @@ class MultiUserManagerServiceTest : public testing::Test { public: static void SetUpTestCase(void) { - if (system::GetBoolParameter(FSCRYPT_POLICY_KEY, false)) { + std::string res = system::GetParameter(FSCRYPT_POLICY_KEY, ""); + if (!res.empty()) { g_fscryptEnable = true; } }; diff --git a/services/storage_manager/volume/test/volume_manager_service_test.cpp b/services/storage_manager/volume/test/volume_manager_service_test.cpp index 05996ad2..74c043c4 100644 --- a/services/storage_manager/volume/test/volume_manager_service_test.cpp +++ b/services/storage_manager/volume/test/volume_manager_service_test.cpp @@ -54,15 +54,42 @@ HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0000, testing::e if (vmService != nullptr) { vmService->OnVolumeCreated(vc); result = vmService->Mount(volumeId); + vmService->OnVolumeDestroyed(volumeId); } - EXPECT_NE(result, E_MOUNT); + EXPECT_EQ(result, E_NON_EXIST); GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0000"; } +/** + * @tc.number: SUB_STORAGE_Volume_manager_service_Mount_0001 + * @tc.name: Volume_manager_service_Mount_0001 + * @tc.desc: Test function of Mount interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Mount_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Mount_0001"; + std::shared_ptr vmService = + DelayedSingleton::GetInstance(); + std::string volumeId = "vol-1-2"; + int32_t fsType = 1; + std::string diskId = "disk-1-2"; + VolumeCore vc(volumeId, fsType, diskId); + int32_t result; + if (vmService != nullptr) { + result = vmService->Mount(volumeId); + } + EXPECT_EQ(result, E_NON_EXIST); + GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Mount_0001"; +} + /** * @tc.number: SUB_STORAGE_Volume_manager_service_Unmount_0000 * @tc.name: Volume_manager_service_Unmount_0000 - * @tc.desc: Test function of Unmount interface for SUCCESS. + * @tc.desc: Test function of Unmount interface for FAILED. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -73,18 +100,46 @@ HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Unmount_0000, testing: GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Unmount_0000"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-2"; + std::string volumeId = "vol-1-3"; int32_t fsType = 1; - std::string diskId = "disk-1-2"; + std::string diskId = "disk-1-3"; + VolumeCore vc(volumeId, fsType, diskId); + int32_t result; + if (vmService != nullptr) { + vc.SetState(VolumeState::MOUNTED); + result = vmService->Unmount(volumeId); + } + EXPECT_EQ(result, E_NON_EXIST); + GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0000"; +} + +/** + * @tc.number: SUB_STORAGE_Volume_manager_service_Unmount_0001 + * @tc.name: Volume_manager_service_Unmount_0001 + * @tc.desc: Test function of Unmount interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000GGUPF + */ +HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_Unmount_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_Unmount_0001"; + std::shared_ptr vmService = + DelayedSingleton::GetInstance(); + std::string volumeId = "vol-1-4"; + int32_t fsType = 1; + std::string diskId = "disk-1-4"; VolumeCore vc(volumeId, fsType, diskId); int32_t result; if (vmService != nullptr) { vc.SetState(VolumeState::MOUNTED); vmService->OnVolumeCreated(vc); result = vmService->Unmount(volumeId); + vmService->OnVolumeDestroyed(volumeId); } - EXPECT_NE(result, E_UMOUNT); - GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0000"; + EXPECT_EQ(result, E_NON_EXIST); + GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_Unmount_0001"; } /** @@ -101,12 +156,13 @@ HWTEST_F(VolumeManagerServiceTest, Volume_manager_service_OnVolumeCreated_0000, GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Volume_manager_service_OnVolumeCreated_0000"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-3"; + std::string volumeId = "vol-1-5"; int type = 1; - std::string diskId = "disk-1-3"; + std::string diskId = "disk-1-5"; VolumeCore vc(volumeId, type, diskId); if (vmService != nullptr) { vmService->OnVolumeCreated(vc); + vmService->OnVolumeDestroyed(volumeId); } GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Volume_manager_service_OnVolumeCreated_0000"; } @@ -172,7 +228,7 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetAllVolumes_0000, tes std::shared_ptr vmService = DelayedSingleton::GetInstance(); std::vector result = vmService->GetAllVolumes(); - EXPECT_NE(result.size(), 0); + EXPECT_EQ(result.size(), 0); GTEST_LOG_(INFO) << "VolumeManagerServiceTest-end Storage_manager_proxy_GetAllVolumes_0000"; } @@ -190,12 +246,12 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeByUuid_0000, t GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeByUuid_0000"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-4"; + std::string volumeId = "vol-1-6"; int32_t fsType = 1; std::string fsUuid = "uuid-1"; std::string path = "/"; std::string description = "description-1"; - std::string diskId = "disk-1-4"; + std::string diskId = "disk-1-6"; VolumeCore vc(volumeId, fsType, diskId); vmService->OnVolumeCreated(vc); vmService->OnVolumeMounted(volumeId, fsType, fsUuid, path, description); @@ -218,9 +274,9 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0000, tes GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0000"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-5"; + std::string volumeId = "vol-1-8"; int32_t fsType = 1; - std::string diskId = "disk-1-5"; + std::string diskId = "disk-1-8"; VolumeCore vc(volumeId, fsType, diskId); vmService->OnVolumeCreated(vc); VolumeExternal ve; @@ -243,7 +299,7 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_GetVolumeById_0001, tes GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_GetVolumeById_0001"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-6"; + std::string volumeId = "vol-1-9"; VolumeExternal ve; int32_t result = vmService->GetVolumeById(volumeId, ve); EXPECT_NE(result, E_OK); @@ -264,9 +320,9 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_SetVolumeDescription_00 GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_SetVolumeDescription_0000"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-7"; + std::string volumeId = "vol-1-10"; int32_t fsType = 1; - std::string diskId = "disk-1-7"; + std::string diskId = "disk-1-10"; VolumeCore vc(volumeId, fsType, diskId); vmService->OnVolumeCreated(vc); std::string fsUuid = "uuid-2"; @@ -290,9 +346,9 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0000, testing::e GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0000"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-8"; + std::string volumeId = "vol-1-11"; int fsType = 1; - std::string diskId = "disk-1-8"; + std::string diskId = "disk-1-11"; VolumeCore vc(volumeId, fsType, diskId); vmService->OnVolumeCreated(vc); string fsTypes = "fs-1"; @@ -312,13 +368,13 @@ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0000, testing::e */ HWTEST_F(VolumeManagerServiceTest, Storage_manager_proxy_Format_0001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0000"; + GTEST_LOG_(INFO) << "VolumeManagerServiceTest-begin Storage_manager_proxy_Format_0001"; std::shared_ptr vmService = DelayedSingleton::GetInstance(); - std::string volumeId = "vol-1-9"; + std::string volumeId = "vol-1-12"; int fsType = 1; std::string fsUuid = "uuid-3"; - std::string diskId = "disk-1-9"; + std::string diskId = "disk-1-12"; VolumeCore vc(volumeId, fsType, diskId, VolumeState::MOUNTED); vmService->OnVolumeCreated(vc); VolumeExternal ve;