Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / kernel / tests / path.c
bloba5e511ef9221b313af00ea46951d803b2bc3e15d
1 /*
2 * Unit test suite for Get*PathNamesA and (Get|Set)CurrentDirectoryA.
4 * Copyright 2002 Geoffrey Hausheer
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 <stdarg.h>
22 #include <stdio.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "winnls.h"
30 #define HAS_TRAIL_SLASH_A(string) (string[lstrlenA(string)-1]=='\\')
32 #define LONGFILE "Long File test.path"
33 #define SHORTFILE "pathtest.pth"
34 #define SHORTDIR "shortdir"
35 #define LONGDIR "Long Directory"
36 #define NONFILE_SHORT "noexist.pth"
37 #define NONFILE_LONG "Non Existent File"
38 #define NONDIR_SHORT "notadir"
39 #define NONDIR_LONG "Non Existent Directory"
41 #define NOT_A_VALID_DRIVE '@'
43 /* the following characters don't work well with GetFullPathNameA
44 in Win98. I don't know if this is a FAT thing, or if it is an OS thing
45 but I don't test these characters now.
46 NOTE: Win2k allows GetFullPathNameA to work with them though
47 |<>"
49 static const CHAR funny_chars[]="!@#$%^&*()=+{}[],?'`";
50 static const CHAR is_char_ok[] ="11111110111111111011";
51 static const CHAR wine_todo[] ="00000000000000000000";
53 static DWORD (WINAPI *pGetLongPathNameA)(LPCSTR,LPSTR,DWORD);
55 /* a structure to deal with wine todos somewhat cleanly */
56 typedef struct {
57 DWORD shortlen;
58 DWORD shorterror;
59 DWORD s2llen;
60 DWORD s2lerror;
61 DWORD longlen;
62 DWORD longerror;
63 } SLpassfail;
65 /* function that tests GetFullPathNameA, GetShortPathNameA,GetLongPathNameA */
66 /* NOTE: the passfail structure is used to allow cutomizeable todo checking
67 for wine. It is not very pretty, but it sure beats duplicating this
68 function lots of times
70 static void test_ValidPathA(CHAR *curdir, CHAR *subdir, CHAR *filename,
71 CHAR *shortstr, SLpassfail *passfail, CHAR *errstr) {
72 CHAR tmpstr[MAX_PATH],
73 fullpath[MAX_PATH], /*full path to the file (not short/long) */
74 subpath[MAX_PATH], /*relative path to the file */
75 fullpathshort[MAX_PATH], /*absolue path to the file (short format) */
76 fullpathlong[MAX_PATH], /*absolute path to the file (long format) */
77 curdirshort[MAX_PATH], /*absolute path to the current dir (short) */
78 curdirlong[MAX_PATH]; /*absolute path to the current dir (long) */
79 LPSTR strptr; /*ptr to the filename portion of the path */
80 DWORD len;
81 /* if passfail is NULL, we can perform all checks within this function,
82 otherwise, we will return the relevant data in the passfail struct, so
83 we must initialize it first
85 if(passfail!=NULL) {
86 passfail->shortlen=-1;passfail->s2llen=-1;passfail->longlen=-1;
87 passfail->shorterror=0;passfail->s2lerror=0;passfail->longerror=0;
89 /* GetLongPathNameA is only supported on Win2k+ and Win98+ */
90 if(pGetLongPathNameA) {
91 ok((len=pGetLongPathNameA(curdir,curdirlong,MAX_PATH)),
92 "%s: GetLongPathNameA failed",errstr);
93 /*GetLongPathNameA can return a trailing '\\' but shouldn't do so here */
94 ok(! HAS_TRAIL_SLASH_A(curdirlong),
95 "%s: GetLongPathNameA should not have a trailing \\",errstr);
97 ok((len=GetShortPathNameA(curdir,curdirshort,MAX_PATH)),
98 "%s: GetShortPathNameA failed",errstr);
99 /*GetShortPathNameA can return a trailing '\\' but shouldn't do so here */
100 ok(! HAS_TRAIL_SLASH_A(curdirshort),
101 "%s: GetShortPathNameA should not have a trailing \\",errstr);
102 /* build relative and absolute paths from inputs */
103 if(lstrlenA(subdir)) {
104 sprintf(subpath,"%s\\%s",subdir,filename);
105 } else {
106 lstrcpyA(subpath,filename);
108 sprintf(fullpath,"%s\\%s",curdir,subpath);
109 sprintf(fullpathshort,"%s\\%s",curdirshort,subpath);
110 sprintf(fullpathlong,"%s\\%s",curdirlong,subpath);
111 /* Test GetFullPathNameA functionality */
112 len=GetFullPathNameA(subpath,MAX_PATH,tmpstr,&strptr);
113 ok(len, "GetFullPathNameA failed for: '%s'",subpath);
114 if(HAS_TRAIL_SLASH_A(subpath)) {
115 /* Wine strips off the trailing '\\'. Neither Win98 nor Win2k do this. */
116 todo_wine {
117 ok(strptr==NULL,
118 "%s: GetFullPathNameA should not return a filename ptr",errstr);
119 ok(lstrcmpiA(fullpath,tmpstr)==0,
120 "%s: GetFullPathNameA returned '%s' instead of '%s'",
121 errstr,tmpstr,fullpath);
123 } else {
124 ok(lstrcmpiA(strptr,filename)==0,
125 "%s: GetFullPathNameA returned '%s' instead of '%s'",
126 errstr,strptr,filename);
127 ok(lstrcmpiA(fullpath,tmpstr)==0,
128 "%s: GetFullPathNameA returned '%s' instead of '%s'",
129 errstr,tmpstr,fullpath);
131 /* Test GetShortPathNameA functionality */
132 SetLastError(0);
133 len=GetShortPathNameA(fullpathshort,shortstr,MAX_PATH);
134 if(passfail==NULL) {
135 ok(len, "%s: GetShortPathNameA failed",errstr);
136 } else {
137 passfail->shortlen=len;
138 passfail->shorterror=GetLastError();
140 /* Test GetLongPathNameA functionality
141 We test both conversion from GetFullPathNameA and from GetShortPathNameA
143 if(pGetLongPathNameA) {
144 if(len==0) {
145 SetLastError(0);
146 len=pGetLongPathNameA(shortstr,tmpstr,MAX_PATH);
147 if(passfail==NULL) {
148 ok(len,
149 "%s: GetLongPathNameA failed during Short->Long conversion", errstr);
150 ok(lstrcmpiA(fullpathlong,tmpstr)==0,
151 "%s: GetLongPathNameA returned '%s' instead of '%s'",
152 errstr,tmpstr,fullpathlong);
153 } else {
154 passfail->s2llen=len;
155 passfail->s2lerror=GetLastError();
158 SetLastError(0);
159 len=pGetLongPathNameA(fullpath,tmpstr,MAX_PATH);
160 if(passfail==NULL) {
161 ok(len, "%s: GetLongPathNameA failed",errstr);
162 if(HAS_TRAIL_SLASH_A(fullpath)) {
163 /* Wine strips off the trailing '\\' Neither Win98 nor Win2k do this */
164 todo_wine {
165 ok(lstrcmpiA(fullpathlong,tmpstr)==0,
166 "%s: GetLongPathNameA returned '%s' instead of '%s'",
167 errstr,tmpstr,fullpathlong);
169 } else {
170 ok(lstrcmpiA(fullpathlong,tmpstr)==0,
171 "%s: GetLongPathNameA returned '%s' instead of '%s'",
172 errstr,tmpstr,fullpathlong);
174 } else {
175 passfail->longlen=len;
176 passfail->longerror=GetLastError();
181 /* split path into leading directory, and 8.3 filename */
182 static void test_SplitShortPathA(CHAR *path,CHAR *dir,CHAR *eight,CHAR *three) {
183 int done,error;
184 int ext,fil;
185 int len,i;
186 len=lstrlenA(path);
187 ext=len; fil=len; done=0; error=0;
188 /* walk backwards over path looking for '.' or '\\' separators */
189 for(i=len-1;(i>=0) && (!done);i--) {
190 if(path[i]=='.')
191 if(ext!=len) error=1; else ext=i;
192 else if(path[i]=='\\') {
193 if(i==len-1) {
194 error=1;
195 } else {
196 fil=i;
197 done=1;
201 /* Check that we didn't find a trailing '\\' or multiple '.' */
202 ok(!error,"Illegal file found in 8.3 path '%s'",path);
203 /* Separate dir, root, and extension */
204 if(ext!=len) lstrcpyA(three,path+ext+1); else lstrcpyA(three,"");
205 if(fil!=len) {
206 lstrcpynA(eight,path+fil+1,ext-fil);
207 lstrcpynA(dir,path,fil+1);
208 } else {
209 lstrcpynA(eight,path,ext+1);
210 lstrcpyA(dir,"");
212 /* Validate that root and extension really are 8.3 */
213 ok(lstrlenA(eight)<=8 && lstrlenA(three)<=3,
214 "GetShortPathNAmeA did not return an 8.3 path");
217 /* Check that GetShortPathNameA returns a valid 8.3 path */
218 static void test_LongtoShortA(CHAR *teststr,CHAR *goodstr,
219 CHAR *ext,CHAR *errstr) {
220 CHAR dir[MAX_PATH],eight[MAX_PATH],three[MAX_PATH];
222 test_SplitShortPathA(teststr,dir,eight,three);
223 ok(lstrcmpiA(dir,goodstr)==0,
224 "GetShortPathNameA returned '%s' instead of '%s'",dir,goodstr);
225 ok(lstrcmpiA(three,ext)==0,
226 "GetShortPathNameA returned '%s' with incorrect extension",three);
229 /* Test that Get(Short|Long|Full)PathNameA work correctly with interesting
230 characters in the filename.
231 'valid' indicates whether this would be an allowed filename
232 'todo' indictaes that wine doesn't get this right yet.
233 NOTE: We always call this routine with a non-existent filename, so
234 Get(Short|Long)PathNameA should never pass, but GetFullPathNameA
235 should.
237 static void test_FunnyChars(CHAR *curdir,CHAR *filename,
238 INT valid,INT todo,CHAR *errstr) {
239 CHAR tmpstr[MAX_PATH],tmpstr1[MAX_PATH];
240 SLpassfail passfail;
242 test_ValidPathA(curdir,"",filename,tmpstr,&passfail,errstr);
243 if(valid) {
244 sprintf(tmpstr1,"%s\\%s",curdir,filename);
245 if(todo) {
246 todo_wine {
247 ok((passfail.shortlen==0 &&
248 (passfail.shorterror==ERROR_FILE_NOT_FOUND || passfail.shorterror==ERROR_PATH_NOT_FOUND || !passfail.shorterror)) ||
249 (passfail.shortlen==strlen(tmpstr1) && lstrcmpiA(tmpstr,tmpstr1)==0),
250 "%s: GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]",
251 errstr,passfail.shortlen,passfail.shorterror,tmpstr);
253 } else {
254 ok((passfail.shortlen==0 &&
255 (passfail.shorterror==ERROR_FILE_NOT_FOUND || passfail.shorterror==ERROR_PATH_NOT_FOUND || !passfail.shorterror)) ||
256 (passfail.shortlen==strlen(tmpstr1) && lstrcmpiA(tmpstr,tmpstr1)==0),
257 "%s: GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]",
258 errstr,passfail.shortlen,passfail.shorterror,tmpstr);
260 } else {
261 if(todo) {
262 todo_wine {
263 /* Win2k returns ERROR_INVALID_NAME, Win98, wine return ERROR_FILE_NOT_FOUND, NT4 doesn't set last error */
264 ok(passfail.shortlen==0 &&
265 (passfail.shorterror==ERROR_INVALID_NAME || passfail.shorterror==ERROR_FILE_NOT_FOUND || !passfail.shorterror),
266 "%s: GetShortPathA should have failed len=%ld, error=%ld",
267 errstr,passfail.shortlen,passfail.shorterror);
269 } else {
270 ok(passfail.shortlen==0 &&
271 (passfail.shorterror==ERROR_INVALID_NAME || passfail.shorterror==ERROR_FILE_NOT_FOUND || !passfail.shorterror),
272 "%s: GetShortPathA should have failed len=%ld, error=%ld",
273 errstr,passfail.shortlen,passfail.shorterror);
276 if(pGetLongPathNameA) {
277 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
278 if(valid) {
279 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
280 "%s: GetLongPathA returned %ld and not %d",
281 errstr,passfail.longerror,ERROR_FILE_NOT_FOUND);
282 } else {
283 ok(passfail.longerror==ERROR_INVALID_NAME ||
284 passfail.longerror==ERROR_FILE_NOT_FOUND,
285 "%s: GetLongPathA returned %ld and not %d or %d'",
286 errstr, passfail.longerror,ERROR_INVALID_NAME,ERROR_FILE_NOT_FOUND);
291 /* Routine to test that SetCurrentDirectory behaves as expected. */
292 static void test_setdir(CHAR *olddir,CHAR *newdir,
293 CHAR *cmprstr, INT pass,CHAR *errstr)
295 CHAR tmppath[MAX_PATH], *dirptr;
296 DWORD val,len,chklen;
298 val=SetCurrentDirectoryA(newdir);
299 len=GetCurrentDirectoryA(MAX_PATH,tmppath);
300 /* if 'pass' then the SetDirectoryA was supposed to pass */
301 if(pass) {
302 dirptr=(cmprstr==NULL) ? newdir : cmprstr;
303 chklen=lstrlenA(dirptr);
304 ok(val,"%s: SetCurrentDirectoryA failed",errstr);
305 ok(len==chklen,
306 "%s: SetCurrentDirectory did not change the directory, though it passed",
307 errstr);
308 ok(lstrcmpiA(dirptr,tmppath)==0,
309 "%s: SetCurrentDirectory did not change the directory, though it passed",
310 errstr);
311 ok(SetCurrentDirectoryA(olddir),
312 "%s: Couldn't set directory to it's original value",errstr);
313 } else {
314 /* else thest that it fails correctly */
315 chklen=lstrlenA(olddir);
316 ok(val==0,
317 "%s: SetCurrentDirectoryA passed when it should have failed",errstr);
318 ok(len==chklen,
319 "%s: SetCurrentDirectory changed the directory, though it failed",
320 errstr);
321 ok(lstrcmpiA(olddir,tmppath)==0,
322 "%s: SetCurrentDirectory changed the directory, though it failed",
323 errstr);
326 static void test_InitPathA(CHAR *newdir, CHAR *curDrive, CHAR *otherDrive)
328 CHAR tmppath[MAX_PATH], /*path to TEMP */
329 tmpstr[MAX_PATH],
330 tmpstr1[MAX_PATH];
331 DWORD len,len1,drives;
332 INT id;
333 HANDLE hndl;
335 *curDrive = *otherDrive = NOT_A_VALID_DRIVE;
337 /* Get the current drive letter */
338 if( GetCurrentDirectoryA( MAX_PATH, tmpstr))
339 *curDrive = tmpstr[0];
340 else
341 trace( "Unable to discover current drive, some tests will not be conducted.\n");
343 /* Test GetTempPathA */
344 len=GetTempPathA(MAX_PATH,tmppath);
345 ok(len!=0 && len < MAX_PATH,"GetTempPathA failed");
346 ok(HAS_TRAIL_SLASH_A(tmppath),
347 "GetTempPathA returned a path that did not end in '\\'");
348 lstrcpyA(tmpstr,"aaaaaaaa");
349 len1=GetTempPathA(len,tmpstr);
350 ok(len1==len+1,
351 "GetTempPathA should return string length %ld instead of %ld",len+1,len1);
353 /* Test GetTmpFileNameA
354 The only test we do here is whether GetTempFileNameA passes or not.
355 We do not thoroughly test this function yet (specifically, whether
356 it behaves correctly when 'unique' is non zero)
358 ok((id=GetTempFileNameA(tmppath,"path",0,newdir)),"GetTempFileNameA failed");
359 sprintf(tmpstr,"pat%.4x.tmp",id & 0xffff);
360 sprintf(tmpstr1,"pat%x.tmp",id & 0xffff);
361 ok(lstrcmpiA(newdir+lstrlenA(tmppath),tmpstr)==0 ||
362 lstrcmpiA(newdir+lstrlenA(tmppath),tmpstr1)==0,
363 "GetTempPath returned '%s' which doesn't match '%s' or '%s'. id=%x",
364 newdir,tmpstr,tmpstr1,id);
366 /* Find first valid drive letter that is neither newdir[0] nor curDrive */
367 drives = GetLogicalDrives() & ~(1<<(newdir[0]-'A'));
368 if( *curDrive != NOT_A_VALID_DRIVE)
369 drives &= ~(1<<(*curDrive-'A'));
370 if( drives)
371 for( *otherDrive='A'; (drives & 1) == 0; drives>>=1, (*otherDrive)++);
372 else
373 trace( "Could not find alternative drive, some tests will not be conducted.\n");
375 /* Do some CreateDirectoryA tests */
376 /* It would be nice to do test the SECURITY_ATTRIBUTES, but I don't
377 really understand how they work.
378 More formal tests should be done along with CreateFile tests
380 ok(CreateDirectoryA(newdir,NULL)==0,
381 "CreateDirectoryA succeeded even though a file of the same name exists");
382 ok(DeleteFileA(newdir),"Couldn't delete the temporary file we just created");
383 ok(CreateDirectoryA(newdir,NULL),"CreateDirectoryA failed");
384 /* Create some files to test other functions. Note, we will test CreateFileA
385 at some later point
387 sprintf(tmpstr,"%s\\%s",newdir,SHORTDIR);
388 ok(CreateDirectoryA(tmpstr,NULL),"CreateDirectoryA failed");
389 sprintf(tmpstr,"%s\\%s",newdir,LONGDIR);
390 ok(CreateDirectoryA(tmpstr,NULL),"CreateDirectoryA failed");
391 sprintf(tmpstr,"%s\\%s\\%s",newdir,SHORTDIR,SHORTFILE);
392 hndl=CreateFileA(tmpstr,GENERIC_WRITE,0,NULL,
393 CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
394 ok(hndl!=INVALID_HANDLE_VALUE,"CreateFileA failed");
395 ok(CloseHandle(hndl),"CloseHandle failed");
396 sprintf(tmpstr,"%s\\%s\\%s",newdir,SHORTDIR,LONGFILE);
397 hndl=CreateFileA(tmpstr,GENERIC_WRITE,0,NULL,
398 CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
399 ok(hndl!=INVALID_HANDLE_VALUE,"CreateFileA failed");
400 ok(CloseHandle(hndl),"CloseHandle failed");
401 sprintf(tmpstr,"%s\\%s\\%s",newdir,LONGDIR,SHORTFILE);
402 hndl=CreateFileA(tmpstr,GENERIC_WRITE,0,NULL,
403 CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
404 ok(hndl!=INVALID_HANDLE_VALUE,"CreateFileA failed");
405 ok(CloseHandle(hndl),"CloseHandle failed");
406 sprintf(tmpstr,"%s\\%s\\%s",newdir,LONGDIR,LONGFILE);
407 hndl=CreateFileA(tmpstr,GENERIC_WRITE,0,NULL,
408 CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
409 ok(hndl!=INVALID_HANDLE_VALUE,"CreateFileA failed");
410 ok(CloseHandle(hndl),"CloseHandle failed");
413 /* Test GetCurrentDirectory & SetCurrentDirectory */
414 static void test_CurrentDirectoryA(CHAR *origdir, CHAR *newdir)
416 CHAR tmpstr[MAX_PATH],tmpstr1[MAX_PATH];
417 DWORD len,len1;
418 /* Save the original directory, so that we can return to it at the end
419 of the test
421 len=GetCurrentDirectoryA(MAX_PATH,origdir);
422 ok(len!=0 && len < MAX_PATH,"GetCurrentDirectoryA failed");
423 ok(lstrcmpiA(origdir+(len-1),"\\")!=0,
424 "GetCurrentDirectoryA should not have a trailing \\");
425 /* Make sure that CetCurrentDirectoryA doesn't overwrite the buffer when the
426 buffer size is too small to hold the current directory
428 lstrcpyA(tmpstr,"aaaaaaa");
429 len1=GetCurrentDirectoryA(len,tmpstr);
430 ok(len1==len+1, "GetCurrentDirectoryA returned %ld instead of %ld",len1,len+1);
431 ok(lstrcmpiA(tmpstr,"aaaaaaa")==0,
432 "GetCurrentDirectoryA should not have modified the buffer");
433 /* SetCurrentDirectoryA shouldn't care whether the string has a
434 trailing '\\' or not
436 sprintf(tmpstr,"%s\\",newdir);
437 test_setdir(origdir,tmpstr,newdir,1,"check 1");
438 test_setdir(origdir,newdir,NULL,1,"check 2");
439 /* Set the directory to the working area. We just tested that this works,
440 so why check it again.
442 SetCurrentDirectoryA(newdir);
443 /* Check that SetCurrentDirectory fails when a non-existent dir is specified */
444 sprintf(tmpstr,"%s\\%s\\%s",newdir,SHORTDIR,NONDIR_SHORT);
445 test_setdir(newdir,tmpstr,NULL,0,"check 3");
446 /* Check that SetCurrentDirectory fails for a non-existent lond directory */
447 sprintf(tmpstr,"%s\\%s\\%s",newdir,SHORTDIR,NONDIR_LONG);
448 test_setdir(newdir,tmpstr,NULL,0,"check 4");
449 /* Check that SetCurrentDirectory passes with a long directory */
450 sprintf(tmpstr,"%s\\%s",newdir,LONGDIR);
451 test_setdir(newdir,tmpstr,NULL,1,"check 5");
452 /* Check that SetCurrentDirectory passes with a short relative directory */
453 sprintf(tmpstr,"%s",SHORTDIR);
454 sprintf(tmpstr1,"%s\\%s",newdir,SHORTDIR);
455 test_setdir(newdir,tmpstr,tmpstr1,1,"check 6");
456 /* starting with a '.' */
457 sprintf(tmpstr,".\\%s",SHORTDIR);
458 test_setdir(newdir,tmpstr,tmpstr1,1,"check 7");
459 /* Check that SetCurrentDirectory passes with a short relative directory */
460 sprintf(tmpstr,"%s",LONGDIR);
461 sprintf(tmpstr1,"%s\\%s",newdir,LONGDIR);
462 test_setdir(newdir,tmpstr,tmpstr1,1,"check 8");
463 /* starting with a '.' */
464 sprintf(tmpstr,".\\%s",LONGDIR);
465 test_setdir(newdir,tmpstr,tmpstr1,1,"check 9");
468 /* Cleanup the mess we made while executing these tests */
469 static void test_CleanupPathA(CHAR *origdir, CHAR *curdir)
471 CHAR tmpstr[MAX_PATH];
472 sprintf(tmpstr,"%s\\%s\\%s",curdir,SHORTDIR,SHORTFILE);
473 ok(DeleteFileA(tmpstr),"DeleteFileA failed");
474 sprintf(tmpstr,"%s\\%s\\%s",curdir,SHORTDIR,LONGFILE);
475 ok(DeleteFileA(tmpstr),"DeleteFileA failed");
476 sprintf(tmpstr,"%s\\%s\\%s",curdir,LONGDIR,SHORTFILE);
477 ok(DeleteFileA(tmpstr),"DeleteFileA failed");
478 sprintf(tmpstr,"%s\\%s\\%s",curdir,LONGDIR,LONGFILE);
479 ok(DeleteFileA(tmpstr),"DeleteFileA failed");
480 sprintf(tmpstr,"%s\\%s",curdir,SHORTDIR);
481 ok(RemoveDirectoryA(tmpstr),"RemoveDirectoryA failed");
482 sprintf(tmpstr,"%s\\%s",curdir,LONGDIR);
483 ok(RemoveDirectoryA(tmpstr),"RemoveDirectoryA failed");
484 ok(SetCurrentDirectoryA(origdir),"SetCurrentDirectoryA failed");
485 ok(RemoveDirectoryA(curdir),"RemoveDirectoryA failed");
488 /* This routine will test Get(Full|Short|Long)PathNameA */
489 static void test_PathNameA(CHAR *curdir, CHAR curDrive, CHAR otherDrive)
491 CHAR curdir_short[MAX_PATH],
492 longdir_short[MAX_PATH];
493 CHAR tmpstr[MAX_PATH],tmpstr1[MAX_PATH],tmpstr2[MAX_PATH];
494 LPSTR strptr; /*ptr to the filename portion of the path */
495 DWORD len;
496 INT i;
497 CHAR dir[MAX_PATH],eight[MAX_PATH],three[MAX_PATH];
498 SLpassfail passfail;
500 /* Get the short form of the current directory */
501 ok((len=GetShortPathNameA(curdir,curdir_short,MAX_PATH)),
502 "GetShortPathNameA failed");
503 ok(!HAS_TRAIL_SLASH_A(curdir_short),
504 "GetShortPathNameA should not have a trailing \\");
505 /* Get the short form of the absolute-path to LONGDIR */
506 sprintf(tmpstr,"%s\\%s",curdir_short,LONGDIR);
507 ok((len=GetShortPathNameA(tmpstr,longdir_short,MAX_PATH)),
508 "GetShortPathNameA failed");
509 ok(lstrcmpiA(longdir_short+(len-1),"\\")!=0,
510 "GetShortPathNameA should not have a trailing \\");
512 if (pGetLongPathNameA) {
513 DWORD rc;
514 sprintf(tmpstr,"%s\\%s\\%s",curdir,LONGDIR,LONGFILE);
515 rc=(*pGetLongPathNameA)(tmpstr,NULL,0);
516 ok(rc==strlen(tmpstr)+1,
517 "GetLongPathNameA: wrong return code, %ld instead of %d",
518 rc, strlen(curdir)+1);
520 todo_wine {
521 sprintf(dir,"%c:",curDrive);
522 rc=(*pGetLongPathNameA)(dir,tmpstr,sizeof(tmpstr));
523 ok(strcmp(dir,tmpstr)==0,
524 "GetLongPathNameA: returned '%s' instead of '%s' (rc=%ld)",
525 tmpstr,dir,rc);
529 /* Check the cases where both file and directory exist first */
530 /* Start with a 8.3 directory, 8.3 filename */
531 test_ValidPathA(curdir,SHORTDIR,SHORTFILE,tmpstr,NULL,"test1");
532 sprintf(tmpstr1,"%s\\%s\\%s",curdir_short,SHORTDIR,SHORTFILE);
533 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
534 "GetShortPathNameA returned '%s' instead of '%s'",tmpstr,tmpstr1);
535 /* Now try a 8.3 directory, long file name */
536 test_ValidPathA(curdir,SHORTDIR,LONGFILE,tmpstr,NULL,"test2");
537 sprintf(tmpstr1,"%s\\%s",curdir_short,SHORTDIR);
538 test_LongtoShortA(tmpstr,tmpstr1,"PAT","test2");
539 /* Next is a long directory, 8.3 file */
540 test_ValidPathA(curdir,LONGDIR,SHORTFILE,tmpstr,NULL,"test3");
541 sprintf(tmpstr1,"%s\\%s",longdir_short,SHORTFILE);
542 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
543 "GetShortPathNameA returned '%s' instead of '%s'",tmpstr,tmpstr1);
544 /*Lastly a long directory, long file */
545 test_ValidPathA(curdir,LONGDIR,LONGFILE,tmpstr,NULL,"test4");
546 test_LongtoShortA(tmpstr,longdir_short,"PAT","test4");
548 /* Now check all of the invalid file w/ valid directory combinations */
549 /* Start with a 8.3 directory, 8.3 filename */
550 test_ValidPathA(curdir,SHORTDIR,NONFILE_SHORT,tmpstr,&passfail,"test5");
551 sprintf(tmpstr1,"%s\\%s\\%s",curdir_short,SHORTDIR,NONFILE_SHORT);
552 ok((passfail.shortlen==0 &&
553 (passfail.shorterror==ERROR_PATH_NOT_FOUND ||
554 passfail.shorterror==ERROR_FILE_NOT_FOUND)) ||
555 (passfail.shortlen==strlen(tmpstr1) && lstrcmpiA(tmpstr,tmpstr1)==0),
556 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]",
557 passfail.shortlen,passfail.shorterror,tmpstr);
558 if(pGetLongPathNameA) {
559 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
560 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
561 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'");
563 /* Now try a 8.3 directory, long file name */
564 test_ValidPathA(curdir,SHORTDIR,NONFILE_LONG,tmpstr,&passfail,"test6");
565 ok(passfail.shortlen==0,"GetShortPathNameA passed when it shouldn't have");
566 ok(passfail.shorterror==ERROR_PATH_NOT_FOUND ||
567 passfail.shorterror==ERROR_FILE_NOT_FOUND ||
568 !passfail.shorterror,
569 "GetShortPathA should have returned 'ERROR_FILE_NOT_FOUND'");
570 if(pGetLongPathNameA) {
571 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
572 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
573 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'");
575 /* Next is a long directory, 8.3 file */
576 test_ValidPathA(curdir,LONGDIR,NONFILE_SHORT,tmpstr,&passfail,"test7");
577 sprintf(tmpstr2,"%s\\%s",curdir_short,LONGDIR);
578 GetShortPathNameA(tmpstr2,tmpstr1,MAX_PATH);
579 strcat(tmpstr1,"\\" NONFILE_SHORT);
580 ok((passfail.shortlen==0 &&
581 (passfail.shorterror==ERROR_PATH_NOT_FOUND ||
582 passfail.shorterror==ERROR_FILE_NOT_FOUND)) ||
583 (passfail.shortlen==strlen(tmpstr1) && lstrcmpiA(tmpstr,tmpstr1)==0),
584 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]",
585 passfail.shortlen,passfail.shorterror,tmpstr);
586 if(pGetLongPathNameA) {
587 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
588 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
589 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'");
591 /*Lastly a long directory, long file */
592 test_ValidPathA(curdir,LONGDIR,NONFILE_LONG,tmpstr,&passfail,"test8");
593 ok(passfail.shortlen==0,"GetShortPathNameA passed when it shouldn't have");
594 ok(passfail.shorterror==ERROR_PATH_NOT_FOUND ||
595 passfail.shorterror==ERROR_FILE_NOT_FOUND ||
596 !passfail.shorterror,
597 "GetShortPathA should have returned 'ERROR_FILE_NOT_FOUND'");
598 if(pGetLongPathNameA) {
599 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
600 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
601 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'");
603 /* Now try again with directories that don't exist */
604 /* 8.3 directory, 8.3 filename */
605 test_ValidPathA(curdir,NONDIR_SHORT,SHORTFILE,tmpstr,&passfail,"test9");
606 sprintf(tmpstr1,"%s\\%s\\%s",curdir_short,NONDIR_SHORT,SHORTFILE);
607 ok((passfail.shortlen==0 &&
608 (passfail.shorterror==ERROR_PATH_NOT_FOUND ||
609 passfail.shorterror==ERROR_FILE_NOT_FOUND)) ||
610 (passfail.shortlen==strlen(tmpstr1) && lstrcmpiA(tmpstr,tmpstr1)==0),
611 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]",
612 passfail.shortlen,passfail.shorterror,tmpstr);
613 if(pGetLongPathNameA) {
614 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
615 ok(passfail.longerror==ERROR_PATH_NOT_FOUND ||
616 passfail.longerror==ERROR_FILE_NOT_FOUND,
617 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
618 passfail.longerror);
620 /* Now try a 8.3 directory, long file name */
621 test_ValidPathA(curdir,NONDIR_SHORT,LONGFILE,tmpstr,&passfail,"test10");
622 ok(passfail.shortlen==0,"GetShortPathNameA passed when it shouldn't have");
623 ok(passfail.shorterror==ERROR_PATH_NOT_FOUND ||
624 passfail.shorterror==ERROR_FILE_NOT_FOUND ||
625 !passfail.shorterror,
626 "GetShortPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
627 passfail.shorterror);
628 if(pGetLongPathNameA) {
629 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
630 ok(passfail.longerror==ERROR_PATH_NOT_FOUND ||
631 passfail.longerror==ERROR_FILE_NOT_FOUND,
632 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
633 passfail.longerror);
635 /* Next is a long directory, 8.3 file */
636 test_ValidPathA(curdir,NONDIR_LONG,SHORTFILE,tmpstr,&passfail,"test11");
637 ok(passfail.shortlen==0,"GetShortPathNameA passed when it shouldn't have");
638 ok(passfail.shorterror==ERROR_PATH_NOT_FOUND ||
639 passfail.shorterror==ERROR_FILE_NOT_FOUND ||
640 !passfail.shorterror,
641 "GetShortPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
642 passfail.shorterror);
643 if(pGetLongPathNameA) {
644 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
645 ok(passfail.longerror==ERROR_PATH_NOT_FOUND ||
646 passfail.longerror==ERROR_FILE_NOT_FOUND,
647 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
648 passfail.longerror);
650 /*Lastly a long directory, long file */
651 test_ValidPathA(curdir,NONDIR_LONG,LONGFILE,tmpstr,&passfail,"test12");
652 ok(passfail.shortlen==0,"GetShortPathNameA passed when it shouldn't have");
653 ok(passfail.shorterror==ERROR_PATH_NOT_FOUND ||
654 passfail.shorterror==ERROR_FILE_NOT_FOUND ||
655 !passfail.shorterror,
656 "GetShortPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
657 passfail.shorterror);
658 if(pGetLongPathNameA) {
659 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
660 ok(passfail.longerror==ERROR_PATH_NOT_FOUND ||
661 passfail.longerror==ERROR_FILE_NOT_FOUND,
662 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'",
663 passfail.longerror);
665 /* Next try directories ending with '\\' */
666 /* Existing Directories */
667 sprintf(tmpstr,"%s\\",SHORTDIR);
668 test_ValidPathA(curdir,"",tmpstr,tmpstr1,NULL,"test13");
669 sprintf(tmpstr,"%s\\",LONGDIR);
670 test_ValidPathA(curdir,"",tmpstr,tmpstr1,NULL,"test14");
671 /* Non-existent directories */
672 sprintf(tmpstr,"%s\\",NONDIR_SHORT);
673 test_ValidPathA(curdir,"",tmpstr,tmpstr1,&passfail,"test15");
674 sprintf(tmpstr2,"%s\\%s",curdir,tmpstr);
675 ok((passfail.shortlen==0 &&
676 (passfail.shorterror==ERROR_PATH_NOT_FOUND ||
677 passfail.shorterror==ERROR_FILE_NOT_FOUND)) ||
678 (passfail.shortlen==strlen(tmpstr2) && lstrcmpiA(tmpstr1,tmpstr2)==0),
679 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]",
680 passfail.shortlen,passfail.shorterror,tmpstr);
681 if(pGetLongPathNameA) {
682 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
683 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
684 "GetLongPathA returned %ld and not 'ERROR_FILE_NOT_FOUND'",
685 passfail.longerror);
687 sprintf(tmpstr,"%s\\",NONDIR_LONG);
688 test_ValidPathA(curdir,"",tmpstr,tmpstr1,&passfail,"test16");
689 ok(passfail.shortlen==0,"GetShortPathNameA passed when it shouldn't have");
690 ok(passfail.shorterror==ERROR_PATH_NOT_FOUND ||
691 passfail.shorterror==ERROR_FILE_NOT_FOUND ||
692 !passfail.shorterror,
693 "GetShortPathA returned %ld and not 'ERROR_FILE_NOT_FOUND'",
694 passfail.shorterror);
695 if(pGetLongPathNameA) {
696 ok(passfail.longlen==0,"GetLongPathNameA passed when it shouldn't have");
697 ok(passfail.longerror==ERROR_FILE_NOT_FOUND,
698 "GetLongPathA returned %ld and not 'ERROR_FILE_NOT_FOUND'",
699 passfail.longerror);
701 /* Test GetFullPathNameA with drive letters */
702 if( curDrive != NOT_A_VALID_DRIVE) {
703 sprintf(tmpstr,"%c:",curdir[0]);
704 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr2,&strptr),
705 "GetFullPathNameA(%c:) failed", curdir[0]);
706 GetCurrentDirectoryA(MAX_PATH,tmpstr);
707 sprintf(tmpstr1,"%s\\",tmpstr);
708 ok(lstrcmpiA(tmpstr,tmpstr2)==0 || lstrcmpiA(tmpstr1,tmpstr2)==0,
709 "GetFullPathNameA(%c:) returned '%s' instead of '%s' or '%s'",
710 curdir[0],tmpstr2,tmpstr,tmpstr1);
712 sprintf(tmpstr,"%c:\\%s\\%s",curDrive,SHORTDIR,SHORTFILE);
713 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr1,&strptr),"GetFullPathNameA failed");
714 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
715 "GetFullPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
716 ok(lstrcmpiA(SHORTFILE,strptr)==0,
717 "GetFullPathNameA returned part '%s' instead of '%s'",strptr,SHORTFILE);
719 /* Without a leading slash, insert the current directory if on the current drive */
720 sprintf(tmpstr,"%c:%s\\%s",curdir[0],SHORTDIR,SHORTFILE);
721 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr1,&strptr),"GetFullPathNameA failed");
722 sprintf(tmpstr,"%s\\%s\\%s",curdir,SHORTDIR,SHORTFILE);
723 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
724 "GetFullPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
725 ok(lstrcmpiA(SHORTFILE,strptr)==0,
726 "GetFullPathNameA returned part '%s' instead of '%s'",strptr,SHORTFILE);
727 /* Otherwise insert the missing leading slash */
728 if( otherDrive != NOT_A_VALID_DRIVE) {
729 sprintf(tmpstr,"%c:%s\\%s",otherDrive,SHORTDIR,SHORTFILE);
730 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr1,&strptr),"GetFullPathNameA failed for %s", tmpstr);
731 sprintf(tmpstr,"%c:\\%s\\%s",otherDrive,SHORTDIR,SHORTFILE);
732 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
733 "GetFullPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
734 ok(lstrcmpiA(SHORTFILE,strptr)==0,
735 "GetFullPathNameA returned part '%s' instead of '%s'",strptr,SHORTFILE);
737 /* Xilinx tools like to mix Unix and DOS formats, which Windows handles fine.
738 So test for them. */
739 if( curDrive != NOT_A_VALID_DRIVE) {
740 sprintf(tmpstr,"%c:/%s\\%s",curDrive,SHORTDIR,SHORTFILE);
741 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr1,&strptr),"GetFullPathNameA failed");
742 sprintf(tmpstr,"%c:\\%s\\%s",curDrive,SHORTDIR,SHORTFILE);
743 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
744 "GetFullPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
745 ok(lstrcmpiA(SHORTFILE,strptr)==0,
746 "GetFullPathNameA returned part '%s' instead of '%s'",strptr,SHORTFILE);
748 /**/
749 sprintf(tmpstr,"%c:%s/%s",curdir[0],SHORTDIR,SHORTFILE);
750 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr1,&strptr),"GetFullPathNameA failed");
751 sprintf(tmpstr,"%s\\%s\\%s",curdir,SHORTDIR,SHORTFILE);
752 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
753 "GetFullPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
754 ok(lstrcmpiA(SHORTFILE,strptr)==0,
755 "GetFullPathNameA returned part '%s' instead of '%s'",strptr,SHORTFILE);
756 /* Windows will insert a drive letter in front of an absolute UNIX path, but
757 Wine probably shouldn't. */
758 sprintf(tmpstr,"/%s/%s",SHORTDIR,SHORTFILE);
759 ok(GetFullPathNameA(tmpstr,MAX_PATH,tmpstr1,&strptr),"GetFullPathNameA failed");
760 todo_wine {
761 if( curDrive != NOT_A_VALID_DRIVE) {
762 sprintf(tmpstr,"C:\\%s\\%s",SHORTDIR,SHORTFILE);
763 ok(lstrcmpiA(tmpstr,tmpstr1)==0,
764 "GetFullPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
767 /* This passes in Wine because it still contains the pointer from the previous test */
768 ok(lstrcmpiA(SHORTFILE,strptr)==0,
769 "GetFullPathNameA returned part '%s' instead of '%s'",strptr,SHORTFILE);
771 /* Now try some relative paths */
772 ok(GetShortPathNameA(LONGDIR,tmpstr,MAX_PATH),"GetShortPathNameA failed");
773 test_SplitShortPathA(tmpstr,dir,eight,three);
774 if(pGetLongPathNameA) {
775 ok(pGetLongPathNameA(tmpstr,tmpstr1,MAX_PATH),"GetShortPathNameA failed");
776 todo_wine {
777 ok(lstrcmpiA(tmpstr1,LONGDIR)==0,
778 "GetLongPathNameA returned '%s' instead of '%s'",tmpstr1,LONGDIR);
781 sprintf(tmpstr,".\\%s",LONGDIR);
782 ok(GetShortPathNameA(tmpstr,tmpstr1,MAX_PATH),"GetShortPathNameA failed");
783 test_SplitShortPathA(tmpstr1,dir,eight,three);
784 ok(lstrcmpiA(dir,".")==0 || dir[0]=='\0',
785 "GetShortPathNameA did not keep relative directory [%s]",tmpstr1);
786 if(pGetLongPathNameA) {
787 ok(pGetLongPathNameA(tmpstr1,tmpstr1,MAX_PATH),"GetShortPathNameA failed");
788 todo_wine {
789 ok(lstrcmpiA(tmpstr1,tmpstr)==0,
790 "GetLongPathNameA returned '%s' instead of '%s'",tmpstr1,tmpstr);
793 /* Check out Get*PathNameA on some funny characters */
794 for(i=0;i<lstrlenA(funny_chars);i++) {
795 INT valid,todo;
796 valid=(is_char_ok[i]=='0') ? 0 : 1;
797 todo=(wine_todo[i]=='0') ? 0 : 1;
798 sprintf(tmpstr1,"check%d-1",i);
799 sprintf(tmpstr,"file%c000.ext",funny_chars[i]);
800 test_FunnyChars(curdir,tmpstr,valid,todo,tmpstr1);
801 sprintf(tmpstr1,"check%d-2",i);
802 sprintf(tmpstr,"file000.e%ct",funny_chars[i]);
803 test_FunnyChars(curdir,tmpstr,valid,todo,tmpstr1);
804 sprintf(tmpstr1,"check%d-3",i);
805 sprintf(tmpstr,"%cfile000.ext",funny_chars[i]);
806 test_FunnyChars(curdir,tmpstr,valid,todo,tmpstr1);
807 sprintf(tmpstr1,"check%d-4",i);
808 sprintf(tmpstr,"file000%c.ext",funny_chars[i]);
809 test_FunnyChars(curdir,tmpstr,valid,todo,tmpstr1);
810 sprintf(tmpstr1,"check%d-5",i);
811 sprintf(tmpstr,"Long %c File",funny_chars[i]);
812 test_FunnyChars(curdir,tmpstr,valid,0,tmpstr1);
813 sprintf(tmpstr1,"check%d-6",i);
814 sprintf(tmpstr,"%c Long File",funny_chars[i]);
815 test_FunnyChars(curdir,tmpstr,valid,0,tmpstr1);
816 sprintf(tmpstr1,"check%d-7",i);
817 sprintf(tmpstr,"Long File %c",funny_chars[i]);
818 test_FunnyChars(curdir,tmpstr,valid,0,tmpstr1);
822 static void test_GetTempPathA(char* tmp_dir)
824 DWORD len, len_with_null;
825 char buf[MAX_PATH];
827 len_with_null = strlen(tmp_dir) + 1;
829 lstrcpyA(buf, "foo");
830 len = GetTempPathA(MAX_PATH, buf);
831 ok(len <= MAX_PATH, "should fit into MAX_PATH");
832 ok(lstrcmpiA(buf, tmp_dir) == 0, "expected [%s], got [%s]",tmp_dir,buf);
833 ok(len == strlen(buf), "returned length should be equal to the length of string");
835 /* Some versions of Windows touch the buffer, some don't so we don't
836 * test that. Also, NT sometimes exagerates the required buffer size
837 * so we cannot test for an exact match. Finally, the
838 * 'len_with_null - 1' case is so buggy on Windows it's not testable.
839 * For instance in some cases Win98 returns len_with_null - 1 instead
840 * of len_with_null.
842 len = GetTempPathA(1, buf);
843 ok(len >= len_with_null, "Expected >= %lu, got %lu", len_with_null, len);
845 len = GetTempPathA(0, NULL);
846 ok(len >= len_with_null, "Expected >= %lu, got %lu", len_with_null, len);
848 /* The call above gave us the buffer size that Windows thinks is needed
849 * so the next call should work
851 lstrcpyA(buf, "foo");
852 len = GetTempPathA(len, buf);
853 ok(lstrcmpiA(buf, tmp_dir) == 0, "expected [%s], got [%s]",tmp_dir,buf);
854 ok(len == strlen(buf), "returned length should be equal to the length of string");
857 static void test_GetTempPathW(char* tmp_dir)
859 DWORD len, len_with_null;
860 WCHAR buf[MAX_PATH];
861 WCHAR tmp_dirW[MAX_PATH];
862 static const WCHAR fooW[] = {'f','o','o',0};
864 MultiByteToWideChar(CP_ACP,0,tmp_dir,-1,tmp_dirW,sizeof(tmp_dirW)/sizeof(*tmp_dirW));
865 len_with_null = lstrlenW(tmp_dirW) + 1;
867 /* This one is different from ANSI version: ANSI version doesn't
868 * touch the buffer, unicode version usually truncates the buffer
869 * to zero size. NT still exagerates the required buffer size
870 * sometimes so we cannot test for an exact match. Finally, the
871 * 'len_with_null - 1' case is so buggy on Windows it's not testable.
872 * For instance on NT4 it will sometimes return a path without the
873 * trailing '\\' and sometimes return an error.
876 lstrcpyW(buf, fooW);
877 len = GetTempPathW(MAX_PATH, buf);
878 if (len==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
879 return;
880 ok(lstrcmpiW(buf, tmp_dirW) == 0, "GetTempPathW returned an incorrect temporary path");
881 ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
883 lstrcpyW(buf, fooW);
884 len = GetTempPathW(1, buf);
885 ok(buf[0] == 0, "unicode version should truncate the buffer to zero size");
886 ok(len >= len_with_null, "Expected >= %lu, got %lu", len_with_null, len);
888 len = GetTempPathW(0, NULL);
889 ok(len >= len_with_null, "Expected >= %lu, got %lu", len_with_null, len);
891 lstrcpyW(buf, fooW);
892 len = GetTempPathW(len, buf);
893 ok(lstrcmpiW(buf, tmp_dirW) == 0, "GetTempPathW returned an incorrect temporary path");
894 ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
897 static void test_GetTempPath(void)
899 char save_TMP[MAX_PATH];
900 char windir[MAX_PATH];
901 char buf[MAX_PATH];
903 GetEnvironmentVariableA("TMP", save_TMP, sizeof(save_TMP));
905 /* test default configuration */
906 trace("TMP=%s\n", save_TMP);
907 strcpy(buf,save_TMP);
908 if (buf[strlen(buf)-1]!='\\')
909 strcat(buf,"\\");
910 test_GetTempPathA(buf);
911 test_GetTempPathW(buf);
913 /* TMP=C:\WINDOWS */
914 GetWindowsDirectoryA(windir, sizeof(windir));
915 SetEnvironmentVariableA("TMP", windir);
916 GetEnvironmentVariableA("TMP", buf, sizeof(buf));
917 trace("TMP=%s\n", buf);
918 strcat(windir,"\\");
919 test_GetTempPathA(windir);
920 test_GetTempPathW(windir);
922 /* TMP=C:\ */
923 GetWindowsDirectoryA(windir, sizeof(windir));
924 windir[3] = 0;
925 SetEnvironmentVariableA("TMP", windir);
926 GetEnvironmentVariableA("TMP", buf, sizeof(buf));
927 trace("TMP=%s\n", buf);
928 test_GetTempPathA(windir);
929 test_GetTempPathW(windir);
931 /* TMP=C: i.e. use current working directory of the specified drive */
932 GetWindowsDirectoryA(windir, sizeof(windir));
933 SetCurrentDirectoryA(windir);
934 windir[2] = 0;
935 SetEnvironmentVariableA("TMP", windir);
936 GetEnvironmentVariableA("TMP", buf, sizeof(buf));
937 trace("TMP=%s\n", buf);
938 GetWindowsDirectoryA(windir, sizeof(windir));
939 strcat(windir,"\\");
940 test_GetTempPathA(windir);
941 test_GetTempPathW(windir);
943 SetEnvironmentVariableA("TMP", save_TMP);
946 START_TEST(path)
948 CHAR origdir[MAX_PATH],curdir[MAX_PATH], curDrive, otherDrive;
949 pGetLongPathNameA = (void*)GetProcAddress( GetModuleHandleA("kernel32.dll"),
950 "GetLongPathNameA" );
951 test_InitPathA(curdir, &curDrive, &otherDrive);
952 test_CurrentDirectoryA(origdir,curdir);
953 test_PathNameA(curdir, curDrive, otherDrive);
954 test_CleanupPathA(origdir,curdir);
955 test_GetTempPath();