Create a function to read a property as an integer.
[wine/hacks.git] / dlls / kernel / tests / codepage.c
blob5036d3aa6bb58d094ce641e72f5b18532f34a07d
1 /*
2 * Unit tests for code page to/from unicode translations
4 * Copyright (c) 2002 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnls.h"
28 static void test_null_source(void)
30 int len;
31 DWORD GLE;
33 SetLastError(0);
34 len = WideCharToMultiByte(CP_ACP, 0, NULL, 0, NULL, 0, NULL, NULL);
35 GLE = GetLastError();
36 ok(!len && GLE == ERROR_INVALID_PARAMETER,
37 "WideCharToMultiByte returned %d with GLE=%ld (expected 0 with ERROR_INVALID_PARAMETER)\n",
38 len, GLE);
41 /* lstrcmpW is not supported on Win9x! */
42 static int mylstrcmpW(const WCHAR* str1, const WCHAR* str2)
44 while (*str1 && *str1==*str2) {
45 str1++;
46 str2++;
48 return *str1-*str2;
51 static void test_negative_source_length(void)
53 int len;
54 char buf[10];
55 WCHAR bufW[10];
56 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
58 /* Test, whether any negative source length works as strlen() + 1 */
59 SetLastError( 0xdeadbeef );
60 memset(buf,'x',sizeof(buf));
61 len = WideCharToMultiByte(CP_ACP, 0, foobarW, -2002, buf, 10, NULL, NULL);
62 ok(len == 7 && !lstrcmpA(buf, "foobar") && GetLastError() == 0xdeadbeef,
63 "WideCharToMultiByte(-2002): len=%d error=%ld\n",len,GetLastError());
65 SetLastError( 0xdeadbeef );
66 memset(bufW,'x',sizeof(bufW));
67 len = MultiByteToWideChar(CP_ACP, 0, "foobar", -2002, bufW, 10);
68 ok(len == 7 && !mylstrcmpW(bufW, foobarW) && GetLastError() == 0xdeadbeef,
69 "MultiByteToWideChar(-2002): len=%d error=%ld\n",len,GetLastError());
72 static void test_overlapped_buffers(void)
74 static const WCHAR strW[] = {'j','u','s','t',' ','a',' ','t','e','s','t',0};
75 static const char strA[] = "just a test";
76 char buf[256];
77 int ret;
79 lstrcpyW((WCHAR *)(buf + 1), strW);
80 ret = WideCharToMultiByte(CP_ACP, 0, (WCHAR *)(buf + 1), -1, buf, sizeof(buf), NULL, NULL);
81 ok(ret == sizeof(strA), "unexpected ret %d != %d\n", ret, sizeof(strA));
82 ok(!memcmp(buf, strA, sizeof(strA)), "conversion failed: %s\n", buf);
85 START_TEST(codepage)
87 test_null_source();
88 test_negative_source_length();
89 test_overlapped_buffers();