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
23 #include "wine/test.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 "NonExistent File"
38 #define NONDIR_SHORT "notadir"
39 #define NONDIR_LONG "NonExistent 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
49 static const CHAR funny_chars
[]="!@#$%^&*()=+{}[],?'`";
50 static const CHAR is_char_ok
[] ="11111110111111111011";
52 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
,LPSTR
,DWORD
);
54 /* a structure to deal with wine todos somewhat cleanly */
64 /* function that tests GetFullPathNameA, GetShortPathNameA,GetLongPathNameA */
65 /* NOTE: the passfail structure is used to allow cutomizeable todo checking
66 for wine. It is not very pretty, but it sure beats duplicating this
67 function lots of times
69 static void test_ValidPathA(const CHAR
*curdir
, const CHAR
*subdir
, const CHAR
*filename
,
70 CHAR
*shortstr
, SLpassfail
*passfail
, const 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 */
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
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\n",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 \\\n",errstr
);
97 ok((len
=GetShortPathNameA(curdir
,curdirshort
,MAX_PATH
)),
98 "%s: GetShortPathNameA failed\n",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 \\\n",errstr
);
102 /* build relative and absolute paths from inputs */
103 if(lstrlenA(subdir
)) {
104 sprintf(subpath
,"%s\\%s",subdir
,filename
);
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'\n",subpath
);
114 if(HAS_TRAIL_SLASH_A(subpath
)) {
116 "%s: GetFullPathNameA should not return a filename ptr\n",errstr
);
117 ok(lstrcmpiA(fullpath
,tmpstr
)==0,
118 "%s: GetFullPathNameA returned '%s' instead of '%s'\n",
119 errstr
,tmpstr
,fullpath
);
121 ok(lstrcmpiA(strptr
,filename
)==0,
122 "%s: GetFullPathNameA returned '%s' instead of '%s'\n",
123 errstr
,strptr
,filename
);
124 ok(lstrcmpiA(fullpath
,tmpstr
)==0,
125 "%s: GetFullPathNameA returned '%s' instead of '%s'\n",
126 errstr
,tmpstr
,fullpath
);
128 /* Test GetShortPathNameA functionality */
130 len
=GetShortPathNameA(fullpathshort
,shortstr
,MAX_PATH
);
132 ok(len
, "%s: GetShortPathNameA failed\n",errstr
);
134 passfail
->shortlen
=len
;
135 passfail
->shorterror
=GetLastError();
137 /* Test GetLongPathNameA functionality
138 We test both conversion from GetFullPathNameA and from GetShortPathNameA
140 if(pGetLongPathNameA
) {
143 len
=pGetLongPathNameA(shortstr
,tmpstr
,MAX_PATH
);
146 "%s: GetLongPathNameA failed during Short->Long conversion\n", errstr
);
147 ok(lstrcmpiA(fullpathlong
,tmpstr
)==0,
148 "%s: GetLongPathNameA returned '%s' instead of '%s'\n",
149 errstr
,tmpstr
,fullpathlong
);
151 passfail
->s2llen
=len
;
152 passfail
->s2lerror
=GetLastError();
156 len
=pGetLongPathNameA(fullpath
,tmpstr
,MAX_PATH
);
158 ok(len
, "%s: GetLongPathNameA failed\n",errstr
);
159 if(HAS_TRAIL_SLASH_A(fullpath
)) {
160 ok(lstrcmpiA(fullpathlong
,tmpstr
)==0,
161 "%s: GetLongPathNameA returned '%s' instead of '%s'\n",
162 errstr
,tmpstr
,fullpathlong
);
164 ok(lstrcmpiA(fullpathlong
,tmpstr
)==0,
165 "%s: GetLongPathNameA returned '%s' instead of '%s'\n",
166 errstr
,tmpstr
,fullpathlong
);
169 passfail
->longlen
=len
;
170 passfail
->longerror
=GetLastError();
175 /* split path into leading directory, and 8.3 filename */
176 static void test_SplitShortPathA(CHAR
*path
,CHAR
*dir
,CHAR
*eight
,CHAR
*three
) {
181 ext
=len
; fil
=len
; done
=0; error
=0;
182 /* walk backwards over path looking for '.' or '\\' separators */
183 for(i
=len
-1;(i
>=0) && (!done
);i
--) {
185 if(ext
!=len
) error
=1; else ext
=i
;
186 else if(path
[i
]=='\\') {
195 /* Check that we didn't find a trailing '\\' or multiple '.' */
196 ok(!error
,"Illegal file found in 8.3 path '%s'\n",path
);
197 /* Separate dir, root, and extension */
198 if(ext
!=len
) lstrcpyA(three
,path
+ext
+1); else lstrcpyA(three
,"");
200 lstrcpynA(eight
,path
+fil
+1,ext
-fil
);
201 lstrcpynA(dir
,path
,fil
+1);
203 lstrcpynA(eight
,path
,ext
+1);
206 /* Validate that root and extension really are 8.3 */
207 ok(lstrlenA(eight
)<=8 && lstrlenA(three
)<=3,
208 "GetShortPathNAmeA did not return an 8.3 path\n");
211 /* Check that GetShortPathNameA returns a valid 8.3 path */
212 static void test_LongtoShortA(CHAR
*teststr
,const CHAR
*goodstr
,
213 const CHAR
*ext
,const CHAR
*errstr
) {
214 CHAR dir
[MAX_PATH
],eight
[MAX_PATH
],three
[MAX_PATH
];
216 test_SplitShortPathA(teststr
,dir
,eight
,three
);
217 ok(lstrcmpiA(dir
,goodstr
)==0,
218 "GetShortPathNameA returned '%s' instead of '%s'\n",dir
,goodstr
);
219 ok(lstrcmpiA(three
,ext
)==0,
220 "GetShortPathNameA returned '%s' with incorrect extension\n",three
);
223 /* Test that Get(Short|Long|Full)PathNameA work correctly with interesting
224 characters in the filename.
225 'valid' indicates whether this would be an allowed filename
226 'todo' indicates that wine doesn't get this right yet.
227 NOTE: We always call this routine with a nonexistent filename, so
228 Get(Short|Long)PathNameA should never pass, but GetFullPathNameA
231 static void test_FunnyChars(CHAR
*curdir
,CHAR
*curdir_short
,CHAR
*filename
, INT valid
,CHAR
*errstr
)
233 CHAR tmpstr
[MAX_PATH
],tmpstr1
[MAX_PATH
];
236 test_ValidPathA(curdir
,"",filename
,tmpstr
,&passfail
,errstr
);
238 sprintf(tmpstr1
,"%s\\%s",curdir_short
,filename
);
239 ok((passfail
.shortlen
==0 &&
240 (passfail
.shorterror
==ERROR_FILE_NOT_FOUND
|| passfail
.shorterror
==ERROR_PATH_NOT_FOUND
|| !passfail
.shorterror
)) ||
241 (passfail
.shortlen
==strlen(tmpstr1
) && lstrcmpiA(tmpstr
,tmpstr1
)==0),
242 "%s: GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]\n",
243 errstr
,passfail
.shortlen
,passfail
.shorterror
,tmpstr
);
245 ok(passfail
.shortlen
==0 &&
246 (passfail
.shorterror
==ERROR_INVALID_NAME
|| passfail
.shorterror
==ERROR_FILE_NOT_FOUND
|| !passfail
.shorterror
),
247 "%s: GetShortPathA should have failed len=%ld, error=%ld\n",
248 errstr
,passfail
.shortlen
,passfail
.shorterror
);
250 if(pGetLongPathNameA
) {
251 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
253 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
254 "%s: GetLongPathA returned %ld and not %d\n",
255 errstr
,passfail
.longerror
,ERROR_FILE_NOT_FOUND
);
257 ok(passfail
.longerror
==ERROR_INVALID_NAME
||
258 passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
259 "%s: GetLongPathA returned %ld and not %d or %d'\n",
260 errstr
, passfail
.longerror
,ERROR_INVALID_NAME
,ERROR_FILE_NOT_FOUND
);
265 /* Routine to test that SetCurrentDirectory behaves as expected. */
266 static void test_setdir(CHAR
*olddir
,CHAR
*newdir
,
267 CHAR
*cmprstr
, INT pass
, const CHAR
*errstr
)
269 CHAR tmppath
[MAX_PATH
], *dirptr
;
270 DWORD val
,len
,chklen
;
272 val
=SetCurrentDirectoryA(newdir
);
273 len
=GetCurrentDirectoryA(MAX_PATH
,tmppath
);
274 /* if 'pass' then the SetDirectoryA was supposed to pass */
276 dirptr
=(cmprstr
==NULL
) ? newdir
: cmprstr
;
277 chklen
=lstrlenA(dirptr
);
278 ok(val
,"%s: SetCurrentDirectoryA failed\n",errstr
);
280 "%s: SetCurrentDirectory did not change the directory, though it passed\n",
282 ok(lstrcmpiA(dirptr
,tmppath
)==0,
283 "%s: SetCurrentDirectory did not change the directory, though it passed\n",
285 ok(SetCurrentDirectoryA(olddir
),
286 "%s: Couldn't set directory to it's original value\n",errstr
);
288 /* else thest that it fails correctly */
289 chklen
=lstrlenA(olddir
);
291 "%s: SetCurrentDirectoryA passed when it should have failed\n",errstr
);
293 "%s: SetCurrentDirectory changed the directory, though it failed\n",
295 ok(lstrcmpiA(olddir
,tmppath
)==0,
296 "%s: SetCurrentDirectory changed the directory, though it failed\n",
300 static void test_InitPathA(CHAR
*newdir
, CHAR
*curDrive
, CHAR
*otherDrive
)
302 CHAR tmppath
[MAX_PATH
], /*path to TEMP */
305 DWORD len
,len1
,drives
;
310 *curDrive
= *otherDrive
= NOT_A_VALID_DRIVE
;
312 /* Get the current drive letter */
313 if( GetCurrentDirectoryA( MAX_PATH
, tmpstr
))
314 *curDrive
= tmpstr
[0];
316 trace( "Unable to discover current drive, some tests will not be conducted.\n");
318 /* Test GetTempPathA */
319 len
=GetTempPathA(MAX_PATH
,tmppath
);
320 ok(len
!=0 && len
< MAX_PATH
,"GetTempPathA failed\n");
321 ok(HAS_TRAIL_SLASH_A(tmppath
),
322 "GetTempPathA returned a path that did not end in '\\'\n");
323 lstrcpyA(tmpstr
,"aaaaaaaa");
324 len1
=GetTempPathA(len
,tmpstr
);
326 "GetTempPathA should return string length %ld instead of %ld\n",len
+1,len1
);
328 /* Test GetTmpFileNameA
329 The only test we do here is whether GetTempFileNameA passes or not.
330 We do not thoroughly test this function yet (specifically, whether
331 it behaves correctly when 'unique' is non zero)
333 ok((id
=GetTempFileNameA(tmppath
,"path",0,newdir
)),"GetTempFileNameA failed\n");
334 sprintf(tmpstr
,"pat%.4x.tmp",id
& 0xffff);
335 sprintf(tmpstr1
,"pat%x.tmp",id
& 0xffff);
336 ok(lstrcmpiA(newdir
+lstrlenA(tmppath
),tmpstr
)==0 ||
337 lstrcmpiA(newdir
+lstrlenA(tmppath
),tmpstr1
)==0,
338 "GetTempPath returned '%s' which doesn't match '%s' or '%s'. id=%x\n",
339 newdir
,tmpstr
,tmpstr1
,id
);
341 /* Find first valid drive letter that is neither newdir[0] nor curDrive */
342 drives
= GetLogicalDrives() & ~(1<<(newdir
[0]-'A'));
343 if( *curDrive
!= NOT_A_VALID_DRIVE
)
344 drives
&= ~(1<<(*curDrive
-'A'));
346 for( *otherDrive
='A'; (drives
& 1) == 0; drives
>>=1, (*otherDrive
)++);
348 trace( "Could not find alternative drive, some tests will not be conducted.\n");
350 /* Do some CreateDirectoryA tests */
351 /* It would be nice to do test the SECURITY_ATTRIBUTES, but I don't
352 really understand how they work.
353 More formal tests should be done along with CreateFile tests
355 ok(CreateDirectoryA(newdir
,NULL
)==0,
356 "CreateDirectoryA succeeded even though a file of the same name exists\n");
357 ok(DeleteFileA(newdir
),"Couldn't delete the temporary file we just created\n");
358 ok(CreateDirectoryA(newdir
,NULL
),"CreateDirectoryA failed\n");
359 /* Create some files to test other functions. Note, we will test CreateFileA
362 sprintf(tmpstr
,"%s\\%s",newdir
,SHORTDIR
);
363 ok(CreateDirectoryA(tmpstr
,NULL
),"CreateDirectoryA failed\n");
364 sprintf(tmpstr
,"%s\\%s",newdir
,LONGDIR
);
365 ok(CreateDirectoryA(tmpstr
,NULL
),"CreateDirectoryA failed\n");
366 bRes
= CreateDirectoryA("c:",NULL
);
367 ok(!bRes
&& (GetLastError() == ERROR_ACCESS_DENIED
||
368 GetLastError() == ERROR_ALREADY_EXISTS
),
369 "CreateDirectoryA(\"c:\" should have failed (%ld)\n", GetLastError());
370 bRes
= CreateDirectoryA("c:\\",NULL
);
371 ok(!bRes
&& (GetLastError() == ERROR_ACCESS_DENIED
||
372 GetLastError() == ERROR_ALREADY_EXISTS
),
373 "CreateDirectoryA(\"c:\\\" should have failed (%ld)\n", GetLastError());
374 sprintf(tmpstr
,"%s\\%s\\%s",newdir
,SHORTDIR
,SHORTFILE
);
375 hndl
=CreateFileA(tmpstr
,GENERIC_WRITE
,0,NULL
,
376 CREATE_NEW
,FILE_ATTRIBUTE_NORMAL
,NULL
);
377 ok(hndl
!=INVALID_HANDLE_VALUE
,"CreateFileA failed\n");
378 ok(CloseHandle(hndl
),"CloseHandle failed\n");
379 sprintf(tmpstr
,"%s\\%s\\%s",newdir
,SHORTDIR
,LONGFILE
);
380 hndl
=CreateFileA(tmpstr
,GENERIC_WRITE
,0,NULL
,
381 CREATE_NEW
,FILE_ATTRIBUTE_NORMAL
,NULL
);
382 ok(hndl
!=INVALID_HANDLE_VALUE
,"CreateFileA failed\n");
383 ok(CloseHandle(hndl
),"CloseHandle failed\n");
384 sprintf(tmpstr
,"%s\\%s\\%s",newdir
,LONGDIR
,SHORTFILE
);
385 hndl
=CreateFileA(tmpstr
,GENERIC_WRITE
,0,NULL
,
386 CREATE_NEW
,FILE_ATTRIBUTE_NORMAL
,NULL
);
387 ok(hndl
!=INVALID_HANDLE_VALUE
,"CreateFileA failed\n");
388 ok(CloseHandle(hndl
),"CloseHandle failed\n");
389 sprintf(tmpstr
,"%s\\%s\\%s",newdir
,LONGDIR
,LONGFILE
);
390 hndl
=CreateFileA(tmpstr
,GENERIC_WRITE
,0,NULL
,
391 CREATE_NEW
,FILE_ATTRIBUTE_NORMAL
,NULL
);
392 ok(hndl
!=INVALID_HANDLE_VALUE
,"CreateFileA failed\n");
393 ok(CloseHandle(hndl
),"CloseHandle failed\n");
396 /* Test GetCurrentDirectory & SetCurrentDirectory */
397 static void test_CurrentDirectoryA(CHAR
*origdir
, CHAR
*newdir
)
399 CHAR tmpstr
[MAX_PATH
],tmpstr1
[MAX_PATH
];
401 /* Save the original directory, so that we can return to it at the end
404 len
=GetCurrentDirectoryA(MAX_PATH
,origdir
);
405 ok(len
!=0 && len
< MAX_PATH
,"GetCurrentDirectoryA failed\n");
406 /* Make sure that CetCurrentDirectoryA doesn't overwrite the buffer when the
407 buffer size is too small to hold the current directory
409 lstrcpyA(tmpstr
,"aaaaaaa");
410 len1
=GetCurrentDirectoryA(len
,tmpstr
);
411 ok(len1
==len
+1, "GetCurrentDirectoryA returned %ld instead of %ld\n",len1
,len
+1);
412 ok(lstrcmpiA(tmpstr
,"aaaaaaa")==0,
413 "GetCurrentDirectoryA should not have modified the buffer\n");
414 /* SetCurrentDirectoryA shouldn't care whether the string has a
417 sprintf(tmpstr
,"%s\\",newdir
);
418 test_setdir(origdir
,tmpstr
,newdir
,1,"check 1");
419 test_setdir(origdir
,newdir
,NULL
,1,"check 2");
420 /* Set the directory to the working area. We just tested that this works,
421 so why check it again.
423 SetCurrentDirectoryA(newdir
);
424 /* Check that SetCurrentDirectory fails when a nonexistent dir is specified */
425 sprintf(tmpstr
,"%s\\%s\\%s",newdir
,SHORTDIR
,NONDIR_SHORT
);
426 test_setdir(newdir
,tmpstr
,NULL
,0,"check 3");
427 /* Check that SetCurrentDirectory fails for a nonexistent lond directory */
428 sprintf(tmpstr
,"%s\\%s\\%s",newdir
,SHORTDIR
,NONDIR_LONG
);
429 test_setdir(newdir
,tmpstr
,NULL
,0,"check 4");
430 /* Check that SetCurrentDirectory passes with a long directory */
431 sprintf(tmpstr
,"%s\\%s",newdir
,LONGDIR
);
432 test_setdir(newdir
,tmpstr
,NULL
,1,"check 5");
433 /* Check that SetCurrentDirectory passes with a short relative directory */
434 sprintf(tmpstr
,"%s",SHORTDIR
);
435 sprintf(tmpstr1
,"%s\\%s",newdir
,SHORTDIR
);
436 test_setdir(newdir
,tmpstr
,tmpstr1
,1,"check 6");
437 /* starting with a '.' */
438 sprintf(tmpstr
,".\\%s",SHORTDIR
);
439 test_setdir(newdir
,tmpstr
,tmpstr1
,1,"check 7");
440 /* Check that SetCurrentDirectory passes with a short relative directory */
441 sprintf(tmpstr
,"%s",LONGDIR
);
442 sprintf(tmpstr1
,"%s\\%s",newdir
,LONGDIR
);
443 test_setdir(newdir
,tmpstr
,tmpstr1
,1,"check 8");
444 /* starting with a '.' */
445 sprintf(tmpstr
,".\\%s",LONGDIR
);
446 test_setdir(newdir
,tmpstr
,tmpstr1
,1,"check 9");
449 /* Cleanup the mess we made while executing these tests */
450 static void test_CleanupPathA(CHAR
*origdir
, CHAR
*curdir
)
452 CHAR tmpstr
[MAX_PATH
];
453 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,SHORTDIR
,SHORTFILE
);
454 ok(DeleteFileA(tmpstr
),"DeleteFileA failed\n");
455 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,SHORTDIR
,LONGFILE
);
456 ok(DeleteFileA(tmpstr
),"DeleteFileA failed\n");
457 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,LONGDIR
,SHORTFILE
);
458 ok(DeleteFileA(tmpstr
),"DeleteFileA failed\n");
459 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,LONGDIR
,LONGFILE
);
460 ok(DeleteFileA(tmpstr
),"DeleteFileA failed\n");
461 sprintf(tmpstr
,"%s\\%s",curdir
,SHORTDIR
);
462 ok(RemoveDirectoryA(tmpstr
),"RemoveDirectoryA failed\n");
463 sprintf(tmpstr
,"%s\\%s",curdir
,LONGDIR
);
464 ok(RemoveDirectoryA(tmpstr
),"RemoveDirectoryA failed\n");
465 ok(SetCurrentDirectoryA(origdir
),"SetCurrentDirectoryA failed\n");
466 ok(RemoveDirectoryA(curdir
),"RemoveDirectoryA failed\n");
469 /* This routine will test Get(Full|Short|Long)PathNameA */
470 static void test_PathNameA(CHAR
*curdir
, CHAR curDrive
, CHAR otherDrive
)
472 CHAR curdir_short
[MAX_PATH
],
473 longdir_short
[MAX_PATH
];
474 CHAR tmpstr
[MAX_PATH
],tmpstr1
[MAX_PATH
],tmpstr2
[MAX_PATH
];
475 LPSTR strptr
; /*ptr to the filename portion of the path */
478 CHAR dir
[MAX_PATH
],eight
[MAX_PATH
],three
[MAX_PATH
];
481 /* Get the short form of the current directory */
482 ok((len
=GetShortPathNameA(curdir
,curdir_short
,MAX_PATH
)),
483 "GetShortPathNameA failed\n");
484 ok(!HAS_TRAIL_SLASH_A(curdir_short
),
485 "GetShortPathNameA should not have a trailing \\\n");
486 /* Get the short form of the absolute-path to LONGDIR */
487 sprintf(tmpstr
,"%s\\%s",curdir_short
,LONGDIR
);
488 ok((len
=GetShortPathNameA(tmpstr
,longdir_short
,MAX_PATH
)),
489 "GetShortPathNameA failed\n");
490 ok(lstrcmpiA(longdir_short
+(len
-1),"\\")!=0,
491 "GetShortPathNameA should not have a trailing \\\n");
493 if (pGetLongPathNameA
) {
495 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,LONGDIR
,LONGFILE
);
496 rc1
=(*pGetLongPathNameA
)(tmpstr
,NULL
,0);
497 rc2
=(*pGetLongPathNameA
)(curdir
,NULL
,0);
498 ok((rc1
-strlen(tmpstr
))==(rc2
-strlen(curdir
)),
499 "GetLongPathNameA: wrong return code, %ld instead of %d\n",
500 rc1
, strlen(tmpstr
)+1);
502 sprintf(dir
,"%c:",curDrive
);
503 rc1
=(*pGetLongPathNameA
)(dir
,tmpstr
,sizeof(tmpstr
));
504 ok(strcmp(dir
,tmpstr
)==0,
505 "GetLongPathNameA: returned '%s' instead of '%s' (rc=%ld)\n",
509 /* Check the cases where both file and directory exist first */
510 /* Start with a 8.3 directory, 8.3 filename */
511 test_ValidPathA(curdir
,SHORTDIR
,SHORTFILE
,tmpstr
,NULL
,"test1");
512 sprintf(tmpstr1
,"%s\\%s\\%s",curdir_short
,SHORTDIR
,SHORTFILE
);
513 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
514 "GetShortPathNameA returned '%s' instead of '%s'\n",tmpstr
,tmpstr1
);
515 /* Now try a 8.3 directory, long file name */
516 test_ValidPathA(curdir
,SHORTDIR
,LONGFILE
,tmpstr
,NULL
,"test2");
517 sprintf(tmpstr1
,"%s\\%s",curdir_short
,SHORTDIR
);
518 test_LongtoShortA(tmpstr
,tmpstr1
,"PAT","test2");
519 /* Next is a long directory, 8.3 file */
520 test_ValidPathA(curdir
,LONGDIR
,SHORTFILE
,tmpstr
,NULL
,"test3");
521 sprintf(tmpstr1
,"%s\\%s",longdir_short
,SHORTFILE
);
522 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
523 "GetShortPathNameA returned '%s' instead of '%s'\n",tmpstr
,tmpstr1
);
524 /*Lastly a long directory, long file */
525 test_ValidPathA(curdir
,LONGDIR
,LONGFILE
,tmpstr
,NULL
,"test4");
526 test_LongtoShortA(tmpstr
,longdir_short
,"PAT","test4");
528 /* Now check all of the invalid file w/ valid directory combinations */
529 /* Start with a 8.3 directory, 8.3 filename */
530 test_ValidPathA(curdir
,SHORTDIR
,NONFILE_SHORT
,tmpstr
,&passfail
,"test5");
531 sprintf(tmpstr1
,"%s\\%s\\%s",curdir_short
,SHORTDIR
,NONFILE_SHORT
);
532 ok((passfail
.shortlen
==0 &&
533 (passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
534 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
)) ||
535 (passfail
.shortlen
==strlen(tmpstr1
) && lstrcmpiA(tmpstr
,tmpstr1
)==0),
536 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]\n",
537 passfail
.shortlen
,passfail
.shorterror
,tmpstr
);
538 if(pGetLongPathNameA
) {
539 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
540 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
541 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'\n");
543 /* Now try a 8.3 directory, long file name */
544 test_ValidPathA(curdir
,SHORTDIR
,NONFILE_LONG
,tmpstr
,&passfail
,"test6");
545 ok(passfail
.shortlen
==0,"GetShortPathNameA passed when it shouldn't have\n");
546 ok(passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
547 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
||
548 !passfail
.shorterror
,
549 "GetShortPathA should have returned 'ERROR_FILE_NOT_FOUND'\n");
550 if(pGetLongPathNameA
) {
551 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
552 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
553 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'\n");
555 /* Next is a long directory, 8.3 file */
556 test_ValidPathA(curdir
,LONGDIR
,NONFILE_SHORT
,tmpstr
,&passfail
,"test7");
557 sprintf(tmpstr2
,"%s\\%s",curdir_short
,LONGDIR
);
558 GetShortPathNameA(tmpstr2
,tmpstr1
,MAX_PATH
);
559 strcat(tmpstr1
,"\\" NONFILE_SHORT
);
560 ok((passfail
.shortlen
==0 &&
561 (passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
562 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
)) ||
563 (passfail
.shortlen
==strlen(tmpstr1
) && lstrcmpiA(tmpstr
,tmpstr1
)==0),
564 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]\n",
565 passfail
.shortlen
,passfail
.shorterror
,tmpstr
);
566 if(pGetLongPathNameA
) {
567 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
568 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
569 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'\n");
571 /*Lastly a long directory, long file */
572 test_ValidPathA(curdir
,LONGDIR
,NONFILE_LONG
,tmpstr
,&passfail
,"test8");
573 ok(passfail
.shortlen
==0,"GetShortPathNameA passed when it shouldn't have\n");
574 ok(passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
575 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
||
576 !passfail
.shorterror
,
577 "GetShortPathA should have returned 'ERROR_FILE_NOT_FOUND'\n");
578 if(pGetLongPathNameA
) {
579 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
580 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
581 "GetlongPathA should have returned 'ERROR_FILE_NOT_FOUND'\n");
583 /* Now try again with directories that don't exist */
584 /* 8.3 directory, 8.3 filename */
585 test_ValidPathA(curdir
,NONDIR_SHORT
,SHORTFILE
,tmpstr
,&passfail
,"test9");
586 sprintf(tmpstr1
,"%s\\%s\\%s",curdir_short
,NONDIR_SHORT
,SHORTFILE
);
587 ok((passfail
.shortlen
==0 &&
588 (passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
589 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
)) ||
590 (passfail
.shortlen
==strlen(tmpstr1
) && lstrcmpiA(tmpstr
,tmpstr1
)==0),
591 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]\n",
592 passfail
.shortlen
,passfail
.shorterror
,tmpstr
);
593 if(pGetLongPathNameA
) {
594 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
595 ok(passfail
.longerror
==ERROR_PATH_NOT_FOUND
||
596 passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
597 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
600 /* Now try a 8.3 directory, long file name */
601 test_ValidPathA(curdir
,NONDIR_SHORT
,LONGFILE
,tmpstr
,&passfail
,"test10");
602 ok(passfail
.shortlen
==0,"GetShortPathNameA passed when it shouldn't have\n");
603 ok(passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
604 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
||
605 !passfail
.shorterror
,
606 "GetShortPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
607 passfail
.shorterror
);
608 if(pGetLongPathNameA
) {
609 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
610 ok(passfail
.longerror
==ERROR_PATH_NOT_FOUND
||
611 passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
612 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
615 /* Next is a long directory, 8.3 file */
616 test_ValidPathA(curdir
,NONDIR_LONG
,SHORTFILE
,tmpstr
,&passfail
,"test11");
617 ok(passfail
.shortlen
==0,"GetShortPathNameA passed when it shouldn't have\n");
618 ok(passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
619 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
||
620 !passfail
.shorterror
,
621 "GetShortPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
622 passfail
.shorterror
);
623 if(pGetLongPathNameA
) {
624 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
625 ok(passfail
.longerror
==ERROR_PATH_NOT_FOUND
||
626 passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
627 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
630 /*Lastly a long directory, long file */
631 test_ValidPathA(curdir
,NONDIR_LONG
,LONGFILE
,tmpstr
,&passfail
,"test12");
632 ok(passfail
.shortlen
==0,"GetShortPathNameA passed when it shouldn't have\n");
633 ok(passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
634 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
||
635 !passfail
.shorterror
,
636 "GetShortPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
637 passfail
.shorterror
);
638 if(pGetLongPathNameA
) {
639 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
640 ok(passfail
.longerror
==ERROR_PATH_NOT_FOUND
||
641 passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
642 "GetLongPathA returned %ld and not 'ERROR_PATH_NOT_FOUND'\n",
645 /* Next try directories ending with '\\' */
646 /* Existing Directories */
647 sprintf(tmpstr
,"%s\\",SHORTDIR
);
648 test_ValidPathA(curdir
,"",tmpstr
,tmpstr1
,NULL
,"test13");
649 sprintf(tmpstr
,"%s\\",LONGDIR
);
650 test_ValidPathA(curdir
,"",tmpstr
,tmpstr1
,NULL
,"test14");
651 /* Nonexistent directories */
652 sprintf(tmpstr
,"%s\\",NONDIR_SHORT
);
653 test_ValidPathA(curdir
,"",tmpstr
,tmpstr1
,&passfail
,"test15");
654 sprintf(tmpstr2
,"%s\\%s",curdir_short
,tmpstr
);
655 ok((passfail
.shortlen
==0 &&
656 (passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
657 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
)) ||
658 (passfail
.shortlen
==strlen(tmpstr2
) && lstrcmpiA(tmpstr1
,tmpstr2
)==0),
659 "GetShortPathNameA error: len=%ld error=%ld tmpstr=[%s]\n",
660 passfail
.shortlen
,passfail
.shorterror
,tmpstr
);
661 if(pGetLongPathNameA
) {
662 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
663 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
664 "GetLongPathA returned %ld and not 'ERROR_FILE_NOT_FOUND'\n",
667 sprintf(tmpstr
,"%s\\",NONDIR_LONG
);
668 test_ValidPathA(curdir
,"",tmpstr
,tmpstr1
,&passfail
,"test16");
669 ok(passfail
.shortlen
==0,"GetShortPathNameA passed when it shouldn't have\n");
670 ok(passfail
.shorterror
==ERROR_PATH_NOT_FOUND
||
671 passfail
.shorterror
==ERROR_FILE_NOT_FOUND
||
672 !passfail
.shorterror
,
673 "GetShortPathA returned %ld and not 'ERROR_FILE_NOT_FOUND'\n",
674 passfail
.shorterror
);
675 if(pGetLongPathNameA
) {
676 ok(passfail
.longlen
==0,"GetLongPathNameA passed when it shouldn't have\n");
677 ok(passfail
.longerror
==ERROR_FILE_NOT_FOUND
,
678 "GetLongPathA returned %ld and not 'ERROR_FILE_NOT_FOUND'\n",
681 /* Test GetFullPathNameA with drive letters */
682 if( curDrive
!= NOT_A_VALID_DRIVE
) {
683 sprintf(tmpstr
,"%c:",curdir
[0]);
684 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr2
,&strptr
),
685 "GetFullPathNameA(%c:) failed\n", curdir
[0]);
686 GetCurrentDirectoryA(MAX_PATH
,tmpstr
);
687 sprintf(tmpstr1
,"%s\\",tmpstr
);
688 ok(lstrcmpiA(tmpstr
,tmpstr2
)==0 || lstrcmpiA(tmpstr1
,tmpstr2
)==0,
689 "GetFullPathNameA(%c:) returned '%s' instead of '%s' or '%s'\n",
690 curdir
[0],tmpstr2
,tmpstr
,tmpstr1
);
692 sprintf(tmpstr
,"%c:\\%s\\%s",curDrive
,SHORTDIR
,SHORTFILE
);
693 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr1
,&strptr
),"GetFullPathNameA failed\n");
694 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
695 "GetFullPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
696 ok(lstrcmpiA(SHORTFILE
,strptr
)==0,
697 "GetFullPathNameA returned part '%s' instead of '%s'\n",strptr
,SHORTFILE
);
699 /* Without a leading slash, insert the current directory if on the current drive */
700 sprintf(tmpstr
,"%c:%s\\%s",curdir
[0],SHORTDIR
,SHORTFILE
);
701 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr1
,&strptr
),"GetFullPathNameA failed\n");
702 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,SHORTDIR
,SHORTFILE
);
703 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
704 "GetFullPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
705 ok(lstrcmpiA(SHORTFILE
,strptr
)==0,
706 "GetFullPathNameA returned part '%s' instead of '%s'\n",strptr
,SHORTFILE
);
707 /* Otherwise insert the missing leading slash */
708 if( otherDrive
!= NOT_A_VALID_DRIVE
) {
709 sprintf(tmpstr
,"%c:%s\\%s",otherDrive
,SHORTDIR
,SHORTFILE
);
710 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr1
,&strptr
),"GetFullPathNameA failed for %s\n", tmpstr
);
711 sprintf(tmpstr
,"%c:\\%s\\%s",otherDrive
,SHORTDIR
,SHORTFILE
);
712 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
713 "GetFullPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
714 ok(lstrcmpiA(SHORTFILE
,strptr
)==0,
715 "GetFullPathNameA returned part '%s' instead of '%s'\n",strptr
,SHORTFILE
);
717 /* Xilinx tools like to mix Unix and DOS formats, which Windows handles fine.
719 if( curDrive
!= NOT_A_VALID_DRIVE
) {
720 sprintf(tmpstr
,"%c:/%s\\%s",curDrive
,SHORTDIR
,SHORTFILE
);
721 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr1
,&strptr
),"GetFullPathNameA failed\n");
722 sprintf(tmpstr
,"%c:\\%s\\%s",curDrive
,SHORTDIR
,SHORTFILE
);
723 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
724 "GetFullPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
725 ok(lstrcmpiA(SHORTFILE
,strptr
)==0,
726 "GetFullPathNameA returned part '%s' instead of '%s'\n",strptr
,SHORTFILE
);
729 sprintf(tmpstr
,"%c:%s/%s",curdir
[0],SHORTDIR
,SHORTFILE
);
730 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr1
,&strptr
),"GetFullPathNameA failed\n");
731 sprintf(tmpstr
,"%s\\%s\\%s",curdir
,SHORTDIR
,SHORTFILE
);
732 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
733 "GetFullPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
734 ok(lstrcmpiA(SHORTFILE
,strptr
)==0,
735 "GetFullPathNameA returned part '%s' instead of '%s'\n",strptr
,SHORTFILE
);
736 /* Windows will insert a drive letter in front of an absolute UNIX path */
737 sprintf(tmpstr
,"/%s/%s",SHORTDIR
,SHORTFILE
);
738 ok(GetFullPathNameA(tmpstr
,MAX_PATH
,tmpstr1
,&strptr
),"GetFullPathNameA failed\n");
739 sprintf(tmpstr
,"%c:\\%s\\%s",*tmpstr1
,SHORTDIR
,SHORTFILE
);
740 ok(lstrcmpiA(tmpstr
,tmpstr1
)==0,
741 "GetFullPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
742 /* This passes in Wine because it still contains the pointer from the previous test */
743 ok(lstrcmpiA(SHORTFILE
,strptr
)==0,
744 "GetFullPathNameA returned part '%s' instead of '%s'\n",strptr
,SHORTFILE
);
746 /* Now try some relative paths */
747 ok(GetShortPathNameA(LONGDIR
,tmpstr
,MAX_PATH
),"GetShortPathNameA failed\n");
748 test_SplitShortPathA(tmpstr
,dir
,eight
,three
);
749 if(pGetLongPathNameA
) {
750 ok(pGetLongPathNameA(tmpstr
,tmpstr1
,MAX_PATH
),"GetLongPathNameA failed\n");
751 ok(lstrcmpiA(tmpstr1
,LONGDIR
)==0,
752 "GetLongPathNameA returned '%s' instead of '%s'\n",tmpstr1
,LONGDIR
);
754 sprintf(tmpstr
,".\\%s",LONGDIR
);
755 ok(GetShortPathNameA(tmpstr
,tmpstr1
,MAX_PATH
),"GetShortPathNameA failed\n");
756 test_SplitShortPathA(tmpstr1
,dir
,eight
,three
);
757 ok(lstrcmpiA(dir
,".")==0 || dir
[0]=='\0',
758 "GetShortPathNameA did not keep relative directory [%s]\n",tmpstr1
);
759 if(pGetLongPathNameA
) {
760 ok(pGetLongPathNameA(tmpstr1
,tmpstr1
,MAX_PATH
),"GetLongPathNameA failed %s\n",
762 ok(lstrcmpiA(tmpstr1
,tmpstr
)==0,
763 "GetLongPathNameA returned '%s' instead of '%s'\n",tmpstr1
,tmpstr
);
765 /* Check out Get*PathNameA on some funny characters */
766 for(i
=0;i
<lstrlenA(funny_chars
);i
++) {
768 valid
=(is_char_ok
[i
]=='0') ? 0 : 1;
769 sprintf(tmpstr1
,"check%d-1",i
);
770 sprintf(tmpstr
,"file%c000.ext",funny_chars
[i
]);
771 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
772 sprintf(tmpstr1
,"check%d-2",i
);
773 sprintf(tmpstr
,"file000.e%ct",funny_chars
[i
]);
774 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
775 sprintf(tmpstr1
,"check%d-3",i
);
776 sprintf(tmpstr
,"%cfile000.ext",funny_chars
[i
]);
777 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
778 sprintf(tmpstr1
,"check%d-4",i
);
779 sprintf(tmpstr
,"file000%c.ext",funny_chars
[i
]);
780 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
781 sprintf(tmpstr1
,"check%d-5",i
);
782 sprintf(tmpstr
,"Long %c File",funny_chars
[i
]);
783 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
784 sprintf(tmpstr1
,"check%d-6",i
);
785 sprintf(tmpstr
,"%c Long File",funny_chars
[i
]);
786 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
787 sprintf(tmpstr1
,"check%d-7",i
);
788 sprintf(tmpstr
,"Long File %c",funny_chars
[i
]);
789 test_FunnyChars(curdir
,curdir_short
,tmpstr
,valid
,tmpstr1
);
793 static void test_GetTempPathA(char* tmp_dir
)
795 DWORD len
, len_with_null
;
798 len_with_null
= strlen(tmp_dir
) + 1;
800 lstrcpyA(buf
, "foo");
801 len
= GetTempPathA(MAX_PATH
, buf
);
802 ok(len
<= MAX_PATH
, "should fit into MAX_PATH\n");
803 ok(lstrcmpiA(buf
, tmp_dir
) == 0, "expected [%s], got [%s]\n",tmp_dir
,buf
);
804 ok(len
== strlen(buf
), "returned length should be equal to the length of string\n");
806 /* Some versions of Windows touch the buffer, some don't so we don't
807 * test that. Also, NT sometimes exagerates the required buffer size
808 * so we cannot test for an exact match. Finally, the
809 * 'len_with_null - 1' case is so buggy on Windows it's not testable.
810 * For instance in some cases Win98 returns len_with_null - 1 instead
813 len
= GetTempPathA(1, buf
);
814 ok(len
>= len_with_null
, "Expected >= %lu, got %lu\n", len_with_null
, len
);
816 len
= GetTempPathA(0, NULL
);
817 ok(len
>= len_with_null
, "Expected >= %lu, got %lu\n", len_with_null
, len
);
819 /* The call above gave us the buffer size that Windows thinks is needed
820 * so the next call should work
822 lstrcpyA(buf
, "foo");
823 len
= GetTempPathA(len
, buf
);
824 ok(lstrcmpiA(buf
, tmp_dir
) == 0, "expected [%s], got [%s]\n",tmp_dir
,buf
);
825 ok(len
== strlen(buf
), "returned length should be equal to the length of string\n");
828 static void test_GetTempPathW(char* tmp_dir
)
830 DWORD len
, len_with_null
;
832 WCHAR tmp_dirW
[MAX_PATH
];
833 static const WCHAR fooW
[] = {'f','o','o',0};
835 MultiByteToWideChar(CP_ACP
,0,tmp_dir
,-1,tmp_dirW
,sizeof(tmp_dirW
)/sizeof(*tmp_dirW
));
836 len_with_null
= lstrlenW(tmp_dirW
) + 1;
838 /* This one is different from ANSI version: ANSI version doesn't
839 * touch the buffer, unicode version usually truncates the buffer
840 * to zero size. NT still exagerates the required buffer size
841 * sometimes so we cannot test for an exact match. Finally, the
842 * 'len_with_null - 1' case is so buggy on Windows it's not testable.
843 * For instance on NT4 it will sometimes return a path without the
844 * trailing '\\' and sometimes return an error.
848 len
= GetTempPathW(MAX_PATH
, buf
);
849 if (len
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
851 ok(lstrcmpiW(buf
, tmp_dirW
) == 0, "GetTempPathW returned an incorrect temporary path\n");
852 ok(len
== lstrlenW(buf
), "returned length should be equal to the length of string\n");
855 len
= GetTempPathW(1, buf
);
856 ok(buf
[0] == 0, "unicode version should truncate the buffer to zero size\n");
857 ok(len
>= len_with_null
, "Expected >= %lu, got %lu\n", len_with_null
, len
);
859 len
= GetTempPathW(0, NULL
);
860 ok(len
>= len_with_null
, "Expected >= %lu, got %lu\n", len_with_null
, len
);
863 len
= GetTempPathW(len
, buf
);
864 ok(lstrcmpiW(buf
, tmp_dirW
) == 0, "GetTempPathW returned an incorrect temporary path\n");
865 ok(len
== lstrlenW(buf
), "returned length should be equal to the length of string\n");
868 static void test_GetTempPath(void)
870 char save_TMP
[MAX_PATH
];
871 char windir
[MAX_PATH
];
874 GetEnvironmentVariableA("TMP", save_TMP
, sizeof(save_TMP
));
876 /* test default configuration */
877 trace("TMP=%s\n", save_TMP
);
878 strcpy(buf
,save_TMP
);
879 if (buf
[strlen(buf
)-1]!='\\')
881 test_GetTempPathA(buf
);
882 test_GetTempPathW(buf
);
885 GetWindowsDirectoryA(windir
, sizeof(windir
));
886 SetEnvironmentVariableA("TMP", windir
);
887 GetEnvironmentVariableA("TMP", buf
, sizeof(buf
));
888 trace("TMP=%s\n", buf
);
890 test_GetTempPathA(windir
);
891 test_GetTempPathW(windir
);
894 GetWindowsDirectoryA(windir
, sizeof(windir
));
896 SetEnvironmentVariableA("TMP", windir
);
897 GetEnvironmentVariableA("TMP", buf
, sizeof(buf
));
898 trace("TMP=%s\n", buf
);
899 test_GetTempPathA(windir
);
900 test_GetTempPathW(windir
);
902 /* TMP=C: i.e. use current working directory of the specified drive */
903 GetWindowsDirectoryA(windir
, sizeof(windir
));
904 SetCurrentDirectoryA(windir
);
906 SetEnvironmentVariableA("TMP", windir
);
907 GetEnvironmentVariableA("TMP", buf
, sizeof(buf
));
908 trace("TMP=%s\n", buf
);
909 GetWindowsDirectoryA(windir
, sizeof(windir
));
911 test_GetTempPathA(windir
);
912 test_GetTempPathW(windir
);
914 SetEnvironmentVariableA("TMP", save_TMP
);
919 CHAR origdir
[MAX_PATH
],curdir
[MAX_PATH
], curDrive
, otherDrive
;
920 pGetLongPathNameA
= (void*)GetProcAddress( GetModuleHandleA("kernel32.dll"),
921 "GetLongPathNameA" );
922 test_InitPathA(curdir
, &curDrive
, &otherDrive
);
923 test_CurrentDirectoryA(origdir
,curdir
);
924 test_PathNameA(curdir
, curDrive
, otherDrive
);
925 test_CleanupPathA(origdir
,curdir
);