tests: Remove MATCH macro and change it to strncmp 65/314865/1 accepted/tizen/unified/20240723.101922 accepted/tizen/unified/dev/20240724.110040 accepted/tizen/unified/toolchain/20240812.133451 accepted/tizen/unified/x/20240724.011732 accepted/tizen/unified/x/asan/20240813.231934
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 22 Jul 2024 07:51:53 +0000 (16:51 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 22 Jul 2024 07:51:53 +0000 (16:51 +0900)
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 <yuni.seo@samsung.com>
tests/libcommon/test-common.c

index 9f97bd29bc6b4848d37343041c22b8204e550806..e579dc5c613102a15a7be7e2132f5d96393292ad 100644 (file)
@@ -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;