summaryrefslogtreecommitdiff
path: root/tests/unit/core/test-core-string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/core/test-core-string.cpp')
-rw-r--r--tests/unit/core/test-core-string.cpp132
1 files changed, 73 insertions, 59 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 3dbcfbc78..540e241b5 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -468,107 +468,121 @@ TEST(CoreString, Comparison)
{
/* case-insensitive comparison */
LONGS_EQUAL(0, string_strcasecmp (NULL, NULL));
- LONGS_EQUAL(-1, string_strcasecmp (NULL, "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-97, string_strcasecmp (NULL, "abc"));
+ LONGS_EQUAL(97, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-98, string_strcasecmp ("", "b"));
+ LONGS_EQUAL(98, string_strcasecmp ("b", ""));
LONGS_EQUAL(0, string_strcasecmp ("abc", "abc"));
LONGS_EQUAL(0, string_strcasecmp ("abc", "ABC"));
LONGS_EQUAL(0, string_strcasecmp ("ABC", "ABC"));
- LONGS_EQUAL(-1, string_strcasecmp ("abc", "def"));
- LONGS_EQUAL(-1, string_strcasecmp ("abc", "DEF"));
- LONGS_EQUAL(-1, string_strcasecmp ("ABC", "def"));
- LONGS_EQUAL(-1, string_strcasecmp ("ABC", "DEF"));
- LONGS_EQUAL(1, string_strcasecmp ("def", "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("def", "ABC"));
- LONGS_EQUAL(1, string_strcasecmp ("DEF", "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("DEF", "ABC"));
+ LONGS_EQUAL(-3, string_strcasecmp ("abc", "def"));
+ LONGS_EQUAL(-3, string_strcasecmp ("abc", "DEF"));
+ LONGS_EQUAL(-3, string_strcasecmp ("ABC", "def"));
+ LONGS_EQUAL(-3, string_strcasecmp ("ABC", "DEF"));
+ LONGS_EQUAL(3, string_strcasecmp ("def", "abc"));
+ LONGS_EQUAL(3, string_strcasecmp ("def", "ABC"));
+ LONGS_EQUAL(3, string_strcasecmp ("DEF", "abc"));
+ LONGS_EQUAL(3, string_strcasecmp ("DEF", "ABC"));
/* case-insensitive comparison with max length */
LONGS_EQUAL(0, string_strncasecmp (NULL, NULL, 3));
- LONGS_EQUAL(-1, string_strncasecmp (NULL, "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-97, string_strncasecmp (NULL, "abc", 3));
+ LONGS_EQUAL(97, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-98, string_strncasecmp ("", "b", 3));
+ LONGS_EQUAL(98, string_strncasecmp ("b", "", 3));
LONGS_EQUAL(0, string_strncasecmp ("abc", "abc", 3));
LONGS_EQUAL(0, string_strncasecmp ("abcabc", "abcdef", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "abcdef", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abcabc", "abcdef", 6));
LONGS_EQUAL(0, string_strncasecmp ("abc", "ABC", 3));
LONGS_EQUAL(0, string_strncasecmp ("abcabc", "ABCDEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abcabc", "ABCDEF", 6));
LONGS_EQUAL(0, string_strncasecmp ("ABC", "ABC", 3));
LONGS_EQUAL(0, string_strncasecmp ("ABCABC", "ABCDEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABCABC", "ABCDEF", 6));
- LONGS_EQUAL(-1, string_strncasecmp ("abc", "def", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abc", "DEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABC", "def", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABC", "DEF", 3));
- LONGS_EQUAL(1, string_strncasecmp ("def", "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("def", "ABC", 3));
- LONGS_EQUAL(1, string_strncasecmp ("DEF", "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("DEF", "ABC", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABCABC", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abc", "def", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("abc", "DEF", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABC", "def", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABC", "DEF", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("def", "abc", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("def", "ABC", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("DEF", "abc", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("DEF", "ABC", 3));
/* case-insensitive comparison with a range */
LONGS_EQUAL(0, string_strcasecmp_range (NULL, NULL, 30));
- LONGS_EQUAL(-1, string_strcasecmp_range (NULL, "abc", 30));
- LONGS_EQUAL(1, string_strcasecmp_range ("abc", NULL, 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("A", "Z", 30));
- LONGS_EQUAL(1, string_strcasecmp_range ("Z", "A", 30));
+ LONGS_EQUAL(-97, string_strcasecmp_range (NULL, "abc", 30));
+ LONGS_EQUAL(97, string_strcasecmp_range ("abc", NULL, 30));
+ LONGS_EQUAL(-98, string_strcasecmp_range ("", "b", 30));
+ LONGS_EQUAL(98, string_strcasecmp_range ("b", "", 30));
+ LONGS_EQUAL(-2, string_strcasecmp_range ("A", "C", 30));
+ LONGS_EQUAL(2, string_strcasecmp_range ("C", "A", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("A", "a", 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("ë", "€", 30));
+ LONGS_EQUAL(-8129, string_strcasecmp_range ("ë", "€", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("[", "{", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("]", "}", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("\\", "|", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("^", "~", 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("[", "{", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("]", "}", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("\\", "|", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("[", "{", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("{", "[", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("]", "}", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("}", "]", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("\\", "|", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("|", "\\", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("~", "^", 26));
/* case-insensitive comparison with max length and a range */
LONGS_EQUAL(0, string_strncasecmp_range (NULL, NULL, 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range (NULL, "abc", 3, 30));
- LONGS_EQUAL(1, string_strncasecmp_range ("abc", NULL, 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ABC", "ZZZ", 3, 30));
- LONGS_EQUAL(1, string_strncasecmp_range ("ZZZ", "ABC", 3, 30));
+ LONGS_EQUAL(-97, string_strncasecmp_range (NULL, "abc", 3, 30));
+ LONGS_EQUAL(97, string_strncasecmp_range ("abc", NULL, 3, 30));
+ LONGS_EQUAL(-98, string_strncasecmp_range ("", "b", 3, 30));
+ LONGS_EQUAL(98, string_strncasecmp_range ("b", "", 3, 30));
+ LONGS_EQUAL(-2, string_strncasecmp_range ("ABC", "CCC", 3, 30));
+ LONGS_EQUAL(2, string_strncasecmp_range ("CCC", "ABC", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("ABC", "abc", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("ABCABC", "abcdef", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ëëë", "€€€", 3, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30));
+ LONGS_EQUAL(-8129, string_strncasecmp_range ("ëëë", "€€€", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("[[[", "{{{", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("[[[abc", "{{{def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("]]]", "}}}", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("]]]abc", "}}}def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\", "|||", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\abc", "|||def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("^^^", "~~~", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("^^^abc", "~~~def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("[[[", "{{{", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("]]]", "}}}", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\", "|||", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("^^^", "~~~", 3, 26));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("[[[", "{{{", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("]]]", "}}}", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("\\\\\\", "|||", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("^^^", "~~~", 3, 26));
/* comparison with chars ignored */
LONGS_EQUAL(0, string_strcmp_ignore_chars (NULL, NULL, "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars (NULL, "abc", "", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc", NULL, "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "ZZZ", "", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("ZZZ", "ABC", "", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars (NULL, "abc", "", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars ("abc", NULL, "", 0));
+ LONGS_EQUAL(-98, string_strcmp_ignore_chars ("", "b", "", 0));
+ LONGS_EQUAL(98, string_strcmp_ignore_chars ("b", "", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("ABC", "CCC", "", 0));
+ LONGS_EQUAL(2, string_strcmp_ignore_chars ("CCC", "ABC", "", 0));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("ABC", "abc", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "abc", "", 1));
+ LONGS_EQUAL(-32, string_strcmp_ignore_chars ("ABC", "abc", "", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abcabc", ".", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1));
+ LONGS_EQUAL(32, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abc-.-.abc",
".-", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC",
- ".-", 1));
+ LONGS_EQUAL(32, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC",
+ ".-", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars (".abc..abc", "..abcabc", ".", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars (".", "..abcabc", ".", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars (".", "..abcabc", ".", 0));
LONGS_EQUAL(0, string_strcmp_ignore_chars (".", ".", ".", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "É", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 1));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "Ê", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 1));
}
/*