[PATCH 3/5] msi/tests: Add tests for custom action return values.
Zebediah Figura
z.figura12 at gmail.com
Thu Nov 23 15:35:58 CST 2017
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/msi/tests/custom.dll/Makefile.in | 1 +
dlls/msi/tests/custom.dll/custom.spec | 1 +
dlls/msi/tests/custom.dll/main.c | 17 ++++++
dlls/msi/tests/install.c | 100 ++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+)
diff --git a/dlls/msi/tests/custom.dll/Makefile.in b/dlls/msi/tests/custom.dll/Makefile.in
index a711e4b..c606b22 100644
--- a/dlls/msi/tests/custom.dll/Makefile.in
+++ b/dlls/msi/tests/custom.dll/Makefile.in
@@ -1,4 +1,5 @@
RESOURCE = custom.dll
+IMPORTS = msi
C_SRCS = \
main.c
diff --git a/dlls/msi/tests/custom.dll/custom.spec b/dlls/msi/tests/custom.dll/custom.spec
index e69de29..2a01b3d 100644
--- a/dlls/msi/tests/custom.dll/custom.spec
+++ b/dlls/msi/tests/custom.dll/custom.spec
@@ -0,0 +1 @@
+@ stdcall test_retval(long)
diff --git a/dlls/msi/tests/custom.dll/main.c b/dlls/msi/tests/custom.dll/main.c
index 838b8ae..7a970bf 100644
--- a/dlls/msi/tests/custom.dll/main.c
+++ b/dlls/msi/tests/custom.dll/main.c
@@ -18,9 +18,26 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#include <stdarg.h>
+#include <stdio.h>
+
#include <windef.h>
+#include <winbase.h>
+#include <msi.h>
+#include <msiquery.h>
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *reserved)
{
return TRUE;
}
+
+UINT WINAPI test_retval(MSIHANDLE hinst)
+{
+ char prop[10];
+ DWORD len = sizeof(prop);
+ UINT retval;
+
+ MsiGetPropertyA(hinst, "TEST_RETVAL", prop, &len);
+ sscanf(prop, "%u", &retval);
+ return retval;
+}
diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c
index 9d2a75b..cc1b536 100644
--- a/dlls/msi/tests/install.c
+++ b/dlls/msi/tests/install.c
@@ -70,6 +70,8 @@ static CHAR COMMON_FILES_DIR[MAX_PATH];
static CHAR APP_DATA_DIR[MAX_PATH];
static CHAR WINDOWS_DIR[MAX_PATH];
+static const char *customdll;
+
/* msi database data */
static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
@@ -690,6 +692,16 @@ static const CHAR wrv_component_dat[] = "Component\tComponentId\tDirectory_\tAtt
"Component\tComponent\n"
"augustus\t\tMSITESTDIR\t0\t\taugustus\n";
+static const CHAR ca1_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
+ "s72\tS255\tI2\n"
+ "InstallExecuteSequence\tAction\n"
+ "testretval\t\t710\n";
+
+static const CHAR ca1_custom_action_dat[] = "Action\tType\tSource\tTarget\n"
+ "s72\ti2\tS64\tS0\n"
+ "CustomAction\tAction\n"
+ "testretval\t1\tcustom.dll\ttest_retval\n";
+
static const CHAR ca51_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
"s72\tS38\ts72\ti2\tS255\tS72\n"
"Component\tComponent\n"
@@ -1689,6 +1701,13 @@ static const msi_table sf_tables[] =
ADD_TABLE(property),
};
+static const msi_table ca1_tables[] =
+{
+ ADD_TABLE(property),
+ ADD_TABLE(ca1_install_exec_seq),
+ ADD_TABLE(ca1_custom_action),
+};
+
static const msi_table ca51_tables[] =
{
ADD_TABLE(ca51_component),
@@ -2595,6 +2614,29 @@ static LONG delete_key( HKEY key, LPCSTR subkey, REGSAM access )
return RegDeleteKeyA( key, subkey );
}
+static char *load_resource(const char *name)
+{
+ static char path[MAX_PATH];
+ DWORD written;
+ HANDLE file;
+ HRSRC res;
+ void *ptr;
+
+ GetTempFileNameA(".", name, 0, path);
+
+ file = CreateFileA(path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", path, GetLastError());
+
+ res = FindResourceA(NULL, name, (LPCSTR)RT_RCDATA);
+ ok( res != 0, "couldn't find resource\n" );
+ ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
+ WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
+ ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
+ CloseHandle( file );
+
+ return path;
+}
+
static void test_MsiInstallProduct(void)
{
UINT r;
@@ -4020,6 +4062,59 @@ error:
DeleteFileA("augustus");
}
+static void add_custom_dll(void)
+{
+ MSIHANDLE hdb = 0, record;
+ UINT res;
+
+ res = MsiOpenDatabaseW(msifileW, MSIDBOPEN_TRANSACT, &hdb);
+ ok(res == ERROR_SUCCESS, "failed to open db: %u\n", res);
+
+ res = run_query(hdb, 0, "CREATE TABLE `Binary` (`Name` CHAR(72) NOT NULL, `Data` OBJECT NOT NULL PRIMARY KEY `Name`)");
+ ok(res == ERROR_SUCCESS, "failed to create Binary table: %u\n", res);
+
+ record = MsiCreateRecord(1);
+ res = MsiRecordSetStreamA(record, 1, customdll);
+ ok(res == ERROR_SUCCESS, "failed to add %s to stream: %u\n", customdll, res);
+
+ res = run_query(hdb, record, "INSERT INTO `Binary` (`Name`, `Data`) VALUES ('custom.dll', ?)");
+ ok(res == ERROR_SUCCESS, "failed to insert into Binary table: %u\n", res);
+
+ res = MsiDatabaseCommit(hdb);
+ ok(res == ERROR_SUCCESS, "failed to commit database: %u\n", res);
+
+ MsiCloseHandle(record);
+ MsiCloseHandle(hdb);
+}
+
+static void test_customaction1(void)
+{
+ UINT r;
+
+ create_database(msifile, ca1_tables, sizeof(ca1_tables) / sizeof(msi_table));
+ add_custom_dll();
+
+ MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
+
+ r = MsiInstallProductA(msifile, "TEST_RETVAL=0");
+ ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
+
+ r = MsiInstallProductA(msifile, "TEST_RETVAL=1626"); /* ERROR_FUNCTION_NOT_CALLED*/
+ ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
+
+ r = MsiInstallProductA(msifile, "TEST_RETVAL=1602");
+ ok(r == ERROR_INSTALL_USEREXIT, "Expected ERROR_INSTALL_USEREXIT, got %u\n", r);
+
+ r = MsiInstallProductA(msifile, "TEST_RETVAL=259"); /* ERROR_NO_MORE_ITEMS */
+ ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
+
+ /* any other error maps to ERROR_INSTALL_FAILURE */
+ r = MsiInstallProductA(msifile, "TEST_RETVAL=1");
+ ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
+
+ DeleteFileA(msifile);
+}
+
static void test_customaction51(void)
{
UINT r;
@@ -5996,6 +6091,8 @@ START_TEST(install)
lstrcatA(log_file, "\\msitest.log");
MsiEnableLogA(INSTALLLOGMODE_FATALEXIT, log_file, 0);
+ customdll = load_resource("custom.dll");
+
if (pSRSetRestorePointA) /* test has side-effects on win2k3 that cause failures in following tests */
test_MsiInstallProduct();
test_MsiSetComponentState();
@@ -6015,6 +6112,7 @@ START_TEST(install)
test_adminprops();
test_missingcab();
test_sourcefolder();
+ test_customaction1();
test_customaction51();
test_installstate();
test_sourcepath();
@@ -6040,6 +6138,8 @@ START_TEST(install)
test_feature_tree();
test_deferred_action();
+ DeleteFileA(customdll);
+
DeleteFileA(log_file);
if (pSRSetRestorePointA && !pMsiGetComponentPathExA && ret)
--
2.7.4
More information about the wine-devel
mailing list