1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include <qbaselinetest.h>
43 #include <QPushButton>
45 class tst_BaselineExample : public QObject
50 tst_BaselineExample();
53 void testBasicUsage();
54 void testMultipleImages();
55 void testDataDriven_data();
56 void testDataDriven();
57 void testDataDrivenChecksum_data();
58 void testDataDrivenChecksum();
62 tst_BaselineExample::tst_BaselineExample()
67 void tst_BaselineExample::testBasicUsage()
70 QPushButton b("Press me!");
73 QVERIFY(QTest::qWaitForWindowExposed(&b));
74 QImage img1 = b.grab().toImage();
75 QVERIFY(!img1.isNull());
77 // Compare it to baseline on server:
78 QBASELINE_CHECK(img1, "button");
82 void tst_BaselineExample::testMultipleImages()
84 QPushButton b("Press me!");
87 QVERIFY(QTest::qWaitForWindowExposed(&b));
88 QBASELINE_CHECK(b.grab().toImage(), "text1");
90 b.setText("Kick me!");
92 QBASELINE_CHECK(b.grab().toImage(), "text2");
96 void tst_BaselineExample::testDataDriven_data()
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>";
107 void tst_BaselineExample::testDataDriven()
109 QFETCH(QString, label);
110 QPushButton b(label);
113 QVERIFY(QTest::qWaitForWindowExposed(&b));
114 QBASELINE_TEST(b.grab().toImage());
118 void tst_BaselineExample::testDataDrivenChecksum_data()
120 QTest::addColumn<QString>("label");
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>"};
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];
133 void tst_BaselineExample::testDataDrivenChecksum()
135 QFETCH(QString, label);
136 QPushButton b(label);
139 QVERIFY(QTest::qWaitForWindowExposed(&b));
140 QBASELINE_TEST(b.grab().toImage());
144 QTEST_MAIN(tst_BaselineExample);
146 #include "tst_baselineexample.moc"