2 * Copyright (C) 2013 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 * Nick Dedekind <nick.dedekind@canonical.com>
20#include "indicatorsmanager.h"
21#include "unitymenumodelstack.h"
25#include <unitymenumodel.h>
30class UnityMenuModelStackTest : public QObject
37 m_model = new UnityMenuModel();
38 m_headChanged = false;
39 m_tailChanged = false;
46 // send deleteLaters to avoid leaks.
47 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
50 void testHeadOnSetHead()
52 UnityMenuModelStack stack;
53 connect(&stack, &UnityMenuModelStack::headChanged, this, &UnityMenuModelStackTest::onHeadChanged);
54 stack.setHead(m_model);
56 QCOMPARE(stack.head(), m_model);
57 QCOMPARE(m_headChanged, true);
60 void testTailOnSetHead()
62 UnityMenuModelStack stack;
63 connect(&stack, &UnityMenuModelStack::tailChanged, this, &UnityMenuModelStackTest::onTailChanged);
64 stack.setHead(m_model);
66 QCOMPARE(stack.tail(), m_model);
67 QCOMPARE(m_tailChanged, true);
70 void testPushPop_data() {
71 QTest::addColumn<int>("menuDepth");
72 QTest::addColumn<int>("subMenuCount");
73 QTest::addColumn<int>("subMenuIndex");
75 QTest::newRow("depth=0") << 0 << 1 << 0;
76 QTest::newRow("depth=1") << 1 << 1 << 0;
77 QTest::newRow("depth=8") << 8 << 2 << 1;
82 QFETCH(int, menuDepth);
83 QFETCH(int, subMenuCount);
84 QFETCH(int, subMenuIndex);
86 m_model->setModelData(recuseAddMenu(subMenuCount, menuDepth));
88 UnityMenuModelStack stack;
89 connect(&stack, &UnityMenuModelStack::tailChanged, this, &UnityMenuModelStackTest::onTailChanged);
91 QList<UnityMenuModel*> models;
94 auto foreachChild = [&](UnityMenuModel* child, int childIndex) {
95 stack.push(child, childIndex);
96 QCOMPARE(stack.count(), count+1);
101 recuseSubmenus(m_model, subMenuIndex, foreachChild);
103 QCOMPARE(stack.count(), models.count());
104 QCOMPARE(stack.count(), menuDepth+1);
105 while(stack.count() > 0) {
106 m_tailChanged = false;
108 QCOMPARE(stack.pop(), models.takeLast());
110 QCOMPARE(m_tailChanged, true);
112 QCOMPARE(stack.tail(), models.last());
115 QCOMPARE(m_tailChanged, true);
118 void testPopOnRemove_data() {
119 QTest::addColumn<int>("menuDepth");
120 QTest::addColumn<int>("subMenuCount");
121 QTest::addColumn<int>("subMenuIndex");
122 QTest::addColumn<int>("removeIndex");
123 QTest::addColumn<int>("resultCount");
125 QTest::newRow("removeIndexBefore") << 4 << 2 << 1 << 0 << 5;
126 QTest::newRow("removeCurrentIndex") << 4 << 2 << 0 << 0 << 1;
127 QTest::newRow("removeIndexAfter") << 4 << 2 << 0 << 1 << 5;
130 void testPopOnRemove()
132 QFETCH(int, menuDepth);
133 QFETCH(int, subMenuCount);
134 QFETCH(int, subMenuIndex);
135 QFETCH(int, removeIndex);
136 QFETCH(int, resultCount);
138 m_model->setModelData(recuseAddMenu(subMenuCount, menuDepth));
140 UnityMenuModelStack stack;
142 auto foreachChild = [&](UnityMenuModel* child, int childIndex) {
143 stack.push(child, childIndex);
145 recuseSubmenus(m_model, subMenuIndex, foreachChild);
147 QCOMPARE(stack.count(), menuDepth+1);
149 m_model->removeRow(removeIndex);
151 QCOMPARE(stack.count(), resultCount);
155 QVariant recuseAddMenu(int subMenuCount, int depth_remaining)
159 for (int i = 0; i < subMenuCount; i ++) {
163 if (depth_remaining > 0) {
164 row["submenu"] = recuseAddMenu(subMenuCount, depth_remaining-1);
167 row["rowData"] = rowData;
175 void recuseSubmenus(UnityMenuModel* model, int childIndex, std::function<void(UnityMenuModel*, int)> func) {
176 UnityMenuModel* parent = model;
177 UnityMenuModel* child = model;
181 func(child, childIndex);
185 child = qobject_cast<UnityMenuModel*>(parent->submenu(childIndex));
191 void onHeadChanged() { m_headChanged = true; }
192 void onTailChanged() { m_tailChanged = true; }
195 UnityMenuModel* m_model;
200QTEST_GUILESS_MAIN(UnityMenuModelStackTest)
201#include "UnityMenuModelStackTest.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