add afs testcase

Signed-off-by: lvyuanyuan <lvyuanyuan7@huawei.com>
Change-Id: I872c50fc5c0ac9f624cf1e463c6647ceae7624d3
This commit is contained in:
lvyuanyuan 2024-08-12 16:11:11 +08:00
parent 773c4b5840
commit 7690d4f825
6 changed files with 149 additions and 1 deletions

View File

@ -59,7 +59,7 @@ string FileUri::GetName()
return "";
}
if (posLast == sandboxPath.size()) {
if (posLast == (sandboxPath.size() - 1)) {
return "";
}

View File

@ -106,6 +106,11 @@ namespace OHOS::AppFileService::ModuleFileUri {
FileUri fileUri(fileStr);
string name = fileUri.GetName();
EXPECT_EQ(name, "test.txt");
string fileStr2 = "/data/storage/el2/base/files/test.txt/";
string uri2 = "file://" + BUNDLE_A + fileStr;
FileUri fileUri2(fileStr2);
EXPECT_EQ(fileUri2.GetName(), "");
GTEST_LOG_(INFO) << "FileUriTest-end File_uri_GetName_0000";
}
@ -130,6 +135,10 @@ namespace OHOS::AppFileService::ModuleFileUri {
FileUri fileUri2(uri2);
path = fileUri2.GetPath();
EXPECT_EQ(path, "/Photo/12/IMG_12345_999999");
string uri4 = "file://media/Photo/12/IMG_12345_999999";
FileUri fileUri4(uri4);
EXPECT_EQ(fileUri2.GetPath(), "/Photo/12/IMG_12345_999999");
GTEST_LOG_(INFO) << "FileUriTest-end File_uri_GetPath_0000";
}

View File

@ -104,6 +104,13 @@ HWTEST_F(TarFileTest, SUB_Tar_File_Packet_0100, testing::ext::TestSize.Level1)
bool ret = TarFile::GetInstance().Packet(srcFiles, tarFileName, pkPath, tarMap);
EXPECT_TRUE(tarMap.empty());
EXPECT_FALSE(ret);
TestManager tm("SUB_Tar_File_Packet_0100");
string root = tm.GetRootDirCurTest();
pkPath = root;
ret = TarFile::GetInstance().Packet(srcFiles, tarFileName, pkPath, tarMap);
EXPECT_TRUE(tarMap.empty());
EXPECT_FALSE(ret);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "TarFileTest-an exception occurred by TarFile.";

View File

@ -143,6 +143,7 @@ ohos_unittest("backup_service_test") {
blocklist = "${path_backup}/cfi_blocklist.txt"
}
defines = [ "private=public" ]
use_exceptions = true
}

View File

@ -121,6 +121,30 @@ HWTEST_F(SchedSchedulerTest, SUB_Service_Sched_0100, testing::ext::TestSize.Leve
GTEST_LOG_(INFO) << "SchedSchedulerTest-end SUB_Service_Sched_0100";
}
/**
* @tc.number: SUB_Service_Sched_0200
* @tc.name: SUB_Service_Sched_0200
* @tc.desc: Sched接口,sessionPtr_为空场景
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: I6F3GV
*/
HWTEST_F(SchedSchedulerTest, SUB_Service_Sched_0200, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "SchedSchedulerTest-begin SUB_Service_Sched_0200";
try {
sptr<SchedScheduler> schedPtrNull = sptr(new SchedScheduler(wptr(servicePtr_), nullptr));
schedPtrNull->Sched();
schedPtrNull->ExecutingQueueTasks("test");
EXPECT_TRUE(true);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "SchedSchedulerTest-an exception occurred by Sched.";
}
GTEST_LOG_(INFO) << "SchedSchedulerTest-end SUB_Service_Sched_0200";
}
/**
* @tc.number: SUB_Service_ExecutingQueueTasks_0100
* @tc.name: SUB_Service_ExecutingQueueTasks_0100
@ -168,4 +192,49 @@ HWTEST_F(SchedSchedulerTest, SUB_Service_RemoveExtConn_0100, testing::ext::TestS
}
GTEST_LOG_(INFO) << "SchedSchedulerTest-end SUB_Service_RemoveExtConn_0100";
}
/**
* @tc.number: SUB_Service_TryUnloadServiceTimer_0100
* @tc.name: SUB_Service_TryUnloadServiceTimer_0100
* @tc.desc: TryUnloadServiceTimer
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: I6F3GV
*/
HWTEST_F(SchedSchedulerTest, SUB_Service_TryUnloadServiceTimer_0100, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "SchedSchedulerTest-begin SUB_Service_TryUnloadServiceTimer_0100";
try {
EXPECT_TRUE(schedPtr_ != nullptr);
schedPtr_->TryUnloadServiceTimer(true);
schedPtr_->TryUnloadServiceTimer(false);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "SchedSchedulerTest-an exception occurred by TryUnloadServiceTimer.";
}
GTEST_LOG_(INFO) << "SchedSchedulerTest-end SUB_Service_TryUnloadServiceTimer_0100";
}
/**
* @tc.number: SUB_Service_TryUnloadService_0100
* @tc.name: SUB_Service_TryUnloadServicer_0100
* @tc.desc: TryUnloadService
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: I6F3GV
*/
HWTEST_F(SchedSchedulerTest, SUB_Service_TryUnloadService_0100, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "SchedSchedulerTest-begin SUB_Service_TryUnloadService_0100";
try {
EXPECT_TRUE(schedPtr_ != nullptr);
schedPtr_->TryUnloadService();
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "SchedSchedulerTest-an exception occurred by TryUnloadService.";
}
GTEST_LOG_(INFO) << "SchedSchedulerTest-end SUB_Service_TryUnloadService_0100";
}
} // namespace OHOS::FileManagement::Backup

View File

@ -441,6 +441,43 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0102, testing::ext::TestSize.Level1)
GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppDone_0102";
}
/**
* @tc.number: SUB_Service_ServiceResultReport_0000
* @tc.name: SUB_Service_ServiceResultReport_0000
* @tc.desc: ServiceResultReport
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: I6F3GV
*/
HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ServiceResultReport_0000";
try {
GTEST_LOG_(INFO) << "SUB_Service_ServiceResultReport Branches Start";
string bundleName = "";
EXPECT_TRUE(servicePtr_ != nullptr);
auto ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::FULL_RESTORE, 0);
EXPECT_EQ(ret, BError(BError::Codes::OK));
ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::INCREMENTAL_RESTORE, 0);
EXPECT_EQ(ret, BError(BError::Codes::OK));
ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::FULL_BACKUP, 0);
EXPECT_EQ(ret, BError(BError::Codes::OK));
ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::INCREMENTAL_BACKUP, 0);
EXPECT_EQ(ret, BError(BError::Codes::OK));
ret = servicePtr_->ServiceResultReport("test", static_cast<BackupRestoreScenario>(1000), 0);
EXPECT_EQ(ret, BError(BError::Codes::OK));
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ServiceResultReport.";
}
GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ServiceResultReport_0000";
}
/**
* @tc.number: SUB_Service_LaunchBackupExtension_0100
* @tc.name: SUB_Service_LaunchBackupExtension_0100
@ -945,4 +982,29 @@ HWTEST_F(ServiceTest, SUB_Service_UpdateTimer_0100, testing::ext::TestSize.Level
}
GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_UpdateTimer_0100";
}
/**
* @tc.number: SUB_Service_GetBackupInfoCmdHandle_0100
* @tc.name: SUB_Service_GetBackupInfoCmdHandle_0100
* @tc.desc: GetBackupInfoCmdHandle
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: I8ZIMJ
*/
HWTEST_F(ServiceTest, SUB_Service_GetBackupInfoCmdHandle_0100, testing::ext::TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetBackupInfoCmdHandle_0100";
try {
std::string bundleName = "com.example.app2backup";
std::string result;
EXPECT_TRUE(servicePtr_ != nullptr);
auto ret = servicePtr_->GetBackupInfoCmdHandle(bundleName, result);
EXPECT_TRUE(ret != BError::BackupErrorCode::E_INVAL);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetBackupInfoCmdHandle.";
}
GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetBackupInfoCmdHandle_0100";
}
} // namespace OHOS::FileManagement::Backup