diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2015-08-22 09:30:08 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2015-08-22 09:30:08 +0200 |
commit | 951d1f91a4595500d50af52245eb0dbeff829aca (patch) | |
tree | 1bafff9fc29544d5045b8fca90aee6836c8c416d /tests/unit | |
parent | 8b47243516dab4462eb57fca2e3ce79b34b5c146 (diff) | |
download | weechat-951d1f91a4595500d50af52245eb0dbeff829aca.zip |
api: add function string_hex_dump()
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/core/test-string.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-string.cpp index 4171aa5cc..dc33029cd 100644 --- a/tests/unit/core/test-string.cpp +++ b/tests/unit/core/test-string.cpp @@ -1125,6 +1125,76 @@ TEST(String, BaseN) /* * Tests functions: + * string_hex_dump + */ + +TEST(String, Hex_dump) +{ + const char *noel_utf8 = "no\xc3\xabl"; /* noël */ + const char *noel_iso = "no\xebl"; + char *str; + + POINTERS_EQUAL(NULL, string_hex_dump (NULL, 0, 0, NULL, NULL)); + POINTERS_EQUAL(NULL, string_hex_dump ("abc", 0, 0, NULL, NULL)); + 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" + "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" + "C3 AB . . \n" + "6C l ", + str); + str = string_hex_dump (noel_utf8, strlen (noel_utf8), 2, "( ", NULL); + STRCMP_EQUAL("( 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" + "( 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" + "EB 6C . l ", + str); +} + +/* + * Tests functions: * string_is_command_char * string_input_for_buffer */ |