Based on a patch by Paul Gofman.
Signed-off-by: Alistair Leslie-Hughes leslie_alistair@hotmail.com --- dlls/user32/tests/Makefile.in | 2 +- dlls/user32/tests/win.c | 182 ++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 1 deletion(-)
diff --git a/dlls/user32/tests/Makefile.in b/dlls/user32/tests/Makefile.in index dd101d69f3c..73f692b9d4b 100644 --- a/dlls/user32/tests/Makefile.in +++ b/dlls/user32/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = user32.dll -IMPORTS = user32 gdi32 advapi32 hid +IMPORTS = user32 gdi32 advapi32 hid ole32 imm32
C_SRCS = \ broadcast.c \ diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 47864340e39..3d570a611a4 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -19,6 +19,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#define COBJMACROS
#include <assert.h> #include <limits.h> @@ -31,6 +32,10 @@ #include "wingdi.h" #include "winuser.h" #include "winreg.h" +#include "objbase.h" +#include "initguid.h" +#include "wincodec.h" +#include "imm.h"
#include "wine/test.h"
@@ -11894,6 +11899,181 @@ static void test_cancel_mode(void) DestroyWindow(hwnd2); }
+static LRESULT CALLBACK TestWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + return DefWindowProcA(hwnd, uMsg, wParam, lParam); +} + +static DWORD WINAPI window_create_noime_thread(LPVOID data) +{ + HWND hwnd; + HRESULT hr; + IUnknown *unk; + + /* Show that Disabling IME stops the implicit MTA creation. */ + ImmDisableIME(GetCurrentThreadId()); + + hwnd = CreateWindowExA(0, "Test class", "Test window", WS_VISIBLE, 0, 0, 100, 100, + GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL); + + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&unk); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + DestroyWindow(hwnd); + + return 0; +} + +static DWORD WINAPI window_create_setwindowpos_thread(LPVOID data) +{ + APTTYPEQUALIFIER apttypequal; + APTTYPE apttype; + HWND hwnd; + HRESULT hr; + IUnknown *unk; + + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + hwnd = CreateWindowExA(0, "Test class", "Test window", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 100, 100, + GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL); + + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&unk); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + /* Showing the window actually causes the implicit MTA */ + SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW); + + hr = CoGetApartmentType(&apttype, &apttypequal); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + todo_wine ok(apttype == APTTYPE_MAINSTA && apttypequal == APTTYPEQUALIFIER_NONE, "Unexpected %u/%u\n", apttype, apttypequal); + + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&unk); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (hr == S_OK) + IUnknown_Release(unk); + + hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(apttype == APTTYPE_MTA && apttypequal == APTTYPEQUALIFIER_NONE, "Unexpected %u/%u\n", apttype, apttypequal); + CoUninitialize(); + + DestroyWindow(hwnd); + + return 0; +} + +static DWORD WINAPI window_create_show_window_thread(LPVOID data) +{ + APTTYPEQUALIFIER apttypequal; + APTTYPE apttype; + HWND hwnd; + HRESULT hr; + IUnknown *unk; + + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + hwnd = CreateWindowExA(0, "Test class", "Test window", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 100, 100, + GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL); + + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&unk); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + /* Showing the window actually causes the implicit MTA */ + ShowWindow(hwnd, SW_SHOW); + + hr = CoGetApartmentType(&apttype, &apttypequal); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + todo_wine ok(apttype == APTTYPE_MAINSTA && apttypequal == APTTYPEQUALIFIER_NONE, "Unexpected %u/%u\n", apttype, apttypequal); + + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&unk); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (hr == S_OK) + IUnknown_Release(unk); + + DestroyWindow(hwnd); + + return 0; +} + +static DWORD WINAPI window_create_visible_thread(LPVOID data) +{ + APTTYPEQUALIFIER apttypequal; + APTTYPE apttype; + HWND hwnd; + HRESULT hr; + IUnknown *unk; + + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + hwnd = CreateWindowExA(0, "Test class", "Test window", WS_VISIBLE, 0, 0, 100, 100, + GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL); + + hr = CoGetApartmentType(&apttype, &apttypequal); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + todo_wine ok(apttype == APTTYPE_MAINSTA && apttypequal == APTTYPEQUALIFIER_NONE, "Unexpected %u/%u\n", apttype, apttypequal); + + hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&unk); + todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (hr == S_OK) + IUnknown_Release(unk); + + DestroyWindow(hwnd); + + return 0; +} + +static void test_implicit_mta(void) +{ + APTTYPEQUALIFIER apttypequal; + APTTYPE apttype; + WNDCLASSA clsA; + HRESULT hr; + HANDLE thread; + + clsA.style = 0; + clsA.lpfnWndProc = TestWindowProc; + clsA.cbClsExtra = 0; + clsA.cbWndExtra = 0; + clsA.hInstance = GetModuleHandleA(NULL); + clsA.hIcon = 0; + clsA.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW); + clsA.hbrBackground = GetStockObject(WHITE_BRUSH); + clsA.lpszMenuName = NULL; + clsA.lpszClassName = "Test class"; + + RegisterClassA(&clsA); + + hr = CoGetApartmentType(&apttype, &apttypequal); + ok(hr == CO_E_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + + thread = CreateThread(NULL, 0, window_create_noime_thread, NULL, 0, NULL); + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + + thread = CreateThread(NULL, 0, window_create_setwindowpos_thread, NULL, 0, NULL); + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + + thread = CreateThread(NULL, 0, window_create_show_window_thread, NULL, 0, NULL); + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + + thread = CreateThread(NULL, 0, window_create_visible_thread, NULL, 0, NULL); + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); +} + START_TEST(win) { char **argv; @@ -11941,6 +12121,8 @@ START_TEST(win) return; }
+ test_implicit_mta(); + if (!RegisterWindowClasses()) assert(0);
hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
I think title is confusing, first because "joining implicit MTA" is internal apartment logic concept, and is not what's happening here. And second because it's not an MTA that's being created by user32 initialization logic.
Another thing is that you don't need to CoCreateInstance() anything as far as I can tell, CoGetApartmentType() tells you everything already.
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=84190
Your paranoid android.
=== w2008s64 (32 bit report) ===
user32: win: Timeout
=== w1064 (32 bit report) ===
user32: win.c:3936: Test failed: hwnd 002A0218/002A0218 message 0200 win.c:3938: Test failed: wparam 0 win.c:3949: Test failed: hwnd 002A0218/002A0218 message 0203 win.c:3953: Test failed: message 0202 available
=== wvistau64 (64 bit report) ===
user32: win: Timeout
=== w2008s64 (64 bit report) ===
user32: win: Timeout