Merge lp:~compiz-team/compiz/compiz.fix_1167983 into lp:compiz/0.9.10

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1167983
Merge into: lp:compiz/0.9.10
Diff against target: 844 lines (+452/-260)
1 file modified
plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp (+452/-260)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1167983
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Compiz Maintainers Pending
Steve Langasek Pending
Review via email: mp+158738@code.launchpad.net

This proposal supersedes a proposal from 2013-04-11.

This proposal has been superseded by a proposal from 2013-04-13.

Commit message

Rewrite screen size change tests.

1. Rename the overly-terse variables names to variables names that have some
   significance
2. Split the giant three-test structure into multiple tests each with only one
   assert
3. Remove a lot of redundant calculation
4. Remove magic numbers peppered throughout the code. Use constants and
   express asserts as relationships between those constants.
5. Refactor some of the more common test-advancement code (such as changing
   the screen size) into the test fixture as common methods.

(LP: #1167983)

Description of the change

Rewrite screen size change tests.

1. Rename the overly-terse variables names to variables names that have some
   significance
2. Split the giant three-test structure into multiple tests each with only one
   assert
3. Remove a lot of redundant calculation
4. Remove magic numbers peppered throughout the code. Use constants and
   express asserts as relationships between those constants.
5. Refactor some of the more common test-advancement code (such as changing
   the screen size) into the test fixture as common methods.

(LP: #1167983)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

^ We're still hitting the valgrind + xorg-gtest race condition sadly :(

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
3655. By Sam Spilsbury

Pull out a few additional tests.

WindowOnPreviousViewportFirstMonitorStaysOnPreviousViewport v WindowOnPreviousViewportFirstMonitorStaysOnPreviousViewportWhenReplugged

and

WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewport v
WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewportWhenReplugged

and

UnplugMonitorWindowOnSecondViewportFirstMonitorStaysOnFirstMonitor v
ReplugMonitorWindowOnSecondViewportFirstMonitorStaysOnFirstMonitor

3656. By Sam Spilsbury

More concise names for the tests

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp'
2--- plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2013-04-07 08:50:44 +0000
3+++ plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2013-04-13 02:53:25 +0000
4@@ -25,29 +25,43 @@
5
6 #include <test-screen-size-change.h>
7 #include <screen-size-change.h>
8-#include <iostream>
9-#include <stdlib.h>
10-#include <cstring>
11-
12-class CompPlaceScreenSizeChangeTestScreenSizeChange :
13- public CompPlaceScreenSizeChangeTest
14-{
15-};
16-
17-class MockScreenSizeChangeObject :
18- public compiz::place::ScreenSizeChangeObject
19+
20+namespace cp = compiz::place;
21+namespace cw = compiz::window;
22+
23+namespace compiz
24+{
25+namespace window
26+{
27+std::ostream &
28+operator<< (std::ostream &os, const Geometry &g)
29+{
30+ return os << "compiz::window::Geometry " << std::endl
31+ << " - x: " << g.x () << std::endl
32+ << " - y: " << g.y () << std::endl
33+ << " - width: " << g.width () << std::endl
34+ << " - height: " << g.height () << std::endl
35+ << " - border: " << g.border ();
36+}
37+}
38+}
39+
40+namespace
41+{
42+class StubScreenSizeChangeObject :
43+ public cp::ScreenSizeChangeObject
44 {
45 public:
46
47- MockScreenSizeChangeObject (const compiz::window::Geometry &);
48- ~MockScreenSizeChangeObject ();
49+ StubScreenSizeChangeObject (const cw::Geometry &);
50+ ~StubScreenSizeChangeObject ();
51
52- const compiz::window::Geometry & getGeometry () const;
53- void applyGeometry (compiz::window::Geometry &n,
54- compiz::window::Geometry &o);
55+ const cw::Geometry & getGeometry () const;
56+ void applyGeometry (cw::Geometry &n,
57+ cw::Geometry &o);
58 const CompPoint & getViewport () const;
59- const CompRect & getWorkarea (const compiz::window::Geometry &g) const;
60- const compiz::window::extents::Extents & getExtents () const;
61+ const CompRect & getWorkarea (const cw::Geometry &g) const;
62+ const cw::extents::Extents & getExtents () const;
63
64 void setVp (const CompPoint &);
65 void setWorkArea (const CompRect &);
66@@ -56,91 +70,163 @@
67 unsigned int top,
68 unsigned int bottom);
69
70- void setGeometry (const compiz::window::Geometry &g);
71- compiz::window::Geometry sizeAdjustTest (const CompSize &oldSize,
72- const CompSize &newSize,
73- CompRect &workArea);
74-
75- private:
76-
77- CompPoint mCurrentVp;
78- CompRect mCurrentWorkArea;
79- compiz::window::extents::Extents mCurrentExtents;
80- compiz::window::Geometry mCurrentGeometry;
81-};
82-
83-MockScreenSizeChangeObject::MockScreenSizeChangeObject (const compiz::window::Geometry &g) :
84+ void setGeometry (const cw::Geometry &g);
85+ cw::Geometry sizeAdjustTest (const CompSize &oldSize,
86+ const CompSize &newSize);
87+
88+ private:
89+
90+ CompPoint mCurrentVp;
91+ CompRect mCurrentWorkArea;
92+ cw::extents::Extents mCurrentExtents;
93+ cw::Geometry mCurrentGeometry;
94+};
95+
96+const unsigned int MOCK_STRUT_SIZE = 24;
97+
98+const unsigned int WIDESCREEN_MONITOR_WIDTH = 1280;
99+const unsigned int MONITOR_WIDTH = 1024;
100+const unsigned int MONITOR_HEIGHT = 768;
101+
102+const unsigned int DUAL_MONITOR_WIDTH = MONITOR_WIDTH * 2;
103+const unsigned int DUAL_MONITOR_HEIGHT = MONITOR_HEIGHT * 2;
104+
105+const unsigned int WINDOW_WIDTH = 300;
106+const unsigned int WINDOW_HEIGHT = 400;
107+const unsigned int WINDOW_X = (MONITOR_WIDTH / 2) - (WINDOW_WIDTH / 2);
108+const unsigned int WINDOW_Y = (MONITOR_HEIGHT / 2) - (WINDOW_HEIGHT / 2);
109+
110+void
111+reserveStruts (CompRect &workArea,
112+ unsigned int strutSize)
113+{
114+ workArea.setLeft (workArea.left () + strutSize);
115+ workArea.setTop (workArea.top () + strutSize);
116+ workArea.setBottom (workArea.bottom () - strutSize);
117+}
118+}
119+
120+class PlaceScreenSizeChange :
121+ public CompPlaceScreenSizeChangeTest
122+{
123+ protected:
124+
125+ PlaceScreenSizeChange () :
126+ windowGeometryBeforeChange (),
127+ stubScreenSizeChangeObject (windowGeometryBeforeChange)
128+ {
129+ }
130+
131+ cw::Geometry
132+ ChangeScreenSizeAndAdjustWindow (const CompSize &newSize);
133+
134+ void
135+ SetWindowGeometry (const cw::Geometry &geometry);
136+
137+ void
138+ SetInitialScreenSize (const CompSize &size);
139+
140+ cw::Geometry
141+ GetInitialWindowGeometry ();
142+
143+ private:
144+
145+ CompSize screenSizeAfterChange;
146+ CompSize screenSizeBeforeChange;
147+
148+ cw::Geometry windowGeometryBeforeChange;
149+
150+ StubScreenSizeChangeObject stubScreenSizeChangeObject;
151+};
152+
153+cw::Geometry
154+PlaceScreenSizeChange::GetInitialWindowGeometry ()
155+{
156+ return windowGeometryBeforeChange;
157+}
158+
159+void
160+PlaceScreenSizeChange::SetInitialScreenSize (const CompSize &size)
161+{
162+ screenSizeBeforeChange = size;
163+}
164+
165+void
166+PlaceScreenSizeChange::SetWindowGeometry (const compiz::window::Geometry &geometry)
167+{
168+ windowGeometryBeforeChange = geometry;
169+ stubScreenSizeChangeObject.setGeometry (windowGeometryBeforeChange);
170+}
171+
172+cw::Geometry
173+PlaceScreenSizeChange::ChangeScreenSizeAndAdjustWindow (const CompSize &newSize)
174+{
175+ cw::Geometry g (stubScreenSizeChangeObject.sizeAdjustTest (screenSizeBeforeChange,
176+ newSize));
177+ screenSizeBeforeChange = newSize;
178+ return g;
179+}
180+
181+StubScreenSizeChangeObject::StubScreenSizeChangeObject (const cw::Geometry &g) :
182 ScreenSizeChangeObject (g),
183 mCurrentVp (0, 0),
184 mCurrentWorkArea (50, 50, 1000, 1000),
185 mCurrentGeometry (g)
186 {
187- memset (&mCurrentExtents, 0, sizeof (compiz::window::extents::Extents));
188+ memset (&mCurrentExtents, 0, sizeof (cw::extents::Extents));
189 }
190
191-MockScreenSizeChangeObject::~MockScreenSizeChangeObject ()
192+StubScreenSizeChangeObject::~StubScreenSizeChangeObject ()
193 {
194 }
195
196-const compiz::window::Geometry &
197-MockScreenSizeChangeObject::getGeometry () const
198+const cw::Geometry &
199+StubScreenSizeChangeObject::getGeometry () const
200 {
201 return mCurrentGeometry;
202 }
203
204 void
205-MockScreenSizeChangeObject::applyGeometry (compiz::window::Geometry &n,
206- compiz::window::Geometry &o)
207+StubScreenSizeChangeObject::applyGeometry (cw::Geometry &n,
208+ cw::Geometry &o)
209 {
210- EXPECT_EQ (mCurrentGeometry, o);
211-
212- std::cout << "DEBUG: new geometry : " << n.x () << " "
213- << n.y () << " "
214- << n.width () << " "
215- << n.height () << " "
216- << n.border () << std::endl;
217-
218- std::cout << "DEBUG: old geometry : " << o.x () << " "
219- << o.y () << " "
220- << o.width () << " "
221- << o.height () << " "
222- << o.border () << std::endl;
223+ ASSERT_EQ (mCurrentGeometry, o) << "incorrect usage of applyGeometry";
224
225 mCurrentGeometry = n;
226 }
227
228 const CompPoint &
229-MockScreenSizeChangeObject::getViewport () const
230+StubScreenSizeChangeObject::getViewport () const
231 {
232 return mCurrentVp;
233 }
234
235 const CompRect &
236-MockScreenSizeChangeObject::getWorkarea (const compiz::window::Geometry &g) const
237+StubScreenSizeChangeObject::getWorkarea (const cw::Geometry &g) const
238 {
239 return mCurrentWorkArea;
240 }
241
242-const compiz::window::extents::Extents &
243-MockScreenSizeChangeObject::getExtents () const
244+const cw::extents::Extents &
245+StubScreenSizeChangeObject::getExtents () const
246 {
247 return mCurrentExtents;
248 }
249
250 void
251-MockScreenSizeChangeObject::setVp (const CompPoint &p)
252+StubScreenSizeChangeObject::setVp (const CompPoint &p)
253 {
254 mCurrentVp = p;
255 }
256
257 void
258-MockScreenSizeChangeObject::setWorkArea (const CompRect &wa)
259+StubScreenSizeChangeObject::setWorkArea (const CompRect &wa)
260 {
261 mCurrentWorkArea = wa;
262 }
263
264 void
265-MockScreenSizeChangeObject::setExtents (unsigned int left,
266+StubScreenSizeChangeObject::setExtents (unsigned int left,
267 unsigned int right,
268 unsigned int top,
269 unsigned int bottom)
270@@ -152,266 +238,372 @@
271 }
272
273 void
274-MockScreenSizeChangeObject::setGeometry (const compiz::window::Geometry &g)
275+StubScreenSizeChangeObject::setGeometry (const cw::Geometry &g)
276 {
277 mCurrentGeometry = g;
278 }
279
280-void
281-reserveStruts (CompRect &workArea)
282+cw::Geometry
283+StubScreenSizeChangeObject::sizeAdjustTest (const CompSize &oldSize,
284+ const CompSize &newSize)
285 {
286- workArea.setLeft (workArea.left () + 24);
287- workArea.setTop (workArea.top () + 24);
288- workArea.setBottom (workArea.bottom () - 24);
289-}
290+ CompRect workArea (0,
291+ 0,
292+ newSize.width (),
293+ newSize.height ());
294
295-compiz::window::Geometry
296-MockScreenSizeChangeObject::sizeAdjustTest (const CompSize &oldSize,
297- const CompSize &newSize,
298- CompRect &workArea)
299-{
300 /* Reserve top, bottom and left parts of the screen for
301 * fake "24px" panels */
302- reserveStruts (workArea);
303+ reserveStruts (workArea, MOCK_STRUT_SIZE);
304
305 setWorkArea (workArea);
306
307- compiz::window::Geometry g = adjustForSize (oldSize, newSize);
308+ cw::Geometry g = adjustForSize (oldSize, newSize);
309
310 return g;
311 }
312
313-
314-TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
315+TEST_F (PlaceScreenSizeChange, MakeScreenSmallerNoMovement)
316 {
317- CompSize current, old;
318- compiz::window::Geometry g (200, 250, 300, 400, 0);
319- compiz::window::Geometry expected;
320-
321- MockScreenSizeChangeObject ms (g);
322-
323- current = CompSize (1280, 800);
324-
325- CompRect workArea;
326+ SetInitialScreenSize (CompSize (WIDESCREEN_MONITOR_WIDTH,
327+ MONITOR_HEIGHT));
328+ SetWindowGeometry (cw::Geometry (WINDOW_X,
329+ WINDOW_Y,
330+ WINDOW_WIDTH,
331+ WINDOW_HEIGHT,
332+ 0));
333
334 /* First test that changing the screen size
335 * to something smaller here doesn't cause our
336 * (small) window to be moved */
337-
338- old = current;
339- current = CompSize (1024, 768);
340- workArea = CompRect (0, 0, current.width (), current.height ());
341-
342- expected = compiz::window::Geometry (200, 250, 300, 400, 0);
343-
344- g = ms.sizeAdjustTest (old, current, workArea);
345-
346- EXPECT_EQ (expected, g);
347+ cw::Geometry expectedWindowGeometryAfterChange =
348+ GetInitialWindowGeometry ();
349+
350+ cw::Geometry windowGeometryAfterChange =
351+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
352+ MONITOR_HEIGHT));
353+
354+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
355+}
356+
357+TEST_F (PlaceScreenSizeChange, MakeScreenLargerNoMovement)
358+{
359+ SetInitialScreenSize (CompSize (MONITOR_WIDTH,
360+ MONITOR_HEIGHT));
361+ SetWindowGeometry (cw::Geometry (WINDOW_X,
362+ WINDOW_Y,
363+ WINDOW_WIDTH,
364+ WINDOW_HEIGHT,
365+ 0));
366
367 /* Making the screen size bigger with no
368 * saved geometry should cause the window not to move */
369- old = current;
370- current = CompSize (2048, 768);
371- workArea = CompRect (0, 0, current.width (), current.height ());
372-
373- g = ms.sizeAdjustTest (old, current, workArea);
374-
375- EXPECT_EQ (expected, g);
376-
377- /* Move the window to the other "monitor" */
378- ms.setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
379-
380- /* Unplug a "monitor" */
381- old = current;
382- current = CompSize (1024, 768);
383- workArea = CompRect (0, 0, current.width (), current.height ());
384-
385- expected = compiz::window::Geometry (724, 250, 300, 400, 0);
386-
387- g = ms.sizeAdjustTest (old, current, workArea);
388-
389- EXPECT_EQ (expected, g);
390+ cw::Geometry expectedWindowGeometryAfterChange =
391+ GetInitialWindowGeometry ();
392+
393+ cw::Geometry windowGeometryAfterChange =
394+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
395+ DUAL_MONITOR_HEIGHT));
396+
397+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
398+}
399+
400+TEST_F (PlaceScreenSizeChange, MakeScreenSmallerWindowPlacedAtEdgeToFit)
401+{
402+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
403+ DUAL_MONITOR_HEIGHT));
404+ /* Move the window to the other "monitor" */
405+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
406+ WINDOW_Y,
407+ WINDOW_WIDTH,
408+ WINDOW_HEIGHT,
409+ 0));
410+
411+ /* Unplug a "monitor" */
412+ cw::Geometry windowGeometryAfterChange =
413+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
414+ MONITOR_HEIGHT));
415+
416+ /* The window should be exactly on-screen at the edge */
417+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH - WINDOW_WIDTH,
418+ WINDOW_Y,
419+ WINDOW_WIDTH,
420+ WINDOW_HEIGHT,
421+ 0);
422+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
423+}
424+
425+TEST_F (PlaceScreenSizeChange, MonitorRepluggedWindowReturnsToOriginalPosition)
426+{
427+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH, MONITOR_HEIGHT));
428+ /* Move the window to the other "monitor" */
429+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
430+ WINDOW_Y,
431+ WINDOW_WIDTH,
432+ WINDOW_HEIGHT,
433+ 0));
434+
435+ /* Unplug a "monitor" */
436+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH, MONITOR_HEIGHT));
437
438 /* Re-plug the monitor - window should go back
439 * to the same position */
440- old = current;
441- current = CompSize (2048, 768);
442- workArea = CompRect (0, 0, current.width (), current.height ());
443-
444- expected = compiz::window::Geometry (1025, 250, 300, 400, 0);
445-
446- g = ms.sizeAdjustTest (old, current, workArea);
447-
448- EXPECT_EQ (expected, g);
449+ cw::Geometry windowGeometryAfterChange =
450+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH, MONITOR_HEIGHT));
451+
452+ /* Window should be at the same position we left it at */
453+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
454+ WINDOW_Y,
455+ WINDOW_WIDTH,
456+ WINDOW_HEIGHT,
457+ 0);
458+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
459+}
460+
461+TEST_F (PlaceScreenSizeChange, MonitorRepluggedAndExpandedNoChangeFromInitial)
462+{
463+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
464+ MONITOR_HEIGHT));
465+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
466+ WINDOW_Y,
467+ WINDOW_WIDTH,
468+ WINDOW_HEIGHT,
469+ 0));
470+
471+ /* Unplug a "monitor" */
472+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
473+ MONITOR_HEIGHT));
474+
475+ /* Re-plug the monitor */
476+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
477+ MONITOR_HEIGHT));
478
479 /* Plug 2 monitors downwards, no change */
480- old = current;
481- current = CompSize (2048, 1536);
482- workArea = CompRect (0, 0, current.width (), current.height ());
483-
484- g = ms.sizeAdjustTest (old, current, workArea);
485-
486- EXPECT_EQ (expected, g);
487-
488- /* Move the window to the bottom "monitor" */
489- ms.setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
490-
491- /* Unplug bottom "monitor" */
492- old = current;
493- current = CompSize (2048, 768);
494- workArea = CompRect (0, 0, current.width (), current.height ());
495-
496- expected = compiz::window::Geometry (1025, 344, 300, 400, 0);
497-
498- g = ms.sizeAdjustTest (old, current, workArea);
499-
500- EXPECT_EQ (expected, g);
501+ cw::Geometry windowGeometryAfterChange =
502+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
503+ DUAL_MONITOR_HEIGHT));
504+
505+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
506+ WINDOW_Y,
507+ WINDOW_WIDTH,
508+ WINDOW_HEIGHT,
509+ 0);
510+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
511+}
512+
513+TEST_F (PlaceScreenSizeChange, MakeScreenSmallerWindowPlacedAtBottomEdgeTakesIntoAccountStruts)
514+{
515+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
516+ MONITOR_HEIGHT));
517+ SetWindowGeometry (cw::Geometry (WINDOW_X,
518+ WINDOW_Y,
519+ WINDOW_WIDTH,
520+ WINDOW_HEIGHT,
521+ 0));
522+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
523+ DUAL_MONITOR_HEIGHT));
524+
525+ /* Move the window to the bottom "monitor" */
526+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
527+ MONITOR_HEIGHT + WINDOW_Y,
528+ WINDOW_WIDTH,
529+ WINDOW_HEIGHT,
530+ 0));
531+
532+ /* Unplug bottom "monitor" */
533+ cw::Geometry windowGeometryAfterChange =
534+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
535+ MONITOR_HEIGHT));
536+
537+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
538+ MONITOR_HEIGHT -
539+ WINDOW_HEIGHT -
540+ MOCK_STRUT_SIZE,
541+ WINDOW_WIDTH,
542+ WINDOW_HEIGHT,
543+ 0);
544+
545+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
546+}
547+
548+TEST_F (PlaceScreenSizeChange, ReplugBottomMonitorWindowReturnsToOriginalPosition)
549+{
550+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
551+ DUAL_MONITOR_HEIGHT));
552+ SetWindowGeometry (cw::Geometry (WINDOW_X,
553+ WINDOW_Y,
554+ WINDOW_WIDTH,
555+ WINDOW_HEIGHT,
556+ 0));
557+
558+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
559+ DUAL_MONITOR_HEIGHT));
560+
561+ /* Move the window to the bottom "monitor" */
562+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
563+ MONITOR_HEIGHT + WINDOW_Y,
564+ WINDOW_WIDTH,
565+ WINDOW_HEIGHT,
566+ 0));
567+
568+ /* Unplug bottom "monitor" */
569+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
570+ MONITOR_HEIGHT));
571
572 /* Re-plug bottom "monitor" */
573- old = current;
574- current = CompSize (2048, 1356);
575- workArea = CompRect (0, 0, current.width (), current.height ());
576-
577- expected = compiz::window::Geometry (1025, 791, 300, 400, 0);
578-
579- g = ms.sizeAdjustTest (old, current, workArea);
580-
581- EXPECT_EQ (expected, g);
582-
583+ cw::Geometry windowGeometryAfterChange =
584+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
585+ DUAL_MONITOR_HEIGHT));
586+
587+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
588+ MONITOR_HEIGHT + WINDOW_Y,
589+ WINDOW_WIDTH,
590+ WINDOW_HEIGHT,
591+ 0);
592+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
593 }
594
595-TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnSecondViewport)
596+TEST_F (PlaceScreenSizeChange, MakeScreenSmallerWindowOnSecondViewportOnFirstMonitorSecondViewport)
597 {
598- CompSize current, old;
599- compiz::window::Geometry g (1025, 791, 300, 400, 0);
600- compiz::window::Geometry expected;
601-
602- MockScreenSizeChangeObject ms (g);
603-
604- current = CompSize (2048, 1356);
605-
606- CompRect workArea;
607-
608+ /* Unplug a "monitor" */
609+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
610+ DUAL_MONITOR_HEIGHT));
611 /* Move the entire window right a viewport */
612- g.setPos (g.pos () + CompPoint (current.width (), 0));
613- ms.setGeometry (g);
614+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH +
615+ MONITOR_WIDTH +
616+ WINDOW_X,
617+ WINDOW_Y,
618+ WINDOW_WIDTH,
619+ WINDOW_HEIGHT,
620+ 0));
621+
622+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH +
623+ (MONITOR_WIDTH -
624+ WINDOW_WIDTH),
625+ WINDOW_Y,
626+ WINDOW_WIDTH,
627+ WINDOW_HEIGHT,
628+ 0);
629
630 /* Now change the screen resolution again - the window should
631 * move to be within the constrained size of its current
632 * viewport */
633+ cw::Geometry windowGeometryAfterChange =
634+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
635+ DUAL_MONITOR_HEIGHT));
636+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
637+}
638+
639+TEST_F (PlaceScreenSizeChange, ReplugMonitorWindowOnSecondViewportInitialPositionOnSecondViewport)
640+{
641+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
642+ DUAL_MONITOR_HEIGHT));
643+ /* Move the entire window right a viewport */
644+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH +
645+ MONITOR_WIDTH +
646+ WINDOW_X,
647+ WINDOW_Y,
648+ WINDOW_WIDTH,
649+ WINDOW_HEIGHT,
650+ 0));
651
652 /* Unplug a "monitor" */
653- old = current;
654- current = CompSize (1024, 1356);
655- workArea = CompRect (0, 0, current.width (), current.height ());
656-
657- expected = compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0);
658-
659- g = ms.sizeAdjustTest (old, current, workArea);
660-
661- EXPECT_EQ (expected, g);
662+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
663+ DUAL_MONITOR_HEIGHT));
664
665 /* Replug the monitor, make sure that the geometry is restored */
666- old = current;
667- current = CompSize (2048, 1356);
668- workArea = CompRect (0, 0, current.width (), current.height ());
669-
670- expected = compiz::window::Geometry (current.width () + 1025, 791, 300, 400, 0);
671-
672- g = ms.sizeAdjustTest (old, current, workArea);
673-
674- EXPECT_EQ (expected, g);
675+ cw::Geometry expectedWindowGeometryAfterChange (DUAL_MONITOR_WIDTH +
676+ MONITOR_WIDTH +
677+ WINDOW_X,
678+ WINDOW_Y,
679+ WINDOW_WIDTH,
680+ WINDOW_HEIGHT,
681+ 0);
682+
683+ cw::Geometry windowGeometryAfterChange =
684+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
685+ DUAL_MONITOR_HEIGHT));
686+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
687+}
688+
689+TEST_F (PlaceScreenSizeChange, ReplugMonitorWindowOnSecondViewportFirstMonitorStaysOnFirstMonitor)
690+{
691+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
692+ DUAL_MONITOR_HEIGHT));
693+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH + WINDOW_X,
694+ MONITOR_HEIGHT + WINDOW_Y,
695+ WINDOW_WIDTH,
696+ WINDOW_HEIGHT,
697+ 0));
698+
699+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
700+ DUAL_MONITOR_HEIGHT));
701
702 /* Replug the monitor and move the window to where it fits on the first
703 * monitor on the second viewport, then make sure it doesn't move */
704- old = CompSize (2048, 1356);
705- current = CompSize (1024, 1356);
706- workArea = CompRect (0, 0, current.width (), current.height ());
707-
708- g.setPos (CompPoint (old.width () + 25, 791));
709- ms.setGeometry (g);
710- /* clear the saved geometry */
711- ms.unset();
712-
713- expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
714-
715- g = ms.sizeAdjustTest (old, current, workArea);
716-
717- EXPECT_EQ (expected, g);
718-
719- old = current;
720- current = CompSize (2048, 1356);
721- workArea = CompRect (0, 0, current.width (), current.height ());
722-
723- expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
724-
725- g = ms.sizeAdjustTest (old, current, workArea);
726-
727- EXPECT_EQ (expected, g);
728+ cw::Geometry windowGeometryAfterChange =
729+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
730+ DUAL_MONITOR_HEIGHT));
731+
732+ cw::Geometry expectedWindowGeometryAfterChange = GetInitialWindowGeometry ();
733+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
734 }
735
736-TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnPreviousViewport)
737+TEST_F (PlaceScreenSizeChange, WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewport)
738 {
739- CompSize current, old;
740- compiz::window::Geometry g (0, 0, 300, 400, 0);
741- compiz::window::Geometry expected;
742-
743- MockScreenSizeChangeObject ms (g);
744-
745- current = CompSize (2048, 1356);
746-
747- CompRect workArea;
748+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
749+ DUAL_MONITOR_HEIGHT));
750
751 /* Deal with the case where the position is negative, which means
752 * it's actually wrapped around to the rightmost viewport
753 */
754- g.setPos (CompPoint (-300, 200));
755- ms.setGeometry (g);
756-
757- expected = g;
758+ SetWindowGeometry (cw::Geometry (-(MONITOR_WIDTH -
759+ WINDOW_X),
760+ WINDOW_Y,
761+ WINDOW_WIDTH,
762+ WINDOW_HEIGHT,
763+ 0));
764
765 /* Unplug the right "monitor" */
766- old = current;
767- current = CompSize (1024, 1356);
768- workArea = CompRect (0, 0, current.width (), current.height ());
769-
770- g = ms.sizeAdjustTest (old, current, workArea);
771-
772- EXPECT_EQ (expected, g);
773+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
774+ DUAL_MONITOR_HEIGHT));
775
776 /* Re-plug the right "monitor" */
777- old = current;
778- current = CompSize (2048, 1356);
779- workArea = CompRect (0, 0, current.width (), current.height ());
780-
781- g = ms.sizeAdjustTest (old, current, workArea);
782-
783- EXPECT_EQ (expected, g);
784+ cw::Geometry windowGeometryAfterChange =
785+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
786+ DUAL_MONITOR_HEIGHT));
787+
788+ cw::Geometry expectedWindowGeometryAfterChange = GetInitialWindowGeometry ();
789+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
790+}
791+
792+TEST_F (PlaceScreenSizeChange, WindowOnPreviousViewportFirstMonitorStaysOnPreviousViewport)
793+{
794+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
795+ DUAL_MONITOR_HEIGHT));
796
797 /* Move the window to the left monitor, verify that it survives an
798 * unplug/plug cycle
799 */
800- g.setPos (CompPoint (-1324, 200));
801- ms.setGeometry (g);
802-
803- old = current;
804- current = CompSize (1024, 1356);
805- workArea = CompRect (0, 0, current.width (), current.height ());
806-
807- expected = compiz::window::Geometry (-300, 200, 300, 400, 0);
808-
809- g = ms.sizeAdjustTest (old, current, workArea);
810-
811- EXPECT_EQ (expected, g);
812-
813- old = current;
814- current = CompSize (2048, 1356);
815- workArea = CompRect (0, 0, current.width (), current.height ());
816-
817- expected = compiz::window::Geometry (-1324, 200, 300, 400, 0);
818-
819- g = ms.sizeAdjustTest (old, current, workArea);
820-
821- EXPECT_EQ (expected, g);
822-
823+ SetWindowGeometry (cw::Geometry (-(DUAL_MONITOR_WIDTH -
824+ WINDOW_X),
825+ WINDOW_Y,
826+ WINDOW_WIDTH,
827+ WINDOW_HEIGHT,
828+ 0));
829+
830+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
831+ DUAL_MONITOR_HEIGHT));
832+
833+ cw::Geometry windowGeometryAfterChange =
834+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
835+ DUAL_MONITOR_HEIGHT));
836+
837+ cw::Geometry expectedWindowGeometryAfterChange (-(DUAL_MONITOR_WIDTH -
838+ WINDOW_X),
839+ WINDOW_Y,
840+ WINDOW_WIDTH,
841+ WINDOW_HEIGHT,
842+ 0);
843+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
844 }

Subscribers

People subscribed via source and target branches

to all changes: