ntdll: Implement RtlUpdateTimer for kernel32's ChangeTimerQueueTimer.
[wine] / dlls / kernel32 / tests / drive.c
1 /*
2  * Unit test suite for drive functions.
3  *
4  * Copyright 2002 Dmitry Timoshkov
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 <stdarg.h>
22
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27
28 static DWORD (WINAPI *pGetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
29
30 static void test_GetDriveTypeA(void)
31 {
32     char drive[] = "?:\\";
33     DWORD logical_drives;
34     UINT type;
35
36     logical_drives = GetLogicalDrives();
37     ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
38
39     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
40     {
41         type = GetDriveTypeA(drive);
42         ok(type > 0 && type <= 6, "not a valid drive %c: type %u\n", drive[0], type);
43
44         if (!(logical_drives & 1))
45             ok(type == DRIVE_NO_ROOT_DIR,
46                "GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
47                drive[0], type);
48
49         logical_drives >>= 1;
50     }
51 }
52
53 static void test_GetDriveTypeW(void)
54 {
55     WCHAR drive[] = {'?',':','\\',0};
56     DWORD logical_drives;
57     UINT type;
58
59     logical_drives = GetLogicalDrives();
60     ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
61
62     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
63     {
64         type = GetDriveTypeW(drive);
65         if (type == DRIVE_UNKNOWN && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
66         {
67             /* Must be Win9x which doesn't support the Unicode functions */
68             return;
69         }
70         ok(type > 0 && type <= 6, "not a valid drive %c: type %u\n", drive[0], type);
71
72         if (!(logical_drives & 1))
73             ok(type == DRIVE_NO_ROOT_DIR,
74                "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
75                drive[0], type);
76
77         logical_drives >>= 1;
78     }
79 }
80
81 static void test_GetDiskFreeSpaceA(void)
82 {
83     BOOL ret;
84     DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
85     char drive[] = "?:\\";
86     DWORD logical_drives;
87
88     ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
89     ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
90
91     ret = GetDiskFreeSpaceA("", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
92     ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
93        "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
94        ret, GetLastError());
95
96     ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
97     ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
98
99     ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
100     ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
101
102     logical_drives = GetLogicalDrives();
103     ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
104
105     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
106     {
107         UINT drivetype = GetDriveTypeA(drive);
108         /* Skip floppy drives because NT pops up a MessageBox if no
109          * floppy is present
110          */
111         if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
112         {
113             ret = GetDiskFreeSpaceA(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
114             if (!(logical_drives & 1))
115                 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
116                    "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
117                    drive, ret, GetLastError());
118             else
119             {
120                 ok(ret ||
121                    (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_DRIVE)),
122                    "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
123                    drive, ret, GetLastError());
124                 if( GetVersion() & 0x80000000)
125                     /* win3.0 thru winME */
126                     ok( total_clusters <= 65535,
127                             "total clusters is %d > 65535\n", total_clusters);
128                 else if (pGetDiskFreeSpaceExA) {
129                     /* NT, 2k, XP : GetDiskFreeSpace should be accurate */
130                     ULARGE_INTEGER totEx, tot, d;
131
132                     tot.QuadPart = sectors_per_cluster;
133                     tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
134                     ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
135                     ok( ret || (!ret && ERROR_NOT_READY == GetLastError()),
136                         "GetDiskFreeSpaceExA( %s ) failed. GetLastError=%d\n", drive, GetLastError());
137                     ok( bytes_per_sector == 0 || /* empty cd rom drive */
138                         totEx.QuadPart <= tot.QuadPart,
139                         "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
140                 }
141             }
142         }
143         logical_drives >>= 1;
144     }
145 }
146
147 static void test_GetDiskFreeSpaceW(void)
148 {
149     BOOL ret;
150     DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
151     WCHAR drive[] = {'?',':','\\',0};
152     DWORD logical_drives;
153     static const WCHAR empty_pathW[] = { 0 };
154     static const WCHAR root_pathW[] = { '\\', 0 };
155     static const WCHAR unix_style_root_pathW[] = { '/', 0 };
156
157     ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
158     if (ret == 0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
159     {
160         /* Must be Win9x which doesn't support the Unicode functions */
161         return;
162     }
163     ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
164
165     ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
166     ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
167        "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
168        ret, GetLastError());
169
170     ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
171     ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
172
173     ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
174     ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
175
176     logical_drives = GetLogicalDrives();
177     ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
178
179     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
180     {
181         UINT drivetype = GetDriveTypeW(drive);
182         /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
183         if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
184         {
185             ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
186             if (!(logical_drives & 1))
187                 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
188                    "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
189                    drive[0], ret, GetLastError());
190             else
191                 ok(ret || GetLastError() == ERROR_NOT_READY,
192                    "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
193                    drive[0], ret, GetLastError());
194         }
195         logical_drives >>= 1;
196     }
197 }
198
199 START_TEST(drive)
200 {
201     HANDLE hkernel32 = GetModuleHandleA("kernel32");
202     pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
203
204     test_GetDriveTypeA();
205     test_GetDriveTypeW();
206
207     test_GetDiskFreeSpaceA();
208     test_GetDiskFreeSpaceW();
209 }