Release 20050930.
[wine/gsoc-2012-control.git] / dlls / msi / tests / package.c
blobea92a2147c34e012d9ccbaa9043bbead7f0d043e
1 /*
2 * tests for Microsoft Installer functionality
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Aric Stewart for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define COBJMACROS
24 #include <stdio.h>
25 #include <windows.h>
26 #include <msi.h>
27 #include <msiquery.h>
29 #include "wine/test.h"
31 static UINT run_query( MSIHANDLE hdb, const char *query )
33 MSIHANDLE hview = 0;
34 UINT r;
36 r = MsiDatabaseOpenView(hdb, query, &hview);
37 if( r != ERROR_SUCCESS )
38 return r;
40 r = MsiViewExecute(hview, 0);
41 if( r == ERROR_SUCCESS )
42 r = MsiViewClose(hview);
43 MsiCloseHandle(hview);
44 return r;
47 static UINT set_summary_info(MSIHANDLE hdb)
49 UINT res;
50 MSIHANDLE suminfo;
52 /* build summmary info */
53 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
54 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
56 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
57 "Installation Database");
58 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
60 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
61 "Installation Database");
62 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
64 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
65 "Wine Hackers");
66 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
68 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
69 ";1033");
70 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
72 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
73 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
74 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
76 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
77 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
79 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
80 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
82 res = MsiSummaryInfoPersist(suminfo);
83 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
85 res = MsiCloseHandle( suminfo);
86 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
88 return res;
92 MSIHANDLE create_package_db(void)
94 MSIHANDLE hdb = 0;
95 CHAR szName[] = "winetest.msi";
96 UINT res;
98 DeleteFile(szName);
100 /* create an empty database */
101 res = MsiOpenDatabase(szName, MSIDBOPEN_CREATE, &hdb );
102 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
103 if( res != ERROR_SUCCESS )
104 return hdb;
106 res = MsiDatabaseCommit( hdb );
107 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
109 res = set_summary_info(hdb);
111 res = run_query( hdb,
112 "CREATE TABLE `Directory` ( "
113 "`Directory` CHAR(255) NOT NULL, "
114 "`Directory_Parent` CHAR(255), "
115 "`DefaultDir` CHAR(255) NOT NULL "
116 "PRIMARY KEY `Directory`)" );
117 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
119 return hdb;
122 MSIHANDLE package_from_db(MSIHANDLE hdb)
124 UINT res;
125 CHAR szPackage[10];
126 MSIHANDLE hPackage;
128 sprintf(szPackage,"#%li",hdb);
129 res = MsiOpenPackage(szPackage,&hPackage);
130 ok( res == ERROR_SUCCESS , "Failed to open package\n" );
132 res = MsiCloseHandle(hdb);
133 ok( res == ERROR_SUCCESS , "Failed to close db handle\n" );
135 return hPackage;
138 static void test_createpackage(void)
140 MSIHANDLE hPackage = 0;
141 UINT res;
143 hPackage = package_from_db(create_package_db());
144 ok( hPackage != 0, " Failed to create package\n");
146 res = MsiCloseHandle( hPackage);
147 ok( res == ERROR_SUCCESS , "Failed to close package\n" );
150 static void test_getsourcepath_bad( void )
152 static const char str[] = { 0 };
153 char buffer[0x80];
154 DWORD sz;
155 UINT r;
157 r = MsiGetSourcePath( -1, NULL, NULL, NULL );
158 ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
160 sz = 0;
161 r = MsiGetSourcePath( -1, NULL, buffer, &sz );
162 ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
164 sz = 0;
165 r = MsiGetSourcePath( -1, str, NULL, &sz );
166 ok( r == ERROR_INVALID_HANDLE, "return value wrong\n");
168 sz = 0;
169 r = MsiGetSourcePath( -1, str, NULL, NULL );
170 ok( r == ERROR_INVALID_HANDLE, "return value wrong\n");
172 sz = 0;
173 r = MsiGetSourcePath( -1, str, buffer, &sz );
174 ok( r == ERROR_INVALID_HANDLE, "return value wrong\n");
177 static UINT add_directory_entry( MSIHANDLE hdb, char *values )
179 char insert[] = "INSERT INTO `Directory` (`Directory`,`Directory_Parent`,`DefaultDir`) VALUES( %s )";
180 char *query;
181 UINT sz, r;
183 sz = strlen(values) + sizeof insert;
184 query = HeapAlloc(GetProcessHeap(),0,sz);
185 sprintf(query,insert,values);
186 r = run_query( hdb, query );
187 HeapFree(GetProcessHeap(), 0, query);
188 return r;
191 static void test_getsourcepath( void )
193 static const char str[] = { 0 };
194 char buffer[0x80];
195 DWORD sz;
196 UINT r;
197 MSIHANDLE hpkg, hdb;
199 hpkg = package_from_db(create_package_db());
200 ok( hpkg, "failed to create package\n");
202 sz = 0;
203 buffer[0] = 'x';
204 r = MsiGetSourcePath( hpkg, str, buffer, &sz );
205 ok( r == ERROR_DIRECTORY, "return value wrong\n");
206 ok( buffer[0] == 'x', "buffer modified\n");
208 sz = 1;
209 buffer[0] = 'x';
210 r = MsiGetSourcePath( hpkg, str, buffer, &sz );
211 ok( r == ERROR_DIRECTORY, "return value wrong\n");
212 ok( buffer[0] == 'x', "buffer modified\n");
214 MsiCloseHandle( hpkg );
217 /* another test but try create a directory this time */
218 hdb = create_package_db();
219 ok( hdb, "failed to create database\n");
221 r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
222 ok( r == S_OK, "failed\n");
224 hpkg = package_from_db(hdb);
225 ok( hpkg, "failed to create package\n");
227 sz = sizeof buffer -1;
228 strcpy(buffer,"x bad");
229 r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
230 ok( r == ERROR_DIRECTORY, "return value wrong\n");
232 todo_wine {
233 r = MsiDoAction( hpkg, "CostInitialize");
234 ok( r == ERROR_SUCCESS, "cost init failed\n");
236 r = MsiDoAction( hpkg, "CostFinalize");
237 ok( r == ERROR_SUCCESS, "cost finalize failed\n");
239 todo_wine {
240 sz = sizeof buffer -1;
241 buffer[0] = 'x';
242 r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
243 ok( r == ERROR_SUCCESS, "return value wrong\n");
244 ok( sz == strlen(buffer), "returned length wrong\n");
246 sz = 0;
247 strcpy(buffer,"x bad");
248 r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
249 ok( r == ERROR_MORE_DATA, "return value wrong\n");
251 ok( buffer[0] == 'x', "buffer modified\n");
253 todo_wine {
254 r = MsiGetSourcePath( hpkg, "TARGETDIR", NULL, NULL );
255 ok( r == ERROR_SUCCESS, "return value wrong\n");
258 r = MsiGetSourcePath( hpkg, "TARGETDIR ", NULL, NULL );
259 ok( r == ERROR_DIRECTORY, "return value wrong\n");
261 r = MsiGetSourcePath( hpkg, "targetdir", NULL, NULL );
262 ok( r == ERROR_DIRECTORY, "return value wrong\n");
264 r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, NULL );
265 ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
267 todo_wine {
268 r = MsiGetSourcePath( hpkg, "TARGETDIR", NULL, &sz );
269 ok( r == ERROR_SUCCESS, "return value wrong\n");
272 MsiCloseHandle( hpkg );
275 static void test_doaction( void )
277 MSIHANDLE hpkg;
278 UINT r;
280 r = MsiDoAction( -1, NULL );
281 ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
283 hpkg = package_from_db(create_package_db());
284 ok( hpkg, "failed to create package\n");
286 r = MsiDoAction(hpkg, NULL);
287 ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
289 r = MsiDoAction(0, "boo");
290 ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
292 r = MsiDoAction(hpkg, "boo");
293 ok( r == ERROR_FUNCTION_NOT_CALLED, "wrong return val\n");
295 MsiCloseHandle( hpkg );
298 static void test_gettargetpath_bad(void)
300 char buffer[0x80];
301 MSIHANDLE hpkg;
302 DWORD sz;
303 UINT r;
305 hpkg = package_from_db(create_package_db());
306 ok( hpkg, "failed to create package\n");
308 r = MsiGetTargetPath( 0, NULL, NULL, NULL );
309 ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
311 r = MsiGetTargetPath( 0, NULL, NULL, &sz );
312 ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
314 r = MsiGetTargetPath( 0, "boo", NULL, NULL );
315 ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
317 r = MsiGetTargetPath( 0, "boo", NULL, NULL );
318 ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
320 r = MsiGetTargetPath( hpkg, "boo", NULL, NULL );
321 ok( r == ERROR_DIRECTORY, "wrong return val\n");
323 r = MsiGetTargetPath( hpkg, "boo", buffer, NULL );
324 ok( r == ERROR_DIRECTORY, "wrong return val\n");
326 MsiCloseHandle( hpkg );
329 START_TEST(package)
331 test_createpackage();
332 test_getsourcepath_bad();
333 test_getsourcepath();
334 test_doaction();
335 test_gettargetpath_bad();