1 // This file is converted by code7bit.
2 // code7bit: https://github.com/katahiromz/code7bit
3 // To revert conversion, please execute "code7bit -r <file>".
4 /*
5 * PROJECT: ReactOS API tests
6 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
7 * PURPOSE: Test for RtlGenerate8dot3Name
8 * COPYRIGHT: Copyright 2015-2016 Pierre Schweitzer <pierre@reactos.org>
9 * Copyright 2021 Jérôme Gardou <jerome.gardou@reactos.org>
10 */
11
12 #include "precomp.h"
13
14 NTSYSAPI
15 VOID
16 NTAPI
17 RtlGenerate8dot3Name(
18 _In_ PCUNICODE_STRING Name,
19 _In_ BOOLEAN AllowExtendedCharacters,
20 _Inout_ PGENERATE_NAME_CONTEXT Context,
21 _Inout_ PUNICODE_STRING Name8dot3);
22
23 ULONG Locales[][2] =
24 {
25 {1252, 850}, // Most used for latin langs
26 {1252, 437}, // Used for English US (not only)
27 {1252, 775}, // Used for Estonian
28 {1252, 932}, // Western SBCS, Japanese
29 {932, 1252}, // Japanese, Western SBCS
30 {932, 932}, // Japanese, Japanese
31 };
32 #define LOCALES_COUNT _countof(Locales)
33
34 PWSTR Names[] = {
35 L"Menu D\u00E9marrer",
36 L"S\u00E9lecteur de configuration clavier.lnk",
37 L"\u00E9\u00E8\u00E0\u00F9\u00E7.txt",
38 L"\u00E7\u00F9\u00E0\u00E8\u00E9.txt",
39 L"\u00E9\u00E8\u00E0\u00F9.txt",
40 L"\u00E7\u00F9\u00E0\u00E8.txt",
41 L"\u00E9\u00E8\u00E0\u00F9\u00E7eeauc.txt",
42 L"\u00E9e\u00E8\u00E9\u00E7c\u00F9u.txt",
43 L"test.\u00E9x\u00E8",
44 L"t\u00A3$t\u00A4.txt",
45 L"Long file name.txt",
46 L"Long file name",
47 L"Longfilename.txt",
48 L"Longfilename",
49 L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7" /* Desktop in Japanese */
50 };
51 #define NAMES_COUNT _countof(Names)
52
53 PWSTR ShortNames1[LOCALES_COUNT][NAMES_COUNT] =
54 {
55 { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"423C~1.TXT", L"925E~1.TXT", L"7E4C~1.TXT", L"EEAUC~1.TXT", L"ECU~1.TXT", L"TEST~1.X", L"T$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
56 { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"423C~1.TXT", L"925E~1.TXT", L"7E4C~1.TXT", L"EEAUC~1.TXT", L"ECU~1.TXT", L"TEST~1.X", L"T$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
57 { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"423C~1.TXT", L"925E~1.TXT", L"7E4C~1.TXT", L"EEAUC~1.TXT", L"ECU~1.TXT", L"TEST~1.X", L"T$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
58 { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"423C~1.TXT", L"925E~1.TXT", L"7E4C~1.TXT", L"EEAUC~1.TXT", L"ECU~1.TXT", L"TEST~1.X", L"T$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
59 { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"423C~1.TXT", L"925E~1.TXT", L"7E4C~1.TXT", L"EEAUC~1.TXT", L"ECU~1.TXT", L"TEST~1.X", L"T$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
60 { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"423C~1.TXT", L"925E~1.TXT", L"7E4C~1.TXT", L"EEAUC~1.TXT", L"ECU~1.TXT", L"TEST~1.X", L"T$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
61 };
62 PWSTR ShortNames2[LOCALES_COUNT][NAMES_COUNT] =
63 {
64 { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"423C~2.TXT", L"925E~2.TXT", L"7E4C~2.TXT", L"EEAUC~2.TXT", L"ECU~2.TXT", L"TEST~2.X", L"T$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
65 { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"423C~2.TXT", L"925E~2.TXT", L"7E4C~2.TXT", L"EEAUC~2.TXT", L"ECU~2.TXT", L"TEST~2.X", L"T$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
66 { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"423C~2.TXT", L"925E~2.TXT", L"7E4C~2.TXT", L"EEAUC~2.TXT", L"ECU~2.TXT", L"TEST~2.X", L"T$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
67 { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"423C~2.TXT", L"925E~2.TXT", L"7E4C~2.TXT", L"EEAUC~2.TXT", L"ECU~2.TXT", L"TEST~2.X", L"T$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
68 { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"423C~2.TXT", L"925E~2.TXT", L"7E4C~2.TXT", L"EEAUC~2.TXT", L"ECU~2.TXT", L"TEST~2.X", L"T$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
69 { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"423C~2.TXT", L"925E~2.TXT", L"7E4C~2.TXT", L"EEAUC~2.TXT", L"ECU~2.TXT", L"TEST~2.X", L"T$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
70 };
71 PWSTR ExShortNames1[LOCALES_COUNT][NAMES_COUNT] =
72 {
73 { L"MENUD\u00C9~1", L"S\u00C9LECT~1.LNK", L"\u00C9\u00C8\u00C0\u00D9\u00C7~1.TXT", L"\u00C7\u00D9\u00C0\u00C8\u00C9~1.TXT", L"\u00C9\u00C8\u00C0\u00D9~1.TXT", L"\u00C7\u00D9\u00C0\u00C8~1.TXT", L"\u00C9\u00C8\u00C0\u00D9\u00C7E~1.TXT", L"\u00C9E\u00C8\u00C9\u00C7C~1.TXT", L"TEST~1.\u00C9X\u00C8", L"T\u00A3$T\u00A4~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
74 { L"MENUD\u00C9~1", L"S\u00C9LECT~1.LNK", L"\u00C9\u00C8\u00C0\u00D9\u00C7~1.TXT", L"\u00C7\u00D9\u00C0\u00C8\u00C9~1.TXT", L"\u00C9\u00C8\u00C0\u00D9~1.TXT", L"\u00C7\u00D9\u00C0\u00C8~1.TXT", L"\u00C9\u00C8\u00C0\u00D9\u00C7E~1.TXT", L"\u00C9E\u00C8\u00C9\u00C7C~1.TXT", L"TEST~1.\u00C9X\u00C8", L"T\u00A3$T_~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
75 { L"MENUD\u00C9~1", L"S\u00C9LECT~1.LNK", L"\u00C9CAU~1.TXT", L"UAC\u00C9~1.TXT", L"\u00C9CAU~1.TXT", L"UAC~1.TXT", L"\u00C9CAUEE~1.TXT", L"\u00C9EC\u00C9CU~1.TXT", L"TEST~1.\u00C9XC", L"T\u00A3$T\u00A4~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
76 { L"MENUDE~1", L"SELECT~1.LNK", L"EEAUC~1.TXT", L"CUAEE~1.TXT", L"EEAU~1.TXT", L"CUAE~1.TXT", L"EEAUCE~1.TXT", L"EEEECC~1.TXT", L"TEST~1.EXE", L"T\uFFE1$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"\u30c7\u30b9\u30af~1" },
77 { L"MENUD\u00C9~1", L"S\u00C9LECT~1.LNK", L"\u00C9\u00C8\u00C0\u00D9\u00C7~1.TXT", L"\u00C7\u00D9\u00C0\u00C8\u00C9~1.TXT", L"\u00C9\u00C8\u00C0\u00D9~1.TXT", L"\u00C7\u00D9\u00C0\u00C8~1.TXT", L"\u00C9\u00C8\u00C0\u00D9\u00C7E~1.TXT", L"\u00C9E\u00C8\u00C9\u00C7C~1.TXT", L"TEST~1.\u00C9X\u00C8", L"T\u00A3$T\u00A4~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"9A16~1" },
78 { L"MENUDE~1", L"SELECT~1.LNK", L"EEAUC~1.TXT", L"CUAEE~1.TXT", L"EEAU~1.TXT", L"CUAE~1.TXT", L"EEAUCE~1.TXT", L"EEEECC~1.TXT", L"TEST~1.EXE", L"T\uFFE1$T~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1", L"\u30c7\u30b9\u30af~1" },
79 };
80 PWSTR ExShortNames2[LOCALES_COUNT][NAMES_COUNT] =
81 {
82 { L"MENUD\u00C9~2", L"S\u00C9LECT~2.LNK", L"\u00C9\u00C8\u00C0\u00D9\u00C7~2.TXT", L"\u00C7\u00D9\u00C0\u00C8\u00C9~2.TXT", L"\u00C9\u00C8\u00C0\u00D9~2.TXT", L"\u00C7\u00D9\u00C0\u00C8~2.TXT", L"\u00C9\u00C8\u00C0\u00D9\u00C7E~2.TXT", L"\u00C9E\u00C8\u00C9\u00C7C~2.TXT", L"TEST~2.\u00C9X\u00C8", L"T\u00A3$T\u00A4~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
83 { L"MENUD\u00C9~2", L"S\u00C9LECT~2.LNK", L"\u00C9\u00C8\u00C0\u00D9\u00C7~2.TXT", L"\u00C7\u00D9\u00C0\u00C8\u00C9~2.TXT", L"\u00C9\u00C8\u00C0\u00D9~2.TXT", L"\u00C7\u00D9\u00C0\u00C8~2.TXT", L"\u00C9\u00C8\u00C0\u00D9\u00C7E~2.TXT", L"\u00C9E\u00C8\u00C9\u00C7C~2.TXT", L"TEST~2.\u00C9X\u00C8", L"T\u00A3$T_~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
84 { L"MENUD\u00C9~2", L"S\u00C9LECT~2.LNK", L"\u00C9CAU~2.TXT", L"UAC\u00C9~2.TXT", L"\u00C9CAU~2.TXT", L"UAC~2.TXT", L"\u00C9CAUEE~2.TXT", L"\u00C9EC\u00C9CU~2.TXT", L"TEST~2.\u00C9XC", L"T\u00A3$T\u00A4~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
85 { L"MENUDE~2", L"SELECT~2.LNK", L"EEAUC~2.TXT", L"CUAEE~2.TXT", L"EEAU~2.TXT", L"CUAE~2.TXT", L"EEAUCE~2.TXT", L"EEEECC~2.TXT", L"TEST~2.EXE", L"T\uFFE1$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"\u30c7\u30b9\u30af~2" },
86 { L"MENUD\u00C9~2", L"S\u00C9LECT~2.LNK", L"\u00C9\u00C8\u00C0\u00D9\u00C7~2.TXT", L"\u00C7\u00D9\u00C0\u00C8\u00C9~2.TXT", L"\u00C9\u00C8\u00C0\u00D9~2.TXT", L"\u00C7\u00D9\u00C0\u00C8~2.TXT", L"\u00C9\u00C8\u00C0\u00D9\u00C7E~2.TXT", L"\u00C9E\u00C8\u00C9\u00C7C~2.TXT", L"TEST~2.\u00C9X\u00C8", L"T\u00A3$T\u00A4~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"9A16~2" },
87 { L"MENUDE~2", L"SELECT~2.LNK", L"EEAUC~2.TXT", L"CUAEE~2.TXT", L"EEAU~2.TXT", L"CUAE~2.TXT", L"EEAUCE~2.TXT", L"EEEECC~2.TXT", L"TEST~2.EXE", L"T\uFFE1$T~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2", L"\u30c7\u30b9\u30af~2" },
88 };
89
90 #define LONG_NAMES_COUNT 12
91 PWSTR LongNames[LONG_NAMES_COUNT] =
92 {
93 L"Long File Name 1.txt", L"Long File Name 2.txt", L"Long File Name 3.txt", L"Long File Name 4.txt", L"Long File Name 5.txt", L"Long File Name 6.txt",
94 L"Very Long File Name 1.txt", L"Very Long File Name 2.txt", L"Very Long File Name 3.txt", L"Very Long File Name 4.txt", L"Very Long File Name 5.txt", L"Very Long File Name 6.txt",
95 };
96
97 PWSTR LongShortNames[LONG_NAMES_COUNT] =
98 {
99 L"LONGFI~1.TXT", L"LONGFI~2.TXT", L"LONGFI~3.TXT", L"LONGFI~4.TXT", L"LO1796~1.TXT", L"LO1796~2.TXT",
100 L"VERYLO~1.TXT", L"VERYLO~2.TXT", L"VERYLO~3.TXT", L"VERYLO~4.TXT", L"VED051~1.TXT", L"VED051~2.TXT",
101 };
102
START_TEST(RtlGenerate8dot3Name)103 START_TEST(RtlGenerate8dot3Name)
104 {
105 USHORT i, j;
106
107 for (j = 0; j < LOCALES_COUNT; ++j)
108 {
109 /* Setup locale. */
110 SetupLocale(Locales[j][0], Locales[j][1], -1);
111
112 for (i = 0; i < NAMES_COUNT; ++i)
113 {
114 WCHAR Buffer[12];
115 GENERATE_NAME_CONTEXT Context;
116 UNICODE_STRING LongName, ShortName, Expected;
117
118 RtlZeroMemory(&Context, sizeof(GENERATE_NAME_CONTEXT));
119 RtlInitUnicodeString(&LongName, Names[i]);
120 ShortName.Buffer = Buffer;
121 ShortName.Length = 0;
122 ShortName.MaximumLength = sizeof(Buffer);
123
124 RtlGenerate8dot3Name(&LongName, FALSE, &Context, &ShortName);
125 RtlInitUnicodeString(&Expected, ShortNames1[j][i]);
126 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "%u,%u:: Generated: %.*S. Expected: %.*S\n", j, i, ShortName.Length / sizeof(WCHAR), ShortName.Buffer, Expected.Length / sizeof(WCHAR), Expected.Buffer);
127
128 ShortName.Length = 0;
129 RtlGenerate8dot3Name(&LongName, FALSE, &Context, &ShortName);
130 RtlInitUnicodeString(&Expected, ShortNames2[j][i]);
131 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "%u,%u:: Generated: %.*S. Expected: %.*S\n", j, i, ShortName.Length / sizeof(WCHAR), ShortName.Buffer, Expected.Length / sizeof(WCHAR), Expected.Buffer);
132
133 RtlZeroMemory(&Context, sizeof(GENERATE_NAME_CONTEXT));
134 ShortName.Length = 0;
135 RtlGenerate8dot3Name(&LongName, TRUE, &Context, &ShortName);
136 RtlInitUnicodeString(&Expected, ExShortNames1[j][i]);
137 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "%u,%u:: Generated: %.*S. Expected: %.*S\n", j, i, ShortName.Length / sizeof(WCHAR), ShortName.Buffer, Expected.Length / sizeof(WCHAR), Expected.Buffer);
138 if (!RtlEqualUnicodeString(&Expected, &ShortName, FALSE))
139 {
140 for (int k = 0; k < (ShortName.Length / sizeof(WCHAR)); k++)
141 trace("Got \\u%04x at %d\n", ShortName.Buffer[k], k);
142 }
143
144 ShortName.Length = 0;
145 RtlGenerate8dot3Name(&LongName, TRUE, &Context, &ShortName);
146 RtlInitUnicodeString(&Expected, ExShortNames2[j][i]);
147 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "%u,%u:: Generated: %.*S. Expected: %.*S\n", j, i, ShortName.Length / sizeof(WCHAR), ShortName.Buffer, Expected.Length / sizeof(WCHAR), Expected.Buffer);
148 if (!RtlEqualUnicodeString(&Expected, &ShortName, FALSE))
149 {
150 for (int k = 0; k < (ShortName.Length / sizeof(WCHAR)); k++)
151 trace("Got \\u%04x at %d\n", ShortName.Buffer[k], k);
152 }
153 }
154 }
155
156 {
157 WCHAR Buffer[12];
158 GENERATE_NAME_CONTEXT Context;
159 UNICODE_STRING LongName, ShortName, Expected;
160
161 ShortName.Buffer = Buffer;
162 ShortName.MaximumLength = sizeof(Buffer);
163
164 for (i = 0; i < LONG_NAMES_COUNT; ++i)
165 {
166 if (i % 6 == 0) RtlZeroMemory(&Context, sizeof(GENERATE_NAME_CONTEXT));
167
168 RtlInitUnicodeString(&LongName, LongNames[i]);
169 ShortName.Length = 0;
170
171 RtlGenerate8dot3Name(&LongName, FALSE, &Context, &ShortName);
172 RtlInitUnicodeString(&Expected, LongShortNames[i]);
173 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "%u:: Generated: %.*S. Expected: %.*S\n", i, ShortName.Length / sizeof(WCHAR), ShortName.Buffer, Expected.Length / sizeof(WCHAR), Expected.Buffer);
174 }
175 }
176 }
177