Paul Vriens : msi/tests: Create a system restore point when needed.

Alexandre Julliard julliard at winehq.org
Tue Sep 2 08:33:13 CDT 2008


Module: wine
Branch: master
Commit: c559895ce901dc9edc69f851309d9d4687728ddd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c559895ce901dc9edc69f851309d9d4687728ddd

Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date:   Mon Sep  1 12:16:41 2008 +0200

msi/tests: Create a system restore point when needed.

---

 dlls/msi/tests/install.c |   59 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c
index e335cfa..3ff3420 100644
--- a/dlls/msi/tests/install.c
+++ b/dlls/msi/tests/install.c
@@ -29,6 +29,7 @@
 #include <msi.h>
 #include <fci.h>
 #include <objidl.h>
+#include <srrestoreptapi.h>
 
 #include "wine/test.h"
 
@@ -39,6 +40,10 @@ static UINT (WINAPI *pMsiSourceListEnumSourcesA)
 static UINT (WINAPI *pMsiSourceListGetInfoA)
     (LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD, LPCSTR, LPSTR, LPDWORD);
 
+static HMODULE hsrclient = 0;
+static BOOL (WINAPI *pSRRemoveRestorePoint)(DWORD);
+static BOOL (WINAPI *pSRSetRestorePointA)(RESTOREPOINTINFOA*, STATEMGRSTATUS*);
+
 static const char *msifile = "msitest.msi";
 static const char *msifile2 = "winetest2.msi";
 static const char *mstfile = "winetest.mst";
@@ -1271,14 +1276,18 @@ static void init_functionpointers(void)
 {
     HMODULE hmsi = GetModuleHandleA("msi.dll");
 
-#define GET_PROC(func) \
-    p ## func = (void*)GetProcAddress(hmsi, #func); \
+#define GET_PROC(mod, func) \
+    p ## func = (void*)GetProcAddress(mod, #func); \
     if(!p ## func) \
       trace("GetProcAddress(%s) failed\n", #func);
 
-    GET_PROC(MsiQueryComponentStateA);
-    GET_PROC(MsiSourceListEnumSourcesA);
-    GET_PROC(MsiSourceListGetInfoA);
+    GET_PROC(hmsi, MsiQueryComponentStateA);
+    GET_PROC(hmsi, MsiSourceListEnumSourcesA);
+    GET_PROC(hmsi, MsiSourceListGetInfoA);
+
+    hsrclient = LoadLibraryA("srclient.dll");
+    GET_PROC(hsrclient, SRRemoveRestorePoint);
+    GET_PROC(hsrclient, SRSetRestorePointA);
 
 #undef GET_PROC
 }
@@ -1618,6 +1627,27 @@ static void check_service_is_installed(void)
     CloseServiceHandle(scm);
 }
 
+static BOOL notify_system_change(DWORD event_type, STATEMGRSTATUS *status)
+{
+    RESTOREPOINTINFOA spec;
+
+    spec.dwEventType = event_type;
+    spec.dwRestorePtType = APPLICATION_INSTALL;
+    spec.llSequenceNumber = status->llSequenceNumber;
+    lstrcpyA(spec.szDescription, "msitest restore point");
+
+    return pSRSetRestorePointA(&spec, status);
+}
+
+static void remove_restore_point(DWORD seq_number)
+{
+    DWORD res;
+
+    res = pSRRemoveRestorePoint(seq_number);
+    if (res != ERROR_SUCCESS)
+        trace("Failed to remove the restore point : %08x\n", res);
+}
+
 static void test_MsiInstallProduct(void)
 {
     UINT r;
@@ -5402,6 +5432,8 @@ START_TEST(install)
 {
     DWORD len;
     char temp_path[MAX_PATH], prev_path[MAX_PATH];
+    STATEMGRSTATUS status;
+    BOOL ret = FALSE;
 
     init_functionpointers();
 
@@ -5417,6 +5449,15 @@ START_TEST(install)
 
     get_program_files_dir(PROG_FILES_DIR, COMMON_FILES_DIR);
 
+    /* Create a restore point ourselves so we circumvent the multitude of restore points
+     * that would have been created by all the installation and removal tests.
+     */
+    if (pSRSetRestorePointA)
+    {
+        memset(&status, 0, sizeof(status));
+        ret = notify_system_change(BEGIN_NESTED_SYSTEM_CHANGE, &status);
+    }
+
     test_MsiInstallProduct();
     test_MsiSetComponentState();
     test_packagecoltypes();
@@ -5453,5 +5494,13 @@ START_TEST(install)
     test_MsiConfigureProductEx();
     test_missingcomponent();
 
+    if (pSRSetRestorePointA && ret)
+    {
+        ret = notify_system_change(END_NESTED_SYSTEM_CHANGE, &status);
+        if (ret)
+            remove_restore_point(status.llSequenceNumber);
+    }
+    FreeLibrary(hsrclient);
+
     SetCurrentDirectoryA(prev_path);
 }




More information about the wine-cvs mailing list