2 * Unit test suite for dir functions
4 * Copyright 2006 CodeWeavers, Aric Stewart
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"
36 static int (__cdecl
*p_makepath_s
)(char *, size_t, const char *, const char *, const char *, const char *);
37 static int (__cdecl
*p_wmakepath_s
)(wchar_t *, size_t, const wchar_t *,const wchar_t *, const wchar_t *, const wchar_t *);
38 static int (__cdecl
*p_searchenv_s
)(const char*, const char*, char*, size_t);
39 static int (__cdecl
*p_wsearchenv_s
)(const wchar_t*, const wchar_t*, wchar_t*, size_t);
41 static void init(void)
43 HMODULE hmod
= GetModuleHandleA("msvcrt.dll");
45 p_makepath_s
= (void *)GetProcAddress(hmod
, "_makepath_s");
46 p_wmakepath_s
= (void *)GetProcAddress(hmod
, "_wmakepath_s");
47 p_searchenv_s
= (void *)GetProcAddress(hmod
, "_searchenv_s");
48 p_wsearchenv_s
= (void *)GetProcAddress(hmod
, "_wsearchenv_s");
61 #define USE_BUFF ((char*)~0ul)
62 static const makepath_case makepath_cases
[] =
64 { NULL
, NULL
, NULL
, NULL
, NULL
, "" }, /* 0 */
65 { NULL
, "c", NULL
, NULL
, NULL
, "c:" },
66 { NULL
, "c:", NULL
, NULL
, NULL
, "c:" },
67 { NULL
, "c:\\", NULL
, NULL
, NULL
, "c:" },
68 { NULL
, NULL
, "dir", NULL
, NULL
, "dir\\" },
69 { NULL
, NULL
, "dir\\", NULL
, NULL
, "dir\\" },
70 { NULL
, NULL
, "\\dir", NULL
, NULL
, "\\dir\\" },
71 { NULL
, NULL
, NULL
, "file", NULL
, "file" },
72 { NULL
, NULL
, NULL
, "\\file", NULL
, "\\file" },
73 { NULL
, NULL
, NULL
, "file", NULL
, "file" },
74 { NULL
, NULL
, NULL
, NULL
, "ext", ".ext" }, /* 10 */
75 { NULL
, NULL
, NULL
, NULL
, ".ext", ".ext" },
76 { "foo", NULL
, NULL
, NULL
, NULL
, "" },
77 { "foo", USE_BUFF
, NULL
, NULL
, NULL
, "f:" },
78 { "foo", NULL
, USE_BUFF
, NULL
, NULL
, "foo\\" },
79 { "foo", NULL
, NULL
, USE_BUFF
, NULL
, "foo" },
80 { "foo", NULL
, USE_BUFF
, "file", NULL
, "foo\\file" },
81 { "foo", NULL
, USE_BUFF
, "file", "ext", "foo\\file.ext" },
82 { "foo", NULL
, NULL
, USE_BUFF
, "ext", "foo.ext" },
83 /* remaining combinations of USE_BUFF crash native */
84 { NULL
, "c", "dir", "file", "ext", "c:dir\\file.ext" },
85 { NULL
, "c:", "dir", "file", "ext", "c:dir\\file.ext" }, /* 20 */
86 { NULL
, "c:\\", "dir", "file", "ext", "c:dir\\file.ext" }
89 static void test_makepath(void)
91 WCHAR driveW
[MAX_PATH
];
93 WCHAR fileW
[MAX_PATH
];
95 WCHAR bufferW
[MAX_PATH
];
96 char buffer
[MAX_PATH
];
100 for (i
= 0; i
< ARRAY_SIZE(makepath_cases
); ++i
)
102 const makepath_case
* p
= &makepath_cases
[i
];
104 memset(buffer
, 'X', MAX_PATH
);
106 strcpy(buffer
, p
->buffer
);
110 p
->drive
== USE_BUFF
? buffer
: p
->drive
,
111 p
->dir
== USE_BUFF
? buffer
: p
->dir
,
112 p
->file
== USE_BUFF
? buffer
: p
->file
,
113 p
->ext
== USE_BUFF
? buffer
: p
->ext
);
115 buffer
[MAX_PATH
- 1] = '\0';
116 ok(!strcmp(p
->expected
, buffer
), "got '%s' for case %d\n", buffer
, i
);
119 if (p
->drive
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->drive
, -1, driveW
, MAX_PATH
);
120 if (p
->dir
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->dir
, -1, dirW
, MAX_PATH
);
121 if (p
->file
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->file
, -1, fileW
, MAX_PATH
);
122 if (p
->ext
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->ext
, -1, extW
, MAX_PATH
);
124 memset(buffer
, 0, MAX_PATH
);
125 for (n
= 0; n
< MAX_PATH
; ++n
)
127 if (p
->buffer
) MultiByteToWideChar( CP_ACP
, 0, p
->buffer
, -1, bufferW
, MAX_PATH
);
130 p
->drive
== USE_BUFF
? bufferW
: p
->drive
? driveW
: NULL
,
131 p
->dir
== USE_BUFF
? bufferW
: p
->dir
? dirW
: NULL
,
132 p
->file
== USE_BUFF
? bufferW
: p
->file
? fileW
: NULL
,
133 p
->ext
== USE_BUFF
? bufferW
: p
->ext
? extW
: NULL
);
135 bufferW
[MAX_PATH
- 1] = '\0';
136 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, MAX_PATH
, NULL
, NULL
);
137 ok(!strcmp(p
->expected
, buffer
), "got '%s' for unicode case %d\n", buffer
, i
);
149 const char* expected
;
150 const WCHAR
*expected_unicode
;
151 size_t expected_length
;
154 static const makepath_s_case makepath_s_cases
[] =
156 /* Behavior with directory parameter containing backslash. */
157 {NULL
, 1, "c:", "d\\", "file", "ext", "\0XXXXXXXXXXXX", L
"\0XXXXXXXXXXXX", 13},
158 {NULL
, 2, "c:", "d\\", "file", "ext", "\0XXXXXXXXXXXX", L
"\0XXXXXXXXXXXX", 13},
159 {NULL
, 3, "c:", "d\\", "file", "ext", "\0:XXXXXXXXXXX", L
"\0:XXXXXXXXXXX", 13},
160 {NULL
, 4, "c:", "d\\", "file", "ext", "\0:dXXXXXXXXXX", L
"\0:dXXXXXXXXXX", 13},
161 {NULL
, 5, "c:", "d\\", "file", "ext", "\0:d\\XXXXXXXXX", L
"\0:d\\XXXXXXXXX", 13},
162 {NULL
, 6, "c:", "d\\", "file", "ext", "\0:d\\fXXXXXXXX", L
"\0:d\\fXXXXXXXX", 13},
163 {NULL
, 7, "c:", "d\\", "file", "ext", "\0:d\\fiXXXXXXX", L
"\0:d\\fiXXXXXXX", 13},
164 {NULL
, 8, "c:", "d\\", "file", "ext", "\0:d\\filXXXXXX", L
"\0:d\\filXXXXXX", 13},
165 {NULL
, 9, "c:", "d\\", "file", "ext", "\0:d\\fileXXXXX", L
"\0:d\\fileXXXXX", 13},
166 {NULL
, 10, "c:", "d\\", "file", "ext", "\0:d\\file.XXXX", L
"\0:d\\file.XXXX", 13},
167 {NULL
, 11, "c:", "d\\", "file", "ext", "\0:d\\file.eXXX", L
"\0:d\\file.eXXX", 13},
168 {NULL
, 12, "c:", "d\\", "file", "ext", "\0:d\\file.exXX", L
"\0:d\\file.exXX", 13},
169 /* Behavior with directory parameter lacking backslash. */
170 {NULL
, 3, "c:", "dir", "f", "ext", "\0:XXXXXXXX", L
"\0:XXXXXXXX", 10},
171 {NULL
, 4, "c:", "dir", "f", "ext", "\0:dXXXXXXX", L
"\0:dXXXXXXX", 10},
172 {NULL
, 5, "c:", "dir", "f", "ext", "\0:diXXXXXX", L
"\0:diXXXXXX", 10},
173 {NULL
, 6, "c:", "dir", "f", "ext", "\0:dirXXXXX", L
"\0:dirXXXXX", 10},
174 {NULL
, 7, "c:", "dir", "f", "ext", "\0:dir\\XXXX", L
"\0:dir\\XXXX", 10},
175 /* Behavior with overlapped buffer. */
176 {"foo", 2, USE_BUFF
, NULL
, NULL
, NULL
, "\0oo", L
"\0oo", 3},
177 {"foo", 4, NULL
, USE_BUFF
, NULL
, NULL
, "\0oo\0X", L
"\0oo\0X", 5},
178 {"foo", 3, NULL
, NULL
, USE_BUFF
, NULL
, "\0oo\0", L
"\0oo", 4},
179 {"foo", 4, NULL
, USE_BUFF
, "file", NULL
, "\0oo\0XXXXX", L
"\0oo\0XXXXX", 9},
180 {"foo", 8, NULL
, USE_BUFF
, "file", NULL
, "\0oo\\filXX", L
"\0oo\\filXX", 9},
181 {"foo", 4, NULL
, USE_BUFF
, "file", "ext", "\0oo\0XXXXXXXXX", L
"\0oo\0XXXXXXXXX", 13},
182 {"foo", 8, NULL
, USE_BUFF
, "file", "ext", "\0oo\\filXXXXXX", L
"\0oo\\filXXXXXX", 13},
183 {"foo", 12, NULL
, USE_BUFF
, "file", "ext", "\0oo\\file.exXX", L
"\0oo\\file.exXX", 13},
184 {"foo", 4, NULL
, NULL
, USE_BUFF
, "ext", "\0oo\0XXXX", L
"\0oo\0XXXX", 8},
185 {"foo", 7, NULL
, NULL
, USE_BUFF
, "ext", "\0oo.exXX", L
"\0oo.exXX", 8},
188 static void test_makepath_s(void)
190 WCHAR driveW
[MAX_PATH
];
191 WCHAR dirW
[MAX_PATH
];
192 WCHAR fileW
[MAX_PATH
];
193 WCHAR extW
[MAX_PATH
];
194 WCHAR bufferW
[MAX_PATH
];
195 char buffer
[MAX_PATH
];
199 if (!p_makepath_s
|| !p_wmakepath_s
)
201 win_skip("Safe makepath functions are not available\n");
206 ret
= p_makepath_s(NULL
, 0, NULL
, NULL
, NULL
, NULL
);
207 ok(ret
== EINVAL
, "Expected _makepath_s to return EINVAL, got %d\n", ret
);
208 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
211 ret
= p_makepath_s(buffer
, 0, NULL
, NULL
, NULL
, NULL
);
212 ok(ret
== EINVAL
, "Expected _makepath_s to return EINVAL, got %d\n", ret
);
213 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
216 ret
= p_wmakepath_s(NULL
, 0, NULL
, NULL
, NULL
, NULL
);
217 ok(ret
== EINVAL
, "Expected _wmakepath_s to return EINVAL, got %d\n", ret
);
218 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
221 ret
= p_wmakepath_s(bufferW
, 0, NULL
, NULL
, NULL
, NULL
);
222 ok(ret
== EINVAL
, "Expected _wmakepath_s to return EINVAL, got %d\n", ret
);
223 ok(errno
== EINVAL
, "Expected errno to be EINVAL, got %d\n", errno
);
225 /* Test with the normal _makepath cases. */
226 for (i
= 0; i
< ARRAY_SIZE(makepath_cases
); i
++)
228 const makepath_case
*p
= makepath_cases
+ i
;
230 memset(buffer
, 'X', MAX_PATH
);
232 strcpy(buffer
, p
->buffer
);
235 ret
= p_makepath_s(buffer
, MAX_PATH
,
236 p
->drive
== USE_BUFF
? buffer
: p
->drive
,
237 p
->dir
== USE_BUFF
? buffer
: p
->dir
,
238 p
->file
== USE_BUFF
? buffer
: p
->file
,
239 p
->ext
== USE_BUFF
? buffer
: p
->ext
);
240 ok(ret
== 0, "[%d] Expected _makepath_s to return 0, got %d\n", i
, ret
);
242 buffer
[MAX_PATH
- 1] = '\0';
243 ok(!strcmp(p
->expected
, buffer
), "got '%s' for case %d\n", buffer
, i
);
246 if (p
->drive
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->drive
, -1, driveW
, MAX_PATH
);
247 if (p
->dir
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->dir
, -1, dirW
, MAX_PATH
);
248 if (p
->file
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->file
, -1, fileW
, MAX_PATH
);
249 if (p
->ext
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->ext
, -1, extW
, MAX_PATH
);
251 memset(buffer
, 0, MAX_PATH
);
252 for (n
= 0; n
< MAX_PATH
; ++n
)
254 if (p
->buffer
) MultiByteToWideChar( CP_ACP
, 0, p
->buffer
, -1, bufferW
, MAX_PATH
);
256 ret
= p_wmakepath_s(bufferW
, MAX_PATH
,
257 p
->drive
== USE_BUFF
? bufferW
: p
->drive
? driveW
: NULL
,
258 p
->dir
== USE_BUFF
? bufferW
: p
->dir
? dirW
: NULL
,
259 p
->file
== USE_BUFF
? bufferW
: p
->file
? fileW
: NULL
,
260 p
->ext
== USE_BUFF
? bufferW
: p
->ext
? extW
: NULL
);
261 ok(ret
== 0, "[%d] Expected _wmakepath_s to return 0, got %d\n", i
, ret
);
263 bufferW
[MAX_PATH
- 1] = '\0';
264 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, MAX_PATH
, NULL
, NULL
);
265 ok(!strcmp(p
->expected
, buffer
), "got '%s' for unicode case %d\n", buffer
, i
);
268 /* Try insufficient length cases. */
269 for (i
= 0; i
< ARRAY_SIZE(makepath_s_cases
); i
++)
271 const makepath_s_case
*p
= makepath_s_cases
+ i
;
273 memset(buffer
, 'X', MAX_PATH
);
275 strcpy(buffer
, p
->buffer
);
279 ret
= p_makepath_s(buffer
, p
->length
,
280 p
->drive
== USE_BUFF
? buffer
: p
->drive
,
281 p
->dir
== USE_BUFF
? buffer
: p
->dir
,
282 p
->file
== USE_BUFF
? buffer
: p
->file
,
283 p
->ext
== USE_BUFF
? buffer
: p
->ext
);
284 ok(ret
== ERANGE
, "[%d] Expected _makepath_s to return ERANGE, got %d\n", i
, ret
);
285 ok(errno
== ERANGE
, "[%d] Expected errno to be ERANGE, got %d\n", i
, errno
);
286 ok(!memcmp(p
->expected
, buffer
, p
->expected_length
), "unexpected output for case %d\n", i
);
289 if (p
->drive
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->drive
, -1, driveW
, MAX_PATH
);
290 if (p
->dir
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->dir
, -1, dirW
, MAX_PATH
);
291 if (p
->file
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->file
, -1, fileW
, MAX_PATH
);
292 if (p
->ext
!= USE_BUFF
) MultiByteToWideChar(CP_ACP
, 0, p
->ext
, -1, extW
, MAX_PATH
);
294 memset(buffer
, 0, MAX_PATH
);
295 for (n
= 0; n
< MAX_PATH
; ++n
)
297 if (p
->buffer
) MultiByteToWideChar( CP_ACP
, 0, p
->buffer
, -1, bufferW
, MAX_PATH
);
300 ret
= p_wmakepath_s(bufferW
, p
->length
,
301 p
->drive
== USE_BUFF
? bufferW
: p
->drive
? driveW
: NULL
,
302 p
->dir
== USE_BUFF
? bufferW
: p
->dir
? dirW
: NULL
,
303 p
->file
== USE_BUFF
? bufferW
: p
->file
? fileW
: NULL
,
304 p
->ext
== USE_BUFF
? bufferW
: p
->ext
? extW
: NULL
);
305 ok(ret
== ERANGE
, "[%d] Expected _wmakepath_s to return ERANGE, got %d\n", i
, ret
);
306 ok(errno
== ERANGE
, "[%d] Expected errno to be ERANGE, got %d\n", i
, errno
);
308 ok(!memcmp(p
->expected_unicode
, bufferW
, p
->expected_length
* sizeof(WCHAR
)), "unexpected output for case %d\n", i
);
312 static void test_fullpath(void)
315 char tmppath
[MAX_PATH
];
316 char prevpath
[MAX_PATH
];
317 char level1
[MAX_PATH
];
318 char level2
[MAX_PATH
];
319 char teststring
[MAX_PATH
];
324 GetCurrentDirectoryA(MAX_PATH
, prevpath
);
325 GetTempPathA(MAX_PATH
,tmppath
);
326 strcpy(level1
,tmppath
);
327 strcat(level1
,"msvcrt-test\\");
329 rc
= CreateDirectoryA(level1
,NULL
);
330 if (!rc
&& GetLastError()==ERROR_ALREADY_EXISTS
)
333 strcpy(level2
,level1
);
334 strcat(level2
,"nextlevel\\");
335 rc
= CreateDirectoryA(level2
,NULL
);
336 if (!rc
&& GetLastError()==ERROR_ALREADY_EXISTS
)
338 SetCurrentDirectoryA(level2
);
340 ok(_fullpath(full
,"test", MAX_PATH
)!=NULL
,"_fullpath failed\n");
341 strcpy(teststring
,level2
);
342 strcat(teststring
,"test");
343 ok(strcmp(full
,teststring
)==0,"Invalid Path returned %s\n",full
);
344 ok(_fullpath(full
,"\\test", MAX_PATH
)!=NULL
,"_fullpath failed\n");
345 memcpy(teststring
,level2
,3);
347 strcat(teststring
,"test");
348 ok(strcmp(full
,teststring
)==0,"Invalid Path returned %s\n",full
);
349 ok(_fullpath(full
,"..\\test", MAX_PATH
)!=NULL
,"_fullpath failed\n");
350 strcpy(teststring
,level1
);
351 strcat(teststring
,"test");
352 ok(strcmp(full
,teststring
)==0,"Invalid Path returned %s\n",full
);
353 ok(_fullpath(full
,"..\\test", 10)==NULL
,"_fullpath failed to generate error\n");
355 freeme
= _fullpath(NULL
,"test", 0);
356 ok(freeme
!=NULL
,"No path returned\n");
357 strcpy(teststring
,level2
);
358 strcat(teststring
,"test");
359 ok(strcmp(freeme
,teststring
)==0,"Invalid Path returned %s\n",freeme
);
362 SetCurrentDirectoryA(prevpath
);
364 RemoveDirectoryA(level2
);
366 RemoveDirectoryA(level1
);
369 static void test_splitpath(void)
371 const char* path
= "c:\\\x83\x5c\x83\x74\x83\x67.bin";
372 char drive
[3], dir
[MAX_PATH
], fname
[MAX_PATH
], ext
[MAX_PATH
];
373 int prev_cp
= _getmbcp();
377 _splitpath(path
, drive
, dir
, fname
, ext
);
378 ok(!strcmp(drive
, "c:"), "got %s\n", drive
);
379 ok(!strcmp(dir
, "\\\x83\x5c"), "got %s\n", dir
);
380 ok(!strcmp(fname
, "\x83\x74\x83\x67"), "got %s\n", fname
);
381 ok(!strcmp(ext
, ".bin"), "got %s\n", ext
);
383 /* MBCS (Japanese) codepage */
385 _splitpath(path
, drive
, dir
, fname
, ext
);
386 ok(!strcmp(drive
, "c:"), "got %s\n", drive
);
387 ok(!strcmp(dir
, "\\"), "got %s\n", dir
);
388 ok(!strcmp(fname
, "\x83\x5c\x83\x74\x83\x67"), "got %s\n", fname
);
389 ok(!strcmp(ext
, ".bin"), "got %s\n", ext
);
394 static void test_searchenv(void)
396 const char *dirs
[] = {
398 "\\search_env_test\\dir1",
399 "\\search_env_test\\dir2",
400 "\\search_env_test\\dir3longer"
403 const char *files
[] = {
404 "\\search_env_test\\dir1\\1.dat",
405 "\\search_env_test\\dir1\\2.dat",
406 "\\search_env_test\\dir2\\1.dat",
407 "\\search_env_test\\dir2\\3.dat",
408 "\\search_env_test\\dir3longer\\3.dat"
411 char env1
[4*MAX_PATH
], env2
[4*MAX_PATH
], tmppath
[MAX_PATH
], path
[2*MAX_PATH
];
412 char result
[MAX_PATH
], exp
[2*MAX_PATH
];
413 WCHAR result_w
[MAX_PATH
];
417 if (getenv("TEST_PATH")) {
418 skip("TEST_PATH environment variable already set\n");
422 path_len
= GetTempPathA(MAX_PATH
, tmppath
);
423 ok(path_len
, "GetTempPath failed\n");
424 memcpy(path
, tmppath
, path_len
);
426 for (i
=0; i
<ARRAY_SIZE(dirs
); i
++) {
427 strcpy(path
+path_len
, dirs
[i
]);
428 ok(!mkdir(path
), "mkdir failed (dir = %s)\n", path
);
431 for (i
=0; i
<ARRAY_SIZE(files
); i
++) {
432 strcpy(path
+path_len
, files
[i
]);
433 tmp_file
= fopen(path
, "wb");
434 ok(tmp_file
!= NULL
, "fopen failed (file = %s)\n", path
);
438 strcpy(env1
, "TEST_PATH=");
439 strcpy(env2
, "TEST_PATH=;");
440 for (i
=1; i
<ARRAY_SIZE(dirs
); i
++) {
441 strcat(env1
, tmppath
);
442 strcat(env1
, dirs
[i
]);
445 strcat(env2
, tmppath
);
446 strcat(env2
, dirs
[i
]);
450 if (!p_searchenv_s
|| !p_wsearchenv_s
)
451 win_skip("searchenv_s or wsearchenv_s function is not available\n");
454 memset(result
, 'x', sizeof(result
));
455 _searchenv("fail", "TEST_PATH", result
);
456 ok(!result
[0], "got %s, expected ''\n", result
);
459 memset(result
, 'x', sizeof(result
));
460 i
= p_searchenv_s("fail", "TEST_PATH", result
, MAX_PATH
);
461 ok(i
== ENOENT
, "searchenv_s returned %d\n", i
);
462 ok(!result
[0], "got %s, expected ''\n", result
);
465 memset(result
, 'x', sizeof(result
));
466 strcpy(exp
, tmppath
);
467 strcat(exp
, files
[0]);
468 _searchenv("1.dat", "TEST_PATH", result
);
469 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
472 memset(result
, 'x', sizeof(result
));
473 i
= p_searchenv_s("1.dat", "TEST_PATH", result
, MAX_PATH
);
474 ok(!i
, "searchenv_s returned %d\n", i
);
475 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
478 memset(result_w
, 'x', sizeof(result_w
));
479 _wsearchenv(L
"1.dat", L
"TEST_PATH", result_w
);
480 WideCharToMultiByte(CP_ACP
, 0, result_w
, -1, result
, MAX_PATH
, NULL
, NULL
);
481 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
483 if (p_wsearchenv_s
) {
484 memset(result_w
, 'x', sizeof(result_w
));
485 i
= p_wsearchenv_s(L
"1.dat", L
"TEST_PATH", result_w
, MAX_PATH
);
486 ok(!i
, "wsearchenv_s returned %d\n", i
);
487 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
490 memset(result
, 'x', sizeof(result
));
491 strcpy(exp
, tmppath
);
492 strcat(exp
, files
[3]);
493 _searchenv("3.dat", "TEST_PATH", result
);
494 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
497 memset(result
, 'x', sizeof(result
));
498 i
= p_searchenv_s("3.dat", "TEST_PATH", result
, MAX_PATH
);
499 ok(!i
, "searchenv_s returned %d\n", i
);
500 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
503 memset(result_w
, 'x', sizeof(result_w
));
504 _wsearchenv(L
"3.dat", L
"TEST_PATH", result_w
);
505 WideCharToMultiByte(CP_ACP
, 0, result_w
, -1, result
, MAX_PATH
, NULL
, NULL
);
506 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
508 if (p_wsearchenv_s
) {
509 memset(result_w
, 'x', sizeof(result_w
));
510 i
= p_wsearchenv_s(L
"3.dat", L
"TEST_PATH", result_w
, MAX_PATH
);
511 ok(!i
, "wsearchenv_s returned %d\n", i
);
512 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
516 memset(result
, 'x', sizeof(result
));
517 strcpy(exp
, tmppath
);
518 strcat(exp
, files
[0]);
519 _searchenv("1.dat", "TEST_PATH", result
);
520 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
523 memset(result
, 'x', sizeof(result
));
524 i
= p_searchenv_s("1.dat", "TEST_PATH", result
, MAX_PATH
);
525 ok(!i
, "searchenv_s returned %d\n", i
);
526 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
529 memset(result_w
, 'x', sizeof(result_w
));
530 _wsearchenv(L
"1.dat", L
"TEST_PATH", result_w
);
531 WideCharToMultiByte(CP_ACP
, 0, result_w
, -1, result
, MAX_PATH
, NULL
, NULL
);
532 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
534 if (p_wsearchenv_s
) {
535 memset(result_w
, 'x', sizeof(result_w
));
536 i
= p_wsearchenv_s(L
"1.dat", L
"TEST_PATH", result_w
, MAX_PATH
);
537 ok(!i
, "wsearchenv_s returned %d\n", i
);
538 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
541 memset(result
, 'x', sizeof(result
));
542 strcpy(exp
, tmppath
);
543 strcat(exp
, files
[3]);
544 _searchenv("3.dat", "TEST_PATH", result
);
545 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
548 memset(result
, 'x', sizeof(result
));
549 i
= p_searchenv_s("3.dat", "TEST_PATH", result
, MAX_PATH
);
550 ok(!i
, "searchenv_s returned %d\n", i
);
551 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
554 memset(result_w
, 'x', sizeof(result_w
));
555 _wsearchenv(L
"3.dat", L
"TEST_PATH", result_w
);
556 WideCharToMultiByte(CP_ACP
, 0, result_w
, -1, result
, MAX_PATH
, NULL
, NULL
);
557 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
559 if (p_wsearchenv_s
) {
560 memset(result_w
, 'x', sizeof(result_w
));
561 i
= p_wsearchenv_s(L
"3.dat", L
"TEST_PATH", result_w
, MAX_PATH
);
562 ok(!i
, "wsearchenv_s returned %d\n", i
);
563 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
566 strcpy(env1
, "TEST_PATH=");
567 strcat(env1
, tmppath
);
568 strcat(env1
, "\"\\search_env_test\\\"d\"i\"r\"1");
570 strcpy(exp
, tmppath
);
571 strcat(exp
, files
[0]);
572 _searchenv("1.dat", "TEST_PATH", result
);
573 ok(!strcmp(result
, exp
), "got %s, expected '%s'\n", result
, exp
);
577 _searchenv("1.dat", "TEST_PATH", result
);
578 ok(!result
[0], "got %s, expected ''\n", result
);
580 putenv("TEST_PATH=");
582 for (i
=ARRAY_SIZE(files
)-1; i
>=0; i
--) {
583 strcpy(path
+path_len
, files
[i
]);
584 ok(!remove(path
), "remove failed (file = %s)\n", path
);
587 for (i
=ARRAY_SIZE(dirs
)-1; i
>=0; i
--) {
588 strcpy(path
+path_len
, dirs
[i
]);
589 ok(!rmdir(path
), "rmdir failed (dir = %s)\n", path
);