TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / comctl32 / tests / pager.c
blobd3521403db348e1eb16308c9d92173e27a84969a
1 /*
2 * Unit tests for the pager control
4 * Copyright 2012 Alexandre Julliard
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.
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.
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
21 #include <windows.h>
22 #include <commctrl.h>
24 #include "wine/test.h"
25 #include "msg.h"
27 #define NUM_MSG_SEQUENCES 1
28 #define PAGER_SEQ_INDEX 0
30 static HWND parent_wnd;
32 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
34 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
36 static const struct message set_child_seq[] = {
37 { PGM_SETCHILD, sent },
38 { WM_WINDOWPOSCHANGING, sent },
39 { WM_NCCALCSIZE, sent|wparam, TRUE },
40 { WM_NOTIFY, sent|id|parent, 0, 0, PGN_CALCSIZE },
41 { WM_WINDOWPOSCHANGED, sent },
42 { 0 }
45 static const struct message set_pos_seq[] = {
46 { PGM_SETPOS, sent },
47 { WM_WINDOWPOSCHANGING, sent },
48 { WM_NCCALCSIZE, sent|wparam, TRUE },
49 { WM_NOTIFY, sent|id|parent, 0, 0, PGN_CALCSIZE },
50 { WM_WINDOWPOSCHANGED, sent },
51 { WM_MOVE, sent|optional },
52 { WM_SIZE, sent|optional },
53 { 0 }
56 static const struct message set_pos_empty_seq[] = {
57 { PGM_SETPOS, sent },
58 { 0 }
61 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
63 static LONG defwndproc_counter = 0;
64 LRESULT ret;
65 struct message msg;
67 /* log system messages, except for painting */
68 if (message < WM_USER &&
69 message != WM_PAINT &&
70 message != WM_ERASEBKGND &&
71 message != WM_NCPAINT &&
72 message != WM_NCHITTEST &&
73 message != WM_GETTEXT &&
74 message != WM_GETICON &&
75 message != WM_DEVICECHANGE)
77 msg.message = message;
78 msg.flags = sent|wparam|lparam|parent;
79 if (defwndproc_counter) msg.flags |= defwinproc;
80 msg.wParam = wParam;
81 msg.lParam = lParam;
82 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
83 add_message(sequences, PAGER_SEQ_INDEX, &msg);
86 defwndproc_counter++;
87 ret = DefWindowProcA(hwnd, message, wParam, lParam);
88 defwndproc_counter--;
90 return ret;
93 static BOOL register_parent_wnd_class(void)
95 WNDCLASSA cls;
97 cls.style = 0;
98 cls.lpfnWndProc = parent_wnd_proc;
99 cls.cbClsExtra = 0;
100 cls.cbWndExtra = 0;
101 cls.hInstance = GetModuleHandleA(NULL);
102 cls.hIcon = 0;
103 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
104 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
105 cls.lpszMenuName = NULL;
106 cls.lpszClassName = "Pager test parent class";
107 return RegisterClassA(&cls);
110 static HWND create_parent_window(void)
112 if (!register_parent_wnd_class())
113 return NULL;
115 return CreateWindowA("Pager test parent class", "Pager test parent window",
116 WS_OVERLAPPED | WS_VISIBLE,
117 0, 0, 200, 200, 0, NULL, GetModuleHandleA(NULL), NULL );
120 static LRESULT WINAPI pager_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
122 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
123 struct message msg;
125 msg.message = message;
126 msg.flags = sent|wparam|lparam;
127 msg.wParam = wParam;
128 msg.lParam = lParam;
129 msg.id = 0;
130 add_message(sequences, PAGER_SEQ_INDEX, &msg);
131 return CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
134 static HWND create_pager_control( DWORD style )
136 WNDPROC oldproc;
137 HWND hwnd;
138 RECT rect;
140 GetClientRect( parent_wnd, &rect );
141 hwnd = CreateWindowA( WC_PAGESCROLLERA, "pager", WS_CHILD | WS_BORDER | WS_VISIBLE | style,
142 0, 0, 100, 100, parent_wnd, 0, GetModuleHandleA(0), 0 );
143 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)pager_subclass_proc);
144 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
145 return hwnd;
148 static void test_pager(void)
150 HWND pager, child;
151 RECT rect;
153 pager = create_pager_control( PGS_HORZ );
154 if (!pager)
156 win_skip( "Pager control not supported\n" );
157 return;
159 child = CreateWindowA( "BUTTON", "button", WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 300, 300,
160 pager, 0, GetModuleHandleA(0), 0 );
162 flush_sequences( sequences, NUM_MSG_SEQUENCES );
163 SendMessageA( pager, PGM_SETCHILD, 0, (LPARAM)child );
164 ok_sequence(sequences, PAGER_SEQ_INDEX, set_child_seq, "set child", TRUE);
165 GetWindowRect( pager, &rect );
166 ok( rect.right - rect.left == 100 && rect.bottom - rect.top == 100,
167 "pager resized %dx%d\n", rect.right - rect.left, rect.bottom - rect.top );
169 flush_sequences( sequences, NUM_MSG_SEQUENCES );
170 SendMessageA( pager, PGM_SETPOS, 0, 10 );
171 ok_sequence(sequences, PAGER_SEQ_INDEX, set_pos_seq, "set pos", TRUE);
172 GetWindowRect( pager, &rect );
173 ok( rect.right - rect.left == 100 && rect.bottom - rect.top == 100,
174 "pager resized %dx%d\n", rect.right - rect.left, rect.bottom - rect.top );
176 flush_sequences( sequences, NUM_MSG_SEQUENCES );
177 SendMessageA( pager, PGM_SETPOS, 0, 10 );
178 ok_sequence(sequences, PAGER_SEQ_INDEX, set_pos_empty_seq, "set pos empty", TRUE);
180 flush_sequences( sequences, NUM_MSG_SEQUENCES );
181 SendMessageA( pager, PGM_SETPOS, 0, 9 );
182 ok_sequence(sequences, PAGER_SEQ_INDEX, set_pos_seq, "set pos", TRUE);
184 DestroyWindow( pager );
187 START_TEST(pager)
189 HMODULE mod = GetModuleHandleA("comctl32.dll");
191 pSetWindowSubclass = (void*)GetProcAddress(mod, (LPSTR)410);
193 InitCommonControls();
194 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
196 parent_wnd = create_parent_window();
197 ok(parent_wnd != NULL, "Failed to create parent window!\n");
199 test_pager();