summaryrefslogtreecommitdiff
path: root/lib/util/charset/tests/convert_string.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-03-31 16:44:24 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-03-31 14:24:22 +0200
commit620921b36bbf9ccfa91124d27b7437ffdb04f660 (patch)
treefe2111b2cd87e0a1e8d4c25d144cf4eb393ca5d4 /lib/util/charset/tests/convert_string.c
parent26ccb6d5ed88638dd3643632157771320cd8042a (diff)
downloadsamba-620921b36bbf9ccfa91124d27b7437ffdb04f660.tar.gz
samba-620921b36bbf9ccfa91124d27b7437ffdb04f660.tar.bz2
samba-620921b36bbf9ccfa91124d27b7437ffdb04f660.zip
lib/util/charset Add tests for strcasecmp_m(), talloc_strupper() et al
This adds tests for: strncasecmp_m strcasecmp_m strupper_talloc_n strlower_talloc strhaslower strhasupper The tests can certainly be improved with pre-calculated upper and lower case text, but this at least puts them though their paces. Andrew Bartlett Autobuild-User: Andrew Bartlett <abartlet@samba.org> Autobuild-Date: Thu Mar 31 14:24:22 CEST 2011 on sn-devel-104
Diffstat (limited to 'lib/util/charset/tests/convert_string.c')
-rw-r--r--lib/util/charset/tests/convert_string.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/lib/util/charset/tests/convert_string.c b/lib/util/charset/tests/convert_string.c
index 5c7bdcb1da..a634e84e9c 100644
--- a/lib/util/charset/tests/convert_string.c
+++ b/lib/util/charset/tests/convert_string.c
@@ -490,6 +490,166 @@ static bool test_plato_latin_cp850_utf8(struct torture_context *tctx)
return true;
}
+static bool test_gd_case_utf8(struct torture_context *tctx)
+{
+ struct smb_iconv_handle *iconv_handle;
+ DATA_BLOB gd_utf8 = base64_decode_data_blob(gd_utf8_base64);
+ char *gd_lower, *gd_upper;
+ talloc_steal(tctx, gd_utf8.data);
+
+ iconv_handle = get_iconv_testing_handle(tctx, "ASCII", "UTF8", "UTF8");
+ torture_assert(tctx, iconv_handle, "getting utf8 iconv handle");
+
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, (const char *)gd_utf8.data),
+ "GD's name has an upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, (const char *)gd_utf8.data),
+ "GD's name has an lower case character");
+ gd_lower = strlower_talloc_handle(iconv_handle, tctx, (const char *)gd_utf8.data);
+ torture_assert(tctx, gd_lower, "failed to convert GD's name into lower case");
+ gd_upper = strupper_talloc_n_handle(iconv_handle, tctx, (const char *)gd_utf8.data, gd_utf8.length);
+ torture_assert(tctx, gd_lower, "failed to convert GD's name into upper case");
+
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, gd_upper),
+ "upper case name has an upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, gd_lower),
+ "lower case name has an lower case character");
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, gd_lower) == false,
+ "lower case name has no upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, gd_upper) == false,
+ "upper case name has no lower case character");
+
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, (const char *)gd_utf8.data,
+ gd_upper) == 0,
+ "case insensitive comparison orig/upper");
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, (const char *)gd_utf8.data,
+ gd_lower) == 0,
+ "case insensitive comparison orig/lower");
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, gd_upper,
+ gd_lower) == 0,
+ "case insensitive comparison upper/lower");
+
+ /* This string isn't different in length upper/lower */
+ torture_assert(tctx, strncasecmp_m_handle(iconv_handle, (const char *)gd_utf8.data,
+ gd_upper, gd_utf8.length) == 0,
+ "case insensitive comparison orig/upper");
+ torture_assert(tctx, strncasecmp_m_handle(iconv_handle, (const char *)gd_utf8.data,
+ gd_lower, gd_utf8.length) == 0,
+ "case insensitive comparison orig/lower");
+ torture_assert(tctx, strncasecmp_m_handle(iconv_handle, gd_upper,
+ gd_lower, gd_utf8.length) == 0,
+ "case insensitive comparison upper/lower");
+ return true;
+}
+
+static bool test_gd_case_cp850(struct torture_context *tctx)
+{
+ struct smb_iconv_handle *iconv_handle;
+ DATA_BLOB gd_cp850 = base64_decode_data_blob(gd_cp850_base64);
+ char *gd_lower, *gd_upper;
+ talloc_steal(tctx, gd_cp850.data);
+
+ iconv_handle = get_iconv_testing_handle(tctx, "ASCII", "CP850", "CP850");
+ torture_assert(tctx, iconv_handle, "getting cp850 iconv handle");
+
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, (const char *)gd_cp850.data),
+ "GD's name has an upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, (const char *)gd_cp850.data),
+ "GD's name has an lower case character");
+ gd_lower = strlower_talloc_handle(iconv_handle, tctx, (const char *)gd_cp850.data);
+ torture_assert(tctx, gd_lower, "failed to convert GD's name into lower case");
+ gd_upper = strupper_talloc_n_handle(iconv_handle, tctx, (const char *)gd_cp850.data, gd_cp850.length);
+ torture_assert(tctx, gd_lower, "failed to convert GD's name into upper case");
+
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, gd_upper),
+ "upper case name has an upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, gd_lower),
+ "lower case name has an lower case character");
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, gd_lower) == false,
+ "lower case name has no upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, gd_upper) == false,
+ "upper case name has no lower case character");
+
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, (const char *)gd_cp850.data,
+ gd_upper) == 0,
+ "case insensitive comparison orig/upper");
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, (const char *)gd_cp850.data,
+ gd_lower) == 0,
+ "case insensitive comparison orig/lower");
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, gd_upper,
+ gd_lower) == 0,
+ "case insensitive comparison upper/lower");
+
+ /* This string isn't different in length upper/lower */
+ torture_assert(tctx, strncasecmp_m_handle(iconv_handle, (const char *)gd_cp850.data,
+ gd_upper, gd_cp850.length) == 0,
+ "case insensitive comparison orig/upper");
+ torture_assert(tctx, strncasecmp_m_handle(iconv_handle, (const char *)gd_cp850.data,
+ gd_lower, gd_cp850.length) == 0,
+ "case insensitive comparison orig/lower");
+ torture_assert(tctx, strncasecmp_m_handle(iconv_handle, gd_upper,
+ gd_lower, gd_cp850.length) == 0,
+ "case insensitive comparison upper/lower");
+ return true;
+}
+
+static bool test_plato_case_utf8(struct torture_context *tctx)
+{
+ struct smb_iconv_handle *iconv_handle;
+ DATA_BLOB plato_utf8 = base64_decode_data_blob(plato_utf8_base64);
+ char *plato_lower, *plato_upper;
+ talloc_steal(tctx, plato_utf8.data);
+
+ iconv_handle = get_iconv_testing_handle(tctx, "ASCII", "UTF8", "UTF8");
+ torture_assert(tctx, iconv_handle, "getting utf8 iconv handle");
+
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, (const char *)plato_utf8.data),
+ "PLATO's apology has an upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, (const char *)plato_utf8.data),
+ "PLATO's apology has an lower case character");
+ plato_lower = strlower_talloc_handle(iconv_handle, tctx, (const char *)plato_utf8.data);
+ torture_assert(tctx, plato_lower, "failed to convert PLATO's apology into lower case");
+ plato_upper = strupper_talloc_n_handle(iconv_handle, tctx, (const char *)plato_utf8.data, plato_utf8.length);
+ torture_assert(tctx, plato_lower, "failed to convert PLATO's apology into upper case");
+
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, plato_upper),
+ "upper case string has an upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, plato_lower),
+ "lower case string has an lower case character");
+ torture_assert(tctx,
+ strhasupper_handle(iconv_handle, plato_lower) == false,
+ "lower case string has no upper case character");
+ torture_assert(tctx,
+ strhaslower_handle(iconv_handle, plato_upper) == false,
+ "upper case string has no lower case character");
+
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, (const char *)plato_utf8.data,
+ plato_upper) == 0,
+ "case insensitive comparison orig/upper");
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, (const char *)plato_utf8.data,
+ plato_lower) == 0,
+ "case insensitive comparison orig/lower");
+ torture_assert(tctx, strcasecmp_m_handle(iconv_handle, plato_upper,
+ plato_lower) == 0,
+ "case insensitive comparison upper/lower");
+ return true;
+}
+
struct torture_suite *torture_local_convert_string(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "convert_string_talloc");
@@ -501,3 +661,13 @@ struct torture_suite *torture_local_convert_string(TALLOC_CTX *mem_ctx)
torture_suite_add_simple_test(suite, "plato_ascii_cp850_utf8", test_plato_latin_cp850_utf8);
return suite;
}
+
+struct torture_suite *torture_local_string_case(TALLOC_CTX *mem_ctx)
+{
+ struct torture_suite *suite = torture_suite_create(mem_ctx, "string_case");
+
+ torture_suite_add_simple_test(suite, "gd_case_utf8", test_gd_case_utf8);
+ torture_suite_add_simple_test(suite, "gd_case_cp850", test_gd_case_cp850);
+ torture_suite_add_simple_test(suite, "plato_case_utf8", test_plato_case_utf8);
+ return suite;
+}