f83ce005fdc5ea1a6fd8db45b4af88ad3ff1d480
[reactos.git] / rostests / apitests / ntdll / RtlGenerate8dot3Name.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlGenerate8dot3Name
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12
13 NTSYSAPI
14 VOID
15 NTAPI
16 RtlGenerate8dot3Name(
17 _In_ PCUNICODE_STRING Name,
18 _In_ BOOLEAN AllowExtendedCharacters,
19 _Inout_ PGENERATE_NAME_CONTEXT Context,
20 _Inout_ PUNICODE_STRING Name8dot3);
21
22 PWSTR Names[] = { L"Menu Démarrer", L"Sélecteur de configuration clavier.lnk", L"éèàùç.txt", L"éèàùçeeauc.txt", L"Long file name.txt", L"Long file name", L"Longfilename.txt", L"Longfilename" };
23 PWSTR ShortNames1[] = { L"MENUDM~1", L"SLECTE~1.LNK", L"5C2D~1.TXT", L"EEAUC~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1" };
24 PWSTR ShortNames2[] = { L"MENUDM~2", L"SLECTE~2.LNK", L"5C2D~2.TXT", L"EEAUC~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2" };
25 PWSTR ExShortNames1[] = { L"MENUDÉ~1", L"SÉLECT~1.LNK", L"ÉÈÀÙÇ~1.TXT", L"ÉÈÀÙÇE~1.TXT", L"LONGFI~1.TXT", L"LONGFI~1", L"LONGFI~1.TXT", L"LONGFI~1" };
26 PWSTR ExShortNames2[] = { L"MENUDÉ~2", L"SÉLECT~2.LNK", L"ÉÈÀÙÇ~2.TXT", L"ÉÈÀÙÇE~2.TXT", L"LONGFI~2.TXT", L"LONGFI~2", L"LONGFI~2.TXT", L"LONGFI~2" };
27
28 START_TEST(RtlGenerate8dot3Name)
29 {
30 USHORT i;
31
32 for (i = 0; i < 8; ++i)
33 {
34 WCHAR Buffer[12];
35 GENERATE_NAME_CONTEXT Context;
36 UNICODE_STRING LongName, ShortName, Expected;
37
38 RtlZeroMemory(&Context, sizeof(GENERATE_NAME_CONTEXT));
39 RtlInitUnicodeString(&LongName, Names[i]);
40 ShortName.Buffer = Buffer;
41 ShortName.Length = 0;
42 ShortName.MaximumLength = sizeof(Buffer);
43
44 RtlGenerate8dot3Name(&LongName, FALSE, &Context, &ShortName);
45 RtlInitUnicodeString(&Expected, ShortNames1[i]);
46 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "Generated: %.*S. Expected: %.*S\n", ShortName.Length, ShortName.Buffer, Expected.Length, Expected.Buffer);
47
48 ShortName.Length = 0;
49 RtlGenerate8dot3Name(&LongName, FALSE, &Context, &ShortName);
50 RtlInitUnicodeString(&Expected, ShortNames2[i]);
51 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "Generated: %.*S. Expected: %.*S\n", ShortName.Length, ShortName.Buffer, Expected.Length, Expected.Buffer);
52
53 RtlZeroMemory(&Context, sizeof(GENERATE_NAME_CONTEXT));
54 ShortName.Length = 0;
55 RtlGenerate8dot3Name(&LongName, TRUE, &Context, &ShortName);
56 RtlInitUnicodeString(&Expected, ExShortNames1[i]);
57 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "Generated: %.*S. Expected: %.*S\n", ShortName.Length, ShortName.Buffer, Expected.Length, Expected.Buffer);
58
59 ShortName.Length = 0;
60 RtlGenerate8dot3Name(&LongName, TRUE, &Context, &ShortName);
61 RtlInitUnicodeString(&Expected, ExShortNames2[i]);
62 ok(RtlEqualUnicodeString(&Expected, &ShortName, FALSE), "Generated: %.*S. Expected: %.*S\n", ShortName.Length, ShortName.Buffer, Expected.Length, Expected.Buffer);
63 }
64 }