Add a prototype code page test
Dmitry Timoshkov
dmitry at baikal.ru
Thu Oct 3 04:22:05 CDT 2002
Hello.
Changelog:
Add a prototype code page test. Fix issues regarding negative source
and destination length handling.
diff -u cvs/hq/wine/dlls/kernel/tests/.cvsignore wine/dlls/kernel/tests/.cvsignore
--- cvs/hq/wine/dlls/kernel/tests/.cvsignore Wed Oct 2 20:09:18 2002
+++ wine/dlls/kernel/tests/.cvsignore Thu Oct 3 17:54:53 2002
@@ -1,6 +1,7 @@
Makefile
alloc.ok
atom.ok
+codepage.ok
directory.ok
drive.ok
environ.ok
diff -u cvs/hq/wine/dlls/kernel/tests/Makefile.in wine/dlls/kernel/tests/Makefile.in
--- cvs/hq/wine/dlls/kernel/tests/Makefile.in Wed Oct 2 20:09:18 2002
+++ wine/dlls/kernel/tests/Makefile.in Thu Oct 3 17:55:16 2002
@@ -8,6 +8,7 @@
CTESTS = \
alloc.c \
atom.c \
+ codepage.c \
directory.c \
drive.c \
environ.c \
diff -u /dev/null wine/dlls/kernel/tests/codepage.c
--- /dev/null Wed May 6 05:32:27 1998
+++ wine/dlls/kernel/tests/codepage.c Thu Oct 3 18:03:49 2002
@@ -0,0 +1,63 @@
+/*
+ * Unit tests for code page to/from unicode translations
+ *
+ * Copyright (c) 2002 Dmitry Timoshkov
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "wine/test.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "winnls.h"
+
+static void test_WideChar_translations(void)
+{
+ int i, len;
+ char buf[10];
+ WCHAR bufW[10];
+ static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
+ static const WCHAR sampleW[10] = {'.','.','.','.','.','.','.','.','.','.'};
+
+ /* Test negative destination buffer length */
+ memset(buf, '.', 10);
+ SetLastError( 0xdeadbeef );
+ len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, -1, NULL, NULL);
+ ok(!len && !memcmp(buf, "..........", 10) && GetLastError() == ERROR_INVALID_PARAMETER,
+ "should return an error and not touch buffer");
+
+ memset(buf, '.', 10);
+ for (i = 0; i < 10; i++) bufW[i] = '.';
+ SetLastError( 0xdeadbeef );
+ len = MultiByteToWideChar(CP_ACP, 0, "foobar", -1, bufW, -1);
+ ok(!len && !memcmp(bufW, sampleW, 10 * sizeof(WCHAR)) && GetLastError() == ERROR_INVALID_PARAMETER,
+ "should return an error and not touch buffer");
+
+ /* Test, whether any negative value works as strlen() + 1 */
+ SetLastError( 0xdeadbeef );
+ len = WideCharToMultiByte(CP_ACP, 0, foobarW, -2002, buf, 10, NULL, NULL);
+ ok(len == 7 && !lstrcmpA(buf, "foobar") && GetLastError() == 0xdeadbeef,
+ "any negative value should work as strlen() + 1");
+
+ SetLastError( 0xdeadbeef );
+ len = MultiByteToWideChar(CP_ACP, 0, "foobar", -2002, bufW, 10);
+ ok(len == 7 && !lstrcmpW(bufW, foobarW) && GetLastError() == 0xdeadbeef,
+ "any negative value should work as strlenW() + 1");
+}
+
+START_TEST(codepage)
+{
+ test_WideChar_translations();
+}
diff -u cvs/hq/wine/memory/codepage.c wine/memory/codepage.c
--- cvs/hq/wine/memory/codepage.c Sat Aug 17 18:42:29 2002
+++ wine/memory/codepage.c Thu Oct 3 17:59:10 2002
@@ -305,13 +305,13 @@
const union cptable *table;
int ret;
- if (!src || (!dst && dstlen))
+ if (!src || (!dst && dstlen) || (dstlen < 0))
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
- if (srclen == -1) srclen = strlen(src) + 1;
+ if (srclen < 0) srclen = strlen(src) + 1;
if (flags & MB_USEGLYPHCHARS) FIXME("MB_USEGLYPHCHARS not supported\n");
@@ -380,13 +380,13 @@
const union cptable *table;
int ret, used_tmp;
- if (!src || (!dst && dstlen))
+ if (!src || (!dst && dstlen) || (dstlen < 0))
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
- if (srclen == -1) srclen = strlenW(src) + 1;
+ if (srclen < 0) srclen = strlenW(src) + 1;
switch(page)
{
More information about the wine-patches
mailing list