fix tdd according to change of func

Signed-off-by: 张文迪 <zhangwendi3@huawei.com>
This commit is contained in:
张文迪 2022-12-08 12:12:48 +08:00
parent 84e9f10506
commit 2f94dfd64d
12 changed files with 172 additions and 363 deletions

View File

@ -44,7 +44,7 @@ public:
virtual int32_t NotifyVolumeMounted(std::string volumeId, int fsType, std::string fsUuid,
std::string path, std::string description) = 0;
virtual int32_t NotifyVolumeDestroyed(std::string volumeId) = 0;
virtual int32_t Mount(std::string volumeIsd) = 0;
virtual int32_t Mount(std::string volumeId) = 0;
virtual int32_t Unmount(std::string volumeId) = 0;
virtual int32_t GetAllVolumes(std::vector<VolumeExternal> &vecOfVol) = 0;
virtual int32_t NotifyDiskCreated(Disk disk) = 0;

View File

@ -81,14 +81,16 @@ int32_t StorageManager::StopUser(int32_t userId)
int32_t StorageManager::GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize)
{
LOGI("StorageManger::getFreeSizeOfVolume start, volumeUuid: %{public}s", volumeUuid.c_str());
int32_t err = DelayedSingleton<VolumeStorageStatusService>::GetInstance()->GetFreeSizeOfVolume(volumeUuid, freeSize);
std::shared_ptr<VolumeStorageStatusService> volumeStatsManager = DelayedSingleton<VolumeStorageStatusService>::GetInstance();
int32_t err = volumeStatsManager->GetFreeSizeOfVolume(volumeUuid, freeSize);
return err;
}
int32_t StorageManager::GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize)
{
LOGI("StorageManger::getTotalSizeOfVolume start, volumeUuid: %{public}s", volumeUuid.c_str());
int32_t err = DelayedSingleton<VolumeStorageStatusService>::GetInstance()->GetTotalSizeOfVolume(volumeUuid, totalSize);
std::shared_ptr<VolumeStorageStatusService> volumeStatsManager = DelayedSingleton<VolumeStorageStatusService>::GetInstance();
int32_t err = volumeStatsManager->GetTotalSizeOfVolume(volumeUuid, totalSize);
return err;
}

View File

@ -386,10 +386,11 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetFreeSizeOfVolume_0000
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetFreeSizeOfVolume_0000";
std::string volumeUuid = "uuid-1";
int64_t freeSize;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int64_t result = proxy_->GetFreeSizeOfVolume(volumeUuid);
int32_t result = proxy_->GetFreeSizeOfVolume(volumeUuid, freeSize);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << result;
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetFreeSizeOfVolume_0000";
@ -408,10 +409,11 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetTotalSizeOfVolume_000
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetTotalSizeOfVolume_0000";
std::string volumeUuid = "uuid-2";
int64_t totalSize;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int64_t result = proxy_->GetTotalSizeOfVolume(volumeUuid);
int32_t result = proxy_->GetTotalSizeOfVolume(volumeUuid, totalSize);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << result;
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetTotalSizeOfVolume_0000";
@ -430,39 +432,15 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetBundleStats_0000, tes
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetBundleStats_0000";
std::string pkgName = "ohos.acts.storage.volume";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
BundleStats result = proxy->GetBundleStats(pkgName);
GTEST_LOG_(INFO) << result.appSize_;
GTEST_LOG_(INFO) << result.cacheSize_;
GTEST_LOG_(INFO) << result.dataSize_;
BundleStats bundleStats;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int32_t result = proxy_->GetBundleStats(pkgName, bundleStats);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetBundleStats_0000";
}
/**
* @tc.number: SUB_STORAGE_Storage_manager_proxy_GetBundleStats_0001
* @tc.name: Storage_manager_proxy_GetBundleStats_0001
* @tc.desc: Test function of GetBundleStats interface for Parameters ERROR which pkgName is not exist.
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: AR000GK101
*/
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetBundleStats_0001, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetBundleStats_0001";
std::string pkgName = "ohos.acts.storage.zzzz";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
BundleStats result = proxy->GetBundleStats(pkgName);
GTEST_LOG_(INFO) << result.appSize_;
GTEST_LOG_(INFO) << result.cacheSize_;
GTEST_LOG_(INFO) << result.dataSize_;
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetBundleStats_0001";
}
/**
* @tc.number: SUB_STORAGE_Storage_manager_proxy_NotifyVolumeCreated_0000
* @tc.name: Storage_manager_proxy_NotifyVolumeCreated_0001
@ -598,8 +576,9 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetAllVolumes_0000, test
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
std::vector<VolumeExternal> result = proxy_->GetAllVolumes();
EXPECT_EQ(result.size(), 0);
std::vector<VolumeExternal> vecOfVol;
int32_t result = proxy_->GetAllVolumes(vecOfVol);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetAllVolumes_0000";
}
@ -664,7 +643,6 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_Partition_0000, testing:
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
std::string diskId = "disk-1-25";
int32_t type = 1;
int32_t result = proxy_->Partition(diskId, type);
@ -687,8 +665,9 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetAllDisks_0000, testin
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
std::vector<Disk> result = proxy_->GetAllDisks();
EXPECT_EQ(result.size(), 0);
std::vector<Disk> vecOfDisk;
int32_t result = proxy_->GetAllDisks(vecOfDisk);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetAllDisks_0000";
}
@ -704,11 +683,12 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetAllDisks_0000, testin
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetSystemSize_0000, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetSystemSize_0000";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
int64_t result = proxy->GetSystemSize();
EXPECT_GE(result, 0);
int64_t systemSize;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int32_t result = proxy_->GetSystemSize(systemSize);
EXPECT_GE(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetSystemSize_0000";
}
@ -724,11 +704,12 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetSystemSize_0000, test
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetTotalSize_0000, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetTotalSize_0000";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
int64_t result = proxy->GetTotalSize();
EXPECT_GE(result, 0);
int64_t totalSize;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int32_t result = proxy_->GetTotalSize(totalSize);
EXPECT_GE(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetTotalSize_0000";
}
@ -744,11 +725,12 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetTotalSize_0000, testi
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetFreeSize_0000, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetFreeSize_0000";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
int64_t result = proxy->GetFreeSize();
EXPECT_GE(result, 0);
int64_t FreeSize;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int32_t result = proxy_->GetFreeSize(FreeSize);
EXPECT_GE(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetFreeSize_0000";
}
@ -764,16 +746,12 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetFreeSize_0000, testin
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetUserStorageStats_0000, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetUserStorageStats_0000";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
StorageStats result = proxy->GetUserStorageStats();
EXPECT_GE(result.total_, 0);
EXPECT_GE(result.audio_, 0);
EXPECT_GE(result.video_, 0);
EXPECT_GE(result.image_, 0);
EXPECT_GE(result.file_, 0);
EXPECT_GE(result.app_, 0);
StorageStats storageStats;
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int32_t result = proxy_->GetUserStorageStats(storageStats);
EXPECT_GE(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetUserStorageStats_0000";
}
@ -789,46 +767,16 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetUserStorageStats_0000
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetUserStorageStats_0001, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetUserStorageStats_0001";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
StorageStats storageStats;
int32_t userId = 111;
StorageStats result = proxy->GetUserStorageStats(userId);
EXPECT_GE(result.total_, 0);
EXPECT_GE(result.audio_, 0);
EXPECT_GE(result.video_, 0);
EXPECT_GE(result.image_, 0);
EXPECT_GE(result.file_, 0);
EXPECT_GE(result.app_, 0);
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
int32_t result = proxy_->GetUserStorageStats(userId, storageStats);
EXPECT_GE(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetUserStorageStats_0001";
}
/**
* @tc.number: SUB_STORAGE_Storage_manager_proxy_GetUserStorageStats_0002
* @tc.name: Storage_manager_proxy_GetUserStorageStats_0002
* @tc.desc: Test function of GetUserStorageStats interface for Parameters ERROR which userId<0.
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: SR000H0373
*/
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetUserStorageStats_0002, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_GetUserStorageStats_0002";
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
auto proxy = iface_cast<IStorageManager>(remote);
int32_t userId = -100;
StorageStats result = proxy->GetUserStorageStats(userId);
EXPECT_GE(result.total_, 0);
EXPECT_GE(result.audio_, 0);
EXPECT_GE(result.video_, 0);
EXPECT_GE(result.image_, 0);
EXPECT_GE(result.file_, 0);
EXPECT_GE(result.app_, 0);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetUserStorageStats_0002";
}
/**
* @tc.number: SUB_STORAGE_Storage_manager_proxy_GetVolumeByUuid_0000
* @tc.name: Storage_manager_proxy_GetVolumeByUuid_0000
@ -1092,13 +1040,9 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_GetCurrentBundleStats_00
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
.Times(1)
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageManagerServiceMock::InvokeSendRequest));
BundleStats result = proxy_->GetCurrentBundleStats();
GTEST_LOG_(INFO) << result.appSize_;
GTEST_LOG_(INFO) << result.cacheSize_;
GTEST_LOG_(INFO) << result.dataSize_;
EXPECT_EQ(result.appSize_, 0);
EXPECT_EQ(result.cacheSize_, 0);
EXPECT_EQ(result.dataSize_, 0);
BundleStats bundleStats;
int32_t result = proxy_->GetCurrentBundleStats(bundleStats);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_GetCurrentBundleStats_0000";
}
} // namespace

View File

@ -55,53 +55,49 @@ public:
return E_OK;
}
virtual int64_t GetFreeSizeOfVolume(std::string volumeUuid) override
virtual int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) override
{
return E_OK;
}
virtual int64_t GetTotalSizeOfVolume(std::string volumeUuid) override
virtual int32_t GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize) override
{
return E_OK;
}
virtual BundleStats GetBundleStats(std::string pkgName) override
{
BundleStats result;
return result;
}
virtual int64_t GetSystemSize() override
virtual int32_t GetBundleStats(std::string pkgName, BundleStats &bundleStats) override
{
return E_OK;
}
virtual int64_t GetTotalSize() override
virtual int32_t GetSystemSize(int64_t &systemSize) override
{
return E_OK;
}
virtual int64_t GetFreeSize() override
virtual int32_t GetTotalSize(int64_t &totalSize) override
{
return E_OK;
}
virtual StorageStats GetUserStorageStats() override
virtual int32_t GetFreeSize(int64_t &freeSize) override
{
StorageStats result;
return result;
return E_OK;
}
virtual StorageStats GetUserStorageStats(int32_t userId) override
virtual int32_t GetUserStorageStats(StorageStats &storageStats) override
{
StorageStats result;
return result;
return E_OK;
}
virtual BundleStats GetCurrentBundleStats() override
virtual int32_t GetUserStorageStats(int32_t userId, StorageStats &storageStats) override
{
BundleStats result;
return result;
return E_OK;
}
virtual int32_t GetCurrentBundleStats(BundleStats &bundleStats) override
{
return E_OK;
}
virtual int32_t NotifyVolumeCreated(VolumeCore vc) override
@ -130,10 +126,9 @@ public:
return E_OK;
}
virtual std::vector<VolumeExternal> GetAllVolumes() override
virtual int32_t GetAllVolumes(std::vector<VolumeExternal> &vecOfVol) override
{
std::vector<VolumeExternal> result;
return result;
return E_OK;
}
virtual int32_t NotifyDiskCreated(Disk disk) override
@ -151,10 +146,9 @@ public:
return E_OK;
}
virtual std::vector<Disk> GetAllDisks() override
virtual int32_t GetAllDisks(std::vector<Disk> &vecOfDisk) override
{
std::vector<Disk> result;
return result;
return E_OK;
}
virtual int32_t GetVolumeByUuid(std::string fsUuid, VolumeExternal &vc) override

View File

@ -28,26 +28,26 @@ public:
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_METHOD2(GetFreeSizeOfVolume, int32_t(std::string, int64_t &));
MOCK_METHOD2(GetTotalSizeOfVolume, int32_t(std::string, int64_t &));
MOCK_METHOD2(GetBundleStats, int32_t(std::string, BundleStats &));
MOCK_METHOD1(GetSystemSize, int32_t(int64_t &));
MOCK_METHOD1(GetTotalSize, int32_t(int64_t &));
MOCK_METHOD1(GetFreeSize, int32_t(int64_t &));
MOCK_METHOD1(GetUserStorageStats, int32_t(StorageStats &));
MOCK_METHOD2(GetUserStorageStats, int32_t(int32_t, StorageStats &));
MOCK_METHOD1(GetCurrentBundleStats, int32_t(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<VolumeExternal>());
MOCK_METHOD1(GetAllVolumes, int32_t(std::vector<VolumeExternal> &));
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<Disk>());
MOCK_METHOD1(GetAllDisks, int32_t(std::vector<Disk> &));
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));

View File

@ -54,8 +54,6 @@ namespace {
IStorageManager::SET_VOL_DESC,
IStorageManager::FORMAT,
IStorageManager::GET_DISK_BY_ID,
};
int g_codes[] = {
IStorageManager::GET_TOTAL,
IStorageManager::GET_FREE,
IStorageManager::GET_SYSTEM_SIZE,
@ -65,6 +63,8 @@ namespace {
IStorageManager::GET_CURR_BUNDLE_STATS,
IStorageManager::GET_CURR_USER_STATS,
IStorageManager::GET_USER_STATS,
IStorageManager::GET_ALL_VOLUMES,
IStorageManager::GET_ALL_DISKS,
};
}
@ -169,6 +169,17 @@ HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemote
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));
EXPECT_CALL(mock, GetFreeSizeOfVolume(testing::_, testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetTotalSizeOfVolume(testing::_, testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetSystemSize(testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetTotalSize(testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetFreeSize(testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetBundleStats(testing::_, testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetCurrentBundleStats(testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetUserStorageStats(testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetUserStorageStats(testing::_, testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetAllVolumes(testing::_)).WillOnce(testing::Return(E_OK));
EXPECT_CALL(mock, GetAllDisks(testing::_)).WillOnce(testing::Return(E_OK));
for (auto c : g_code) {
MessageParcel data;
@ -183,153 +194,5 @@ HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemote
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<VolumeExternal> 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<Disk> 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<VolumeExternal> vec1;
std::vector<Disk> 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

View File

@ -142,7 +142,6 @@ int32_t StorageStatusService::GetCurrentBundleStats(BundleStats &bundleStats)
int userId = GetCurrentUserId();
LOGD("StorageStatusService::userId is:%d", userId);
std::string pkgName = GetCallingPkgName();
LOGD("StorageStatusService::pkgName is %{public}s", pkgName.c_str());
return GetBundleStats(pkgName, userId, bundleStats);
}

View File

@ -77,7 +77,7 @@ int32_t StorageTotalStatusService::GetFreeSize(int64_t &freeSize)
return GetSizeOfPath(PATH_DATA, SizeType::FREE, freeSize);
}
int32_t StorageTotalStatusService::GetSizeOfPath(const char * path, int32_t type, int64_t &size)
int32_t StorageTotalStatusService::GetSizeOfPath(const char *path, int32_t type, int64_t &size)
{
struct statvfs diskInfo;
int ret = statvfs(path, &diskInfo);

View File

@ -18,6 +18,7 @@
#include "storage/storage_status_service.h"
#include "storage/storage_total_status_service.h"
#include "storage_service_errno.h"
namespace {
using namespace std;
@ -44,8 +45,9 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_GetSystemSize_0000,
{
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_service_GetSystemSize_0000";
std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
int64_t result = service->GetSystemSize();
EXPECT_GE(result, 0);
int64_t systemSize;
int32_t result = service->GetSystemSize(systemSize);
EXPECT_EQ(result, 0);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_service_GetSystemSize_0000";
}
@ -62,8 +64,9 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_GetTotalSize_0000,
{
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_service_GetTotalSize_0000";
std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
int64_t result = service->GetTotalSize();
EXPECT_GE(result, 0);
int64_t totalSize;
int32_t result = service->GetTotalSize(totalSize);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_service_GetTotalSize_0000";
}
@ -80,8 +83,9 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_total_status_GetFreeSize_0000, t
{
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_total_status_service_GetFreeSize_0000";
std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
int64_t result = service->GetFreeSize();
EXPECT_GE(result, 0);
int64_t freeSize;
int32_t result = service->GetFreeSize(freeSize);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_total_status_service_GetFreeSize_0000";
}
@ -98,13 +102,9 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetUserStorageStats_0000,
{
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetUserStorageStats_0000";
std::shared_ptr<StorageStatusService> service = DelayedSingleton<StorageStatusService>::GetInstance();
StorageStats result = service->GetUserStorageStats();
EXPECT_GE(result.total_, 0);
EXPECT_GE(result.audio_, 0);
EXPECT_GE(result.video_, 0);
EXPECT_GE(result.image_, 0);
EXPECT_GE(result.file_, 0);
EXPECT_GE(result.app_, 0);
StorageStats storageStats;
int32_t result = service->GetUserStorageStats(storageStats);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetUserStorageStats_0000";
}
@ -121,14 +121,10 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetUserStorageStats_0001,
{
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetUserStorageStats_0001";
std::shared_ptr<StorageStatusService> service = DelayedSingleton<StorageStatusService>::GetInstance();
int32_t userId = 200;
StorageStats result = service->GetUserStorageStats(userId);
EXPECT_GE(result.total_, 0);
EXPECT_GE(result.audio_, 0);
EXPECT_GE(result.video_, 0);
EXPECT_GE(result.image_, 0);
EXPECT_GE(result.file_, 0);
EXPECT_GE(result.app_, 0);
int32_t userId = 100;
StorageStats storageStats;
int32_t result = service->GetUserStorageStats(userId, storageStats);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetUserStorageStats_0001";
}
@ -146,13 +142,9 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetBundleStats_0000, test
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetBundleStats_0000";
std::shared_ptr<StorageStatusService> service = DelayedSingleton<StorageStatusService>::GetInstance();
string pkgName = "com.test";
BundleStats result = service->GetBundleStats(pkgName);
GTEST_LOG_(INFO) << result.appSize_;
GTEST_LOG_(INFO) << result.cacheSize_;
GTEST_LOG_(INFO) << result.dataSize_;
EXPECT_EQ(result.appSize_, 0);
EXPECT_EQ(result.cacheSize_, 0);
EXPECT_EQ(result.dataSize_, 0);
BundleStats bundleStats;
int32_t result = service->GetBundleStats(pkgName, bundleStats);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetBundleStats_0000";
}
@ -171,20 +163,16 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetBundleStats_0001, test
std::shared_ptr<StorageStatusService> service = DelayedSingleton<StorageStatusService>::GetInstance();
int userId = 100;
string pkgName = "com.test";
BundleStats result = service->GetBundleStats(pkgName, userId);
GTEST_LOG_(INFO) << result.appSize_;
GTEST_LOG_(INFO) << result.cacheSize_;
GTEST_LOG_(INFO) << result.dataSize_;
EXPECT_EQ(result.appSize_, 0);
EXPECT_EQ(result.cacheSize_, 0);
EXPECT_EQ(result.dataSize_, 0);
BundleStats bundleStats;
int32_t result = service->GetBundleStats(pkgName, userId, bundleStats);
EXPECT_EQ(result, E_OK);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetBundleStats_0001";
}
/**
* @tc.number: SUB_STORAGE_Storage_status_service_GetCurrentBundleStats_0000
* @tc.name: Storage_status_service_GetCurrentBundleStats_0000
* @tc.desc: Test function of GetCurrentBundleStats interface for SUCCESS.
* @tc.desc: Test function of GetCurrentBundleStats when caller is not hap.
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
@ -194,13 +182,9 @@ HWTEST_F(StorageTotalStatusServiceTest, Storage_status_GetCurrentBundleStats_000
{
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-begin Storage_status_service_GetCurrentBundleStats_0000";
std::shared_ptr<StorageStatusService> service = DelayedSingleton<StorageStatusService>::GetInstance();
BundleStats result = service->GetCurrentBundleStats();
GTEST_LOG_(INFO) << result.appSize_;
GTEST_LOG_(INFO) << result.cacheSize_;
GTEST_LOG_(INFO) << result.dataSize_;
EXPECT_EQ(result.appSize_, 0);
EXPECT_EQ(result.cacheSize_, 0);
EXPECT_EQ(result.dataSize_, 0);
BundleStats bundleStats;
int32_t result = service->GetCurrentBundleStats(bundleStats);
EXPECT_EQ(result, E_BUNDLEMGR_ERROR);
GTEST_LOG_(INFO) << "StorageTotalStatusServiceTest-end Storage_status_service_GetCurrentBundleStats_0000";
}

View File

@ -48,7 +48,8 @@ HWTEST_F(VolumeStorageStatusServiceTest,
GTEST_LOG_(INFO) << "Volume_storage_status_service_GetFreeSizeOfVolume_0000 start";
std::shared_ptr<VolumeStorageStatusService> service = DelayedSingleton<VolumeStorageStatusService>::GetInstance();
string volumeUuid ="";
int64_t result = service->GetFreeSizeOfVolume(volumeUuid);
int64_t freeSize;
int32_t result = service->GetFreeSizeOfVolume(volumeUuid, freeSize);
EXPECT_EQ(result, E_ERR);
GTEST_LOG_(INFO) << "Volume_storage_status_service_GetFreeSizeOfVolume_0000 end";
@ -69,7 +70,8 @@ HWTEST_F(VolumeStorageStatusServiceTest,
GTEST_LOG_(INFO) << "Volume_storage_status_service_GetTotalSizeOfVolume_0000 start";
std::shared_ptr<VolumeStorageStatusService> service = DelayedSingleton<VolumeStorageStatusService>::GetInstance();
string volumeUuid ="";
int64_t result = service->GetTotalSizeOfVolume(volumeUuid);
int64_t totalSize;
int32_t result = service->GetTotalSizeOfVolume(volumeUuid, totalSize);
EXPECT_EQ(result, E_ERR);
GTEST_LOG_(INFO) << "Volume_storage_status_service_GetTotalSizeOfVolume_0000 end";

View File

@ -80,20 +80,28 @@ bool StorageManagerProxyGetFuzzTest(const uint8_t *data, size_t size)
std::string pkgName((const char *)data, size);
int32_t userId = *(reinterpret_cast<const int32_t *>(data));
std::string fsUuid((const char *)data, size);
getStor.GetAllVolumes();
getStor.GetAllDisks();
getStor.GetSystemSize();
getStor.GetTotalSize();
getStor.GetFreeSize();
getStor.GetUserStorageStats();
getStor.GetBundleStats(pkgName);
getStor.GetCurrentBundleStats();
getStor.GetUserStorageStats(userId);
int64_t systemSize = *(reinterpret_cast<const int64_t *>(data));
int64_t totalSize = *(reinterpret_cast<const int64_t *>(data));
int64_t freeSize = *(reinterpret_cast<const int64_t *>(data));
int64_t freeVolSize = *(reinterpret_cast<const int64_t *>(data));
int64_t totalVolSize = *(reinterpret_cast<const int64_t *>(data));
BundleStats bundleStats;
StorageStats storageStats;
std::vector<VolumeExternal> vecOfVol;
std::vector<Disk> vecOfDisk;
getStor.GetAllVolumes(vecOfVol);
getStor.GetAllDisks(vecOfDisk);
getStor.GetSystemSize(systemSize);
getStor.GetTotalSize(totalSize);
getStor.GetFreeSize(freeSize);
getStor.GetUserStorageStats(storageStats);
getStor.GetBundleStats(pkgName, bundleStats);
getStor.GetCurrentBundleStats(bundleStats);
getStor.GetUserStorageStats(userId, storageStats);
getStor.GetVolumeByUuid(fsUuid, vc1);
getStor.GetVolumeById(volumeUuid, vc1);
getStor.GetFreeSizeOfVolume(volumeUuid);
getStor.GetTotalSizeOfVolume(volumeUuid);
getStor.GetFreeSizeOfVolume(volumeUuid, freeVolSize);
getStor.GetTotalSizeOfVolume(volumeUuid, totalVolSize);
return true;
}

View File

@ -15,6 +15,7 @@
#include "storagetotalstatusservice_fuzzer.h"
#include "storage/storage_total_status_service.h"
#include "storage_service_log.h"
#include "storage_service_errno.h"
namespace OHOS {
namespace StorageManager {
bool StorageTotalStatusServiceFuzzTest(const uint8_t *data, size_t size)
@ -23,16 +24,28 @@ bool StorageTotalStatusServiceFuzzTest(const uint8_t *data, size_t size)
return false;
}
std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
int64_t result = service->GetTotalSize();
service->GetSystemSize();
service->GetFreeSize();
// You can add other interfaces of class StorageTotalStatusService here.
if (result >= 0) {
LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize success!");
return true;
int64_t totalSize;
int64_t systemSize;
int64_t freeSize;
int32_t result = service->GetTotalSize(totalSize);
if (result != E_OK) {
LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize failed!");
return false;
}
LOGE("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize failed!");
return false;
result = service->GetSystemSize(systemSize);
if (result != E_OK) {
LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetSystemSize failed!");
return false;
}
result = service->GetFreeSize(freeSize);
if (result != E_OK) {
LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetFreeSize failed!");
return false;
}
// You can add other interfaces of class StorageTotalStatusService here.
LOGE("Storage total status service fuzz test of interface StorageTotalStatusService: success!");
return true;
}
} // namespace StorageManager
} // namespace OHOS