[PATCH] rtworkq/tests: Load CoGetApartmentType() dynamically.

Francois Gouget fgouget at codeweavers.com
Wed Apr 21 13:18:09 CDT 2021


The main goal is to get WineTest reports to state that the test was
skipped because rtworkq.dll is missing rather than because of a
possibly unrelated API.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
Restating differently, currently looking at a WineTest report (or
test.winehq.org) I see that the test was skipped on Vista because
of a missing API and I am left to guess whether rtworkq.dll was
available at all.

This patch takes out the guessing part even if nothing can be tested 
(so far).
---
 dlls/rtworkq/tests/rtworkq.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/dlls/rtworkq/tests/rtworkq.c b/dlls/rtworkq/tests/rtworkq.c
index 627e024d761..6337eb35f3d 100644
--- a/dlls/rtworkq/tests/rtworkq.c
+++ b/dlls/rtworkq/tests/rtworkq.c
@@ -25,6 +25,9 @@
 
 #include "wine/test.h"
 
+/* functions that are not present on all versions of Windows */
+static HRESULT (WINAPI * pCoGetApartmentType)(APTTYPE *type, APTTYPEQUALIFIER *qualifier);
+
 static void test_platform_init(void)
 {
     APTTYPEQUALIFIER qualifier;
@@ -32,13 +35,13 @@ static void test_platform_init(void)
     HRESULT hr;
 
     /* Startup initializes MTA. */
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr);
 
     hr = RtwqStartup();
     ok(hr == S_OK, "Failed to start up, hr %#x.\n", hr);
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == S_OK || broken(FAILED(hr)) /* Win8 */, "Unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ok(apttype == APTTYPE_MTA && qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
@@ -47,14 +50,14 @@ static void test_platform_init(void)
     hr = RtwqShutdown();
     ok(hr == S_OK, "Failed to shut down, hr %#x.\n", hr);
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr);
 
     /* Try with STA initialized before startup. */
     hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
     ok(hr == S_OK, "Failed to initialize, hr %#x.\n", hr);
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
     ok(apttype == APTTYPE_MAINSTA && qualifier == APTTYPEQUALIFIER_NONE,
             "Unexpected apartment type %d, qualifier %d.\n", apttype, qualifier);
@@ -62,7 +65,7 @@ static void test_platform_init(void)
     hr = RtwqStartup();
     ok(hr == S_OK, "Failed to start up, hr %#x.\n", hr);
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
     ok(apttype == APTTYPE_MAINSTA && qualifier == APTTYPEQUALIFIER_NONE,
             "Unexpected apartment type %d, qualifier %d.\n", apttype, qualifier);
@@ -76,7 +79,7 @@ static void test_platform_init(void)
     hr = RtwqStartup();
     ok(hr == S_OK, "Failed to start up, hr %#x.\n", hr);
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == S_OK || broken(FAILED(hr)) /* Win8 */, "Unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ok(apttype == APTTYPE_MTA && qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
@@ -85,14 +88,14 @@ static void test_platform_init(void)
     hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
     ok(hr == S_OK, "Failed to initialize, hr %#x.\n", hr);
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
     ok(apttype == APTTYPE_MAINSTA && qualifier == APTTYPEQUALIFIER_NONE,
             "Unexpected apartment type %d, qualifier %d.\n", apttype, qualifier);
 
     CoUninitialize();
 
-    hr = CoGetApartmentType(&apttype, &qualifier);
+    hr = pCoGetApartmentType(&apttype, &qualifier);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
     ok(apttype == APTTYPE_MTA && qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
             "Unexpected apartment type %d, qualifier %d.\n", apttype, qualifier);
@@ -103,5 +106,13 @@ static void test_platform_init(void)
 
 START_TEST(rtworkq)
 {
+    HMODULE hOle32 = GetModuleHandleA("ole32");
+    pCoGetApartmentType = (void*)GetProcAddress(hOle32, "CoGetApartmentType");
+    if (!pCoGetApartmentType)
+    {
+        win_skip("CoGetApartmentType() is missing\n");
+        return;
+    }
+
     test_platform_init();
 }
-- 
2.20.1



More information about the wine-devel mailing list