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
29 #include "wine/test.h"
31 static UINT
run_query( MSIHANDLE hdb
, const char *query
)
36 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
37 if( r
!= ERROR_SUCCESS
)
40 r
= MsiViewExecute(hview
, 0);
41 if( r
== ERROR_SUCCESS
)
42 r
= MsiViewClose(hview
);
43 MsiCloseHandle(hview
);
47 static UINT
set_summary_info(MSIHANDLE hdb
)
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
,
66 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
68 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
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" );
92 MSIHANDLE
create_package_db(void)
95 CHAR szName
[] = "winetest.msi";
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
)
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" );
122 MSIHANDLE
package_from_db(MSIHANDLE hdb
)
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" );
138 static void test_createpackage(void)
140 MSIHANDLE hPackage
= 0;
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 };
157 r
= MsiGetSourcePath( -1, NULL
, NULL
, NULL
);
158 ok( r
== ERROR_INVALID_PARAMETER
, "return value wrong\n");
161 r
= MsiGetSourcePath( -1, NULL
, buffer
, &sz
);
162 ok( r
== ERROR_INVALID_PARAMETER
, "return value wrong\n");
165 r
= MsiGetSourcePath( -1, str
, NULL
, &sz
);
166 ok( r
== ERROR_INVALID_HANDLE
, "return value wrong\n");
169 r
= MsiGetSourcePath( -1, str
, NULL
, NULL
);
170 ok( r
== ERROR_INVALID_HANDLE
, "return value wrong\n");
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 )";
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
);
191 static void test_getsourcepath( void )
193 static const char str
[] = { 0 };
199 hpkg
= package_from_db(create_package_db());
200 ok( hpkg
, "failed to create package\n");
204 r
= MsiGetSourcePath( hpkg
, str
, buffer
, &sz
);
205 ok( r
== ERROR_DIRECTORY
, "return value wrong\n");
206 ok( buffer
[0] == 'x', "buffer modified\n");
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");
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");
240 sz
= sizeof buffer
-1;
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");
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");
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");
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 )
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)
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
);
331 test_createpackage();
332 test_getsourcepath_bad();
333 test_getsourcepath();
335 test_gettargetpath_bad();