ReactOS  0.4.15-dev-3173-g40ee59d
RtlUnicodeToOemN.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: 0BSD (https://spdx.org/licenses/0BSD.html)
4  * PURPOSE: Test for RtlUnicodeToOemN
5  * COPYRIGHT: Copyright 2021 Jérôme Gardou <jerome.gardou@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 static const struct
11 {
14  struct
15  {
20  } Test[10];
21 } TestData[] =
22 {
23  {
24  1252, 1252, /* Western SBCS */
25  {
26  {
27  L"ABCDEF",
29  6,
30  "ABCDEF"
31  },
32  {
33  L"ABCDEF",
35  6,
36  "ABCDEF\xAA\xAA\xAA"
37  },
38  {
39  L"ABCDEF",
41  3,
42  "ABC"
43  },
44  {
45  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
47  6,
48  "??????"
49  },
50  {
51  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
53  3,
54  "???"
55  },
56  }
57  },
58  {
59  1252, 932, /* Western SBCS - Modified SJIS */
60  {
61  {
62  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
64  12,
65  "\x83\x66\x83\x58\x83\x4e\x83\x67\x83\x62\x83\x76"
66  },
67  {
68  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
70  12,
71  "\x83\x66\x83\x58\x83\x4e\x83\x67\x83\x62\x83\x76\xAA\xAA\xAA"
72  },
73  }
74  },
75  {
76  932, 1252, /* Modified SJIS - Western SBCS */
77  {
78  {
79  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
81  6,
82  "??????"
83  },
84  {
85  L"\u30c7\u30b9\u30afABC",
87  6,
88  "???ABC"
89  },
90  {
91  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
93  3,
94  "???"
95  },
96  }
97  },
98  {
99  932, 932, /* Modified SJIS - Modified SJIS */
100  {
101  {
102  L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
104  12,
105  "\x83\x66\x83\x58\x83\x4e\x83\x67\x83\x62\x83\x76"
106  }
107  }
108  },
109 };
110 
112 {
113  ULONG Length;
114  LPSTR StrOem;
115  ULONG ResultSize;
117  CHAR OemBuffer[4];
118 
119  /* Basic things */
120  Status = RtlUnicodeToOemN(NULL, 0, NULL, NULL, 0);
122 
123  Status = RtlUnicodeToOemN(NULL, 0, NULL, L"ABCDEF", 0);
125 
126  Status = RtlUnicodeToOemN(NULL, 0, NULL, NULL, 2);
128 
129  Status = RtlUnicodeToOemN(NULL, 0, NULL, L"A", 2);
131 
132  Status = RtlUnicodeToOemN(NULL, 0, NULL, L"A", 2);
134 
135  StartSeh()
136  Status = RtlUnicodeToOemN(NULL, 1, NULL, L"A", 2);
138 
139  OemBuffer[0] = 0xAA;
140  OemBuffer[1] = 0xAA;
141  Status = RtlUnicodeToOemN(OemBuffer, 1, NULL, L"A", 2);
143  ok_char(OemBuffer[0], 'A');
144  ok_char(OemBuffer[1], (CHAR)0xAA);
145 
146  OemBuffer[0] = 0xAA;
147  OemBuffer[1] = 0xAA;
148  Status = RtlUnicodeToOemN(OemBuffer, 1, NULL, L"AB", 4);
150  ok_char(OemBuffer[0], 'A');
151  ok_char(OemBuffer[1], (CHAR)0xAA);
152 
153  OemBuffer[0] = 0xAA;
154  OemBuffer[1] = 0xAA;
155  Status = RtlUnicodeToOemN(OemBuffer, 2, NULL, L"A", 4);
157  ok_char(OemBuffer[0], 'A');
158  ok_char(OemBuffer[1], '\0');
159 
160  /* RtlUnicodeToOemN doesn't care about string termination */
161  OemBuffer[0] = 0xAA;
162  OemBuffer[1] = 0xAA;
163  Status = RtlUnicodeToOemN(OemBuffer, 1, NULL, L"A", 4);
165  ok_char(OemBuffer[0], 'A');
166  ok_char(OemBuffer[1], (CHAR)0xAA);
167 
168  OemBuffer[0] = 0xAA;
169  OemBuffer[1] = 0xAA;
170  OemBuffer[2] = 0xAA;
171  OemBuffer[3] = 0xAA;
172  Status = RtlUnicodeToOemN(OemBuffer, 4, NULL, L"A\0B", 8);
174  ok_char(OemBuffer[0], 'A');
175  ok_char(OemBuffer[1], '\0');
176  ok_char(OemBuffer[2], 'B');
177  ok_char(OemBuffer[3], '\0');
178 
179  /* Odd Unicode buffer size */
180  OemBuffer[0] = 0xAA;
181  OemBuffer[1] = 0xAA;
182  OemBuffer[2] = 0xAA;
183  OemBuffer[3] = 0xAA;
184  Status = RtlUnicodeToOemN(OemBuffer, 2, NULL, L"AB", 5);
186  ok_char(OemBuffer[0], 'A');
187  ok_char(OemBuffer[1], 'B');
188  ok_char(OemBuffer[2], (CHAR)0xAA);
189  ok_char(OemBuffer[3], (CHAR)0xAA);
190 
191  /* Odd Unicode buffer size */
192  OemBuffer[0] = 0xAA;
193  OemBuffer[1] = 0xAA;
194  OemBuffer[2] = 0xAA;
195  OemBuffer[3] = 0xAA;
196  Status = RtlUnicodeToOemN(OemBuffer, 3, NULL, L"AB", 5);
198  ok_char(OemBuffer[0], 'A');
199  ok_char(OemBuffer[1], 'B');
200  ok_char(OemBuffer[2], (CHAR)0xAA);
201  ok_char(OemBuffer[3], (CHAR)0xAA);
202 
203  for (int i = 0; i < _countof(TestData); i++)
204  {
206 
207  for (int j = 0; TestData[i].Test[j].StrW != NULL; j++)
208  {
210  StrOem = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length + 1);
211 
212  memset(StrOem, 0xAA, Length + 1);
213  ResultSize = 0x0BADF00D;
214 
216  Length,
217  &ResultSize,
218  TestData[i].Test[j].StrW,
219  wcslen(TestData[i].Test[j].StrW) * sizeof(WCHAR));
220 
222  ok_long(ResultSize, TestData[i].Test[j].ReturnedSize);
223  for (int k = 0; k < ResultSize; k++)
224  {
225  ok(StrOem[k] == TestData[i].Test[j].StrOem[k],
226  "Wrong char \\x%02x, expected TestData[%u].Test[%u].StrOem[%u] (\\x%02x)\n",
227  StrOem[k], i, j, k, TestData[i].Test[j].StrOem[k]);
228  }
229  for (int k = ResultSize; k < (Length + 1); k++)
230  {
231  ok_char(StrOem[k], (CHAR)0xAA);
232  }
233 
234  RtlFreeHeap(RtlGetProcessHeap(), 0, StrOem);
235  }
236  }
237 }
ULONG ReturnedSize
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
ULONG AnsiCp
void SetupLocale(ULONG AnsiCode, ULONG OemCode, ULONG Unicode)
Definition: IsTextUnicode.c:38
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
LPCSTR StrOem
LPCWSTR StrW
START_TEST(RtlUnicodeToOemN)
char * LPSTR
Definition: xmlstorage.h:182
#define ok_long(expression, result)
Definition: atltest.h:133
#define StartSeh()
Definition: _sntprintf.h:16
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToOemN(PCHAR OemString, ULONG OemSize, PULONG ResultSize, PCWCH UnicodeString, ULONG UnicodeSize)
#define ok_char(expression, result)
Definition: atltest.h:122
const char * LPCSTR
Definition: xmlstorage.h:183
ULONG OemCp
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSTATUS Status
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define memset(x, y, z)
Definition: compat.h:39
int k
Definition: mpi.c:3369
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17