1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Unit test suite for dir functions
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2006 CodeWeavers, Aric Stewart
5c2c66affSColin Finck  *
6c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14c2c66affSColin Finck  * Lesser General Public License for more details.
15c2c66affSColin Finck  *
16c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck  */
20c2c66affSColin Finck 
211c9ac7a2SAmine Khaldi #include "wine/test.h"
221c9ac7a2SAmine Khaldi #include <stdarg.h>
231c9ac7a2SAmine Khaldi #include <stdlib.h>
241c9ac7a2SAmine Khaldi #include <stdio.h>
251c9ac7a2SAmine Khaldi #include <fcntl.h>
261c9ac7a2SAmine Khaldi #include <direct.h>
271c9ac7a2SAmine Khaldi #include <sys/stat.h>
281c9ac7a2SAmine Khaldi #include <io.h>
29c2c66affSColin Finck #include <mbctype.h>
301c9ac7a2SAmine Khaldi #include <windef.h>
311c9ac7a2SAmine Khaldi #include <winbase.h>
321c9ac7a2SAmine Khaldi #include <winnls.h>
331c9ac7a2SAmine Khaldi #include <process.h>
341c9ac7a2SAmine Khaldi #include <errno.h>
35c2c66affSColin Finck 
36c2c66affSColin Finck static int (__cdecl *p_makepath_s)(char *, size_t, const char *, const char *, const char *, const char *);
37c2c66affSColin Finck static int (__cdecl *p_wmakepath_s)(wchar_t *, size_t, const wchar_t *,const wchar_t *, const wchar_t *, const wchar_t *);
381c9ac7a2SAmine Khaldi static int (__cdecl *p_searchenv_s)(const char*, const char*, char*, size_t);
391c9ac7a2SAmine Khaldi static int (__cdecl *p_wsearchenv_s)(const wchar_t*, const wchar_t*, wchar_t*, size_t);
40c2c66affSColin Finck 
init(void)41c2c66affSColin Finck static void init(void)
42c2c66affSColin Finck {
43c2c66affSColin Finck     HMODULE hmod = GetModuleHandleA("msvcrt.dll");
44c2c66affSColin Finck 
45c2c66affSColin Finck     p_makepath_s = (void *)GetProcAddress(hmod, "_makepath_s");
46c2c66affSColin Finck     p_wmakepath_s = (void *)GetProcAddress(hmod, "_wmakepath_s");
471c9ac7a2SAmine Khaldi     p_searchenv_s = (void *)GetProcAddress(hmod, "_searchenv_s");
481c9ac7a2SAmine Khaldi     p_wsearchenv_s = (void *)GetProcAddress(hmod, "_wsearchenv_s");
49c2c66affSColin Finck }
50c2c66affSColin Finck 
51c2c66affSColin Finck typedef struct
52c2c66affSColin Finck {
53c2c66affSColin Finck     const char* buffer;
54c2c66affSColin Finck     const char* drive;
55c2c66affSColin Finck     const char* dir;
56c2c66affSColin Finck     const char* file;
57c2c66affSColin Finck     const char* ext;
58c2c66affSColin Finck     const char* expected;
59c2c66affSColin Finck } makepath_case;
60c2c66affSColin Finck 
61c2c66affSColin Finck #define USE_BUFF ((char*)~0ul)
62c2c66affSColin Finck static const makepath_case makepath_cases[] =
63c2c66affSColin Finck {
64c2c66affSColin Finck     { NULL, NULL, NULL, NULL, NULL, "" }, /* 0 */
65c2c66affSColin Finck     { NULL, "c", NULL, NULL, NULL, "c:" },
66c2c66affSColin Finck     { NULL, "c:", NULL, NULL, NULL, "c:" },
67c2c66affSColin Finck     { NULL, "c:\\", NULL, NULL, NULL, "c:" },
68c2c66affSColin Finck     { NULL, NULL, "dir", NULL, NULL, "dir\\" },
69c2c66affSColin Finck     { NULL, NULL, "dir\\", NULL, NULL, "dir\\" },
70c2c66affSColin Finck     { NULL, NULL, "\\dir", NULL, NULL, "\\dir\\" },
71c2c66affSColin Finck     { NULL, NULL, NULL, "file", NULL, "file" },
72c2c66affSColin Finck     { NULL, NULL, NULL, "\\file", NULL, "\\file" },
73c2c66affSColin Finck     { NULL, NULL, NULL, "file", NULL, "file" },
74c2c66affSColin Finck     { NULL, NULL, NULL, NULL, "ext", ".ext" }, /* 10 */
75c2c66affSColin Finck     { NULL, NULL, NULL, NULL, ".ext", ".ext" },
76c2c66affSColin Finck     { "foo", NULL, NULL, NULL, NULL, "" },
77c2c66affSColin Finck     { "foo", USE_BUFF, NULL, NULL, NULL, "f:" },
78c2c66affSColin Finck     { "foo", NULL, USE_BUFF, NULL, NULL, "foo\\" },
79c2c66affSColin Finck     { "foo", NULL, NULL, USE_BUFF, NULL, "foo" },
80c2c66affSColin Finck     { "foo", NULL, USE_BUFF, "file", NULL, "foo\\file" },
81c2c66affSColin Finck     { "foo", NULL, USE_BUFF, "file", "ext", "foo\\file.ext" },
82c2c66affSColin Finck     { "foo", NULL, NULL, USE_BUFF, "ext", "foo.ext" },
83c2c66affSColin Finck     /* remaining combinations of USE_BUFF crash native */
84c2c66affSColin Finck     { NULL, "c", "dir", "file", "ext", "c:dir\\file.ext" },
85c2c66affSColin Finck     { NULL, "c:", "dir", "file", "ext", "c:dir\\file.ext" }, /* 20 */
86c2c66affSColin Finck     { NULL, "c:\\", "dir", "file", "ext", "c:dir\\file.ext" }
87c2c66affSColin Finck };
88c2c66affSColin Finck 
test_makepath(void)89c2c66affSColin Finck static void test_makepath(void)
90c2c66affSColin Finck {
91c2c66affSColin Finck     WCHAR driveW[MAX_PATH];
92c2c66affSColin Finck     WCHAR dirW[MAX_PATH];
93c2c66affSColin Finck     WCHAR fileW[MAX_PATH];
94c2c66affSColin Finck     WCHAR extW[MAX_PATH];
95c2c66affSColin Finck     WCHAR bufferW[MAX_PATH];
96c2c66affSColin Finck     char buffer[MAX_PATH];
97c2c66affSColin Finck 
98c2c66affSColin Finck     unsigned int i, n;
99c2c66affSColin Finck 
100*f446a50fSAmine Khaldi     for (i = 0; i < ARRAY_SIZE(makepath_cases); ++i)
101c2c66affSColin Finck     {
102c2c66affSColin Finck         const makepath_case* p = &makepath_cases[i];
103c2c66affSColin Finck 
104c2c66affSColin Finck         memset(buffer, 'X', MAX_PATH);
105c2c66affSColin Finck         if (p->buffer)
106c2c66affSColin Finck             strcpy(buffer, p->buffer);
107c2c66affSColin Finck 
108c2c66affSColin Finck         /* Ascii */
109c2c66affSColin Finck         _makepath(buffer,
110c2c66affSColin Finck                   p->drive == USE_BUFF ? buffer : p->drive,
111c2c66affSColin Finck                   p->dir == USE_BUFF ? buffer : p->dir,
112c2c66affSColin Finck                   p->file == USE_BUFF? buffer : p->file,
113c2c66affSColin Finck                   p->ext == USE_BUFF ? buffer : p->ext);
114c2c66affSColin Finck 
115c2c66affSColin Finck         buffer[MAX_PATH - 1] = '\0';
116c2c66affSColin Finck         ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
117c2c66affSColin Finck 
118c2c66affSColin Finck         /* Unicode */
119c2c66affSColin Finck         if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH);
120c2c66affSColin Finck         if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH);
121c2c66affSColin Finck         if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH);
122c2c66affSColin Finck         if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH);
123c2c66affSColin Finck 
124c2c66affSColin Finck         memset(buffer, 0, MAX_PATH);
125c2c66affSColin Finck         for (n = 0; n < MAX_PATH; ++n)
126c2c66affSColin Finck             bufferW[n] = 'X';
127c2c66affSColin Finck         if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
128c2c66affSColin Finck 
129c2c66affSColin Finck         _wmakepath(bufferW,
130c2c66affSColin Finck                    p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL,
131c2c66affSColin Finck                    p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL,
132c2c66affSColin Finck                    p->file == USE_BUFF? bufferW : p->file ? fileW : NULL,
133c2c66affSColin Finck                    p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL);
134c2c66affSColin Finck 
135c2c66affSColin Finck         bufferW[MAX_PATH - 1] = '\0';
136c2c66affSColin Finck         WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
137c2c66affSColin Finck         ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
138c2c66affSColin Finck     }
139c2c66affSColin Finck }
140c2c66affSColin Finck 
141c2c66affSColin Finck static const WCHAR expected0[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X'};
142c2c66affSColin Finck static const WCHAR expected1[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X'};
143c2c66affSColin Finck static const WCHAR expected2[] = {'\0',':','X','X','X','X','X','X','X','X','X','X','X'};
144c2c66affSColin Finck static const WCHAR expected3[] = {'\0',':','d','X','X','X','X','X','X','X','X','X','X'};
145c2c66affSColin Finck static const WCHAR expected4[] = {'\0',':','d','\\','X','X','X','X','X','X','X','X','X'};
146c2c66affSColin Finck static const WCHAR expected5[] = {'\0',':','d','\\','f','X','X','X','X','X','X','X','X'};
147c2c66affSColin Finck static const WCHAR expected6[] = {'\0',':','d','\\','f','i','X','X','X','X','X','X','X'};
148c2c66affSColin Finck static const WCHAR expected7[] = {'\0',':','d','\\','f','i','l','X','X','X','X','X','X'};
149c2c66affSColin Finck static const WCHAR expected8[] = {'\0',':','d','\\','f','i','l','e','X','X','X','X','X'};
150c2c66affSColin Finck static const WCHAR expected9[] = {'\0',':','d','\\','f','i','l','e','.','X','X','X','X'};
151c2c66affSColin Finck static const WCHAR expected10[] = {'\0',':','d','\\','f','i','l','e','.','e','X','X','X'};
152c2c66affSColin Finck static const WCHAR expected11[] = {'\0',':','d','\\','f','i','l','e','.','e','x','X','X'};
153c2c66affSColin Finck 
154c2c66affSColin Finck static const WCHAR expected12[] = {'\0',':','X','X','X','X','X','X','X','X'};
155c2c66affSColin Finck static const WCHAR expected13[] = {'\0',':','d','X','X','X','X','X','X','X'};
156c2c66affSColin Finck static const WCHAR expected14[] = {'\0',':','d','i','X','X','X','X','X','X'};
157c2c66affSColin Finck static const WCHAR expected15[] = {'\0',':','d','i','r','X','X','X','X','X'};
158c2c66affSColin Finck static const WCHAR expected16[] = {'\0',':','d','i','r','\\','X','X','X','X'};
159c2c66affSColin Finck 
160c2c66affSColin Finck static const WCHAR expected17[] = {'\0','o','o'};
161c2c66affSColin Finck static const WCHAR expected18[] = {'\0','o','o','\0','X'};
162c2c66affSColin Finck static const WCHAR expected19[] = {'\0','o','o','\0'};
163c2c66affSColin Finck static const WCHAR expected20[] = {'\0','o','o','\0','X','X','X','X','X'};
164c2c66affSColin Finck static const WCHAR expected21[] = {'\0','o','o','\\','f','i','l','X','X'};
165c2c66affSColin Finck static const WCHAR expected22[] = {'\0','o','o','\0','X','X','X','X','X','X','X','X','X'};
166c2c66affSColin Finck static const WCHAR expected23[] = {'\0','o','o','\\','f','i','l','X','X','X','X','X','X'};
167c2c66affSColin Finck static const WCHAR expected24[] = {'\0','o','o','\\','f','i','l','e','.','e','x','X','X'};
168c2c66affSColin Finck static const WCHAR expected25[] = {'\0','o','o','\0','X','X','X','X'};
169c2c66affSColin Finck static const WCHAR expected26[] = {'\0','o','o','.','e','x','X','X'};
170c2c66affSColin Finck 
171c2c66affSColin Finck typedef struct
172c2c66affSColin Finck {
173c2c66affSColin Finck     const char* buffer;
174c2c66affSColin Finck     size_t length;
175c2c66affSColin Finck     const char* drive;
176c2c66affSColin Finck     const char* dir;
177c2c66affSColin Finck     const char* file;
178c2c66affSColin Finck     const char* ext;
179c2c66affSColin Finck     const char* expected;
180c2c66affSColin Finck     const WCHAR *expected_unicode;
181c2c66affSColin Finck     size_t expected_length;
182c2c66affSColin Finck } makepath_s_case;
183c2c66affSColin Finck 
184c2c66affSColin Finck static const makepath_s_case makepath_s_cases[] =
185c2c66affSColin Finck {
186c2c66affSColin Finck     /* Behavior with directory parameter containing backslash. */
187c2c66affSColin Finck     {NULL, 1, "c:", "d\\", "file", "ext", "\0XXXXXXXXXXXX", expected0, 13},
188c2c66affSColin Finck     {NULL, 2, "c:", "d\\", "file", "ext", "\0XXXXXXXXXXXX", expected1, 13},
189c2c66affSColin Finck     {NULL, 3, "c:", "d\\", "file", "ext", "\0:XXXXXXXXXXX", expected2, 13},
190c2c66affSColin Finck     {NULL, 4, "c:", "d\\", "file", "ext", "\0:dXXXXXXXXXX", expected3, 13},
191c2c66affSColin Finck     {NULL, 5, "c:", "d\\", "file", "ext", "\0:d\\XXXXXXXXX", expected4, 13},
192c2c66affSColin Finck     {NULL, 6, "c:", "d\\", "file", "ext", "\0:d\\fXXXXXXXX", expected5, 13},
193c2c66affSColin Finck     {NULL, 7, "c:", "d\\", "file", "ext", "\0:d\\fiXXXXXXX", expected6, 13},
194c2c66affSColin Finck     {NULL, 8, "c:", "d\\", "file", "ext", "\0:d\\filXXXXXX", expected7, 13},
195c2c66affSColin Finck     {NULL, 9, "c:", "d\\", "file", "ext", "\0:d\\fileXXXXX", expected8, 13},
196c2c66affSColin Finck     {NULL, 10, "c:", "d\\", "file", "ext", "\0:d\\file.XXXX", expected9, 13},
197c2c66affSColin Finck     {NULL, 11, "c:", "d\\", "file", "ext", "\0:d\\file.eXXX", expected10, 13},
198c2c66affSColin Finck     {NULL, 12, "c:", "d\\", "file", "ext", "\0:d\\file.exXX", expected11, 13},
199c2c66affSColin Finck     /* Behavior with directory parameter lacking backslash. */
200c2c66affSColin Finck     {NULL, 3, "c:", "dir", "f", "ext", "\0:XXXXXXXX", expected12, 10},
201c2c66affSColin Finck     {NULL, 4, "c:", "dir", "f", "ext", "\0:dXXXXXXX", expected13, 10},
202c2c66affSColin Finck     {NULL, 5, "c:", "dir", "f", "ext", "\0:diXXXXXX", expected14, 10},
203c2c66affSColin Finck     {NULL, 6, "c:", "dir", "f", "ext", "\0:dirXXXXX", expected15, 10},
204c2c66affSColin Finck     {NULL, 7, "c:", "dir", "f", "ext", "\0:dir\\XXXX", expected16, 10},
205c2c66affSColin Finck     /* Behavior with overlapped buffer. */
206c2c66affSColin Finck     {"foo", 2, USE_BUFF, NULL, NULL, NULL, "\0oo", expected17, 3},
207c2c66affSColin Finck     {"foo", 4, NULL, USE_BUFF, NULL, NULL, "\0oo\0X", expected18, 5},
208c2c66affSColin Finck     {"foo", 3, NULL, NULL, USE_BUFF, NULL, "\0oo\0", expected19, 4},
209c2c66affSColin Finck     {"foo", 4, NULL, USE_BUFF, "file", NULL, "\0oo\0XXXXX", expected20, 9},
210c2c66affSColin Finck     {"foo", 8, NULL, USE_BUFF, "file", NULL, "\0oo\\filXX", expected21, 9},
211c2c66affSColin Finck     {"foo", 4, NULL, USE_BUFF, "file", "ext", "\0oo\0XXXXXXXXX", expected22, 13},
212c2c66affSColin Finck     {"foo", 8, NULL, USE_BUFF, "file", "ext", "\0oo\\filXXXXXX", expected23, 13},
213c2c66affSColin Finck     {"foo", 12, NULL, USE_BUFF, "file", "ext", "\0oo\\file.exXX", expected24, 13},
214c2c66affSColin Finck     {"foo", 4, NULL, NULL, USE_BUFF, "ext", "\0oo\0XXXX", expected25, 8},
215c2c66affSColin Finck     {"foo", 7, NULL, NULL, USE_BUFF, "ext", "\0oo.exXX", expected26, 8},
216c2c66affSColin Finck };
217c2c66affSColin Finck 
test_makepath_s(void)218c2c66affSColin Finck static void test_makepath_s(void)
219c2c66affSColin Finck {
220c2c66affSColin Finck     WCHAR driveW[MAX_PATH];
221c2c66affSColin Finck     WCHAR dirW[MAX_PATH];
222c2c66affSColin Finck     WCHAR fileW[MAX_PATH];
223c2c66affSColin Finck     WCHAR extW[MAX_PATH];
224c2c66affSColin Finck     WCHAR bufferW[MAX_PATH];
225c2c66affSColin Finck     char buffer[MAX_PATH];
226c2c66affSColin Finck     int ret;
227c2c66affSColin Finck     unsigned int i, n;
228c2c66affSColin Finck 
229c2c66affSColin Finck     if (!p_makepath_s || !p_wmakepath_s)
230c2c66affSColin Finck     {
231c2c66affSColin Finck         win_skip("Safe makepath functions are not available\n");
232c2c66affSColin Finck         return;
233c2c66affSColin Finck     }
234c2c66affSColin Finck 
235c2c66affSColin Finck     errno = EBADF;
236c2c66affSColin Finck     ret = p_makepath_s(NULL, 0, NULL, NULL, NULL, NULL);
237c2c66affSColin Finck     ok(ret == EINVAL, "Expected _makepath_s to return EINVAL, got %d\n", ret);
238c2c66affSColin Finck     ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
239c2c66affSColin Finck 
240c2c66affSColin Finck     errno = EBADF;
241c2c66affSColin Finck     ret = p_makepath_s(buffer, 0, NULL, NULL, NULL, NULL);
242c2c66affSColin Finck     ok(ret == EINVAL, "Expected _makepath_s to return EINVAL, got %d\n", ret);
243c2c66affSColin Finck     ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
244c2c66affSColin Finck 
245c2c66affSColin Finck     errno = EBADF;
246c2c66affSColin Finck     ret = p_wmakepath_s(NULL, 0, NULL, NULL, NULL, NULL);
247c2c66affSColin Finck     ok(ret == EINVAL, "Expected _wmakepath_s to return EINVAL, got %d\n", ret);
248c2c66affSColin Finck     ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
249c2c66affSColin Finck 
250c2c66affSColin Finck     errno = EBADF;
251c2c66affSColin Finck     ret = p_wmakepath_s(bufferW, 0, NULL, NULL, NULL, NULL);
252c2c66affSColin Finck     ok(ret == EINVAL, "Expected _wmakepath_s to return EINVAL, got %d\n", ret);
253c2c66affSColin Finck     ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno);
254c2c66affSColin Finck 
255c2c66affSColin Finck     /* Test with the normal _makepath cases. */
256*f446a50fSAmine Khaldi     for (i = 0; i < ARRAY_SIZE(makepath_cases); i++)
257c2c66affSColin Finck     {
258c2c66affSColin Finck         const makepath_case *p = makepath_cases + i;
259c2c66affSColin Finck 
260c2c66affSColin Finck         memset(buffer, 'X', MAX_PATH);
261c2c66affSColin Finck         if (p->buffer)
262c2c66affSColin Finck             strcpy(buffer, p->buffer);
263c2c66affSColin Finck 
264c2c66affSColin Finck         /* Ascii */
265c2c66affSColin Finck         ret = p_makepath_s(buffer, MAX_PATH,
266c2c66affSColin Finck                            p->drive == USE_BUFF ? buffer : p->drive,
267c2c66affSColin Finck                            p->dir == USE_BUFF ? buffer : p->dir,
268c2c66affSColin Finck                            p->file == USE_BUFF? buffer : p->file,
269c2c66affSColin Finck                            p->ext == USE_BUFF ? buffer : p->ext);
270c2c66affSColin Finck         ok(ret == 0, "[%d] Expected _makepath_s to return 0, got %d\n", i, ret);
271c2c66affSColin Finck 
272c2c66affSColin Finck         buffer[MAX_PATH - 1] = '\0';
273c2c66affSColin Finck         ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
274c2c66affSColin Finck 
275c2c66affSColin Finck         /* Unicode */
276c2c66affSColin Finck         if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH);
277c2c66affSColin Finck         if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH);
278c2c66affSColin Finck         if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH);
279c2c66affSColin Finck         if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH);
280c2c66affSColin Finck 
281c2c66affSColin Finck         memset(buffer, 0, MAX_PATH);
282c2c66affSColin Finck         for (n = 0; n < MAX_PATH; ++n)
283c2c66affSColin Finck             bufferW[n] = 'X';
284c2c66affSColin Finck         if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
285c2c66affSColin Finck 
286c2c66affSColin Finck         ret = p_wmakepath_s(bufferW, MAX_PATH,
287c2c66affSColin Finck                             p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL,
288c2c66affSColin Finck                             p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL,
289c2c66affSColin Finck                             p->file == USE_BUFF? bufferW : p->file ? fileW : NULL,
290c2c66affSColin Finck                             p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL);
291c2c66affSColin Finck         ok(ret == 0, "[%d] Expected _wmakepath_s to return 0, got %d\n", i, ret);
292c2c66affSColin Finck 
293c2c66affSColin Finck         bufferW[MAX_PATH - 1] = '\0';
294c2c66affSColin Finck         WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
295c2c66affSColin Finck         ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
296c2c66affSColin Finck     }
297c2c66affSColin Finck 
298c2c66affSColin Finck     /* Try insufficient length cases. */
299*f446a50fSAmine Khaldi     for (i = 0; i < ARRAY_SIZE(makepath_s_cases); i++)
300c2c66affSColin Finck     {
301c2c66affSColin Finck         const makepath_s_case *p = makepath_s_cases + i;
302c2c66affSColin Finck 
303c2c66affSColin Finck         memset(buffer, 'X', MAX_PATH);
304c2c66affSColin Finck         if (p->buffer)
305c2c66affSColin Finck             strcpy(buffer, p->buffer);
306c2c66affSColin Finck 
307c2c66affSColin Finck         /* Ascii */
308c2c66affSColin Finck         errno = EBADF;
309c2c66affSColin Finck         ret = p_makepath_s(buffer, p->length,
310c2c66affSColin Finck                            p->drive == USE_BUFF ? buffer : p->drive,
311c2c66affSColin Finck                            p->dir == USE_BUFF ? buffer : p->dir,
312c2c66affSColin Finck                            p->file == USE_BUFF? buffer : p->file,
313c2c66affSColin Finck                            p->ext == USE_BUFF ? buffer : p->ext);
314c2c66affSColin Finck         ok(ret == ERANGE, "[%d] Expected _makepath_s to return ERANGE, got %d\n", i, ret);
315c2c66affSColin Finck         ok(errno == ERANGE, "[%d] Expected errno to be ERANGE, got %d\n", i, errno);
316c2c66affSColin Finck         ok(!memcmp(p->expected, buffer, p->expected_length), "unexpected output for case %d\n", i);
317c2c66affSColin Finck 
318c2c66affSColin Finck         /* Unicode */
319c2c66affSColin Finck         if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH);
320c2c66affSColin Finck         if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH);
321c2c66affSColin Finck         if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH);
322c2c66affSColin Finck         if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH);
323c2c66affSColin Finck 
324c2c66affSColin Finck         memset(buffer, 0, MAX_PATH);
325c2c66affSColin Finck         for (n = 0; n < MAX_PATH; ++n)
326c2c66affSColin Finck             bufferW[n] = 'X';
327c2c66affSColin Finck         if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
328c2c66affSColin Finck 
329c2c66affSColin Finck         errno = EBADF;
330c2c66affSColin Finck         ret = p_wmakepath_s(bufferW, p->length,
331c2c66affSColin Finck                             p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL,
332c2c66affSColin Finck                             p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL,
333c2c66affSColin Finck                             p->file == USE_BUFF? bufferW : p->file ? fileW : NULL,
334c2c66affSColin Finck                             p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL);
335c2c66affSColin Finck         ok(ret == ERANGE, "[%d] Expected _wmakepath_s to return ERANGE, got %d\n", i, ret);
336c2c66affSColin Finck         ok(errno == ERANGE, "[%d] Expected errno to be ERANGE, got %d\n", i, errno);
337c2c66affSColin Finck 
338c2c66affSColin Finck         ok(!memcmp(p->expected_unicode, bufferW, p->expected_length * sizeof(WCHAR)), "unexpected output for case %d\n", i);
339c2c66affSColin Finck     }
340c2c66affSColin Finck }
341c2c66affSColin Finck 
test_fullpath(void)342c2c66affSColin Finck static void test_fullpath(void)
343c2c66affSColin Finck {
344c2c66affSColin Finck     char full[MAX_PATH];
345c2c66affSColin Finck     char tmppath[MAX_PATH];
346c2c66affSColin Finck     char prevpath[MAX_PATH];
347c2c66affSColin Finck     char level1[MAX_PATH];
348c2c66affSColin Finck     char level2[MAX_PATH];
349c2c66affSColin Finck     char teststring[MAX_PATH];
350c2c66affSColin Finck     char *freeme;
351c2c66affSColin Finck     BOOL rc,free1,free2;
352c2c66affSColin Finck 
353c2c66affSColin Finck     free1=free2=TRUE;
354c2c66affSColin Finck     GetCurrentDirectoryA(MAX_PATH, prevpath);
355c2c66affSColin Finck     GetTempPathA(MAX_PATH,tmppath);
356c2c66affSColin Finck     strcpy(level1,tmppath);
357c2c66affSColin Finck     strcat(level1,"msvcrt-test\\");
358c2c66affSColin Finck 
359c2c66affSColin Finck     rc = CreateDirectoryA(level1,NULL);
360c2c66affSColin Finck     if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
361c2c66affSColin Finck         free1=FALSE;
362c2c66affSColin Finck 
363c2c66affSColin Finck     strcpy(level2,level1);
364c2c66affSColin Finck     strcat(level2,"nextlevel\\");
365c2c66affSColin Finck     rc = CreateDirectoryA(level2,NULL);
366c2c66affSColin Finck     if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
367c2c66affSColin Finck         free2=FALSE;
368c2c66affSColin Finck     SetCurrentDirectoryA(level2);
369c2c66affSColin Finck 
370c2c66affSColin Finck     ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n");
371c2c66affSColin Finck     strcpy(teststring,level2);
372c2c66affSColin Finck     strcat(teststring,"test");
373c2c66affSColin Finck     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
374c2c66affSColin Finck     ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
375c2c66affSColin Finck     memcpy(teststring,level2,3);
376c2c66affSColin Finck     teststring[3]=0;
377c2c66affSColin Finck     strcat(teststring,"test");
378c2c66affSColin Finck     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
379c2c66affSColin Finck     ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
380c2c66affSColin Finck     strcpy(teststring,level1);
381c2c66affSColin Finck     strcat(teststring,"test");
382c2c66affSColin Finck     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
383c2c66affSColin Finck     ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n");
384c2c66affSColin Finck 
385c2c66affSColin Finck     freeme = _fullpath(NULL,"test", 0);
386c2c66affSColin Finck     ok(freeme!=NULL,"No path returned\n");
387c2c66affSColin Finck     strcpy(teststring,level2);
388c2c66affSColin Finck     strcat(teststring,"test");
389c2c66affSColin Finck     ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme);
390c2c66affSColin Finck     free(freeme);
391c2c66affSColin Finck 
392c2c66affSColin Finck     SetCurrentDirectoryA(prevpath);
393c2c66affSColin Finck     if (free2)
394c2c66affSColin Finck         RemoveDirectoryA(level2);
395c2c66affSColin Finck     if (free1)
396c2c66affSColin Finck         RemoveDirectoryA(level1);
397c2c66affSColin Finck }
398c2c66affSColin Finck 
test_splitpath(void)399c2c66affSColin Finck static void test_splitpath(void)
400c2c66affSColin Finck {
401c2c66affSColin Finck     const char* path = "c:\\\x83\x5c\x83\x74\x83\x67.bin";
402c2c66affSColin Finck     char drive[3], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH];
403c2c66affSColin Finck     int prev_cp = _getmbcp();
404c2c66affSColin Finck 
405c2c66affSColin Finck     /* SBCS codepage */
406c2c66affSColin Finck     _setmbcp(1252);
407c2c66affSColin Finck     _splitpath(path, drive, dir, fname, ext);
408c2c66affSColin Finck     ok(!strcmp(drive, "c:"), "got %s\n", drive);
409c2c66affSColin Finck     ok(!strcmp(dir, "\\\x83\x5c"), "got %s\n", dir);
410c2c66affSColin Finck     ok(!strcmp(fname, "\x83\x74\x83\x67"), "got %s\n", fname);
411c2c66affSColin Finck     ok(!strcmp(ext, ".bin"), "got %s\n", ext);
412c2c66affSColin Finck 
413c2c66affSColin Finck     /* MBCS (Japanese) codepage */
414c2c66affSColin Finck     _setmbcp(932);
415c2c66affSColin Finck     _splitpath(path, drive, dir, fname, ext);
416c2c66affSColin Finck     ok(!strcmp(drive, "c:"), "got %s\n", drive);
417c2c66affSColin Finck     ok(!strcmp(dir, "\\"), "got %s\n", dir);
418c2c66affSColin Finck     ok(!strcmp(fname, "\x83\x5c\x83\x74\x83\x67"), "got %s\n", fname);
419c2c66affSColin Finck     ok(!strcmp(ext, ".bin"), "got %s\n", ext);
420c2c66affSColin Finck 
421c2c66affSColin Finck     _setmbcp(prev_cp);
422c2c66affSColin Finck }
423c2c66affSColin Finck 
test_searchenv(void)4241c9ac7a2SAmine Khaldi static void test_searchenv(void)
4251c9ac7a2SAmine Khaldi {
4261c9ac7a2SAmine Khaldi     const char *dirs[] = {
4271c9ac7a2SAmine Khaldi         "\\search_env_test",
4281c9ac7a2SAmine Khaldi         "\\search_env_test\\dir1",
4291c9ac7a2SAmine Khaldi         "\\search_env_test\\dir2",
4301c9ac7a2SAmine Khaldi         "\\search_env_test\\dir3longer"
4311c9ac7a2SAmine Khaldi     };
4321c9ac7a2SAmine Khaldi 
4331c9ac7a2SAmine Khaldi     const char *files[] = {
4341c9ac7a2SAmine Khaldi         "\\search_env_test\\dir1\\1.dat",
4351c9ac7a2SAmine Khaldi         "\\search_env_test\\dir1\\2.dat",
4361c9ac7a2SAmine Khaldi         "\\search_env_test\\dir2\\1.dat",
4371c9ac7a2SAmine Khaldi         "\\search_env_test\\dir2\\3.dat",
4381c9ac7a2SAmine Khaldi         "\\search_env_test\\dir3longer\\3.dat"
4391c9ac7a2SAmine Khaldi     };
4401c9ac7a2SAmine Khaldi 
4411c9ac7a2SAmine Khaldi     const WCHAR env_w[] = {'T','E','S','T','_','P','A','T','H',0};
4421c9ac7a2SAmine Khaldi     const WCHAR dat1_w[] = {'1','.','d','a','t',0};
4431c9ac7a2SAmine Khaldi     const WCHAR dat3_w[] = {'3','.','d','a','t',0};
4441c9ac7a2SAmine Khaldi 
4451c9ac7a2SAmine Khaldi     char env1[4*MAX_PATH], env2[4*MAX_PATH], tmppath[MAX_PATH], path[2*MAX_PATH];
4461c9ac7a2SAmine Khaldi     char result[MAX_PATH], exp[2*MAX_PATH];
4471c9ac7a2SAmine Khaldi     WCHAR result_w[MAX_PATH];
4481c9ac7a2SAmine Khaldi     int i, path_len;
4491c9ac7a2SAmine Khaldi     FILE *tmp_file;
4501c9ac7a2SAmine Khaldi 
4511c9ac7a2SAmine Khaldi     if (getenv("TEST_PATH")) {
4521c9ac7a2SAmine Khaldi         skip("TEST_PATH environment variable already set\n");
4531c9ac7a2SAmine Khaldi         return;
4541c9ac7a2SAmine Khaldi     }
4551c9ac7a2SAmine Khaldi 
4561c9ac7a2SAmine Khaldi     path_len = GetTempPathA(MAX_PATH, tmppath);
4571c9ac7a2SAmine Khaldi     ok(path_len, "GetTempPath failed\n");
4581c9ac7a2SAmine Khaldi     memcpy(path, tmppath, path_len);
4591c9ac7a2SAmine Khaldi 
460*f446a50fSAmine Khaldi     for (i=0; i<ARRAY_SIZE(dirs); i++) {
4611c9ac7a2SAmine Khaldi         strcpy(path+path_len, dirs[i]);
4621c9ac7a2SAmine Khaldi 	ok(!mkdir(path), "mkdir failed (dir = %s)\n", path);
4631c9ac7a2SAmine Khaldi     }
4641c9ac7a2SAmine Khaldi 
465*f446a50fSAmine Khaldi     for (i=0; i<ARRAY_SIZE(files); i++) {
4661c9ac7a2SAmine Khaldi         strcpy(path+path_len, files[i]);
4671c9ac7a2SAmine Khaldi         tmp_file = fopen(path, "wb");
4681c9ac7a2SAmine Khaldi 	ok(tmp_file != NULL, "fopen failed (file = %s)\n", path);
4691c9ac7a2SAmine Khaldi         fclose(tmp_file);
4701c9ac7a2SAmine Khaldi     }
4711c9ac7a2SAmine Khaldi 
4721c9ac7a2SAmine Khaldi     strcpy(env1, "TEST_PATH=");
4731c9ac7a2SAmine Khaldi     strcpy(env2, "TEST_PATH=;");
474*f446a50fSAmine Khaldi     for (i=1; i<ARRAY_SIZE(dirs); i++) {
4751c9ac7a2SAmine Khaldi         strcat(env1, tmppath);
4761c9ac7a2SAmine Khaldi         strcat(env1, dirs[i]);
4771c9ac7a2SAmine Khaldi         strcat(env1, ";");
4781c9ac7a2SAmine Khaldi 
4791c9ac7a2SAmine Khaldi         strcat(env2, tmppath);
4801c9ac7a2SAmine Khaldi         strcat(env2, dirs[i]);
4811c9ac7a2SAmine Khaldi         strcat(env2, ";;");
4821c9ac7a2SAmine Khaldi     }
4831c9ac7a2SAmine Khaldi 
4841c9ac7a2SAmine Khaldi     if (!p_searchenv_s || !p_wsearchenv_s)
4851c9ac7a2SAmine Khaldi         win_skip("searchenv_s or wsearchenv_s function is not available\n");
4861c9ac7a2SAmine Khaldi 
4871c9ac7a2SAmine Khaldi     putenv(env1);
4881c9ac7a2SAmine Khaldi     memset(result, 'x', sizeof(result));
4891c9ac7a2SAmine Khaldi     _searchenv("fail", "TEST_PATH", result);
4901c9ac7a2SAmine Khaldi     ok(!result[0], "got %s, expected ''\n", result);
4911c9ac7a2SAmine Khaldi 
4921c9ac7a2SAmine Khaldi     if (p_searchenv_s) {
4931c9ac7a2SAmine Khaldi         memset(result, 'x', sizeof(result));
4941c9ac7a2SAmine Khaldi         i = p_searchenv_s("fail", "TEST_PATH", result, MAX_PATH);
4951c9ac7a2SAmine Khaldi         ok(i == ENOENT, "searchenv_s returned %d\n", i);
4961c9ac7a2SAmine Khaldi         ok(!result[0], "got %s, expected ''\n", result);
4971c9ac7a2SAmine Khaldi     }
4981c9ac7a2SAmine Khaldi 
4991c9ac7a2SAmine Khaldi     memset(result, 'x', sizeof(result));
5001c9ac7a2SAmine Khaldi     strcpy(exp, tmppath);
5011c9ac7a2SAmine Khaldi     strcat(exp, files[0]);
5021c9ac7a2SAmine Khaldi     _searchenv("1.dat", "TEST_PATH", result);
5031c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5041c9ac7a2SAmine Khaldi 
5051c9ac7a2SAmine Khaldi     if (p_searchenv_s) {
5061c9ac7a2SAmine Khaldi         memset(result, 'x', sizeof(result));
5071c9ac7a2SAmine Khaldi         i = p_searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
5081c9ac7a2SAmine Khaldi         ok(!i, "searchenv_s returned %d\n", i);
5091c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5101c9ac7a2SAmine Khaldi     }
5111c9ac7a2SAmine Khaldi 
5121c9ac7a2SAmine Khaldi     memset(result_w, 'x', sizeof(result_w));
5131c9ac7a2SAmine Khaldi     _wsearchenv(dat1_w, env_w, result_w);
5141c9ac7a2SAmine Khaldi     WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL);
5151c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5161c9ac7a2SAmine Khaldi 
5171c9ac7a2SAmine Khaldi     if (p_wsearchenv_s) {
5181c9ac7a2SAmine Khaldi         memset(result_w, 'x', sizeof(result_w));
5191c9ac7a2SAmine Khaldi         i = p_wsearchenv_s(dat1_w, env_w, result_w, MAX_PATH);
5201c9ac7a2SAmine Khaldi         ok(!i, "wsearchenv_s returned %d\n", i);
5211c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5221c9ac7a2SAmine Khaldi     }
5231c9ac7a2SAmine Khaldi 
5241c9ac7a2SAmine Khaldi     memset(result, 'x', sizeof(result));
5251c9ac7a2SAmine Khaldi     strcpy(exp, tmppath);
5261c9ac7a2SAmine Khaldi     strcat(exp, files[3]);
5271c9ac7a2SAmine Khaldi     _searchenv("3.dat", "TEST_PATH", result);
5281c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5291c9ac7a2SAmine Khaldi 
5301c9ac7a2SAmine Khaldi     if (p_searchenv_s) {
5311c9ac7a2SAmine Khaldi         memset(result, 'x', sizeof(result));
5321c9ac7a2SAmine Khaldi         i = p_searchenv_s("3.dat", "TEST_PATH", result, MAX_PATH);
5331c9ac7a2SAmine Khaldi         ok(!i, "searchenv_s returned %d\n", i);
5341c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5351c9ac7a2SAmine Khaldi     }
5361c9ac7a2SAmine Khaldi 
5371c9ac7a2SAmine Khaldi     memset(result_w, 'x', sizeof(result_w));
5381c9ac7a2SAmine Khaldi     _wsearchenv(dat3_w, env_w, result_w);
5391c9ac7a2SAmine Khaldi     WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL);
5401c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5411c9ac7a2SAmine Khaldi 
5421c9ac7a2SAmine Khaldi     if (p_wsearchenv_s) {
5431c9ac7a2SAmine Khaldi         memset(result_w, 'x', sizeof(result_w));
5441c9ac7a2SAmine Khaldi         i = p_wsearchenv_s(dat3_w, env_w, result_w, MAX_PATH);
5451c9ac7a2SAmine Khaldi         ok(!i, "wsearchenv_s returned %d\n", i);
5461c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5471c9ac7a2SAmine Khaldi     }
5481c9ac7a2SAmine Khaldi 
5491c9ac7a2SAmine Khaldi     putenv(env2);
5501c9ac7a2SAmine Khaldi     memset(result, 'x', sizeof(result));
5511c9ac7a2SAmine Khaldi     strcpy(exp, tmppath);
5521c9ac7a2SAmine Khaldi     strcat(exp, files[0]);
5531c9ac7a2SAmine Khaldi     _searchenv("1.dat", "TEST_PATH", result);
5541c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5551c9ac7a2SAmine Khaldi 
5561c9ac7a2SAmine Khaldi     if (p_searchenv_s) {
5571c9ac7a2SAmine Khaldi         memset(result, 'x', sizeof(result));
5581c9ac7a2SAmine Khaldi         i = p_searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH);
5591c9ac7a2SAmine Khaldi         ok(!i, "searchenv_s returned %d\n", i);
5601c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5611c9ac7a2SAmine Khaldi     }
5621c9ac7a2SAmine Khaldi 
5631c9ac7a2SAmine Khaldi     memset(result_w, 'x', sizeof(result_w));
5641c9ac7a2SAmine Khaldi     _wsearchenv(dat1_w, env_w, result_w);
5651c9ac7a2SAmine Khaldi     WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL);
5661c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5671c9ac7a2SAmine Khaldi 
5681c9ac7a2SAmine Khaldi     if (p_wsearchenv_s) {
5691c9ac7a2SAmine Khaldi         memset(result_w, 'x', sizeof(result_w));
5701c9ac7a2SAmine Khaldi         i = p_wsearchenv_s(dat1_w, env_w, result_w, MAX_PATH);
5711c9ac7a2SAmine Khaldi         ok(!i, "wsearchenv_s returned %d\n", i);
5721c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5731c9ac7a2SAmine Khaldi     }
5741c9ac7a2SAmine Khaldi 
5751c9ac7a2SAmine Khaldi     memset(result, 'x', sizeof(result));
5761c9ac7a2SAmine Khaldi     strcpy(exp, tmppath);
5771c9ac7a2SAmine Khaldi     strcat(exp, files[3]);
5781c9ac7a2SAmine Khaldi     _searchenv("3.dat", "TEST_PATH", result);
5791c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5801c9ac7a2SAmine Khaldi 
5811c9ac7a2SAmine Khaldi     if (p_searchenv_s) {
5821c9ac7a2SAmine Khaldi         memset(result, 'x', sizeof(result));
5831c9ac7a2SAmine Khaldi         i = p_searchenv_s("3.dat", "TEST_PATH", result, MAX_PATH);
5841c9ac7a2SAmine Khaldi         ok(!i, "searchenv_s returned %d\n", i);
5851c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5861c9ac7a2SAmine Khaldi     }
5871c9ac7a2SAmine Khaldi 
5881c9ac7a2SAmine Khaldi     memset(result_w, 'x', sizeof(result_w));
5891c9ac7a2SAmine Khaldi     _wsearchenv(dat3_w, env_w, result_w);
5901c9ac7a2SAmine Khaldi     WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL);
5911c9ac7a2SAmine Khaldi     ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5921c9ac7a2SAmine Khaldi 
5931c9ac7a2SAmine Khaldi     if (p_wsearchenv_s) {
5941c9ac7a2SAmine Khaldi         memset(result_w, 'x', sizeof(result_w));
5951c9ac7a2SAmine Khaldi         i = p_wsearchenv_s(dat3_w, env_w, result_w, MAX_PATH);
5961c9ac7a2SAmine Khaldi         ok(!i, "wsearchenv_s returned %d\n", i);
5971c9ac7a2SAmine Khaldi         ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp);
5981c9ac7a2SAmine Khaldi     }
5991c9ac7a2SAmine Khaldi 
6001c9ac7a2SAmine Khaldi     putenv("TEST_PATH=");
6011c9ac7a2SAmine Khaldi 
602*f446a50fSAmine Khaldi     for (i=ARRAY_SIZE(files)-1; i>=0; i--) {
6031c9ac7a2SAmine Khaldi         strcpy(path+path_len, files[i]);
6041c9ac7a2SAmine Khaldi         ok(!remove(path), "remove failed (file = %s)\n", path);
6051c9ac7a2SAmine Khaldi     }
6061c9ac7a2SAmine Khaldi 
607*f446a50fSAmine Khaldi     for (i=ARRAY_SIZE(dirs)-1; i>=0; i--) {
6081c9ac7a2SAmine Khaldi         strcpy(path+path_len, dirs[i]);
6091c9ac7a2SAmine Khaldi         ok(!rmdir(path), "rmdir failed (dir = %s)\n", path);
6101c9ac7a2SAmine Khaldi     }
6111c9ac7a2SAmine Khaldi }
6121c9ac7a2SAmine Khaldi 
START_TEST(dir)613c2c66affSColin Finck START_TEST(dir)
614c2c66affSColin Finck {
615c2c66affSColin Finck     init();
616c2c66affSColin Finck 
617c2c66affSColin Finck     test_fullpath();
618c2c66affSColin Finck     test_makepath();
619c2c66affSColin Finck     test_makepath_s();
620c2c66affSColin Finck     test_splitpath();
6211c9ac7a2SAmine Khaldi     test_searchenv();
622c2c66affSColin Finck }
623