Add a test for handling overlapped buffers by WideCharToMultiByte.
[wine/multimedia.git] / dlls / kernel / tests / codepage.c
blob7f61f1d83cb94908c18c656a3c685e735b51f185
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 /* lstrcmpW is not supported on Win9x! */
29 static int mylstrcmpW(const WCHAR* str1, const WCHAR* str2)
31 while (*str1 && *str1==*str2) {
32 str1++;
33 str2++;
35 return *str1-*str2;
38 static void test_negative_source_length(void)
40 int len;
41 char buf[10];
42 WCHAR bufW[10];
43 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
45 /* Test, whether any negative source length works as strlen() + 1 */
46 SetLastError( 0xdeadbeef );
47 memset(buf,'x',sizeof(buf));
48 len = WideCharToMultiByte(CP_ACP, 0, foobarW, -2002, buf, 10, NULL, NULL);
49 ok(len == 7 && !lstrcmpA(buf, "foobar") && GetLastError() == 0xdeadbeef,
50 "WideCharToMultiByte(-2002): len=%d error=%ld\n",len,GetLastError());
52 SetLastError( 0xdeadbeef );
53 memset(bufW,'x',sizeof(bufW));
54 len = MultiByteToWideChar(CP_ACP, 0, "foobar", -2002, bufW, 10);
55 ok(len == 7 && !mylstrcmpW(bufW, foobarW) && GetLastError() == 0xdeadbeef,
56 "MultiByteToWideChar(-2002): len=%d error=%ld\n",len,GetLastError());
59 static void test_overlapped_buffers(void)
61 static const WCHAR strW[] = {'j','u','s','t',' ','a',' ','t','e','s','t',0};
62 static const char strA[] = "just a test";
63 char buf[256];
64 int ret;
66 lstrcpyW((WCHAR *)(buf + 1), strW);
67 ret = WideCharToMultiByte(CP_ACP, 0, (WCHAR *)(buf + 1), -1, buf, sizeof(buf), NULL, NULL);
68 ok(ret == sizeof(strA), "unexpected ret %d != %d\n", ret, sizeof(strA));
69 ok(!memcmp(buf, strA, sizeof(strA)), "conversion failed: %s\n", buf);
72 START_TEST(codepage)
74 test_negative_source_length();
75 test_overlapped_buffers();