ReactOS 0.4.15-dev-7934-g1dc8d80
dosdev.c
Go to the documentation of this file.
1/*
2 * Unit test suite for virtual substituted drive functions.
3 *
4 * Copyright 2011 Sam Arun Raj
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "precomp.h"
22
23#define SUBST_DRIVE_LETTER 'M'
24#define SUBST_DRIVE "M:"
25#define SUBST_DRIVE_NON_EXIST_DIR "M:\\deadbeef"
26#define SUBST_DRIVE_WITH_TRAILING_PATH_SEPERATOR "M:\\"
27#define SUBST_DRIVE_SEARCH "M:\\*"
28#define SUBST_DRIVE_LOWERCASE "m:"
29#define SUBST_DRIVE_LOWERCASE_SEARCH "m:\\*"
30#define SUBST_DRIVE2_LETTER 'N'
31#define SUBST_DRIVE2 "N:"
32#define SUBST_DRIVE2_WITH_TRAILING_PATH_SEPERATOR "N:\\"
33#define SUBST_DRIVE2_SEARCH "N:\\*"
34
35static void test_DefineDosDeviceA(void)
36{
39 UINT CharCount;
40 HANDLE hnd;
42 UINT SystemDriveType, DriveType1, DriveType2;
43 DWORD dwMaskPrev, dwMaskCur;
44 CHAR c;
45
46 /* Choose the symbolic link target */
48 ok(CharCount > 0, "Failed to get windows directory\n");
49 c = Target[3];
50 Target[3] = '\0';
51 SystemDriveType = GetDriveTypeA(Target);
52 Target[3] = c;
53
54 /* Test with a subst drive pointing to another substed drive */
55 dwMaskPrev = GetLogicalDrives();
57 ok(Result, "Failed to subst drive\n");
60 ok(Result, "Failed to subst drive\n");
62 dwMaskCur = GetLogicalDrives();
63 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
64 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
65 ok((dwMaskCur & (1 << (SUBST_DRIVE2_LETTER - 'A'))), "Drive bit is not set\n");
67 ok(hnd != INVALID_HANDLE_VALUE, "Failed to open subst drive\n");
68 if (hnd) FindClose(hnd);
69 ok(DriveType1 == DriveType2, "subst drive types don't match\n");
70 ok(DriveType1 == SystemDriveType, "subst drive types don't match\n");
71 ok(DriveType2 == SystemDriveType, "subst drive types don't match\n");
73 ok(Result, "Failed to remove subst drive using NULL Target name\n");
75 ok(hnd == INVALID_HANDLE_VALUE, "Opened subst drive when it should fail, we removed the target\n");
76 if (hnd) FindClose(hnd);
78 ok(Result, "Failed to remove subst drive using NULL Target name\n");
80 ok(!Result, "Subst drive is present even after remove attempt\n");
82 ok(!Result, "Subst drive is present even after remove attempt\n");
83 dwMaskCur = GetLogicalDrives();
84 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
85
86 /* Test using lowercase drive letter */
87 dwMaskPrev = GetLogicalDrives();
89 ok(Result, "Failed to subst drive using lowercase drive letter\n");
91 ok(DriveType1 == SystemDriveType, "subst drive types don't match\n");
92 dwMaskCur = GetLogicalDrives();
93 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
94 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
96 ok(hnd != INVALID_HANDLE_VALUE, "Failed to open subst drive\n");
97 if (hnd) FindClose(hnd);
99 ok(Result, "Failed to remove subst drive using lowercase drive letter\n");
101 ok(!Result, "Subst drive is present even after remove attempt\n");
102 dwMaskCur = GetLogicalDrives();
103 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
104
105 /* Test remove without using DDD_EXACT_MATCH_ON_REMOVE */
106 dwMaskPrev = GetLogicalDrives();
108 ok(Result, "Failed to subst drive\n");
110 ok(DriveType1 == SystemDriveType, "subst drive types don't match\n");
111 dwMaskCur = GetLogicalDrives();
112 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
113 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
115 ok(hnd != INVALID_HANDLE_VALUE, "Failed to open subst drive\n");
116 if (hnd) FindClose(hnd);
118 ok(Result, "Failed to remove subst drive using NULL Target name\n");
120 ok(!Result, "Subst drive is present even after remove attempt\n");
121 dwMaskCur = GetLogicalDrives();
122 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
123
124 /* Test multiple adds and multiple removes in add order */
125 dwMaskPrev = GetLogicalDrives();
126 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp1");
127 ok(Result, "Failed to subst drive\n");
128 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp2");
129 ok(Result, "Failed to subst drive\n");
130 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp3");
131 ok(Result, "Failed to subst drive\n");
133 ok(DriveType1 != SystemDriveType, "subst drive types match when it shouldn't\n");
134 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_FILE_NOT_FOUND), GetLastError());
135 dwMaskCur = GetLogicalDrives();
136 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
137 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
139 ok(Result, "Failed to remove subst drive\n");
141 ok(Result, "Failed to query subst drive\n");
142 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp3") == 0), "Subst drive is not pointing to correct target\n");
144 ok(Result, "Failed to remove subst drive\n");
146 ok(Result, "Failed to query subst drive\n");
147 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp3") == 0), "Subst drive is not pointing to correct target\n");
149 ok(Result, "Failed to remove subst drive\n");
151 ok(!Result, "Subst drive is present even after remove attempt\n");
152 dwMaskCur = GetLogicalDrives();
153 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
154
155 /* Test multiple adds and multiple removes in reverse order */
156 dwMaskPrev = GetLogicalDrives();
157 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp1");
158 ok(Result, "Failed to subst drive\n");
159 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp2");
160 ok(Result, "Failed to subst drive\n");
161 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp3");
162 ok(Result, "Failed to subst drive\n");
164 ok(DriveType1 != SystemDriveType, "subst drive types match when it shouldn't\n");
165 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_FILE_NOT_FOUND), GetLastError());
166 dwMaskCur = GetLogicalDrives();
167 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
168 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
170 ok(Result, "Failed to remove subst drive\n");
172 ok(Result, "Failed to query subst drive\n");
173 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp2") == 0), "Subst drive is not pointing to correct target\n");
175 ok(Result, "Failed to remove subst drive\n");
177 ok(Result, "Failed to query subst drive\n");
178 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp1") == 0), "Subst drive is not pointing to correct target\n");
180 ok(Result, "Failed to remove subst drive\n");
182 ok(!Result, "Subst drive is present even after remove attempt\n");
183 dwMaskCur = GetLogicalDrives();
184 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
185
186 /* Test multiple adds and multiple removes out of order */
187 dwMaskPrev = GetLogicalDrives();
188 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp1");
189 ok(Result, "Failed to subst drive\n");
190 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp2");
191 ok(Result, "Failed to subst drive\n");
192 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp3");
193 ok(Result, "Failed to subst drive\n");
194 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp4");
195 ok(Result, "Failed to subst drive\n");
196 Result = DefineDosDeviceA(0, SUBST_DRIVE, "C:\\temp5");
197 ok(Result, "Failed to subst drive\n");
199 ok(DriveType1 != SystemDriveType, "subst drive types match when it shouldn't\n");
200 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_FILE_NOT_FOUND), GetLastError());
201 dwMaskCur = GetLogicalDrives();
202 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
203 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
205 ok(Result, "Failed to remove subst drive\n");
207 ok(Result, "Failed to query subst drive\n");
208 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp5") == 0), "Subst drive is not pointing to correct target\n");
210 ok(Result, "Failed to remove subst drive\n");
212 ok(Result, "Failed to query subst drive\n");
213 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp4") == 0), "Subst drive is not pointing to correct target\n");
215 ok(Result, "Failed to remove subst drive\n");
217 ok(Result, "Failed to query subst drive\n");
218 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp4") == 0), "Subst drive is not pointing to correct target\n");
220 ok(Result, "Failed to remove subst drive\n");
222 ok(Result, "Failed to query subst drive\n");
223 if (Result) ok((_stricmp(Buffer, "\\??\\C:\\temp4") == 0), "Subst drive is not pointing to correct target");
225 ok(Result, "Failed to remove subst drive\n");
227 ok(!Result, "Subst drive is present even after remove attempt\n");
228 dwMaskCur = GetLogicalDrives();
229 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
230
231 /* Test with trailing '\' appended to TargetPath */
232 dwMaskPrev = GetLogicalDrives();
233 snprintf(Buffer, sizeof(Buffer), "%s\\\\\\", Target);
235 ok(Result, "Failed to subst drive\n");
237 ok(DriveType1 == SystemDriveType, "subst drive types don't match\n");
238 dwMaskCur = GetLogicalDrives();
239 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
240 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
242 ok(hnd != INVALID_HANDLE_VALUE, "Failed to open subst drive\n");
243 if (hnd) FindClose(hnd);
245 ok(Result, "Failed to remove subst drive using NULL Target name\n");
247 ok(!Result, "Subst drive is present even after remove attempt\n");
248 dwMaskCur = GetLogicalDrives();
249 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
250
251 /* Test with trailing '\' appended to TargetPath and DDD_RAW_TARGET_PATH flag */
252 dwMaskPrev = GetLogicalDrives();
253 snprintf(Buffer, sizeof(Buffer), "\\??\\%s\\\\\\", Target);
255 ok(Result, "Failed to subst drive\n");
257 ok(DriveType1 != SystemDriveType, "subst drive types match when they shouldn't\n");
258 dwMaskCur = GetLogicalDrives();
259 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
260 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
262 ok(hnd == INVALID_HANDLE_VALUE, "Opened subst drive when it should fail\n");
263 ok(GetLastError() == ERROR_INVALID_NAME, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_INVALID_NAME), GetLastError());
264 if (hnd) FindClose(hnd);
266 ok(Result, "Failed to remove subst drive using NULL Target name\n");
268 ok(!Result, "Subst drive is present even after remove attempt\n");
269 dwMaskCur = GetLogicalDrives();
270 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
271
272 /* Test using trailing \ against drive letter */
273 dwMaskPrev = GetLogicalDrives();
275 ok(!Result, "Subst drive using trailing path seperator, this should not happen\n");
277 ok(DriveType1 != SystemDriveType, "subst drive types match when it shouldn't\n");
278 dwMaskCur = GetLogicalDrives();
279 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
280 ok(!(dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is set when it shouldn't\n");
282 ok(hnd == INVALID_HANDLE_VALUE, "Opened subst drive when it should fail\n");
283 if (hnd) FindClose(hnd);
285 ok(!Result, "Removing Subst drive using trailing path seperator passed when it should fail\n");
287 ok(!Result, "Subst drive is present when it should not be created in the first place\n");
288 dwMaskCur = GetLogicalDrives();
289 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
290
291 /* Test using arbitary string, not necessarily a DOS drive letter */
292 dwMaskPrev = GetLogicalDrives();
293 Result = DefineDosDeviceA(0, "!QHello:", Target);
294 ok(Result, "Failed to subst drive using non-DOS drive name\n");
295 dwMaskCur = GetLogicalDrives();
296 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
298 ok(Result, "Failed to subst drive using non-DOS drive name\n");
299 Result = QueryDosDeviceA("!QHello:", Buffer, MAX_PATH);
300 ok(!Result, "Subst drive is present even after remove attempt\n");
301 dwMaskCur = GetLogicalDrives();
302 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
303
304 /* Test by subst a drive to itself */
305 dwMaskPrev = GetLogicalDrives();
307 ok(Result, "Failed to subst drive\n");
309 ok(DriveType1 != SystemDriveType, "subst drive types match when it shouldn't\n");
310 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_FILE_NOT_FOUND), GetLastError());
311 dwMaskCur = GetLogicalDrives();
312 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
313 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
315 ok(hnd == INVALID_HANDLE_VALUE, "Opened subst drive when it should fail\n");
316 if (hnd) FindClose(hnd);
318 ok(Result, "Failed to remove subst drive using lowercase drive letter\n");
320 ok(!Result, "Subst drive is present even after remove attempt\n");
321 dwMaskCur = GetLogicalDrives();
322 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
323
324 /* Test by subst a drive to an non-existent folder under itself */
325 dwMaskPrev = GetLogicalDrives();
327 ok(Result, "Failed to subst drive\n");
329 ok(DriveType1 != SystemDriveType, "subst drive types match when it shouldn't\n");
330 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_FILE_NOT_FOUND), GetLastError());
331 dwMaskCur = GetLogicalDrives();
332 ok(dwMaskCur != dwMaskPrev, "Drive masks match when it shouldn't\n");
333 ok((dwMaskCur & (1 << (SUBST_DRIVE_LETTER - 'A'))), "Drive bit is not set\n");
335 ok(hnd == INVALID_HANDLE_VALUE, "Opened subst drive when it should fail\n");
336 if (hnd) FindClose(hnd);
338 ok(Result, "Failed to remove subst drive using lowercase drive letter\n");
340 ok(!Result, "Subst drive is present even after remove attempt\n");
341 dwMaskCur = GetLogicalDrives();
342 ok(dwMaskCur == dwMaskPrev, "Drive masks don't match\n");
343}
344
345static void test_QueryDosDeviceA(void)
346{
348 BOOL Result;
349 UINT CharCount;
350
351 /* Choose the symbolic link target */
353 ok(CharCount > 0, "Failed to get windows directory\n");
354
356 ok(Result, "Failed to subst drive\n");
358 ok(!Result, "Should fail as the buffer passed is supposed to be small\n");
359 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_INSUFFICIENT_BUFFER), GetLastError());
361 ok(Result, "failed to get target path\n");
362 ok(_strnicmp(Buffer, "\\??\\", 4) == 0, "The target returned does have correct prefix set\n");
363 ok(stricmp(&Buffer[4], Target) == 0, "The target returned does not match the one set\n");
365 ok(Result, "Failed to remove subst drive using lowercase drive letter\n");
367
368 /* This will try to retrieve all existing MS-DOS device names */
370 ok(!Result, "Should fail as the buffer passed is supposed to be small\n");
371 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Wrong last error. Expected %lu, got %lu\n", (DWORD)(ERROR_INSUFFICIENT_BUFFER), GetLastError());
372}
373
375{
378}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define _stricmp
Definition: cat.c:22
Definition: bufpool.h:45
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
#define stricmp(_String1, _String2)
Definition: compat.h:24
#define MAX_PATH
Definition: compat.h:34
#define ERROR_INVALID_NAME
Definition: compat.h:103
DWORD WINAPI QueryDosDeviceA(LPCSTR lpDeviceName, LPSTR lpTargetPath, DWORD ucchMax)
Definition: dosdev.c:422
BOOL WINAPI DefineDosDeviceA(DWORD dwFlags, LPCSTR lpDeviceName, LPCSTR lpTargetPath)
Definition: dosdev.c:162
UINT WINAPI GetDriveTypeA(IN LPCSTR lpRootPathName)
Definition: disk.c:468
HANDLE WINAPI FindFirstFileA(IN LPCSTR lpFileName, OUT LPWIN32_FIND_DATAA lpFindFileData)
Definition: find.c:263
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
UINT WINAPI GetSystemWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2367
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define SUBST_DRIVE2_WITH_TRAILING_PATH_SEPERATOR
Definition: dosdev.c:32
#define SUBST_DRIVE2
Definition: dosdev.c:31
static void test_QueryDosDeviceA(void)
Definition: dosdev.c:345
#define SUBST_DRIVE_LETTER
Definition: dosdev.c:23
static void test_DefineDosDeviceA(void)
Definition: dosdev.c:35
#define SUBST_DRIVE2_SEARCH
Definition: dosdev.c:33
#define SUBST_DRIVE2_LETTER
Definition: dosdev.c:30
#define SUBST_DRIVE_LOWERCASE
Definition: dosdev.c:28
#define SUBST_DRIVE_WITH_TRAILING_PATH_SEPERATOR
Definition: dosdev.c:26
#define SUBST_DRIVE_NON_EXIST_DIR
Definition: dosdev.c:25
#define SUBST_DRIVE
Definition: dosdev.c:24
#define SUBST_DRIVE_SEARCH
Definition: dosdev.c:27
unsigned int UINT
Definition: ndis.h:50
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define DDD_EXACT_MATCH_ON_REMOVE
Definition: winbase.h:525
#define DDD_RAW_TARGET_PATH
Definition: winbase.h:523
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define DDD_REMOVE_DEFINITION
Definition: winbase.h:524
#define snprintf
Definition: wintirpc.h:48
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
char CHAR
Definition: xmlstorage.h:175