~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to tests/auto/slidecontainerautotest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
 
2
/*
 
3
Gwenview: an image viewer
 
4
Copyright 2011 Aurélien Gâteau <agateau@kde.org>
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
 
19
 
 
20
*/
 
21
// Self
 
22
#include "slidecontainerautotest.moc"
 
23
 
 
24
// Local
 
25
#include <lib/slidecontainer.h>
 
26
 
 
27
// KDE
 
28
#include <qtest_kde.h>
 
29
#include <kdebug.h>
 
30
 
 
31
// Qt
 
32
#include <QTextEdit>
 
33
#include <QVBoxLayout>
 
34
 
 
35
QTEST_KDEMAIN(SlideContainerAutoTest, GUI)
 
36
 
 
37
using namespace Gwenview;
 
38
 
 
39
struct TestWindow : public QWidget {
 
40
    explicit TestWindow(QWidget* parent = 0)
 
41
        : QWidget(parent)
 
42
        , mContainer(new SlideContainer)
 
43
        , mContent(0) {
 
44
        createContent();
 
45
 
 
46
        mMainWidget = new QTextEdit();
 
47
        QVBoxLayout* layout = new QVBoxLayout(this);
 
48
        layout->setSpacing(0);
 
49
        layout->setMargin(0);
 
50
        layout->addWidget(mMainWidget);
 
51
        layout->addWidget(mContainer);
 
52
    }
 
53
 
 
54
    void createContent()
 
55
    {
 
56
        mContent = new QTextEdit;
 
57
        mContent->setFixedSize(100, 40);
 
58
        mContainer->setContent(mContent);
 
59
    }
 
60
 
 
61
    SlideContainer* mContainer;
 
62
    QWidget* mMainWidget;
 
63
    QWidget* mContent;
 
64
};
 
65
 
 
66
void SlideContainerAutoTest::testInit()
 
67
{
 
68
    // Even with content, a SlideContainer should be invisible until slideIn()
 
69
    // is called
 
70
    TestWindow window;
 
71
    window.show();
 
72
 
 
73
    QTest::qWait(500);
 
74
    QCOMPARE(window.mMainWidget->height(), window.height());
 
75
}
 
76
 
 
77
void SlideContainerAutoTest::testSlideIn()
 
78
{
 
79
    TestWindow window;
 
80
    window.show();
 
81
 
 
82
    window.mContainer->slideIn();
 
83
    while (window.mContainer->slideHeight() != window.mContent->height()) {
 
84
        QTest::qWait(100);
 
85
    }
 
86
    QCOMPARE(window.mContainer->height(), window.mContent->height());
 
87
}
 
88
 
 
89
void SlideContainerAutoTest::testSlideOut()
 
90
{
 
91
    TestWindow window;
 
92
    window.show();
 
93
 
 
94
    window.mContainer->slideIn();
 
95
    while (window.mContainer->slideHeight() != window.mContent->height()) {
 
96
        QTest::qWait(100);
 
97
    }
 
98
    window.mContainer->slideOut();
 
99
    while (window.mContainer->slideHeight() != 0) {
 
100
        QTest::qWait(100);
 
101
    }
 
102
    QCOMPARE(window.mContainer->height(), 0);
 
103
}
 
104
 
 
105
void SlideContainerAutoTest::testSlideInDeleteSlideOut()
 
106
{
 
107
    // If content is deleted while visible, slideOut() should still produce an
 
108
    // animation
 
109
    TestWindow window;
 
110
    window.show();
 
111
 
 
112
    window.mContainer->slideIn();
 
113
    while (window.mContainer->slideHeight() != window.mContent->height()) {
 
114
        QTest::qWait(100);
 
115
    }
 
116
    window.mContent->deleteLater();
 
117
    window.mContainer->slideOut();
 
118
    while (window.mContainer->slideHeight() != 0) {
 
119
        QTest::qWait(100);
 
120
    }
 
121
    QCOMPARE(window.mContainer->height(), 0);
 
122
}
 
123
 
 
124
void SlideContainerAutoTest::testHiddenContentResize()
 
125
{
 
126
    // Resizing content should not trigger a slide if it is not visible.
 
127
    TestWindow window;
 
128
    window.show();
 
129
    QTest::qWaitForWindowShown(&window);
 
130
 
 
131
    window.mContent->show();
 
132
    window.mContent->setFixedSize(150, 80);
 
133
    QTest::qWait(500);
 
134
    QCOMPARE(window.mContainer->height(), 0);
 
135
}
 
 
b'\\ No newline at end of file'