wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / version / tests / install.c
blob6fc19bbe08eaca7e718361623e69c90071d465ab
1 /*
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
19 #include <stdarg.h>
20 #include <stdio.h>
22 #include "wine/test.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winver.h"
28 static void test_find_file(void)
30 DWORD ret;
31 UINT dwCur, dwOut ;
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 CHAR empty[] = "",
38 regedit[] = "regedit",
39 regedit_exe[] = "regedit.exe";
41 memset(appdir, 0, MAX_PATH);
42 memset(windir, 0, MAX_PATH);
44 dwCur=MAX_PATH;
45 dwOut=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);
49 switch(ret) {
50 case 0L:
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);
55 break;
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);
61 break;
62 default:
63 ok(0, "Got unexpected return value %x\n", ret);
66 if(!GetWindowsDirectoryA(windir, MAX_PATH))
67 trace("GetWindowsDirectoryA failed\n");
68 else {
69 sprintf(appdir, "%s\\regedit.exe", windir);
70 if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(appdir))
71 trace("GetFileAttributesA(%s) failed\n", appdir);
72 else {
73 dwCur=MAX_PATH;
74 dwOut=MAX_PATH;
75 memset(curdir, 0, MAX_PATH);
76 memset(outBuf, 0, MAX_PATH);
77 ret = VerFindFileA(0, regedit_exe, empty, empty, curdir, &dwCur, outBuf, &dwOut);
78 switch(ret) {
79 case VFF_CURNEDEST:
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);
84 break;
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);
90 break;
91 default:
92 todo_wine ok(0, "Got unexpected return value %x\n", ret);
95 dwCur=MAX_PATH;
96 dwOut=MAX_PATH;
97 memset(curdir, 0, MAX_PATH);
98 memset(outBuf, 0, MAX_PATH);
99 ret = VerFindFileA(0, regedit_exe, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
100 switch(ret) {
101 case VFF_CURNEDEST:
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);
106 break;
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);
112 break;
113 default:
114 todo_wine 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");
122 else {
123 char *p = strrchr(filename, '\\');
124 if(p) {
125 *(p++) ='\0';
126 SetCurrentDirectoryA(filename);
127 memmove(filename, p, 1 + strlen(p));
130 dwCur=MAX_PATH;
131 dwOut=MAX_PATH;
132 memset(outBuf, 0, MAX_PATH);
133 memset(curdir, 0, MAX_PATH);
134 ret = VerFindFileA(0, filename, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
135 switch(ret) {
136 case VFF_CURNEDEST:
137 ok(dwOut == 1, "Wrong length of buffer for the recommended installation location"
138 "got %d(%s) expected 1\n", dwOut, outBuf);
139 break;
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);
143 break;
144 default:
145 todo_wine ok(0, "Got unexpected return value %x\n", ret);
148 dwCur=MAX_PATH;
149 dwOut=MAX_PATH;
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);
157 dwCur=MAX_PATH;
158 dwOut=MAX_PATH;
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;
172 DWORD rc;
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));
184 size = MAX_PATH;
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));
188 size = MAX_PATH;
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));
192 size = MAX_PATH;
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));
199 size = MAX_PATH;
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));
203 size = MAX_PATH;
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);
208 START_TEST(install)
210 test_find_file();
211 test_install_file();