msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / kernel32 / tests / volume.c
blob97e3559c000addeba7bbcf3f25245fe42de60ff0
1 /*
2 * Unit test suite
4 * Copyright 2006 Stefan Leichter
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
22 #include "winbase.h"
24 static HINSTANCE hdll;
25 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
26 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
27 static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
28 static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
29 static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
30 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
31 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
33 /* ############################### */
35 static void test_query_dos_deviceA(void)
37 char drivestr[] = "a:";
38 char *p, buffer[2000];
39 DWORD ret;
40 BOOL found = FALSE;
42 if (!pFindFirstVolumeA) {
43 skip("On win9x, HARDDISK and RAMDISK not present\n");
44 return;
47 for (;drivestr[0] <= 'z'; drivestr[0]++) {
48 ret = QueryDosDeviceA( drivestr, buffer, sizeof(buffer));
49 if(ret) {
50 for (p = buffer; *p; p++) *p = toupper(*p);
51 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
54 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
57 static void test_FindFirstVolume(void)
59 char volume[51];
60 HANDLE handle;
62 if (!pFindFirstVolumeA) {
63 skip("FindFirstVolumeA not found\n");
64 return;
67 handle = pFindFirstVolumeA( volume, 0 );
68 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
69 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
70 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
71 "wrong error %u\n", GetLastError() );
72 handle = pFindFirstVolumeA( volume, 49 );
73 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
74 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
75 handle = pFindFirstVolumeA( volume, 51 );
76 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
77 if (handle != INVALID_HANDLE_VALUE)
81 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
82 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
83 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
84 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
85 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
86 pFindVolumeClose( handle );
90 static void test_GetVolumeNameForVolumeMountPointA(void)
92 BOOL ret;
93 char volume[MAX_PATH], path[] = "c:\\";
94 DWORD len = sizeof(volume);
96 /* not present before w2k */
97 if (!pGetVolumeNameForVolumeMountPointA) {
98 skip("GetVolumeNameForVolumeMountPointA not found\n");
99 return;
102 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
103 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
105 if (0) { /* these crash on XP */
106 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
107 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
109 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
110 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
113 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
114 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
117 static void test_GetVolumeNameForVolumeMountPointW(void)
119 BOOL ret;
120 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
121 DWORD len = sizeof(volume) / sizeof(WCHAR);
123 /* not present before w2k */
124 if (!pGetVolumeNameForVolumeMountPointW) {
125 skip("GetVolumeNameForVolumeMountPointW not found\n");
126 return;
129 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
130 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
132 if (0) { /* these crash on XP */
133 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
134 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
136 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
137 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
140 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
141 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
144 static void test_GetLogicalDriveStringsA(void)
146 UINT size, size2;
147 char *buf, *ptr;
149 if(!pGetLogicalDriveStringsA) {
150 win_skip("GetLogicalDriveStringsA not available\n");
151 return;
154 size = pGetLogicalDriveStringsA(0, NULL);
155 ok(size%4 == 1, "size = %d\n", size);
157 buf = HeapAlloc(GetProcessHeap(), 0, size);
159 *buf = 0;
160 size2 = pGetLogicalDriveStringsA(2, buf);
161 ok(size2 == size, "size2 = %d\n", size2);
162 ok(!*buf, "buf changed\n");
164 size2 = pGetLogicalDriveStringsA(size, buf);
165 ok(size2 == size-1, "size2 = %d\n", size2);
167 for(ptr = buf; ptr < buf+size2; ptr += 4) {
168 ok(('A' <= *ptr && *ptr <= 'Z') ||
169 (broken('a' <= *ptr && *ptr <= 'z')), /* Win9x and WinMe */
170 "device name '%c' is not uppercase\n", *ptr);
171 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
172 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
173 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
175 ok(!*ptr, "buf[size2] is not nullbyte\n");
177 HeapFree(GetProcessHeap(), 0, buf);
180 static void test_GetLogicalDriveStringsW(void)
182 UINT size, size2;
183 WCHAR *buf, *ptr;
185 if(!pGetLogicalDriveStringsW) {
186 win_skip("GetLogicalDriveStringsW not available\n");
187 return;
190 SetLastError(0xdeadbeef);
191 size = pGetLogicalDriveStringsW(0, NULL);
192 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
193 win_skip("GetLogicalDriveStringsW not implemented\n");
194 return;
196 ok(size%4 == 1, "size = %d\n", size);
198 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
200 *buf = 0;
201 size2 = pGetLogicalDriveStringsW(2, buf);
202 ok(size2 == size, "size2 = %d\n", size2);
203 ok(!*buf, "buf changed\n");
205 size2 = pGetLogicalDriveStringsW(size, buf);
206 ok(size2 == size-1, "size2 = %d\n", size2);
208 for(ptr = buf; ptr < buf+size2; ptr += 4) {
209 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
210 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
211 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
212 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
214 ok(!*ptr, "buf[size2] is not nullbyte\n");
216 HeapFree(GetProcessHeap(), 0, buf);
219 START_TEST(volume)
221 hdll = GetModuleHandleA("kernel32.dll");
222 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
223 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
224 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
225 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
226 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
227 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
228 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
230 test_query_dos_deviceA();
231 test_FindFirstVolume();
232 test_GetVolumeNameForVolumeMountPointA();
233 test_GetVolumeNameForVolumeMountPointW();
234 test_GetLogicalDriveStringsA();
235 test_GetLogicalDriveStringsW();