ole32/tests: Some tests for returned apartment type in implicit MTA case.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2016-12-25 01:19:07 +03:00 committed by Alexandre Julliard
parent 80d2edd584
commit 3e2ed9c761
1 changed files with 48 additions and 0 deletions

View File

@ -617,6 +617,26 @@ static DWORD CALLBACK ole_initialize_thread(LPVOID pv)
return hr;
}
#define test_apt_type(t, q, t_t, t_q) _test_apt_type(t, q, t_t, t_q, __LINE__)
static void _test_apt_type(APTTYPE expected_type, APTTYPEQUALIFIER expected_qualifier, BOOL todo_type,
BOOL todo_qualifier, int line)
{
APTTYPEQUALIFIER qualifier = ~0u;
APTTYPE type = ~0u;
HRESULT hr;
if (!pCoGetApartmentType)
return;
hr = pCoGetApartmentType(&type, &qualifier);
ok_(__FILE__, line)(hr == S_OK || hr == CO_E_NOTINITIALIZED, "Unexpected return code: 0x%08x\n", hr);
todo_wine_if(todo_type)
ok_(__FILE__, line)(type == expected_type, "Wrong apartment type %d, expected %d\n", type, expected_type);
todo_wine_if(todo_qualifier)
ok_(__FILE__, line)(qualifier == expected_qualifier, "Wrong apartment qualifier %d, expected %d\n", qualifier,
expected_qualifier);
}
static void test_CoCreateInstance(void)
{
HRESULT hr;
@ -661,6 +681,8 @@ static void test_CoCreateInstance(void)
/* show that COM doesn't have to be initialized for multi-threaded apartments if another
thread has already done so */
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
info.wait = CreateEventA(NULL, TRUE, FALSE, NULL);
ok(info.wait != NULL, "CreateEvent failed with error %d\n", GetLastError());
@ -672,6 +694,8 @@ static void test_CoCreateInstance(void)
ok( !WaitForSingleObject(info.wait, 10000 ), "wait timed out\n" );
test_apt_type(APTTYPE_MTA, APTTYPEQUALIFIER_IMPLICIT_MTA, TRUE, TRUE);
pUnk = (IUnknown *)0xdeadbeef;
hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
ok(hr == S_OK, "CoCreateInstance should have returned S_OK instead of 0x%08x\n", hr);
@ -687,6 +711,8 @@ static void test_CoCreateInstance(void)
CloseHandle(thread);
CloseHandle(info.wait);
CloseHandle(info.stop);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
}
static void test_CoGetClassObject(void)
@ -713,6 +739,8 @@ static void test_CoGetClassObject(void)
/* show that COM doesn't have to be initialized for multi-threaded apartments if another
thread has already done so */
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
info.wait = CreateEventA(NULL, TRUE, FALSE, NULL);
ok(info.wait != NULL, "CreateEvent failed with error %d\n", GetLastError());
@ -724,6 +752,8 @@ static void test_CoGetClassObject(void)
ok( !WaitForSingleObject(info.wait, 10000), "wait timed out\n" );
test_apt_type(APTTYPE_MTA, APTTYPEQUALIFIER_IMPLICIT_MTA, TRUE, TRUE);
pUnk = (IUnknown *)0xdeadbeef;
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
if(hr == REGDB_E_CLASSNOTREG)
@ -745,6 +775,8 @@ static void test_CoGetClassObject(void)
CloseHandle(info.wait);
CloseHandle(info.stop);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
if (!pRegOverridePredefKey)
{
win_skip("RegOverridePredefKey not available\n");
@ -1798,6 +1830,8 @@ static void test_CoGetObjectContext(void)
/* show that COM doesn't have to be initialized for multi-threaded apartments if another
thread has already done so */
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
info.wait = CreateEventA(NULL, TRUE, FALSE, NULL);
ok(info.wait != NULL, "CreateEvent failed with error %d\n", GetLastError());
@ -1809,6 +1843,8 @@ static void test_CoGetObjectContext(void)
ok( !WaitForSingleObject(info.wait, 10000), "wait timed out\n" );
test_apt_type(APTTYPE_MTA, APTTYPEQUALIFIER_IMPLICIT_MTA, TRUE, TRUE);
pComThreadingInfo = NULL;
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr);
@ -1842,8 +1878,12 @@ static void test_CoGetObjectContext(void)
CloseHandle(info.wait);
CloseHandle(info.stop);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
test_apt_type(APTTYPE_MAINSTA, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo);
ok_ole_success(hr, "CoGetObjectContext");
@ -2028,6 +2068,8 @@ static void test_CoGetContextToken(void)
/* show that COM doesn't have to be initialized for multi-threaded apartments if another
thread has already done so */
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
info.wait = CreateEventA(NULL, TRUE, FALSE, NULL);
ok(info.wait != NULL, "CreateEvent failed with error %d\n", GetLastError());
@ -2039,6 +2081,8 @@ static void test_CoGetContextToken(void)
ok( !WaitForSingleObject(info.wait, 10000), "wait timed out\n" );
test_apt_type(APTTYPE_MTA, APTTYPEQUALIFIER_IMPLICIT_MTA, TRUE, TRUE);
token = 0;
hr = pCoGetContextToken(&token);
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr);
@ -2059,8 +2103,12 @@ static void test_CoGetContextToken(void)
CloseHandle(info.wait);
CloseHandle(info.stop);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
CoInitialize(NULL);
test_apt_type(APTTYPE_MAINSTA, APTTYPEQUALIFIER_NONE, FALSE, FALSE);
hr = pCoGetContextToken(NULL);
ok(hr == E_POINTER, "Expected E_POINTER, got 0x%08x\n", hr);