shell32: Implement IExplorerBrowser::BrowseToObject.
[wine] / dlls / shell32 / tests / autocomplete.c
1 /*
2  * Tests for autocomplete
3  *
4  * Copyright 2008 Jan de Mooij
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 #define COBJMACROS
22
23 #include <wine/test.h>
24 #include <stdarg.h>
25
26 #include "windows.h"
27 #include "shobjidl.h"
28 #include "shlguid.h"
29 #include "initguid.h"
30 #include "shldisp.h"
31
32 static HWND hMainWnd, hEdit;
33 static HINSTANCE hinst;
34 static int killfocus_count;
35
36 static IAutoComplete *test_init(void)
37 {
38     HRESULT r;
39     IAutoComplete* ac;
40     IUnknown *acSource;
41
42     /* AutoComplete instance */
43     r = CoCreateInstance(&CLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER,
44                          &IID_IAutoComplete, (LPVOID*)&ac);
45     if (r == REGDB_E_CLASSNOTREG)
46     {
47         win_skip("CLSID_AutoComplete is not registered\n");
48         return NULL;
49     }
50     ok(r == S_OK, "no IID_IAutoComplete (0x%08x)\n", r);
51
52     /* AutoComplete source */
53     r = CoCreateInstance(&CLSID_ACLMulti, NULL, CLSCTX_INPROC_SERVER,
54                         &IID_IACList, (LPVOID*)&acSource);
55     if (r == REGDB_E_CLASSNOTREG)
56     {
57         win_skip("CLSID_ACLMulti is not registered\n");
58         return NULL;
59     }
60     ok(r == S_OK, "no IID_IACList (0x%08x)\n", r);
61
62 if (0)
63 {
64     /* crashes on native */
65     r = IAutoComplete_Init(ac, hEdit, NULL, NULL, NULL);
66 }
67     /* bind to edit control */
68     r = IAutoComplete_Init(ac, hEdit, acSource, NULL, NULL);
69     ok(r == S_OK, "Init failed (0x%08x)\n", r);
70
71     IUnknown_Release(acSource);
72
73     return ac;
74 }
75
76 static void test_killfocus(void)
77 {
78     /* Test if WM_KILLFOCUS messages are handled properly by checking if
79      * the parent receives an EN_KILLFOCUS message. */
80     SetFocus(hEdit);
81     killfocus_count = 0;
82     SetFocus(0);
83     ok(killfocus_count == 1, "Expected one EN_KILLFOCUS message, got: %d\n", killfocus_count);
84 }
85
86 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
87 {
88     switch(msg) {
89     case WM_CREATE:
90         /* create edit control */
91         hEdit = CreateWindowEx(0, "EDIT", "Some text", 0, 10, 10, 300, 300,
92                     hWnd, NULL, hinst, NULL);
93         ok(hEdit != NULL, "Can't create edit control\n");
94         break;
95     case WM_COMMAND:
96         if(HIWORD(wParam) == EN_KILLFOCUS)
97             killfocus_count++;
98         break;
99     }
100     return DefWindowProcA(hWnd, msg, wParam, lParam);
101 }
102
103 static void createMainWnd(void)
104 {
105     WNDCLASSA wc;
106     wc.style = CS_HREDRAW | CS_VREDRAW;
107     wc.cbClsExtra = 0;
108     wc.cbWndExtra = 0;
109     wc.hInstance = GetModuleHandleA(NULL);
110     wc.hIcon = NULL;
111     wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
112     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
113     wc.lpszMenuName = NULL;
114     wc.lpszClassName = "MyTestWnd";
115     wc.lpfnWndProc = MyWndProc;
116     RegisterClassA(&wc);
117
118     hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
119       CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
120 }
121
122 START_TEST(autocomplete)
123 {
124     HRESULT r;
125     MSG msg;
126     IAutoComplete* ac;
127
128     r = CoInitialize(NULL);
129     ok(r == S_OK, "CoInitialize failed (0x%08x). Tests aborted.\n", r);
130     if (r != S_OK)
131         return;
132
133     createMainWnd();
134     ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
135     if (!hMainWnd) return;
136
137     ac = test_init();
138     if (!ac)
139         goto cleanup;
140     test_killfocus();
141
142     PostQuitMessage(0);
143     while(GetMessageA(&msg,0,0,0)) {
144         TranslateMessage(&msg);
145         DispatchMessageA(&msg);
146     }
147
148     IAutoComplete_Release(ac);
149
150 cleanup:
151     DestroyWindow(hEdit);
152     DestroyWindow(hMainWnd);
153
154     CoUninitialize();
155 }