summaryrefslogtreecommitdiff
path: root/tests/unit/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2020-05-31 14:51:41 +0200
committerSébastien Helleu <flashcode@flashtux.org>2020-05-31 14:51:41 +0200
commit8818fbb233d4b21e8ae8bc0f83db673dea440fd4 (patch)
tree30091166fb75d24757815e3120e3977145e14377 /tests/unit/core
parent527aa3c563a6c151c242d45bd133311a0b40c391 (diff)
downloadweechat-8818fbb233d4b21e8ae8bc0f83db673dea440fd4.zip
tests: fix memory leak in test of function string_hex_dump
Diffstat (limited to 'tests/unit/core')
-rw-r--r--tests/unit/core/test-core-string.cpp73
1 files changed, 29 insertions, 44 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 686c06edb..9812a2367 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -108,6 +108,13 @@ extern "C"
STRCMP_EQUAL(__result, str); \
free (str);
+#define WEE_HEX_DUMP(__result, __data, __size, __bytes_per_line, \
+ __prefix, __suffix) \
+ str = string_hex_dump (__data, __size, __bytes_per_line, \
+ __prefix, __suffix); \
+ STRCMP_EQUAL(__result, str); \
+ free (str);
+
extern struct t_hashtable *string_hashtable_shared;
TEST_GROUP(CoreString)
@@ -1917,58 +1924,36 @@ TEST(CoreString, Hex_dump)
POINTERS_EQUAL(NULL, string_hex_dump ("abc", 3, 0, NULL, NULL));
POINTERS_EQUAL(NULL, string_hex_dump ("abc", 0, 5, NULL, NULL));
- str = string_hex_dump ("abc", 3, 3, NULL, NULL);
- STRCMP_EQUAL("61 62 63 a b c ", str);
-
- str = string_hex_dump ("abc", 3, 3, "", "");
- STRCMP_EQUAL("61 62 63 a b c ", str);
-
- str = string_hex_dump ("abc", 3, 3, "(( ", NULL);
- STRCMP_EQUAL("(( 61 62 63 a b c ", str);
-
- str = string_hex_dump ("abc", 3, 3, NULL, " ))");
- STRCMP_EQUAL("61 62 63 a b c ))", str);
-
- str = string_hex_dump ("abc", 3, 3, "(( ", " ))");
- STRCMP_EQUAL("(( 61 62 63 a b c ))", str);
-
- str = string_hex_dump ("abc", 3, 5, NULL, NULL);
- STRCMP_EQUAL("61 62 63 a b c ", str);
-
- str = string_hex_dump ("abc", 3, 10, NULL, NULL);
- STRCMP_EQUAL("61 62 63 a b c ", str);
-
- str = string_hex_dump ("abc", 3, 2, NULL, NULL);
- STRCMP_EQUAL("61 62 a b \n"
+ WEE_HEX_DUMP("61 62 63 a b c ", "abc", 3, 3, NULL, NULL);
+ WEE_HEX_DUMP("61 62 63 a b c ", "abc", 3, 3, "", "");
+ WEE_HEX_DUMP("(( 61 62 63 a b c ", "abc", 3, 3, "(( ", NULL);
+ WEE_HEX_DUMP("61 62 63 a b c ))", "abc", 3, 3, NULL, " ))");
+ WEE_HEX_DUMP("(( 61 62 63 a b c ))", "abc", 3, 3, "(( ", " ))");
+ WEE_HEX_DUMP("61 62 63 a b c ", "abc", 3, 5, NULL, NULL);
+ WEE_HEX_DUMP("61 62 63 a b c ",
+ "abc", 3, 10, NULL, NULL);
+ WEE_HEX_DUMP("61 62 a b \n"
"63 c ",
- str);
-
- str = string_hex_dump (noel_utf8, strlen (noel_utf8), 5, NULL, NULL);
- STRCMP_EQUAL("6E 6F C3 AB 6C n o . . l ", str);
-
- str = string_hex_dump (noel_utf8, strlen (noel_utf8), 2, NULL, NULL);
- STRCMP_EQUAL("6E 6F n o \n"
+ "abc", 3, 2, NULL, NULL);
+ WEE_HEX_DUMP("6E 6F C3 AB 6C n o . . l ",
+ noel_utf8, strlen (noel_utf8), 5, NULL, NULL);
+ WEE_HEX_DUMP("6E 6F n o \n"
"C3 AB . . \n"
"6C l ",
- str);
- str = string_hex_dump (noel_utf8, strlen (noel_utf8), 2, "( ", NULL);
- STRCMP_EQUAL("( 6E 6F n o \n"
+ noel_utf8, strlen (noel_utf8), 2, NULL, NULL);
+ WEE_HEX_DUMP("( 6E 6F n o \n"
"( C3 AB . . \n"
"( 6C l ",
- str);
- str = string_hex_dump (noel_utf8, strlen (noel_utf8), 2, "( ", " )");
- STRCMP_EQUAL("( 6E 6F n o )\n"
+ noel_utf8, strlen (noel_utf8), 2, "( ", NULL);
+ WEE_HEX_DUMP("( 6E 6F n o )\n"
"( C3 AB . . )\n"
"( 6C l )",
- str);
-
- str = string_hex_dump (noel_iso, strlen (noel_iso), 5, NULL, NULL);
- STRCMP_EQUAL("6E 6F EB 6C n o . l ", str);
-
- str = string_hex_dump (noel_iso, strlen (noel_iso), 2, NULL, NULL);
- STRCMP_EQUAL("6E 6F n o \n"
+ noel_utf8, strlen (noel_utf8), 2, "( ", " )");
+ WEE_HEX_DUMP("6E 6F EB 6C n o . l ",
+ noel_iso, strlen (noel_iso), 5, NULL, NULL);
+ WEE_HEX_DUMP("6E 6F n o \n"
"EB 6C . l ",
- str);
+ noel_iso, strlen (noel_iso), 2, NULL, NULL);
}
/*