[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / kernel32 / GetDriveType.c
1 #include <apitest.h>
2 #include <strsafe.h>
3
4 #define IS_DRIVE_TYPE_VALID(type) ((type) != DRIVE_UNKNOWN && (type) != DRIVE_NO_ROOT_DIR)
5
6 START_TEST(GetDriveType)
7 {
8 UINT Type, Type2, i;
9 WCHAR Path[MAX_PATH];
10
11 /* Note: Successful calls can set last error to at least ERROR_NOT_A_REPARSE_POINT, we don't test it here */
12 SetLastError(0xdeadbeaf);
13
14 Type = GetDriveTypeW(L"");
15 ok(Type == DRIVE_NO_ROOT_DIR, "Expected DRIVE_NO_ROOT_DIR, got %u\n", Type);
16
17 Type = GetDriveTypeW(L"\nC:\\");
18 ok(Type == DRIVE_NO_ROOT_DIR, "Expected DRIVE_NO_ROOT_DIR, got %u\n", Type);
19
20 Type = GetDriveTypeW(L"Z:\\");
21 ok(Type == DRIVE_NO_ROOT_DIR, "Expected DRIVE_NO_ROOT_DIR, got %u\n", Type);
22
23 ok(GetLastError() == 0xdeadbeaf, "Expected no errors, got %lu\n", GetLastError());
24
25 /* Drive root is accepted without ending slash */
26 Type = GetDriveTypeW(L"C:");
27 ok(IS_DRIVE_TYPE_VALID(Type), "Expected valid drive type, got %u\n", Type);
28
29 Type = GetDriveTypeW(L"C:\\");
30 ok(IS_DRIVE_TYPE_VALID(Type), "Expected valid drive type, got %u\n", Type);
31
32 Type = GetDriveTypeW(NULL);
33 ok(IS_DRIVE_TYPE_VALID(Type), "Expected valid drive type, got %u\n", Type);
34
35 i = GetCurrentDirectoryW(sizeof(Path)/sizeof(Path[0]), Path);
36 if (i)
37 {
38 /* No trailing backslash returned unless we're at the drive root */
39 if (Path[i - 1] != L'\\')
40 {
41 SetLastError(0xdeadbeaf);
42 Type2 = GetDriveTypeW(Path);
43 ok(Type2 == DRIVE_NO_ROOT_DIR, "Expected DRIVE_NO_ROOT_DIR, got %u\n", Type2);
44 ok(GetLastError() == 0xdeadbeaf, "Expected no errors, got %lu\n", GetLastError());
45
46 StringCchCopyW(Path + i, MAX_PATH - i, L"\\");
47 }
48 Type2 = GetDriveTypeW(Path);
49 ok(Type == Type2, "Types are not equal: %u != %u\n", Type, Type2);
50 }
51
52 i = GetSystemDirectoryW(Path, sizeof(Path)/sizeof(Path[0]));
53 if (i)
54 {
55 /* Note: there is no backslash at the end of Path */
56 SetLastError(0xdeadbeaf);
57 Type = GetDriveTypeW(Path);
58 ok(Type == DRIVE_NO_ROOT_DIR, "Expected DRIVE_NO_ROOT_DIR, got %u\n", Type);
59 ok(GetLastError() == 0xdeadbeaf, "Expected no errors, got %lu\n", GetLastError());
60
61 StringCchCopyW(Path + i, MAX_PATH - i, L"\\");
62 Type = GetDriveTypeW(Path);
63 ok(IS_DRIVE_TYPE_VALID(Type), "Expected valid drive type, got %u\n", Type);
64
65 StringCchCopyW(Path + i, MAX_PATH - i, L"/");
66 Type = GetDriveTypeW(Path);
67 ok(IS_DRIVE_TYPE_VALID(Type), "Expected valid drive type, got %u\n", Type);
68
69 StringCchCopyW(Path + i, MAX_PATH - i, L"\\\\");
70 Type = GetDriveTypeW(Path);
71 ok(IS_DRIVE_TYPE_VALID(Type), "Expected valid drive type, got %u\n", Type);
72 }
73 }