fix msi winetest
[reactos.git] / rostests / winetests / msi / suminfo.c
1 /*
2 * Copyright (C) 2005 Mike McCormack for CodeWeavers
3 *
4 * A test program for MSI database files.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define COBJMACROS
22
23 #include <stdio.h>
24 #include <windows.h>
25 #include <msi.h>
26 #include <msiquery.h>
27
28 #include "wine/test.h"
29
30 /*
31 * The following are defined in Windows SDK's msidefs.h
32 * but that file doesn't exist in the msvc6 header set.
33 *
34 * Some are already defined in PropIdl.h - undefine them
35 */
36 #undef PID_DICTIONARY
37 #undef PID_CODEPAGE
38 #undef PID_SUBJECT
39 #undef PID_SECURITY
40
41 #define PID_DICTIONARY 0
42 #define PID_CODEPAGE 1
43 #define PID_TITLE 2
44 #define PID_SUBJECT 3
45 #define PID_AUTHOR 4
46 #define PID_KEYWORDS 5
47 #define PID_COMMENTS 6
48 #define PID_TEMPLATE 7
49 #define PID_LASTAUTHOR 8
50 #define PID_REVNUMBER 9
51 #define PID_EDITTINE 10
52 #define PID_LASTPRINTED 11
53 #define PID_CREATE_DTM 12
54 #define PID_LASTSAVE_DTM 13
55 #define PID_PAGECOUNT 14
56 #define PID_WORDCOUNT 15
57 #define PID_CHARCOUNT 16
58 #define PID_THUMBNAIL 17
59 #define PID_APPNAME 18
60 #define PID_SECURITY 19
61 #define PID_MSIVERSION PID_PAGECOUNT
62 #define PID_MSISOURCE PID_WORDCOUNT
63 #define PID_MSIRESTRICT PID_CHARCOUNT
64
65 START_TEST(suminfo)
66 {
67 const char *msifile = "winetest.msi";
68 MSIHANDLE hdb = 0, hsuminfo;
69 UINT r, count, type;
70 DWORD sz;
71 INT val;
72 FILETIME ft;
73 char buf[0x10];
74
75 DeleteFile(msifile);
76
77 /* just MsiOpenDatabase should not create a file */
78 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
79 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
80
81 r = MsiGetSummaryInformation(hdb, NULL, 0, NULL);
82 ok(r == ERROR_INVALID_PARAMETER, "MsiGetSummaryInformation wrong error\n");
83
84 r = MsiGetSummaryInformation(hdb, NULL, 0, &hsuminfo);
85 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
86
87 r = MsiSummaryInfoGetPropertyCount(0, NULL);
88 ok(r == ERROR_INVALID_HANDLE, "getpropcount failed\n");
89
90 r = MsiSummaryInfoGetPropertyCount(hsuminfo, NULL);
91 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
92
93 count = -1;
94 r = MsiSummaryInfoGetPropertyCount(hsuminfo, &count);
95 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
96 ok(count == 0, "count should be zero\n");
97
98 r = MsiSummaryInfoGetProperty(hsuminfo, 0, NULL, NULL, NULL, 0, NULL);
99 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
100
101 type = -1;
102 r = MsiSummaryInfoGetProperty(hsuminfo, 0, &type, NULL, NULL, 0, NULL);
103 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
104 ok(type == 0, "wrong type\n");
105
106 type = -1;
107 val = 1234;
108 r = MsiSummaryInfoGetProperty(hsuminfo, 0, &type, &val, NULL, 0, NULL);
109 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
110 ok(type == 0, "wrong type\n");
111 ok(val == 1234, "wrong val\n");
112
113 buf[0]='x';
114 buf[1]=0;
115 sz = 0x10;
116 r = MsiSummaryInfoGetProperty(hsuminfo, PID_REVNUMBER, &type, &val, NULL, buf, &sz);
117 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
118 ok(buf[0]=='x', "cleared buffer\n");
119 ok(sz == 0x10, "count wasn't zero\n");
120 ok(type == VT_EMPTY, "should be empty\n");
121
122 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
123 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
124
125 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 1, NULL, "JungAh");
126 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
127
128 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 1, &ft, "Mike");
129 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
130
131 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "JungAh");
132 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
133
134 r = MsiCloseHandle(hsuminfo);
135 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
136
137 /* try again with the update count set */
138 r = MsiGetSummaryInformation(hdb, NULL, 1, &hsuminfo);
139 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
140
141 r = MsiSummaryInfoSetProperty(hsuminfo, 0, VT_LPSTR, 1, NULL, NULL);
142 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
143
144 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
145 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
146
147 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_I4, 0, NULL, "Mike");
148 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
149
150 r = MsiSummaryInfoSetProperty(hsuminfo, PID_AUTHOR, VT_I4, 0, NULL, "JungAh");
151 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
152
153 r = MsiSummaryInfoSetProperty(hsuminfo, PID_KEYWORDS, VT_I2, 0, NULL, "Mike");
154 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
155
156 r = MsiSummaryInfoSetProperty(hsuminfo, PID_COMMENTS, VT_FILETIME, 0, NULL, "JungAh");
157 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
158
159 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TEMPLATE, VT_I2, 0, NULL, "Mike");
160 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
161
162 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTAUTHOR, VT_LPSTR, 0, NULL, NULL);
163 ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");
164
165 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTSAVE_DTM, VT_FILETIME, 0, NULL, NULL);
166 ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");
167
168 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTAUTHOR, VT_LPWSTR, 0, NULL, "h\0i\0\0");
169 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
170
171 r = MsiSummaryInfoSetProperty(hsuminfo, PID_REVNUMBER, VT_I4, 0, NULL, "Jungah");
172 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
173
174 r = MsiSummaryInfoSetProperty(hsuminfo, PID_PAGECOUNT, VT_LPSTR, 1, NULL, NULL);
175 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
176
177 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
178 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
179
180 sz = 2;
181 strcpy(buf,"x");
182 r = MsiSummaryInfoGetProperty(hsuminfo, PID_TITLE, &type, NULL, NULL, buf, &sz );
183 ok(r == ERROR_MORE_DATA, "MsiSummaryInfoSetProperty failed\n");
184 ok(sz == 4, "count was wrong\n");
185 ok(type == VT_LPSTR, "type was wrong\n");
186 ok(!strcmp(buf,"M"), "buffer was wrong\n");
187
188 sz = 4;
189 strcpy(buf,"x");
190 r = MsiSummaryInfoGetProperty(hsuminfo, PID_TITLE, &type, NULL, NULL, buf, &sz );
191 ok(r == ERROR_MORE_DATA, "MsiSummaryInfoSetProperty failed\n");
192 ok(sz == 4, "count was wrong\n");
193 ok(type == VT_LPSTR, "type was wrong\n");
194 ok(!strcmp(buf,"Mik"), "buffer was wrong\n");
195
196 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
197 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
198
199 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
200 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
201
202 r = MsiCloseHandle(hsuminfo);
203 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
204
205 /* try again with a higher update count */
206 r = MsiGetSummaryInformation(hdb, NULL, 10, &hsuminfo);
207 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
208
209 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
210 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
211
212 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
213 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
214
215 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, NULL, NULL);
216 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
217
218 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
219 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
220
221 r = MsiSummaryInfoSetProperty(hsuminfo, PID_AUTHOR, VT_LPSTR, 1, &ft, "Mike");
222 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
223
224 r = MsiSummaryInfoPersist(hsuminfo);
225 ok(r == ERROR_SUCCESS, "MsiSummaryInfoPersist failed\n");
226
227 MsiDatabaseCommit(hdb);
228
229 r = MsiCloseHandle(hsuminfo);
230 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
231
232 r = MsiCloseHandle(hdb);
233 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
234
235 r = DeleteFile(msifile);
236 ok(r, "DeleteFile failed\n");
237 }