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