~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/kernel32/tests/codepage.c

Version: ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Unit tests for code page to/from unicode translations
  3  *
  4  * Copyright (c) 2002 Dmitry Timoshkov
  5  *
  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.
 10  *
 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.
 15  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include <stdarg.h>
 22 #include <limits.h>
 23 
 24 #include "wine/test.h"
 25 #include "windef.h"
 26 #include "winbase.h"
 27 #include "winnls.h"
 28 
 29 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
 30 
 31 static void test_destination_buffer(void)
 32 {
 33     LPSTR   buffer;
 34     INT     maxsize;
 35     INT     needed;
 36     INT     len;
 37 
 38     SetLastError(0xdeadbeef);
 39     needed = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, NULL, 0, NULL, NULL);
 40     ok( (needed > 0), "returned %d with %u (expected '> 0')\n",
 41         needed, GetLastError());
 42 
 43     maxsize = needed*2;
 44     buffer = HeapAlloc(GetProcessHeap(), 0, maxsize);
 45     if (buffer == NULL) return;
 46 
 47     maxsize--;
 48     memset(buffer, 'x', maxsize);
 49     buffer[maxsize] = '\0';
 50     SetLastError(0xdeadbeef);
 51     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buffer, needed+1, NULL, NULL);
 52     ok( (len > 0), "returned %d with %u and '%s' (expected '> 0')\n",
 53         len, GetLastError(), buffer);
 54 
 55     memset(buffer, 'x', maxsize);
 56     buffer[maxsize] = '\0';
 57     SetLastError(0xdeadbeef);
 58     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buffer, needed, NULL, NULL);
 59     ok( (len > 0), "returned %d with %u and '%s' (expected '> 0')\n",
 60         len, GetLastError(), buffer);
 61 
 62     memset(buffer, 'x', maxsize);
 63     buffer[maxsize] = '\0';
 64     SetLastError(0xdeadbeef);
 65     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buffer, needed-1, NULL, NULL);
 66     ok( !len && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
 67         "returned %d with %u and '%s' (expected '' with "
 68         "ERROR_INSUFFICIENT_BUFFER)\n", len, GetLastError(), buffer);
 69 
 70     memset(buffer, 'x', maxsize);
 71     buffer[maxsize] = '\0';
 72     SetLastError(0xdeadbeef);
 73     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buffer, 1, NULL, NULL);
 74     ok( !len && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
 75         "returned %d with %u and '%s' (expected '' with "
 76         "ERROR_INSUFFICIENT_BUFFER)\n", len, GetLastError(), buffer);
 77 
 78     SetLastError(0xdeadbeef);
 79     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buffer, 0, NULL, NULL);
 80     ok( (len > 0), "returned %d with %u (expected '> 0')\n",
 81         len, GetLastError());
 82 
 83     SetLastError(0xdeadbeef);
 84     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, NULL, needed, NULL, NULL);
 85     ok( !len && (GetLastError() == ERROR_INVALID_PARAMETER),
 86         "returned %d with %u (expected '' with "
 87         "ERROR_INVALID_PARAMETER)\n", len, GetLastError());
 88 
 89     HeapFree(GetProcessHeap(), 0, buffer);
 90 }
 91 
 92 
 93 static void test_null_source(void)
 94 {
 95     int len;
 96     DWORD GLE;
 97 
 98     SetLastError(0);
 99     len = WideCharToMultiByte(CP_ACP, 0, NULL, 0, NULL, 0, NULL, NULL);
100     GLE = GetLastError();
101     ok(!len && GLE == ERROR_INVALID_PARAMETER,
102         "WideCharToMultiByte returned %d with GLE=%u (expected 0 with ERROR_INVALID_PARAMETER)\n",
103         len, GLE);
104 
105     SetLastError(0);
106     len = WideCharToMultiByte(CP_ACP, 0, NULL, -1, NULL, 0, NULL, NULL);
107     GLE = GetLastError();
108     ok(!len && GLE == ERROR_INVALID_PARAMETER,
109         "WideCharToMultiByte returned %d with GLE=%u (expected 0 with ERROR_INVALID_PARAMETER)\n",
110         len, GLE);
111 }
112 
113 /* lstrcmpW is not supported on Win9x! */
114 static int mylstrcmpW(const WCHAR* str1, const WCHAR* str2)
115 {
116     while (*str1 && *str1==*str2) {
117         str1++;
118         str2++;
119     }
120     return *str1-*str2;
121 }
122 
123 static void test_negative_source_length(void)
124 {
125     int len;
126     char buf[10];
127     WCHAR bufW[10];
128 
129     /* Test, whether any negative source length works as strlen() + 1 */
130     SetLastError( 0xdeadbeef );
131     memset(buf,'x',sizeof(buf));
132     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -2002, buf, 10, NULL, NULL);
133     ok(len == 7 && !lstrcmpA(buf, "foobar") && GetLastError() == 0xdeadbeef,
134        "WideCharToMultiByte(-2002): len=%d error=%u\n", len, GetLastError());
135 
136     SetLastError( 0xdeadbeef );
137     memset(bufW,'x',sizeof(bufW));
138     len = MultiByteToWideChar(CP_ACP, 0, "foobar", -2002, bufW, 10);
139     ok(len == 7 && !mylstrcmpW(bufW, foobarW) && GetLastError() == 0xdeadbeef,
140        "MultiByteToWideChar(-2002): len=%d error=%u\n", len, GetLastError());
141 
142     SetLastError(0xdeadbeef);
143     memset(bufW, 'x', sizeof(bufW));
144     len = MultiByteToWideChar(CP_ACP, 0, "foobar", -1, bufW, 6);
145     ok(len == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
146        "MultiByteToWideChar(-1): len=%d error=%u\n", len, GetLastError());
147 }
148 
149 #define LONGBUFLEN 100000
150 static void test_negative_dest_length(void)
151 {
152     int len, i;
153     static char buf[LONGBUFLEN];
154     static WCHAR originalW[LONGBUFLEN];
155     static char originalA[LONGBUFLEN];
156     DWORD theError;
157 
158     /* Test return on -1 dest length */
159     SetLastError( 0xdeadbeef );
160     memset(buf,'x',sizeof(buf));
161     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, -1, NULL, NULL);
162     todo_wine {
163       ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
164          "WideCharToMultiByte(destlen -1): len=%d error=%x\n", len, GetLastError());
165     }
166 
167     /* Test return on -1000 dest length */
168     SetLastError( 0xdeadbeef );
169     memset(buf,'x',sizeof(buf));
170     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, -1000, NULL, NULL);
171     todo_wine {
172       ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
173          "WideCharToMultiByte(destlen -1000): len=%d error=%x\n", len, GetLastError());
174     }
175 
176     /* Test return on INT_MAX dest length */
177     SetLastError( 0xdeadbeef );
178     memset(buf,'x',sizeof(buf));
179     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, INT_MAX, NULL, NULL);
180     ok(len == 7 && !lstrcmpA(buf, "foobar") && GetLastError() == 0xdeadbeef,
181        "WideCharToMultiByte(destlen INT_MAX): len=%d error=%x\n", len, GetLastError());
182 
183     /* Test return on INT_MAX dest length and very long input */
184     SetLastError( 0xdeadbeef );
185     memset(buf,'x',sizeof(buf));
186     for (i=0; i < LONGBUFLEN - 1; i++) {
187         originalW[i] = 'Q';
188         originalA[i] = 'Q';
189     }
190     originalW[LONGBUFLEN-1] = 0;
191     originalA[LONGBUFLEN-1] = 0;
192     len = WideCharToMultiByte(CP_ACP, 0, originalW, -1, buf, INT_MAX, NULL, NULL);
193     theError = GetLastError();
194     ok(len == LONGBUFLEN && !lstrcmpA(buf, originalA) && theError == 0xdeadbeef,
195        "WideCharToMultiByte(srclen %d, destlen INT_MAX): len %d error=%x\n", LONGBUFLEN, len, theError);
196 
197 }
198 
199 static void test_overlapped_buffers(void)
200 {
201     static const WCHAR strW[] = {'j','u','s','t',' ','a',' ','t','e','s','t',0};
202     static const char strA[] = "just a test";
203     char buf[256];
204     int ret;
205 
206     memcpy((WCHAR *)(buf + 1), strW, sizeof(strW));
207     ret = WideCharToMultiByte(CP_ACP, 0, (WCHAR *)(buf + 1), -1, buf, sizeof(buf), NULL, NULL);
208     ok(ret == sizeof(strA), "unexpected ret %d\n", ret);
209     ok(!memcmp(buf, strA, sizeof(strA)), "conversion failed: %s\n", buf);
210 }
211 
212 START_TEST(codepage)
213 {
214     test_destination_buffer();
215     test_null_source();
216     test_negative_source_length();
217     test_negative_dest_length();
218     test_overlapped_buffers();
219 }
220 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.