From d20e6c1203e43e2ae02c6e7e51f11f88f756fd1d Mon Sep 17 00:00:00 2001 From: huangxiaolinabc123 Date: Sat, 27 Aug 2022 08:26:19 +0800 Subject: [PATCH 01/46] add tests Signed-off-by: huangxiaolinabc123 Change-Id: Ie88320210e55e8703bce5b527cb2ea3715eae7a4 --- services/common/test/unittest/BUILD.gn | 5 ++- .../common/test/unittest/parse_util_test.cpp | 39 +++++++++++++++++++ test/resource/ohos_test.xml | 1 + test/resource/profile/empty_libpath.xml | 27 +++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/resource/profile/empty_libpath.xml diff --git a/services/common/test/unittest/BUILD.gn b/services/common/test/unittest/BUILD.gn index 3de283d8..499a3e8a 100644 --- a/services/common/test/unittest/BUILD.gn +++ b/services/common/test/unittest/BUILD.gn @@ -25,7 +25,10 @@ ohos_unittest("ParseUtilTest") { "//foundation/systemabilitymgr/samgr/utils/native/include", ] - sources = [ "./parse_util_test.cpp" ] + sources = [ + "./parse_util_test.cpp", + "//foundation/systemabilitymgr/samgr/utils/native/source/tools.cpp", + ] configs = [ "//foundation/systemabilitymgr/samgr/test/resource:coverage_flags" ] diff --git a/services/common/test/unittest/parse_util_test.cpp b/services/common/test/unittest/parse_util_test.cpp index b3f2f9e6..4c742bf9 100644 --- a/services/common/test/unittest/parse_util_test.cpp +++ b/services/common/test/unittest/parse_util_test.cpp @@ -15,6 +15,7 @@ #include "gtest/gtest.h" #include "string_ex.h" #include "test_log.h" +#include "tools.h" #define private public #include "parse_util.h" @@ -191,6 +192,10 @@ HWTEST_F(ParseUtilTest, GetSaProfiles002, TestSize.Level3) */ bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "profile.xml"); ASSERT_TRUE(ret); + SaProfile saRunOnCreateTrue,saRunOnCreateFalse; + saRunOnCreateTrue.runOnCreate = true; + parser_->saProfiles_.emplace_back(saRunOnCreateTrue); + parser_->saProfiles_.emplace_back(saRunOnCreateFalse); parser_->OpenSo(); list profiles = parser_->GetAllSaProfiles(); if (!profiles.empty()) { @@ -557,6 +562,7 @@ HWTEST_F(ParseUtilTest, LoadSaLib002, TestSize.Level2) bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); EXPECT_EQ(ret, true); ret = parser_->LoadSaLib(TEST_PROFILE_SAID_INVAILD); + parser_->CloseSo(MOCK_SAID); EXPECT_NE(ret, true); } @@ -600,6 +606,24 @@ HWTEST_F(ParseUtilTest, LoadSaLib004, TestSize.Level2) parser_->LoadSaLib(MOCK_SAID); } +/** + * @tc.name: LoadSaLib005 + * @tc.desc: Verify if can load salib + * @tc.type: FUNC + * @tc.require: I5KMF7 + */ +HWTEST_F(ParseUtilTest, LoadSaLib005, TestSize.Level2) +{ + DTEST_LOG << " LoadSaLib005 start " << std::endl; + /** + * @tc.steps: step1. check exsit salib + * @tc.expected: step1. return false when load not exist salib + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "empty_libpath.xml"); + EXPECT_EQ(ret, true); + ret = parser_->LoadSaLib(MOCK_SAID); + EXPECT_EQ(ret, true); +} /** * @tc.name: GetProcessName001 * @tc.desc: Verify if can get procesname @@ -870,5 +894,20 @@ HWTEST_F(ParseUtilTest, ParseSaid002, TestSize.Level1) bool res = parser_->ParseSaId(rootNodeptr, tempSaId); EXPECT_EQ(res, false); } + +/** + * @tc.name: DeleteAllMark001 + * @tc.desc: Verify if can DeleteAllMark + * @tc.type: FUNC + * @tc.require: I5KMF7 + */ +HWTEST_F(ParseUtilTest, DeleteAllMark001, TestSize.Level3) +{ + DTEST_LOG << " DeleteAllMark001 " << std::endl; + u16string temp = u"stests"; + u16string mask = u"s"; + u16string res = DeleteAllMark(temp, mask); + EXPECT_EQ(res, u"tet"); +} } // namespace SAMGR } // namespace OHOS diff --git a/test/resource/ohos_test.xml b/test/resource/ohos_test.xml index 8ff753bc..84af8b00 100644 --- a/test/resource/ohos_test.xml +++ b/test/resource/ohos_test.xml @@ -30,6 +30,7 @@