[PATCH] kernel32: added some basic tests for CompareString().

Yann Droneaud yann at droneaud.fr
Mon Mar 8 15:25:16 CST 2010


While trying to debug cmd.exe, valgrind found some problem in
CompareString() calls. Those tests help me to understand how
CompareString() is excepted to be called:
when string length is given NUL characters are ignored in this string.
---
 dlls/kernel32/tests/Makefile.in |    1 +
 dlls/kernel32/tests/string.c    |   81 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100644 dlls/kernel32/tests/string.c

diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in
index 452e690..7246016 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -31,6 +31,7 @@ C_SRCS = \
 	process.c \
 	profile.c \
 	resource.c \
+	string.c \
 	sync.c \
 	thread.c \
 	time.c \
diff --git a/dlls/kernel32/tests/string.c b/dlls/kernel32/tests/string.c
new file mode 100644
index 0000000..b885dda
--- /dev/null
+++ b/dlls/kernel32/tests/string.c
@@ -0,0 +1,81 @@
+/*
+ * Unit tests string function
+ *
+ * Copyright (C) 2010 Yann Droneaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "wine/test.h"
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "winnls.h"
+
+#define CLEN(name) ((sizeof(name)/sizeof(name[0])) - 1)
+
+static void test_CompareStringA(void)
+{
+  int ret;
+
+  char string1[] = "begin\0foo";
+  char string2[] = "begin";
+  char string3[] = "begin\0bar";
+
+  /* compare empty strings */
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, "", -1 , "", -1);
+  ok(ret == 2, "Empty string must match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, "", 0 , "", 0);
+  ok(ret == 2, "Empty string must match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, "", 1 , "", 1);
+  ok(ret == 2, "Empty string must match\n");
+
+  /* compare string */
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, string1, -1, string2, -1);
+  ok(ret == 2, "String must match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, string1, -1, string1, CLEN(string1));
+  ok(ret != 2 && ret != 0, "String must not match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, string1, CLEN(string1), string2, -1);
+  ok(ret != 2 && ret != 0, "String must not match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, string1, CLEN(string1), string3, CLEN(string3));
+  ok(ret != 2 && ret != 0, "String must not match\n");
+
+  /* compare fixed length */
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, "A\0", 2 , "A", 1);
+  ok(ret == 2, "Short string must match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, "AX", 2 , "AX", 1);
+  ok(ret != 2 && ret != 0, "Short string must not match\n");
+
+  ret = CompareStringA(LOCALE_SYSTEM_DEFAULT, 0, "AX", 1 , "A", 1);
+  ok(ret == 2, "Short string must match\n");
+}
+
+
+START_TEST(string)
+{
+  test_CompareStringA();
+}
-- 
1.6.2.5




More information about the wine-patches mailing list