Merge lp:~alan-griffiths/compiz-core/wrapsystem into lp:compiz-core/0.9.5

Proposed by Alan Griffiths
Status: Merged
Approved by: Sam Spilsbury
Approved revision: 2911
Merged at revision: 2912
Proposed branch: lp:~alan-griffiths/compiz-core/wrapsystem
Merge into: lp:compiz-core/0.9.5
Diff against target: 1056 lines (+358/-103)
14 files modified
include/core/wrapsystem.h (+43/-36)
plugins/composite/src/screen.cpp (+6/-6)
plugins/composite/src/window.cpp (+1/-1)
plugins/cube/src/cube.cpp (+9/-9)
plugins/opengl/src/paint.cpp (+10/-10)
plugins/scale/src/scale.cpp (+4/-4)
src/CMakeLists.txt (+1/-0)
src/event.cpp (+2/-2)
src/match.cpp (+3/-3)
src/plugin.cpp (+2/-2)
src/screen.cpp (+11/-11)
src/window.cpp (+19/-19)
src/wrapsystem/tests/CMakeLists.txt (+18/-0)
src/wrapsystem/tests/test-wrapsystem.cpp (+229/-0)
To merge this branch: bzr merge lp:~alan-griffiths/compiz-core/wrapsystem
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Sam Spilsbury Approve
Review via email: mp+88433@code.launchpad.net

Description of the change

Test harness for wrapsystem and some code initial cleanup.

To post a comment you must log in.
2911. By Alan Griffiths

Use new macros and drop magic numbers in implementation file

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Great.

I think it might be useful to look into whether or not we can make the constructor for the *Interface just do Foo::get (base) (just taking the *actual* "base" class name for that private class). That way we can get rid of ::setHandler

Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

+1 for no more magic numbers.

Clean merge, clean build, manual testing works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/wrapsystem.h'
2--- include/core/wrapsystem.h 2009-11-18 17:08:58 +0000
3+++ include/core/wrapsystem.h 2012-01-13 07:52:25 +0000
4@@ -28,6 +28,7 @@
5
6 #include <stdlib.h>
7 #include <vector>
8+#include <algorithm>
9
10 #define WRAPABLE_DEF(func, ...) \
11 { \
12@@ -48,10 +49,17 @@
13 void func ## SetCurrentIndex (unsigned int index) \
14 { \
15 mCurrFunction[num] = index; \
16- }
17+ } \
18+ enum { func ## Index = num };
19
20+// For compatability ignore num and forward
21 #define WRAPABLE_HND_FUNC(num, func, ...) \
22+ WRAPABLE_HND_FUNCTN(func, __VA_ARGS__)
23+
24+// New macro that doesn't need magic number
25+#define WRAPABLE_HND_FUNCTN(func, ...) \
26 { \
27+ enum { num = func ## Index }; \
28 unsigned int curr = mCurrFunction[num]; \
29 while (mCurrFunction[num] < mInterface.size () && \
30 !mInterface[mCurrFunction[num]].enabled[num]) \
31@@ -65,8 +73,14 @@
32 mCurrFunction[num] = curr; \
33 }
34
35+// For compatability ignore num and forward
36 #define WRAPABLE_HND_FUNC_RETURN(num, rtype, func, ...) \
37+ WRAPABLE_HND_FUNCTN_RETURN(rtype, func, __VA_ARGS__)
38+
39+// New macro that doesn't need magic number
40+#define WRAPABLE_HND_FUNCTN_RETURN(rtype, func, ...) \
41 { \
42+ enum { num = func ## Index }; \
43 unsigned int curr = mCurrFunction[num]; \
44 while (mCurrFunction[num] < mInterface.size () && \
45 !mInterface[mCurrFunction[num]].enabled[num]) \
46@@ -83,12 +97,12 @@
47 template <typename T, typename T2>
48 class WrapableInterface {
49 protected:
50- WrapableInterface () : mHandler (0) {};
51+ WrapableInterface () : mHandler (0) {}
52 virtual ~WrapableInterface ()
53 {
54 if (mHandler)
55 mHandler->unregisterWrap (static_cast<T2*> (this));
56- };
57+ }
58
59 void setHandler (T *handler, bool enabled = true)
60 {
61@@ -108,77 +122,70 @@
62 void registerWrap (T *, bool);
63 void unregisterWrap (T *);
64
65- unsigned int numWrapClients () { return mInterface.size (); };
66+ unsigned int numWrapClients () { return mInterface.size (); }
67
68 protected:
69
70- class Interface
71+ struct Interface
72 {
73- public:
74- T *obj;
75- bool *enabled;
76+ Interface(T *obj, bool enable) : obj(obj)
77+ {
78+ std::fill_n(this->enabled, N, enable);
79+ }
80+
81+ T *obj;
82+ bool enabled[N];
83 };
84
85 WrapableHandler () : mInterface ()
86 {
87- mCurrFunction = new unsigned int [N];
88- if (!mCurrFunction)
89- abort ();
90- for (unsigned int i = 0; i < N; i++)
91- mCurrFunction[i] = 0;
92- };
93+ std::fill_n(mCurrFunction, N, 0);
94+ }
95
96 ~WrapableHandler ()
97 {
98- typename std::vector<Interface>::iterator it;
99- for (it = mInterface.begin (); it != mInterface.end (); it++)
100- delete [] (*it).enabled;
101 mInterface.clear ();
102- delete [] mCurrFunction;
103- };
104+ }
105
106 void functionSetEnabled (T *, unsigned int, bool);
107
108- unsigned int *mCurrFunction;
109+ unsigned int mCurrFunction[N];
110 std::vector<Interface> mInterface;
111 };
112
113 template <typename T, unsigned int N>
114 void WrapableHandler<T,N>::registerWrap (T *obj, bool enabled)
115 {
116- typename WrapableHandler<T,N>::Interface in;
117- in.obj = obj;
118- in.enabled = new bool [N];
119- if (!in.enabled)
120- return;
121- for (unsigned int i = 0; i < N; i++)
122- in.enabled[i] = enabled;
123- mInterface.insert (mInterface.begin (), in);
124-};
125+ mInterface.insert (mInterface.begin (), Interface(obj, enabled));
126+}
127
128 template <typename T, unsigned int N>
129 void WrapableHandler<T,N>::unregisterWrap (T *obj)
130 {
131- typename std::vector<Interface>::iterator it;
132- for (it = mInterface.begin (); it != mInterface.end (); it++)
133- if ((*it).obj == obj)
134+ typedef typename std::vector<Interface>::iterator iterator;
135+ for (iterator it = mInterface.begin (); it != mInterface.end (); ++it)
136+ {
137+ if (it->obj == obj)
138 {
139- delete [] (*it).enabled;
140 mInterface.erase (it);
141 break;
142 }
143+ }
144 }
145
146 template <typename T, unsigned int N>
147 void WrapableHandler<T,N>::functionSetEnabled (T *obj, unsigned int num,
148 bool enabled)
149 {
150- for (unsigned int i = 0; i < mInterface.size (); i++)
151- if (mInterface[i].obj == obj)
152+ typedef typename std::vector<Interface>::iterator iterator;
153+ for (iterator it = mInterface.begin (); it != mInterface.end (); ++it)
154+ {
155+ if (it->obj == obj)
156 {
157- mInterface[i].enabled[num] = enabled;
158+ it->enabled[num] = enabled;
159 break;
160 }
161+ }
162 }
163
164 #endif
165
166=== modified file 'plugins/composite/src/screen.cpp'
167--- plugins/composite/src/screen.cpp 2011-10-31 13:51:00 +0000
168+++ plugins/composite/src/screen.cpp 2012-01-13 07:52:25 +0000
169@@ -388,7 +388,7 @@
170 {
171 Display *dpy;
172
173- WRAPABLE_HND_FUNC_RETURN (4, bool, registerPaintHandler, pHnd);
174+ WRAPABLE_HND_FUNCTN_RETURN (bool, registerPaintHandler, pHnd);
175
176 dpy = screen->dpy ();
177
178@@ -434,7 +434,7 @@
179 {
180 Display *dpy;
181
182- WRAPABLE_HND_FUNC (5, unregisterPaintHandler)
183+ WRAPABLE_HND_FUNCTN (unregisterPaintHandler)
184
185 dpy = screen->dpy ();
186
187@@ -913,17 +913,17 @@
188
189 void
190 CompositeScreen::preparePaint (int msSinceLastPaint)
191- WRAPABLE_HND_FUNC (0, preparePaint, msSinceLastPaint)
192+ WRAPABLE_HND_FUNCTN (preparePaint, msSinceLastPaint)
193
194 void
195 CompositeScreen::donePaint ()
196- WRAPABLE_HND_FUNC (1, donePaint)
197+ WRAPABLE_HND_FUNCTN (donePaint)
198
199 void
200 CompositeScreen::paint (CompOutput::ptrList &outputs,
201 unsigned int mask)
202 {
203- WRAPABLE_HND_FUNC (2, paint, outputs, mask)
204+ WRAPABLE_HND_FUNCTN (paint, outputs, mask)
205
206 if (priv->pHnd)
207 priv->pHnd->paintOutputs (outputs, mask, priv->tmpRegion);
208@@ -932,7 +932,7 @@
209 const CompWindowList &
210 CompositeScreen::getWindowPaintList ()
211 {
212- WRAPABLE_HND_FUNC_RETURN (3, const CompWindowList &, getWindowPaintList)
213+ WRAPABLE_HND_FUNCTN_RETURN (const CompWindowList &, getWindowPaintList)
214
215 /* Include destroyed windows */
216 if (screen->destroyedWindows ().empty ())
217
218=== modified file 'plugins/composite/src/window.cpp'
219--- plugins/composite/src/window.cpp 2011-09-29 03:29:41 +0000
220+++ plugins/composite/src/window.cpp 2012-01-13 07:52:25 +0000
221@@ -492,7 +492,7 @@
222 CompositeWindow::damageRect (bool initial,
223 const CompRect &rect)
224 {
225- WRAPABLE_HND_FUNC_RETURN (0, bool, damageRect, initial, rect)
226+ WRAPABLE_HND_FUNCTN_RETURN (bool, damageRect, initial, rect)
227 return false;
228 }
229
230
231=== modified file 'plugins/cube/src/cube.cpp'
232--- plugins/cube/src/cube.cpp 2011-02-24 07:52:09 +0000
233+++ plugins/cube/src/cube.cpp 2012-01-13 07:52:25 +0000
234@@ -213,7 +213,7 @@
235 bool
236 CubeScreen::cubeShouldPaintAllViewports ()
237 {
238- WRAPABLE_HND_FUNC_RETURN (8, bool, cubeShouldPaintAllViewports);
239+ WRAPABLE_HND_FUNCTN_RETURN (bool, cubeShouldPaintAllViewports);
240
241 return priv->mPaintAllViewports;
242 }
243@@ -816,7 +816,7 @@
244 CompOutput *output,
245 std::vector<GLVector> &points)
246 {
247- WRAPABLE_HND_FUNC_RETURN (5, bool, cubeCheckOrientation, sAttrib, transform, output, points)
248+ WRAPABLE_HND_FUNCTN_RETURN (bool, cubeCheckOrientation, sAttrib, transform, output, points)
249 GLMatrix sTransform = transform;
250 GLMatrix mvp, pm (priv->gScreen->projectionMatrix ());
251 GLVector pntA, pntB, pntC;
252@@ -863,7 +863,7 @@
253 CompOutput *output,
254 PaintOrder order)
255 {
256- WRAPABLE_HND_FUNC_RETURN (7, bool, cubeShouldPaintViewport, sAttrib, transform, output, order)
257+ WRAPABLE_HND_FUNCTN_RETURN (bool, cubeShouldPaintViewport, sAttrib, transform, output, order)
258
259 bool ftb;
260 float pointZ;
261@@ -1048,7 +1048,7 @@
262 void
263 CubeScreen::cubeGetRotation (float &x, float &v, float &progress)
264 {
265- WRAPABLE_HND_FUNC (0, cubeGetRotation, x, v, progress)
266+ WRAPABLE_HND_FUNCTN (cubeGetRotation, x, v, progress)
267
268 x = 0.0f;
269 v = 0.0f;
270@@ -1058,7 +1058,7 @@
271 void
272 CubeScreen::cubeClearTargetOutput (float xRotate, float vRotate)
273 {
274- WRAPABLE_HND_FUNC (1, cubeClearTargetOutput, xRotate, vRotate)
275+ WRAPABLE_HND_FUNCTN (cubeClearTargetOutput, xRotate, vRotate)
276
277 if (priv->mSky.size () > 0)
278 {
279@@ -1092,7 +1092,7 @@
280 CompOutput *output,
281 int size)
282 {
283- WRAPABLE_HND_FUNC (2, cubePaintTop, sAttrib, transform, output, size)
284+ WRAPABLE_HND_FUNCTN (cubePaintTop, sAttrib, transform, output, size)
285
286 GLScreenPaintAttrib sa = sAttrib;
287 GLMatrix sTransform = transform;
288@@ -1159,7 +1159,7 @@
289 CompOutput *output,
290 int size)
291 {
292- WRAPABLE_HND_FUNC (3, cubePaintBottom, sAttrib, transform, output, size)
293+ WRAPABLE_HND_FUNCTN (cubePaintBottom, sAttrib, transform, output, size)
294
295 GLScreenPaintAttrib sa = sAttrib;
296 GLMatrix sTransform = transform;
297@@ -1216,7 +1216,7 @@
298 CompOutput *output,
299 int size)
300 {
301- WRAPABLE_HND_FUNC (4, cubePaintInside, sAttrib, transform, output, size)
302+ WRAPABLE_HND_FUNCTN (cubePaintInside, sAttrib, transform, output, size)
303 }
304
305 void
306@@ -1272,7 +1272,7 @@
307 CompOutput *output,
308 unsigned int mask)
309 {
310- WRAPABLE_HND_FUNC (6, cubePaintViewport, sAttrib, transform, region, output, mask)
311+ WRAPABLE_HND_FUNCTN (cubePaintViewport, sAttrib, transform, region, output, mask)
312
313 priv->gScreen->glPaintTransformedOutput (sAttrib, transform, region,
314 output, mask);
315
316=== modified file 'plugins/opengl/src/paint.cpp'
317--- plugins/opengl/src/paint.cpp 2011-11-07 22:03:58 +0000
318+++ plugins/opengl/src/paint.cpp 2012-01-13 07:52:25 +0000
319@@ -49,7 +49,7 @@
320 CompOutput *output,
321 GLMatrix *transform)
322 {
323- WRAPABLE_HND_FUNC (2, glApplyTransform, sAttrib, output, transform)
324+ WRAPABLE_HND_FUNCTN (glApplyTransform, sAttrib, output, transform)
325
326 transform->translate (sAttrib.xTranslate,
327 sAttrib.yTranslate,
328@@ -362,7 +362,7 @@
329 const CompRegion &region,
330 CompOutput *output)
331 {
332- WRAPABLE_HND_FUNC (4, glEnableOutputClipping, transform, region, output)
333+ WRAPABLE_HND_FUNCTN (glEnableOutputClipping, transform, region, output)
334
335 GLdouble h = screen->height ();
336
337@@ -401,7 +401,7 @@
338 void
339 GLScreen::glDisableOutputClipping ()
340 {
341- WRAPABLE_HND_FUNC (4, glDisableOutputClipping)
342+ WRAPABLE_HND_FUNCTN (glDisableOutputClipping)
343
344 glDisable (GL_CLIP_PLANE0);
345 glDisable (GL_CLIP_PLANE1);
346@@ -419,7 +419,7 @@
347 CompOutput *output,
348 unsigned int mask)
349 {
350- WRAPABLE_HND_FUNC (2, glPaintTransformedOutput, sAttrib, transform,
351+ WRAPABLE_HND_FUNCTN (glPaintTransformedOutput, sAttrib, transform,
352 region, output, mask)
353
354 GLMatrix sTransform = transform;
355@@ -466,7 +466,7 @@
356 CompOutput *output,
357 unsigned int mask)
358 {
359- WRAPABLE_HND_FUNC_RETURN (1, bool, glPaintOutput, sAttrib, transform,
360+ WRAPABLE_HND_FUNCTN_RETURN (bool, glPaintOutput, sAttrib, transform,
361 region, output, mask)
362
363 GLMatrix sTransform = transform;
364@@ -591,7 +591,7 @@
365 void
366 GLWindow::glDrawGeometry ()
367 {
368- WRAPABLE_HND_FUNC (4, glDrawGeometry)
369+ WRAPABLE_HND_FUNCTN (glDrawGeometry)
370
371 int texUnit = priv->geometry.texUnits;
372 int currentTexUnit = 0;
373@@ -716,7 +716,7 @@
374 unsigned int maxGridWidth,
375 unsigned int maxGridHeight)
376 {
377- WRAPABLE_HND_FUNC (2, glAddGeometry, matrix, region, clip)
378+ WRAPABLE_HND_FUNCTN (glAddGeometry, matrix, region, clip)
379
380 BoxRec full;
381 int nMatrix = matrix.size ();
382@@ -1142,7 +1142,7 @@
383 GLFragment::Attrib &attrib,
384 unsigned int mask)
385 {
386- WRAPABLE_HND_FUNC (3, glDrawTexture, texture, attrib, mask)
387+ WRAPABLE_HND_FUNCTN (glDrawTexture, texture, attrib, mask)
388
389 GLTexture::Filter filter;
390
391@@ -1168,7 +1168,7 @@
392 const CompRegion &region,
393 unsigned int mask)
394 {
395- WRAPABLE_HND_FUNC_RETURN (1, bool, glDraw, transform,
396+ WRAPABLE_HND_FUNCTN_RETURN (bool, glDraw, transform,
397 fragment, region, mask)
398
399 const CompRegion reg = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ?
400@@ -1228,7 +1228,7 @@
401 const CompRegion &region,
402 unsigned int mask)
403 {
404- WRAPABLE_HND_FUNC_RETURN (0, bool, glPaint, attrib, transform, region, mask)
405+ WRAPABLE_HND_FUNCTN_RETURN (bool, glPaint, attrib, transform, region, mask)
406
407 GLFragment::Attrib fragment (attrib);
408 bool status;
409
410=== modified file 'plugins/scale/src/scale.cpp'
411--- plugins/scale/src/scale.cpp 2011-10-21 15:20:26 +0000
412+++ plugins/scale/src/scale.cpp 2012-01-13 07:52:25 +0000
413@@ -130,7 +130,7 @@
414 const CompRegion& region,
415 unsigned int mask)
416 {
417- WRAPABLE_HND_FUNC (0, scalePaintDecoration, attrib, transform, region, mask)
418+ WRAPABLE_HND_FUNCTN (scalePaintDecoration, attrib, transform, region, mask)
419
420 if (priv->spScreen->optionGetOverlayIcon () != ScaleOptions::OverlayIconNone)
421 {
422@@ -257,7 +257,7 @@
423 bool
424 ScaleWindow::setScaledPaintAttributes (GLWindowPaintAttrib& attrib)
425 {
426- WRAPABLE_HND_FUNC_RETURN (1, bool, setScaledPaintAttributes, attrib)
427+ WRAPABLE_HND_FUNCTN_RETURN (bool, setScaledPaintAttributes, attrib)
428
429 bool drawScaled = false;
430
431@@ -676,7 +676,7 @@
432 bool
433 ScaleScreen::layoutSlotsAndAssignWindows ()
434 {
435- WRAPABLE_HND_FUNC_RETURN (0, bool, layoutSlotsAndAssignWindows)
436+ WRAPABLE_HND_FUNCTN_RETURN (bool, layoutSlotsAndAssignWindows)
437
438 /* create a grid of slots */
439 priv->layoutSlots ();
440@@ -1209,7 +1209,7 @@
441 void
442 ScaleWindow::scaleSelectWindow ()
443 {
444- WRAPABLE_HND_FUNC (2, scaleSelectWindow)
445+ WRAPABLE_HND_FUNCTN (scaleSelectWindow)
446
447 if (priv->spScreen->selectedWindow != priv->window->id ())
448 {
449
450=== modified file 'src/CMakeLists.txt'
451--- src/CMakeLists.txt 2011-12-23 06:44:28 +0000
452+++ src/CMakeLists.txt 2012-01-13 07:52:25 +0000
453@@ -5,6 +5,7 @@
454 add_subdirectory( logmessage )
455 add_subdirectory( timer )
456 add_subdirectory( pluginclasshandler )
457+add_subdirectory( wrapsystem/tests )
458
459 compiz_add_bcop_targets (
460 core
461
462=== modified file 'src/event.cpp'
463--- src/event.cpp 2011-10-07 11:45:38 +0000
464+++ src/event.cpp 2012-01-13 07:52:25 +0000
465@@ -979,12 +979,12 @@
466 CompScreen::handleCompizEvent (const char *plugin,
467 const char *event,
468 CompOption::Vector &options)
469- WRAPABLE_HND_FUNC (7, handleCompizEvent, plugin, event, options)
470+ WRAPABLE_HND_FUNCTN (handleCompizEvent, plugin, event, options)
471
472 void
473 CompScreen::handleEvent (XEvent *event)
474 {
475- WRAPABLE_HND_FUNC (6, handleEvent, event)
476+ WRAPABLE_HND_FUNCTN (handleEvent, event)
477
478 CompWindow *w = NULL;
479 XWindowAttributes wa;
480
481=== modified file 'src/match.cpp'
482--- src/match.cpp 2009-07-14 22:01:03 +0000
483+++ src/match.cpp 2012-01-13 07:52:25 +0000
484@@ -116,7 +116,7 @@
485 CompMatch::Expression *
486 CompScreen::matchInitExp (const CompString& str)
487 {
488- WRAPABLE_HND_FUNC_RETURN (10, CompMatch::Expression *, matchInitExp, str)
489+ WRAPABLE_HND_FUNCTN_RETURN (CompMatch::Expression *, matchInitExp, str)
490
491 return new CoreExp (str);
492 }
493@@ -145,7 +145,7 @@
494 void
495 CompScreen::matchExpHandlerChanged ()
496 {
497- WRAPABLE_HND_FUNC (11, matchExpHandlerChanged)
498+ WRAPABLE_HND_FUNCTN (matchExpHandlerChanged)
499
500 foreach (CompPlugin *p, CompPlugin::getPlugins ())
501 {
502@@ -157,7 +157,7 @@
503 void
504 CompScreen::matchPropertyChanged (CompWindow *w)
505 {
506- WRAPABLE_HND_FUNC (12, matchPropertyChanged, w)
507+ WRAPABLE_HND_FUNCTN (matchPropertyChanged, w)
508 }
509
510 static void
511
512=== modified file 'src/plugin.cpp'
513--- src/plugin.cpp 2011-08-19 14:25:11 +0000
514+++ src/plugin.cpp 2012-01-13 07:52:25 +0000
515@@ -317,7 +317,7 @@
516 bool
517 CompScreen::initPluginForScreen (CompPlugin *p)
518 {
519- WRAPABLE_HND_FUNC_RETURN (2, bool, initPluginForScreen, p)
520+ WRAPABLE_HND_FUNCTN_RETURN (bool, initPluginForScreen, p)
521
522 bool status = true;
523 CompWindowList::iterator it, fail;
524@@ -349,7 +349,7 @@
525 void
526 CompScreen::finiPluginForScreen (CompPlugin *p)
527 {
528- WRAPABLE_HND_FUNC (3, finiPluginForScreen, p)
529+ WRAPABLE_HND_FUNCTN (finiPluginForScreen, p)
530
531 foreach (CompWindow *w, priv->windows)
532 p->vTable->finiWindow (w);
533
534=== modified file 'src/screen.cpp'
535--- src/screen.cpp 2011-10-31 13:51:00 +0000
536+++ src/screen.cpp 2012-01-13 07:52:25 +0000
537@@ -324,18 +324,18 @@
538
539 void
540 CompScreen::fileWatchAdded (CompFileWatch *watch)
541- WRAPABLE_HND_FUNC (0, fileWatchAdded, watch)
542+ WRAPABLE_HND_FUNCTN (fileWatchAdded, watch)
543
544 void
545 CompScreen::fileWatchRemoved (CompFileWatch *watch)
546- WRAPABLE_HND_FUNC (1, fileWatchRemoved, watch)
547+ WRAPABLE_HND_FUNCTN (fileWatchRemoved, watch)
548
549 bool
550 CompScreen::setOptionForPlugin (const char *plugin,
551 const char *name,
552 CompOption::Value &value)
553 {
554- WRAPABLE_HND_FUNC_RETURN (4, bool, setOptionForPlugin,
555+ WRAPABLE_HND_FUNCTN_RETURN (bool, setOptionForPlugin,
556 plugin, name, value)
557
558 CompPlugin *p = CompPlugin::find (plugin);
559@@ -348,7 +348,7 @@
560 void
561 CompScreen::sessionEvent (CompSession::Event event,
562 CompOption::Vector &arguments)
563- WRAPABLE_HND_FUNC (5, sessionEvent, event, arguments)
564+ WRAPABLE_HND_FUNCTN (sessionEvent, event, arguments)
565
566 void
567 ScreenInterface::fileWatchAdded (CompFileWatch *watch)
568@@ -1145,7 +1145,7 @@
569 int &stride,
570 void *&data)
571 {
572- WRAPABLE_HND_FUNC_RETURN (8, bool, fileToImage, name, size, stride, data);
573+ WRAPABLE_HND_FUNCTN_RETURN (bool, fileToImage, name, size, stride, data);
574 return false;
575 }
576
577@@ -1156,7 +1156,7 @@
578 int stride,
579 void *data)
580 {
581- WRAPABLE_HND_FUNC_RETURN (9, bool, imageToFile, path, format, size,
582+ WRAPABLE_HND_FUNCTN_RETURN (bool, imageToFile, path, format, size,
583 stride, data)
584 return false;
585 }
586@@ -1166,7 +1166,7 @@
587 CompLogLevel level,
588 const char *message)
589 {
590- WRAPABLE_HND_FUNC (13, logMessage, componentName, level, message)
591+ WRAPABLE_HND_FUNCTN (logMessage, componentName, level, message)
592 ::logMessage (componentName, level, message);
593 }
594
595@@ -2151,7 +2151,7 @@
596 void
597 CompScreen::addSupportedAtoms (std::vector<Atom> &atoms)
598 {
599- WRAPABLE_HND_FUNC (17, addSupportedAtoms, atoms);
600+ WRAPABLE_HND_FUNCTN (addSupportedAtoms, atoms);
601
602 atoms.push_back (Atoms::supported);
603 atoms.push_back (Atoms::supportingWmCheck);
604@@ -2350,7 +2350,7 @@
605 void
606 CompScreen::enterShowDesktopMode ()
607 {
608- WRAPABLE_HND_FUNC (14, enterShowDesktopMode)
609+ WRAPABLE_HND_FUNCTN (enterShowDesktopMode)
610
611 unsigned long data = 1;
612 int count = 0;
613@@ -2392,7 +2392,7 @@
614 void
615 CompScreen::leaveShowDesktopMode (CompWindow *window)
616 {
617- WRAPABLE_HND_FUNC (15, leaveShowDesktopMode, window)
618+ WRAPABLE_HND_FUNCTN (leaveShowDesktopMode, window)
619
620 unsigned long data = 0;
621
622@@ -3771,7 +3771,7 @@
623
624 void
625 CompScreen::outputChangeNotify ()
626- WRAPABLE_HND_FUNC (16, outputChangeNotify)
627+ WRAPABLE_HND_FUNCTN (outputChangeNotify)
628
629
630
631
632=== modified file 'src/window.cpp'
633--- src/window.cpp 2011-12-23 08:03:10 +0000
634+++ src/window.cpp 2012-01-13 07:52:25 +0000
635@@ -684,7 +684,7 @@
636 CompWindow::getAllowedActions (unsigned int &setActions,
637 unsigned int &clearActions)
638 {
639- WRAPABLE_HND_FUNC (1, getAllowedActions, setActions, clearActions)
640+ WRAPABLE_HND_FUNCTN (getAllowedActions, setActions, clearActions)
641
642 setActions = 0;
643 clearActions = 0;
644@@ -1108,7 +1108,7 @@
645 void
646 CompWindow::getOutputExtents (CompWindowExtents& output)
647 {
648- WRAPABLE_HND_FUNC (0, getOutputExtents, output)
649+ WRAPABLE_HND_FUNCTN (getOutputExtents, output)
650
651 output.left = 0;
652 output.right = 0;
653@@ -2532,7 +2532,7 @@
654 bool
655 CompWindow::focus ()
656 {
657- WRAPABLE_HND_FUNC_RETURN (2, bool, focus)
658+ WRAPABLE_HND_FUNCTN_RETURN (bool, focus)
659
660 if (overrideRedirect ())
661 return false;
662@@ -2561,7 +2561,7 @@
663 bool
664 CompWindow::place (CompPoint &pos)
665 {
666- WRAPABLE_HND_FUNC_RETURN (4, bool, place, pos)
667+ WRAPABLE_HND_FUNCTN_RETURN (bool, place, pos)
668 return false;
669 }
670
671@@ -2570,7 +2570,7 @@
672 XWindowChanges *xwc,
673 unsigned int source)
674 {
675- WRAPABLE_HND_FUNC (5, validateResizeRequest, mask, xwc, source)
676+ WRAPABLE_HND_FUNCTN (validateResizeRequest, mask, xwc, source)
677
678 if (!(priv->type & (CompWindowTypeDockMask |
679 CompWindowTypeFullscreenMask |
680@@ -2633,17 +2633,17 @@
681 int dy,
682 int dwidth,
683 int dheight)
684- WRAPABLE_HND_FUNC (6, resizeNotify, dx, dy, dwidth, dheight)
685+ WRAPABLE_HND_FUNCTN (resizeNotify, dx, dy, dwidth, dheight)
686
687 void
688 CompWindow::moveNotify (int dx,
689 int dy,
690 bool immediate)
691- WRAPABLE_HND_FUNC (7, moveNotify, dx, dy, immediate)
692+ WRAPABLE_HND_FUNCTN (moveNotify, dx, dy, immediate)
693
694 void
695 CompWindow::windowNotify (CompWindowNotify n)
696- WRAPABLE_HND_FUNC (8, windowNotify, n)
697+ WRAPABLE_HND_FUNCTN (windowNotify, n)
698
699 void
700 CompWindow::grabNotify (int x,
701@@ -2651,21 +2651,21 @@
702 unsigned int state,
703 unsigned int mask)
704 {
705- WRAPABLE_HND_FUNC (9, grabNotify, x, y, state, mask)
706+ WRAPABLE_HND_FUNCTN (grabNotify, x, y, state, mask)
707 priv->grabbed = true;
708 }
709
710 void
711 CompWindow::ungrabNotify ()
712 {
713- WRAPABLE_HND_FUNC (10, ungrabNotify)
714+ WRAPABLE_HND_FUNCTN (ungrabNotify)
715 priv->grabbed = false;
716 }
717
718 void
719 CompWindow::stateChangeNotify (unsigned int lastState)
720 {
721- WRAPABLE_HND_FUNC (11, stateChangeNotify, lastState);
722+ WRAPABLE_HND_FUNCTN (stateChangeNotify, lastState);
723
724 /* if being made sticky */
725 if (!(lastState & CompWindowStateStickyMask) &&
726@@ -4667,7 +4667,7 @@
727 void
728 CompWindow::activate ()
729 {
730- WRAPABLE_HND_FUNC (3, activate)
731+ WRAPABLE_HND_FUNCTN (activate)
732
733 screen->priv->setCurrentDesktop (priv->desktop);
734
735@@ -4969,7 +4969,7 @@
736 void
737 CompWindow::minimize ()
738 {
739- WRAPABLE_HND_FUNC (13, minimize);
740+ WRAPABLE_HND_FUNCTN (minimize);
741
742 if (!priv->managed)
743 return;
744@@ -4999,7 +4999,7 @@
745 void
746 CompWindow::unminimize ()
747 {
748- WRAPABLE_HND_FUNC (14, unminimize);
749+ WRAPABLE_HND_FUNCTN (unminimize);
750 if (priv->minimized)
751 {
752 windowNotify (CompWindowNotifyUnminimize);
753@@ -6052,7 +6052,7 @@
754 bool
755 CompWindow::managed ()
756 {
757- WRAPABLE_HND_FUNC_RETURN (18, bool, managed);
758+ WRAPABLE_HND_FUNCTN_RETURN (bool, managed);
759 return priv->managed;
760 }
761
762@@ -6252,7 +6252,7 @@
763 bool
764 CompWindow::minimized ()
765 {
766- WRAPABLE_HND_FUNC_RETURN (15, bool, minimized);
767+ WRAPABLE_HND_FUNCTN_RETURN (bool, minimized);
768 return priv->minimized;
769 }
770
771@@ -6801,7 +6801,7 @@
772 bool
773 CompWindow::alpha ()
774 {
775- WRAPABLE_HND_FUNC_RETURN (16, bool, alpha);
776+ WRAPABLE_HND_FUNCTN_RETURN (bool, alpha);
777
778 return priv->alpha;
779 }
780@@ -6840,7 +6840,7 @@
781 bool
782 CompWindow::isFocussable ()
783 {
784- WRAPABLE_HND_FUNC_RETURN (17, bool, isFocussable);
785+ WRAPABLE_HND_FUNCTN_RETURN (bool, isFocussable);
786
787 if (priv->inputHint)
788 return true;
789@@ -6994,7 +6994,7 @@
790
791 void
792 CompWindow::updateFrameRegion (CompRegion& region)
793- WRAPABLE_HND_FUNC (12, updateFrameRegion, region)
794+ WRAPABLE_HND_FUNCTN (updateFrameRegion, region)
795
796 bool
797 PrivateWindow::reparent ()
798
799=== added directory 'src/wrapsystem'
800=== added directory 'src/wrapsystem/tests'
801=== added file 'src/wrapsystem/tests/CMakeLists.txt'
802--- src/wrapsystem/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
803+++ src/wrapsystem/tests/CMakeLists.txt 2012-01-13 07:52:25 +0000
804@@ -0,0 +1,18 @@
805+include_directories(
806+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../include
807+)
808+
809+add_executable(
810+ compiz_wrapsystem_test
811+
812+ ${CMAKE_CURRENT_SOURCE_DIR}/test-wrapsystem.cpp
813+)
814+
815+target_link_libraries(
816+ compiz_wrapsystem_test
817+
818+ ${GTEST_BOTH_LIBRARIES}
819+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
820+)
821+
822+add_test( compiz_wrapsystem_test compiz_wrapsystem_test )
823
824=== added file 'src/wrapsystem/tests/test-wrapsystem.cpp'
825--- src/wrapsystem/tests/test-wrapsystem.cpp 1970-01-01 00:00:00 +0000
826+++ src/wrapsystem/tests/test-wrapsystem.cpp 2012-01-13 07:52:25 +0000
827@@ -0,0 +1,229 @@
828+#include "core/wrapsystem.h"
829+
830+#include <gtest/gtest.h>
831+
832+//#define TEST_OLD_MACROS
833+
834+namespace {
835+
836+class TestImplementation;
837+
838+class TestInterface : public WrapableInterface<TestImplementation, TestInterface> {
839+public:
840+ TestInterface();
841+ ~TestInterface();
842+
843+ virtual void testMethodReturningVoid() /* const */ = 0;
844+ virtual int testMethodReturningInt(int i) /* const */ = 0;
845+
846+ static int testMethodReturningVoidCalls;
847+ static int testMethodReturningIntCalls;
848+
849+private:
850+ TestInterface(TestInterface const&);
851+ TestInterface& operator=(TestInterface const&);
852+};
853+
854+// Needs a magic number for the count of "wrappable" functions
855+class TestImplementation : public WrapableHandler<TestInterface, 2> {
856+public:
857+
858+ // 1. need for magic numbers
859+ // 2. why can't we just pass &TestInterface::testMethod (and deduce return etc.
860+ // 3. relies on __VA_ARGS__ when an extra set of parentheses would be enough
861+ WRAPABLE_HND (0, TestInterface, void, testMethodReturningVoid)
862+
863+ WRAPABLE_HND (1, TestInterface, int, testMethodReturningInt, int)
864+
865+ static int testMethodReturningVoidCalls;
866+ static int testMethodReturningIntCalls;
867+};
868+
869+class TestWrapper : public TestInterface {
870+ TestImplementation& impl;
871+public:
872+
873+ TestWrapper(TestImplementation& impl)
874+ : impl(impl)
875+ { setHandler(&impl, true); } // The need to remember this is a PITA
876+
877+ ~TestWrapper()
878+ { setHandler(&impl, false); } // The need to remember this is a PITA
879+
880+ virtual void testMethodReturningVoid();
881+ virtual int testMethodReturningInt(int i);
882+
883+ static int testMethodReturningVoidCalls;
884+ static int testMethodReturningIntCalls;
885+
886+ void disableTestMethodReturningVoid() {
887+ impl.testMethodReturningVoidSetEnabled (this, false);
888+ }
889+};
890+} // (abstract) namespace
891+
892+
893+int TestWrapper::testMethodReturningVoidCalls = 0;
894+int TestInterface::testMethodReturningVoidCalls = 0;
895+int TestImplementation::testMethodReturningVoidCalls = 0;
896+
897+int TestWrapper::testMethodReturningIntCalls = 0;
898+int TestInterface::testMethodReturningIntCalls = 0;
899+int TestImplementation::testMethodReturningIntCalls = 0;
900+
901+// A pain these need definition after TestImplementation definition
902+TestInterface::TestInterface() {}
903+TestInterface::~TestInterface() {}
904+
905+void TestInterface::testMethodReturningVoid() /* const */ {
906+ WRAPABLE_DEF (testMethodReturningVoid);
907+ testMethodReturningVoidCalls++;
908+}
909+
910+int TestInterface::testMethodReturningInt(int i) {
911+ WRAPABLE_DEF (testMethodReturningInt, i);
912+ testMethodReturningIntCalls++;
913+ return i;
914+}
915+
916+void TestImplementation::testMethodReturningVoid() {
917+#ifdef TEST_OLD_MACROS
918+ WRAPABLE_HND_FUNC(0, testMethodReturningVoid) // Magic number needs to match class definition
919+#else
920+ WRAPABLE_HND_FUNCTN(testMethodReturningVoid)
921+#endif
922+ testMethodReturningVoidCalls++;
923+}
924+
925+int TestImplementation::testMethodReturningInt(int i) {
926+#ifdef TEST_OLD_MACROS
927+ WRAPABLE_HND_FUNC_RETURN(1, int, testMethodReturningInt, i) // Magic number needs to match class definition
928+#else
929+ WRAPABLE_HND_FUNCTN_RETURN(int, testMethodReturningInt, i)
930+#endif
931+ testMethodReturningIntCalls++;
932+ return i;
933+}
934+
935+void TestWrapper::testMethodReturningVoid() {
936+ impl.testMethodReturningVoid();
937+ testMethodReturningVoidCalls++;
938+}
939+
940+int TestWrapper::testMethodReturningInt(int i) {
941+ testMethodReturningIntCalls++;
942+ return impl.testMethodReturningInt(i);
943+}
944+
945+
946+TEST(WrapSystem, an_interface_never_gets_functions_called)
947+{
948+ TestInterface::testMethodReturningIntCalls = 0;
949+
950+ TestImplementation imp;
951+
952+ imp.testMethodReturningInt(1);
953+ ASSERT_EQ(0, TestInterface::testMethodReturningIntCalls);
954+
955+ {
956+ TestWrapper wrap(imp);
957+
958+ imp.testMethodReturningInt(1);
959+ ASSERT_EQ(0, TestInterface::testMethodReturningIntCalls);
960+ }
961+
962+ imp.testMethodReturningInt(1);
963+ ASSERT_EQ(0, TestInterface::testMethodReturningIntCalls);
964+}
965+
966+TEST(WrapSystem, an_interface_never_gets_void_functions_called)
967+{
968+ TestInterface::testMethodReturningVoidCalls = 0;
969+
970+ TestImplementation imp;
971+
972+ imp.testMethodReturningVoid();
973+ ASSERT_EQ(0, TestInterface::testMethodReturningVoidCalls);
974+
975+ {
976+ TestWrapper wrap(imp);
977+
978+ imp.testMethodReturningVoid();
979+ ASSERT_EQ(0, TestInterface::testMethodReturningVoidCalls);
980+ }
981+
982+ imp.testMethodReturningVoid();
983+ ASSERT_EQ(0, TestInterface::testMethodReturningVoidCalls);
984+}
985+
986+TEST(WrapSystem, an_implementation_gets_functions_called)
987+{
988+ TestImplementation::testMethodReturningVoidCalls = 0;
989+
990+ TestImplementation imp;
991+ {
992+ TestWrapper wrap(imp);
993+
994+ imp.testMethodReturningVoid();
995+
996+ ASSERT_EQ(1, TestImplementation::testMethodReturningVoidCalls);
997+ }
998+
999+ imp.testMethodReturningVoid();
1000+
1001+ ASSERT_EQ(2, TestImplementation::testMethodReturningVoidCalls);
1002+}
1003+
1004+TEST(WrapSystem, a_wrapper_gets_its_functions_called)
1005+{
1006+ TestWrapper::testMethodReturningVoidCalls = 0;
1007+
1008+ TestImplementation imp;
1009+ {
1010+ TestWrapper wrap(imp);
1011+
1012+ imp.testMethodReturningVoid();
1013+
1014+ ASSERT_EQ(1, TestWrapper::testMethodReturningVoidCalls);
1015+ }
1016+
1017+ imp.testMethodReturningVoid();
1018+
1019+ ASSERT_EQ(1, TestWrapper::testMethodReturningVoidCalls);
1020+}
1021+
1022+TEST(WrapSystem, a_wrapper_doesnt_get_disabled_functions_called)
1023+{
1024+ TestWrapper::testMethodReturningVoidCalls = 0;
1025+
1026+ TestImplementation imp;
1027+ {
1028+ TestWrapper wrap(imp);
1029+
1030+ wrap.disableTestMethodReturningVoid();
1031+
1032+ imp.testMethodReturningVoid();
1033+
1034+ ASSERT_EQ(0, TestWrapper::testMethodReturningVoidCalls);
1035+ }
1036+}
1037+
1038+TEST(WrapSystem, two_wrappers_get_their_functions_called)
1039+{
1040+ TestWrapper::testMethodReturningVoidCalls = 0;
1041+
1042+ TestImplementation imp;
1043+ {
1044+ TestWrapper wrap1(imp);
1045+ TestWrapper wrap2(imp);
1046+
1047+ imp.testMethodReturningVoid();
1048+
1049+ ASSERT_EQ(2, TestWrapper::testMethodReturningVoidCalls);
1050+ }
1051+
1052+ imp.testMethodReturningVoid();
1053+
1054+ ASSERT_EQ(2, TestWrapper::testMethodReturningVoidCalls);
1055+}
1056+

Subscribers

People subscribed via source and target branches