xref: /reactos/base/setup/lib/utils/arcname_tests.c (revision 6f19c83b)
1*6f19c83bSHermès Bélusca-Maïto /*
2*6f19c83bSHermès Bélusca-Maïto  * PROJECT:     ReactOS Setup Library
3*6f19c83bSHermès Bélusca-Maïto  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4*6f19c83bSHermès Bélusca-Maïto  * PURPOSE:     Tests for the arcname.c functions:
5*6f19c83bSHermès Bélusca-Maïto  *              ArcPathNormalize(), ArcPathToNtPath().
6*6f19c83bSHermès Bélusca-Maïto  * COPYRIGHT:   Copyright 2017-2018 Hermes Belusca-Maito
7*6f19c83bSHermès Bélusca-Maïto  *
8*6f19c83bSHermès Bélusca-Maïto  * You may need to fix the included headers before being able to
9*6f19c83bSHermès Bélusca-Maïto  * compile this file (this file has only been compiled under VS).
10*6f19c83bSHermès Bélusca-Maïto  */
11*6f19c83bSHermès Bélusca-Maïto 
12*6f19c83bSHermès Bélusca-Maïto #include <stdio.h>
13*6f19c83bSHermès Bélusca-Maïto #include <tchar.h>
14*6f19c83bSHermès Bélusca-Maïto #include <conio.h>
15*6f19c83bSHermès Bélusca-Maïto 
16*6f19c83bSHermès Bélusca-Maïto #define WIN32_NO_STATUS
17*6f19c83bSHermès Bélusca-Maïto #include <windows.h>
18*6f19c83bSHermès Bélusca-Maïto #include <winternl.h>
19*6f19c83bSHermès Bélusca-Maïto #undef WIN32_NO_STATUS
20*6f19c83bSHermès Bélusca-Maïto 
21*6f19c83bSHermès Bélusca-Maïto #include <ntstatus.h>
22*6f19c83bSHermès Bélusca-Maïto 
23*6f19c83bSHermès Bélusca-Maïto #include <strsafe.h>
24*6f19c83bSHermès Bélusca-Maïto 
25*6f19c83bSHermès Bélusca-Maïto #include "arcname.h"
26*6f19c83bSHermès Bélusca-Maïto 
27*6f19c83bSHermès Bélusca-Maïto #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
28*6f19c83bSHermès Bélusca-Maïto 
29*6f19c83bSHermès Bélusca-Maïto int _tmain(int argc, _TCHAR* argv[])
30*6f19c83bSHermès Bélusca-Maïto {
31*6f19c83bSHermès Bélusca-Maïto     WCHAR ArcPath[MAX_PATH] = L"multi(5)disk()rdisk(1)partition()\\ReactOS";
32*6f19c83bSHermès Bélusca-Maïto     WCHAR NormalizedArcPathBuffer[MAX_PATH];
33*6f19c83bSHermès Bélusca-Maïto     UNICODE_STRING NormalizedArcPath;
34*6f19c83bSHermès Bélusca-Maïto     WCHAR NtPathBuffer[MAX_PATH];
35*6f19c83bSHermès Bélusca-Maïto     UNICODE_STRING NtPath;
36*6f19c83bSHermès Bélusca-Maïto 
37*6f19c83bSHermès Bélusca-Maïto     NormalizedArcPath.Buffer = NormalizedArcPathBuffer;
38*6f19c83bSHermès Bélusca-Maïto     NormalizedArcPath.Length = 0;
39*6f19c83bSHermès Bélusca-Maïto     NormalizedArcPath.MaximumLength = sizeof(NormalizedArcPathBuffer);
40*6f19c83bSHermès Bélusca-Maïto 
41*6f19c83bSHermès Bélusca-Maïto     ArcPathNormalize(&NormalizedArcPath, ArcPath);
42*6f19c83bSHermès Bélusca-Maïto     wprintf(L"ArcPath = '%s' ; Normalized = '%wZ'\n", ArcPath, &NormalizedArcPath);
43*6f19c83bSHermès Bélusca-Maïto 
44*6f19c83bSHermès Bélusca-Maïto     NtPath.Buffer = NtPathBuffer;
45*6f19c83bSHermès Bélusca-Maïto     NtPath.Length = 0;
46*6f19c83bSHermès Bélusca-Maïto     NtPath.MaximumLength = sizeof(NtPathBuffer);
47*6f19c83bSHermès Bélusca-Maïto 
48*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, NormalizedArcPath.Buffer);
49*6f19c83bSHermès Bélusca-Maïto     // wprintf(L"ArcPath = '%s' ; NtPath = '%wZ'\n", ArcPath, &NtPath);
50*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
51*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"ramdisk(0)");                // OK
52*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
53*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"ramdisk(0)\\ReactOS\\system32\\ntoskrnl.exe");   // OK
54*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
55*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"net(0)\\Foobar");            // OK but not supported
56*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
57*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"net(0)disk(1)\\Foobar");     // Bad
58*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
59*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(2)disk(1)rdisk(3)");    // OK
60*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
61*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(2)disk(1)fdisk(3)");    // OK
62*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
63*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(2)cdrom(1)");           // Bad: missing fdisk
64*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
65*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(2)cdrom(1)cdrom(0)");   // Bad: twice cdrom
66*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
67*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(2)cdrom(1)fdisk(0)");   // OK
68*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
69*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(2)cdrom(1)rdisk(0)");   // Bad; cdrom controller and rdisk peripheral
70*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
71*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(2)cdrom(1)fdisk(0)");  // Bad: multi adapter cannot have cdrom controller
72*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
73*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(2)rdisk(1)cdrom(1)fdisk(0)");  // Bad: rdisk is not a controller
74*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
75*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(2)disk(1)cdrom(1)fdisk(0)");   // OK (disk(1) ignored)
76*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
77*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(2)disk(1)rdisk(1)fdisk(0)");   // Same (and also fdisk is not considered as part of ARC path)
78*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
79*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(2)disk(1)rdisk(1)partition(3)");   // OK (disk(1) ignored)
80*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
81*6f19c83bSHermès Bélusca-Maïto 
82*6f19c83bSHermès Bélusca-Maïto     _getch();
83*6f19c83bSHermès Bélusca-Maïto 
84*6f19c83bSHermès Bélusca-Maïto     /* All these are OK */
85*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(0)disk(3)rdisk(0)partition(1)\\OS.DIR");
86*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
87*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"scsi(1)disk(3)rdisk(3)partition(2)\\OS\\ARCOS\\LOADER");
88*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
89*6f19c83bSHermès Bélusca-Maïto 
90*6f19c83bSHermès Bélusca-Maïto     _getch();
91*6f19c83bSHermès Bélusca-Maïto 
92*6f19c83bSHermès Bélusca-Maïto     /* All these are OK */
93*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)rdisk(0)partition(1)");
94*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
95*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)rdisk(0)partition(0)");
96*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
97*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)cdrom(3)");
98*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
99*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"ramdisk(0)");
100*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
101*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"net(0)");
102*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
103*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)fdisk(0)");
104*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
105*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)rdisk(1)partition(0)");
106*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
107*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)rdisk(1)partition(3)");
108*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
109*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)rdisk(1)partition(1)");
110*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
111*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)rdisk(0)partition(3)");
112*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
113*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)fdisk(1)partition(0)");
114*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
115*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)fdisk(0)partition(0)");
116*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
117*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)disk(0)fdisk(1)");
118*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
119*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"eisa(0)disk(0)fdisk(0)");
120*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
121*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"eisa(0)disk(0)fdisk(1)partition(0)");
122*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
123*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"eisa(0)disk(0)fdisk(0)partition(0)");
124*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
125*6f19c83bSHermès Bélusca-Maïto 
126*6f19c83bSHermès Bélusca-Maïto     /* These are invalid storage ARC paths (but otherwise are valid ARC names) */
127*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)video(0)monitor(0)");
128*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
129*6f19c83bSHermès Bélusca-Maïto     ArcPathToNtPath(&NtPath, L"multi(0)key(0)keyboard(0)");
130*6f19c83bSHermès Bélusca-Maïto     wprintf(L"NtPath = '%wZ'\n", &NtPath);
131*6f19c83bSHermès Bélusca-Maïto 
132*6f19c83bSHermès Bélusca-Maïto     _getch();
133*6f19c83bSHermès Bélusca-Maïto     return 0;
134*6f19c83bSHermès Bélusca-Maïto }
135