Fixed some illegal lvalue casts / increments.
[wine] / dlls / kernel / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 void test_GetDriveTypeA(void)
29 {
30     char drive[] = "?:\\";
31     DWORD logical_drives;
32     UINT type;
33
34     logical_drives = GetLogicalDrives();
35     ok(logical_drives != 0, "GetLogicalDrives error %ld\n", GetLastError());
36
37     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
38     {
39         type = GetDriveTypeA(drive);
40         ok(type > 0 && type <= 6, "not a valid drive %c: type %u\n", drive[0], type);
41
42         if (!(logical_drives & 1))
43             ok(type == DRIVE_NO_ROOT_DIR,
44                "GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistant drive %c: but not %u\n",
45                drive[0], type);
46
47         logical_drives >>= 1;
48     }
49 }
50
51 void test_GetDriveTypeW(void)
52 {
53     WCHAR drive[] = {'?',':','\\',0};
54     DWORD logical_drives;
55     UINT type;
56
57     logical_drives = GetLogicalDrives();
58     ok(logical_drives != 0, "GetLogicalDrives error %ld\n", GetLastError());
59
60     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
61     {
62         type = GetDriveTypeW(drive);
63         if (type == DRIVE_UNKNOWN && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
64         {
65             /* Must be Win9x which doesn't support the Unicode functions */
66             return;
67         }
68         ok(type > 0 && type <= 6, "not a valid drive %c: type %u\n", drive[0], type);
69
70         if (!(logical_drives & 1))
71             ok(type == DRIVE_NO_ROOT_DIR,
72                "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistant drive %c: but not %u\n",
73                drive[0], type);
74
75         logical_drives >>= 1;
76     }
77 }
78
79 void test_GetDiskFreeSpaceA(void)
80 {
81     BOOL ret;
82     DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
83     char drive[] = "?:\\";
84     DWORD logical_drives;
85
86     ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
87     ok(ret, "GetDiskFreeSpaceA error %ld\n", GetLastError());
88
89     ret = GetDiskFreeSpaceA("", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
90     ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
91        "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%ld\n",
92        ret, GetLastError());
93
94     ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
95     ok(ret, "GetDiskFreeSpaceA error %ld\n", GetLastError());
96
97     ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
98     ok(ret, "GetDiskFreeSpaceA error %ld\n", GetLastError());
99
100     logical_drives = GetLogicalDrives();
101     ok(logical_drives != 0, "GetLogicalDrives error %ld\n", GetLastError());
102
103     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
104     {
105         /* Skip floppy drives because NT pops up a MessageBox if no
106          * floppy is present
107          */
108         if (GetDriveTypeA(drive)!=DRIVE_REMOVABLE)
109         {
110             ret = GetDiskFreeSpaceA(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
111             if (!(logical_drives & 1))
112                 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
113                    "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld\n",
114                    drive, ret, GetLastError());
115             else
116                 ok(ret ||
117                    (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_DRIVE)),
118                    "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld\n",
119                    drive, ret, GetLastError());
120         }
121         logical_drives >>= 1;
122     }
123 }
124
125 void test_GetDiskFreeSpaceW(void)
126 {
127     BOOL ret;
128     DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
129     WCHAR drive[] = {'?',':','\\',0};
130     DWORD logical_drives;
131     static const WCHAR empty_pathW[] = { 0 };
132     static const WCHAR root_pathW[] = { '\\', 0 };
133     static const WCHAR unix_style_root_pathW[] = { '/', 0 };
134
135     ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
136     if (ret == 0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
137     {
138         /* Must be Win9x which doesn't support the Unicode functions */
139         return;
140     }
141     ok(ret, "GetDiskFreeSpaceW error %ld\n", GetLastError());
142
143     ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
144     ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
145        "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%ld\n",
146        ret, GetLastError());
147
148     ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
149     ok(ret, "GetDiskFreeSpaceW(\"\") error %ld\n", GetLastError());
150
151     ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
152     ok(ret, "GetDiskFreeSpaceW error %ld\n", GetLastError());
153
154     logical_drives = GetLogicalDrives();
155     ok(logical_drives != 0, "GetLogicalDrives error %ld\n", GetLastError());
156
157     for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
158     {
159         /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
160         if (GetDriveTypeW(drive)!=DRIVE_REMOVABLE)
161         {
162             ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
163             if (!(logical_drives & 1))
164                 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
165                    "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%ld\n",
166                    drive[0], ret, GetLastError());
167             else
168                 ok(ret || GetLastError() == ERROR_NOT_READY,
169                    "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%ld\n",
170                    drive[0], ret, GetLastError());
171         }
172         logical_drives >>= 1;
173     }
174 }
175
176 START_TEST(drive)
177 {
178     test_GetDriveTypeA();
179     test_GetDriveTypeW();
180
181     test_GetDiskFreeSpaceA();
182     test_GetDiskFreeSpaceW();
183 }