1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPLv2+ - See COPYING in the top level directory
4  * PURPOSE:         Test for MultiByteToWideChar
5  * PROGRAMMERS:     Mike "tamlin" Nordell
6  *                  Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7  */
8 
9 #include "precomp.h"
10 
11 static ULONG OsVersion;
12 
13 /* NOTE: Tested on Win10. We follow Win10 in this function.
14          Win10 might alter its design in future. */
15 
16 /* TODO: Russian, French, Korean etc. codepages */
17 
18 #define CP932   932     /* Japanese Shift_JIS (SJIS) codepage */
19 
20 /* "Japanese" in Japanese UTF-8 */
21 static const char UTF8_Japanese[] = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E";
22 /* "Japanese" in Japanese Shift_JIS */
23 static const char SJIS_Japanese[] = "\x93\xFA\x96\x7B\x8C\xEA";
24 
25 #define MAX_BUFFER  10
26 
27 /* test entry */
28 typedef struct ENTRY
29 {
30     int LineNo;
31     ULONG VersionRange[2];
32     int Return;
33     DWORD Error;
34     UINT CodePage;
35     DWORD Flags;
36     const char *Src;
37     int SrcLen;
38     int DestLen;
39     WCHAR CheckDest[MAX_BUFFER];
40     int CheckLen;
41     BOOL SamePointer;
42 } ENTRY;
43 
44 static const ENTRY Entries[] =
45 {
46     /* without buffer */
47     { __LINE__, {0x000,0xA00}, 1, 0xBEAF, CP_UTF8, 0, "a", 1 },
48     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "a", 2 },
49     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, MB_ERR_INVALID_CHARS, "a", 2 },
50     /* negative length */
51     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "a", -1 },
52     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "a", -2 },
53     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, MB_ERR_INVALID_CHARS, "a", -1 },
54     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, MB_ERR_INVALID_CHARS, "a", -3 },
55     /* with buffer */
56     { __LINE__, {0x000,0xA00}, 1, 0xBEAF, CP_UTF8, 0, "a", 1, 1, {'a', 0x7F7F}, 2 },
57     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "a", 2, 4, {'a', 0, 0x7F7F}, 3 },
58     { __LINE__, {0x000,0xA00}, 2, 0xBEAF, CP_UTF8, MB_ERR_INVALID_CHARS, "a", 2, 4, {'a', 0, 0x7F7F}, 3 },
59     /* short buffer */
60     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "a", 2, 1, {'a', 0x7F7F}, 2 },
61     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "a", 2, 1, {'a', 0x7F7F}, 2 },
62     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "a", 2, 1, {'a', 0x7F7F}, 2 },
63     /* same pointer */
64     { __LINE__, {0x000,0xA00}, 0, ERROR_INVALID_PARAMETER, CP_UTF8, 0, "", 1, 1, { 0x7F7F }, 1, TRUE },
65     { __LINE__, {0x000,0xA00}, 0, ERROR_INVALID_PARAMETER, CP_UTF8, MB_ERR_INVALID_CHARS, "", 1, 1, { 0x7F7F }, 1, TRUE },
66     /* invalid UTF-8 sequences without buffer */
67     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xC0", 2 },
68     { __LINE__, {0x600,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "\xC0", 2 },
69     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xC0\xC0\x80", 4 },
70     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xC0\xC0\x80", 4 },
71     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xE0\xC0", 3 },
72     { __LINE__, {0x600,0xA00}, 3, 0xBEAF, CP_UTF8, 0, "\xE0\xC0", 3 },
73     { __LINE__, {0x000,0x502}, 2, 0xBEAF, CP_UTF8, 0, "\xE0\x20\xC0", 4 },
74     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xE0\x20\xC0", 4 },
75     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2", -1 },
76     { __LINE__, {0x600,0xA00}, 5, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2", -1 },
77     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2\x82", -1 },
78     { __LINE__, {0x600,0xA00}, 6, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2\x82", -1 },
79     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0", 2 },
80     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0\xC0\x80", 4 },
81     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\xC0", 3 },
82     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\x20\xC0", 4 },
83     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2", -1 },
84     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2\x82", -1 },
85     /* invalid UTF-8 sequences with buffer */
86     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xC0", 2, 4, {0x00, 0x7F7F, 0x7F7F}, 3},
87     { __LINE__, {0x600,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "\xC0", 2, 4, {0xFFFD, 0, 0x7F7F}, 3},
88     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xC0\xC0\x80", 4, 5, {0x00, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
89     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xC0\xC0\x80", 4, 5, {0xFFFD, 0xFFFD, 0xFFFD, 0, 0x7F7F}, 5 },
90     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xE0\xC0", 3, 4, {0, 0x7F7F, 0x7F7F, 0x7F7F}, 4 },
91     { __LINE__, {0x600,0xA00}, 3, 0xBEAF, CP_UTF8, 0, "\xE0\xC0", 3, 4, {0xFFFD, 0xFFFD, 0, 0x7F7F}, 4 },
92     { __LINE__, {0x000,0x502}, 2, 0xBEAF, CP_UTF8, 0, "\xE0\x20\xC0", 4, 5, {0x0020, 0, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
93     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xE0\x20\xC0", 4, 5, {0xFFFD, 0x0020, 0xFFFD, 0, 0x7F7F}, 5 },
94     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2", -1, 5, {0, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
95     { __LINE__, {0x600,0xA00}, 5, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2", -1, 5, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0}, 5 },
96     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2\x82", -1, 8, {0, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
97     { __LINE__, {0x600,0xA00}, 6, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2\x82", -1, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0}, 6 },
98     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0", 2, 4, {0x7F7F, 0x7F7F, 0x7F7F}, 3 },
99     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0", 2, 4, {0xFFFD, 0, 0x7F7F}, 3 },
100     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0\xC0\x80", 4, 5, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
101     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0\xC0\x80", 4, 5, {0xFFFD, 0xFFFD, 0xFFFD, 0, 0x7F7F}, 5 },
102     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\xC0", 3, 4, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 4 },
103     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\xC0", 3, 4, {0xFFFD, 0xFFFD, 0, 0x7F7F}, 4 },
104     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\x20\xC0", 4, 5, {0x0020, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
105     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\x20\xC0", 4, 5, {0xFFFD, 0x0020, 0xFFFD, 0, 0x7F7F}, 5 },
106     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2", -1, 6, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
107     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2", -1, 6, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0, 0x7F7F}, 6 },
108     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2\x82", -1, 7, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 7 },
109     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2\x82", -1, 7, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0, 0x7F7F}, 7 },
110     /* invalid UTF-8 sequences with short buffer */
111     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xC0", 2, 1, {0, 0x7F7F}, 2},
112     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\xC0", 2, 1, {0xFFFD, 0x7F7F}, 2},
113     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xC0\xC0\x80", 4, 1, {0, 0x7F7F}, 2 },
114     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\xC0\xC0\x80", 4, 1, {0xFFFD, 0x7F7F}, 2 },
115     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xE0\xC0", 3, 1, {0, 0x7F7F}, 2 },
116     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\xE0\xC0", 3, 1, {0xFFFD, 0x7F7F}, 2 },
117     { __LINE__, {0x000,0x502}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\xE0\x20\xC0", 4, 1, {0x0020, 0x7F7F}, 2 },
118     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\xE0\x20\xC0", 4, 1, {0xFFFD, 0x7F7F}, 2 },
119     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2", -1, 1, {0, 0x7F7F}, 2 },
120     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\x82\xA0\x82\xA2", -1, 1, {0xFFFD, 0x7F7F}, 2 },
121     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\x82\xA0\x82\xA2\x82", -1, 1, {0, 0x7F7F}, 2 },
122     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\x82\xA0\x82\xA2\x82", -1, 1, {0xFFFD, 0x7F7F}, 2 },
123     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0", 2, 1, {0x7F7F, 0x7F7F}, 2 },
124     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0", 2, 1, {0xFFFD, 0x7F7F}, 2 },
125     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0\xC0\x80", 4, 1, {0x7F7F, 0x7F7F}, 2 },
126     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "\xC0\xC0\x80", 4, 1, {0xFFFD, 0x7F7F}, 2 },
127     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\xC0", 3, 1, {0x7F7F, 0x7F7F}, 2 },
128     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\xC0", 3, 1, {0xFFFD, 0x7F7F}, 2 },
129     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\x20\xC0", 4, 1, {0x0020, 0x7F7F}, 2 },
130     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "\xE0\x20\xC0", 4, 1, {0xFFFD, 0x7F7F}, 2 },
131     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2", -1, 1, {0x7F7F, 0x7F7F}, 2 },
132     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2", -1, 1, {0xFFFD, 0x7F7F}, 2 },
133     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2\x82", -1, 1, {0x7F7F, 0x7F7F}, 2 },
134     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, "\x82\xA0\x82\xA2\x82", -1, 1, {0xFFFD, 0x7F7F}, 2 },
135     /* Japanese UTF-8 without buffer */
136     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP_UTF8, 0, UTF8_Japanese, sizeof(UTF8_Japanese) },
137     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP_UTF8, MB_ERR_INVALID_CHARS, UTF8_Japanese, sizeof(UTF8_Japanese) },
138     /* Japanese UTF-8 with buffer */
139     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP_UTF8, 0, UTF8_Japanese, sizeof(UTF8_Japanese), 4, {0x65E5, 0x672C, 0x8A9E, 0, 0x7F7F}, 5 },
140     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP_UTF8, MB_ERR_INVALID_CHARS, UTF8_Japanese, sizeof(UTF8_Japanese), 4, {0x65E5, 0x672C, 0x8A9E, 0, 0x7F7F}, 5 },
141     /* Japanese UTF-8 with short buffer */
142     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, UTF8_Japanese, sizeof(UTF8_Japanese), 1, {0x65E5, 0x7F7F}, 2 },
143     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, MB_ERR_INVALID_CHARS, UTF8_Japanese, sizeof(UTF8_Japanese), 1, {0x65E5, 0x7F7F}, 2 },
144     /* Japanese UTF-8 truncated source */
145     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, UTF8_Japanese, 1, 4, {0x7F7F, 0x7F7F}, 2 },
146     { __LINE__, {0x600,0xA00}, 1, 0xBEAF, CP_UTF8, 0, UTF8_Japanese, 1, 4, {0xFFFD, 0x7F7F}, 2 },
147     { __LINE__, {0x000,0x502}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, UTF8_Japanese, 1, 4, {0x7F7F, 0x7F7F}, 2 },
148     { __LINE__, {0x600,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP_UTF8, MB_ERR_INVALID_CHARS, UTF8_Japanese, 1, 4, {0xFFFD, 0x7F7F}, 2 },
149     /* Japanese CP932 without buffer */
150     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP932, 0, SJIS_Japanese, sizeof(SJIS_Japanese) },
151     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP932, MB_ERR_INVALID_CHARS, SJIS_Japanese, sizeof(SJIS_Japanese) },
152     /* Japanese CP932 with buffer */
153     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP932, 0, SJIS_Japanese, sizeof(SJIS_Japanese), 4, {0x65E5, 0x672C, 0x8A9E, 0, 0x7F7F}, 5 },
154     { __LINE__, {0x000,0xA00}, 4, 0xBEAF, CP932, MB_ERR_INVALID_CHARS, SJIS_Japanese, sizeof(SJIS_Japanese), 4, {0x65E5, 0x672C, 0x8A9E, 0, 0x7F7F}, 5 },
155     /* Japanese CP932 with short buffer */
156     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP932, 0, SJIS_Japanese, sizeof(SJIS_Japanese), 1, {0x65E5, 0x7F7F}, 2 },
157     { __LINE__, {0x000,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP932, MB_ERR_INVALID_CHARS, SJIS_Japanese, sizeof(SJIS_Japanese), 1, {0x65E5, 0x7F7F}, 2 },
158     /* Japanese CP932 truncated source */
159     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP932, 0, SJIS_Japanese, 1, 4, {0, 0x7F7F}, 2 },
160     { __LINE__, {0x600,0xA00}, 1, 0xBEAF, CP932, 0, SJIS_Japanese, 1, 4, {0x30FB, 0x7F7F}, 2 },
161     { __LINE__, {0x000,0xA00}, 0, ERROR_NO_UNICODE_TRANSLATION, CP932, MB_ERR_INVALID_CHARS, SJIS_Japanese, 1, 4, {0x7F7F, 0x7F7F}, 2 },
162     /* invalid 5-byte UTF-8 sequences */
163     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 1, 8, {0x7F7F, 0x7F7F}, 2 },
164     { __LINE__, {0x600,0xA00}, 1, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 1, 8, {0xFFFD, 0x7F7F}, 2 },
165     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 2, 8, {0x7F7F, 0x7F7F, 0x7F7F}, 3 },
166     { __LINE__, {0x600,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 2, 8, {0xFFFD, 0xFFFD, 0x7F7F}, 3 },
167     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 3, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 4 },
168     { __LINE__, {0x600,0xA00}, 3, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 3, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 4 },
169     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 4, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
170     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 4, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 5 },
171     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 5, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
172     { __LINE__, {0x600,0xA00}, 5, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 5, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 6 },
173     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 6, 8, {0, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
174     { __LINE__, {0x600,0xA00}, 6, 0xBEAF, CP_UTF8, 0, "\xF8\xA3\xA3\xA3\xA3", 6, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0}, 6 },
175     /* invalid 6-byte UTF-8 sequences */
176     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 1, 8, {0x7F7F, 0x7F7F}, 2 },
177     { __LINE__, {0x600,0xA00}, 1, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 1, 8, {0xFFFD, 0x7F7F}, 2 },
178     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 2, 8, {0x7F7F, 0x7F7F, 0x7F7F}, 3 },
179     { __LINE__, {0x600,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 2, 8, {0xFFFD, 0xFFFD, 0x7F7F}, 3 },
180     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 3, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 4 },
181     { __LINE__, {0x600,0xA00}, 3, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 3, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 4 },
182     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 4, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
183     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 4, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 5 },
184     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 5, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
185     { __LINE__, {0x600,0xA00}, 5, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 5, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 6 },
186     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 6, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 7 },
187     { __LINE__, {0x600,0xA00}, 6, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 6, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 7 },
188     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 7, 8, {0, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 7 },
189     { __LINE__, {0x600,0xA00}, 7, 0xBEAF, CP_UTF8, 0, "\xFC\xA3\xA3\xA3\xA3\xA3", 7, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0}, 7 },
190     /* invalid 7-byte UTF-8 sequences */
191     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 1, 8, {0x7F7F, 0x7F7F}, 2 },
192     { __LINE__, {0x600,0xA00}, 1, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 1, 8, {0xFFFD, 0x7F7F}, 2 },
193     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 2, 8, {0x7F7F, 0x7F7F, 0x7F7F}, 3 },
194     { __LINE__, {0x600,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 2, 8, {0xFFFD, 0xFFFD, 0x7F7F}, 3 },
195     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 3, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 4 },
196     { __LINE__, {0x600,0xA00}, 3, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 3, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 4 },
197     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 4, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
198     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 4, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 5 },
199     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 5, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
200     { __LINE__, {0x600,0xA00}, 5, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 5, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 6 },
201     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 6, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 7 },
202     { __LINE__, {0x600,0xA00}, 6, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 6, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 7 },
203     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 7, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 8 },
204     { __LINE__, {0x600,0xA00}, 7, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 7, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 8 },
205     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 8, 8, {0, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 8 },
206     { __LINE__, {0x600,0xA00}, 8, 0xBEAF, CP_UTF8, 0, "\xFE\xA3\xA3\xA3\xA3\xA3\xA3", 8, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0}, 8 },
207     /* invalid UTF-8 sequences */
208     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 1, 8, {0x7F7F, 0x7F7F}, 2 },
209     { __LINE__, {0x600,0xA00}, 1, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 1, 8, {0xFFFD, 0x7F7F}, 2 },
210     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 2, 8, {0x7F7F, 0x7F7F, 0x7F7F}, 3 },
211     { __LINE__, {0x600,0xA00}, 2, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 2, 8, {0xFFFD, 0xFFFD, 0x7F7F}, 3 },
212     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 3, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 4 },
213     { __LINE__, {0x600,0xA00}, 3, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 3, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 4 },
214     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 4, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 5 },
215     { __LINE__, {0x600,0xA00}, 4, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 4, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 5 },
216     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 5, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 6 },
217     { __LINE__, {0x600,0xA00}, 5, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 5, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 6 },
218     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 6, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 7 },
219     { __LINE__, {0x600,0xA00}, 6, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 6, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 7 },
220     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 7, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 8 },
221     { __LINE__, {0x600,0xA00}, 7, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 7, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 8 },
222     { __LINE__, {0x000,0x502}, 0, ERROR_SUCCESS, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 8, 8, {0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 9 },
223     { __LINE__, {0x600,0xA00}, 8, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 8, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 9 },
224     { __LINE__, {0x000,0x502}, 1, 0xBEAF, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 9, 8, {0, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F, 0x7F7F}, 9 },
225     { __LINE__, {0x600,0xA00}, 0, ERROR_INSUFFICIENT_BUFFER, CP_UTF8, 0, "\xFF\xA3\xA3\xA3\xA3\xA3\xA3\xA3", 9, 8, {0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x7F7F}, 9 },
226 };
227 
228 static void TestEntry(const ENTRY *pEntry)
229 {
230     int ret, i;
231     WCHAR Buffer[MAX_BUFFER];
232     DWORD Error;
233 
234     if ((OsVersion < pEntry->VersionRange[0]) ||
235         (OsVersion > pEntry->VersionRange[1]))
236     {
237         skip("Skipping entry from line %u (Version range %lx-%lx, current %lx)\n",
238              pEntry->LineNo,
239              pEntry->VersionRange[0],
240              pEntry->VersionRange[1],
241              OsVersion);
242         return;
243     }
244 
245     FillMemory(Buffer, sizeof(Buffer), 0x7F);
246     SetLastError(0xBEAF);
247 
248     if (pEntry->DestLen == 0)
249     {
250         /* dest is NULL */
251         ret = MultiByteToWideChar(pEntry->CodePage, pEntry->Flags, pEntry->Src,
252                                   pEntry->SrcLen, NULL, 0);
253     }
254     else
255     {
256         ok(pEntry->DestLen >= pEntry->CheckLen - 1,
257            "Line %d: DestLen was shorter than (CheckLen - 1)\n", pEntry->LineNo);
258 
259         if (pEntry->SamePointer)
260         {
261             /* src ptr == dest ptr */
262             ret = MultiByteToWideChar(pEntry->CodePage, pEntry->Flags,
263                                       (const char *)Buffer, pEntry->SrcLen,
264                                       Buffer, pEntry->DestLen);
265         }
266         else
267         {
268             /* src ptr != dest ptr */
269             ret = MultiByteToWideChar(pEntry->CodePage, pEntry->Flags,
270                                       pEntry->Src, pEntry->SrcLen,
271                                       Buffer, pEntry->DestLen);
272         }
273     }
274 
275     Error = GetLastError();
276 
277     /* check ret */
278     ok(ret == pEntry->Return, "Line %d: ret expected %d, got %d\n",
279        pEntry->LineNo, pEntry->Return, ret);
280 
281     /* check error code */
282     ok(Error == pEntry->Error,
283        "Line %d: Wrong last error. Expected %lu, got %lu\n",
284        pEntry->LineNo, pEntry->Error, Error);
285 
286     if (pEntry->DestLen)
287     {
288         /* check buffer */
289         for (i = 0; i < pEntry->CheckLen; ++i)
290         {
291             ok(Buffer[i] == pEntry->CheckDest[i], "Line %d: Buffer[%d] expected %d, got %d\n",
292                pEntry->LineNo, i, pEntry->CheckDest[i], Buffer[i]);
293         }
294     }
295 }
296 
297 START_TEST(MultiByteToWideChar)
298 {
299     RTL_OSVERSIONINFOW vi;
300     size_t i;
301 
302     vi.dwOSVersionInfoSize = sizeof(vi);
303     if (RtlGetVersion(&vi) < 0)
304     {
305         skip("Failed to get OS version!\n");
306         return;
307     }
308 
309     OsVersion = (vi.dwMajorVersion << 8) | vi.dwMinorVersion;
310 
311     for (i = 0; i < _countof(Entries); ++i)
312     {
313         TestEntry(&Entries[i]);
314     }
315 }
316