Remove usage of deprecated qWaitForWindowShown(QWidget *) method.
[profile/ivi/qtbase.git] / tests / auto / other / baselineexample / tst_baselineexample.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qbaselinetest.h>
43 #include <QPushButton>
44
45 class tst_BaselineExample : public QObject
46 {
47     Q_OBJECT
48
49 public:
50     tst_BaselineExample();
51
52 private Q_SLOTS:
53     void testBasicUsage();
54     void testMultipleImages();
55     void testDataDriven_data();
56     void testDataDriven();
57     void testDataDrivenChecksum_data();
58     void testDataDrivenChecksum();
59 };
60
61
62 tst_BaselineExample::tst_BaselineExample()
63 {
64 }
65
66
67 void tst_BaselineExample::testBasicUsage()
68 {
69     // Generate an image:
70     QPushButton b("Press me!");
71     b.resize(100, 50);
72     b.show();
73     QVERIFY(QTest::qWaitForWindowExposed(&b));
74     QImage img1 = b.grab().toImage();
75     QVERIFY(!img1.isNull());
76
77     // Compare it to baseline on server:
78     QBASELINE_CHECK(img1, "button");
79 }
80
81
82 void tst_BaselineExample::testMultipleImages()
83 {
84     QPushButton b("Press me!");
85     b.resize(100, 50);
86     b.show();
87     QVERIFY(QTest::qWaitForWindowExposed(&b));
88     QBASELINE_CHECK(b.grab().toImage(), "text1");
89
90     b.setText("Kick me!");
91     QTest::qWait(50);
92     QBASELINE_CHECK(b.grab().toImage(), "text2");
93 }
94
95
96 void tst_BaselineExample::testDataDriven_data()
97 {
98     QTest::addColumn<QString>("label");
99     QBaselineTest::newRow("short") << "Ok!";
100     QBaselineTest::newRow("long") << "A really long button text that just does not seem to end";
101     QBaselineTest::newRow("empty") << "";
102     QBaselineTest::newRow("signs") << "!@#$%^&*()_";
103     QBaselineTest::newRow("html") << "<b>BOLD</b>";
104 }
105
106
107 void tst_BaselineExample::testDataDriven()
108 {
109     QFETCH(QString, label);
110     QPushButton b(label);
111     b.resize(100, 50);
112     b.show();
113     QVERIFY(QTest::qWaitForWindowExposed(&b));
114     QBASELINE_TEST(b.grab().toImage());
115 }
116
117
118 void tst_BaselineExample::testDataDrivenChecksum_data()
119 {
120     QTest::addColumn<QString>("label");
121
122     const int numItems = 5;
123     const char *tags[numItems] = {"short", "long", "empty", "signs", "html"};
124     const char *labels[numItems] = {"Ok!", "A really long button text that just does not seem to end", "", "!@#$%^&*()_", "<b>BOLD</b>"};
125
126     for (int i = 0; i<numItems; i++) {
127         quint16 checksum = qChecksum(labels[i], qstrlen(labels[i]));
128         QBaselineTest::newRow(tags[i], checksum) << labels[i];
129     }
130 }
131
132
133 void tst_BaselineExample::testDataDrivenChecksum()
134 {
135     QFETCH(QString, label);
136     QPushButton b(label);
137     b.resize(100, 50);
138     b.show();
139     QVERIFY(QTest::qWaitForWindowExposed(&b));
140     QBASELINE_TEST(b.grab().toImage());
141 }
142
143
144 QTEST_MAIN(tst_BaselineExample);
145
146 #include "tst_baselineexample.moc"