msi/tests: Skip some source tests if a required product key cannot be created.
[wine] / dlls / atl / tests / atl_ax.c
1 /*
2  * Unit tests for Active Template Library ActiveX functions
3  *
4  * Copyright 2010 Andrew Nguyen
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include <wine/test.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winuser.h>
30 #include <wingdi.h>
31 #include <winnls.h>
32 #include <winerror.h>
33 #include <winnt.h>
34 #include <wtypes.h>
35 #include <olectl.h>
36 #include <ocidl.h>
37 #include <exdisp.h>
38
39 HRESULT WINAPI AtlAxAttachControl(IUnknown *, HWND, IUnknown **);
40
41 static ATOM register_class(void)
42 {
43     WNDCLASSA wndclassA;
44
45     wndclassA.style = 0;
46     wndclassA.lpfnWndProc = DefWindowProc;
47     wndclassA.cbClsExtra = 0;
48     wndclassA.cbWndExtra = 0;
49     wndclassA.hInstance = GetModuleHandleA(NULL);
50     wndclassA.hIcon = NULL;
51     wndclassA.hCursor = LoadCursorA(NULL, IDC_ARROW);
52     wndclassA.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
53     wndclassA.lpszMenuName = NULL;
54     wndclassA.lpszClassName = "WineAtlTestClass";
55
56     return RegisterClassA(&wndclassA);
57 }
58
59 static void test_AtlAxAttachControl(void)
60 {
61     HWND hwnd = CreateWindowA("WineAtlTestClass", "Wine ATL Test Window", 0,
62                               CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
63                               CW_USEDEFAULT, NULL, NULL, NULL, NULL);
64     HRESULT hr;
65     IUnknown *pObj, *pContainer;
66
67     hr = AtlAxAttachControl(NULL, NULL, NULL);
68     ok(hr == E_INVALIDARG, "Expected AtlAxAttachControl to return E_INVALIDARG, got 0x%08x\n", hr);
69
70     pContainer = (IUnknown *)0xdeadbeef;
71     hr = AtlAxAttachControl(NULL, NULL, &pContainer);
72     ok(hr == E_INVALIDARG, "Expected AtlAxAttachControl to return E_INVALIDARG, got 0x%08x\n", hr);
73     ok(pContainer == (IUnknown *)0xdeadbeef,
74        "Expected the output container pointer to be untouched, got %p\n", pContainer);
75
76     hr = AtlAxAttachControl(NULL, hwnd, NULL);
77     ok(hr == E_INVALIDARG, "Expected AtlAxAttachControl to return E_INVALIDARG, got 0x%08x\n", hr);
78
79     hr = CoCreateInstance(&CLSID_WebBrowser, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
80                           &IID_IOleObject, (void **)&pObj);
81     ok(hr == S_OK, "Expected CoCreateInstance to return S_OK, got 0x%08x\n", hr);
82
83     if (FAILED(hr))
84     {
85         skip("Couldn't obtain a test IOleObject instance\n");
86         return;
87     }
88
89     hr = AtlAxAttachControl(pObj, NULL, NULL);
90     todo_wine
91     ok(hr == S_FALSE, "Expected AtlAxAttachControl to return S_FALSE, got 0x%08x\n", hr);
92
93     pContainer = (IUnknown *)0xdeadbeef;
94     hr = AtlAxAttachControl(pObj, NULL, &pContainer);
95     todo_wine
96     ok(hr == S_FALSE, "Expected AtlAxAttachControl to return S_FALSE, got 0x%08x\n", hr);
97     ok(pContainer != (IUnknown *)0xdeadbeef &&
98        pContainer != NULL,
99        "Expected the output container pointer to be initialized to non-NULL, got %p\n", pContainer);
100
101     if (pContainer != (IUnknown *)0xdeadbeef && pContainer != NULL)
102         IUnknown_Release(pContainer);
103
104     hr = AtlAxAttachControl(pObj, hwnd, NULL);
105     ok(hr == S_OK, "Expected AtlAxAttachControl to return S_OK, got 0x%08x\n", hr);
106
107     IUnknown_Release(pObj);
108
109     DestroyWindow(hwnd);
110 }
111
112 START_TEST(atl_ax)
113 {
114     if (!register_class())
115         return;
116
117     CoInitialize(NULL);
118
119     test_AtlAxAttachControl();
120
121     CoUninitialize();
122 }