new 818051de2c8769029049ce3d36c6b856f47496c9
[wine/hacks.git] / dlls / msvcrt / tests / dir.c
blob009cbdb61fe4ffaf45eda5fbc9cef30cc32f5025
1 /*
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"
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <fcntl.h>
26 #include <sys/stat.h>
27 #include <io.h>
28 #include <windef.h>
29 #include <winbase.h>
30 #include <winnls.h>
31 #include <process.h>
32 #include <errno.h>
34 static void test_fullpath(void)
36 char full[MAX_PATH];
37 char tmppath[MAX_PATH];
38 char prevpath[MAX_PATH];
39 char level1[MAX_PATH];
40 char level2[MAX_PATH];
41 char teststring[MAX_PATH];
42 char *freeme;
43 BOOL rc,free1,free2;
45 free1=free2=TRUE;
46 GetCurrentDirectory(MAX_PATH, prevpath);
47 GetTempPath(MAX_PATH,tmppath);
48 strcpy(level1,tmppath);
49 strcat(level1,"msvcrt-test\\");
51 rc = CreateDirectory(level1,NULL);
52 if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
53 free1=FALSE;
55 strcpy(level2,level1);
56 strcat(level2,"nextlevel\\");
57 rc = CreateDirectory(level2,NULL);
58 if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
59 free2=FALSE;
60 SetCurrentDirectory(level2);
62 ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n");
63 strcpy(teststring,level2);
64 strcat(teststring,"test");
65 ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
66 ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
67 strncpy(teststring,level2,3);
68 teststring[3]=0;
69 strcat(teststring,"test");
70 ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
71 ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
72 strcpy(teststring,level1);
73 strcat(teststring,"test");
74 ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
75 ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n");
77 freeme = _fullpath(NULL,"test", 0);
78 ok(freeme!=NULL,"No path returned\n");
79 strcpy(teststring,level2);
80 strcat(teststring,"test");
81 ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme);
82 free(freeme);
84 SetCurrentDirectory(prevpath);
85 if (free2)
86 RemoveDirectory(level2);
87 if (free1)
88 RemoveDirectory(level1);
91 START_TEST(dir)
93 test_fullpath();