14e0ce779SJérôme Gardou /*
24e0ce779SJérôme Gardou * PROJECT: ReactOS API tests
3*e944dfa7SHermès Bélusca-Maïto * LICENSE: 0BSD (https://spdx.org/licenses/0BSD)
44e0ce779SJérôme Gardou * PURPOSE: Test for RtlUnicodeToOemN
54e0ce779SJérôme Gardou * COPYRIGHT: Copyright 2021 Jérôme Gardou <jerome.gardou@reactos.org>
64e0ce779SJérôme Gardou */
74e0ce779SJérôme Gardou
84e0ce779SJérôme Gardou #include "precomp.h"
94e0ce779SJérôme Gardou
104e0ce779SJérôme Gardou static const struct
114e0ce779SJérôme Gardou {
124e0ce779SJérôme Gardou ULONG AnsiCp;
134e0ce779SJérôme Gardou ULONG OemCp;
144e0ce779SJérôme Gardou struct
154e0ce779SJérôme Gardou {
164e0ce779SJérôme Gardou LPCWSTR StrW;
174e0ce779SJérôme Gardou NTSTATUS Status;
184e0ce779SJérôme Gardou ULONG ReturnedSize;
194e0ce779SJérôme Gardou LPCSTR StrOem;
204e0ce779SJérôme Gardou } Test[10];
214e0ce779SJérôme Gardou } TestData[] =
224e0ce779SJérôme Gardou {
234e0ce779SJérôme Gardou {
244e0ce779SJérôme Gardou 1252, 1252, /* Western SBCS */
254e0ce779SJérôme Gardou {
264e0ce779SJérôme Gardou {
274e0ce779SJérôme Gardou L"ABCDEF",
284e0ce779SJérôme Gardou STATUS_SUCCESS,
294e0ce779SJérôme Gardou 6,
304e0ce779SJérôme Gardou "ABCDEF"
314e0ce779SJérôme Gardou },
324e0ce779SJérôme Gardou {
334e0ce779SJérôme Gardou L"ABCDEF",
344e0ce779SJérôme Gardou STATUS_SUCCESS,
354e0ce779SJérôme Gardou 6,
364e0ce779SJérôme Gardou "ABCDEF\xAA\xAA\xAA"
374e0ce779SJérôme Gardou },
384e0ce779SJérôme Gardou {
394e0ce779SJérôme Gardou L"ABCDEF",
404e0ce779SJérôme Gardou STATUS_BUFFER_OVERFLOW,
414e0ce779SJérôme Gardou 3,
424e0ce779SJérôme Gardou "ABC"
434e0ce779SJérôme Gardou },
444e0ce779SJérôme Gardou {
454e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
464e0ce779SJérôme Gardou STATUS_SUCCESS,
474e0ce779SJérôme Gardou 6,
484e0ce779SJérôme Gardou "??????"
494e0ce779SJérôme Gardou },
504e0ce779SJérôme Gardou {
514e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
524e0ce779SJérôme Gardou STATUS_BUFFER_OVERFLOW,
534e0ce779SJérôme Gardou 3,
544e0ce779SJérôme Gardou "???"
554e0ce779SJérôme Gardou },
564e0ce779SJérôme Gardou }
574e0ce779SJérôme Gardou },
584e0ce779SJérôme Gardou {
594e0ce779SJérôme Gardou 1252, 932, /* Western SBCS - Modified SJIS */
604e0ce779SJérôme Gardou {
614e0ce779SJérôme Gardou {
624e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
634e0ce779SJérôme Gardou STATUS_SUCCESS,
644e0ce779SJérôme Gardou 12,
654e0ce779SJérôme Gardou "\x83\x66\x83\x58\x83\x4e\x83\x67\x83\x62\x83\x76"
664e0ce779SJérôme Gardou },
674e0ce779SJérôme Gardou {
684e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
694e0ce779SJérôme Gardou STATUS_SUCCESS,
704e0ce779SJérôme Gardou 12,
714e0ce779SJérôme Gardou "\x83\x66\x83\x58\x83\x4e\x83\x67\x83\x62\x83\x76\xAA\xAA\xAA"
724e0ce779SJérôme Gardou },
734e0ce779SJérôme Gardou }
744e0ce779SJérôme Gardou },
754e0ce779SJérôme Gardou {
764e0ce779SJérôme Gardou 932, 1252, /* Modified SJIS - Western SBCS */
774e0ce779SJérôme Gardou {
784e0ce779SJérôme Gardou {
794e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
804e0ce779SJérôme Gardou STATUS_SUCCESS,
814e0ce779SJérôme Gardou 6,
824e0ce779SJérôme Gardou "??????"
834e0ce779SJérôme Gardou },
844e0ce779SJérôme Gardou {
854e0ce779SJérôme Gardou L"\u30c7\u30b9\u30afABC",
864e0ce779SJérôme Gardou STATUS_SUCCESS,
874e0ce779SJérôme Gardou 6,
884e0ce779SJérôme Gardou "???ABC"
894e0ce779SJérôme Gardou },
904e0ce779SJérôme Gardou {
914e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
924e0ce779SJérôme Gardou STATUS_BUFFER_OVERFLOW,
934e0ce779SJérôme Gardou 3,
944e0ce779SJérôme Gardou "???"
954e0ce779SJérôme Gardou },
964e0ce779SJérôme Gardou }
974e0ce779SJérôme Gardou },
984e0ce779SJérôme Gardou {
994e0ce779SJérôme Gardou 932, 932, /* Modified SJIS - Modified SJIS */
1004e0ce779SJérôme Gardou {
1014e0ce779SJérôme Gardou {
1024e0ce779SJérôme Gardou L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7",
1034e0ce779SJérôme Gardou STATUS_SUCCESS,
1044e0ce779SJérôme Gardou 12,
1054e0ce779SJérôme Gardou "\x83\x66\x83\x58\x83\x4e\x83\x67\x83\x62\x83\x76"
1064e0ce779SJérôme Gardou }
1074e0ce779SJérôme Gardou }
1084e0ce779SJérôme Gardou },
1094e0ce779SJérôme Gardou };
1104e0ce779SJérôme Gardou
START_TEST(RtlUnicodeToOemN)1114e0ce779SJérôme Gardou START_TEST(RtlUnicodeToOemN)
1124e0ce779SJérôme Gardou {
1134e0ce779SJérôme Gardou ULONG Length;
1144e0ce779SJérôme Gardou LPSTR StrOem;
1154e0ce779SJérôme Gardou ULONG ResultSize;
1164e0ce779SJérôme Gardou NTSTATUS Status;
1174e0ce779SJérôme Gardou CHAR OemBuffer[4];
1184e0ce779SJérôme Gardou
1194e0ce779SJérôme Gardou /* Basic things */
1204e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(NULL, 0, NULL, NULL, 0);
1214e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1224e0ce779SJérôme Gardou
1234e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(NULL, 0, NULL, L"ABCDEF", 0);
1244e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1254e0ce779SJérôme Gardou
1264e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(NULL, 0, NULL, NULL, 2);
1274e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_BUFFER_OVERFLOW);
1284e0ce779SJérôme Gardou
1294e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(NULL, 0, NULL, L"A", 2);
1304e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_BUFFER_OVERFLOW);
1314e0ce779SJérôme Gardou
1324e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(NULL, 0, NULL, L"A", 2);
1334e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_BUFFER_OVERFLOW);
1344e0ce779SJérôme Gardou
1354e0ce779SJérôme Gardou StartSeh()
1364e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(NULL, 1, NULL, L"A", 2);
1374e0ce779SJérôme Gardou EndSeh(STATUS_ACCESS_VIOLATION)
1384e0ce779SJérôme Gardou
1394e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1404e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1414e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 1, NULL, L"A", 2);
1424e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1434e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1444e0ce779SJérôme Gardou ok_char(OemBuffer[1], (CHAR)0xAA);
1454e0ce779SJérôme Gardou
1464e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1474e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1484e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 1, NULL, L"AB", 4);
1494e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_BUFFER_OVERFLOW);
1504e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1514e0ce779SJérôme Gardou ok_char(OemBuffer[1], (CHAR)0xAA);
1524e0ce779SJérôme Gardou
1534e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1544e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1554e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 2, NULL, L"A", 4);
1564e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1574e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1584e0ce779SJérôme Gardou ok_char(OemBuffer[1], '\0');
1594e0ce779SJérôme Gardou
1604e0ce779SJérôme Gardou /* RtlUnicodeToOemN doesn't care about string termination */
1614e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1624e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1634e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 1, NULL, L"A", 4);
1644e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_BUFFER_OVERFLOW);
1654e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1664e0ce779SJérôme Gardou ok_char(OemBuffer[1], (CHAR)0xAA);
1674e0ce779SJérôme Gardou
1684e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1694e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1704e0ce779SJérôme Gardou OemBuffer[2] = 0xAA;
1714e0ce779SJérôme Gardou OemBuffer[3] = 0xAA;
1724e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 4, NULL, L"A\0B", 8);
1734e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1744e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1754e0ce779SJérôme Gardou ok_char(OemBuffer[1], '\0');
1764e0ce779SJérôme Gardou ok_char(OemBuffer[2], 'B');
1774e0ce779SJérôme Gardou ok_char(OemBuffer[3], '\0');
1784e0ce779SJérôme Gardou
1794e0ce779SJérôme Gardou /* Odd Unicode buffer size */
1804e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1814e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1824e0ce779SJérôme Gardou OemBuffer[2] = 0xAA;
1834e0ce779SJérôme Gardou OemBuffer[3] = 0xAA;
1844e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 2, NULL, L"AB", 5);
1854e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1864e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1874e0ce779SJérôme Gardou ok_char(OemBuffer[1], 'B');
1884e0ce779SJérôme Gardou ok_char(OemBuffer[2], (CHAR)0xAA);
1894e0ce779SJérôme Gardou ok_char(OemBuffer[3], (CHAR)0xAA);
1904e0ce779SJérôme Gardou
1914e0ce779SJérôme Gardou /* Odd Unicode buffer size */
1924e0ce779SJérôme Gardou OemBuffer[0] = 0xAA;
1934e0ce779SJérôme Gardou OemBuffer[1] = 0xAA;
1944e0ce779SJérôme Gardou OemBuffer[2] = 0xAA;
1954e0ce779SJérôme Gardou OemBuffer[3] = 0xAA;
1964e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(OemBuffer, 3, NULL, L"AB", 5);
1974e0ce779SJérôme Gardou ok_ntstatus(Status, STATUS_SUCCESS);
1984e0ce779SJérôme Gardou ok_char(OemBuffer[0], 'A');
1994e0ce779SJérôme Gardou ok_char(OemBuffer[1], 'B');
2004e0ce779SJérôme Gardou ok_char(OemBuffer[2], (CHAR)0xAA);
2014e0ce779SJérôme Gardou ok_char(OemBuffer[3], (CHAR)0xAA);
2024e0ce779SJérôme Gardou
2034e0ce779SJérôme Gardou for (int i = 0; i < _countof(TestData); i++)
2044e0ce779SJérôme Gardou {
2054e0ce779SJérôme Gardou SetupLocale(TestData[i].AnsiCp, TestData[i].OemCp, -1);
2064e0ce779SJérôme Gardou
2074e0ce779SJérôme Gardou for (int j = 0; TestData[i].Test[j].StrW != NULL; j++)
2084e0ce779SJérôme Gardou {
2094e0ce779SJérôme Gardou Length = strlen(TestData[i].Test[j].StrOem);
2104e0ce779SJérôme Gardou StrOem = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length + 1);
2114e0ce779SJérôme Gardou
2124e0ce779SJérôme Gardou memset(StrOem, 0xAA, Length + 1);
2134e0ce779SJérôme Gardou ResultSize = 0x0BADF00D;
2144e0ce779SJérôme Gardou
2154e0ce779SJérôme Gardou Status = RtlUnicodeToOemN(StrOem,
2164e0ce779SJérôme Gardou Length,
2174e0ce779SJérôme Gardou &ResultSize,
2184e0ce779SJérôme Gardou TestData[i].Test[j].StrW,
2194e0ce779SJérôme Gardou wcslen(TestData[i].Test[j].StrW) * sizeof(WCHAR));
2204e0ce779SJérôme Gardou
2214e0ce779SJérôme Gardou ok_ntstatus(Status, TestData[i].Test[j].Status);
2224e0ce779SJérôme Gardou ok_long(ResultSize, TestData[i].Test[j].ReturnedSize);
2234e0ce779SJérôme Gardou for (int k = 0; k < ResultSize; k++)
2244e0ce779SJérôme Gardou {
2254e0ce779SJérôme Gardou ok(StrOem[k] == TestData[i].Test[j].StrOem[k],
2264e0ce779SJérôme Gardou "Wrong char \\x%02x, expected TestData[%u].Test[%u].StrOem[%u] (\\x%02x)\n",
2274e0ce779SJérôme Gardou StrOem[k], i, j, k, TestData[i].Test[j].StrOem[k]);
2284e0ce779SJérôme Gardou }
2294e0ce779SJérôme Gardou for (int k = ResultSize; k < (Length + 1); k++)
2304e0ce779SJérôme Gardou {
2314e0ce779SJérôme Gardou ok_char(StrOem[k], (CHAR)0xAA);
2324e0ce779SJérôme Gardou }
2334e0ce779SJérôme Gardou
2344e0ce779SJérôme Gardou RtlFreeHeap(RtlGetProcessHeap(), 0, StrOem);
2354e0ce779SJérôme Gardou }
2364e0ce779SJérôme Gardou }
2374e0ce779SJérôme Gardou }
238