From: Yunhee Seo Date: Mon, 22 Jul 2024 07:51:53 +0000 (+0900) Subject: tests: Remove MATCH macro and change it to strncmp X-Git-Tag: accepted/tizen/unified/20240723.101922^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d80949d66d00e2da5009932cb18288df046462b1;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git tests: Remove MATCH macro and change it to strncmp MATCH macro was used to compare two strings in wrong way. This because when the two string are compared by strncmp, the comparison length should be strlen + 1 of one string to avoid null string comparison case. Thus, MATCH macro is replaced by original strncmp function. Furthermore, using sizeof literal is more clear in terms of readability and maintenance. Change-Id: I00272ccb12f9424177bdab3a3d33a1f97617b29c Signed-off-by: Yunhee Seo --- diff --git a/tests/libcommon/test-common.c b/tests/libcommon/test-common.c index 9f97bd2..e579dc5 100644 --- a/tests/libcommon/test-common.c +++ b/tests/libcommon/test-common.c @@ -167,17 +167,17 @@ static int test_parser(struct parse_result *result, void *data) { assert_int_equal(data, check_user_data); - if (MATCH(result->section, "Section1") && - MATCH(result->name, "Key1") && - MATCH(result->value, "Value1")) + if (!strncmp(result->section, "Section1", sizeof("Section1")) && + !strncmp(result->name, "Key1", sizeof("Key1")) && + !strncmp(result->value, "Value1", sizeof("Value1"))) checked1 = true; - else if (MATCH(result->section, "Section2") && - MATCH(result->name, "Key2") && - MATCH(result->value, "Value2")) + else if (!strncmp(result->section, "Section2", sizeof("Section2")) && + !strncmp(result->name, "Key2", sizeof("Key2")) && + !strncmp(result->value, "Value2", sizeof("Value2"))) checked2 = true; - else if (MATCH(result->section, "Section2") && - MATCH(result->name, "Key3") && - MATCH(result->value, "Value3")) + else if (!strncmp(result->section, "Section2", sizeof("Section2")) && + !strncmp(result->name, "Key3", sizeof("Key3")) && + !strncmp(result->value, "Value3", sizeof("Value3"))) checked3 = true; else garbage = true;