0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtCore/QCoreApplication>
|
|
43 |
#include <QtCore/QByteArray>
|
|
44 |
#include <QtCore/QDebug>
|
|
45 |
#include <QtCore/QDir>
|
|
46 |
#include <QtCore/QFile>
|
|
47 |
#include <QtCore/QProcess>
|
|
48 |
#include <QtCore/QTimer>
|
|
49 |
|
|
50 |
#include <QtTest/QtTest>
|
|
51 |
|
|
52 |
|
|
53 |
class tst_rcc : public QObject
|
|
54 |
{
|
|
55 |
Q_OBJECT
|
|
56 |
public:
|
|
57 |
tst_rcc() {}
|
|
58 |
|
|
59 |
private slots:
|
|
60 |
void rcc_data();
|
|
61 |
void rcc();
|
|
62 |
};
|
|
63 |
|
|
64 |
|
|
65 |
QString findExpectedFile(const QString &base)
|
|
66 |
{
|
|
67 |
QString expectedrccfile = base;
|
|
68 |
|
|
69 |
// Must be updated with each minor release.
|
|
70 |
if (QFileInfo(expectedrccfile + QLatin1String(".450")).exists())
|
|
71 |
expectedrccfile += QLatin1String(".450");
|
|
72 |
|
|
73 |
return expectedrccfile;
|
|
74 |
}
|
|
75 |
|
|
76 |
static QString doCompare(const QStringList &actual, const QStringList &expected)
|
|
77 |
{
|
|
78 |
if (actual.size() != expected.size()) {
|
|
79 |
return QString("Length count different: actual: %1, expected: %2")
|
|
80 |
.arg(actual.size()).arg(expected.size());
|
|
81 |
}
|
|
82 |
|
|
83 |
QByteArray ba;
|
|
84 |
for (int i = 0, n = expected.size(); i != n; ++i) {
|
|
85 |
if (expected.at(i).startsWith("IGNORE:"))
|
|
86 |
continue;
|
|
87 |
if (expected.at(i) != actual.at(i)) {
|
|
88 |
qDebug() << "LINES" << i << "DIFFER";
|
|
89 |
ba.append(
|
|
90 |
"\n<<<<<< actual\n" + actual.at(i) + "\n======\n" + expected.at(i)
|
|
91 |
+ "\n>>>>>> expected\n"
|
|
92 |
);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
return ba;
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
void tst_rcc::rcc_data()
|
|
100 |
{
|
|
101 |
QTest::addColumn<QString>("directory");
|
|
102 |
QTest::addColumn<QString>("qrcfile");
|
|
103 |
QTest::addColumn<QString>("expected");
|
|
104 |
|
|
105 |
QTest::newRow("images") << "data" << "images.qrc" << "images.expected";
|
|
106 |
}
|
|
107 |
|
|
108 |
void tst_rcc::rcc()
|
|
109 |
{
|
|
110 |
QFETCH(QString, directory);
|
|
111 |
QFETCH(QString, qrcfile);
|
|
112 |
QFETCH(QString, expected);
|
|
113 |
|
|
114 |
if (!QDir::setCurrent(directory)) {
|
|
115 |
QString message = QString::fromLatin1("Unable to cd from '%1' to '%2'").arg(QDir::currentPath(), directory);
|
|
116 |
QFAIL(qPrintable(message));
|
|
117 |
}
|
|
118 |
|
|
119 |
// If the file expectedoutput.txt exists, compare the
|
|
120 |
// console output with the content of that file
|
|
121 |
const QString expected2 = findExpectedFile(expected);
|
|
122 |
QFile expectedFile(expected2);
|
|
123 |
if (!expectedFile.exists()) {
|
|
124 |
qDebug() << "NO EXPECTATIONS? " << expected2;
|
|
125 |
return;
|
|
126 |
}
|
|
127 |
|
|
128 |
// Launch
|
|
129 |
const QString command = QLatin1String("rcc");
|
|
130 |
QProcess process;
|
|
131 |
process.start(command, QStringList(qrcfile));
|
|
132 |
if (!process.waitForFinished()) {
|
|
133 |
const QString path = QString::fromLocal8Bit(qgetenv("PATH"));
|
|
134 |
QString message = QString::fromLatin1("'%1' could not be found when run from '%2'. Path: '%3' ").
|
|
135 |
arg(command, QDir::currentPath(), path);
|
|
136 |
QFAIL(qPrintable(message));
|
|
137 |
}
|
|
138 |
const QChar cr = QLatin1Char('\r');
|
|
139 |
const QString err = QString::fromLocal8Bit(process.readAllStandardError()).remove(cr);
|
|
140 |
const QString out = QString::fromAscii(process.readAllStandardOutput()).remove(cr);
|
|
141 |
|
|
142 |
if (!err.isEmpty()) {
|
|
143 |
qDebug() << "UNEXPECTED STDERR CONTENTS: " << err;
|
|
144 |
QFAIL("UNEXPECTED STDERR CONTENTS");
|
|
145 |
}
|
|
146 |
|
|
147 |
const QChar nl = QLatin1Char('\n');
|
|
148 |
const QStringList actualLines = out.split(nl);
|
|
149 |
|
|
150 |
QVERIFY(expectedFile.open(QIODevice::ReadOnly|QIODevice::Text));
|
|
151 |
const QStringList expectedLines = QString::fromAscii(expectedFile.readAll()).split(nl);
|
|
152 |
|
|
153 |
const QString diff = doCompare(actualLines, expectedLines);
|
|
154 |
if (diff.size())
|
|
155 |
QFAIL(qPrintable(diff));
|
|
156 |
}
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
QTEST_APPLESS_MAIN(tst_rcc)
|
|
161 |
|
|
162 |
#include "tst_rcc.moc"
|