2 * Copyright (C) 2017 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include <QtTest/QtTest>
19// WindowManager plugin
20#include <TopLevelWindowModel.h>
23#include "UnityApplicationMocks.h"
25class tst_TopLevelWindowModel : public QObject
30 void init(); // called right before each and every test function is executed
31 void cleanup(); // called right after each and every test function is executed
33 void singleSurfaceStartsHidden();
34 void secondSurfaceIsHidden();
37 ApplicationManager *applicationManager{nullptr};
38 SurfaceManager *surfaceManager{nullptr};
39 TopLevelWindowModel *topLevelWindowModel{nullptr};
42void tst_TopLevelWindowModel::init()
44 applicationManager = new ApplicationManager;
45 surfaceManager = new SurfaceManager;
47 topLevelWindowModel = new TopLevelWindowModel;
48 topLevelWindowModel->setApplicationManager(applicationManager);
49 topLevelWindowModel->setSurfaceManager(surfaceManager);
52void tst_TopLevelWindowModel::cleanup()
54 delete topLevelWindowModel;
55 topLevelWindowModel = nullptr;
57 delete surfaceManager;
58 surfaceManager = nullptr;
60 delete applicationManager;
61 applicationManager = nullptr;
64void tst_TopLevelWindowModel::singleSurfaceStartsHidden()
66 QCOMPARE(topLevelWindowModel->rowCount(), 0);
68 auto application = static_cast<Application*>(applicationManager->startApplication(QString("hello-world"), QStringList()));
70 QCOMPARE(topLevelWindowModel->rowCount(), 1);
71 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)nullptr);
73 auto surface = new MirSurface;
74 surface->m_state = Mir::HiddenState;
75 application->m_surfaceList.addSurface(surface);
76 Q_EMIT surfaceManager->surfaceCreated(surface);
78 QCOMPARE(topLevelWindowModel->rowCount(), 1);
79 // not showing the surface as it's still hidden
80 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)nullptr);
82 surface->requestState(Mir::RestoredState);
84 QCOMPARE(topLevelWindowModel->rowCount(), 1);
85 // Now that the surface is no longer hidden, TopLevelWindowModel should expose it.
86 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)surface);
89void tst_TopLevelWindowModel::secondSurfaceIsHidden()
91 QCOMPARE(topLevelWindowModel->rowCount(), 0);
93 auto application = static_cast<Application*>(applicationManager->startApplication(QString("hello-world"), QStringList()));
95 QCOMPARE(topLevelWindowModel->rowCount(), 1);
96 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)nullptr);
98 auto firstSurface = new MirSurface;
99 application->m_surfaceList.addSurface(firstSurface);
100 Q_EMIT surfaceManager->surfaceCreated(firstSurface);
102 QCOMPARE(topLevelWindowModel->rowCount(), 1);
103 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
105 auto secondSurface = new MirSurface;
106 secondSurface->m_state = Mir::HiddenState;
107 application->m_surfaceList.addSurface(secondSurface);
108 Q_EMIT surfaceManager->surfaceCreated(secondSurface);
110 // still only the first surface is exposed by TopLevelWindowModel
111 QCOMPARE(topLevelWindowModel->rowCount(), 1);
112 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
114 secondSurface->requestState(Mir::RestoredState);
116 // now the second surface finally shows up
117 QCOMPARE(topLevelWindowModel->rowCount(), 2);
118 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)secondSurface);
119 QCOMPARE((void*)topLevelWindowModel->windowAt(1)->surface(), (void*)firstSurface);
121 secondSurface->requestState(Mir::HiddenState);
123 // and it's gone again
124 QCOMPARE(topLevelWindowModel->rowCount(), 1);
125 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
128QTEST_MAIN(tst_TopLevelWindowModel)
130#include "tst_TopLevelWindowModel.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list