Rev 11661: Add testsuite for lib/charset in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Mon Mar 5 00:07:38 GMT 2007


At file:///home/jelmer/bzr.samba/SAMBA_4_0/

------------------------------------------------------------
revno: 11661
revision-id: jelmer at samba.org-20070305000727-wh4as3qq9g9ad7rz
parent: svn-v2:21690 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Mon 2007-03-05 01:07:27 +0100
message:
  Add testsuite for lib/charset
added:
  source/lib/charset/testsuite.c testsuite.c-20070304230422-kli0bc9lvnu3zmgz-1
modified:
  source/lib/charset/util_unistr.c svn-v2:15295 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fcharset%2futil_unistr.c
  source/torture/local/config.mk svn-v2:12008 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2ftorture%2flocal%2fconfig.mk
  source/torture/local/local.c   svn-v2:16333 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2ftorture%2flocal%2flocal.c
=== added file 'source/lib/charset/testsuite.c'
--- a/source/lib/charset/testsuite.c	1970-01-01 00:00:00 +0000
+++ b/source/lib/charset/testsuite.c	2007-03-05 00:07:27 +0000
@@ -0,0 +1,236 @@
+/* 
+   Unix SMB/CIFS implementation.
+   test suite for the charcnv functions
+
+   Copyright (C) Jelmer Vernooij 2007
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+
+static bool test_toupper_w(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, toupper_w('c'), 'C', "c");
+	torture_assert_int_equal(tctx, toupper_w('Z'), 'Z', "z");
+	torture_assert_int_equal(tctx, toupper_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565");
+	return true;
+}
+
+static bool test_tolower_w(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, tolower_w('C'), 'c', "c");
+	torture_assert_int_equal(tctx, tolower_w('z'), 'z', "z");
+	torture_assert_int_equal(tctx, tolower_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565");
+	return true;
+}
+
+static bool test_codepoint_cmpi(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, codepoint_cmpi('a', 'a'), 0, "same char");
+	torture_assert_int_equal(tctx, codepoint_cmpi('A', 'a'), 0, "upcase version");
+	torture_assert_int_equal(tctx, codepoint_cmpi('b', 'a'), 1, "right diff");
+	torture_assert_int_equal(tctx, codepoint_cmpi('a', 'b'), -1, "right diff");
+	return true;
+}
+
+static bool test_strcasecmp_m(struct torture_context *tctx)
+{
+	torture_assert(tctx, strcasecmp_m("foo", "bar") != 0, "different strings");
+	torture_assert(tctx, strcasecmp_m("foo", "foo") == 0, "same case strings");
+	torture_assert(tctx, strcasecmp_m("foo", "Foo") == 0, "different case strings");
+	torture_assert(tctx, strcasecmp_m(NULL, "Foo") != 0, "one NULL");
+	torture_assert(tctx, strcasecmp_m("foo", NULL) != 0, "other NULL");
+	torture_assert(tctx, strcasecmp_m(NULL, NULL) == 0, "both NULL");
+	return true;
+}
+
+
+static bool test_strequal_w(struct torture_context *tctx)
+{
+	torture_assert(tctx, !strequal_w("foo", "bar"), "different strings");
+	torture_assert(tctx, strequal_w("foo", "foo"), "same case strings");
+	torture_assert(tctx, strequal_w("foo", "Foo"), "different case strings");
+	torture_assert(tctx, !strequal_w(NULL, "Foo"), "one NULL");
+	torture_assert(tctx, !strequal_w("foo", NULL), "other NULL");
+	torture_assert(tctx, strequal_w(NULL, NULL), "both NULL");
+	return true;
+}
+
+static bool test_strcsequal_w(struct torture_context *tctx)
+{
+	torture_assert(tctx, !strcsequal_w("foo", "bar"), "different strings");
+	torture_assert(tctx, strcsequal_w("foo", "foo"), "same case strings");
+	torture_assert(tctx, !strcsequal_w("foo", "Foo"), "different case strings");
+	torture_assert(tctx, !strcsequal_w(NULL, "Foo"), "one NULL");
+	torture_assert(tctx, !strcsequal_w("foo", NULL), "other NULL");
+	torture_assert(tctx, strcsequal_w(NULL, NULL), "both NULL");
+	return true;
+}
+
+static bool test_string_replace_w(struct torture_context *tctx)
+{
+	char data[] = "bla";
+	string_replace_w(data, 'b', 'c');
+	torture_assert_str_equal(tctx, data, "cla", "first char replaced");
+	memcpy(data, "bab", 4);
+	string_replace_w(data, 'b', 'c');
+	torture_assert_str_equal(tctx, data, "cac", "other chars replaced");
+	memcpy(data, "bba", 4);
+	string_replace_w(data, 'b', 'c');
+	torture_assert_str_equal(tctx, data, "cca", "other chars replaced");
+	memcpy(data, "blala", 6);
+	string_replace_w(data, 'o', 'c');
+	torture_assert_str_equal(tctx, data, "blala", "no chars replaced");
+	string_replace_w(NULL, 'b', 'c');
+	return true;
+}
+
+static bool test_strncasecmp_m(struct torture_context *tctx)
+{
+	torture_assert(tctx, strncasecmp_m("foo", "bar", 3) != 0, "different strings");
+	torture_assert(tctx, strncasecmp_m("foo", "foo", 3) == 0, "same case strings");
+	torture_assert(tctx, strncasecmp_m("foo", "Foo", 3) == 0, "different case strings");
+	torture_assert(tctx, strncasecmp_m("fool", "Foo", 3) == 0, "different case strings");
+	torture_assert(tctx, strncasecmp_m("fool", "Fool", 40) == 0, "over size");
+	torture_assert(tctx, strncasecmp_m("BLA", "Fool", 0) == 0, "empty");
+	torture_assert(tctx, strncasecmp_m(NULL, "Foo", 3) != 0, "one NULL");
+	torture_assert(tctx, strncasecmp_m("foo", NULL, 3) != 0, "other NULL");
+	torture_assert(tctx, strncasecmp_m(NULL, NULL, 3) == 0, "both NULL");
+	return true;
+}
+
+
+
+static bool test_next_token(struct torture_context *tctx)
+{
+	const char *teststr = "foo bar bla";
+	char buf[20];
+	torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "foo", "token matches");
+	torture_assert_str_equal(tctx, teststr, "bar bla", "ptr modified correctly");
+
+	torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "bar", "token matches");
+	torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly");
+
+	torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "bla", "token matches");
+	torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly");
+
+	torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work");
+	return true;
+}
+
+static bool test_next_token_seps(struct torture_context *tctx)
+{
+	const char *teststr = ",foo bla";
+	char buf[20];
+	torture_assert(tctx, next_token(&teststr, buf, ",", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "foo bla", "token matches");
+	torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly");
+
+	torture_assert(tctx, !next_token(&teststr, buf, ",", 20), "finding token doesn't work");
+	return true;
+}
+
+static bool test_next_token_quotes(struct torture_context *tctx)
+{
+	const char *teststr = "\"foo bar\" bla";
+	char buf[20];
+	torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "foo bar", "token matches");
+	torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly");
+
+	torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "bla", "token matches");
+	torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly");
+
+	torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work");
+	return true;
+}
+
+static bool test_next_token_quote_wrong(struct torture_context *tctx)
+{
+	const char *teststr = "\"foo bar bla";
+	char buf[20];
+	torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works");
+	torture_assert_str_equal(tctx, buf, "foo bar bla", "token matches");
+	torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly");
+
+	torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work");
+	return true;
+}
+
+static bool test_strlen_m(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, strlen_m("foo"), 3, "simple len");
+	torture_assert_int_equal(tctx, strlen_m("foo\x83l"), 6, "extended len");
+	torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL");
+	return true;
+}
+
+static bool test_strlen_m_term(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, strlen_m_term("foo"), 4, "simple len");
+	torture_assert_int_equal(tctx, strlen_m_term("foo\x83l"), 7, "extended len");
+	torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL");
+	return true;
+}
+
+static bool test_strhaslower(struct torture_context *tctx)
+{
+	torture_assert(tctx, strhaslower("a"), "one low char");
+	torture_assert(tctx, strhaslower("aB"), "one low, one up char");
+	torture_assert(tctx, !strhaslower("B"), "one up char");
+	torture_assert(tctx, !strhaslower(""), "empty string");
+	torture_assert(tctx, !strhaslower("3"), "one digit");
+	return true;
+}
+
+static bool test_strhasupper(struct torture_context *tctx)
+{
+	torture_assert(tctx, strhasupper("B"), "one up char");
+	torture_assert(tctx, strhasupper("aB"), "one low, one up char");
+	torture_assert(tctx, !strhasupper("a"), "one low char");
+	torture_assert(tctx, !strhasupper(""), "empty string");
+	torture_assert(tctx, !strhasupper("3"), "one digit");
+	return true;
+}
+
+struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx)
+{
+	struct torture_suite *suite = torture_suite_create(mem_ctx, "CHARSET");
+
+	torture_suite_add_simple_test(suite, "toupper_w", test_toupper_w);
+	torture_suite_add_simple_test(suite, "tolower_w", test_tolower_w);
+	torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi);
+	torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m);
+	torture_suite_add_simple_test(suite, "strequal_w", test_strequal_w);
+	torture_suite_add_simple_test(suite, "strcsequal_w", test_strcsequal_w);
+	torture_suite_add_simple_test(suite, "string_replace_w", test_string_replace_w);
+	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_quotes", test_next_token_quotes);
+	torture_suite_add_simple_test(suite, "next_token_seps", test_next_token_seps);
+	torture_suite_add_simple_test(suite, "next_token_quote_wrong", test_next_token_quote_wrong);
+	torture_suite_add_simple_test(suite, "strlen_m", test_strlen_m);
+	torture_suite_add_simple_test(suite, "strlen_m_term", test_strlen_m_term);
+	torture_suite_add_simple_test(suite, "strhaslower", test_strhaslower);
+	torture_suite_add_simple_test(suite, "strhasupper", test_strhasupper);
+
+	return suite;
+}

=== modified file 'source/lib/charset/util_unistr.c'
--- a/source/lib/charset/util_unistr.c	2007-01-10 11:47:27 +0000
+++ b/source/lib/charset/util_unistr.c	2007-03-05 00:07:27 +0000
@@ -251,11 +251,6 @@
  **/
 _PUBLIC_ BOOL strequal_w(const char *s1, const char *s2)
 {
-	if (s1 == s2)
-		return(True);
-	if (!s1 || !s2)
-		return(False);
-  
 	return strcasecmp_m(s1,s2) == 0;
 }
 
@@ -279,7 +274,7 @@
 **/
 _PUBLIC_ void string_replace_w(char *s, char oldc, char newc)
 {
-	for (; s && *s; s++) {
+	while (s && *s) {
 		size_t size;
 		codepoint_t c = next_codepoint(s, &size);
 		if (c == oldc) {

=== modified file 'source/torture/local/config.mk'
--- a/source/torture/local/config.mk	2007-03-04 22:36:41 +0000
+++ b/source/torture/local/config.mk	2007-03-05 00:07:27 +0000
@@ -26,6 +26,7 @@
 		../../lib/util/tests/strlist.o \
 		../../lib/util/tests/file.o \
 		../../lib/util/tests/genrand.o \
+		../../lib/charset/testsuite.o \
 		sddl.o \
 		../../lib/tdr/testsuite.o \
 		event.o \

=== modified file 'source/torture/local/local.c'
--- a/source/torture/local/local.c	2007-03-04 22:36:41 +0000
+++ b/source/torture/local/local.c	2007-03-05 00:07:27 +0000
@@ -45,6 +45,7 @@
 	torture_local_sddl,
 	torture_local_ndr, 
 	torture_local_tdr, 
+	torture_local_charset,
 	torture_local_event, 
 	torture_local_torture,
 	torture_local_dbspeed, 



More information about the samba-cvs mailing list