msvcrt/tests: Fix 4 tests that always fail on Vista.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static void test_makepath(void)
35 {
36     char buffer[MAX_PATH];
37
38     _makepath(buffer, "C", "\\foo", "dummy", "txt");
39     ok( strcmp(buffer, "C:\\foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
40     _makepath(buffer, "C:", "\\foo\\", "dummy", ".txt");
41     ok( strcmp(buffer, "C:\\foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
42
43     /* this works with native and e.g. Freelancer depends on it */
44     strcpy(buffer, "foo");
45     _makepath(buffer, NULL, buffer, "dummy.txt", NULL);
46     ok( strcmp(buffer, "foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
47 }
48
49 static void test_fullpath(void)
50 {
51     char full[MAX_PATH];
52     char tmppath[MAX_PATH];
53     char prevpath[MAX_PATH];
54     char level1[MAX_PATH];
55     char level2[MAX_PATH];
56     char teststring[MAX_PATH];
57     char *freeme;
58     BOOL rc,free1,free2;
59
60     free1=free2=TRUE;
61     GetCurrentDirectory(MAX_PATH, prevpath);
62     GetTempPath(MAX_PATH,tmppath);
63     strcpy(level1,tmppath);
64     strcat(level1,"msvcrt-test\\");
65
66     rc = CreateDirectory(level1,NULL);
67     if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
68         free1=FALSE;
69
70     strcpy(level2,level1);
71     strcat(level2,"nextlevel\\");
72     rc = CreateDirectory(level2,NULL);
73     if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
74         free2=FALSE;
75     SetCurrentDirectory(level2);
76
77     ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n");
78     strcpy(teststring,level2);
79     strcat(teststring,"test");
80     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
81     ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
82     strncpy(teststring,level2,3);
83     teststring[3]=0;
84     strcat(teststring,"test");
85     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
86     ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
87     strcpy(teststring,level1);
88     strcat(teststring,"test");
89     ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
90     ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n");
91
92     freeme = _fullpath(NULL,"test", 0);
93     ok(freeme!=NULL,"No path returned\n");
94     strcpy(teststring,level2);
95     strcat(teststring,"test");
96     ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme);
97     free(freeme);
98
99     SetCurrentDirectory(prevpath);
100     if (free2)
101         RemoveDirectory(level2);
102     if (free1)
103         RemoveDirectory(level1);
104 }
105
106 START_TEST(dir)
107 {
108     test_fullpath();
109     test_makepath();
110 }