ReactOS  0.4.14-dev-599-g2d4d3f5
custom.c
Go to the documentation of this file.
1 /*
2  * DLL for testing type 1 custom actions
3  *
4  * Copyright 2017 Zebediah Figura
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 #include <stdarg.h>
22 #include <stdio.h>
23 
24 #include <windef.h>
25 #include <winbase.h>
26 #define COBJMACROS
27 #include <objbase.h>
28 #include <unknwn.h>
29 #include <msi.h>
30 #include <msiquery.h>
31 
32 static void ok_(MSIHANDLE hinst, int todo, const char *file, int line, int condition, const char *msg, ...)
33 {
34  static char buffer[2000];
37 
40  va_end(valist);
41 
50 }
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__)
53 
54 
55 /* Main test. Anything that doesn't depend on a specific install configuration
56  * or have undesired side effects should go here. */
58 {
59  UINT res;
60  IUnknown *unk = NULL;
61  HRESULT hres;
62 
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);
66 
67  if (unk) IUnknown_Release(unk);
68 
69  /* Test MsiGetDatabaseState() */
71  todo_wine_ok(hinst, res == MSIDBSTATE_ERROR, "expected MSIDBSTATE_ERROR, got %u\n", res);
72 
73  return ERROR_SUCCESS;
74 }
75 
77 {
78  char prop[10];
79  DWORD len = sizeof(prop);
80  UINT retval;
81 
82  MsiGetPropertyA(hinst, "TEST_RETVAL", prop, &len);
83  sscanf(prop, "%u", &retval);
84  return retval;
85 }
86 
87 static void append_file(MSIHANDLE hinst, const char *filename, const char *text)
88 {
89  DWORD size;
91  ok(hinst, file != INVALID_HANDLE_VALUE, "CreateFile failed, error %u\n", GetLastError());
92 
96 }
97 
99 {
100  char prop[300];
101  DWORD len = sizeof(prop);
102 
103  MsiGetPropertyA(hinst, "TESTPATH", prop, &len);
104 
105  append_file(hinst, prop, "one");
106 
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");
110 
111  return ERROR_SUCCESS;
112 }
113 
115 {
116  char prop[300];
117  DWORD len = sizeof(prop);
118  LANGID lang;
119  UINT r;
120 
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");
125 
126  append_file(hinst, prop, "two");
127 
128  /* Test available properties */
129  len = sizeof(prop);
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);
133 
134  len = sizeof(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);
138 
139  len = sizeof(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);
143 
144  /* Test modes */
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");
148 
150  ok(hinst, lang != ERROR_INVALID_HANDLE, "MsiGetLanguage failed\n");
151 
152  return ERROR_SUCCESS;
153 }
static void ok_(MSIHANDLE hinst, int todo, const char *file, int line, int condition, const char *msg,...)
Definition: custom.c:32
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static void append_file(MSIHANDLE hinst, const char *filename, const char *text)
Definition: custom.c:87
MSIHANDLE WINAPI MsiCreateRecord(UINT cParams)
Definition: record.c:95
#define CloseHandle
Definition: compat.h:406
UINT WINAPI MsiGetPropertyA(MSIHANDLE hInstall, LPCSTR szName, LPSTR szValueBuf, LPDWORD pchValueBuf)
Definition: package.c:2488
UINT WINAPI MsiRecordSetStringA(MSIHANDLE handle, UINT iField, LPCSTR szValue)
Definition: record.c:601
UINT WINAPI MsiRecordSetInteger(MSIHANDLE handle, UINT iField, int iVal)
Definition: record.c:351
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const WCHAR * text
Definition: package.c:1827
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
BOOL todo
Definition: filedlg.c:313
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
WORD LANGID
Definition: typedefs.h:79
const char * filename
Definition: ioapi.h:135
UINT WINAPI da_immediate(MSIHANDLE hinst)
Definition: custom.c:98
unsigned long MSIHANDLE
Definition: msiserver.idl:25
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
Definition: install.c:690
#define va_end(ap)
Definition: acmsvcex.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
GLenum condition
Definition: glext.h:9255
UINT WINAPI main_test(MSIHANDLE hinst)
Definition: custom.c:57
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
char * va_list
Definition: acmsvcex.h:78
INT WINAPI MsiProcessMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, MSIHANDLE hRecord)
Definition: package.c:2052
UINT WINAPI da_deferred(MSIHANDLE hinst)
Definition: custom.c:114
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define OPEN_EXISTING
Definition: compat.h:434
MSIDBSTATE WINAPI MsiGetDatabaseState(MSIHANDLE handle)
Definition: database.c:2001
static const WCHAR lang[]
Definition: wbemdisp.c:287
GLsizeiptr size
Definition: glext.h:5919
HRESULT hres
Definition: protocol.c:465
#define FILE_END
Definition: winbase.h:114
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define todo_wine_ok(hinst, condition,...)
Definition: custom.c:52
#define WINAPI
Definition: msvc.h:6
#define ok(hinst, condition,...)
Definition: custom.c:51
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
Definition: handle.c:270
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:59
UINT WINAPI test_retval(MSIHANDLE hinst)
Definition: custom.c:76
const CLSID CLSID_Picture_Metafile
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
unsigned int UINT
Definition: ndis.h:50
#define msg(x)
Definition: auth_time.c:54
LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
Definition: install.c:1615
GLuint res
Definition: glext.h:9613
static HINSTANCE hinst
Definition: edit.c:551
static __ms_va_list valist
Definition: printf.c:64
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
Definition: fci.c:126