|
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 |
|
43 #include <QtCore/QDir> |
|
44 #include <QtCore/QString> |
|
45 #include <QtTest/QtTest> |
|
46 #include <QtCore/QProcess> |
|
47 #include <QtCore/QByteArray> |
|
48 #include <QtCore/QLibraryInfo> |
|
49 |
|
50 #ifndef Q_OS_WINCE |
|
51 |
|
52 class tst_uic : public QObject |
|
53 { |
|
54 Q_OBJECT |
|
55 |
|
56 public: |
|
57 tst_uic(); |
|
58 |
|
59 private Q_SLOTS: |
|
60 void initTestCase(); |
|
61 |
|
62 void run(); |
|
63 void run_data() const; |
|
64 |
|
65 void compare(); |
|
66 void compare_data() const; |
|
67 |
|
68 void cleanupTestCase(); |
|
69 |
|
70 private: |
|
71 QString workingDir() const; |
|
72 |
|
73 private: |
|
74 bool uicExists; |
|
75 const QString command; |
|
76 }; |
|
77 |
|
78 |
|
79 tst_uic::tst_uic() |
|
80 : uicExists(true) |
|
81 , command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/uic")) |
|
82 { |
|
83 } |
|
84 |
|
85 void tst_uic::initTestCase() |
|
86 { |
|
87 QProcess process; |
|
88 process.start(command, QStringList(QLatin1String("-help"))); |
|
89 |
|
90 if (!process.waitForFinished()) { |
|
91 uicExists = false; |
|
92 const QString path = QString::fromLocal8Bit(qgetenv("PATH")); |
|
93 QString message = QString::fromLatin1("'%1' could not be found when run from '%2'. Path: '%3' "). |
|
94 arg(command, QDir::currentPath(), path); |
|
95 QFAIL(qPrintable(message)); |
|
96 } |
|
97 // Print version |
|
98 const QString out = QString::fromLocal8Bit(process.readAllStandardError()).remove(QLatin1Char('\r')); |
|
99 const QStringList outLines = out.split(QLatin1Char('\n')); |
|
100 // Print version |
|
101 QString msg = QString::fromLatin1("uic test built %1 running in '%2' using: "). |
|
102 arg(QString::fromAscii(__DATE__), QDir::currentPath()); |
|
103 if (!outLines.empty()) |
|
104 msg += outLines.front(); |
|
105 qDebug() << msg; |
|
106 process.terminate(); |
|
107 |
|
108 QCOMPARE(QFileInfo(QLatin1String(SRCDIR "baseline")).exists(), true); |
|
109 QCOMPARE(QFileInfo(QLatin1String(SRCDIR "generated_ui")).exists(), true); |
|
110 } |
|
111 |
|
112 void tst_uic::run() |
|
113 { |
|
114 if (!uicExists) |
|
115 QSKIP("uic not found in the path...", SkipAll); |
|
116 |
|
117 QFETCH(QString, originalFile); |
|
118 QFETCH(QString, generatedFile); |
|
119 |
|
120 QProcess process; |
|
121 process.setWorkingDirectory(workingDir()); |
|
122 |
|
123 process.start(command, QStringList(originalFile) << QString(QLatin1String("-o")) |
|
124 << generatedFile); |
|
125 |
|
126 QCOMPARE(process.exitStatus(), QProcess::NormalExit); |
|
127 |
|
128 if (process.waitForFinished()) { |
|
129 QCOMPARE(process.exitCode(), 0); |
|
130 QCOMPARE(QFileInfo(generatedFile).exists(), true); |
|
131 } else { |
|
132 QString error(QLatin1String("could not generated file: ")); |
|
133 QFAIL(error.append(generatedFile).toUtf8().constData()); |
|
134 } |
|
135 } |
|
136 |
|
137 void tst_uic::run_data() const |
|
138 { |
|
139 QTest::addColumn<QString>("originalFile"); |
|
140 QTest::addColumn<QString>("generatedFile"); |
|
141 |
|
142 QString cwd = workingDir().append(QDir::separator()); |
|
143 |
|
144 QDir dir(cwd + QLatin1String("baseline")); |
|
145 QFileInfoList originalFiles = dir.entryInfoList(QStringList("*.ui"), QDir::Files); |
|
146 |
|
147 dir.setPath(cwd + QLatin1String("generated_ui")); |
|
148 for (int i = 0; i < originalFiles.count(); ++i) { |
|
149 QTest::newRow(qPrintable(originalFiles.at(i).baseName())) |
|
150 << originalFiles.at(i).absoluteFilePath() |
|
151 << dir.absolutePath() + QDir::separator() |
|
152 + originalFiles.at(i).fileName().append(QLatin1String(".h")); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 void tst_uic::compare() |
|
158 { |
|
159 QFETCH(QString, originalFile); |
|
160 QFETCH(QString, generatedFile); |
|
161 |
|
162 QFile orgFile(originalFile); |
|
163 QFile genFile(generatedFile); |
|
164 |
|
165 if (!orgFile.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
166 QString err(QLatin1String("Could not read file: %1...")); |
|
167 QFAIL(err.arg(orgFile.fileName()).toUtf8()); |
|
168 } |
|
169 |
|
170 if (!genFile.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
171 QString err(QLatin1String("Could not read file: %1...")); |
|
172 QFAIL(err.arg(genFile.fileName()).toUtf8()); |
|
173 } |
|
174 |
|
175 originalFile = orgFile.readAll(); |
|
176 originalFile.replace(QRegExp(QLatin1String("Created:.{0,25}[\\d]{4,4}")), ""); |
|
177 originalFile.replace(QRegExp(QLatin1String("by: Qt User Interface Compiler version [.\\d]{5,5}")), ""); |
|
178 |
|
179 generatedFile = genFile.readAll(); |
|
180 generatedFile.replace(QRegExp(QLatin1String("Created:.{0,25}[\\d]{4,4}")), ""); |
|
181 generatedFile.replace(QRegExp(QLatin1String("by: Qt User Interface Compiler version [.\\d]{5,5}")), ""); |
|
182 |
|
183 QCOMPARE(generatedFile, originalFile); |
|
184 } |
|
185 |
|
186 void tst_uic::compare_data() const |
|
187 { |
|
188 QTest::addColumn<QString>("originalFile"); |
|
189 QTest::addColumn<QString>("generatedFile"); |
|
190 |
|
191 QString cwd = workingDir().append(QDir::separator()); |
|
192 |
|
193 QDir dir(cwd + QLatin1String("baseline")); |
|
194 QFileInfoList originalFiles = dir.entryInfoList(QStringList("*.h"), QDir::Files); |
|
195 |
|
196 dir.setPath(cwd + QLatin1String("generated_ui")); |
|
197 for (int i = 0; i < originalFiles.count(); ++i) { |
|
198 QTest::newRow(qPrintable(originalFiles.at(i).baseName())) |
|
199 << originalFiles.at(i).absoluteFilePath() |
|
200 << dir.absolutePath() + QDir::separator() |
|
201 + originalFiles.at(i).fileName(); |
|
202 } |
|
203 } |
|
204 |
|
205 void tst_uic::cleanupTestCase() |
|
206 { |
|
207 QString cwd = workingDir().append(QDir::separator()); |
|
208 QDir dir(cwd.append(QLatin1String("/generated_ui"))); |
|
209 QFileInfoList generatedFiles = dir.entryInfoList(QDir::Files); |
|
210 |
|
211 foreach (const QFileInfo& fInfo, generatedFiles) { |
|
212 QFile file(fInfo.absoluteFilePath()); |
|
213 // file.remove(); |
|
214 } |
|
215 } |
|
216 |
|
217 QString tst_uic::workingDir() const |
|
218 { |
|
219 return QDir::cleanPath(SRCDIR); |
|
220 } |
|
221 |
|
222 QTEST_APPLESS_MAIN(tst_uic) |
|
223 #include "tst_uic.moc" |
|
224 #else |
|
225 QTEST_NOOP_MAIN |
|
226 #endif |