1 /* Unit test suite for header control.
3 * Copyright 2005 Vijay Kiran Kamuju
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
25 #include "wine/test.h"
27 static HWND hHeaderParentWnd;
30 static LONG addItem(HWND hdex, int idx, LPCSTR text)
33 hdItem.mask = HDI_TEXT | HDI_WIDTH;
35 hdItem.pszText = (LPSTR)text;
36 hdItem.cchTextMax = 0;
37 return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
40 static LONG setItem(HWND hdex, int idx, LPCSTR text)
43 hdexItem.mask = HDI_TEXT;
44 hdexItem.pszText = (LPSTR)text;
45 hdexItem.cchTextMax = 0;
46 return (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
49 static LONG delItem(HWND hdex, int idx)
51 return (LONG)SendMessage(hdex, HDM_DELETEITEM, (WPARAM)idx, 0);
54 static LONG getItemCount(HWND hdex)
56 return (LONG)SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
59 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
62 hdItem.mask = HDI_TEXT;
63 hdItem.pszText = textBuffer;
64 hdItem.cchTextMax = MAX_CHARS;
65 return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
68 static HWND create_header_control (void)
75 handle = CreateWindowEx(0, WC_HEADER, NULL,
76 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
78 hHeaderParentWnd, NULL, NULL, NULL);
81 if (winetest_interactive)
82 ShowWindow (hHeaderParentWnd, SW_SHOW);
84 GetClientRect(hHeaderParentWnd,&rectwin);
85 hlayout.prc = &rectwin;
86 hlayout.pwpos = &winpos;
87 SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
88 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
89 winpos.cx, winpos.cy, 0);
94 static const char *str_items[] =
95 {"First Item", "Second Item", "Third Item", "Fourth Item", "Replace Item", "Out Of Range Item"};
97 #define TEST_GET_ITEM(i,c)\
98 { res = getItem(hWndHeader, i, buffer);\
99 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%ld)\n", i, res);\
100 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
103 #define TEST_GET_ITEMCOUNT(i)\
104 { res = getItemCount(hWndHeader);\
105 ok(res == i, "Got Item Count as %ld\n", res);\
108 static void test_header_control (void)
112 static char buffer[MAX_CHARS];
115 hWndHeader = create_header_control ();
117 for (i = 3; i >= 0; i--)
119 TEST_GET_ITEMCOUNT(3-i);
120 res = addItem(hWndHeader, 0, str_items[i]);
121 ok(res == 0, "Adding simple item failed (%ld)\n", res);
124 TEST_GET_ITEMCOUNT(4);
125 res = addItem(hWndHeader, 99, str_items[i+1]);
126 ok(res != -1, "Adding Out of Range item should fail with -1 got (%ld)\n", res);
127 TEST_GET_ITEMCOUNT(5);
128 res = addItem(hWndHeader, 5, str_items[i+1]);
129 ok(res != -1, "Adding Out of Range item should fail with -1 got (%ld)\n", res);
130 TEST_GET_ITEMCOUNT(6);
132 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
134 res=getItem(hWndHeader, 99, buffer);
135 ok(res == 0, "Getting Out of Range item should fail with 0 (%ld), got %s\n", res,buffer);
136 res=getItem(hWndHeader, 5, buffer);
137 ok(res == 1, "Getting Out of Range item should fail with 1 (%ld), got %s\n", res,buffer);
138 res=getItem(hWndHeader, -2, buffer);
139 ok(res == 0, "Getting Out of Range item should fail with 0 (%ld), got %s\n", res,buffer);
141 if (winetest_interactive)
143 UpdateWindow(hHeaderParentWnd);
144 UpdateWindow(hWndHeader);
147 TEST_GET_ITEMCOUNT(6);
148 res=setItem(hWndHeader, 99, str_items[5]);
149 ok(res == 0, "Setting Out of Range item should fail with 0 (%ld)\n", res);
150 res=setItem(hWndHeader, 5, str_items[5]);
151 ok(res == 1, "Setting Out of Range item should fail with 1 (%ld)\n", res);
152 res=setItem(hWndHeader, -2, str_items[5]);
153 ok(res == 0, "Setting Out of Range item should fail with 0 (%ld)\n", res);
154 TEST_GET_ITEMCOUNT(6);
156 for (i = 0; i < 4; i++)
158 res = setItem(hWndHeader, i, str_items[4]);
159 ok(res != 0, "Setting %d item failed (%ld)\n", i+1, res);
161 TEST_GET_ITEMCOUNT(6);
164 res = delItem(hWndHeader, 5);
165 ok(res == 1, "Deleting Out of Range item should fail with 1 (%ld)\n", res);
166 res = delItem(hWndHeader, -2);
167 ok(res == 0, "Deleting Out of Range item should fail with 0 (%ld)\n", res);
168 TEST_GET_ITEMCOUNT(5);
170 res = delItem(hWndHeader, 3);
171 ok(res != 0, "Deleting using out of range index failed (%ld)\n", res);
172 TEST_GET_ITEMCOUNT(4);
173 res = delItem(hWndHeader, 0);
174 ok(res != 0, "Deleting using out of range index failed (%ld)\n", res);
175 TEST_GET_ITEMCOUNT(3);
176 res = delItem(hWndHeader, 0);
177 ok(res != 0, "Deleting using out of range index failed (%ld)\n", res);
178 TEST_GET_ITEMCOUNT(2);
179 res = delItem(hWndHeader, 0);
180 ok(res != 0, "Deleting using out of range index failed (%ld)\n", res);
181 TEST_GET_ITEMCOUNT(1);
183 DestroyWindow(hWndHeader);
188 INITCOMMONCONTROLSEX icex;
190 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
191 icex.dwICC = ICC_USEREX_CLASSES;
192 InitCommonControlsEx(&icex);
193 hHeaderParentWnd = CreateWindowExA(0, "static", "Header test", WS_OVERLAPPEDWINDOW,
194 CW_USEDEFAULT, CW_USEDEFAULT, 480, 100, NULL, NULL, NULL, 0);
195 assert(hHeaderParentWnd != NULL);
197 test_header_control();
199 DestroyWindow(hHeaderParentWnd);