From 399631125396476e596e4e1e25e9fc8dbcdcc40d Mon Sep 17 00:00:00 2001 From: ry Date: Fri, 18 Mar 2022 19:17:40 +0800 Subject: [PATCH] =?UTF-8?q?fixed=209821ad8=20from=20https://gitee.com/inte?= =?UTF-8?q?r515/xts=5Facts=5Frelease/pulls/2642=20=E5=A2=9E=E5=8A=A0memset?= =?UTF-8?q?=5Fs=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ry --- .../appexecfwk_hal/src/bundle_mgr_test.c | 27 +++++++++------ .../appexecfwk_posix/src/BundleMgrTest.cpp | 33 ++++++++++++------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/appexecfwk_lite/appexecfwk_hal/src/bundle_mgr_test.c b/appexecfwk_lite/appexecfwk_hal/src/bundle_mgr_test.c index 928d0d8b9..ae9256903 100755 --- a/appexecfwk_lite/appexecfwk_hal/src/bundle_mgr_test.c +++ b/appexecfwk_lite/appexecfwk_hal/src/bundle_mgr_test.c @@ -51,7 +51,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testClearAbilityInfoLegal, Function | MediumT { printf("------start testClearAbilityInfo------\n"); AbilityInfo abilityInfo; - memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + int result = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + TEST_ASSERT_TRUE(result == 0); abilityInfo.bundleName = "com.openharmony.testjsdemo"; TEST_ASSERT_EQUAL_STRING(abilityInfo.bundleName, "com.openharmony.testjsdemo"); ClearAbilityInfo(&abilityInfo); @@ -68,7 +69,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testClearAbilityInfoIllegal, Function | Mediu { printf("------start testClearAbilityInfoIllegal------\n"); AbilityInfo abilityInfo = { 0 }; - memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + int result = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + TEST_ASSERT_TRUE(result == 0); abilityInfo.bundleName = "com.openharmony.testjsdemo"; ClearAbilityInfo(NULL); TEST_ASSERT_EQUAL_STRING(abilityInfo.bundleName, "com.openharmony.testjsdemo"); @@ -84,7 +86,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testClearBundleInfoLegal, Function | MediumTe { printf("------start testClearBundleInfo------\n"); BundleInfo bundleInfo = { 0 }; - memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + TEST_ASSERT_TRUE(result == 0); bundleInfo.bundleName = "com.openharmony.testjsdemo"; TEST_ASSERT_EQUAL_STRING(bundleInfo.bundleName, "com.openharmony.testjsdemo"); ClearBundleInfo(&bundleInfo); @@ -101,7 +104,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testClearBundleInfoIllegal, Function | Medium { printf("------start testClearBundleInfoIllegal------\n"); BundleInfo bundleInfo; - memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + TEST_ASSERT_TRUE(result == 0); bundleInfo.bundleName = "com.openharmony.testjsdemo"; ClearBundleInfo(NULL); TEST_ASSERT_EQUAL_STRING(bundleInfo.bundleName, "com.openharmony.testjsdemo"); @@ -117,7 +121,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testClearModuleInfoLegal, Function | MediumTe { printf("------start testClearModuleInfo------\n"); ModuleInfo moduleInfo = { 0 }; - memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + int result = memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + TEST_ASSERT_TRUE(result == 0); moduleInfo.moduleName = "test"; TEST_ASSERT_EQUAL_STRING(moduleInfo.moduleName, "test"); ClearModuleInfo(&moduleInfo); @@ -134,7 +139,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testClearModuleInfoIllegal, Function | Medium { printf("------start testClearModuleInfoIllegal------\n"); ModuleInfo moduleInfo = { 0 }; - memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + int result = memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + TEST_ASSERT_TRUE(result == 0); moduleInfo.moduleName = "test"; ClearModuleInfo(NULL); TEST_ASSERT_EQUAL_STRING(moduleInfo.moduleName, "test"); @@ -278,9 +284,10 @@ LITE_TEST_CASE(BundleMgrTestSuite, testGetBundleInfoIllegal, Function | MediumTe { printf("------start testGetBundleInfoIllegal------\n"); BundleInfo bundleInfo; - memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + TEST_ASSERT_TRUE(result == 0); const char *bundleName = "com.openharmony.nothishap"; - int32_t flags = 0; + int flags = 0; uint8_t ret = GetBundleInfo(bundleName, flags, &bundleInfo); TEST_ASSERT_TRUE(ret == 2); ret = GetBundleInfo(NULL, flags, &bundleInfo); @@ -303,8 +310,8 @@ LITE_TEST_CASE(BundleMgrTestSuite, testGetBundleInfosIllegal, Function | MediumT { printf("------start testGetBundleInfosIllegal------\n"); BundleInfo *bundleInfos = {NULL}; - int32_t *length = NULL; - int32_t flags = 0; + int *length = NULL; + int flags = 0; uint8_t ret = GetBundleInfos(flags, NULL, length); TEST_ASSERT_TRUE(ret == 1); ret = GetBundleInfos(flags, &bundleInfos, NULL); diff --git a/appexecfwk_lite/appexecfwk_posix/src/BundleMgrTest.cpp b/appexecfwk_lite/appexecfwk_posix/src/BundleMgrTest.cpp index 82dda1b72..6a310c655 100755 --- a/appexecfwk_lite/appexecfwk_posix/src/BundleMgrTest.cpp +++ b/appexecfwk_lite/appexecfwk_posix/src/BundleMgrTest.cpp @@ -102,7 +102,8 @@ HWTEST_F(BundleMgrTest, testClearAbilityInfoIllegal, Function | MediumTest | Lev printf("------start testClearAbilityInfoIllegal------\n"); // abilityInfo is nullptr AbilityInfo abilityInfo; - memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + int32_t result = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + EXPECT_EQ(result, 0); abilityInfo.bundleName = (char*)"com.openharmony.testjsdemo"; printf("abilityInfo.bundleName is %s \n", abilityInfo.bundleName); ClearAbilityInfo(nullptr); @@ -119,7 +120,8 @@ HWTEST_F(BundleMgrTest, testClearBundleInfoIllegal, Function | MediumTest | Leve { printf("------start testClearBundleInfoIllegal------\n"); BundleInfo bundleInfo; - memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + int32_t result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + EXPECT_EQ(result, 0); bundleInfo.bundleName = (char*)"com.openharmony.testjsdemo"; printf("abilityInfo.bundleName is %s \n", bundleInfo.bundleName); ClearBundleInfo(nullptr); @@ -137,7 +139,8 @@ HWTEST_F(BundleMgrTest, testClearModuleInfoIllegal, Function | MediumTest | Leve { printf("------start testClearModuleInfoIllegal------\n"); ModuleInfo moduleInfo; - memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + int32_t result = memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + EXPECT_EQ(result, 0); moduleInfo.description = (char*)"test app"; moduleInfo.moduleType = (char*)"entry"; ClearModuleInfo(nullptr); @@ -556,15 +559,18 @@ HWTEST_F(BundleMgrTest, testQueryAbilityInfoRight, Function | MediumTest | Level { printf("------start testQueryAbilityInfoRight------\n"); Want want; - memset_s(&want, sizeof(Want), 0, sizeof(Want)); + int32_t resultWant = memset_s(&want, sizeof(Want), 0, sizeof(Want)); + EXPECT_EQ(resultWant, 0); ElementName element; - memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + int32_t resultElementName = memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + EXPECT_EQ(resultElementName, 0); SetElementAbilityName(&element, "MainAbility"); SetElementBundleName(&element, "com.openharmony.testjsdemo"); SetWantElement(&want, element); SetWantData(&want, "test", 4); AbilityInfo abilityInfo; - memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + int32_t result = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + EXPECT_EQ(result, 0); printf("element.elementname is %s \n", want.element->bundleName); printf("AbilityName2 is %s \n", want.element->abilityName); g_errorCode = QueryAbilityInfo(&want, &abilityInfo); @@ -584,16 +590,19 @@ HWTEST_F(BundleMgrTest, testQueryAbilityInfoIllegal, Function | MediumTest | Lev { printf("------start testQueryAbilityInfoIllegal------\n"); AbilityInfo abilityInfo; - memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)); + int32_t result = memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)); + EXPECT_EQ(result, 0); // want is nullptr g_errorCode = QueryAbilityInfo(nullptr, &abilityInfo); printf("ret is %d \n", g_errorCode); EXPECT_TRUE(g_errorCode == 4); // abilityInfo is nullptr Want want; - memset_s(&want, sizeof(Want), 0, sizeof(Want)); + int32_t resultWant = memset_s(&want, sizeof(Want), 0, sizeof(Want)); + EXPECT_EQ(resultWant, 0); ElementName element; - memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + int32_t resultElementName = memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + EXPECT_EQ(resultElementName, 0); SetElementAbilityName(&element, "MainAbility"); SetElementBundleName(&element, "com.openharmony.testjsdemo"); SetWantElement(&want, element); @@ -624,7 +633,8 @@ HWTEST_F(BundleMgrTest, testGetBundleInfoRight, Function | MediumTest | Level1) { printf("------start testGetBundleInfoRight------\n"); BundleInfo bundleInfo; - memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + int32_t result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + EXPECT_EQ(result, 0); const char *bundleName = (char*)"com.openharmony.testjsdemo"; int32_t flags = 0; printf("bundleName is %s \n", bundleName); @@ -655,7 +665,8 @@ HWTEST_F(BundleMgrTest, testGetBundleInfoIllegal, Function | MediumTest | Level2 { printf("------start testGetBundleInfoIllegal------\n"); BundleInfo bundleInfo; - memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + int32_t result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + EXPECT_EQ(result, 0); const char *bundleName = (char*)"com.openharmony.nothishap"; int32_t flags = 0; // error bundleName -- GitLab