From dea0bf536cdced106ce5c1827599188cf625e5a9 Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:17:00 +0000 Subject: [PATCH 01/11] update tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp. Signed-off-by: chensihan --- .../b_jsonutil/b_jsonutil_test.cpp | 511 +++++++++++++++++- 1 file changed, 489 insertions(+), 22 deletions(-) diff --git a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp index 936de04fa..09d7926d0 100644 --- a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp +++ b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp @@ -30,6 +30,10 @@ namespace OHOS::FileManagement::Backup { using namespace std; +namespace { +constexpr uint32_t TEST_USER_ID = 100; +} // namespace + class BJsonUtilTest : public testing::Test { public: static void SetUpTestCase(void) {}; @@ -52,8 +56,7 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::T GTEST_LOG_(INFO) << "BJsonUtilTest-begin b_dir_GetDirFiles_0100"; try { std::string bundleName = "com.hos.app01:1"; - std::string pattern = ":"; - BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName, pattern); + BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); EXPECT_EQ("com.hos.app01", detailInfo.bundleName); } catch (...) { EXPECT_TRUE(false); @@ -62,6 +65,29 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::T GTEST_LOG_(INFO) << "BDirTest-end b_dir_GetDirFiles_0100"; } +/** + * @tc.number: b_jsonutil_ParseBundleNameIndexStr_0200 + * @tc.name: b_jsonutil_ParseBundleNameIndexStr_0200 + * @tc.desc: Test function of ParseBundleNameIndexStr interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0200, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin ParseBundleNameIndexStr_0200"; + try { + std::string bundleName = "com.hos.app01"; + BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); + EXPECT_EQ("com.hos.app01", detailInfo.bundleName); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BDirTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BDirTest-end ParseBundleNameIndexStr_0200"; +} + /** * @tc.number: b_jsonutil_BuildBundleInfos_0100 * @tc.name: b_jsonutil_BuildBundleInfos_0100 @@ -77,33 +103,474 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0100, testing::ext::TestSize try { std::vector bundleNames; std::string bundleName = "com.hos.app01:1"; - std::string bundleName1 = "com.hos.app02"; bundleNames.push_back(bundleName); - bundleNames.push_back(bundleName1); - std::string pattern = ":"; - std::vector detailInfos; - std::string detail01 = "{ - "infos" : [ { - "details" : [ { - "detail" : [ { "source" : "com.ohos.app01", "target" : "com.hos.app01" } ], - "type" : "app_mapping_relation" } ], - "type" : "broadcast" } ] - }"; - detailInfos.push_back(detail01); - detailInfos.push_back(""); - int32_t userId = 100; - std::vector realBundleNames; + std::vector bundleInfos; + std::string bundleInfo = "info1"; + std::string bundleInfo2 = "info2"; + bundleInfos.push_back(bundleInfo); + bundleInfos.push_back(bundleInfo2); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; std::map isClearDataFlags; - std::map> bundleNameDetailMap = - BJsonUtil::BuildBundleInfos(bundleNames, detailInfos, realBundleNames, + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_TRUE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0100"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0200 + * @tc.name: b_jsonutil_BuildBundleInfos_0200 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0200, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0200"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = "{\"infos\":\"infos\"}"; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0200"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0300 + * @tc.name: b_jsonutil_BuildBundleInfos_0300 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0300, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0300"; + try { + std::vector bundleNames; + std::string bundleName = "bundle1:"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = "info1"; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_TRUE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0300"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0301 + * @tc.name: b_jsonutil_BuildBundleInfos_0301 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0301, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0301"; + try { + std::vector bundleNames; + std::string bundleName = ":bundle1"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = "info1"; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_TRUE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0301"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0400 + * @tc.name: b_jsonutil_BuildBundleInfos_0400 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0400, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0400"; + try { + std::vector bundleNames; + std::string bundleName = "bundle1"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = { + "{\"infos\":[{\"type\":\"type1\",\"details\":\"details1\"}],\"clearBackupData\": \"false\"}" + }; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, userId, isClearDataFlags); - std::string key = "com.hos.app01"; - EXPECT_EQ("com.hos.app01", bundleNameDetailMap[key].bundleName[0]); + EXPECT_EQ(isClearDataFlags[bundleName], false); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0400"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0500 + * @tc.name: b_jsonutil_BuildBundleInfos_0500 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0500, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0500"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = {"{\"infos\":[{\"type\":null}]}"}; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_EQ(isClearDataFlags[bundleName], true); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0500"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0600 + * @tc.name: b_jsonutil_BuildBundleInfos_0600 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0600, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0600"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = {"{\"infos\":[{\"type\":123}],\"clearBackupData\": \"true\"}"}; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_EQ(isClearDataFlags[bundleName], true); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0600"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0700 + * @tc.name: b_jsonutil_BuildBundleInfos_0700 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0700, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0700"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":null}]}"}; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0700"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0800 + * @tc.name: b_jsonutil_BuildBundleInfos_0800 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0800, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0800"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":[]}]}"}; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0800"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_0900 + * @tc.name: b_jsonutil_BuildBundleInfos_0900 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0900, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0900"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":[\"detail\"]}]}"}; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0900"; +} + +/** + * @tc.number: b_jsonutil_BuildBundleInfos_1000 + * @tc.name: b_jsonutil_BuildBundleInfos_1000 + * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_1000, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_1000"; + try { + std::vector bundleNames; + std::string bundleName = "bundle"; + bundleNames.push_back(bundleName); + std::vector bundleInfos; + std::string bundleInfo = {"{\"infos\":[\"infos\"]}"}; + bundleInfos.push_back(bundleInfo); + int32_t userId = TEST_USER_ID; + std::vector bundleNamesOnly; + std::map isClearDataFlags; + + auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + userId, isClearDataFlags); + EXPECT_FALSE(result.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_1000"; +} + +/** + * @tc.number: b_jsonutil_FindBundleInfoByName_0100 + * @tc.name: b_jsonutil_FindBundleInfoByName_0100 + * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0100"; + try { + std::map> bundleNameDetailsMap; + std::string bundleName = "bundle1"; + std::string jobType = "type"; + BJsonUtil::BundleDetailInfo bundleDetail; + + bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType, bundleDetail); + EXPECT_EQ(false, result); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0100"; +} + +/** + * @tc.number: b_jsonutil_FindBundleInfoByName_0200 + * @tc.name: b_jsonutil_FindBundleInfoByName_0200 + * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0200, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0200"; + try { + std::map> bundleNameDetailsMap; + std::string bundleName = "bundle1"; + std::string jobType = "type"; + BJsonUtil::BundleDetailInfo detailInfo; + detailInfo.bundleName = bundleName; + detailInfo.type = jobType; + bundleNameDetailsMap[bundleName] = {detailInfo}; + BJsonUtil::BundleDetailInfo bundleDetail; + + bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType, bundleDetail); + EXPECT_EQ(true, result); + EXPECT_EQ(bundleDetail.type, detailInfo.type); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0200"; +} + +/** + * @tc.number: b_jsonutil_FindBundleInfoByName_0300 + * @tc.name: b_jsonutil_FindBundleInfoByName_0300 + * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0300, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0300"; + try { + std::map> bundleNameDetailsMap; + std::string bundleName = "bundle1"; + std::string jobType = "type"; + std::string jobType1 = "type1"; + BJsonUtil::BundleDetailInfo detailInfo; + detailInfo.bundleName = bundleName; + detailInfo.type = jobType; + bundleNameDetailsMap[bundleName] = {detailInfo}; + BJsonUtil::BundleDetailInfo bundleDetail; + + bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType1, bundleDetail); + EXPECT_EQ(false, result); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0300"; +} + +/** + * @tc.number: b_jsonutil_BuildExtensionErrInfo_0100 + * @tc.name: b_jsonutil_BuildExtensionErrInfo_0100 + * @tc.desc: Test function of BuildExtensionErrInfo interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0100"; + try { + std::string jsonStr; + int errCode = 1; + std::string errMsg = "error"; + + bool result = BJsonUtil::BuildExtensionErrInfo(jsonStr, errCode, errMsg); + EXPECT_EQ(true, result); + EXPECT_NE(jsonStr.find("errorCode"), std::string::npos); + EXPECT_NE(jsonStr.find("errorInfo"), std::string::npos); + EXPECT_NE(jsonStr.find("type"), std::string::npos); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; } - GTEST_LOG_(INFO) << "BJsonUtilTest-end b_dir_BuildBundleInfos_0100"; + GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildExtensionErrInfo_0100"; } /* * -- Gitee From 0358202c2a812f2142545c1d944ce2f71df1ae46 Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:17:33 +0000 Subject: [PATCH 02/11] update tests/unittests/backup_utils/b_error/b_error_test.cpp. Signed-off-by: chensihan --- .../backup_utils/b_error/b_error_test.cpp | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/unittests/backup_utils/b_error/b_error_test.cpp b/tests/unittests/backup_utils/b_error/b_error_test.cpp index d48c401d7..7a77a1791 100644 --- a/tests/unittests/backup_utils/b_error/b_error_test.cpp +++ b/tests/unittests/backup_utils/b_error/b_error_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -452,4 +452,58 @@ HWTEST_F(BErrorTest, b_error_int_0100, testing::ext::TestSize.Level0) EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "BErrorTest-end b_error_int_0100"; } + +/** + * @tc.number: SUB_backup_b_error_GetCodeByErrno_0100 + * @tc.name: b_error_GetCodeByErrno_0100 + * @tc.desc: Test function of int interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCodeByErrno_0100"; + int32_t errnoSys = 0; + int result = BError::GetCodeByErrno(errnoSys); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "BErrorTest-end b_error_GetCodeByErrno_0100"; +} + +/** + * @tc.number: SUB_backup_b_error_GetCodeByErrno_0200 + * @tc.name: b_error_GetCodeByErrno_0200 + * @tc.desc: Test function of int interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0200, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCodeByErrno_0200"; + int32_t errnoSys = EPERM; + int result = BError::GetCodeByErrno(errnoSys); + EXPECT_EQ(result, BError::BackupErrorCode::E_PERM); + GTEST_LOG_(INFO) << "BErrorTest-end b_error_GetCodeByErrno_0200"; +} + +/** + * @tc.number: SUB_backup_b_error_GetCodeByErrno_0300 + * @tc.name: b_error_GetCodeByErrno_0300 + * @tc.desc: Test function of int interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BErrorTest, b_error_GetCodeByErrno_0300, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCodeByErrno_0300"; + int32_t errnoSys = -EPERM; + int result = BError::GetCodeByErrno(errnoSys); + EXPECT_EQ(result, BError::BackupErrorCode::E_UKERR); + GTEST_LOG_(INFO) << "BErrorTest-end b_error_GetCodeByErrno_0300"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From cc5fc143f2702f409cf7c5423f7472ebb0a26422 Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:18:40 +0000 Subject: [PATCH 03/11] update tests/unittests/backup_utils/BUILD.gn. Signed-off-by: chensihan --- tests/unittests/backup_utils/BUILD.gn | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/unittests/backup_utils/BUILD.gn b/tests/unittests/backup_utils/BUILD.gn index 40476eb1b..5584b74bd 100644 --- a/tests/unittests/backup_utils/BUILD.gn +++ b/tests/unittests/backup_utils/BUILD.gn @@ -54,6 +54,8 @@ ohos_unittest("b_file_test") { "b_filesystem/b_file_test.cpp", ] + include_dirs = [ "${path_backup}/utils/src/b_filesystem" ] + deps = [ "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils/:backup_utils", @@ -76,23 +78,23 @@ ohos_unittest("b_jsonutil_test") { cfi_cross_dso = true debug = false } - + module_out_path = path_module_out_tests - + sources = [ "b_jsonutil/b_jsonutil_test.cpp" ] - + deps = [ "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils/:backup_utils", "${path_jsoncpp}:jsoncpp", ] - + external_deps = [ "cJSON:cjson", "c_utils:utils", "hilog:libhilog", ] - + use_exceptions = true } @@ -293,6 +295,7 @@ group("backup_test") { ":b_file_test", ":b_json_other_test", ":b_json_test", + ":b_jsonutil_test", ":b_process_test", ":b_tarball_cmdline_test", ":b_tarball_factory_test", -- Gitee From cff13a9c302b4e61958207a88e510f9dfce14792 Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:25:58 +0000 Subject: [PATCH 04/11] update tests/unittests/backup_tools/BUILD.gn. Signed-off-by: chensihan --- tests/unittests/backup_tools/BUILD.gn | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index 15fa2bced..0a0c1d50a 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -21,12 +21,16 @@ ohos_unittest("backup_tool_test") { sources = [ "${path_backup_mock}/b_filesystem/b_file_mock.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_backup_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", "${path_backup}/tools/backup_tool/src/tools_op_backup.cpp", "${path_backup}/tools/backup_tool/src/tools_op_check_sa.cpp", "${path_backup}/tools/backup_tool/src/tools_op_help.cpp", - "${path_backup}/tools/backup_tool/src/tools_op_incremental_backup.cpp", "backup_tool/tools_op_backup_test.cpp", "backup_tool/tools_op_check_sa_test.cpp", "backup_tool/tools_op_help_test.cpp", @@ -37,9 +41,11 @@ ohos_unittest("backup_tool_test") { include_dirs = [ "${path_base}/include", + "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/tools/backup_tool/include", + "${path_backup}/tools/backup_tool/src", ] include_dirs += backup_mock_utils_include @@ -81,10 +87,14 @@ ohos_unittest("backup_tool_restore_test") { sources = [ "${path_backup_mock}/b_filesystem/b_file_mock.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_data.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", - "${path_backup}/tools/backup_tool/src/tools_op_incremental_restore.cpp", "backup_tool/tools_op_incremental_restore_test.cpp", "backup_tool/tools_op_restore_async_test.cpp", "backup_tool/tools_op_restore_test.cpp", @@ -93,6 +103,7 @@ ohos_unittest("backup_tool_restore_test") { include_dirs = [ "${path_base}/include", + "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/tools/backup_tool/include", -- Gitee From 24da4415086e67598174e9cad4f9695321cddc1b Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:28:11 +0000 Subject: [PATCH 05/11] update tests/unittests/backup_tools/backup_tool/tools_op_incremental_backup_test.cpp. Signed-off-by: chensihan --- .../tools_op_incremental_backup_test.cpp | 397 +++++++++++++++++- 1 file changed, 395 insertions(+), 2 deletions(-) diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_incremental_backup_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_incremental_backup_test.cpp index a4b754222..75727088e 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_incremental_backup_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_incremental_backup_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -21,7 +21,7 @@ #include "b_resources/b_constants.h" #include "tools_op.h" -#include "tools_op_incremental_backup.h" +#include "tools_op_incremental_backup.cpp" #include "utils_mock_global_variable.h" namespace OHOS::FileManagement::Backup { @@ -178,4 +178,397 @@ HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_03 } GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_backup_0300"; } + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0400 + * @tc.name: SUB_backup_tools_op_incremental_backup_0400 + * @tc.desc: 测试OnFileReady分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_restore_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_restore_0400"; + try { + auto ctx = make_shared(); + BFileInfo fileInfo; + fileInfo.owner = "test"; + fileInfo.fileName = "/manage.json"; + fileInfo.sn = 1; + UniqueFd fd(open("textFile", O_RDONLY)); + UniqueFd manifestFd(open("textManifest", O_RDONLY)); + OnFileReady(ctx, fileInfo, move(fd), move(manifestFd)); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_restore_0400"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0500 + * @tc.name: SUB_backup_tools_op_incremental_backup_0500 + * @tc.desc: 测试OnBundleStarted分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0500"; + try { + auto ctx = make_shared(); + ErrCode err = 0; + BundleName name = "bundle"; + OnBundleStarted(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0500"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0501 + * @tc.name: SUB_backup_tools_op_incremental_backup_0501 + * @tc.desc: 测试OnBundleStarted分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0501, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0501"; + try { + auto ctx = make_shared(); + ctx->SetBundleFinishedCount(1); + ErrCode err = -1; + BundleName name = "bundle"; + OnBundleStarted(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0501"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0600 + * @tc.name: SUB_backup_tools_op_incremental_backup_0600 + * @tc.desc: 测试OnBundleFinished分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0600"; + try { + auto ctx = make_shared(); + ctx->SetBundleFinishedCount(1); + ErrCode err = 0; + BundleName name = "bundle"; + OnBundleFinished(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0600"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0700 + * @tc.name: SUB_backup_tools_op_incremental_backup_0700 + * @tc.desc: 测试OnAllBundlesFinished分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0700"; + try { + auto ctx = make_shared(); + ErrCode err = 0; + OnAllBundlesFinished(ctx, err); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0700"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0701 + * @tc.name: SUB_backup_tools_op_incremental_backup_0701 + * @tc.desc: 测试OnAllBundlesFinished分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0701, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0701"; + try { + auto ctx = make_shared(); + ErrCode err = -1; + OnAllBundlesFinished(ctx, err); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0701"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0800 + * @tc.name: SUB_backup_tools_op_incremental_backup_0800 + * @tc.desc: 测试OnBackupServiceDied分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0800, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0800"; + try { + auto ctx = make_shared(); + OnBackupServiceDied(ctx); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0800"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_0900 + * @tc.name: SUB_backup_tools_op_incremental_backup_0900 + * @tc.desc: 测试BackupToolDirSoftlinkToBackupDir分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_0900"; + try { + BackupToolDirSoftlinkToBackupDir(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_0900"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1000 + * @tc.name: SUB_backup_tools_op_incremental_backup_1000 + * @tc.desc: 测试GetLocalCapabilitiesIncremental分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1000"; + try { + auto ctx = make_shared(); + string pathCapFile = ""; + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times = {"100"}; + int32_t ret = GetLocalCapabilitiesIncremental(ctx, pathCapFile, bundleNames, times); + EXPECT_EQ(-EPERM, ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1000"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1001 + * @tc.name: SUB_backup_tools_op_incremental_backup_1001 + * @tc.desc: 测试GetLocalCapabilitiesIncremental分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1001"; + try { + auto ctx = make_shared(); + string pathCapFile = "/data/backup"; + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times; + times.push_back("100"); + times.push_back("200"); + int32_t ret = GetLocalCapabilitiesIncremental(ctx, pathCapFile, bundleNames, times); + EXPECT_EQ(-EPERM, ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1001"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1100 + * @tc.name: SUB_backup_tools_op_incremental_backup_1100 + * @tc.desc: 测试Init分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1100"; + try { + string pathCapFile = "/data/backup"; + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times; + times.push_back("100"); + times.push_back("200"); + int32_t ret = Init(pathCapFile, bundleNames, times); + EXPECT_EQ(-EPERM, ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1100"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1200 + * @tc.name: SUB_backup_tools_op_incremental_backup_1200 + * @tc.desc: 测试Exec分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1200"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"bundles", {"bundle1", "bundle2"}}, + {"incrementalTime", {"time"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1200"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1201 + * @tc.name: SUB_backup_tools_op_incremental_backup_1201 + * @tc.desc: 测试Exec分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1201, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1201"; + try { + map> mapArgToVal = { + {"bundles", {"bundle1"}}, + {"incrementalTime", {"time"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1201"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1202 + * @tc.name: SUB_backup_tools_op_incremental_backup_1202 + * @tc.desc: 测试Exec分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1202, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1202"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"incrementalTime", {"time"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1202"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_backup_1203 + * @tc.name: SUB_backup_tools_op_incremental_backup_1203 + * @tc.desc: 测试Exec分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalBackupTest, SUB_backup_tools_op_incremental_backup_1203, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-begin SUB_backup_tools_op_incremental_backup_1203"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"bundles", {"bundle1"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalBackupTest-end SUB_backup_tools_op_incremental_backup_1203"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 21be04a28c59bff40eee653859aee98d5b00de1e Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:30:47 +0000 Subject: [PATCH 06/11] update tests/unittests/backup_tools/backup_tool/tools_op_incremental_restore_test.cpp. Signed-off-by: chensihan --- .../tools_op_incremental_restore_test.cpp | 655 +++++++++++++++++- 1 file changed, 653 insertions(+), 2 deletions(-) diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_incremental_restore_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_incremental_restore_test.cpp index a5f8038a8..94de50821 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_incremental_restore_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_incremental_restore_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -21,7 +21,7 @@ #include "b_resources/b_constants.h" #include "tools_op.h" -#include "tools_op_incremental_restore.h" +#include "tools_op_incremental_restore.cpp" namespace OHOS::FileManagement::Backup { using namespace std; @@ -195,4 +195,655 @@ HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_ } GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_restore_0300"; } + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0400 + * @tc.name: SUB_backup_tools_op_incremental_restore_0400 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0400"; + try { + auto ctx = make_shared(); + BFileInfo fileInfo; + fileInfo.owner = "test"; + fileInfo.fileName = "/manage.json"; + fileInfo.sn = 1; + UniqueFd fd(open("textFile", O_RDONLY)); + UniqueFd manifestFd(open("textManifest", O_RDONLY)); + OnFileReady(ctx, fileInfo, move(fd), move(manifestFd), 0); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0400"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0500 + * @tc.name: SUB_backup_tools_op_incremental_restore_0500 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0500"; + try { + auto ctx = make_shared(); + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times = {"100"}; + int32_t ret = InitRestoreSession(ctx, bundleNames, times); + EXPECT_EQ(-EPERM, ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0500"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0501 + * @tc.name: SUB_backup_tools_op_incremental_restore_0501 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0501, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0501"; + try { + auto ctx = make_shared(); + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times; + times.push_back("100"); + times.push_back("200"); + int32_t ret = InitRestoreSession(nullptr, bundleNames, times); + EXPECT_EQ(-EPERM, ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0501"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0502 + * @tc.name: SUB_backup_tools_op_incremental_restore_0502 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0502, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0502"; + try { + auto ctx = make_shared(); + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times; + times.push_back("10"); + times.push_back("20"); + int32_t ret = InitRestoreSession(ctx, bundleNames, times); + EXPECT_EQ(0, ret); + + BFileInfo fileInfo; + fileInfo.owner = "test"; + fileInfo.fileName = "manage.json"; + fileInfo.sn = 1; + UniqueFd fd(open("textFile", O_RDONLY)); + UniqueFd manifestFd(open("textManifest", O_RDONLY)); + OnFileReady(ctx, fileInfo, move(fd), move(manifestFd), 0); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0502"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0600 + * @tc.name: SUB_backup_tools_op_incremental_restore_0600 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0600"; + try { + auto ctx = make_shared(); + ErrCode err = 0; + BundleName name = "bundle"; + OnBundleStarted(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0600"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0601 + * @tc.name: SUB_backup_tools_op_incremental_restore_0601 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0601, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0601"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = -1; + BundleName name = "bundle"; + OnBundleStarted(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0601"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0700 + * @tc.name: SUB_backup_tools_op_incremental_restore_0700 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0700"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = 0; + BundleName name = "bundle"; + OnBundleFinished(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0700"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0701 + * @tc.name: SUB_backup_tools_op_incremental_restore_0701 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0701, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0701"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = -1; + BundleName name = "bundle"; + OnBundleFinished(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0701"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0800 + * @tc.name: SUB_backup_tools_op_incremental_restore_0800 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0800, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0800"; + try { + auto ctx = make_shared(); + ErrCode err = 0; + OnAllBundlesFinished(ctx, err); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0800"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0801 + * @tc.name: SUB_backup_tools_op_incremental_restore_0801 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0801, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0801"; + try { + auto ctx = make_shared(); + ErrCode err = -1; + OnAllBundlesFinished(ctx, err); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0801"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_0900 + * @tc.name: SUB_backup_tools_op_incremental_restore_0900 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_0900"; + try { + auto ctx = make_shared(); + OnBackupServiceDied(ctx); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_0900"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1000 + * @tc.name: SUB_backup_tools_op_incremental_restore_1000 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1000"; + try { + shared_ptr restore = nullptr; + RestoreApp(restore); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1000"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1001 + * @tc.name: SUB_backup_tools_op_incremental_restore_1001 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1001"; + try { + shared_ptr restore = make_shared(); + restore->session_ = nullptr; + RestoreApp(restore); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1001"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1002 + * @tc.name: SUB_backup_tools_op_incremental_restore_1002 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1002"; + try { + shared_ptr restore = make_shared(); + restore->session_ = {}; + BIncrementalData data("text", 1); + restore->lastIncrementalData = {data}; + RestoreApp(restore); + EXPECT_TRUE(true); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1002"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1003 + * @tc.name: SUB_backup_tools_op_incremental_restore_1003 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1003"; + try { + auto ctx = make_shared(); + vector bundleNames; + bundleNames.push_back("bundle1"); + bundleNames.push_back("bundle2"); + vector times; + times.push_back("10"); + times.push_back("20"); + int32_t ret = InitRestoreSession(ctx, bundleNames, times); + EXPECT_EQ(0, ret); + + RestoreApp(ctx); + EXPECT_TRUE(ctx); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1003"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1100 + * @tc.name: SUB_backup_tools_op_incremental_restore_1100 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1100"; + try { + string pathCapFile = ""; + vector bundleNames = {"com.example.app2backup/"}; + bool depMode = true; + vector times = {"10"}; + int32_t ret = Init(pathCapFile, bundleNames, depMode, times); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1100"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1101 + * @tc.name: SUB_backup_tools_op_incremental_restore_1101 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1101"; + try { + string pathCapFile = "/data/backup"; + vector bundleNames = {"com.example.app2backup/"}; + bool depMode = true; + vector times = {"1"}; + int32_t ret = Init(pathCapFile, bundleNames, depMode, times); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1101"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1102 + * @tc.name: SUB_backup_tools_op_incremental_restore_1102 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1102"; + try { + string pathCapFile = ""; + vector bundleNames = {"com.example.app2backup/"}; + bool depMode = false; + vector times = {"10"}; + int32_t ret = Init(pathCapFile, bundleNames, depMode, times); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1102"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1200 + * @tc.name: SUB_backup_tools_op_incremental_restore_1200 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1200"; + try { + map> mapArgToVal; + mapArgToVal["depMode"] = {"false"}; + g_exec(mapArgToVal); + EXPECT_EQ(mapArgToVal["depMode"][0], "false"); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1200"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1201 + * @tc.name: SUB_backup_tools_op_incremental_restore_1201 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1201, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1201"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"bundles", {"bundle1"}}, + {"incrementalTime", {"time"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1201"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1202 + * @tc.name: SUB_backup_tools_op_incremental_restore_1202 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1202, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1202"; + try { + map> mapArgToVal = { + {"bundles", {"bundle1"}}, + {"incrementalTime", {"time"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1202"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1203 + * @tc.name: SUB_backup_tools_op_incremental_restore_1203 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1203, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1203"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"bundles", {"bundle1"}}, + {"incrementalTime", {"time"}}, + {"depMode", {"true"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1203"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1204 + * @tc.name: SUB_backup_tools_op_incremental_restore_1204 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1204, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1204"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"incrementalTime", {"time"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1204"; +} + +/** + * @tc.number: SUB_backup_tools_op_incremental_restore_1205 + * @tc.name: SUB_backup_tools_op_incremental_restore_1205 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ToolsOpIncrementalRestoreTest, SUB_backup_tools_op_incremental_restore_1205, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-begin SUB_backup_tools_op_incremental_restore_1205"; + try { + map> mapArgToVal = { + {"pathCapFile", {"path"}}, + {"bundles", {"bundle1"}} + }; + int ret = g_exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpIncrementalRestoreTest-end SUB_backup_tools_op_incremental_restore_1205"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From e5c035e1ea3d2b01dfd963315ce188208683c5cd Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:31:05 +0000 Subject: [PATCH 07/11] update tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp. Signed-off-by: chensihan --- .../tools_op_restore_async_test.cpp | 160 +++++++++++++++++- 1 file changed, 153 insertions(+), 7 deletions(-) diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp index c7f7a7b9e..cc797c548 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -293,6 +293,32 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_0400, testing::ext::Tes GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_0400"; } +/** + * @tc.number: SUB_backup_tools_op_restore_async_0401 + * @tc.name: tools_op_restore_async_0401 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9JNFM + */ +HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_0401, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_0401"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = -1; + BundleName name = "testBundle"; + OnBundleStarted(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_0401"; +} + /** * @tc.number: SUB_backup_tools_op_restore_async_0500 * @tc.name: tools_op_restore_async_0500 @@ -318,6 +344,32 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_0500, testing::ext::Tes GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_0500"; } +/** + * @tc.number: SUB_backup_tools_op_restore_async_0501 + * @tc.name: tools_op_restore_async_0501 + * @tc.desc: 测试OnBundleFinished方法 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9JNFM + */ +HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_0501, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_0501"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = -1; + BundleName name = "testBundle"; + OnBundleFinished(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_0501"; +} + /** * @tc.number: SUB_backup_tools_op_restore_async_0600 * @tc.name: tools_op_restore_async_0600 @@ -452,8 +504,9 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1001, testing::ext::Tes GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_1001"; try { vector bundleNames; - bundleNames.push_back("bundle/name");\ + bundleNames.push_back("bundle/name"); shared_ptr restore = make_shared(); + restore->session_ = {}; RestoreApp(restore, bundleNames); } catch (BError &e) { EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); @@ -479,8 +532,9 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1002, testing::ext::Tes GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_1002"; try { vector bundleNames; - bundleNames.push_back("bundlename");\ + bundleNames.push_back("bundlename"); shared_ptr restore = make_shared(); + restore->session_ = {}; RestoreApp(restore, bundleNames); } catch (BError &e) { EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); @@ -508,7 +562,7 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1100, testing::ext::Tes string pathCapFile = "/data/user/0/test/files/bundleInfo.json"; vector bundleNames = {"bundlenames"}; string type = "false"; - int32_t ret =ChangeBundleInfo(pathCapFile, bundleNames, type); + int32_t ret = ChangeBundleInfo(pathCapFile, bundleNames, type); EXPECT_LT(ret, 0); } catch (...) { EXPECT_TRUE(false); @@ -533,7 +587,7 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1101, testing::ext::Tes string pathCapFile = " "; vector bundleNames = {"bundlenames"}; string type = "false"; - int32_t ret =ChangeBundleInfo(pathCapFile, bundleNames, type); + int32_t ret = ChangeBundleInfo(pathCapFile, bundleNames, type); EXPECT_LT(ret, 0); } catch (...) { EXPECT_TRUE(false); @@ -558,7 +612,7 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1102, testing::ext::Tes string pathCapFile = "/data/user/0/test/files/bundleInfo.json"; vector bundleNames = {}; string type = "true"; - int32_t ret =ChangeBundleInfo(pathCapFile, bundleNames, type); + int32_t ret = ChangeBundleInfo(pathCapFile, bundleNames, type); EXPECT_LT(ret, 0); } catch (...) { EXPECT_TRUE(false); @@ -768,7 +822,6 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1401, testing::ext::Tes { GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_1401"; try { - map> mapArgToVal; int ret = Exec(mapArgToVal); EXPECT_EQ(ret, -EPERM); @@ -778,4 +831,97 @@ HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1401, testing::ext::Tes } GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_1401"; } + +/** + * @tc.number: SUB_backup_tools_op_restore_async_1500 + * @tc.name: tools_op_restore_async_1500 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_1500"; + try { + std::string path = "/data/backup/receive"; + std::vector pkgInfo; + ExtManageInfo info; + info.hashName = "hashName"; + info.fileName = "fileName"; + info.isBigFile = false; + info.isUserTar = false; + pkgInfo.push_back(info); + + auto result = ReadyExtManage(path, pkgInfo); + EXPECT_EQ(result.size(), 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_1500"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_async_1501 + * @tc.name: tools_op_restore_async_1501 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1501, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_1501"; + try { + std::string path = "/data/backup/receive"; + std::vector pkgInfo; + ExtManageInfo info; + info.hashName = ""; + info.fileName = ""; + info.isBigFile = false; + info.isUserTar = false; + pkgInfo.push_back(info); + + auto result = ReadyExtManage(path, pkgInfo); + EXPECT_EQ(result.size(), 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_1501"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_async_1502 + * @tc.name: tools_op_restore_async_1502 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreAsyncTest, tools_op_restore_async_1502, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin tools_op_restore_async_1502"; + try { + std::string path = "/data/backup/receive"; + std::vector pkgInfo; + ExtManageInfo info; + info.hashName = "hashName"; + info.fileName = "fileName"; + info.isBigFile = true; + info.isUserTar = true; + pkgInfo.push_back(info); + + auto result = ReadyExtManage(path, pkgInfo); + EXPECT_EQ(result.size(), 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end tools_op_restore_async_1502"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 2bdfc084d3a438049a78613c75b25ecd320a2d04 Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 03:31:17 +0000 Subject: [PATCH 08/11] update tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp. Signed-off-by: chensihan --- .../backup_tool/tools_op_restore_test.cpp | 229 +++++++++++++++++- 1 file changed, 228 insertions(+), 1 deletion(-) diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp index 3d7220db8..6244fabf5 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -432,6 +432,129 @@ HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OnBundleStarted_0601, testing::ext GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_OnBundleStarted_0601"; } +/** + * @tc.number: SUB_backup_tools_op_restore_0700 + * @tc.name: tools_op_restore_OnBundleFinished_0700 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OnBundleFinished_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_OnBundleFinished_0700"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = 0; + BundleName name = BUNDLE_NAME; + OnBundleFinished(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_OnBundleFinished_0700"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_0701 + * @tc.name: tools_op_restore_OnBundleFinished_0701 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OnBundleFinished_0701, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_OnBundleFinished_0701"; + try { + auto ctx = make_shared(); + ctx->cnt_ = 1; + ErrCode err = -1; + BundleName name = BUNDLE_NAME; + OnBundleFinished(ctx, err, name); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_OnBundleFinished_0701"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_0702 + * @tc.name: tools_op_restore_OnBundleFinished_0702 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OnBundleFinished_0702, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_OnBundleFinished_0702"; + try { + auto ctx = make_shared(); + ErrCode err = 0; + OnAllBundlesFinished(ctx, err); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_OnBundleFinished_0702"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_0703 + * @tc.name: tools_op_restore_OnBundleFinished_0703 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OnBundleFinished_0703, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_OnBundleFinished_0703"; + try { + auto ctx = make_shared(); + ErrCode err = -1; + OnAllBundlesFinished(ctx, err); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_OnBundleFinished_0703"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_0704 + * @tc.name: tools_op_restore_OnBundleFinished_0704 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OnBundleFinished_0704, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_OnBundleFinished_0704"; + try { + auto ctx = make_shared(); + OnBackupServiceDied(ctx); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_OnBundleFinished_0704"; +} + /** * @tc.number: SUB_backup_tools_op_restore_0800 * @tc.name: tools_op_restore_OnResultReport_0800 @@ -639,6 +762,31 @@ HWTEST_F(ToolsOpRestoreTest, tools_op_restore_InitRestoreSession_1100, testing:: GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_GInitRestoreSession_1100"; } +/** + * @tc.number: SUB_backup_tools_op_restore_1101 + * @tc.name: tools_op_restore_InitRestoreSession_1101 + * @tc.desc: 测试当ctx + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_InitRestoreSession_1101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_InitRestoreSession_1101"; + try { + shared_ptr ctx = make_shared(); + InitRestoreSession(ctx); + } catch (BError &e) { + EXPECT_EQ(e.GetCode(), BError(BError::Codes::TOOL_INVAL_ARG).GetCode()); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_InitRestoreSession_1101"; +} + /** * @tc.number: SUB_backup_tools_op_restore_1200 * @tc.name: tools_op_restore_InitPathCapFile_1200 @@ -664,6 +812,60 @@ HWTEST_F(ToolsOpRestoreTest, tools_op_restore_InitPathCapFile_1200, testing::ext GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_InitPathCapFile_1200"; } +/** + * @tc.number: SUB_backup_tools_op_restore_1201 + * @tc.name: tools_op_restore_InitPathCapFile_1201 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_InitPathCapFile_1201, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_InitPathCapFile_1201"; + try { + string pathCapFile = "/data/backup/tmp"; + vector bundleNames = {"com.example.app2backup/"}; + bool depMode = true; + int32_t ret = InitPathCapFile(pathCapFile, bundleNames, depMode); + EXPECT_LT(ret, 0); + } catch (BError &e) { + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_InitPathCapFile_1201"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_1202 + * @tc.name: tools_op_restore_InitPathCapFile_1202 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_InitPathCapFile_1202, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_InitPathCapFile_1202"; + try { + string pathCapFile = "/data/backup/tmp"; + vector bundleNames = {"com.example.app2backup/"}; + bool depMode = false; + int32_t ret = InitPathCapFile(pathCapFile, bundleNames, depMode); + EXPECT_LT(ret, 0); + } catch (BError &e) { + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_InitPathCapFile_1202"; +} + /** * @tc.number: SUB_backup_tools_op_restore_1300 * @tc.name: tools_op_restore_Exec_1300 @@ -767,4 +969,29 @@ HWTEST_F(ToolsOpRestoreTest, tools_op_restore_Exec_1303, testing::ext::TestSize. } GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_Exec_1303"; } + +/** + * @tc.number: SUB_backup_tools_op_restore_1304 + * @tc.name: tools_op_restore_Exec_1304 + * @tc.desc: test func + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I9NOPD + */ +HWTEST_F(ToolsOpRestoreTest, tools_op_restore_Exec_1304, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_Exec_1304"; + try { + map> mapArgToVal; + mapArgToVal["pathCapFile"] = {"/data/backup/recived/com.example.app2backup/"}; + mapArgToVal["bundles"] = {"com.example.app2backup/"}; + int ret = Exec(mapArgToVal); + EXPECT_LT(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreTest-end tools_op_restore_Exec_1304"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 1eabf5e78cbec788fe09caeeeecb9138ee6c240b Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 06:51:21 +0000 Subject: [PATCH 09/11] update tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp. Signed-off-by: chensihan --- .../b_jsonutil/b_jsonutil_test.cpp | 511 +----------------- 1 file changed, 22 insertions(+), 489 deletions(-) diff --git a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp index 09d7926d0..936de04fa 100644 --- a/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp +++ b/tests/unittests/backup_utils/b_jsonutil/b_jsonutil_test.cpp @@ -30,10 +30,6 @@ namespace OHOS::FileManagement::Backup { using namespace std; -namespace { -constexpr uint32_t TEST_USER_ID = 100; -} // namespace - class BJsonUtilTest : public testing::Test { public: static void SetUpTestCase(void) {}; @@ -56,7 +52,8 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::T GTEST_LOG_(INFO) << "BJsonUtilTest-begin b_dir_GetDirFiles_0100"; try { std::string bundleName = "com.hos.app01:1"; - BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); + std::string pattern = ":"; + BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName, pattern); EXPECT_EQ("com.hos.app01", detailInfo.bundleName); } catch (...) { EXPECT_TRUE(false); @@ -65,29 +62,6 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::T GTEST_LOG_(INFO) << "BDirTest-end b_dir_GetDirFiles_0100"; } -/** - * @tc.number: b_jsonutil_ParseBundleNameIndexStr_0200 - * @tc.name: b_jsonutil_ParseBundleNameIndexStr_0200 - * @tc.desc: Test function of ParseBundleNameIndexStr interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0200, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin ParseBundleNameIndexStr_0200"; - try { - std::string bundleName = "com.hos.app01"; - BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); - EXPECT_EQ("com.hos.app01", detailInfo.bundleName); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BDirTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BDirTest-end ParseBundleNameIndexStr_0200"; -} - /** * @tc.number: b_jsonutil_BuildBundleInfos_0100 * @tc.name: b_jsonutil_BuildBundleInfos_0100 @@ -103,474 +77,33 @@ HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0100, testing::ext::TestSize try { std::vector bundleNames; std::string bundleName = "com.hos.app01:1"; + std::string bundleName1 = "com.hos.app02"; bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = "info1"; - std::string bundleInfo2 = "info2"; - bundleInfos.push_back(bundleInfo); - bundleInfos.push_back(bundleInfo2); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_TRUE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0100"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0200 - * @tc.name: b_jsonutil_BuildBundleInfos_0200 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0200, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0200"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = "{\"infos\":\"infos\"}"; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0200"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0300 - * @tc.name: b_jsonutil_BuildBundleInfos_0300 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0300, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0300"; - try { - std::vector bundleNames; - std::string bundleName = "bundle1:"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = "info1"; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_TRUE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0300"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0301 - * @tc.name: b_jsonutil_BuildBundleInfos_0301 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0301, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0301"; - try { - std::vector bundleNames; - std::string bundleName = ":bundle1"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = "info1"; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_TRUE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0301"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0400 - * @tc.name: b_jsonutil_BuildBundleInfos_0400 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0400, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0400"; - try { - std::vector bundleNames; - std::string bundleName = "bundle1"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = { - "{\"infos\":[{\"type\":\"type1\",\"details\":\"details1\"}],\"clearBackupData\": \"false\"}" - }; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_EQ(isClearDataFlags[bundleName], false); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0400"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0500 - * @tc.name: b_jsonutil_BuildBundleInfos_0500 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0500, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0500"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = {"{\"infos\":[{\"type\":null}]}"}; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_EQ(isClearDataFlags[bundleName], true); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0500"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0600 - * @tc.name: b_jsonutil_BuildBundleInfos_0600 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0600, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0600"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = {"{\"infos\":[{\"type\":123}],\"clearBackupData\": \"true\"}"}; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_EQ(isClearDataFlags[bundleName], true); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0600"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0700 - * @tc.name: b_jsonutil_BuildBundleInfos_0700 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0700, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0700"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":null}]}"}; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0700"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0800 - * @tc.name: b_jsonutil_BuildBundleInfos_0800 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0800, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0800"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":[]}]}"}; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0800"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_0900 - * @tc.name: b_jsonutil_BuildBundleInfos_0900 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0900, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0900"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":[\"detail\"]}]}"}; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; - std::map isClearDataFlags; - - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, - userId, isClearDataFlags); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0900"; -} - -/** - * @tc.number: b_jsonutil_BuildBundleInfos_1000 - * @tc.name: b_jsonutil_BuildBundleInfos_1000 - * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_1000, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_1000"; - try { - std::vector bundleNames; - std::string bundleName = "bundle"; - bundleNames.push_back(bundleName); - std::vector bundleInfos; - std::string bundleInfo = {"{\"infos\":[\"infos\"]}"}; - bundleInfos.push_back(bundleInfo); - int32_t userId = TEST_USER_ID; - std::vector bundleNamesOnly; + bundleNames.push_back(bundleName1); + std::string pattern = ":"; + std::vector detailInfos; + std::string detail01 = "{ + "infos" : [ { + "details" : [ { + "detail" : [ { "source" : "com.ohos.app01", "target" : "com.hos.app01" } ], + "type" : "app_mapping_relation" } ], + "type" : "broadcast" } ] + }"; + detailInfos.push_back(detail01); + detailInfos.push_back(""); + int32_t userId = 100; + std::vector realBundleNames; std::map isClearDataFlags; - - auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, + std::map> bundleNameDetailMap = + BJsonUtil::BuildBundleInfos(bundleNames, detailInfos, realBundleNames, userId, isClearDataFlags); - EXPECT_FALSE(result.empty()); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_1000"; -} - -/** - * @tc.number: b_jsonutil_FindBundleInfoByName_0100 - * @tc.name: b_jsonutil_FindBundleInfoByName_0100 - * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0100, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0100"; - try { - std::map> bundleNameDetailsMap; - std::string bundleName = "bundle1"; - std::string jobType = "type"; - BJsonUtil::BundleDetailInfo bundleDetail; - - bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType, bundleDetail); - EXPECT_EQ(false, result); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0100"; -} - -/** - * @tc.number: b_jsonutil_FindBundleInfoByName_0200 - * @tc.name: b_jsonutil_FindBundleInfoByName_0200 - * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0200, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0200"; - try { - std::map> bundleNameDetailsMap; - std::string bundleName = "bundle1"; - std::string jobType = "type"; - BJsonUtil::BundleDetailInfo detailInfo; - detailInfo.bundleName = bundleName; - detailInfo.type = jobType; - bundleNameDetailsMap[bundleName] = {detailInfo}; - BJsonUtil::BundleDetailInfo bundleDetail; - - bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType, bundleDetail); - EXPECT_EQ(true, result); - EXPECT_EQ(bundleDetail.type, detailInfo.type); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0200"; -} - -/** - * @tc.number: b_jsonutil_FindBundleInfoByName_0300 - * @tc.name: b_jsonutil_FindBundleInfoByName_0300 - * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0300, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0300"; - try { - std::map> bundleNameDetailsMap; - std::string bundleName = "bundle1"; - std::string jobType = "type"; - std::string jobType1 = "type1"; - BJsonUtil::BundleDetailInfo detailInfo; - detailInfo.bundleName = bundleName; - detailInfo.type = jobType; - bundleNameDetailsMap[bundleName] = {detailInfo}; - BJsonUtil::BundleDetailInfo bundleDetail; - - bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType1, bundleDetail); - EXPECT_EQ(false, result); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0300"; -} - -/** - * @tc.number: b_jsonutil_BuildExtensionErrInfo_0100 - * @tc.name: b_jsonutil_BuildExtensionErrInfo_0100 - * @tc.desc: Test function of BuildExtensionErrInfo interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 0 - * @tc.require: I6F3GV - */ -HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0100, testing::ext::TestSize.Level0) -{ - GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0100"; - try { - std::string jsonStr; - int errCode = 1; - std::string errMsg = "error"; - - bool result = BJsonUtil::BuildExtensionErrInfo(jsonStr, errCode, errMsg); - EXPECT_EQ(true, result); - EXPECT_NE(jsonStr.find("errorCode"), std::string::npos); - EXPECT_NE(jsonStr.find("errorInfo"), std::string::npos); - EXPECT_NE(jsonStr.find("type"), std::string::npos); + std::string key = "com.hos.app01"; + EXPECT_EQ("com.hos.app01", bundleNameDetailMap[key].bundleName[0]); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; } - GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildExtensionErrInfo_0100"; + GTEST_LOG_(INFO) << "BJsonUtilTest-end b_dir_BuildBundleInfos_0100"; } /* * -- Gitee From 824c3b5cf18f089af5295f7629fbd529f07ceb0f Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 06:52:02 +0000 Subject: [PATCH 10/11] update tests/unittests/backup_utils/BUILD.gn. Signed-off-by: chensihan --- tests/unittests/backup_utils/BUILD.gn | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unittests/backup_utils/BUILD.gn b/tests/unittests/backup_utils/BUILD.gn index 5584b74bd..47be52ea6 100644 --- a/tests/unittests/backup_utils/BUILD.gn +++ b/tests/unittests/backup_utils/BUILD.gn @@ -78,23 +78,23 @@ ohos_unittest("b_jsonutil_test") { cfi_cross_dso = true debug = false } - + module_out_path = path_module_out_tests - + sources = [ "b_jsonutil/b_jsonutil_test.cpp" ] - + deps = [ "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils/:backup_utils", "${path_jsoncpp}:jsoncpp", ] - + external_deps = [ "cJSON:cjson", "c_utils:utils", "hilog:libhilog", ] - + use_exceptions = true } -- Gitee From 84d4f76c4c2cc2a6bb1ebd59d7a695d56f391bb5 Mon Sep 17 00:00:00 2001 From: chensihan Date: Thu, 10 Oct 2024 07:14:19 +0000 Subject: [PATCH 11/11] update tests/unittests/backup_utils/BUILD.gn. Signed-off-by: chensihan --- tests/unittests/backup_utils/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unittests/backup_utils/BUILD.gn b/tests/unittests/backup_utils/BUILD.gn index 47be52ea6..4295818aa 100644 --- a/tests/unittests/backup_utils/BUILD.gn +++ b/tests/unittests/backup_utils/BUILD.gn @@ -295,7 +295,6 @@ group("backup_test") { ":b_file_test", ":b_json_other_test", ":b_json_test", - ":b_jsonutil_test", ":b_process_test", ":b_tarball_cmdline_test", ":b_tarball_factory_test", -- Gitee