winhttp, wininet: Load i2d_X509 from libcrypto.so.
[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 void test_init(void) {
37     HRESULT r;
38     IAutoComplete* ac;
39     IUnknown *acSource;
40
41     /* AutoComplete instance */
42     r = CoCreateInstance(&CLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER,
43                          &IID_IAutoComplete, (LPVOID*)&ac);
44     ok(SUCCEEDED(r), "no IID_IAutoComplete (0x%08x)\n", r);
45
46     /* AutoComplete source */
47     r = CoCreateInstance(&CLSID_ACLMulti, NULL, CLSCTX_INPROC_SERVER,
48                         &IID_IACList, (LPVOID*)&acSource);
49     ok(SUCCEEDED(r), "no IID_IACList (0x%08x)\n", r);
50
51     /* bind to edit control */
52     r = IAutoComplete_Init(ac, hEdit, acSource, NULL, NULL);
53     ok(SUCCEEDED(r), "Init failed (0x%08x)\n", r);
54 }
55 static void test_killfocus(void) {
56     /* Test if WM_KILLFOCUS messages are handled properly by checking if
57      * the parent receives an EN_KILLFOCUS message. */
58     SetFocus(hEdit);
59     killfocus_count = 0;
60     SetFocus(0);
61     ok(killfocus_count == 1, "Expected one EN_KILLFOCUS message, got: %d\n", killfocus_count);
62 }
63 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
64     switch(msg) {
65     case WM_CREATE:
66         /* create edit control */
67         hEdit = CreateWindowEx(0, "EDIT", "Some text", 0, 10, 10, 300, 300,
68                     hWnd, NULL, hinst, NULL);
69         ok(hEdit != NULL, "Can't create edit control\n");
70         break;
71     case WM_COMMAND:
72         if(HIWORD(wParam) == EN_KILLFOCUS)
73             killfocus_count++;
74         break;
75     }
76     return DefWindowProcA(hWnd, msg, wParam, lParam);
77 }
78 static void createMainWnd(void) {
79     WNDCLASSA wc;
80     wc.style = CS_HREDRAW | CS_VREDRAW;
81     wc.cbClsExtra = 0;
82     wc.cbWndExtra = 0;
83     wc.hInstance = GetModuleHandleA(NULL);
84     wc.hIcon = NULL;
85     wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
86     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
87     wc.lpszMenuName = NULL;
88     wc.lpszClassName = "MyTestWnd";
89     wc.lpfnWndProc = MyWndProc;
90     RegisterClassA(&wc);
91
92     hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
93       CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
94 }
95 START_TEST(autocomplete) {
96     HRESULT r;
97     MSG msg;
98
99     r = CoInitialize(NULL);
100     ok(SUCCEEDED(r), "CoInitialize failed (0x%08x). Tests aborted.\n", r);
101     if (FAILED(r))
102         return;
103
104     createMainWnd();
105
106     if(!ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n"))
107         return;
108
109     test_init();
110     test_killfocus();
111
112     PostQuitMessage(0);
113     while(GetMessageA(&msg,0,0,0)) {
114         TranslateMessage(&msg);
115         DispatchMessageA(&msg);
116     }
117
118     DestroyWindow(hEdit);
119     DestroyWindow(hMainWnd);
120
121     CoUninitialize();
122 }