~fboucault/unity-2d/keyboard_navigation_experimental

« back to all changes in this revision

Viewing changes to libunity-2d/tests/paneltest.cpp

Merged from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of unity-2d
 
3
 *
 
4
 * Copyright 2010 Canonical Ltd.
 
5
 *
 
6
 * Authors:
 
7
 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; version 3.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
// Local
 
23
#include <unity2dpanel.h>
 
24
 
 
25
// Qt
 
26
#include <QApplication>
 
27
#include <QDesktopWidget>
 
28
#include <QtTestGui>
 
29
 
 
30
class PanelTest : public QObject
 
31
{
 
32
    Q_OBJECT
 
33
private Q_SLOTS:
 
34
    void testSetEdge()
 
35
    {
 
36
        QRect screen = QApplication::desktop()->screenGeometry();
 
37
        QRect available = QApplication::desktop()->availableGeometry();
 
38
 
 
39
        Unity2dPanel panel;
 
40
        panel.setFixedHeight(16);
 
41
        panel.setEdge(Unity2dPanel::TopEdge);
 
42
        panel.show();
 
43
        QTest::qWait(500);
 
44
 
 
45
        QRect expectedGeometry = QRect(screen.left(), screen.top(), screen.width(), 16);
 
46
        QCOMPARE(panel.geometry(), expectedGeometry);
 
47
        QCOMPARE(QApplication::desktop()->availableGeometry(), available.adjusted(0, 16, 0, 0));
 
48
    }
 
49
 
 
50
    void testAddQWidget()
 
51
    {
 
52
        Unity2dPanel panel;
 
53
        QWidget* widget1 = new QWidget;
 
54
        QWidget* widget2 = new QWidget;
 
55
        panel.addWidget(widget1);
 
56
        panel.addWidget(widget2);
 
57
        panel.show();
 
58
 
 
59
        QCOMPARE(widget1->geometry(), QRect(0, 0, panel.width() / 2, panel.height()));
 
60
        QCOMPARE(widget2->geometry(), QRect(panel.width() / 2, 0, panel.width() / 2, panel.height()));
 
61
    }
 
62
 
 
63
    void testAddSpacer()
 
64
    {
 
65
        Unity2dPanel panel;
 
66
        QWidget* widget1 = new QWidget;
 
67
        widget1->setFixedWidth(100);
 
68
        QWidget* widget2 = new QWidget;
 
69
        widget2->setFixedWidth(200);
 
70
        panel.addWidget(widget1);
 
71
        panel.addSpacer();
 
72
        panel.addWidget(widget2);
 
73
        panel.show();
 
74
 
 
75
        QCOMPARE(widget1->geometry(), QRect(0, 0, 100, panel.height()));
 
76
        QCOMPARE(widget2->geometry(), QRect(panel.width() - 200, 0, 200, panel.height()));
 
77
    }
 
78
};
 
79
 
 
80
QTEST_MAIN(PanelTest)
 
81
 
 
82
#include "paneltest.moc"