Rob Shearman : ole32: Add tests for CoGetObjectContext.

Alexandre Julliard julliard at winehq.org
Fri Nov 2 08:10:16 CDT 2007


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

Author: Rob Shearman <rob at codeweavers.com>
Date:   Thu Nov  1 13:26:56 2007 +0000

ole32: Add tests for CoGetObjectContext.

---

 dlls/ole32/tests/compobj.c |   57 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c
index 12fe4f6..d7a88f7 100644
--- a/dlls/ole32/tests/compobj.c
+++ b/dlls/ole32/tests/compobj.c
@@ -33,6 +33,7 @@
 
 /* functions that are not present on all versions of Windows */
 HRESULT (WINAPI * pCoInitializeEx)(LPVOID lpReserved, DWORD dwCoInit);
+HRESULT (WINAPI * pCoGetObjectContext)(REFIID riid, LPVOID *ppv);
 
 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
@@ -938,10 +939,65 @@ static void test_CoFreeUnusedLibraries(void)
     CoUninitialize();
 }
 
+static void test_CoGetObjectContext(void)
+{
+    HRESULT hr;
+    ULONG refs;
+    IComThreadingInfo *pComThreadingInfo;
+    APTTYPE apttype;
+    THDTYPE thdtype;
+
+    if (!pCoGetObjectContext)
+    {
+        skip("CoGetObjectContext not present\n");
+        return;
+    }
+
+    hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
+    ok(hr == CO_E_NOTINITIALIZED, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
+    ok(pComThreadingInfo == NULL, "pComThreadingInfo should have been set to NULL\n");
+
+    pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+
+    hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
+    ok_ole_success(hr, "CoGetObjectContext");
+
+    hr = IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo, &apttype);
+    ok_ole_success(hr, "IComThreadingInfo_GetCurrentApartmentType");
+    ok(apttype == APTTYPE_MAINSTA, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype);
+
+    hr = IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo, &thdtype);
+    ok_ole_success(hr, "IComThreadingInfo_GetCurrentThreadType");
+    ok(thdtype == THDTYPE_PROCESSMESSAGES, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype);
+
+    refs = IComThreadingInfo_Release(pComThreadingInfo);
+    ok(refs == 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs);
+
+    CoUninitialize();
+
+    pCoInitializeEx(NULL, COINIT_MULTITHREADED);
+
+    hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
+    ok_ole_success(hr, "CoGetObjectContext");
+
+    hr = IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo, &apttype);
+    ok_ole_success(hr, "IComThreadingInfo_GetCurrentApartmentType");
+    ok(apttype == APTTYPE_MTA, "apartment type should be APTTYPE_MTA instead of %d\n", apttype);
+
+    hr = IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo, &thdtype);
+    ok_ole_success(hr, "IComThreadingInfo_GetCurrentThreadType");
+    ok(thdtype == THDTYPE_BLOCKMESSAGES, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype);
+
+    refs = IComThreadingInfo_Release(pComThreadingInfo);
+    ok(refs == 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs);
+
+    CoUninitialize();
+}
 
 START_TEST(compobj)
 {
     HMODULE hOle32 = GetModuleHandle("ole32");
+    pCoGetObjectContext = (void*)GetProcAddress(hOle32, "CoGetObjectContext");
     if (!(pCoInitializeEx = (void*)GetProcAddress(hOle32, "CoInitializeEx")))
     {
         trace("You need DCOM95 installed to run this test\n");
@@ -964,4 +1020,5 @@ START_TEST(compobj)
     test_CoRegisterClassObject();
     test_registered_object_thread_affinity();
     test_CoFreeUnusedLibraries();
+    test_CoGetObjectContext();
 }




More information about the wine-cvs mailing list