Move and reshuffle reactos/regtetsts into rostests. 1/2
[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 #include "wine/windef.h"
30
31 /*
32 * The following are defined in Windows SDK's msidefs.h
33 * but that file doesn't exist in the msvc6 header set.
34 *
35 * Some are already defined in PropIdl.h - undefine them
36 */
37 #undef PID_DICTIONARY
38 #undef PID_CODEPAGE
39 #undef PID_SUBJECT
40 #undef PID_SECURITY
41
42 #define PID_DICTIONARY 0
43 #define PID_CODEPAGE 1
44 #define PID_TITLE 2
45 #define PID_SUBJECT 3
46 #define PID_AUTHOR 4
47 #define PID_KEYWORDS 5
48 #define PID_COMMENTS 6
49 #define PID_TEMPLATE 7
50 #define PID_LASTAUTHOR 8
51 #define PID_REVNUMBER 9
52 #define PID_EDITTINE 10
53 #define PID_LASTPRINTED 11
54 #define PID_CREATE_DTM 12
55 #define PID_LASTSAVE_DTM 13
56 #define PID_PAGECOUNT 14
57 #define PID_WORDCOUNT 15
58 #define PID_CHARCOUNT 16
59 #define PID_THUMBNAIL 17
60 #define PID_APPNAME 18
61 #define PID_SECURITY 19
62 #define PID_MSIVERSION PID_PAGECOUNT
63 #define PID_MSISOURCE PID_WORDCOUNT
64 #define PID_MSIRESTRICT PID_CHARCOUNT
65
66 START_TEST(suminfo)
67 {
68 const char *msifile = "winetest.msi";
69 MSIHANDLE hdb = 0, hsuminfo;
70 UINT r, count, type;
71 DWORD sz;
72 INT val;
73 FILETIME ft;
74 char buf[0x10];
75
76 DeleteFile(msifile);
77
78 /* just MsiOpenDatabase should not create a file */
79 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
80 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
81
82 r = MsiGetSummaryInformation(hdb, NULL, 0, NULL);
83 ok(r == ERROR_INVALID_PARAMETER, "MsiGetSummaryInformation wrong error\n");
84
85 r = MsiGetSummaryInformation(hdb, NULL, 0, &hsuminfo);
86 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
87
88 r = MsiSummaryInfoGetPropertyCount(0, NULL);
89 ok(r == ERROR_INVALID_HANDLE, "getpropcount failed\n");
90
91 r = MsiSummaryInfoGetPropertyCount(hsuminfo, NULL);
92 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
93
94 count = -1;
95 r = MsiSummaryInfoGetPropertyCount(hsuminfo, &count);
96 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
97 ok(count == 0, "count should be zero\n");
98
99 r = MsiSummaryInfoGetProperty(hsuminfo, 0, NULL, NULL, NULL, 0, NULL);
100 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
101
102 type = -1;
103 r = MsiSummaryInfoGetProperty(hsuminfo, 0, &type, NULL, NULL, 0, NULL);
104 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
105 ok(type == 0, "wrong type\n");
106
107 type = -1;
108 val = 1234;
109 r = MsiSummaryInfoGetProperty(hsuminfo, 0, &type, &val, NULL, 0, NULL);
110 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
111 ok(type == 0, "wrong type\n");
112 ok(val == 1234, "wrong val\n");
113
114 buf[0]='x';
115 buf[1]=0;
116 sz = 0x10;
117 r = MsiSummaryInfoGetProperty(hsuminfo, PID_REVNUMBER, &type, &val, NULL, buf, &sz);
118 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
119 ok(buf[0]=='x', "cleared buffer\n");
120 ok(sz == 0x10, "count wasn't zero\n");
121 ok(type == VT_EMPTY, "should be empty\n");
122
123 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
124 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
125
126 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 1, NULL, "JungAh");
127 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
128
129 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 1, &ft, "Mike");
130 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
131
132 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "JungAh");
133 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
134
135 r = MsiCloseHandle(hsuminfo);
136 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
137
138 /* try again with the update count set */
139 r = MsiGetSummaryInformation(hdb, NULL, 1, &hsuminfo);
140 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
141
142 r = MsiSummaryInfoSetProperty(hsuminfo, 0, VT_LPSTR, 1, NULL, NULL);
143 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
144
145 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
146 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
147
148 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_I4, 0, NULL, "Mike");
149 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
150
151 r = MsiSummaryInfoSetProperty(hsuminfo, PID_AUTHOR, VT_I4, 0, NULL, "JungAh");
152 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
153
154 r = MsiSummaryInfoSetProperty(hsuminfo, PID_KEYWORDS, VT_I2, 0, NULL, "Mike");
155 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
156
157 r = MsiSummaryInfoSetProperty(hsuminfo, PID_COMMENTS, VT_FILETIME, 0, NULL, "JungAh");
158 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
159
160 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TEMPLATE, VT_I2, 0, NULL, "Mike");
161 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
162
163 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTAUTHOR, VT_LPSTR, 0, NULL, NULL);
164 ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");
165
166 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTSAVE_DTM, VT_FILETIME, 0, NULL, NULL);
167 ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");
168
169 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTAUTHOR, VT_LPWSTR, 0, NULL, "h\0i\0\0");
170 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
171
172 r = MsiSummaryInfoSetProperty(hsuminfo, PID_REVNUMBER, VT_I4, 0, NULL, "Jungah");
173 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
174
175 r = MsiSummaryInfoSetProperty(hsuminfo, PID_PAGECOUNT, VT_LPSTR, 1, NULL, NULL);
176 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
177
178 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
179 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
180
181 sz = 2;
182 strcpy(buf,"x");
183 r = MsiSummaryInfoGetProperty(hsuminfo, PID_TITLE, &type, NULL, NULL, buf, &sz );
184 ok(r == ERROR_MORE_DATA, "MsiSummaryInfoSetProperty failed\n");
185 ok(sz == 4, "count was wrong\n");
186 ok(type == VT_LPSTR, "type was wrong\n");
187 ok(!strcmp(buf,"M"), "buffer was wrong\n");
188
189 sz = 4;
190 strcpy(buf,"x");
191 r = MsiSummaryInfoGetProperty(hsuminfo, PID_TITLE, &type, NULL, NULL, buf, &sz );
192 ok(r == ERROR_MORE_DATA, "MsiSummaryInfoSetProperty failed\n");
193 ok(sz == 4, "count was wrong\n");
194 ok(type == VT_LPSTR, "type was wrong\n");
195 ok(!strcmp(buf,"Mik"), "buffer was wrong\n");
196
197 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
198 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
199
200 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
201 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
202
203 r = MsiCloseHandle(hsuminfo);
204 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
205
206 /* try again with a higher update count */
207 r = MsiGetSummaryInformation(hdb, NULL, 10, &hsuminfo);
208 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
209
210 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
211 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
212
213 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
214 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
215
216 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, NULL, NULL);
217 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
218
219 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
220 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
221
222 r = MsiSummaryInfoSetProperty(hsuminfo, PID_AUTHOR, VT_LPSTR, 1, &ft, "Mike");
223 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
224
225 r = MsiSummaryInfoPersist(hsuminfo);
226 ok(r == ERROR_SUCCESS, "MsiSummaryInfoPersist failed\n");
227
228 MsiDatabaseCommit(hdb);
229
230 r = MsiCloseHandle(hsuminfo);
231 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
232
233 r = MsiCloseHandle(hdb);
234 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
235
236 r = DeleteFile(msifile);
237 ok(r, "DeleteFile failed\n");
238 }