Use strlen or lstrlenA as appropriate to avoid signed/unsigned
[wine/multimedia.git] / dlls / kernel / tests / drive.c
blob45f23d4f314db845cad6e262db42129359d55148
1 /*
2 * Unit test suite for drive functions.
4 * Copyright 2002 Dmitry Timoshkov
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.
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.
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
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winerror.h"
25 void test_GetDriveTypeA(void)
27 char drive[] = "?:\\";
28 DWORD logical_drives;
29 UINT type;
31 logical_drives = GetLogicalDrives();
32 ok(logical_drives != 0, "GetLogicalDrives error %ld", GetLastError());
34 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
36 type = GetDriveTypeA(drive);
37 ok(type > 0 && type <= 6, "not a valid drive %c: type %u", drive[0], type);
39 if (!(logical_drives & 1))
40 ok(type == DRIVE_NO_ROOT_DIR,
41 "GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistant drive %c: but not %u",
42 drive[0], type);
44 logical_drives >>= 1;
48 void test_GetDriveTypeW(void)
50 WCHAR drive[] = {'?',':','\\',0};
51 DWORD logical_drives;
52 UINT type;
54 logical_drives = GetLogicalDrives();
55 ok(logical_drives != 0, "GetLogicalDrives error %ld", GetLastError());
57 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
59 type = GetDriveTypeW(drive);
60 if (type == DRIVE_UNKNOWN && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
62 /* Must be Win9x which doesn't support the Unicode functions */
63 return;
65 ok(type > 0 && type <= 6, "not a valid drive %c: type %u", drive[0], type);
67 if (!(logical_drives & 1))
68 ok(type == DRIVE_NO_ROOT_DIR,
69 "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistant drive %c: but not %u",
70 drive[0], type);
72 logical_drives >>= 1;
76 void test_GetDiskFreeSpaceA(void)
78 BOOL ret;
79 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
80 char drive[] = "?:\\";
81 DWORD logical_drives;
83 ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
84 ok(ret, "GetDiskFreeSpaceA error %ld", GetLastError());
86 ret = GetDiskFreeSpaceA("", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
87 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
88 "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%ld",
89 ret, GetLastError());
91 ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
92 ok(ret, "GetDiskFreeSpaceA error %ld", GetLastError());
94 ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
95 ok(ret, "GetDiskFreeSpaceA error %ld", GetLastError());
97 logical_drives = GetLogicalDrives();
98 ok(logical_drives != 0, "GetLogicalDrives error %ld", GetLastError());
100 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
102 /* Skip floppy drives because NT pops up a MessageBox if no
103 * floppy is present
105 if (GetDriveTypeA(drive)!=DRIVE_REMOVABLE)
107 ret = GetDiskFreeSpaceA(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
108 if (!(logical_drives & 1))
109 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
110 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld",
111 drive, ret, GetLastError());
112 else
113 ok(ret ||
114 (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_DRIVE)),
115 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld",
116 drive, ret, GetLastError());
118 logical_drives >>= 1;
122 void test_GetDiskFreeSpaceW(void)
124 BOOL ret;
125 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
126 WCHAR drive[] = {'?',':','\\',0};
127 DWORD logical_drives;
128 static const WCHAR empty_pathW[] = { 0 };
129 static const WCHAR root_pathW[] = { '\\', 0 };
130 static const WCHAR unix_style_root_pathW[] = { '/', 0 };
132 ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
133 if (ret == 0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
135 /* Must be Win9x which doesn't support the Unicode functions */
136 return;
138 ok(ret, "GetDiskFreeSpaceW error %ld", GetLastError());
140 ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
141 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
142 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%ld",
143 ret, GetLastError());
145 ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
146 ok(ret, "GetDiskFreeSpaceW(\"\") error %ld", GetLastError());
148 ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
149 ok(ret, "GetDiskFreeSpaceW error %ld", GetLastError());
151 logical_drives = GetLogicalDrives();
152 ok(logical_drives != 0, "GetLogicalDrives error %ld", GetLastError());
154 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
156 /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
157 if (GetDriveTypeW(drive)!=DRIVE_REMOVABLE)
159 ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
160 if (!(logical_drives & 1))
161 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
162 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%ld",
163 drive[0], ret, GetLastError());
164 else
165 ok(ret || GetLastError() == ERROR_NOT_READY,
166 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%ld",
167 drive[0], ret, GetLastError());
169 logical_drives >>= 1;
173 START_TEST(drive)
175 test_GetDriveTypeA();
176 test_GetDriveTypeW();
178 test_GetDiskFreeSpaceA();
179 test_GetDiskFreeSpaceW();