Release 20050930.
[wine/gsoc-2012-control.git] / dlls / msi / tests / suminfo.c
blob80c050a8b67dd0fe80226ddd41e3ea112fe1c4c4
1 /*
2 * Copyright (C) 2005 Mike McCormack for CodeWeavers
4 * A test program for MSI database files.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define COBJMACROS
23 #include <stdio.h>
24 #include <windows.h>
25 #include <msi.h>
26 #include <msiquery.h>
28 #include "wine/test.h"
31 * The following are defined in Windows SDK's msidefs.h
32 * but that file doesn't exist in the msvc6 header set.
34 * Some are already defined in PropIdl.h - undefine them
36 #undef PID_DICTIONARY
37 #undef PID_CODEPAGE
38 #undef PID_SUBJECT
39 #undef PID_SECURITY
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
65 START_TEST(suminfo)
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];
75 DeleteFile(msifile);
77 /* just MsiOpenDatabase should not create a file */
78 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
79 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
81 r = MsiGetSummaryInformation(hdb, NULL, 0, NULL);
82 ok(r == ERROR_INVALID_PARAMETER, "MsiGetSummaryInformation wrong error\n");
84 r = MsiGetSummaryInformation(hdb, NULL, 0, &hsuminfo);
85 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
87 r = MsiSummaryInfoGetPropertyCount(0, NULL);
88 ok(r == ERROR_INVALID_HANDLE, "getpropcount failed\n");
90 r = MsiSummaryInfoGetPropertyCount(hsuminfo, NULL);
91 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
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");
98 r = MsiSummaryInfoGetProperty(hsuminfo, 0, NULL, NULL, NULL, 0, NULL);
99 ok(r == ERROR_SUCCESS, "getpropcount failed\n");
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");
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");
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");
122 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
123 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
125 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 1, NULL, "JungAh");
126 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
128 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 1, &ft, "Mike");
129 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
131 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "JungAh");
132 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
134 r = MsiCloseHandle(hsuminfo);
135 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
137 /* try again with the update count set */
138 r = MsiGetSummaryInformation(hdb, NULL, 1, &hsuminfo);
139 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
141 r = MsiSummaryInfoSetProperty(hsuminfo, 0, VT_LPSTR, 1, NULL, NULL);
142 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
144 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
145 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
147 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_I4, 0, NULL, "Mike");
148 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
150 r = MsiSummaryInfoSetProperty(hsuminfo, PID_AUTHOR, VT_I4, 0, NULL, "JungAh");
151 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
153 r = MsiSummaryInfoSetProperty(hsuminfo, PID_KEYWORDS, VT_I2, 0, NULL, "Mike");
154 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
156 r = MsiSummaryInfoSetProperty(hsuminfo, PID_COMMENTS, VT_FILETIME, 0, NULL, "JungAh");
157 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
159 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TEMPLATE, VT_I2, 0, NULL, "Mike");
160 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
162 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTAUTHOR, VT_LPSTR, 0, NULL, NULL);
163 ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");
165 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTSAVE_DTM, VT_FILETIME, 0, NULL, NULL);
166 ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");
168 r = MsiSummaryInfoSetProperty(hsuminfo, PID_LASTAUTHOR, VT_LPWSTR, 0, NULL, "h\0i\0\0");
169 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
171 r = MsiSummaryInfoSetProperty(hsuminfo, PID_REVNUMBER, VT_I4, 0, NULL, "Jungah");
172 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
174 r = MsiSummaryInfoSetProperty(hsuminfo, PID_PAGECOUNT, VT_LPSTR, 1, NULL, NULL);
175 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
177 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
178 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
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");
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");
196 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
197 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
199 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
200 ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");
202 r = MsiCloseHandle(hsuminfo);
203 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
205 /* try again with a higher update count */
206 r = MsiGetSummaryInformation(hdb, NULL, 10, &hsuminfo);
207 ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");
209 r = MsiSummaryInfoSetProperty(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
210 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");
212 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
213 ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");
215 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, NULL, NULL);
216 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
218 r = MsiSummaryInfoSetProperty(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
219 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
221 r = MsiSummaryInfoSetProperty(hsuminfo, PID_AUTHOR, VT_LPSTR, 1, &ft, "Mike");
222 ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");
224 r = MsiSummaryInfoPersist(hsuminfo);
225 ok(r == ERROR_SUCCESS, "MsiSummaryInfoPersist failed\n");
227 MsiDatabaseCommit(hdb);
229 r = MsiCloseHandle(hsuminfo);
230 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
232 r = MsiCloseHandle(hdb);
233 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
235 r = DeleteFile(msifile);
236 ok(r, "DeleteFile failed\n");