2 * Copyright (C) 2005 Stefan Leichter
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
28 static void test_find_file(void)
32 char appdir
[MAX_PATH
];
33 char curdir
[MAX_PATH
];
34 char filename
[MAX_PATH
];
35 char outBuf
[MAX_PATH
];
36 char windir
[MAX_PATH
];
37 static const char empty
[] = "",
38 regedit
[] = "regedit",
39 regedit_exe
[] = "regedit.exe";
41 memset(appdir
, 0, MAX_PATH
);
42 memset(windir
, 0, MAX_PATH
);
46 memset(curdir
, 0, MAX_PATH
);
47 memset(outBuf
, 0, MAX_PATH
);
48 ret
= VerFindFileA(0, regedit
, empty
, empty
, curdir
, &dwCur
, outBuf
, &dwOut
);
51 ok(dwCur
== 1, "Wrong length of buffer for current location: "
52 "got %d(%s) expected 1\n", dwCur
, curdir
);
53 ok(dwOut
== 1, "Wrong length of buffer for the recommended installation location: "
54 "got %d(%s) expected 1\n", dwOut
, outBuf
);
56 case VFF_BUFFTOOSMALL
:
57 ok(dwCur
== MAX_PATH
, "Wrong length of buffer for current location: "
58 "got %d(%s) expected MAX_PATH\n", dwCur
, curdir
);
59 ok(dwOut
== MAX_PATH
, "Wrong length of buffer for the recommended installation location: "
60 "got %d(%s) expected MAX_PATH\n", dwOut
, outBuf
);
63 ok(0, "Got unexpected return value %x\n", ret
);
66 if(!GetWindowsDirectoryA(windir
, MAX_PATH
))
67 trace("GetWindowsDirectoryA failed\n");
69 sprintf(appdir
, "%s\\regedit.exe", windir
);
70 if(INVALID_FILE_ATTRIBUTES
== GetFileAttributesA(appdir
))
71 trace("GetFileAttributesA(%s) failed\n", appdir
);
75 memset(curdir
, 0, MAX_PATH
);
76 memset(outBuf
, 0, MAX_PATH
);
77 ret
= VerFindFileA(0, regedit_exe
, empty
, empty
, curdir
, &dwCur
, outBuf
, &dwOut
);
80 ok(dwCur
== 1 + strlen(windir
), "Wrong length of buffer for current location: "
81 "got %d(%s) expected %d\n", dwCur
, curdir
, lstrlenA(windir
)+1);
82 ok(dwOut
== 1, "Wrong length of buffer for the recommended installation location: "
83 "got %d(%s) expected 1\n", dwOut
, outBuf
);
85 case VFF_BUFFTOOSMALL
:
86 ok(dwCur
== MAX_PATH
, "Wrong length of buffer for current location: "
87 "got %d(%s) expected MAX_PATH\n", dwCur
, curdir
);
88 ok(dwOut
== MAX_PATH
, "Wrong length of buffer for the recommended installation location: "
89 "got %d(%s) expected MAX_PATH\n", dwOut
, outBuf
);
92 ok(0, "Got unexpected return value %x\n", ret
);
97 memset(curdir
, 0, MAX_PATH
);
98 memset(outBuf
, 0, MAX_PATH
);
99 ret
= VerFindFileA(0, regedit_exe
, NULL
, NULL
, curdir
, &dwCur
, outBuf
, &dwOut
);
102 ok(dwCur
== 1 + strlen(windir
), "Wrong length of buffer for current location: "
103 "got %d(%s) expected %d\n", dwCur
, curdir
, lstrlenA(windir
)+1);
104 ok(dwOut
== 1, "Wrong length of buffer for the recommended installation location: "
105 "got %d(%s) expected 1\n", dwOut
, outBuf
);
107 case VFF_BUFFTOOSMALL
:
108 ok(dwCur
== MAX_PATH
, "Wrong length of buffer for current location: "
109 "got %d(%s) expected MAX_PATH\n", dwCur
, curdir
);
110 ok(dwOut
== MAX_PATH
, "Wrong length of buffer for the recommended installation location: "
111 "got %d(%s) expected MAX_PATH\n", dwOut
, outBuf
);
114 ok(0, "Got unexpected return value %x\n", ret
);
118 if(!GetModuleFileNameA(NULL
, filename
, MAX_PATH
) ||
119 !GetSystemDirectoryA(windir
, MAX_PATH
) ||
120 !GetTempPathA(MAX_PATH
, appdir
))
121 trace("GetModuleFileNameA, GetSystemDirectoryA or GetTempPathA failed\n");
123 char *p
= strrchr(filename
, '\\');
126 SetCurrentDirectoryA(filename
);
127 memmove(filename
, p
, 1 + strlen(p
));
132 memset(outBuf
, 0, MAX_PATH
);
133 memset(curdir
, 0, MAX_PATH
);
134 ret
= VerFindFileA(0, filename
, NULL
, NULL
, curdir
, &dwCur
, outBuf
, &dwOut
);
137 ok(dwOut
== 1, "Wrong length of buffer for the recommended installation location"
138 "got %d(%s) expected 1\n", dwOut
, outBuf
);
140 case VFF_BUFFTOOSMALL
:
141 ok(dwOut
== MAX_PATH
, "Wrong length of buffer for the recommended installation location"
142 "got %d(%s) expected MAX_PATH\n", dwOut
, outBuf
);
145 todo_wine
ok(0, "Got unexpected return value %x\n", ret
);
150 memset(outBuf
, 0, MAX_PATH
);
151 memset(curdir
, 0, MAX_PATH
);
152 ret
= VerFindFileA(VFFF_ISSHAREDFILE
, filename
, NULL
, appdir
, curdir
, &dwCur
, outBuf
, &dwOut
);
153 todo_wine
ok(VFF_CURNEDEST
== ret
, "Wrong return value got %x expected VFF_CURNEDEST\n", ret
);
154 ok(dwOut
== 1 + strlen(windir
), "Wrong length of buffer for current location: "
155 "got %d(%s) expected %d\n", dwOut
, outBuf
, lstrlenA(windir
)+1);
159 memset(outBuf
, 0, MAX_PATH
);
160 memset(curdir
, 0, MAX_PATH
);
161 ret
= VerFindFileA(0, filename
, NULL
, appdir
, curdir
, &dwCur
, outBuf
, &dwOut
);
162 todo_wine
ok(VFF_CURNEDEST
== ret
, "Wrong return value got %x expected VFF_CURNEDEST\n", ret
);
163 ok(dwOut
== 1 + strlen(appdir
), "Wrong length of buffer for current location: "
164 "got %d(%s) expected %d\n", dwOut
, outBuf
, lstrlenA(appdir
)+1);
168 static void test_install_file(void)
170 CHAR tmpname
[MAX_PATH
];
171 UINT size
= MAX_PATH
;
173 static const CHAR szSrcFileName
[] = "nofile.txt";
174 static const CHAR szDestFileName
[] = "nofile2.txt";
175 static const CHAR szSrcDir
[] = "D:\\oes\\not\\exist";
176 static const CHAR szDestDir
[] = "D:\\oes\\not\\exist\\either";
177 static const CHAR szCurDir
[] = "C:\\";
179 /* testing Invalid Parameters */
180 memset(tmpname
,0,sizeof(tmpname
));
181 rc
= VerInstallFileA(0x0, NULL
, NULL
, NULL
, NULL
, NULL
, tmpname
, &size
);
182 ok (rc
== 0x10000 && tmpname
[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc
,tmpname
);
183 memset(tmpname
,0,sizeof(tmpname
));
185 rc
= VerInstallFileA(0x0, szSrcFileName
, NULL
, NULL
, NULL
, NULL
, tmpname
, &size
);
186 ok (rc
== 0x10000 && tmpname
[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc
,tmpname
);
187 memset(tmpname
,0,sizeof(tmpname
));
189 rc
= VerInstallFileA(0x0, szSrcFileName
, szDestFileName
, NULL
, NULL
, NULL
, tmpname
, &size
);
190 ok (rc
== 0x10000 && tmpname
[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc
,tmpname
);
191 memset(tmpname
,0,sizeof(tmpname
));
193 rc
= VerInstallFileA(0x0, szSrcFileName
, szDestFileName
, szSrcDir
, NULL
, NULL
, tmpname
, &size
);
194 ok (rc
== 0x10000 && tmpname
[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc
,tmpname
);
196 /* Source file does not exist*/
198 memset(tmpname
,0,sizeof(tmpname
));
200 rc
= VerInstallFileA(0x0, szSrcFileName
, szDestFileName
, szSrcDir
, szDestDir
, NULL
, tmpname
, &size
);
201 ok (rc
== 0x10000 && tmpname
[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc
,tmpname
);
202 memset(tmpname
,0,sizeof(tmpname
));
204 rc
= VerInstallFileA(0x0, szSrcFileName
, szDestFileName
, szSrcDir
, szDestDir
, szCurDir
, tmpname
, &size
);
205 ok (rc
== 0x10000 && tmpname
[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc
,tmpname
);