summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2017-09-06 11:24:28 +0200
committerStefan Metzmacher <metze@samba.org>2017-09-16 09:24:12 +0200
commit16308387b5e1bcda7bbaf7d6cf947948ba3cb409 (patch)
tree7f07161c1f89a22fc68b6feb46cb3d5f95af67ec /lib/util
parentc6a49313f696b9f893bba2b03ad66f4322fb7be7 (diff)
downloadsamba-16308387b5e1bcda7bbaf7d6cf947948ba3cb409.tar.gz
charset/tests: also tests the system str[n]casecmp()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13018 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> (cherry picked from commit 9d99b640b9002ad6c0eb0d29a6d7adcfda870e13)
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/charset/tests/charset.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/util/charset/tests/charset.c b/lib/util/charset/tests/charset.c
index 918bf57fb99..71635c6fea3 100644
--- a/lib/util/charset/tests/charset.c
+++ b/lib/util/charset/tests/charset.c
@@ -48,6 +48,21 @@ static bool test_codepoint_cmpi(struct torture_context *tctx)
return true;
}
+static bool test_strcasecmp(struct torture_context *tctx)
+{
+ torture_assert_int_equal(tctx, strcasecmp("foo", "bar"), 4, "different strings both lower");
+ torture_assert_int_equal(tctx, strcasecmp("foo", "Bar"), 4, "different strings lower/upper");
+ torture_assert_int_equal(tctx, strcasecmp("Foo", "bar"), 4, "different strings upper/lower");
+ torture_assert_int_equal(tctx, strcasecmp("AFoo", "_bar"), 2, "different strings upper/lower");
+ torture_assert_int_equal(tctx, strcasecmp("foo", "foo"), 0, "same case strings");
+ torture_assert_int_equal(tctx, strcasecmp("foo", "Foo"), 0, "different case strings");
+
+ /*
+ * Note that strcasecmp() doesn't allow NULL arguments
+ */
+ return true;
+}
+
static bool test_strcasecmp_m(struct torture_context *tctx)
{
/* file.{accented e} in iso8859-1 */
@@ -109,6 +124,24 @@ static bool test_string_replace_m(struct torture_context *tctx)
return true;
}
+static bool test_strncasecmp(struct torture_context *tctx)
+{
+ torture_assert_int_equal(tctx, strncasecmp("foo", "bar", 3), 4, "different strings both lower");
+ torture_assert_int_equal(tctx, strncasecmp("foo", "Bar", 3), 4, "different strings lower/upper");
+ torture_assert_int_equal(tctx, strncasecmp("Foo", "bar", 3), 4, "different strings upper/lower");
+ torture_assert_int_equal(tctx, strncasecmp("AFoo", "_bar", 4), 2, "different strings upper/lower");
+ torture_assert_int_equal(tctx, strncasecmp("foo", "foo", 3), 0, "same case strings");
+ torture_assert_int_equal(tctx, strncasecmp("foo", "Foo", 3), 0, "different case strings");
+ torture_assert_int_equal(tctx, strncasecmp("fool", "Foo", 3),0, "different case strings");
+ torture_assert_int_equal(tctx, strncasecmp("fool", "Fool", 40), 0, "over size");
+ torture_assert_int_equal(tctx, strncasecmp("BLA", "Fool", 0),0, "empty");
+
+ /*
+ * Note that strncasecmp() doesn't allow NULL arguments
+ */
+ return true;
+}
+
static bool test_strncasecmp_m(struct torture_context *tctx)
{
/* file.{accented e} in iso8859-1 */
@@ -282,10 +315,12 @@ struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx)
torture_suite_add_simple_test(suite, "toupper_m", test_toupper_m);
torture_suite_add_simple_test(suite, "tolower_m", test_tolower_m);
torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi);
+ torture_suite_add_simple_test(suite, "strcasecmp", test_strcasecmp);
torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m);
torture_suite_add_simple_test(suite, "strequal_m", test_strequal_m);
torture_suite_add_simple_test(suite, "strcsequal", test_strcsequal);
torture_suite_add_simple_test(suite, "string_replace_m", test_string_replace_m);
+ torture_suite_add_simple_test(suite, "strncasecmp", test_strncasecmp);
torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m);
torture_suite_add_simple_test(suite, "next_token", test_next_token);
torture_suite_add_simple_test(suite, "next_token_null", test_next_token_null);