2 * DLL for testing type 1 custom actions
4 * Copyright 2017 Zebediah Figura
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 static void ok_(MSIHANDLE hinst
, int todo
, const char *file
, int line
, int condition
, const char *msg
, ...)
34 static char buffer
[2000];
38 va_start(valist
, msg
);
39 vsprintf(buffer
, msg
, valist
);
42 record
= MsiCreateRecord(5);
43 MsiRecordSetInteger(record
, 1, todo
);
44 MsiRecordSetStringA(record
, 2, file
);
45 MsiRecordSetInteger(record
, 3, line
);
46 MsiRecordSetInteger(record
, 4, condition
);
47 MsiRecordSetStringA(record
, 5, buffer
);
48 MsiProcessMessage(hinst
, INSTALLMESSAGE_USER
, record
);
49 MsiCloseHandle(record
);
51 #define ok(hinst, condition, ...) ok_(hinst, 0, __FILE__, __LINE__, condition, __VA_ARGS__)
52 #define todo_wine_ok(hinst, condition, ...) ok_(hinst, 1, __FILE__, __LINE__, condition, __VA_ARGS__)
55 /* Main test. Anything that doesn't depend on a specific install configuration
56 * or have undesired side effects should go here. */
57 UINT WINAPI
main_test(MSIHANDLE hinst
)
63 /* Test for an MTA apartment */
64 hres
= CoCreateInstance(&CLSID_Picture_Metafile
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&unk
);
65 todo_wine_ok(hinst
, hres
== S_OK
, "CoCreateInstance failed with %08x\n", hres
);
67 if (unk
) IUnknown_Release(unk
);
69 /* Test MsiGetDatabaseState() */
70 res
= MsiGetDatabaseState(hinst
);
71 todo_wine_ok(hinst
, res
== MSIDBSTATE_ERROR
, "expected MSIDBSTATE_ERROR, got %u\n", res
);
76 UINT WINAPI
test_retval(MSIHANDLE hinst
)
79 DWORD len
= sizeof(prop
);
82 MsiGetPropertyA(hinst
, "TEST_RETVAL", prop
, &len
);
83 sscanf(prop
, "%u", &retval
);
87 static void append_file(MSIHANDLE hinst
, const char *filename
, const char *text
)
90 HANDLE file
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
91 ok(hinst
, file
!= INVALID_HANDLE_VALUE
, "CreateFile failed, error %u\n", GetLastError());
93 SetFilePointer(file
, 0, NULL
, FILE_END
);
94 WriteFile(file
, text
, strlen(text
), &size
, NULL
);
98 UINT WINAPI
da_immediate(MSIHANDLE hinst
)
101 DWORD len
= sizeof(prop
);
103 MsiGetPropertyA(hinst
, "TESTPATH", prop
, &len
);
105 append_file(hinst
, prop
, "one");
107 ok(hinst
, !MsiGetMode(hinst
, MSIRUNMODE_SCHEDULED
), "shouldn't be scheduled\n");
108 ok(hinst
, !MsiGetMode(hinst
, MSIRUNMODE_ROLLBACK
), "shouldn't be rollback\n");
109 ok(hinst
, !MsiGetMode(hinst
, MSIRUNMODE_COMMIT
), "shouldn't be commit\n");
111 return ERROR_SUCCESS
;
114 UINT WINAPI
da_deferred(MSIHANDLE hinst
)
117 DWORD len
= sizeof(prop
);
121 /* Test that we were in fact deferred */
122 r
= MsiGetPropertyA(hinst
, "CustomActionData", prop
, &len
);
123 ok(hinst
, r
== ERROR_SUCCESS
, "got %u\n", r
);
124 ok(hinst
, prop
[0], "CustomActionData was empty\n");
126 append_file(hinst
, prop
, "two");
128 /* Test available properties */
130 r
= MsiGetPropertyA(hinst
, "ProductCode", prop
, &len
);
131 ok(hinst
, r
== ERROR_SUCCESS
, "got %u\n", r
);
132 ok(hinst
, prop
[0], "got %s\n", prop
);
135 r
= MsiGetPropertyA(hinst
, "UserSID", prop
, &len
);
136 ok(hinst
, r
== ERROR_SUCCESS
, "got %u\n", r
);
137 ok(hinst
, prop
[0], "got %s\n", prop
);
140 r
= MsiGetPropertyA(hinst
, "TESTPATH", prop
, &len
);
141 ok(hinst
, r
== ERROR_SUCCESS
, "got %u\n", r
);
142 todo_wine_ok(hinst
, !prop
[0], "got %s\n", prop
);
145 ok(hinst
, MsiGetMode(hinst
, MSIRUNMODE_SCHEDULED
), "should be scheduled\n");
146 ok(hinst
, !MsiGetMode(hinst
, MSIRUNMODE_ROLLBACK
), "shouldn't be rollback\n");
147 ok(hinst
, !MsiGetMode(hinst
, MSIRUNMODE_COMMIT
), "shouldn't be commit\n");
149 lang
= MsiGetLanguage(hinst
);
150 ok(hinst
, lang
!= ERROR_INVALID_HANDLE
, "MsiGetLanguage failed\n");
152 return ERROR_SUCCESS
;