diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-03-31 16:44:24 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-03-31 14:24:22 +0200 |
commit | 620921b36bbf9ccfa91124d27b7437ffdb04f660 (patch) | |
tree | fe2111b2cd87e0a1e8d4c25d144cf4eb393ca5d4 /lib/util/charset/util_str.c | |
parent | 26ccb6d5ed88638dd3643632157771320cd8042a (diff) | |
download | samba-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/util_str.c')
-rw-r--r-- | lib/util/charset/util_str.c | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/lib/util/charset/util_str.c b/lib/util/charset/util_str.c index f36c91eef3..e8f0b788b1 100644 --- a/lib/util/charset/util_str.c +++ b/lib/util/charset/util_str.c @@ -28,13 +28,13 @@ #endif /** - Case insensitive string compararison + Case insensitive string compararison, handle specified for testing **/ -_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) +_PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle, + const char *s1, const char *s2) { codepoint_t c1=0, c2=0; size_t size1, size2; - struct smb_iconv_handle *iconv_handle = get_iconv_handle(); /* handle null ptr comparisons to simplify the use in qsort */ if (s1 == s2) return 0; @@ -67,13 +67,22 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) } /** - Case insensitive string compararison, length limited + Case insensitive string compararison **/ -_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) +_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) +{ + struct smb_iconv_handle *iconv_handle = get_iconv_handle(); + return strcasecmp_m_handle(iconv_handle, s1, s2); +} + +/** + Case insensitive string compararison, length limited, handle specified for testing +**/ +_PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle, + const char *s1, const char *s2, size_t n) { codepoint_t c1=0, c2=0; size_t size1, size2; - struct smb_iconv_handle *iconv_handle = get_iconv_handle(); /* handle null ptr comparisons to simplify the use in qsort */ if (s1 == s2) return 0; @@ -112,6 +121,15 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) } /** + Case insensitive string compararison, length limited +**/ +_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) +{ + struct smb_iconv_handle *iconv_handle = get_iconv_handle(); + return strncasecmp_m_handle(iconv_handle, s1, s2, n); +} + +/** * Compare 2 strings. * * @note The comparison is case-insensitive. @@ -399,9 +417,9 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) /** return True if any (multi-byte) character is lower case */ -_PUBLIC_ bool strhaslower(const char *string) +_PUBLIC_ bool strhaslower_handle(struct smb_iconv_handle *ic, + const char *string) { - struct smb_iconv_handle *ic = get_iconv_handle(); while (*string) { size_t c_size; codepoint_t s; @@ -420,12 +438,18 @@ _PUBLIC_ bool strhaslower(const char *string) return false; } +_PUBLIC_ bool strhaslower(const char *string) +{ + struct smb_iconv_handle *ic = get_iconv_handle(); + return strhaslower_handle(ic, string); +} + /** return True if any (multi-byte) character is upper case */ -_PUBLIC_ bool strhasupper(const char *string) +_PUBLIC_ bool strhasupper_handle(struct smb_iconv_handle *ic, + const char *string) { - struct smb_iconv_handle *ic = get_iconv_handle(); while (*string) { size_t c_size; codepoint_t s; @@ -444,3 +468,8 @@ _PUBLIC_ bool strhasupper(const char *string) return false; } +_PUBLIC_ bool strhasupper(const char *string) +{ + struct smb_iconv_handle *ic = get_iconv_handle(); + return strhasupper_handle(ic, string); +} |