Merge lp:~gerboland/miral/fix-windowmanager-tests into lp:miral

Proposed by Gerry Boland
Status: Merged
Merged at revision: 321
Proposed branch: lp:~gerboland/miral/fix-windowmanager-tests
Merge into: lp:miral
Diff against target: 301 lines (+67/-10)
1 file modified
miral-qt/tests/modules/WindowManager/windowmodel_test.cpp (+67/-10)
To merge this branch: bzr merge lp:~gerboland/miral/fix-windowmanager-tests
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+305283@code.launchpad.net

Commit message

[miral-qt] Fix failing tests due to lack of event loop, and fix mocking the Window size so can enable its test

To post a comment you must log in.
Revision history for this message
Gerry Boland (gerboland) wrote :

I could add functions to wrap each notifier.* method with flush() call, but wasn't sure the test readability would be enhanced. Second opinion desired.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+// windowSpec.of_size(toMirSize(size)); // useless, Window/Surface has the size actually used

useless

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> I could add functions to wrap each notifier.* method with flush() call, but
> wasn't sure the test readability would be enhanced. Second opinion desired.

Well, I'd be tempted by a bit more a restructuring of the tests:

All the tests start with:

    WindowModelNotifier notifier;
    WindowModel model(&notifier, nullptr); // no need for controller in this testcase

I don't see why these can't be moved into the fixture.

Then the fixture can have:

    void processEvents(std::function<void>(WindowModelNotifier& notifier) const& eventSource)
    {
        eventSource(notifier);
        qtApp->sendPostedEvents();
    }

and the tests can have:

    processEvents([&](WindowModelNotifier& notifier)
        {
            notifier.addWindow(mirWindowInfo1);
            notifier.addWindow(mirWindowInfo2);
        });

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

If you want to land this and (optionally) rework the tests later then I'm fine with that.

review: Approve
Revision history for this message
Gerry Boland (gerboland) wrote :

Rework more significant, so I'd prefer doing it separately

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'miral-qt/tests/modules/WindowManager/windowmodel_test.cpp'
--- miral-qt/tests/modules/WindowManager/windowmodel_test.cpp 2016-09-07 14:11:13 +0000
+++ miral-qt/tests/modules/WindowManager/windowmodel_test.cpp 2016-09-08 23:24:56 +0000
@@ -34,10 +34,19 @@
3434
35namespace ms = mir::scene;35namespace ms = mir::scene;
36namespace mg = mir::graphics;36namespace mg = mir::graphics;
37using StubSurface = mir::test::doubles::StubSurface;
38using StubSession = mir::test::doubles::StubSession;37using StubSession = mir::test::doubles::StubSession;
39using namespace testing;38using namespace testing;
4039
40struct SizedStubSurface : public mir::test::doubles::StubSurface
41{
42 mir::geometry::Size size() const override { return toMirSize(m_size); }
43
44 void setSize(QSize size) { m_size = size; }
45
46private:
47 QSize m_size;
48};
49
4150
42class WindowModelTest : public ::testing::Test51class WindowModelTest : public ::testing::Test
43{52{
@@ -51,16 +60,18 @@
51 miral::WindowInfo createMirALWindowInfo(QPoint position = {160, 320}, QSize size = {100, 200})60 miral::WindowInfo createMirALWindowInfo(QPoint position = {160, 320}, QSize size = {100, 200})
52 {61 {
53 const miral::Application app{stubSession};62 const miral::Application app{stubSession};
63 stubSurface->setSize(size);
54 const miral::Window window{app, stubSurface};64 const miral::Window window{app, stubSurface};
5565
56 ms::SurfaceCreationParameters windowSpec;66 ms::SurfaceCreationParameters windowSpec;
57 windowSpec.of_size(toMirSize(size));67// windowSpec.of_size(toMirSize(size)); // useless, Window/Surface has the size actually used
58 windowSpec.of_position(toMirPoint(position));68 windowSpec.of_position(toMirPoint(position));
59 return miral::WindowInfo{window, windowSpec};69 return miral::WindowInfo{window, windowSpec};
60 }70 }
6171
62 MirSurface *getMirSurfaceFromModel(const WindowModel &model, int index)72 MirSurface *getMirSurfaceFromModel(const WindowModel &model, int index)
63 {73 {
74 flushEvents();
64 return model.data(model.index(index, 0), WindowModel::SurfaceRole).value<MirSurface*>();75 return model.data(model.index(index, 0), WindowModel::SurfaceRole).value<MirSurface*>();
65 }76 }
6677
@@ -69,8 +80,26 @@
69 return getMirSurfaceFromModel(model, index)->window();80 return getMirSurfaceFromModel(model, index)->window();
70 }81 }
7182
83 void SetUp() override
84 {
85 int argc = 0;
86 char* argv[0];
87 qtApp = new QCoreApplication(argc, argv); // needed for event loop
88 }
89
90 void TearDown() override
91 {
92 delete qtApp;
93 }
94
95 void flushEvents()
96 {
97 qtApp->sendPostedEvents();
98 }
99
72 const std::shared_ptr<StubSession> stubSession{std::make_shared<StubSession>()};100 const std::shared_ptr<StubSession> stubSession{std::make_shared<StubSession>()};
73 const std::shared_ptr<StubSurface> stubSurface{std::make_shared<StubSurface>()};101 const std::shared_ptr<SizedStubSurface> stubSurface{std::make_shared<SizedStubSurface>()};
102 QCoreApplication *qtApp;
74};103};
75104
76/*105/*
@@ -85,6 +114,7 @@
85 auto mirWindowInfo = createMirALWindowInfo();114 auto mirWindowInfo = createMirALWindowInfo();
86115
87 notifier.addWindow(mirWindowInfo);116 notifier.addWindow(mirWindowInfo);
117 flushEvents();
88118
89 EXPECT_EQ(1, model.count());119 EXPECT_EQ(1, model.count());
90}120}
@@ -103,6 +133,7 @@
103 QSignalSpy spyCountChanged(&model, SIGNAL(countChanged()));133 QSignalSpy spyCountChanged(&model, SIGNAL(countChanged()));
104134
105 notifier.addWindow(mirWindowInfo);135 notifier.addWindow(mirWindowInfo);
136 flushEvents();
106137
107 EXPECT_EQ(1, spyCountChanged.count());138 EXPECT_EQ(1, spyCountChanged.count());
108}139}
@@ -119,6 +150,7 @@
119 auto mirWindowInfo = createMirALWindowInfo();150 auto mirWindowInfo = createMirALWindowInfo();
120151
121 notifier.addWindow(mirWindowInfo);152 notifier.addWindow(mirWindowInfo);
153 flushEvents();
122154
123 auto miralWindow = getMirALWindowFromModel(model, 0);155 auto miralWindow = getMirALWindowFromModel(model, 0);
124 EXPECT_EQ(mirWindowInfo.window(), miralWindow);156 EXPECT_EQ(mirWindowInfo.window(), miralWindow);
@@ -138,6 +170,7 @@
138170
139 // Test removing the window171 // Test removing the window
140 notifier.removeWindow(mirWindowInfo);172 notifier.removeWindow(mirWindowInfo);
173 flushEvents();
141174
142 EXPECT_EQ(0, model.count());175 EXPECT_EQ(0, model.count());
143}176}
@@ -153,11 +186,13 @@
153186
154 auto mirWindowInfo = createMirALWindowInfo();187 auto mirWindowInfo = createMirALWindowInfo();
155 notifier.addWindow(mirWindowInfo);188 notifier.addWindow(mirWindowInfo);
189 flushEvents();
156190
157 // Test removing the window191 // Test removing the window
158 QSignalSpy spyCountChanged(&model, SIGNAL(countChanged()));192 QSignalSpy spyCountChanged(&model, SIGNAL(countChanged()));
159193
160 notifier.removeWindow(mirWindowInfo);194 notifier.removeWindow(mirWindowInfo);
195 flushEvents();
161196
162 EXPECT_EQ(1, spyCountChanged.count());197 EXPECT_EQ(1, spyCountChanged.count());
163}198}
@@ -176,6 +211,7 @@
176211
177 notifier.addWindow(mirWindowInfo1);212 notifier.addWindow(mirWindowInfo1);
178 notifier.addWindow(mirWindowInfo2);213 notifier.addWindow(mirWindowInfo2);
214 flushEvents();
179215
180 ASSERT_EQ(2, model.count());216 ASSERT_EQ(2, model.count());
181 auto miralWindow1 = getMirALWindowFromModel(model, 0);217 auto miralWindow1 = getMirALWindowFromModel(model, 0);
@@ -200,6 +236,7 @@
200236
201 // Remove second window237 // Remove second window
202 notifier.removeWindow(mirWindowInfo2);238 notifier.removeWindow(mirWindowInfo2);
239 flushEvents();
203240
204 ASSERT_EQ(1, model.count());241 ASSERT_EQ(1, model.count());
205 auto miralWindow = getMirALWindowFromModel(model, 0);242 auto miralWindow = getMirALWindowFromModel(model, 0);
@@ -222,6 +259,7 @@
222259
223 // Remove first window260 // Remove first window
224 notifier.removeWindow(mirWindowInfo1);261 notifier.removeWindow(mirWindowInfo1);
262 flushEvents();
225263
226 ASSERT_EQ(1, model.count());264 ASSERT_EQ(1, model.count());
227 auto miralWindow = getMirALWindowFromModel(model, 0);265 auto miralWindow = getMirALWindowFromModel(model, 0);
@@ -245,6 +283,7 @@
245 notifier.removeWindow(mirWindowInfo1);283 notifier.removeWindow(mirWindowInfo1);
246284
247 notifier.addWindow(mirWindowInfo3);285 notifier.addWindow(mirWindowInfo3);
286 flushEvents();
248287
249 ASSERT_EQ(2, model.count());288 ASSERT_EQ(2, model.count());
250 auto miralWindow2 = getMirALWindowFromModel(model, 0);289 auto miralWindow2 = getMirALWindowFromModel(model, 0);
@@ -270,6 +309,7 @@
270 notifier.addWindow(mirWindowInfo3);309 notifier.addWindow(mirWindowInfo3);
271310
272 notifier.removeWindow(mirWindowInfo2);311 notifier.removeWindow(mirWindowInfo2);
312 flushEvents();
273313
274 ASSERT_EQ(2, model.count());314 ASSERT_EQ(2, model.count());
275 auto miralWindow1 = getMirALWindowFromModel(model, 0);315 auto miralWindow1 = getMirALWindowFromModel(model, 0);
@@ -291,6 +331,7 @@
291331
292 // Raise first window332 // Raise first window
293 notifier.raiseWindows({mirWindowInfo1.window()});333 notifier.raiseWindows({mirWindowInfo1.window()});
334 flushEvents();
294335
295 ASSERT_EQ(1, model.count());336 ASSERT_EQ(1, model.count());
296 auto topWindow = getMirALWindowFromModel(model, 0);337 auto topWindow = getMirALWindowFromModel(model, 0);
@@ -312,6 +353,7 @@
312353
313 // Raise second window (currently on top)354 // Raise second window (currently on top)
314 notifier.raiseWindows({mirWindowInfo2.window()});355 notifier.raiseWindows({mirWindowInfo2.window()});
356 flushEvents();
315357
316 // Check second window still on top358 // Check second window still on top
317 ASSERT_EQ(2, model.count());359 ASSERT_EQ(2, model.count());
@@ -334,6 +376,7 @@
334376
335 // Raise first window (currently at bottom)377 // Raise first window (currently at bottom)
336 notifier.raiseWindows({mirWindowInfo1.window()});378 notifier.raiseWindows({mirWindowInfo1.window()});
379 flushEvents();
337380
338 // Check first window now on top381 // Check first window now on top
339 ASSERT_EQ(2, model.count());382 ASSERT_EQ(2, model.count());
@@ -368,6 +411,8 @@
368 // 2: Window1411 // 2: Window1
369 // 1: Window2412 // 1: Window2
370 // 0: Window3413 // 0: Window3
414 flushEvents();
415
371 ASSERT_EQ(3, model.count());416 ASSERT_EQ(3, model.count());
372 auto topWindow = getMirALWindowFromModel(model, 2);417 auto topWindow = getMirALWindowFromModel(model, 2);
373 EXPECT_EQ(mirWindowInfo1.window(), topWindow);418 EXPECT_EQ(mirWindowInfo1.window(), topWindow);
@@ -400,6 +445,8 @@
400 // Model should now be like this:445 // Model should now be like this:
401 // 1: Window1446 // 1: Window1
402 // 0: Window2447 // 0: Window2
448 flushEvents();
449
403 ASSERT_EQ(2, model.count());450 ASSERT_EQ(2, model.count());
404 auto topWindow = getMirALWindowFromModel(model, 1);451 auto topWindow = getMirALWindowFromModel(model, 1);
405 EXPECT_EQ(mirWindowInfo1.window(), topWindow);452 EXPECT_EQ(mirWindowInfo1.window(), topWindow);
@@ -435,6 +482,8 @@
435 // 2: Window2482 // 2: Window2
436 // 1: Window1483 // 1: Window1
437 // 0: Window3484 // 0: Window3
485 flushEvents();
486
438 ASSERT_EQ(3, model.count());487 ASSERT_EQ(3, model.count());
439 auto topWindow = getMirALWindowFromModel(model, 2);488 auto topWindow = getMirALWindowFromModel(model, 2);
440 EXPECT_EQ(mirWindowInfo2.window(), topWindow);489 EXPECT_EQ(mirWindowInfo2.window(), topWindow);
@@ -456,6 +505,7 @@
456505
457 auto mirWindowInfo = createMirALWindowInfo(position);506 auto mirWindowInfo = createMirALWindowInfo(position);
458 notifier.addWindow(mirWindowInfo);507 notifier.addWindow(mirWindowInfo);
508 flushEvents();
459509
460 auto surface = getMirSurfaceFromModel(model, 0);510 auto surface = getMirSurfaceFromModel(model, 0);
461 EXPECT_EQ(position, surface->position());511 EXPECT_EQ(position, surface->position());
@@ -479,6 +529,7 @@
479529
480 // Move window, check new position set530 // Move window, check new position set
481 notifier.moveWindow(mirWindowInfo, toMirPoint(newPosition));531 notifier.moveWindow(mirWindowInfo, toMirPoint(newPosition));
532 flushEvents();
482533
483 EXPECT_EQ(newPosition, surface->position());534 EXPECT_EQ(newPosition, surface->position());
484}535}
@@ -503,6 +554,7 @@
503554
504 // Move window, check new position set555 // Move window, check new position set
505 notifier.moveWindow(mirWindowInfo1, toMirPoint(newPosition));556 notifier.moveWindow(mirWindowInfo1, toMirPoint(newPosition));
557 flushEvents();
506558
507 EXPECT_EQ(newPosition, surface->position());559 EXPECT_EQ(newPosition, surface->position());
508}560}
@@ -526,6 +578,7 @@
526578
527 // Move window, check new position set579 // Move window, check new position set
528 notifier.moveWindow(mirWindowInfo1, toMirPoint(QPoint(350, 420)));580 notifier.moveWindow(mirWindowInfo1, toMirPoint(QPoint(350, 420)));
581 flushEvents();
529582
530 // Ensure other window untouched583 // Ensure other window untouched
531 EXPECT_EQ(fixedPosition, surface->position());584 EXPECT_EQ(fixedPosition, surface->position());
@@ -543,6 +596,7 @@
543596
544 auto mirWindowInfo1 = createMirALWindowInfo(QPoint(), size);597 auto mirWindowInfo1 = createMirALWindowInfo(QPoint(), size);
545 notifier.addWindow(mirWindowInfo1);598 notifier.addWindow(mirWindowInfo1);
599 flushEvents();
546600
547 auto surface = getMirSurfaceFromModel(model, 0);601 auto surface = getMirSurfaceFromModel(model, 0);
548 EXPECT_EQ(size, surface->size());602 EXPECT_EQ(size, surface->size());
@@ -563,8 +617,9 @@
563617
564 auto surface = getMirSurfaceFromModel(model, 0);618 auto surface = getMirSurfaceFromModel(model, 0);
565619
566 // Move window, check new position set620 // Resize window, check new size set
567 notifier.resizeWindow(mirWindowInfo1, toMirSize(newSize));621 notifier.resizeWindow(mirWindowInfo1, toMirSize(newSize));
622 flushEvents();
568623
569 EXPECT_EQ(newSize, surface->size());624 EXPECT_EQ(newSize, surface->size());
570}625}
@@ -586,8 +641,9 @@
586641
587 auto surface = getMirSurfaceFromModel(model, 0);642 auto surface = getMirSurfaceFromModel(model, 0);
588643
589 // Move window, check new position set644 // Resize window, check new size set
590 notifier.resizeWindow(mirWindowInfo1, toMirSize(newSize));645 notifier.resizeWindow(mirWindowInfo1, toMirSize(newSize));
646 flushEvents();
591647
592 EXPECT_EQ(newSize, surface->size());648 EXPECT_EQ(newSize, surface->size());
593}649}
@@ -595,23 +651,24 @@
595/*651/*
596 * Test: with 2 windows, ensure window resize does not impact other MirSurfaces652 * Test: with 2 windows, ensure window resize does not impact other MirSurfaces
597 */653 */
598TEST_F(WindowModelTest, DISABLED_WindowResizeDoesNotTouchOtherMirSurfaces)654TEST_F(WindowModelTest, WindowResizeDoesNotTouchOtherMirSurfaces)
599{655{
600 WindowModelNotifier notifier;656 WindowModelNotifier notifier;
601 WindowModel model(&notifier, nullptr); // no need for controller in this testcase657 WindowModel model(&notifier, nullptr); // no need for controller in this testcase
602658
603 QSize fixedPosition(300, 400);659 QSize fixedSize(300, 400);
604660
605 auto mirWindowInfo1 = createMirALWindowInfo(QPoint(), QSize(100, 200));661 auto mirWindowInfo1 = createMirALWindowInfo(QPoint(), QSize(100, 200));
606 auto mirWindowInfo2 = createMirALWindowInfo(QPoint(), fixedPosition);662 auto mirWindowInfo2 = createMirALWindowInfo(QPoint(), fixedSize);
607 notifier.addWindow(mirWindowInfo1);663 notifier.addWindow(mirWindowInfo1);
608 notifier.addWindow(mirWindowInfo2);664 notifier.addWindow(mirWindowInfo2);
609665
610 auto surface = getMirSurfaceFromModel(model, 1);666 auto surface = getMirSurfaceFromModel(model, 1);
611667
612 // Move window668 // Resize window
613 notifier.resizeWindow(mirWindowInfo1, toMirSize(QSize(150, 220)));669 notifier.resizeWindow(mirWindowInfo1, toMirSize(QSize(150, 220)));
670 flushEvents();
614671
615 // Ensure other window untouched672 // Ensure other window untouched
616 EXPECT_EQ(fixedPosition, surface->size());673 EXPECT_EQ(fixedSize, surface->size());
617}674}

Subscribers

People subscribed via source and target branches