msvcrt: Modify dir test to create its own directory to ensure the
[wine] / dlls / msvcrt / tests / dir.c
1 /*
2  * Unit test suite for dir functions
3  *
4  * Copyright 2006 CodeWeavers, Aric Stewart
5  *
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.
10  *
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.
15  *
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
19  */
20
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>
33
34 void test_fullpath()
35 {
36     char full[MAX_PATH];
37     char tmppath[MAX_PATH];
38     char level1[MAX_PATH];
39     char level2[MAX_PATH];
40     char teststring[MAX_PATH];
41     char *freeme;
42     BOOL rc,free1,free2;
43
44     free1=free2=TRUE;
45     GetTempPath(MAX_PATH,tmppath);
46     strcpy(level1,tmppath);
47     strcat(level1,"msvcrt-test\\");
48
49     rc = CreateDirectory(level1,NULL);
50     if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
51         free1=FALSE;
52
53     strcpy(level2,level1);
54     strcat(level2,"nextlevel\\");
55     rc = CreateDirectory(level2,NULL);
56     if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
57         free2=FALSE;
58     SetCurrentDirectory(level2);
59
60     ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n");
61     strcpy(teststring,level2);
62     strcat(teststring,"test");
63     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
64     ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
65     strncpy(teststring,level2,3);
66     teststring[3]=0;
67     strcat(teststring,"test");
68     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
69     ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
70     strcpy(teststring,level1);
71     strcat(teststring,"test");
72     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
73     ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n");
74
75     freeme = _fullpath(NULL,"test", 0);
76     ok(freeme!=NULL,"No path returned\n");
77     strcpy(teststring,level2);
78     strcat(teststring,"test");
79     ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme);
80     free(freeme);
81
82     if (free2)
83         RemoveDirectory(level2);
84     if (free1)
85         RemoveDirectory(level1);
86 }
87
88 START_TEST(dir)
89 {
90     test_fullpath();
91 }