Fixes for missing prototypes warnings.
[wine/multimedia.git] / dlls / comctl32 / tests / comboex.c
blob8a109a534277ac7732971a9fe7597292635fc656
1 /* Unit test suite for comboex control.
3 * Copyright 2005 Jason Edmeades
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <assert.h>
21 #include <windows.h>
22 #include <commctrl.h>
24 #include "wine/test.h"
26 static HWND hComboExParentWnd;
27 static HINSTANCE hMainHinst;
28 static const char ComboExTestClass[] = "ComboExTestClass";
30 #define MAX_CHARS 100
31 static char *textBuffer = NULL;
33 static HWND createComboEx(DWORD style) {
34 return CreateWindowExA(0, WC_COMBOBOXEXA, NULL, style, 0, 0, 300, 300,
35 hComboExParentWnd, NULL, hMainHinst, NULL);
38 static LONG addItem(HWND cbex, int idx, LPTSTR text) {
39 COMBOBOXEXITEM cbexItem;
40 memset(&cbexItem, 0x00, sizeof(cbexItem));
41 cbexItem.mask = CBEIF_TEXT;
42 cbexItem.iItem = idx;
43 cbexItem.pszText = text;
44 cbexItem.cchTextMax = 0;
45 return (LONG)SendMessage(cbex, CBEM_INSERTITEM, 0,(LPARAM)&cbexItem);
48 static LONG setItem(HWND cbex, int idx, LPTSTR text) {
49 COMBOBOXEXITEM cbexItem;
50 memset(&cbexItem, 0x00, sizeof(cbexItem));
51 cbexItem.mask = CBEIF_TEXT;
52 cbexItem.iItem = idx;
53 cbexItem.pszText = text;
54 cbexItem.cchTextMax = 0;
55 return (LONG)SendMessage(cbex, CBEM_SETITEM, 0,(LPARAM)&cbexItem);
58 static LONG delItem(HWND cbex, int idx) {
59 return (LONG)SendMessage(cbex, CBEM_DELETEITEM, (LPARAM)idx, 0);
62 static LONG getItem(HWND cbex, int idx, COMBOBOXEXITEM *cbItem) {
63 memset(cbItem, 0x00, sizeof(COMBOBOXEXITEM));
64 cbItem->mask = CBEIF_TEXT;
65 cbItem->pszText = textBuffer;
66 cbItem->iItem = idx;
67 cbItem->cchTextMax = 100;
68 return (LONG)SendMessage(cbex, CBEM_GETITEM, 0, (LPARAM)cbItem);
71 static void test_comboboxex(void) {
72 HWND myHwnd = 0;
73 LONG res = -1;
74 COMBOBOXEXITEM cbexItem;
76 #define FIRST_ITEM "First Item"
77 #define SECOND_ITEM "Second Item"
78 #define THIRD_ITEM "Third Item"
79 #define MIDDLE_ITEM "Between First and Second Items"
80 #define REPLACEMENT_ITEM "Between First and Second Items"
82 /* Allocate space for result */
83 textBuffer = malloc(MAX_CHARS);
85 /* Basic comboboxex test */
86 myHwnd = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
88 /* Add items onto the end of the combobox */
89 res = addItem(myHwnd, -1, FIRST_ITEM);
90 ok(res == 0, "Adding simple item failed (%ld)\n", res);
91 res = addItem(myHwnd, -1, SECOND_ITEM);
92 ok(res == 1, "Adding simple item failed (%ld)\n", res);
93 res = addItem(myHwnd, 2, THIRD_ITEM);
94 ok(res == 2, "Adding simple item failed (%ld)\n", res);
95 res = addItem(myHwnd, 1, MIDDLE_ITEM);
96 ok(res == 1, "Inserting simple item failed (%ld)\n", res);
98 /* Add an item completely out of range */
99 res = addItem(myHwnd, 99, "Out Of Range Item");
100 ok(res == -1, "Adding using out of range index worked unexpectedly (%ld)\n", res);
101 res = addItem(myHwnd, 5, "Out Of Range Item");
102 ok(res == -1, "Adding using out of range index worked unexpectedly (%ld)\n", res);
103 /* Removed: Causes traps on Windows XP
104 res = addItem(myHwnd, -2, "Out Of Range Item");
105 ok(res == -1, "Adding out of range worked unexpectedly (%ld)\n", res);
108 /* Get an item completely out of range */
109 res = getItem(myHwnd, 99, &cbexItem);
110 ok(res == 0, "Getting item using out of range index worked unexpectedly (%ld, %s)\n", res, cbexItem.pszText);
111 res = getItem(myHwnd, 4, &cbexItem);
112 ok(res == 0, "Getting item using out of range index worked unexpectedly (%ld, %s)\n", res, cbexItem.pszText);
113 res = getItem(myHwnd, -2, &cbexItem);
114 ok(res == 0, "Getting item using out of range index worked unexpectedly (%ld, %s)\n", res, cbexItem.pszText);
116 /* Get an item in range */
117 res = getItem(myHwnd, 0, &cbexItem);
118 ok(res != 0, "Getting item using valid index failed unexpectedly (%ld)\n", res);
119 ok(strcmp(FIRST_ITEM, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
121 res = getItem(myHwnd, 1, &cbexItem);
122 ok(res != 0, "Getting item using valid index failed unexpectedly (%ld)\n", res);
123 ok(strcmp(MIDDLE_ITEM, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
125 res = getItem(myHwnd, 2, &cbexItem);
126 ok(res != 0, "Getting item using valid index failed unexpectedly (%ld)\n", res);
127 ok(strcmp(SECOND_ITEM, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
129 res = getItem(myHwnd, 3, &cbexItem);
130 ok(res != 0, "Getting item using valid index failed unexpectedly (%ld)\n", res);
131 ok(strcmp(THIRD_ITEM, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
133 /* Set an item completely out of range */
134 res = setItem(myHwnd, 99, REPLACEMENT_ITEM);
135 ok(res == 0, "Setting item using out of range index worked unexpectedly (%ld)\n", res);
136 res = setItem(myHwnd, 4, REPLACEMENT_ITEM);
137 ok(res == 0, "Setting item using out of range index worked unexpectedly (%ld)\n", res);
138 res = setItem(myHwnd, -2, REPLACEMENT_ITEM);
139 ok(res == 0, "Setting item using out of range index worked unexpectedly (%ld)\n", res);
141 /* Set an item in range */
142 res = setItem(myHwnd, 0, REPLACEMENT_ITEM);
143 ok(res != 0, "Setting first item failed (%ld)\n", res);
144 res = setItem(myHwnd, 3, REPLACEMENT_ITEM);
145 ok(res != 0, "Setting last item failed (%ld)\n", res);
147 /* Remove items completely out of range (4 items in control at this point) */
148 res = delItem(myHwnd, -1);
149 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%ld)\n", res);
150 res = delItem(myHwnd, 4);
151 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%ld)\n", res);
153 /* Remove items in range (4 items in control at this point) */
154 res = delItem(myHwnd, 3);
155 ok(res == 3, "Deleting using out of range index failed (%ld)\n", res);
156 res = delItem(myHwnd, 0);
157 ok(res == 2, "Deleting using out of range index failed (%ld)\n", res);
158 res = delItem(myHwnd, 0);
159 ok(res == 1, "Deleting using out of range index failed (%ld)\n", res);
160 res = delItem(myHwnd, 0);
161 ok(res == 0, "Deleting using out of range index failed (%ld)\n", res);
163 /* Remove from an empty box */
164 res = delItem(myHwnd, 0);
165 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%ld)\n", res);
168 /* Cleanup */
169 free(textBuffer);
173 LRESULT CALLBACK ComboExTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
175 switch(msg) {
177 case WM_DESTROY:
178 PostQuitMessage(0);
179 break;
181 default:
182 return DefWindowProcA(hWnd, msg, wParam, lParam);
185 return 0L;
188 static void init(void) {
189 WNDCLASSA wc;
190 INITCOMMONCONTROLSEX icex;
192 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
193 icex.dwICC = ICC_USEREX_CLASSES;
194 InitCommonControlsEx(&icex);
196 wc.style = CS_HREDRAW | CS_VREDRAW;
197 wc.cbClsExtra = 0;
198 wc.cbWndExtra = 0;
199 wc.hInstance = GetModuleHandleA(NULL);
200 wc.hIcon = NULL;
201 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));
202 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
203 wc.lpszMenuName = NULL;
204 wc.lpszClassName = ComboExTestClass;
205 wc.lpfnWndProc = ComboExTestWndProc;
206 RegisterClassA(&wc);
208 hComboExParentWnd = CreateWindowExA(0, ComboExTestClass, "ComboEx test", WS_OVERLAPPEDWINDOW,
209 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
210 assert(hComboExParentWnd != NULL);
212 hMainHinst = GetModuleHandleA(NULL);
216 static void cleanup(void)
218 MSG msg;
220 PostMessageA(hComboExParentWnd, WM_CLOSE, 0, 0);
221 while (GetMessageA(&msg,0,0,0)) {
222 TranslateMessage(&msg);
223 DispatchMessageA(&msg);
226 UnregisterClassA(ComboExTestClass, GetModuleHandleA(NULL));
229 START_TEST(comboex)
231 init();
233 test_comboboxex();
235 cleanup();