ReactOS 0.4.16-dev-927-g467dec4
dir.c File Reference
#include "wine/test.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <direct.h>
#include <sys/stat.h>
#include <io.h>
#include <mbctype.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <process.h>
#include <errno.h>
Include dependency graph for dir.c:

Go to the source code of this file.

Classes

struct  makepath_case
 
struct  makepath_s_case
 

Macros

#define USE_BUFF   ((char*)~0ul)
 

Functions

static int (__cdecl *p_makepath_s)(char *
 
static void init (void)
 
static void test_makepath (void)
 
static void test_makepath_s (void)
 
static void test_fullpath (void)
 
static void test_splitpath (void)
 
static void test_searchenv (void)
 
 START_TEST (dir)
 

Variables

static size_t
 
static const makepath_case makepath_cases []
 
static const makepath_s_case makepath_s_cases []
 

Macro Definition Documentation

◆ USE_BUFF

#define USE_BUFF   ((char*)~0ul)

Definition at line 61 of file dir.c.

Function Documentation

◆ init()

static void init ( void  )
static

Definition at line 41 of file dir.c.

42{
43 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
44
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");
49}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143

Referenced by START_TEST().

◆ int()

static int ( __cdecl p_makepath_s)
static

◆ START_TEST()

START_TEST ( dir  )

Definition at line 593 of file dir.c.

594{
595 init();
596
602}
static void test_fullpath(void)
Definition: dir.c:312
static void init(void)
Definition: dir.c:41
static void test_makepath(void)
Definition: dir.c:89
static void test_searchenv(void)
Definition: dir.c:394
static void test_splitpath(void)
Definition: dir.c:369
static void test_makepath_s(void)
Definition: dir.c:188

◆ test_fullpath()

static void test_fullpath ( void  )
static

Definition at line 312 of file dir.c.

313{
314 char full[MAX_PATH];
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];
320 char *freeme;
321 BOOL rc,free1,free2;
322
323 free1=free2=TRUE;
325 GetTempPathA(MAX_PATH,tmppath);
326 strcpy(level1,tmppath);
327 strcat(level1,"msvcrt-test\\");
328
329 rc = CreateDirectoryA(level1,NULL);
331 free1=FALSE;
332
333 strcpy(level2,level1);
334 strcat(level2,"nextlevel\\");
335 rc = CreateDirectoryA(level2,NULL);
337 free2=FALSE;
338 SetCurrentDirectoryA(level2);
339
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);
346 teststring[3]=0;
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");
354
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);
360 free(freeme);
361
362 SetCurrentDirectoryA(prevpath);
363 if (free2)
364 RemoveDirectoryA(level2);
365 if (free1)
366 RemoveDirectoryA(level1);
367}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2206
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP char *__cdecl _fullpath(_Out_writes_opt_z_(_SizeInBytes) char *_FullPath, _In_z_ const char *_Path, _In_ size_t _SizeInBytes)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
strcat
Definition: string.h:92
strcpy
Definition: string.h:131
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ test_makepath()

static void test_makepath ( void  )
static

Definition at line 89 of file dir.c.

90{
91 WCHAR driveW[MAX_PATH];
92 WCHAR dirW[MAX_PATH];
94 WCHAR extW[MAX_PATH];
95 WCHAR bufferW[MAX_PATH];
96 char buffer[MAX_PATH];
97
98 unsigned int i, n;
99
100 for (i = 0; i < ARRAY_SIZE(makepath_cases); ++i)
101 {
102 const makepath_case* p = &makepath_cases[i];
103
104 memset(buffer, 'X', MAX_PATH);
105 if (p->buffer)
106 strcpy(buffer, p->buffer);
107
108 /* Ascii */
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);
114
115 buffer[MAX_PATH - 1] = '\0';
116 ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
117
118 /* Unicode */
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);
123
125 for (n = 0; n < MAX_PATH; ++n)
126 bufferW[n] = 'X';
127 if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
128
129 _wmakepath(bufferW,
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);
134
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);
138 }
139}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
static const WCHAR fileW[]
Definition: url.c:111
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP void __cdecl _wmakepath(_Pre_notnull_ _Post_z_ wchar_t *_ResultPath, _In_opt_z_ const wchar_t *_Drive, _In_opt_z_ const wchar_t *_Dir, _In_opt_z_ const wchar_t *_Filename, _In_opt_z_ const wchar_t *_Ext)
_makepath
Definition: stdlib.h:1096
static const makepath_case makepath_cases[]
Definition: dir.c:62
#define USE_BUFF
Definition: dir.c:61
#define memset(x, y, z)
Definition: compat.h:39
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_makepath_s()

static void test_makepath_s ( void  )
static

Definition at line 188 of file dir.c.

189{
190 WCHAR driveW[MAX_PATH];
191 WCHAR dirW[MAX_PATH];
193 WCHAR extW[MAX_PATH];
194 WCHAR bufferW[MAX_PATH];
195 char buffer[MAX_PATH];
196 int ret;
197 unsigned int i, n;
198
199 if (!p_makepath_s || !p_wmakepath_s)
200 {
201 win_skip("Safe makepath functions are not available\n");
202 return;
203 }
204
205 errno = EBADF;
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);
209
210 errno = EBADF;
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);
214
215 errno = EBADF;
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);
219
220 errno = EBADF;
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);
224
225 /* Test with the normal _makepath cases. */
226 for (i = 0; i < ARRAY_SIZE(makepath_cases); i++)
227 {
228 const makepath_case *p = makepath_cases + i;
229
230 memset(buffer, 'X', MAX_PATH);
231 if (p->buffer)
232 strcpy(buffer, p->buffer);
233
234 /* Ascii */
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);
241
242 buffer[MAX_PATH - 1] = '\0';
243 ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
244
245 /* Unicode */
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);
250
252 for (n = 0; n < MAX_PATH; ++n)
253 bufferW[n] = 'X';
254 if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
255
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);
262
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);
266 }
267
268 /* Try insufficient length cases. */
269 for (i = 0; i < ARRAY_SIZE(makepath_s_cases); i++)
270 {
272
273 memset(buffer, 'X', MAX_PATH);
274 if (p->buffer)
275 strcpy(buffer, p->buffer);
276
277 /* Ascii */
278 errno = EBADF;
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);
287
288 /* Unicode */
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);
293
295 for (n = 0; n < MAX_PATH; ++n)
296 bufferW[n] = 'X';
297 if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
298
299 errno = EBADF;
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);
307
308 ok(!memcmp(p->expected_unicode, bufferW, p->expected_length * sizeof(WCHAR)), "unexpected output for case %d\n", i);
309 }
310}
#define EINVAL
Definition: acclib.h:90
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERANGE
Definition: acclib.h:92
#define EBADF
Definition: acclib.h:82
static const makepath_s_case makepath_s_cases[]
Definition: dir.c:154
#define errno
Definition: errno.h:18
#define win_skip
Definition: test.h:164
int ret

Referenced by START_TEST().

◆ test_searchenv()

static void test_searchenv ( void  )
static

Definition at line 394 of file dir.c.

395{
396 const char *dirs[] = {
397 "\\search_env_test",
398 "\\search_env_test\\dir1",
399 "\\search_env_test\\dir2",
400 "\\search_env_test\\dir3longer"
401 };
402
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"
409 };
410
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];
414 int i, path_len;
415 FILE *tmp_file;
416
417 if (getenv("TEST_PATH")) {
418 skip("TEST_PATH environment variable already set\n");
419 return;
420 }
421
422 path_len = GetTempPathA(MAX_PATH, tmppath);
423 ok(path_len, "GetTempPath failed\n");
424 memcpy(path, tmppath, path_len);
425
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);
429 }
430
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);
435 fclose(tmp_file);
436 }
437
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]);
443 strcat(env1, ";");
444
445 strcat(env2, tmppath);
446 strcat(env2, dirs[i]);
447 strcat(env2, ";;");
448 }
449
450 if (!p_searchenv_s || !p_wsearchenv_s)
451 win_skip("searchenv_s or wsearchenv_s function is not available\n");
452
453 putenv(env1);
454 memset(result, 'x', sizeof(result));
455 _searchenv("fail", "TEST_PATH", result);
456 ok(!result[0], "got %s, expected ''\n", result);
457
458 if (p_searchenv_s) {
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);
463 }
464
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);
470
471 if (p_searchenv_s) {
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);
476 }
477
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);
482
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);
488 }
489
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);
495
496 if (p_searchenv_s) {
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);
501 }
502
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);
507
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);
513 }
514
515 putenv(env2);
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);
521
522 if (p_searchenv_s) {
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);
527 }
528
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);
533
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);
539 }
540
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);
546
547 if (p_searchenv_s) {
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);
552 }
553
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);
558
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);
564 }
565
566 strcpy(env1, "TEST_PATH=");
567 strcat(env1, tmppath);
568 strcat(env1, "\"\\search_env_test\\\"d\"i\"r\"1");
569 putenv(env1);
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);
574
575 strcat(env1, ";");
576 putenv(env1);
577 _searchenv("1.dat", "TEST_PATH", result);
578 ok(!result[0], "got %s, expected ''\n", result);
579
580 putenv("TEST_PATH=");
581
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);
585 }
586
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);
590 }
591}
#define ENOENT
Definition: acclib.h:79
#define mkdir
Definition: acwin.h:101
#define skip(...)
Definition: atltest.h:64
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl putenv(_In_z_ const char *_EnvString)
_CRTIMP void __cdecl _wsearchenv(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_EnvVar, _Pre_notnull_ _Post_z_ wchar_t *_ResultPath)
_CRTIMP void __cdecl _searchenv(_In_z_ const char *_Filename, _In_z_ const char *_EnvVar, _Pre_notnull_ _Post_z_ char *_ResultPath)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
static DWORD path_len
Definition: batch.c:31
DWORD exp
Definition: msg.c:16058
int remove
Definition: msacm.c:1366
#define rmdir
Definition: syshdrs.h:70
#define L(x)
Definition: ntvdm.h:50

Referenced by START_TEST().

◆ test_splitpath()

static void test_splitpath ( void  )
static

Definition at line 369 of file dir.c.

370{
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();
374
375 /* SBCS codepage */
376 _setmbcp(1252);
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);
382
383 /* MBCS (Japanese) codepage */
384 _setmbcp(932);
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);
390
391 _setmbcp(prev_cp);
392}
unsigned int dir
Definition: maze.c:112
_CRTIMP int __cdecl _getmbcp(void)
Definition: locale.c:1474
static const WCHAR *const ext[]
Definition: module.c:53
_CRTIMP void __cdecl _splitpath(_In_z_ const char *_FullPath, _Pre_maybenull_ _Post_z_ char *_Drive, _Pre_maybenull_ _Post_z_ char *_Dir, _Pre_maybenull_ _Post_z_ char *_Filename, _Pre_maybenull_ _Post_z_ char *_Ext)
int __cdecl _setmbcp(int)
Definition: _setmbcp.c:218

Referenced by START_TEST().

Variable Documentation

◆ makepath_cases

const makepath_case makepath_cases[]
static
Initial value:
=
{
{ NULL, NULL, NULL, NULL, NULL, "" },
{ NULL, "c", NULL, NULL, NULL, "c:" },
{ NULL, "c:", NULL, NULL, NULL, "c:" },
{ NULL, "c:\\", NULL, NULL, NULL, "c:" },
{ NULL, NULL, "dir", NULL, NULL, "dir\\" },
{ NULL, NULL, "dir\\", NULL, NULL, "dir\\" },
{ NULL, NULL, "\\dir", NULL, NULL, "\\dir\\" },
{ NULL, NULL, NULL, "file", NULL, "file" },
{ NULL, NULL, NULL, "\\file", NULL, "\\file" },
{ NULL, NULL, NULL, "file", NULL, "file" },
{ NULL, NULL, NULL, NULL, "ext", ".ext" },
{ NULL, NULL, NULL, NULL, ".ext", ".ext" },
{ "foo", NULL, NULL, NULL, NULL, "" },
{ "foo", USE_BUFF, NULL, NULL, NULL, "f:" },
{ "foo", NULL, USE_BUFF, NULL, NULL, "foo\\" },
{ "foo", NULL, NULL, USE_BUFF, NULL, "foo" },
{ "foo", NULL, USE_BUFF, "file", NULL, "foo\\file" },
{ "foo", NULL, USE_BUFF, "file", "ext", "foo\\file.ext" },
{ "foo", NULL, NULL, USE_BUFF, "ext", "foo.ext" },
{ NULL, "c", "dir", "file", "ext", "c:dir\\file.ext" },
{ NULL, "c:", "dir", "file", "ext", "c:dir\\file.ext" },
{ NULL, "c:\\", "dir", "file", "ext", "c:dir\\file.ext" }
}

Definition at line 62 of file dir.c.

Referenced by test_makepath(), and test_makepath_s().

◆ makepath_s_cases

const makepath_s_case makepath_s_cases[]
static

Definition at line 154 of file dir.c.

Referenced by test_makepath_s().

◆ size_t

Definition at line 36 of file dir.c.