explorerframe: Add IOleWindow implementation.
[wine.git] / dlls / explorerframe / tests / nstc.c
blob6a72eb349ce0b47f3bd615f38826c12f811b8841
1 /*
2 * Unit tests for the NamespaceTree Control
4 * Copyright 2010 David Hedberg
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.
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.
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
21 #include <stdio.h>
23 #define COBJMACROS
25 #include "shlobj.h"
26 #include "wine/test.h"
28 static HWND hwnd;
30 /* "Intended for internal use" */
31 #define TVS_EX_NOSINGLECOLLAPSE 0x1
33 /* Returns FALSE if the NamespaceTreeControl failed to be instantiated. */
34 static BOOL test_initialization(void)
36 INameSpaceTreeControl *pnstc;
37 IOleWindow *pow;
38 IUnknown *punk;
39 HWND hwnd_host1;
40 LONG lres;
41 HRESULT hr;
42 RECT rc;
44 hr = CoCreateInstance(&CLSID_NamespaceTreeControl, NULL, CLSCTX_INPROC_SERVER,
45 &IID_INameSpaceTreeControl, (void**)&pnstc);
46 ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got 0x%08x\n", hr);
47 if(FAILED(hr))
49 return FALSE;
52 hr = INameSpaceTreeControl_Initialize(pnstc, NULL, NULL, 0);
53 ok(hr == HRESULT_FROM_WIN32(ERROR_TLW_WITH_WSCHILD), "Got (0x%08x)\n", hr);
55 hr = INameSpaceTreeControl_Initialize(pnstc, (HWND)0xDEADBEEF, NULL, 0);
56 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE), "Got (0x%08x)\n", hr);
58 ZeroMemory(&rc, sizeof(RECT));
59 hr = INameSpaceTreeControl_Initialize(pnstc, NULL, &rc, 0);
60 ok(hr == HRESULT_FROM_WIN32(ERROR_TLW_WITH_WSCHILD), "Got (0x%08x)\n", hr);
62 hr = INameSpaceTreeControl_Initialize(pnstc, (HWND)0xDEADBEEF, &rc, 0);
63 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE), "Got (0x%08x)\n", hr);
65 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleWindow, (void**)&pow);
66 ok(hr == S_OK, "Got (0x%08x)\n", hr);
67 if(SUCCEEDED(hr))
69 hr = IOleWindow_GetWindow(pow, &hwnd_host1);
70 ok(hr == S_OK, "Got (0x%08x)\n", hr);
71 ok(hwnd_host1 == NULL, "hwnd is not null.\n");
73 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
74 ok(hr == E_NOTIMPL, "Got (0x%08x)\n", hr);
75 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
76 ok(hr == E_NOTIMPL, "Got (0x%08x)\n", hr);
77 IOleWindow_Release(pow);
80 hr = INameSpaceTreeControl_Initialize(pnstc, hwnd, NULL, 0);
81 ok(hr == S_OK, "Got (0x%08x)\n", hr);
82 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleWindow, (void**)&pow);
83 ok(hr == S_OK, "Got 0x%08x\n", hr);
84 if(SUCCEEDED(hr))
86 static const CHAR namespacetree[] = "NamespaceTreeControl";
87 char buf[1024];
88 LONG style, expected_style;
89 HWND hwnd_tv;
90 hr = IOleWindow_GetWindow(pow, &hwnd_host1);
91 ok(hr == S_OK, "Got (0x%08x)\n", hr);
92 ok(hwnd_host1 != NULL, "hwnd_host1 is null.\n");
93 buf[0] = '\0';
94 GetClassNameA(hwnd_host1, buf, 1024);
95 ok(!lstrcmpA(namespacetree, buf), "Class name was %s\n", buf);
97 expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
98 style = GetWindowLongPtrW(hwnd_host1, GWL_STYLE);
99 ok(style == expected_style, "Got style %08x\n", style);
101 expected_style = 0;
102 style = GetWindowLongPtrW(hwnd_host1, GWL_EXSTYLE);
103 ok(style == expected_style, "Got style %08x\n", style);
105 expected_style = 0;
106 style = SendMessageW(hwnd_host1, TVM_GETEXTENDEDSTYLE, 0, 0);
107 ok(style == expected_style, "Got 0x%08x\n", style);
109 hwnd_tv = FindWindowExW(hwnd_host1, NULL, WC_TREEVIEWW, NULL);
110 ok(hwnd_tv != NULL, "Failed to get treeview hwnd.\n");
111 if(hwnd_tv)
113 expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
114 WS_CLIPCHILDREN | WS_TABSTOP | TVS_NOHSCROLL |
115 TVS_NONEVENHEIGHT | TVS_INFOTIP | TVS_TRACKSELECT | TVS_EDITLABELS;
116 style = GetWindowLongPtrW(hwnd_tv, GWL_STYLE);
117 ok(style == expected_style, "Got style %08x\n", style);
119 expected_style = 0;
120 style = GetWindowLongPtrW(hwnd_tv, GWL_EXSTYLE);
121 ok(style == expected_style, "Got style %08x\n", style);
123 expected_style = TVS_EX_NOSINGLECOLLAPSE | TVS_EX_DOUBLEBUFFER |
124 TVS_EX_RICHTOOLTIP | TVS_EX_DRAWIMAGEASYNC;
125 style = SendMessageW(hwnd_tv, TVM_GETEXTENDEDSTYLE, 0, 0);
126 todo_wine ok(style == expected_style, "Got 0x%08x\n", style);
129 IOleWindow_Release(pow);
132 if(0)
134 /* The control can be initialized again without crashing, but
135 * the reference counting will break. */
136 hr = INameSpaceTreeControl_Initialize(pnstc, hwnd, &rc, 0);
137 ok(hr == S_OK, "Got (0x%08x)\n", hr);
138 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleWindow, (void**)&pow);
139 if(SUCCEEDED(hr))
141 HWND hwnd_host2;
142 hr = IOleWindow_GetWindow(pow, &hwnd_host2);
143 ok(hr == S_OK, "Got (0x%08x)\n", hr);
144 ok(hwnd_host1 != hwnd_host2, "Same hwnd.\n");
145 IOleWindow_Release(pow);
149 /* Some "random" interfaces */
150 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceObject, (void**)&punk);
151 ok(hr == E_NOINTERFACE || hr == S_OK /* vista, w2k8 */, "Got (0x%08x)\n", hr);
152 if(SUCCEEDED(hr)) IUnknown_Release(punk);
153 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceActiveObject, (void**)&punk);
154 ok(hr == E_NOINTERFACE || hr == S_OK /* vista, w2k8 */, "Got (0x%08x)\n", hr);
155 if(SUCCEEDED(hr)) IUnknown_Release(punk);
156 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceObjectWindowless, (void**)&punk);
157 ok(hr == E_NOINTERFACE || hr == S_OK /* vista, w2k8 */, "Got (0x%08x)\n", hr);
158 if(SUCCEEDED(hr)) IUnknown_Release(punk);
160 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceUIWindow, (void**)&punk);
161 ok(hr == E_NOINTERFACE, "Got (0x%08x)\n", hr);
162 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceFrame, (void**)&punk);
163 ok(hr == E_NOINTERFACE, "Got (0x%08x)\n", hr);
164 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceSite, (void**)&punk);
165 ok(hr == E_NOINTERFACE, "Got (0x%08x)\n", hr);
166 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceSiteEx, (void**)&punk);
167 ok(hr == E_NOINTERFACE, "Got (0x%08x)\n", hr);
168 hr = INameSpaceTreeControl_QueryInterface(pnstc, &IID_IOleInPlaceSiteWindowless, (void**)&punk);
169 ok(hr == E_NOINTERFACE, "Got (0x%08x)\n", hr);
171 /* On windows, the reference count won't go to zero until the
172 * window is destroyed. */
173 INameSpaceTreeControl_AddRef(pnstc);
174 lres = INameSpaceTreeControl_Release(pnstc);
175 ok(lres > 1, "Reference count was (%d).\n", lres);
177 DestroyWindow(hwnd_host1);
178 lres = INameSpaceTreeControl_Release(pnstc);
179 ok(!lres, "lres was %d\n", lres);
181 return TRUE;
184 static void setup_window(void)
186 WNDCLASSA wc;
187 static const char nstctest_wnd_name[] = "nstctest_wnd";
189 ZeroMemory(&wc, sizeof(WNDCLASSA));
190 wc.lpfnWndProc = DefWindowProcA;
191 wc.lpszClassName = nstctest_wnd_name;
192 RegisterClassA(&wc);
193 hwnd = CreateWindowA(nstctest_wnd_name, NULL, WS_TABSTOP,
194 0, 0, 200, 200, NULL, 0, 0, NULL);
195 ok(hwnd != NULL, "Failed to create window for test (lasterror: %d).\n",
196 GetLastError());
199 static void destroy_window(void)
201 DestroyWindow(hwnd);
204 START_TEST(nstc)
206 OleInitialize(NULL);
207 setup_window();
209 test_initialization();
211 destroy_window();
212 OleUninitialize();