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

Proposed by Sam Spilsbury
Status: Merged
Approved by: Sam Spilsbury
Approved revision: 3656
Merged at revision: 3676
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1167983
Merge into: lp:compiz/0.9.10
Diff against target: 955 lines (+563/-278)
1 file modified
plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp (+563/-278)
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 Approve
Steve Langasek Approve
Compiz Maintainers Pending
Review via email: mp+158742@code.launchpad.net

This proposal supersedes 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 : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Steve Langasek (vorlon) wrote :

Generally looks good to me. The refactoring of the workArea/struts handling was something I had already pondered in my previous attempt, but I left it out in the interest of being conservative with my changes (I thought perhaps we would have tests in the future that might require a different workArea).

I see some differences in the tests that I'd like to call out:

- previously, the first test tested that the window geometry remained the same when both width and height were reduced. The new test only tests reducing the width (1200->1024), not the height (800->768).
- the second test previously tested that the window geometry remained the same across a big->little->big screen size transition. The new tests are testing big->little and little->big separately, which means we're not testing for the possibility of wrong saved geometry handling (in the case where there should not be any saved geometry). I think this is important to test.
- WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewport: this has dropped a check that the window geometry remains the same after unplugging the monitor. It's important to test this explicitly, not just an unplug/plug round-trip, as the previous code did not get this case right.

> SetWindowGeometry (cw::Geometry (-(DUAL_MONITOR_WIDTH -
> WINDOW_X),

Would probably be clearer as 'WINDOW_X - DUAL_MONITOR_WIDTH' instead

> MakeScreenSmallerWindowOnSecondViewportOnFirstMonitorSecondViewport

seems to me that this test could do with a shorter name. 'MakeScreenSmallerWindowOnFirstMonitorSecondViewport'?

In total, there seems to be a net reduction of 4 EXPECT_EQ() occurrences in the new code vs. the old. One of these is the dropped check mentioned above for WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewport, a second is in applyGeometry(); I haven't looked to see where the other two have gone and whether they represent a regression in our test coverage.

review: Needs Fixing
Revision history for this message
Sam Spilsbury (smspillaz) wrote :
Download full text (5.3 KiB)

Hey Steve, thanks for the review.

> I see some differences in the tests that I'd like to call out:
>
> - previously, the first test tested that the window geometry remained the same
> when both width and height were reduced. The new test only tests reducing the
> width (1200->1024), not the height (800->768).

Thanks for catching that. I've created a separate test which checks that a reduction in screen height would likewise have no effect.

> - the second test previously tested that the window geometry remained the same
> across a big->little->big screen size transition. The new tests are testing
> big->little and little->big separately, which means we're not testing for the
> possibility of wrong saved geometry handling (in the case where there should
> not be any saved geometry). I think this is important to test.

So, at the moment what I've been doing is trying to get the number of asserts-per-test down to one, and splitting each case where we had a new assert into a different testcase. So there might be some instances where I've taken a test that does multiple things and split it into two and had some code duplicated. For example:

TEST_F (PlaceScreenSizeChange, MakeScreenLargerNoMovement)
{
    SetInitialScreenSize (CompSize (MONITOR_WIDTH,
        MONITOR_HEIGHT));
    SetWindowGeometry (cw::Geometry (WINDOW_X,
         WINDOW_Y,
         WINDOW_WIDTH,
         WINDOW_HEIGHT,
         0));

    /* Making the screen size bigger with no
     * saved geometry should cause the window not to move */
    cw::Geometry expectedWindowGeometryAfterChange =
 GetInitialWindowGeometry ();

    cw::Geometry windowGeometryAfterChange =
 ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
         DUAL_MONITOR_HEIGHT));

    EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
}

Test little -> big (no change, first assert in the second "test").

TEST_F (PlaceScreenSizeChange, MakeScreenSmallerWindowPlacedAtEdgeToFit)
{
    SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
        DUAL_MONITOR_HEIGHT));
    /* Move the window to the other "monitor" */
    SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
         WINDOW_Y,
         WINDOW_WIDTH,
         WINDOW_HEIGHT,
         0));

    /* Unplug a "monitor" */
    cw::Geometry windowGeometryAfterChange =
 ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
         MONITOR_HEIGHT));

    /* The window should be exactly on-screen at the edge */
    cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH - WINDOW_WIDTH,
          WINDOW_Y,
          WINDOW_WIDTH,
          WINDOW_HEIGHT,
          0);
    EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
}

Test little -> big -> little (expect that the window remains on the edge of the viewport).

> - WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewport: this has
> dropped a check that the window geometry remains the same after unplugging the
> monitor. It's important to test this explicitly, not just an unplug/plug
> round-trip, as the previous code did not get this case right.

Thanks for catching that. It was meant to conform to the specifics that I mentio...

Read more...

3655. By Sam Spilsbury

Pull out a few additional tests.

WindowOnPreviousViewportFirstMonitorStaysOnPreviousViewport v WindowOnPreviousViewportFirstMonitorStaysOnPreviousViewportWhenReplugged

and

WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewport v
WindowOnPreviousViewportSecondMonitorStaysOnPreviousViewportWhenReplugged

and

UnplugMonitorWindowOnSecondViewportFirstMonitorStaysOnFirstMonitor v
ReplugMonitorWindowOnSecondViewportFirstMonitorStaysOnFirstMonitor

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

More concise names for the tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

+1 for the name changes.
Unfortunately I am not able to test this, because I get hit by bug #1171364.

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

Steve ?

Revision history for this message
MC Return (mc-return) wrote :

If you would rebase this MP on trunk, I could *maybe/probably* test this...

Revision history for this message
Steve Langasek (vorlon) wrote :

Looks like it addresses my concerns, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

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-16 04:26:23 +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,164 @@
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 TALLER_MONITOR_HEIGHT = 1050;
100+const unsigned int MONITOR_WIDTH = 1024;
101+const unsigned int MONITOR_HEIGHT = 768;
102+
103+const unsigned int DUAL_MONITOR_WIDTH = MONITOR_WIDTH * 2;
104+const unsigned int DUAL_MONITOR_HEIGHT = MONITOR_HEIGHT * 2;
105+
106+const unsigned int WINDOW_WIDTH = 300;
107+const unsigned int WINDOW_HEIGHT = 400;
108+const unsigned int WINDOW_X = (MONITOR_WIDTH / 2) - (WINDOW_WIDTH / 2);
109+const unsigned int WINDOW_Y = (MONITOR_HEIGHT / 2) - (WINDOW_HEIGHT / 2);
110+
111+void
112+reserveStruts (CompRect &workArea,
113+ unsigned int strutSize)
114+{
115+ workArea.setLeft (workArea.left () + strutSize);
116+ workArea.setTop (workArea.top () + strutSize);
117+ workArea.setBottom (workArea.bottom () - strutSize);
118+}
119+}
120+
121+class PlaceScreenSizeChange :
122+ public CompPlaceScreenSizeChangeTest
123+{
124+ protected:
125+
126+ PlaceScreenSizeChange () :
127+ windowGeometryBeforeChange (),
128+ stubScreenSizeChangeObject (windowGeometryBeforeChange)
129+ {
130+ }
131+
132+ cw::Geometry
133+ ChangeScreenSizeAndAdjustWindow (const CompSize &newSize);
134+
135+ void
136+ SetWindowGeometry (const cw::Geometry &geometry);
137+
138+ void
139+ SetInitialScreenSize (const CompSize &size);
140+
141+ cw::Geometry
142+ GetInitialWindowGeometry ();
143+
144+ private:
145+
146+ CompSize screenSizeAfterChange;
147+ CompSize screenSizeBeforeChange;
148+
149+ cw::Geometry windowGeometryBeforeChange;
150+
151+ StubScreenSizeChangeObject stubScreenSizeChangeObject;
152+};
153+
154+cw::Geometry
155+PlaceScreenSizeChange::GetInitialWindowGeometry ()
156+{
157+ return windowGeometryBeforeChange;
158+}
159+
160+void
161+PlaceScreenSizeChange::SetInitialScreenSize (const CompSize &size)
162+{
163+ screenSizeBeforeChange = size;
164+}
165+
166+void
167+PlaceScreenSizeChange::SetWindowGeometry (const compiz::window::Geometry &geometry)
168+{
169+ windowGeometryBeforeChange = geometry;
170+ stubScreenSizeChangeObject.setGeometry (windowGeometryBeforeChange);
171+}
172+
173+cw::Geometry
174+PlaceScreenSizeChange::ChangeScreenSizeAndAdjustWindow (const CompSize &newSize)
175+{
176+ cw::Geometry g (stubScreenSizeChangeObject.sizeAdjustTest (screenSizeBeforeChange,
177+ newSize));
178+ screenSizeBeforeChange = newSize;
179+ return g;
180+}
181+
182+StubScreenSizeChangeObject::StubScreenSizeChangeObject (const cw::Geometry &g) :
183 ScreenSizeChangeObject (g),
184 mCurrentVp (0, 0),
185 mCurrentWorkArea (50, 50, 1000, 1000),
186 mCurrentGeometry (g)
187 {
188- memset (&mCurrentExtents, 0, sizeof (compiz::window::extents::Extents));
189+ memset (&mCurrentExtents, 0, sizeof (cw::extents::Extents));
190 }
191
192-MockScreenSizeChangeObject::~MockScreenSizeChangeObject ()
193+StubScreenSizeChangeObject::~StubScreenSizeChangeObject ()
194 {
195 }
196
197-const compiz::window::Geometry &
198-MockScreenSizeChangeObject::getGeometry () const
199+const cw::Geometry &
200+StubScreenSizeChangeObject::getGeometry () const
201 {
202 return mCurrentGeometry;
203 }
204
205 void
206-MockScreenSizeChangeObject::applyGeometry (compiz::window::Geometry &n,
207- compiz::window::Geometry &o)
208+StubScreenSizeChangeObject::applyGeometry (cw::Geometry &n,
209+ cw::Geometry &o)
210 {
211- EXPECT_EQ (mCurrentGeometry, o);
212-
213- std::cout << "DEBUG: new geometry : " << n.x () << " "
214- << n.y () << " "
215- << n.width () << " "
216- << n.height () << " "
217- << n.border () << std::endl;
218-
219- std::cout << "DEBUG: old geometry : " << o.x () << " "
220- << o.y () << " "
221- << o.width () << " "
222- << o.height () << " "
223- << o.border () << std::endl;
224+ ASSERT_EQ (mCurrentGeometry, o) << "incorrect usage of applyGeometry";
225
226 mCurrentGeometry = n;
227 }
228
229 const CompPoint &
230-MockScreenSizeChangeObject::getViewport () const
231+StubScreenSizeChangeObject::getViewport () const
232 {
233 return mCurrentVp;
234 }
235
236 const CompRect &
237-MockScreenSizeChangeObject::getWorkarea (const compiz::window::Geometry &g) const
238+StubScreenSizeChangeObject::getWorkarea (const cw::Geometry &g) const
239 {
240 return mCurrentWorkArea;
241 }
242
243-const compiz::window::extents::Extents &
244-MockScreenSizeChangeObject::getExtents () const
245+const cw::extents::Extents &
246+StubScreenSizeChangeObject::getExtents () const
247 {
248 return mCurrentExtents;
249 }
250
251 void
252-MockScreenSizeChangeObject::setVp (const CompPoint &p)
253+StubScreenSizeChangeObject::setVp (const CompPoint &p)
254 {
255 mCurrentVp = p;
256 }
257
258 void
259-MockScreenSizeChangeObject::setWorkArea (const CompRect &wa)
260+StubScreenSizeChangeObject::setWorkArea (const CompRect &wa)
261 {
262 mCurrentWorkArea = wa;
263 }
264
265 void
266-MockScreenSizeChangeObject::setExtents (unsigned int left,
267+StubScreenSizeChangeObject::setExtents (unsigned int left,
268 unsigned int right,
269 unsigned int top,
270 unsigned int bottom)
271@@ -152,266 +239,464 @@
272 }
273
274 void
275-MockScreenSizeChangeObject::setGeometry (const compiz::window::Geometry &g)
276+StubScreenSizeChangeObject::setGeometry (const cw::Geometry &g)
277 {
278 mCurrentGeometry = g;
279 }
280
281-void
282-reserveStruts (CompRect &workArea)
283+cw::Geometry
284+StubScreenSizeChangeObject::sizeAdjustTest (const CompSize &oldSize,
285+ const CompSize &newSize)
286 {
287- workArea.setLeft (workArea.left () + 24);
288- workArea.setTop (workArea.top () + 24);
289- workArea.setBottom (workArea.bottom () - 24);
290-}
291+ CompRect workArea (0,
292+ 0,
293+ newSize.width (),
294+ newSize.height ());
295
296-compiz::window::Geometry
297-MockScreenSizeChangeObject::sizeAdjustTest (const CompSize &oldSize,
298- const CompSize &newSize,
299- CompRect &workArea)
300-{
301 /* Reserve top, bottom and left parts of the screen for
302 * fake "24px" panels */
303- reserveStruts (workArea);
304+ reserveStruts (workArea, MOCK_STRUT_SIZE);
305
306 setWorkArea (workArea);
307
308- compiz::window::Geometry g = adjustForSize (oldSize, newSize);
309+ cw::Geometry g = adjustForSize (oldSize, newSize);
310
311 return g;
312 }
313
314-
315-TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
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-
327- /* First test that changing the screen size
328- * to something smaller here doesn't cause our
329- * (small) window to be moved */
330-
331- old = current;
332- current = CompSize (1024, 768);
333- workArea = CompRect (0, 0, current.width (), current.height ());
334-
335- expected = compiz::window::Geometry (200, 250, 300, 400, 0);
336-
337- g = ms.sizeAdjustTest (old, current, workArea);
338-
339- EXPECT_EQ (expected, g);
340+TEST_F (PlaceScreenSizeChange, NoMovementOnSmallerWidth)
341+{
342+ SetInitialScreenSize (CompSize (WIDESCREEN_MONITOR_WIDTH,
343+ MONITOR_HEIGHT));
344+ SetWindowGeometry (cw::Geometry (WINDOW_X,
345+ WINDOW_Y,
346+ WINDOW_WIDTH,
347+ WINDOW_HEIGHT,
348+ 0));
349+
350+ /* First test that changing the screen size
351+ * to something smaller here doesn't cause our
352+ * (small) window to be moved */
353+ cw::Geometry expectedWindowGeometryAfterChange =
354+ GetInitialWindowGeometry ();
355+
356+ cw::Geometry windowGeometryAfterChange =
357+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
358+ MONITOR_HEIGHT));
359+
360+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
361+}
362+
363+TEST_F (PlaceScreenSizeChange, NoMovementOnSmallerHeight)
364+{
365+ SetInitialScreenSize (CompSize (MONITOR_WIDTH,
366+ TALLER_MONITOR_HEIGHT));
367+ SetWindowGeometry (cw::Geometry (WINDOW_X,
368+ WINDOW_Y,
369+ WINDOW_WIDTH,
370+ WINDOW_HEIGHT,
371+ 0));
372+
373+ /* First test that changing the screen size
374+ * to something smaller here doesn't cause our
375+ * (small) window to be moved */
376+ cw::Geometry expectedWindowGeometryAfterChange =
377+ GetInitialWindowGeometry ();
378+
379+ cw::Geometry windowGeometryAfterChange =
380+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
381+ MONITOR_HEIGHT));
382+
383+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
384+}
385+
386+TEST_F (PlaceScreenSizeChange, NoMovementOnLargerSize)
387+{
388+ SetInitialScreenSize (CompSize (MONITOR_WIDTH,
389+ MONITOR_HEIGHT));
390+ SetWindowGeometry (cw::Geometry (WINDOW_X,
391+ WINDOW_Y,
392+ WINDOW_WIDTH,
393+ WINDOW_HEIGHT,
394+ 0));
395
396 /* Making the screen size bigger with no
397 * saved geometry should cause the window not to move */
398- old = current;
399- current = CompSize (2048, 768);
400- workArea = CompRect (0, 0, current.width (), current.height ());
401-
402- g = ms.sizeAdjustTest (old, current, workArea);
403-
404- EXPECT_EQ (expected, g);
405-
406- /* Move the window to the other "monitor" */
407- ms.setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
408-
409- /* Unplug a "monitor" */
410- old = current;
411- current = CompSize (1024, 768);
412- workArea = CompRect (0, 0, current.width (), current.height ());
413-
414- expected = compiz::window::Geometry (724, 250, 300, 400, 0);
415-
416- g = ms.sizeAdjustTest (old, current, workArea);
417-
418- EXPECT_EQ (expected, g);
419+ cw::Geometry expectedWindowGeometryAfterChange =
420+ GetInitialWindowGeometry ();
421+
422+ cw::Geometry windowGeometryAfterChange =
423+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
424+ DUAL_MONITOR_HEIGHT));
425+
426+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
427+}
428+
429+TEST_F (PlaceScreenSizeChange, MovedToEdgeOfRemainingMonitorOnUnplug)
430+{
431+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
432+ DUAL_MONITOR_HEIGHT));
433+ /* Move the window to the other "monitor" */
434+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
435+ WINDOW_Y,
436+ WINDOW_WIDTH,
437+ WINDOW_HEIGHT,
438+ 0));
439+
440+ /* Unplug a "monitor" */
441+ cw::Geometry windowGeometryAfterChange =
442+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
443+ MONITOR_HEIGHT));
444+
445+ /* The window should be exactly on-screen at the edge */
446+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH - WINDOW_WIDTH,
447+ WINDOW_Y,
448+ WINDOW_WIDTH,
449+ WINDOW_HEIGHT,
450+ 0);
451+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
452+}
453+
454+TEST_F (PlaceScreenSizeChange, MovedBackToOriginalPositionOnReplug)
455+{
456+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH, MONITOR_HEIGHT));
457+ /* Move the window to the other "monitor" */
458+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
459+ WINDOW_Y,
460+ WINDOW_WIDTH,
461+ WINDOW_HEIGHT,
462+ 0));
463+
464+ /* Unplug a "monitor" */
465+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH, MONITOR_HEIGHT));
466
467 /* Re-plug the monitor - window should go back
468 * to the same position */
469- old = current;
470- current = CompSize (2048, 768);
471- workArea = CompRect (0, 0, current.width (), current.height ());
472-
473- expected = compiz::window::Geometry (1025, 250, 300, 400, 0);
474-
475- g = ms.sizeAdjustTest (old, current, workArea);
476-
477- EXPECT_EQ (expected, g);
478+ cw::Geometry windowGeometryAfterChange =
479+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH, MONITOR_HEIGHT));
480+
481+ /* Window should be at the same position we left it at */
482+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
483+ WINDOW_Y,
484+ WINDOW_WIDTH,
485+ WINDOW_HEIGHT,
486+ 0);
487+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
488+}
489+
490+TEST_F (PlaceScreenSizeChange, MovedBackToOriginalPositionOnExpansion)
491+{
492+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
493+ MONITOR_HEIGHT));
494+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
495+ WINDOW_Y,
496+ WINDOW_WIDTH,
497+ WINDOW_HEIGHT,
498+ 0));
499+
500+ /* Unplug a "monitor" */
501+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
502+ MONITOR_HEIGHT));
503+
504+ /* Re-plug the monitor */
505+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
506+ MONITOR_HEIGHT));
507
508 /* Plug 2 monitors downwards, no change */
509- old = current;
510- current = CompSize (2048, 1536);
511- workArea = CompRect (0, 0, current.width (), current.height ());
512-
513- g = ms.sizeAdjustTest (old, current, workArea);
514-
515- EXPECT_EQ (expected, g);
516-
517- /* Move the window to the bottom "monitor" */
518- ms.setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
519-
520- /* Unplug bottom "monitor" */
521- old = current;
522- current = CompSize (2048, 768);
523- workArea = CompRect (0, 0, current.width (), current.height ());
524-
525- expected = compiz::window::Geometry (1025, 344, 300, 400, 0);
526-
527- g = ms.sizeAdjustTest (old, current, workArea);
528-
529- EXPECT_EQ (expected, g);
530+ cw::Geometry windowGeometryAfterChange =
531+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
532+ DUAL_MONITOR_HEIGHT));
533+
534+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
535+ WINDOW_Y,
536+ WINDOW_WIDTH,
537+ WINDOW_HEIGHT,
538+ 0);
539+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
540+}
541+
542+TEST_F (PlaceScreenSizeChange, NoOverlapStrutsOnRePlacement)
543+{
544+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
545+ MONITOR_HEIGHT));
546+ SetWindowGeometry (cw::Geometry (WINDOW_X,
547+ WINDOW_Y,
548+ WINDOW_WIDTH,
549+ WINDOW_HEIGHT,
550+ 0));
551+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
552+ DUAL_MONITOR_HEIGHT));
553+
554+ /* Move the window to the bottom "monitor" */
555+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
556+ MONITOR_HEIGHT + WINDOW_Y,
557+ WINDOW_WIDTH,
558+ WINDOW_HEIGHT,
559+ 0));
560+
561+ /* Unplug bottom "monitor" */
562+ cw::Geometry windowGeometryAfterChange =
563+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
564+ MONITOR_HEIGHT));
565+
566+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
567+ MONITOR_HEIGHT -
568+ WINDOW_HEIGHT -
569+ MOCK_STRUT_SIZE,
570+ WINDOW_WIDTH,
571+ WINDOW_HEIGHT,
572+ 0);
573+
574+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
575+}
576+
577+TEST_F (PlaceScreenSizeChange, MovedToOriginalPositionOnPerpendicularExpansion)
578+{
579+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
580+ DUAL_MONITOR_HEIGHT));
581+ SetWindowGeometry (cw::Geometry (WINDOW_X,
582+ WINDOW_Y,
583+ WINDOW_WIDTH,
584+ WINDOW_HEIGHT,
585+ 0));
586+
587+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
588+ DUAL_MONITOR_HEIGHT));
589+
590+ /* Move the window to the bottom "monitor" */
591+ SetWindowGeometry (cw::Geometry (MONITOR_WIDTH + WINDOW_X,
592+ MONITOR_HEIGHT + WINDOW_Y,
593+ WINDOW_WIDTH,
594+ WINDOW_HEIGHT,
595+ 0));
596+
597+ /* Unplug bottom "monitor" */
598+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
599+ MONITOR_HEIGHT));
600
601 /* Re-plug bottom "monitor" */
602- old = current;
603- current = CompSize (2048, 1356);
604- workArea = CompRect (0, 0, current.width (), current.height ());
605-
606- expected = compiz::window::Geometry (1025, 791, 300, 400, 0);
607-
608- g = ms.sizeAdjustTest (old, current, workArea);
609-
610- EXPECT_EQ (expected, g);
611-
612+ cw::Geometry windowGeometryAfterChange =
613+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
614+ DUAL_MONITOR_HEIGHT));
615+
616+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
617+ MONITOR_HEIGHT + WINDOW_Y,
618+ WINDOW_WIDTH,
619+ WINDOW_HEIGHT,
620+ 0);
621+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
622 }
623
624-TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnSecondViewport)
625+TEST_F (PlaceScreenSizeChange, RemainOnSecondViewportWhenConstraineToFirst)
626 {
627- CompSize current, old;
628- compiz::window::Geometry g (1025, 791, 300, 400, 0);
629- compiz::window::Geometry expected;
630-
631- MockScreenSizeChangeObject ms (g);
632-
633- current = CompSize (2048, 1356);
634-
635- CompRect workArea;
636-
637+ /* Unplug a "monitor" */
638+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
639+ DUAL_MONITOR_HEIGHT));
640 /* Move the entire window right a viewport */
641- g.setPos (g.pos () + CompPoint (current.width (), 0));
642- ms.setGeometry (g);
643+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH +
644+ MONITOR_WIDTH +
645+ WINDOW_X,
646+ WINDOW_Y,
647+ WINDOW_WIDTH,
648+ WINDOW_HEIGHT,
649+ 0));
650+
651+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH +
652+ (MONITOR_WIDTH -
653+ WINDOW_WIDTH),
654+ WINDOW_Y,
655+ WINDOW_WIDTH,
656+ WINDOW_HEIGHT,
657+ 0);
658
659 /* Now change the screen resolution again - the window should
660 * move to be within the constrained size of its current
661 * viewport */
662+ cw::Geometry windowGeometryAfterChange =
663+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
664+ DUAL_MONITOR_HEIGHT));
665+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
666+}
667+
668+TEST_F (PlaceScreenSizeChange, RemainOnSecondViewportAfterMovedToOriginalPosition)
669+{
670+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
671+ DUAL_MONITOR_HEIGHT));
672+ /* Move the entire window right a viewport */
673+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH +
674+ MONITOR_WIDTH +
675+ WINDOW_X,
676+ WINDOW_Y,
677+ WINDOW_WIDTH,
678+ WINDOW_HEIGHT,
679+ 0));
680
681 /* Unplug a "monitor" */
682- old = current;
683- current = CompSize (1024, 1356);
684- workArea = CompRect (0, 0, current.width (), current.height ());
685-
686- expected = compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0);
687-
688- g = ms.sizeAdjustTest (old, current, workArea);
689-
690- EXPECT_EQ (expected, g);
691+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
692+ DUAL_MONITOR_HEIGHT));
693
694 /* Replug the monitor, make sure that the geometry is restored */
695- old = current;
696- current = CompSize (2048, 1356);
697- workArea = CompRect (0, 0, current.width (), current.height ());
698-
699- expected = compiz::window::Geometry (current.width () + 1025, 791, 300, 400, 0);
700-
701- g = ms.sizeAdjustTest (old, current, workArea);
702-
703- EXPECT_EQ (expected, g);
704+ cw::Geometry expectedWindowGeometryAfterChange (DUAL_MONITOR_WIDTH +
705+ MONITOR_WIDTH +
706+ WINDOW_X,
707+ WINDOW_Y,
708+ WINDOW_WIDTH,
709+ WINDOW_HEIGHT,
710+ 0);
711+
712+ cw::Geometry windowGeometryAfterChange =
713+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
714+ DUAL_MONITOR_HEIGHT));
715+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
716+}
717+
718+TEST_F (PlaceScreenSizeChange, RemainAtOriginalPositionOnSecondViewportUnplug)
719+{
720+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
721+ DUAL_MONITOR_HEIGHT));
722+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH + WINDOW_X,
723+ MONITOR_HEIGHT + WINDOW_Y,
724+ WINDOW_WIDTH,
725+ WINDOW_HEIGHT,
726+ 0));
727+
728+ cw::Geometry windowGeometryAfterChange =
729+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
730+ DUAL_MONITOR_HEIGHT));
731+
732+ cw::Geometry expectedWindowGeometryAfterChange (MONITOR_WIDTH + WINDOW_X,
733+ MONITOR_HEIGHT + WINDOW_Y,
734+ WINDOW_WIDTH,
735+ WINDOW_HEIGHT,
736+ 0);
737+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
738+}
739+
740+TEST_F (PlaceScreenSizeChange, RemainAtOriginalPositionOnSecondViewportReplug)
741+{
742+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
743+ DUAL_MONITOR_HEIGHT));
744+ SetWindowGeometry (cw::Geometry (DUAL_MONITOR_WIDTH + WINDOW_X,
745+ MONITOR_HEIGHT + WINDOW_Y,
746+ WINDOW_WIDTH,
747+ WINDOW_HEIGHT,
748+ 0));
749+
750+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
751+ DUAL_MONITOR_HEIGHT));
752
753 /* Replug the monitor and move the window to where it fits on the first
754 * monitor on the second viewport, then make sure it doesn't move */
755- old = CompSize (2048, 1356);
756- current = CompSize (1024, 1356);
757- workArea = CompRect (0, 0, current.width (), current.height ());
758-
759- g.setPos (CompPoint (old.width () + 25, 791));
760- ms.setGeometry (g);
761- /* clear the saved geometry */
762- ms.unset();
763-
764- expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
765-
766- g = ms.sizeAdjustTest (old, current, workArea);
767-
768- EXPECT_EQ (expected, g);
769-
770- old = current;
771- current = CompSize (2048, 1356);
772- workArea = CompRect (0, 0, current.width (), current.height ());
773-
774- expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
775-
776- g = ms.sizeAdjustTest (old, current, workArea);
777-
778- EXPECT_EQ (expected, g);
779-}
780-
781-TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnPreviousViewport)
782-{
783- CompSize current, old;
784- compiz::window::Geometry g (0, 0, 300, 400, 0);
785- compiz::window::Geometry expected;
786-
787- MockScreenSizeChangeObject ms (g);
788-
789- current = CompSize (2048, 1356);
790-
791- CompRect workArea;
792-
793- /* Deal with the case where the position is negative, which means
794- * it's actually wrapped around to the rightmost viewport
795- */
796- g.setPos (CompPoint (-300, 200));
797- ms.setGeometry (g);
798-
799- expected = g;
800-
801- /* Unplug the right "monitor" */
802- old = current;
803- current = CompSize (1024, 1356);
804- workArea = CompRect (0, 0, current.width (), current.height ());
805-
806- g = ms.sizeAdjustTest (old, current, workArea);
807-
808- EXPECT_EQ (expected, g);
809+ cw::Geometry windowGeometryAfterChange =
810+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
811+ DUAL_MONITOR_HEIGHT));
812+
813+ cw::Geometry expectedWindowGeometryAfterChange = GetInitialWindowGeometry ();
814+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
815+}
816+
817+TEST_F (PlaceScreenSizeChange, RemainOnPreviousViewportWhenMovedToFirstMonitor)
818+{
819+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
820+ DUAL_MONITOR_HEIGHT));
821+
822+ /* Deal with the case where the position is negative, which means
823+ * it's actually wrapped around to the rightmost viewport
824+ */
825+ SetWindowGeometry (cw::Geometry (WINDOW_X - MONITOR_WIDTH,
826+ WINDOW_Y,
827+ WINDOW_WIDTH,
828+ WINDOW_HEIGHT,
829+ 0));
830+
831+ /* Unplug the right "monitor" */
832+ cw::Geometry windowGeometryAfterChange =
833+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
834+ DUAL_MONITOR_HEIGHT));
835+
836+ cw::Geometry expectedWindowGeometryAfterChange (-WINDOW_WIDTH,
837+ WINDOW_Y,
838+ WINDOW_WIDTH,
839+ WINDOW_HEIGHT,
840+ 0);
841+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
842+}
843+
844+TEST_F (PlaceScreenSizeChange, RemainOnPreviousViewportWhenRestored)
845+{
846+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
847+ DUAL_MONITOR_HEIGHT));
848+
849+ /* Deal with the case where the position is negative, which means
850+ * it's actually wrapped around to the rightmost viewport
851+ */
852+ SetWindowGeometry (cw::Geometry (WINDOW_X - MONITOR_WIDTH,
853+ WINDOW_Y,
854+ WINDOW_WIDTH,
855+ WINDOW_HEIGHT,
856+ 0));
857+
858+ /* Unplug the right "monitor" */
859+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
860+ DUAL_MONITOR_HEIGHT));
861
862 /* Re-plug the right "monitor" */
863- old = current;
864- current = CompSize (2048, 1356);
865- workArea = CompRect (0, 0, current.width (), current.height ());
866-
867- g = ms.sizeAdjustTest (old, current, workArea);
868-
869- EXPECT_EQ (expected, g);
870-
871- /* Move the window to the left monitor, verify that it survives an
872- * unplug/plug cycle
873- */
874- g.setPos (CompPoint (-1324, 200));
875- ms.setGeometry (g);
876-
877- old = current;
878- current = CompSize (1024, 1356);
879- workArea = CompRect (0, 0, current.width (), current.height ());
880-
881- expected = compiz::window::Geometry (-300, 200, 300, 400, 0);
882-
883- g = ms.sizeAdjustTest (old, current, workArea);
884-
885- EXPECT_EQ (expected, g);
886-
887- old = current;
888- current = CompSize (2048, 1356);
889- workArea = CompRect (0, 0, current.width (), current.height ());
890-
891- expected = compiz::window::Geometry (-1324, 200, 300, 400, 0);
892-
893- g = ms.sizeAdjustTest (old, current, workArea);
894-
895- EXPECT_EQ (expected, g);
896-
897+ cw::Geometry windowGeometryAfterChange =
898+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
899+ DUAL_MONITOR_HEIGHT));
900+
901+ cw::Geometry expectedWindowGeometryAfterChange = GetInitialWindowGeometry ();
902+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
903+}
904+
905+TEST_F (PlaceScreenSizeChange, RemainOnPreviousViewportFirstMonitor)
906+{
907+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
908+ DUAL_MONITOR_HEIGHT));
909+
910+ /* Move the window to the left monitor, verify that it survives an
911+ * unplug/plug cycle
912+ */
913+ SetWindowGeometry (cw::Geometry (WINDOW_X - DUAL_MONITOR_WIDTH,
914+ WINDOW_Y,
915+ WINDOW_WIDTH,
916+ WINDOW_HEIGHT,
917+ 0));
918+
919+ cw::Geometry windowGeometryAfterChange =
920+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
921+ DUAL_MONITOR_HEIGHT));
922+
923+ cw::Geometry expectedWindowGeometryAfterChange (WINDOW_X - MONITOR_WIDTH,
924+ WINDOW_Y,
925+ WINDOW_WIDTH,
926+ WINDOW_HEIGHT,
927+ 0);
928+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
929+}
930+
931+TEST_F (PlaceScreenSizeChange, RemainOnPreviousViewportFirstMonitorWhenRestored)
932+{
933+ SetInitialScreenSize (CompSize (DUAL_MONITOR_WIDTH,
934+ DUAL_MONITOR_HEIGHT));
935+
936+ /* Move the window to the left monitor, verify that it survives an
937+ * unplug/plug cycle
938+ */
939+ SetWindowGeometry (cw::Geometry (WINDOW_X - DUAL_MONITOR_WIDTH,
940+ WINDOW_Y,
941+ WINDOW_WIDTH,
942+ WINDOW_HEIGHT,
943+ 0));
944+
945+ ChangeScreenSizeAndAdjustWindow (CompSize (MONITOR_WIDTH,
946+ DUAL_MONITOR_HEIGHT));
947+
948+ cw::Geometry windowGeometryAfterChange =
949+ ChangeScreenSizeAndAdjustWindow (CompSize (DUAL_MONITOR_WIDTH,
950+ DUAL_MONITOR_HEIGHT));
951+
952+ cw::Geometry expectedWindowGeometryAfterChange
953+ = GetInitialWindowGeometry ();
954+ EXPECT_EQ (expectedWindowGeometryAfterChange, windowGeometryAfterChange);
955 }

Subscribers

People subscribed via source and target branches

to all changes: