1 | /** @file
|
---|
2 | * Automated test of the X11 seamless Additions code.
|
---|
3 | * @todo Better separate test data from implementation details!
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <stdlib.h> /* exit() */
|
---|
19 |
|
---|
20 | #include <X11/Xatom.h>
|
---|
21 | #include <X11/Xmu/WinUtil.h>
|
---|
22 |
|
---|
23 | #include <iprt/initterm.h>
|
---|
24 | #include <iprt/mem.h>
|
---|
25 | #include <iprt/path.h>
|
---|
26 | #include <iprt/semaphore.h>
|
---|
27 | #include <iprt/stream.h>
|
---|
28 | #include <iprt/string.h>
|
---|
29 |
|
---|
30 | #include "../seamless.h"
|
---|
31 |
|
---|
32 | #undef DefaultRootWindow
|
---|
33 |
|
---|
34 | /******************************************************
|
---|
35 | * Mock X11 functions needed by the seamless X11 class *
|
---|
36 | ******************************************************/
|
---|
37 |
|
---|
38 | int XFree(void *data)
|
---|
39 | {
|
---|
40 | RTMemFree(data);
|
---|
41 | return 0;
|
---|
42 | }
|
---|
43 |
|
---|
44 | #define TEST_DISPLAY ((Display *)0xffff)
|
---|
45 | #define TEST_ROOT ((Window)1)
|
---|
46 |
|
---|
47 | extern "C" Display *XOpenDisplay(const char *display_name);
|
---|
48 | Display *XOpenDisplay(const char *display_name)
|
---|
49 | {
|
---|
50 | return TEST_DISPLAY;
|
---|
51 | }
|
---|
52 |
|
---|
53 | extern "C" int XCloseDisplay(Display *display);
|
---|
54 | int XCloseDisplay(Display *display)
|
---|
55 | {
|
---|
56 | Assert(display == TEST_DISPLAY);
|
---|
57 | return 0;
|
---|
58 | }
|
---|
59 |
|
---|
60 | enum
|
---|
61 | {
|
---|
62 | ATOM_PROP = 1,
|
---|
63 | ATOM_DESKTOP_PROP
|
---|
64 | };
|
---|
65 |
|
---|
66 | extern "C" Atom XInternAtom(Display *display, const char *atom_name,
|
---|
67 | Bool only_if_exists);
|
---|
68 | Atom XInternAtom(Display *display, const char *atom_name, Bool only_if_exists)
|
---|
69 | {
|
---|
70 | Assert(display == TEST_DISPLAY);
|
---|
71 | if (!RTStrCmp(atom_name, WM_TYPE_PROP))
|
---|
72 | return (Atom) ATOM_PROP;
|
---|
73 | if (!RTStrCmp(atom_name, WM_TYPE_DESKTOP_PROP))
|
---|
74 | return (Atom) ATOM_DESKTOP_PROP;
|
---|
75 | AssertFailed();
|
---|
76 | return (Atom)0;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /** The window (if any) on which the WM_TYPE_PROP property is set to the
|
---|
80 | * WM_TYPE_DESKTOP_PROP atom. */
|
---|
81 | static Window g_hSmlsDesktopWindow = 0;
|
---|
82 |
|
---|
83 | extern "C" int XGetWindowProperty(Display *display, Window w, Atom property,
|
---|
84 | long long_offset, long long_length,
|
---|
85 | Bool delProp, Atom req_type,
|
---|
86 | Atom *actual_type_return,
|
---|
87 | int *actual_format_return,
|
---|
88 | unsigned long *nitems_return,
|
---|
89 | unsigned long *bytes_after_return,
|
---|
90 | unsigned char **prop_return);
|
---|
91 | int XGetWindowProperty(Display *display, Window w, Atom property,
|
---|
92 | long long_offset, long long_length, Bool delProp,
|
---|
93 | Atom req_type, Atom *actual_type_return,
|
---|
94 | int *actual_format_return,
|
---|
95 | unsigned long *nitems_return,
|
---|
96 | unsigned long *bytes_after_return,
|
---|
97 | unsigned char **prop_return)
|
---|
98 | {
|
---|
99 | Assert(display == TEST_DISPLAY);
|
---|
100 | Atom atomType = XInternAtom (display, WM_TYPE_PROP, true);
|
---|
101 | Atom atomTypeDesktop = XInternAtom (display, WM_TYPE_DESKTOP_PROP, true);
|
---|
102 | /* We only handle things we expect. */
|
---|
103 | AssertReturn((req_type == XA_ATOM) || (req_type == AnyPropertyType),
|
---|
104 | 0xffff);
|
---|
105 | AssertReturn(property == atomType, 0xffff);
|
---|
106 | *actual_type_return = XA_ATOM;
|
---|
107 | *actual_format_return = sizeof(Atom) * 8;
|
---|
108 | *nitems_return = 0;
|
---|
109 | *bytes_after_return = sizeof(Atom);
|
---|
110 | *prop_return = NULL;
|
---|
111 | if ((w != g_hSmlsDesktopWindow) || (g_hSmlsDesktopWindow == 0))
|
---|
112 | return Success;
|
---|
113 | AssertReturn(long_offset == 0, 0);
|
---|
114 | AssertReturn(delProp == false, 0);
|
---|
115 | unsigned char *pProp;
|
---|
116 | pProp = (unsigned char *)RTMemDup(&atomTypeDesktop,
|
---|
117 | sizeof(atomTypeDesktop));
|
---|
118 | AssertReturn(pProp, 0xffff);
|
---|
119 | *nitems_return = 1;
|
---|
120 | *prop_return = pProp;
|
---|
121 | *bytes_after_return = 0;
|
---|
122 | return 0;
|
---|
123 | }
|
---|
124 |
|
---|
125 | /** Sets the current set of properties for all mock X11 windows */
|
---|
126 | static void smlsSetDesktopWindow(Window hWin)
|
---|
127 | {
|
---|
128 | g_hSmlsDesktopWindow = hWin;
|
---|
129 | }
|
---|
130 |
|
---|
131 | extern "C" Bool XShapeQueryExtension (Display *dpy, int *event_basep,
|
---|
132 | int *error_basep);
|
---|
133 | Bool XShapeQueryExtension (Display *dpy, int *event_basep, int *error_basep)
|
---|
134 | {
|
---|
135 | Assert(dpy == TEST_DISPLAY);
|
---|
136 | return true;
|
---|
137 | }
|
---|
138 |
|
---|
139 | /* We silently ignore this for now. */
|
---|
140 | extern "C" int XSelectInput(Display *display, Window w, long event_mask);
|
---|
141 | int XSelectInput(Display *display, Window w, long event_mask)
|
---|
142 | {
|
---|
143 | Assert(display == TEST_DISPLAY);
|
---|
144 | return 0;
|
---|
145 | }
|
---|
146 |
|
---|
147 | /* We silently ignore this for now. */
|
---|
148 | extern "C" void XShapeSelectInput(Display *display, Window w,
|
---|
149 | unsigned long event_mask);
|
---|
150 | void XShapeSelectInput(Display *display, Window w, unsigned long event_mask)
|
---|
151 | {
|
---|
152 | Assert(display == TEST_DISPLAY);
|
---|
153 | }
|
---|
154 |
|
---|
155 | extern "C" Window XDefaultRootWindow(Display *display);
|
---|
156 | Window XDefaultRootWindow(Display *display)
|
---|
157 | {
|
---|
158 | Assert(display == TEST_DISPLAY);
|
---|
159 | return TEST_ROOT;
|
---|
160 | }
|
---|
161 |
|
---|
162 | static unsigned g_cSmlsWindows = 0;
|
---|
163 | static Window *g_paSmlsWindows = NULL;
|
---|
164 | static XWindowAttributes *g_paSmlsWinAttribs = NULL;
|
---|
165 | static const char **g_papszSmlsWinNames = NULL;
|
---|
166 |
|
---|
167 | extern "C" Status XQueryTree(Display *display, Window w, Window *root_return,
|
---|
168 | Window *parent_return, Window **children_return,
|
---|
169 | unsigned int *nchildren_return);
|
---|
170 | Status XQueryTree(Display *display, Window w, Window *root_return,
|
---|
171 | Window *parent_return, Window **children_return,
|
---|
172 | unsigned int *nchildren_return)
|
---|
173 | {
|
---|
174 | Assert(display == TEST_DISPLAY);
|
---|
175 | AssertReturn(w == TEST_ROOT, False); /* We support nothing else */
|
---|
176 | AssertPtrReturn(children_return, False);
|
---|
177 | AssertReturn(g_paSmlsWindows, False);
|
---|
178 | if (root_return)
|
---|
179 | *root_return = TEST_ROOT;
|
---|
180 | if (parent_return)
|
---|
181 | *parent_return = TEST_ROOT;
|
---|
182 | *children_return = (Window *)RTMemDup(g_paSmlsWindows,
|
---|
183 | g_cSmlsWindows * sizeof(Window));
|
---|
184 | if (nchildren_return)
|
---|
185 | *nchildren_return = g_cSmlsWindows;
|
---|
186 | return (g_cSmlsWindows != 0);
|
---|
187 | }
|
---|
188 |
|
---|
189 | extern "C" Window XmuClientWindow(Display *dpy, Window win);
|
---|
190 | Window XmuClientWindow(Display *dpy, Window win)
|
---|
191 | {
|
---|
192 | Assert(dpy == TEST_DISPLAY);
|
---|
193 | return win;
|
---|
194 | }
|
---|
195 |
|
---|
196 | extern "C" Status XGetWindowAttributes(Display *display, Window w,
|
---|
197 | XWindowAttributes *window_attributes_return);
|
---|
198 | Status XGetWindowAttributes(Display *display, Window w,
|
---|
199 | XWindowAttributes *window_attributes_return)
|
---|
200 | {
|
---|
201 | Assert(display == TEST_DISPLAY);
|
---|
202 | AssertPtrReturn(window_attributes_return, 1);
|
---|
203 | for (unsigned i = 0; i < g_cSmlsWindows; ++i)
|
---|
204 | if (g_paSmlsWindows[i] == w)
|
---|
205 | {
|
---|
206 | *window_attributes_return = g_paSmlsWinAttribs[i];
|
---|
207 | return 1;
|
---|
208 | }
|
---|
209 | return 0;
|
---|
210 | }
|
---|
211 |
|
---|
212 | extern "C" Status XGetWMNormalHints(Display *display, Window w,
|
---|
213 | XSizeHints *hints_return,
|
---|
214 | long *supplied_return);
|
---|
215 |
|
---|
216 | Status XGetWMNormalHints(Display *display, Window w,
|
---|
217 | XSizeHints *hints_return, long *supplied_return)
|
---|
218 | {
|
---|
219 | Assert(display == TEST_DISPLAY);
|
---|
220 | return 1;
|
---|
221 | }
|
---|
222 |
|
---|
223 | static void smlsSetWindowAttributes(XWindowAttributes *pAttribs,
|
---|
224 | Window *pWindows, unsigned cAttribs,
|
---|
225 | const char **paNames)
|
---|
226 | {
|
---|
227 | g_paSmlsWinAttribs = pAttribs;
|
---|
228 | g_paSmlsWindows = pWindows;
|
---|
229 | g_cSmlsWindows = cAttribs;
|
---|
230 | g_papszSmlsWinNames = paNames;
|
---|
231 | }
|
---|
232 |
|
---|
233 | static Window g_SmlsShapedWindow = 0;
|
---|
234 | static int g_cSmlsShapeRectangles = 0;
|
---|
235 | static XRectangle *g_pSmlsShapeRectangles = NULL;
|
---|
236 |
|
---|
237 | extern "C" XRectangle *XShapeGetRectangles (Display *dpy, Window window,
|
---|
238 | int kind, int *count,
|
---|
239 | int *ordering);
|
---|
240 | XRectangle *XShapeGetRectangles (Display *dpy, Window window, int kind,
|
---|
241 | int *count, int *ordering)
|
---|
242 | {
|
---|
243 | Assert(dpy == TEST_DISPLAY);
|
---|
244 | if ((window != g_SmlsShapedWindow) || (window == 0))
|
---|
245 | return NULL; /* Probably not correct, but works for us. */
|
---|
246 | *count = g_cSmlsShapeRectangles;
|
---|
247 | *ordering = 0;
|
---|
248 | return (XRectangle *)RTMemDup(g_pSmlsShapeRectangles,
|
---|
249 | sizeof(XRectangle)
|
---|
250 | * g_cSmlsShapeRectangles);
|
---|
251 | }
|
---|
252 |
|
---|
253 | static void smlsSetShapeRectangles(Window window, int cRects,
|
---|
254 | XRectangle *pRects)
|
---|
255 | {
|
---|
256 | g_SmlsShapedWindow = window;
|
---|
257 | g_cSmlsShapeRectangles = cRects;
|
---|
258 | g_pSmlsShapeRectangles = pRects;
|
---|
259 | }
|
---|
260 |
|
---|
261 | static int g_SmlsEventType = 0;
|
---|
262 | static Window g_SmlsEventWindow = 0;
|
---|
263 |
|
---|
264 | /* This should not be needed in the bits of the code we test. */
|
---|
265 | extern "C" int XNextEvent(Display *display, XEvent *event_return);
|
---|
266 | int XNextEvent(Display *display, XEvent *event_return)
|
---|
267 | {
|
---|
268 | Assert(display == TEST_DISPLAY);
|
---|
269 | event_return->xany.type = g_SmlsEventType;
|
---|
270 | event_return->xany.window = g_SmlsEventWindow;
|
---|
271 | event_return->xmap.window = g_SmlsEventWindow;
|
---|
272 | return True;
|
---|
273 | }
|
---|
274 |
|
---|
275 | static void smlsSetNextEvent(int type, Window window)
|
---|
276 | {
|
---|
277 | g_SmlsEventType = type;
|
---|
278 | g_SmlsEventWindow = window;
|
---|
279 | }
|
---|
280 |
|
---|
281 | /* This should not be needed in the bits of the code we test. */
|
---|
282 | extern "C" Status XSendEvent(Display *display, Window w, Bool propagate,
|
---|
283 | long event_mask, XEvent *event_send);
|
---|
284 | Status XSendEvent(Display *display, Window w, Bool propagate,
|
---|
285 | long event_mask, XEvent *event_send)
|
---|
286 | {
|
---|
287 | Assert(display == TEST_DISPLAY);
|
---|
288 | AssertFailedReturn(0);
|
---|
289 | }
|
---|
290 |
|
---|
291 | /* This should not be needed in the bits of the code we test. */
|
---|
292 | extern "C" int XFlush(Display *display);
|
---|
293 | int XFlush(Display *display)
|
---|
294 | {
|
---|
295 | Assert(display == TEST_DISPLAY);
|
---|
296 | AssertFailedReturn(0);
|
---|
297 | }
|
---|
298 |
|
---|
299 | /** Global "received a notification" flag. */
|
---|
300 | static bool g_fNotified = false;
|
---|
301 |
|
---|
302 | /** Dummy host call-back. */
|
---|
303 | static void sendRegionUpdate(RTRECT *pRects, size_t cRects)
|
---|
304 | {
|
---|
305 | g_fNotified = true;
|
---|
306 | }
|
---|
307 |
|
---|
308 | static bool gotNotification(void)
|
---|
309 | {
|
---|
310 | if (!g_fNotified)
|
---|
311 | return false;
|
---|
312 | g_fNotified = false;
|
---|
313 | return true;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /*****************************
|
---|
317 | * The actual tests to be run *
|
---|
318 | *****************************/
|
---|
319 |
|
---|
320 | /** The name of the unit test */
|
---|
321 | static const char *g_pszTestName = NULL;
|
---|
322 |
|
---|
323 | /*** Test fixture data and data structures ***/
|
---|
324 |
|
---|
325 | /** A structure describing a test fixture to be run through. Each fixture
|
---|
326 | * describes the state of the windows visible (and unmapped) on the X server
|
---|
327 | * before and after a particular event is delivered, and the expected
|
---|
328 | * on-screen positions of all interesting visible windows at the end of the
|
---|
329 | * fixture as reported by the code (currently in the order it is likely to
|
---|
330 | * report them in, @todo sort this). We expect that the set of visible
|
---|
331 | * windows will be the same whether we start the code before the event and
|
---|
332 | * handle it or start the code after the event.
|
---|
333 | */
|
---|
334 | struct SMLSFIXTURE
|
---|
335 | {
|
---|
336 | /** The number of windows visible before the event */
|
---|
337 | unsigned cWindowsBefore;
|
---|
338 | /** An array of Window IDs for the visible and unmapped windows before
|
---|
339 | * the event */
|
---|
340 | Window *pahWindowsBefore;
|
---|
341 | /** The window attributes matching the windows in @a paWindowsBefore */
|
---|
342 | XWindowAttributes *paAttribsBefore;
|
---|
343 | /** The window names matching the windows in @a paWindowsBefore */
|
---|
344 | const char **papszNamesBefore;
|
---|
345 | /** The shaped window before the event - we allow at most one of these.
|
---|
346 | * Zero for none. */
|
---|
347 | Window hShapeWindowBefore;
|
---|
348 | /** The number of rectangles in the shaped window before the event. */
|
---|
349 | int cShapeRectsBefore;
|
---|
350 | /** The rectangles in the shaped window before the event */
|
---|
351 | XRectangle *paShapeRectsBefore;
|
---|
352 | /** The number of windows visible after the event */
|
---|
353 | unsigned cWindowsAfter;
|
---|
354 | /** An array of Window IDs for the visible and unmapped windows after
|
---|
355 | * the event */
|
---|
356 | Window *pahWindowsAfter;
|
---|
357 | /** The window attributes matching the windows in @a paWindowsAfter */
|
---|
358 | XWindowAttributes *paAttribsAfter;
|
---|
359 | /** The window names matching the windows in @a paWindowsAfter */
|
---|
360 | const char **papszNamesAfter;
|
---|
361 | /** The shaped window after the event - we allow at most one of these.
|
---|
362 | * Zero for none. */
|
---|
363 | Window hShapeWindowAfter;
|
---|
364 | /** The number of rectangles in the shaped window after the event. */
|
---|
365 | int cShapeRectsAfter;
|
---|
366 | /** The rectangles in the shaped window after the event */
|
---|
367 | XRectangle *paShapeRectsAfter;
|
---|
368 | /** The event to delivered */
|
---|
369 | int x11EventType;
|
---|
370 | /** The window for which the event in @enmEvent is delivered */
|
---|
371 | Window hEventWindow;
|
---|
372 | /** The number of windows expected to be reported at the end of the
|
---|
373 | * fixture */
|
---|
374 | unsigned cReportedRects;
|
---|
375 | /** The onscreen positions of those windows. */
|
---|
376 | RTRECT *paReportedRects;
|
---|
377 | /** Do we expect notification after the event? */
|
---|
378 | bool fExpectNotification;
|
---|
379 | };
|
---|
380 |
|
---|
381 | /*** Test fixture to test the code against X11 configure (move) events ***/
|
---|
382 |
|
---|
383 | static Window g_ahWin1[] = { 20 };
|
---|
384 | static XWindowAttributes g_aAttrib1Before[] =
|
---|
385 | { { 100, 200, 200, 300, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, IsViewable }
|
---|
386 | };
|
---|
387 | static XRectangle g_aRectangle1[] =
|
---|
388 | {
|
---|
389 | { 0, 0, 50, 50 },
|
---|
390 | { 50, 50, 150, 250 }
|
---|
391 | };
|
---|
392 | static XWindowAttributes g_aAttrib1After[] =
|
---|
393 | { { 200, 300, 200, 300, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, IsViewable }
|
---|
394 | };
|
---|
395 | static const char *g_apszNames1[] = { "Test Window" };
|
---|
396 |
|
---|
397 | AssertCompile(RT_ELEMENTS(g_ahWin1) == RT_ELEMENTS(g_aAttrib1Before));
|
---|
398 | AssertCompile(RT_ELEMENTS(g_ahWin1) == RT_ELEMENTS(g_aAttrib1After));
|
---|
399 | AssertCompile(RT_ELEMENTS(g_ahWin1) == RT_ELEMENTS(g_apszNames1));
|
---|
400 |
|
---|
401 | static RTRECT g_aRects1[] =
|
---|
402 | {
|
---|
403 | { 200, 300, 250, 350 },
|
---|
404 | { 250, 350, 400, 600 }
|
---|
405 | };
|
---|
406 |
|
---|
407 | static SMLSFIXTURE g_testMove =
|
---|
408 | {
|
---|
409 | RT_ELEMENTS(g_ahWin1),
|
---|
410 | g_ahWin1,
|
---|
411 | g_aAttrib1Before,
|
---|
412 | g_apszNames1,
|
---|
413 | 20,
|
---|
414 | RT_ELEMENTS(g_aRectangle1),
|
---|
415 | g_aRectangle1,
|
---|
416 | RT_ELEMENTS(g_ahWin1),
|
---|
417 | g_ahWin1,
|
---|
418 | g_aAttrib1After,
|
---|
419 | g_apszNames1,
|
---|
420 | 20,
|
---|
421 | RT_ELEMENTS(g_aRectangle1),
|
---|
422 | g_aRectangle1,
|
---|
423 | ConfigureNotify,
|
---|
424 | 20,
|
---|
425 | RT_ELEMENTS(g_aRects1),
|
---|
426 | g_aRects1,
|
---|
427 | true
|
---|
428 | };
|
---|
429 |
|
---|
430 | /*** Test fixture to test the code against X11 configure (resize) events ***/
|
---|
431 |
|
---|
432 | static XWindowAttributes g_aAttrib2Before[] =
|
---|
433 | { { 100, 200, 200, 300, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, IsViewable }
|
---|
434 | };
|
---|
435 | static XRectangle g_aRectangle2Before[] =
|
---|
436 | {
|
---|
437 | { 0, 0, 50, 50 },
|
---|
438 | { 50, 50, 100, 100 }
|
---|
439 | };
|
---|
440 |
|
---|
441 | AssertCompile(RT_ELEMENTS(g_ahWin1) == RT_ELEMENTS(g_aAttrib2Before));
|
---|
442 |
|
---|
443 | static SMLSFIXTURE g_testResize =
|
---|
444 | {
|
---|
445 | RT_ELEMENTS(g_ahWin1),
|
---|
446 | g_ahWin1,
|
---|
447 | g_aAttrib2Before,
|
---|
448 | g_apszNames1,
|
---|
449 | 20,
|
---|
450 | RT_ELEMENTS(g_aRectangle2Before),
|
---|
451 | g_aRectangle2Before,
|
---|
452 | RT_ELEMENTS(g_ahWin1),
|
---|
453 | g_ahWin1,
|
---|
454 | g_aAttrib1After,
|
---|
455 | g_apszNames1,
|
---|
456 | 20,
|
---|
457 | RT_ELEMENTS(g_aRectangle1),
|
---|
458 | g_aRectangle1,
|
---|
459 | ConfigureNotify,
|
---|
460 | 20,
|
---|
461 | RT_ELEMENTS(g_aRects1),
|
---|
462 | g_aRects1,
|
---|
463 | true
|
---|
464 | };
|
---|
465 |
|
---|
466 | /*** Test fixture to test the code against X11 map events ***/
|
---|
467 |
|
---|
468 | static XWindowAttributes g_aAttrib3Before[] =
|
---|
469 | { { 200, 300, 200, 300, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, IsUnmapped }
|
---|
470 | };
|
---|
471 |
|
---|
472 | AssertCompile(RT_ELEMENTS(g_ahWin1) == RT_ELEMENTS(g_aAttrib3Before));
|
---|
473 |
|
---|
474 | static SMLSFIXTURE g_testMap =
|
---|
475 | {
|
---|
476 | RT_ELEMENTS(g_ahWin1),
|
---|
477 | g_ahWin1,
|
---|
478 | g_aAttrib3Before,
|
---|
479 | g_apszNames1,
|
---|
480 | 20,
|
---|
481 | RT_ELEMENTS(g_aRectangle1),
|
---|
482 | g_aRectangle1,
|
---|
483 | RT_ELEMENTS(g_ahWin1),
|
---|
484 | g_ahWin1,
|
---|
485 | g_aAttrib1After,
|
---|
486 | g_apszNames1,
|
---|
487 | 20,
|
---|
488 | RT_ELEMENTS(g_aRectangle1),
|
---|
489 | g_aRectangle1,
|
---|
490 | MapNotify,
|
---|
491 | 20,
|
---|
492 | RT_ELEMENTS(g_aRects1),
|
---|
493 | g_aRects1,
|
---|
494 | true
|
---|
495 | };
|
---|
496 |
|
---|
497 | /*** Test fixtures to test the code against X11 unmap events ***/
|
---|
498 |
|
---|
499 | static XWindowAttributes g_aAttrib4After[] =
|
---|
500 | { { 100, 200, 300, 400, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, IsUnmapped }
|
---|
501 | };
|
---|
502 |
|
---|
503 | AssertCompile(RT_ELEMENTS(g_ahWin1) == RT_ELEMENTS(g_aAttrib4After));
|
---|
504 |
|
---|
505 | static SMLSFIXTURE g_testUnmap =
|
---|
506 | {
|
---|
507 | RT_ELEMENTS(g_ahWin1),
|
---|
508 | g_ahWin1,
|
---|
509 | g_aAttrib1Before,
|
---|
510 | g_apszNames1,
|
---|
511 | 20,
|
---|
512 | RT_ELEMENTS(g_aRectangle1),
|
---|
513 | g_aRectangle1,
|
---|
514 | RT_ELEMENTS(g_ahWin1),
|
---|
515 | g_ahWin1,
|
---|
516 | g_aAttrib4After,
|
---|
517 | g_apszNames1,
|
---|
518 | 20,
|
---|
519 | RT_ELEMENTS(g_aRectangle1),
|
---|
520 | g_aRectangle1,
|
---|
521 | UnmapNotify,
|
---|
522 | 20,
|
---|
523 | 0,
|
---|
524 | NULL,
|
---|
525 | true
|
---|
526 | };
|
---|
527 |
|
---|
528 | /*** A window we are not monitoring has been unmapped. Nothing should
|
---|
529 | *** happen, especially nothing bad. ***/
|
---|
530 |
|
---|
531 | static RTRECT g_aRects2[] =
|
---|
532 | {
|
---|
533 | { 100, 200, 150, 250 },
|
---|
534 | { 150, 250, 300, 500 }
|
---|
535 | };
|
---|
536 |
|
---|
537 | static SMLSFIXTURE g_testUnmapOther =
|
---|
538 | {
|
---|
539 | RT_ELEMENTS(g_ahWin1),
|
---|
540 | g_ahWin1,
|
---|
541 | g_aAttrib1Before,
|
---|
542 | g_apszNames1,
|
---|
543 | 20,
|
---|
544 | RT_ELEMENTS(g_aRectangle1),
|
---|
545 | g_aRectangle1,
|
---|
546 | RT_ELEMENTS(g_ahWin1),
|
---|
547 | g_ahWin1,
|
---|
548 | g_aAttrib1Before,
|
---|
549 | g_apszNames1,
|
---|
550 | 20,
|
---|
551 | RT_ELEMENTS(g_aRectangle1),
|
---|
552 | g_aRectangle1,
|
---|
553 | UnmapNotify,
|
---|
554 | 21,
|
---|
555 | RT_ELEMENTS(g_aRects2),
|
---|
556 | g_aRects2,
|
---|
557 | false
|
---|
558 | };
|
---|
559 |
|
---|
560 | /*** Test fixture to test the code against X11 shape events ***/
|
---|
561 |
|
---|
562 | static XRectangle g_aRectangle5Before[] =
|
---|
563 | {
|
---|
564 | { 0, 0, 200, 200 }
|
---|
565 | };
|
---|
566 |
|
---|
567 | static SMLSFIXTURE g_testShape =
|
---|
568 | {
|
---|
569 | RT_ELEMENTS(g_ahWin1),
|
---|
570 | g_ahWin1,
|
---|
571 | g_aAttrib1After,
|
---|
572 | g_apszNames1,
|
---|
573 | 20,
|
---|
574 | RT_ELEMENTS(g_aRectangle5Before),
|
---|
575 | g_aRectangle5Before,
|
---|
576 | RT_ELEMENTS(g_ahWin1),
|
---|
577 | g_ahWin1,
|
---|
578 | g_aAttrib1After,
|
---|
579 | g_apszNames1,
|
---|
580 | 20,
|
---|
581 | RT_ELEMENTS(g_aRectangle1),
|
---|
582 | g_aRectangle1,
|
---|
583 | VBoxShapeNotify,
|
---|
584 | 20,
|
---|
585 | RT_ELEMENTS(g_aRects1),
|
---|
586 | g_aRects1,
|
---|
587 | true
|
---|
588 | };
|
---|
589 |
|
---|
590 | /*** And the test code proper ***/
|
---|
591 |
|
---|
592 | /** Compare two RTRECT structures */
|
---|
593 | static bool smlsCompRect(RTRECT *pFirst, RTRECT *pSecond)
|
---|
594 | {
|
---|
595 | return ( (pFirst->xLeft == pSecond->xLeft)
|
---|
596 | && (pFirst->yTop == pSecond->yTop)
|
---|
597 | && (pFirst->xRight == pSecond->xRight)
|
---|
598 | && (pFirst->yBottom == pSecond->yBottom));
|
---|
599 | }
|
---|
600 |
|
---|
601 | static void smlsPrintDiffRects(RTRECT *pExp, RTRECT *pGot)
|
---|
602 | {
|
---|
603 | RTPrintf(" Expected: %d, %d, %d, %d. Got: %d, %d, %d, %d\n",
|
---|
604 | pExp->xLeft, pExp->yTop, pExp->xRight, pExp->yBottom,
|
---|
605 | pGot->xLeft, pGot->yTop, pGot->xRight, pGot->yBottom);
|
---|
606 | }
|
---|
607 |
|
---|
608 | /** Run through a test fixture */
|
---|
609 | static unsigned smlsDoFixture(SMLSFIXTURE *pFixture, const char *pszDesc)
|
---|
610 | {
|
---|
611 | SeamlessX11 subject;
|
---|
612 | unsigned cErrs = 0;
|
---|
613 |
|
---|
614 | subject.init(sendRegionUpdate);
|
---|
615 | smlsSetWindowAttributes(pFixture->paAttribsBefore,
|
---|
616 | pFixture->pahWindowsBefore,
|
---|
617 | pFixture->cWindowsBefore,
|
---|
618 | pFixture->papszNamesBefore);
|
---|
619 | smlsSetShapeRectangles(pFixture->hShapeWindowBefore,
|
---|
620 | pFixture->cShapeRectsBefore,
|
---|
621 | pFixture->paShapeRectsBefore);
|
---|
622 | subject.start();
|
---|
623 | smlsSetWindowAttributes(pFixture->paAttribsAfter,
|
---|
624 | pFixture->pahWindowsAfter,
|
---|
625 | pFixture->cWindowsAfter,
|
---|
626 | pFixture->papszNamesAfter);
|
---|
627 | smlsSetShapeRectangles(pFixture->hShapeWindowAfter,
|
---|
628 | pFixture->cShapeRectsAfter,
|
---|
629 | pFixture->paShapeRectsAfter);
|
---|
630 | smlsSetNextEvent(pFixture->x11EventType, pFixture->hEventWindow);
|
---|
631 | if (gotNotification()) /* Initial window tree rebuild */
|
---|
632 | {
|
---|
633 | RTPrintf("%s: fixture: %s. Notification was set before the first event!!!\n",
|
---|
634 | g_pszTestName, pszDesc);
|
---|
635 | ++cErrs;
|
---|
636 | }
|
---|
637 | subject.nextConfigurationEvent();
|
---|
638 | if (!gotNotification())
|
---|
639 | {
|
---|
640 | RTPrintf("%s: fixture: %s. No notification was sent for the initial window tree rebuild.\n",
|
---|
641 | g_pszTestName, pszDesc);
|
---|
642 | ++cErrs;
|
---|
643 | }
|
---|
644 | smlsSetNextEvent(0, 0);
|
---|
645 | subject.nextConfigurationEvent();
|
---|
646 | if (pFixture->fExpectNotification && !gotNotification())
|
---|
647 | {
|
---|
648 | RTPrintf("%s: fixture: %s. No notification was sent after the event.\n",
|
---|
649 | g_pszTestName, pszDesc);
|
---|
650 | ++cErrs;
|
---|
651 | }
|
---|
652 | RTRECT *pRects = subject.getRects();
|
---|
653 | size_t cRects = subject.getRectCount();
|
---|
654 | if (cRects != pFixture->cReportedRects)
|
---|
655 | {
|
---|
656 | RTPrintf("%s: fixture: %s. Wrong number of rectangles reported after processing event (expected %u, got %u).\n",
|
---|
657 | g_pszTestName, pszDesc, pFixture->cReportedRects,
|
---|
658 | cRects);
|
---|
659 | ++cErrs;
|
---|
660 | }
|
---|
661 | else
|
---|
662 | for (unsigned i = 0; i < cRects; ++i)
|
---|
663 | if (!smlsCompRect(&pRects[i], &pFixture->paReportedRects[i]))
|
---|
664 | {
|
---|
665 | RTPrintf("%s: fixture: %s. Rectangle %u wrong after processing event.\n",
|
---|
666 | g_pszTestName, pszDesc, i);
|
---|
667 | smlsPrintDiffRects(&pFixture->paReportedRects[i],
|
---|
668 | &pRects[i]);
|
---|
669 | ++cErrs;
|
---|
670 | break;
|
---|
671 | }
|
---|
672 | subject.stop();
|
---|
673 | subject.start();
|
---|
674 | if (cRects != pFixture->cReportedRects)
|
---|
675 | {
|
---|
676 | RTPrintf("%s: fixture: %s. Wrong number of rectangles reported without processing event (expected %u, got %u).\n",
|
---|
677 | g_pszTestName, pszDesc, pFixture->cReportedRects,
|
---|
678 | cRects);
|
---|
679 | ++cErrs;
|
---|
680 | }
|
---|
681 | else
|
---|
682 | for (unsigned i = 0; i < cRects; ++i)
|
---|
683 | if (!smlsCompRect(&pRects[i], &pFixture->paReportedRects[i]))
|
---|
684 | {
|
---|
685 | RTPrintf("%s: fixture: %s. Rectangle %u wrong without processing event.\n",
|
---|
686 | g_pszTestName, pszDesc, i);
|
---|
687 | smlsPrintDiffRects(&pFixture->paReportedRects[i],
|
---|
688 | &pRects[i]);
|
---|
689 | ++cErrs;
|
---|
690 | break;
|
---|
691 | }
|
---|
692 | return cErrs;
|
---|
693 | }
|
---|
694 |
|
---|
695 | int main( int argc, char **argv)
|
---|
696 | {
|
---|
697 | RTR3InitExe(argc, &argv, 0);
|
---|
698 | unsigned cErrs = 0;
|
---|
699 | g_pszTestName = RTPathFilename(argv[0]);
|
---|
700 |
|
---|
701 | RTPrintf("%s: TESTING\n", g_pszTestName);
|
---|
702 | cErrs += smlsDoFixture(&g_testMove,
|
---|
703 | "ConfigureNotify event (window moved)");
|
---|
704 | // Currently not working
|
---|
705 | cErrs += smlsDoFixture(&g_testResize,
|
---|
706 | "ConfigureNotify event (window resized)");
|
---|
707 | cErrs += smlsDoFixture(&g_testMap, "MapNotify event");
|
---|
708 | cErrs += smlsDoFixture(&g_testUnmap, "UnmapNotify event");
|
---|
709 | cErrs += smlsDoFixture(&g_testUnmapOther,
|
---|
710 | "UnmapNotify event for unmonitored window");
|
---|
711 | cErrs += smlsDoFixture(&g_testShape, "ShapeNotify event");
|
---|
712 | if (cErrs > 0)
|
---|
713 | RTPrintf("%u errors\n", cErrs);
|
---|
714 | return cErrs == 0 ? 0 : 1;
|
---|
715 | }
|
---|