Francois Gouget : msi/tests: Tweak the get_user_sid() functions to simplify their use.

Alexandre Julliard julliard at winehq.org
Tue May 26 09:24:55 CDT 2009


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

Author: Francois Gouget <fgouget at free.fr>
Date:   Tue May 26 00:41:30 2009 +0200

msi/tests: Tweak the get_user_sid() functions to simplify their use.

Now the function deals with all errors and win_skips() itself.

---

 dlls/msi/tests/install.c |   49 +++++++++++++++++----------------------------
 dlls/msi/tests/package.c |   25 ++++++++++++++---------
 2 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c
index 933a145..2e03bf4 100644
--- a/dlls/msi/tests/install.c
+++ b/dlls/msi/tests/install.c
@@ -1346,26 +1346,35 @@ static BOOL check_win9x(void)
     return FALSE;
 }
 
-static void get_user_sid(LPSTR *usersid)
+static LPSTR get_user_sid(LPSTR *usersid)
 {
     HANDLE token;
     BYTE buf[1024];
     DWORD size;
     PTOKEN_USER user;
-    HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
+    static HMODULE hadvapi32 = NULL;
     static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
 
     *usersid = NULL;
-    pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
-    if (!pConvertSidToStringSidA)
-        return;
+    if (!hadvapi32)
+    {
+        hadvapi32 = GetModuleHandleA("advapi32.dll");
+        pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
+        if (!pConvertSidToStringSidA)
+        {
+            win_skip("ConvertSidToStringSidA is not available\n");
+            return NULL;
+        }
+    }
 
     OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
     size = sizeof(buf);
     GetTokenInformation(token, TokenUser, buf, size, &size);
     user = (PTOKEN_USER)buf;
     pConvertSidToStringSidA(user->User.Sid, usersid);
+    ok(*usersid != NULL, "pConvertSidToStringSidA failed lre=%d\n", GetLastError());
     CloseHandle(token);
+    return *usersid;
 }
 
 static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val)
@@ -2511,12 +2520,8 @@ static void test_publish_registerproduct(void)
     static const CHAR userugkey[] = "Software\\Microsoft\\Installer\\UpgradeCodes"
                                     "\\51AAE0C44620A5E4788506E91F249BD2";
 
-    get_user_sid(&usersid);
-    if (!usersid)
-    {
-        skip("ConvertSidToStringSidA is not available\n");
+    if (!get_user_sid(&usersid))
         return;
-    }
 
     get_date_str(date);
     GetTempPath(MAX_PATH, temp);
@@ -2756,12 +2761,8 @@ static void test_publish_publishproduct(void)
     static const CHAR machprod[] = "Installer\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB";
     static const CHAR machup[] = "Installer\\UpgradeCodes\\51AAE0C44620A5E4788506E91F249BD2";
 
-    get_user_sid(&usersid);
-    if (!usersid)
-    {
-        skip("ConvertSidToStringSidA is not available\n");
+    if (!get_user_sid(&usersid))
         return;
-    }
 
     GetTempPath(MAX_PATH, temp);
 
@@ -2952,12 +2953,8 @@ static void test_publish_publishfeatures(void)
     static const CHAR classfeat[] = "Software\\Classes\\Installer\\Features"
                                     "\\84A88FD7F6998CE40A22FB59F6B9C2BB";
 
-    get_user_sid(&usersid);
-    if (!usersid)
-    {
-        skip("ConvertSidToStringSidA is not available\n");
+    if (!get_user_sid(&usersid))
         return;
-    }
 
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
@@ -3114,12 +3111,8 @@ static void test_publish_registeruser(void)
         "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\"
         "UserData\\%s\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB\\InstallProperties";
 
-    get_user_sid(&usersid);
-    if (!usersid)
-    {
-        skip("ConvertSidToStringSidA is not available\n");
+    if (!get_user_sid(&usersid))
         return;
-    }
 
     get_owner_company(&owner, &company);
 
@@ -3197,12 +3190,8 @@ static void test_publish_processcomponents(void)
     static const CHAR compkey[] =
         "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Components";
 
-    get_user_sid(&usersid);
-    if (!usersid)
-    {
-        skip("ConvertSidToStringSidA is not available\n");
+    if (!get_user_sid(&usersid))
         return;
-    }
 
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c
index 308a9cc..21795d5 100644
--- a/dlls/msi/tests/package.c
+++ b/dlls/msi/tests/package.c
@@ -34,26 +34,35 @@ char CURR_DIR[MAX_PATH];
 
 static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR);
 
-static void get_user_sid(LPSTR *usersid)
+static LPSTR get_user_sid(LPSTR *usersid)
 {
     HANDLE token;
     BYTE buf[1024];
     DWORD size;
     PTOKEN_USER user;
-    HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
+    static HMODULE hadvapi32 = NULL;
     static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
 
     *usersid = NULL;
-    pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
-    if (!pConvertSidToStringSidA)
-        return;
+    if (!hadvapi32)
+    {
+        hadvapi32 = GetModuleHandleA("advapi32.dll");
+        pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
+        if (!pConvertSidToStringSidA)
+        {
+            win_skip("ConvertSidToStringSidA is not available\n");
+            return NULL;
+        }
+    }
 
     OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
     size = sizeof(buf);
     GetTokenInformation(token, TokenUser, buf, size, &size);
     user = (PTOKEN_USER)buf;
     pConvertSidToStringSidA(user->User.Sid, usersid);
+    ok(*usersid != NULL, "pConvertSidToStringSidA failed lre=%d\n", GetLastError());
     CloseHandle(token);
+    return *usersid;
 }
 
 /* RegDeleteTreeW from dlls/advapi32/registry.c */
@@ -7336,12 +7345,8 @@ static void test_appsearch_complocator(void)
     DWORD size;
     UINT r;
 
-    get_user_sid(&usersid);
-    if (!usersid)
-    {
-        skip("ConvertSidToStringSidA is not available\n");
+    if (!get_user_sid(&usersid))
         return;
-    }
 
     create_test_file("FileName1");
     create_test_file("FileName4");




More information about the wine-cvs mailing list