Release 20050930.
[wine/gsoc-2012-control.git] / dlls / comctl32 / tests / treeview.c
blob4cb1cbd4673c64a795f5ca88ec3dd42f0351e44b
1 /* Unit tests for treeview.
3 * Copyright 2005 Krzysztof Foltman
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 <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "commctrl.h"
31 #include "wine/test.h"
33 static HWND hMainWnd;
35 static HWND hTree;
36 static HTREEITEM hRoot, hChild;
38 static int pos = 0;
39 static char sequence[256];
41 static void Clear(void)
43 pos = 0;
44 sequence[0] = '\0';
47 static void AddItem(char ch)
49 sequence[pos++] = ch;
50 sequence[pos] = '\0';
53 static void IdentifyItem(HTREEITEM hItem)
55 if (hItem == hRoot) {
56 AddItem('R');
57 return;
59 if (hItem == hChild) {
60 AddItem('C');
61 return;
63 if (hItem == NULL) {
64 AddItem('n');
65 return;
67 AddItem('?');
70 static void FillRoot(void)
72 TVINSERTSTRUCTA ins;
74 Clear();
75 AddItem('A');
76 ins.hParent = TVI_ROOT;
77 ins.hInsertAfter = TVI_ROOT;
78 U(ins).item.mask = TVIF_TEXT;
79 U(ins).item.pszText = "Root";
80 hRoot = TreeView_InsertItem(hTree, &ins);
81 assert(hRoot);
83 AddItem('B');
84 ins.hParent = hRoot;
85 ins.hInsertAfter = TVI_FIRST;
86 U(ins).item.mask = TVIF_TEXT;
87 U(ins).item.pszText = "Child";
88 hChild = TreeView_InsertItem(hTree, &ins);
89 assert(hChild);
90 AddItem('.');
92 ok(!strcmp(sequence, "AB."), "Item creation\n");
95 static void DoTest1(void)
97 TreeView_SelectItem(hTree, NULL);
98 Clear();
99 AddItem('1');
100 TreeView_SelectItem(hTree, hRoot);
101 AddItem('2');
102 TreeView_SelectItem(hTree, hRoot);
103 AddItem('3');
104 TreeView_SelectItem(hTree, NULL);
105 AddItem('4');
106 TreeView_SelectItem(hTree, NULL);
107 AddItem('5');
108 TreeView_SelectItem(hTree, hRoot);
109 AddItem('.');
110 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
113 static void DoTest2(void)
115 TreeView_SelectItem(hTree, NULL);
116 Clear();
117 AddItem('1');
118 TreeView_SelectItem(hTree, hRoot);
119 AddItem('2');
120 TreeView_SelectItem(hTree, hRoot);
121 AddItem('3');
122 TreeView_SelectItem(hTree, hChild);
123 AddItem('4');
124 TreeView_SelectItem(hTree, hChild);
125 AddItem('5');
126 TreeView_SelectItem(hTree, hRoot);
127 AddItem('.');
128 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
131 LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
133 switch(msg) {
135 case WM_CREATE:
137 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
138 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS,
139 0, 0, 300, 50, hWnd, (HMENU)100, GetModuleHandleA(0), 0);
141 SetFocus(hTree);
142 return 0;
144 case WM_NOTIFY:
146 NMHDR *pHdr = (NMHDR *)lParam;
148 if (pHdr->idFrom == 100) {
149 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
150 switch(pHdr->code) {
151 case TVN_SELCHANGINGA:
152 AddItem('(');
153 IdentifyItem(pTreeView->itemOld.hItem);
154 IdentifyItem(pTreeView->itemNew.hItem);
155 return 0;
156 case TVN_SELCHANGEDA:
157 AddItem(')');
158 IdentifyItem(pTreeView->itemOld.hItem);
159 IdentifyItem(pTreeView->itemNew.hItem);
160 return 0;
163 return 0;
166 case WM_SIZE:
167 MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
168 break;
170 case WM_DESTROY:
171 PostQuitMessage(0);
172 break;
174 default:
175 return DefWindowProcA(hWnd, msg, wParam, lParam);
177 return 0L;
180 START_TEST(treeview)
182 WNDCLASSA wc;
183 MSG msg;
184 INITCOMMONCONTROLSEX icex;
185 RECT rc;
187 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
188 icex.dwICC = ICC_TREEVIEW_CLASSES;
189 InitCommonControlsEx(&icex);
191 wc.style = CS_HREDRAW | CS_VREDRAW;
192 wc.cbClsExtra = 0;
193 wc.cbWndExtra = 0;
194 wc.hInstance = GetModuleHandleA(NULL);
195 wc.hIcon = NULL;
196 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
197 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
198 wc.lpszMenuName = NULL;
199 wc.lpszClassName = "MyTestWnd";
200 wc.lpfnWndProc = MyWndProc;
201 RegisterClassA(&wc);
204 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
205 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
206 GetClientRect(hMainWnd, &rc);
208 FillRoot();
209 DoTest1();
210 DoTest2();
212 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
213 while(GetMessageA(&msg,0,0,0)) {
214 TranslateMessage(&msg);
215 DispatchMessageA(&msg);