diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-01-13 19:45:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-01-13 20:22:32 +0100 |
commit | c174983474d4a010a18e3bb9a59e351a442480f5 (patch) | |
tree | 3501d667abb9ec0015c9cf449c10608acef36d60 /src/test | |
parent | shared: replace a few invocations of strcasecmp() for DNS labels with ascii_s... (diff) | |
download | systemd-c174983474d4a010a18e3bb9a59e351a442480f5.tar.xz systemd-c174983474d4a010a18e3bb9a59e351a442480f5.zip |
basic: add ascii_strcasecmp_nn() call
In contrast to ascii_strcasecmp_nn() it takes two character buffers with their individual length. It will then compare
the buffers up the smaller size of the two buffers, and finally the length themselves.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-string-util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 4758108706..12889ce873 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -82,8 +82,26 @@ static void test_ascii_strcasecmp_n(void) { assert_se(ascii_strcasecmp_n("xxxxYxxxx", "xxxxXxxxx", 9) > 0); } +static void test_ascii_strcasecmp_nn(void) { + assert_se(ascii_strcasecmp_nn("", 0, "", 0) == 0); + assert_se(ascii_strcasecmp_nn("", 0, "", 1) < 0); + assert_se(ascii_strcasecmp_nn("", 1, "", 0) > 0); + assert_se(ascii_strcasecmp_nn("", 1, "", 1) == 0); + + assert_se(ascii_strcasecmp_nn("aaaa", 4, "aaAa", 4) == 0); + assert_se(ascii_strcasecmp_nn("aaa", 3, "aaAa", 4) < 0); + assert_se(ascii_strcasecmp_nn("aaa", 4, "aaAa", 4) < 0); + assert_se(ascii_strcasecmp_nn("aaaa", 4, "aaA", 3) > 0); + assert_se(ascii_strcasecmp_nn("aaaa", 4, "AAA", 4) > 0); + + assert_se(ascii_strcasecmp_nn("aaaa", 4, "bbbb", 4) < 0); + assert_se(ascii_strcasecmp_nn("aaAA", 4, "BBbb", 4) < 0); + assert_se(ascii_strcasecmp_nn("BBbb", 4, "aaaa", 4) > 0); +} + int main(int argc, char *argv[]) { test_string_erase(); test_ascii_strcasecmp_n(); + test_ascii_strcasecmp_nn(); return 0; } |