forked from wine-mirror/wine
/
install.c
212 lines (197 loc) · 8.89 KB
/
install.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Copyright (C) 2005 Stefan Leichter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <stdio.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winver.h"
static void test_find_file(void)
{
DWORD ret;
UINT dwCur, dwOut ;
char appdir[MAX_PATH];
char curdir[MAX_PATH];
char filename[MAX_PATH];
char outBuf[MAX_PATH];
char windir[MAX_PATH];
static const char empty[] = "",
regedit[] = "regedit",
regedit_exe[] = "regedit.exe";
memset(appdir, 0, MAX_PATH);
memset(windir, 0, MAX_PATH);
dwCur=MAX_PATH;
dwOut=MAX_PATH;
memset(curdir, 0, MAX_PATH);
memset(outBuf, 0, MAX_PATH);
ret = VerFindFileA(0, regedit, empty, empty, curdir, &dwCur, outBuf, &dwOut);
switch(ret) {
case 0L:
ok(dwCur == 1, "Wrong length of buffer for current location: "
"got %d(%s) expected 1\n", dwCur, curdir);
ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
"got %d(%s) expected 1\n", dwOut, outBuf);
break;
case VFF_BUFFTOOSMALL:
ok(dwCur == MAX_PATH, "Wrong length of buffer for current location: "
"got %d(%s) expected MAX_PATH\n", dwCur, curdir);
ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location: "
"got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
break;
default:
ok(0, "Got unexpected return value %x\n", ret);
}
if(!GetWindowsDirectoryA(windir, MAX_PATH))
trace("GetWindowsDirectoryA failed\n");
else {
sprintf(appdir, "%s\\regedit.exe", windir);
if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(appdir))
trace("GetFileAttributesA(%s) failed\n", appdir);
else {
dwCur=MAX_PATH;
dwOut=MAX_PATH;
memset(curdir, 0, MAX_PATH);
memset(outBuf, 0, MAX_PATH);
ret = VerFindFileA(0, regedit_exe, empty, empty, curdir, &dwCur, outBuf, &dwOut);
switch(ret) {
case VFF_CURNEDEST:
ok(dwCur == 1 + strlen(windir), "Wrong length of buffer for current location: "
"got %d(%s) expected %d\n", dwCur, curdir, lstrlenA(windir)+1);
ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
"got %d(%s) expected 1\n", dwOut, outBuf);
break;
case VFF_BUFFTOOSMALL:
ok(dwCur == MAX_PATH, "Wrong length of buffer for current location: "
"got %d(%s) expected MAX_PATH\n", dwCur, curdir);
ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location: "
"got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
break;
default:
ok(0, "Got unexpected return value %x\n", ret);
}
dwCur=MAX_PATH;
dwOut=MAX_PATH;
memset(curdir, 0, MAX_PATH);
memset(outBuf, 0, MAX_PATH);
ret = VerFindFileA(0, regedit_exe, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
switch(ret) {
case VFF_CURNEDEST:
ok(dwCur == 1 + strlen(windir), "Wrong length of buffer for current location: "
"got %d(%s) expected %d\n", dwCur, curdir, lstrlenA(windir)+1);
ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
"got %d(%s) expected 1\n", dwOut, outBuf);
break;
case VFF_BUFFTOOSMALL:
ok(dwCur == MAX_PATH, "Wrong length of buffer for current location: "
"got %d(%s) expected MAX_PATH\n", dwCur, curdir);
ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location: "
"got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
break;
default:
ok(0, "Got unexpected return value %x\n", ret);
}
}
}
if(!GetModuleFileNameA(NULL, filename, MAX_PATH) ||
!GetSystemDirectoryA(windir, MAX_PATH) ||
!GetTempPathA(MAX_PATH, appdir))
trace("GetModuleFileNameA, GetSystemDirectoryA or GetTempPathA failed\n");
else {
char *p = strrchr(filename, '\\');
if(p) {
*(p++) ='\0';
SetCurrentDirectoryA(filename);
memmove(filename, p, 1 + strlen(p));
}
dwCur=MAX_PATH;
dwOut=MAX_PATH;
memset(outBuf, 0, MAX_PATH);
memset(curdir, 0, MAX_PATH);
ret = VerFindFileA(0, filename, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
switch(ret) {
case VFF_CURNEDEST:
ok(dwOut == 1, "Wrong length of buffer for the recommended installation location"
"got %d(%s) expected 1\n", dwOut, outBuf);
break;
case VFF_BUFFTOOSMALL:
ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location"
"got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
break;
default:
todo_wine ok(0, "Got unexpected return value %x\n", ret);
}
dwCur=MAX_PATH;
dwOut=MAX_PATH;
memset(outBuf, 0, MAX_PATH);
memset(curdir, 0, MAX_PATH);
ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
ok(dwOut == 1 + strlen(windir), "Wrong length of buffer for current location: "
"got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(windir)+1);
dwCur=MAX_PATH;
dwOut=MAX_PATH;
memset(outBuf, 0, MAX_PATH);
memset(curdir, 0, MAX_PATH);
ret = VerFindFileA(0, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
ok(dwOut == 1 + strlen(appdir), "Wrong length of buffer for current location: "
"got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(appdir)+1);
}
}
static void test_install_file(void)
{
CHAR tmpname[MAX_PATH];
UINT size = MAX_PATH;
DWORD rc;
static const CHAR szSrcFileName[] = "nofile.txt";
static const CHAR szDestFileName[] = "nofile2.txt";
static const CHAR szSrcDir[] = "D:\\oes\\not\\exist";
static const CHAR szDestDir[] = "D:\\oes\\not\\exist\\either";
static const CHAR szCurDir[] = "C:\\";
/* testing Invalid Parameters */
memset(tmpname,0,sizeof(tmpname));
rc = VerInstallFileA(0x0, NULL, NULL, NULL, NULL, NULL, tmpname, &size);
ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
memset(tmpname,0,sizeof(tmpname));
size = MAX_PATH;
rc = VerInstallFileA(0x0, szSrcFileName, NULL, NULL, NULL, NULL, tmpname, &size);
ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
memset(tmpname,0,sizeof(tmpname));
size = MAX_PATH;
rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, NULL, NULL, NULL, tmpname, &size);
ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
memset(tmpname,0,sizeof(tmpname));
size = MAX_PATH;
rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, szSrcDir, NULL, NULL, tmpname, &size);
ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
/* Source file does not exist*/
memset(tmpname,0,sizeof(tmpname));
size = MAX_PATH;
rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, szSrcDir, szDestDir, NULL, tmpname, &size);
ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
memset(tmpname,0,sizeof(tmpname));
size = MAX_PATH;
rc = VerInstallFileA(0x0, szSrcFileName, szDestFileName, szSrcDir, szDestDir, szCurDir, tmpname, &size);
ok (rc == 0x10000 && tmpname[0]==0," expected return 0x10000 and no tempname, got %08x/\'%s\'\n",rc,tmpname);
}
START_TEST(install)
{
test_find_file();
test_install_file();
}