author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt Linguist 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 <QtTest/QtTest> |
|
43 |
#include <QtCore/QFile> |
|
44 |
||
45 |
class tst_lconvert : public QObject |
|
46 |
{ |
|
47 |
Q_OBJECT |
|
48 |
||
49 |
public: |
|
50 |
tst_lconvert() : dataDir("data/"), binDir(QLibraryInfo::location(QLibraryInfo::BinariesPath)) {} |
|
51 |
||
52 |
private slots: |
|
53 |
void initTestCase(); |
|
54 |
void readverifies_data(); |
|
55 |
void readverifies(); |
|
56 |
void converts_data(); |
|
57 |
void converts(); |
|
58 |
void roundtrips_data(); |
|
59 |
void roundtrips(); |
|
60 |
#if 0 |
|
61 |
void chains_data(); |
|
62 |
void chains(); |
|
63 |
#endif |
|
64 |
||
65 |
private: |
|
66 |
void doWait(QProcess *cvt, int stage); |
|
67 |
void doCompare(QIODevice *actual, const QString &expectedFn); |
|
68 |
void verifyReadFail(const QString &fn); |
|
69 |
// args can be empty or have one element less than stations |
|
70 |
void convertChain(const QString &inFileName, const QString &outFileName, |
|
71 |
const QStringList &stations, const QList<QStringList> &args); |
|
72 |
void convertRoundtrip(const QString &fileName, const QStringList &stations, |
|
73 |
const QList<QStringList> &args); |
|
74 |
||
75 |
QString dataDir; |
|
76 |
QString binDir; |
|
77 |
}; |
|
78 |
||
79 |
void tst_lconvert::initTestCase() |
|
80 |
{ |
|
81 |
if (!QFile::exists(QLatin1String("data/plural-1.po"))) |
|
82 |
QProcess::execute(QLatin1String("perl"), QStringList() << QLatin1String("data/makeplurals.pl") << QLatin1String("data/")); |
|
83 |
QVERIFY(QFile::exists(QLatin1String("data/plural-1.po"))); |
|
84 |
} |
|
85 |
||
86 |
void tst_lconvert::doWait(QProcess *cvt, int stage) |
|
87 |
{ |
|
88 |
if (QTest::currentTestFailed()) { |
|
89 |
cvt->kill(); |
|
90 |
cvt->waitForFinished(); |
|
91 |
} else { |
|
92 |
QVERIFY2(cvt->waitForFinished(3000), |
|
93 |
qPrintable(QString("Process %1 hung").arg(stage))); |
|
94 |
QVERIFY2(cvt->exitStatus() == QProcess::NormalExit, |
|
95 |
qPrintable(QString("Process %1 crashed").arg(stage))); |
|
96 |
QVERIFY2(cvt->exitCode() == 0, |
|
97 |
qPrintable(QString("Process %1 exited with status %2. Errors:\n%3") |
|
98 |
.arg(stage).arg(cvt->exitCode()) |
|
99 |
.arg(QString::fromUtf8(cvt->readAllStandardError())))); |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
void tst_lconvert::doCompare(QIODevice *actualDev, const QString &expectedFn) |
|
104 |
{ |
|
105 |
QList<QByteArray> actual = actualDev->readAll().split('\n'); |
|
106 |
||
107 |
QFile file(expectedFn); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); |
0 | 109 |
QList<QByteArray> expected = file.readAll().split('\n'); |
110 |
||
111 |
int i = 0, ei = expected.size(), gi = actual.size(); |
|
112 |
for (; ; i++) { |
|
113 |
if (i == gi) { |
|
114 |
if (i == ei) |
|
115 |
return; |
|
116 |
gi = 0; |
|
117 |
break; |
|
118 |
} else if (i == ei) { |
|
119 |
ei = 0; |
|
120 |
break; |
|
121 |
} else if (actual.at(i) != expected.at(i)) { |
|
122 |
while ((ei - 1) >= i && (gi - 1) >= i && actual.at(gi - 1) == expected.at(ei - 1)) |
|
123 |
ei--, gi--; |
|
124 |
break; |
|
125 |
} |
|
126 |
} |
|
127 |
QByteArray diff; |
|
128 |
for (int j = qMax(0, i - 3); j < i; j++) |
|
129 |
diff += expected.at(j) + '\n'; |
|
130 |
diff += "<<<<<<< got\n"; |
|
131 |
for (int j = i; j < gi; j++) { |
|
132 |
diff += actual.at(j) + '\n'; |
|
133 |
if (j >= i + 5) { |
|
134 |
diff += "...\n"; |
|
135 |
break; |
|
136 |
} |
|
137 |
} |
|
138 |
diff += "=========\n"; |
|
139 |
for (int j = i; j < ei; j++) { |
|
140 |
diff += expected.at(j) + '\n'; |
|
141 |
if (j >= i + 5) { |
|
142 |
diff += "...\n"; |
|
143 |
break; |
|
144 |
} |
|
145 |
} |
|
146 |
diff += ">>>>>>> expected\n"; |
|
147 |
for (int j = ei; j < qMin(ei + 3, expected.size()); j++) |
|
148 |
diff += expected.at(j) + '\n'; |
|
149 |
QFAIL(qPrintable("Output for " + expectedFn + " does not meet expectations:\n" + diff)); |
|
150 |
} |
|
151 |
||
152 |
void tst_lconvert::verifyReadFail(const QString &fn) |
|
153 |
{ |
|
154 |
QProcess cvt; |
|
155 |
cvt.start(binDir + "/lconvert", QStringList() << (dataDir + fn)); |
|
156 |
QVERIFY(cvt.waitForFinished(1000)); |
|
157 |
QVERIFY(cvt.exitStatus() == QProcess::NormalExit); |
|
158 |
QVERIFY2(cvt.exitCode() == 2, "Accepted invalid input"); |
|
159 |
} |
|
160 |
||
161 |
void tst_lconvert::convertChain(const QString &_inFileName, const QString &_outFileName, |
|
162 |
const QStringList &stations, const QList<QStringList> &argList) |
|
163 |
{ |
|
164 |
QList<QProcess *> cvts; |
|
165 |
||
166 |
QString fileName = dataDir + _inFileName; |
|
167 |
QString outFileName = dataDir + _outFileName; |
|
168 |
||
169 |
for (int i = 0; i < stations.size() - 1; i++) { |
|
170 |
QProcess *cvt = new QProcess(this); |
|
171 |
if (cvts.isEmpty()) |
|
172 |
cvt->setStandardInputFile(fileName); |
|
173 |
else |
|
174 |
cvts.last()->setStandardOutputProcess(cvt); |
|
175 |
cvts.append(cvt); |
|
176 |
} |
|
177 |
for (int i = 0; i < stations.size() - 1; i++) { |
|
178 |
QStringList args; |
|
179 |
if (!argList.isEmpty()) |
|
180 |
args += argList[i]; |
|
181 |
args << "-if" << stations[i] << "-i" << "-" << "-of" << stations[i + 1]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
cvts.at(i)->start(binDir + "/lconvert", args, QIODevice::ReadWrite | QIODevice::Text); |
0 | 183 |
} |
184 |
int st = 0; |
|
185 |
foreach (QProcess *cvt, cvts) |
|
186 |
doWait(cvt, ++st); |
|
187 |
||
188 |
if (!QTest::currentTestFailed()) |
|
189 |
doCompare(cvts.last(), outFileName); |
|
190 |
||
191 |
qDeleteAll(cvts); |
|
192 |
} |
|
193 |
||
194 |
void tst_lconvert::convertRoundtrip(const QString &_fileName, const QStringList &stations, |
|
195 |
const QList<QStringList> &argList) |
|
196 |
{ |
|
197 |
convertChain(_fileName, _fileName, stations, argList); |
|
198 |
} |
|
199 |
||
200 |
void tst_lconvert::readverifies_data() |
|
201 |
{ |
|
202 |
QTest::addColumn<QString>("fileName"); |
|
203 |
QTest::addColumn<QString>("format"); |
|
204 |
||
205 |
QTest::newRow("empty comment") << "test-empty-comment.po" << "po"; |
|
206 |
QTest::newRow("translator comment") << "test-translator-comment.po" << "po"; |
|
207 |
QTest::newRow("developer comment") << "test-developer-comment.po" << "po"; |
|
208 |
QTest::newRow("kde context") << "test-kde-ctxt.po" << "po"; |
|
209 |
QTest::newRow("kde fuzzy") << "test-kde-fuzzy.po" << "po"; |
|
210 |
QTest::newRow("kde plurals") << "test-kde-plurals.po" << "po"; |
|
211 |
QTest::newRow("kde multiline") << "test-kde-multiline.po" << "po"; |
|
212 |
QTest::newRow("po linewrapping") << "wrapping.po" << "po"; |
|
213 |
QTest::newRow("relative locations") << "relative.ts" << "ts"; |
|
214 |
QTest::newRow("message ids") << "msgid.ts" << "ts"; |
|
215 |
QTest::newRow("length variants") << "variants.ts" << "ts"; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
QTest::newRow("qph") << "phrasebook.qph" << "qph"; |
0 | 217 |
} |
218 |
||
219 |
void tst_lconvert::readverifies() |
|
220 |
{ |
|
221 |
QFETCH(QString, fileName); |
|
222 |
QFETCH(QString, format); |
|
223 |
||
224 |
convertRoundtrip(fileName, QStringList() << format << format, QList<QStringList>()); |
|
225 |
} |
|
226 |
||
227 |
void tst_lconvert::converts_data() |
|
228 |
{ |
|
229 |
QTest::addColumn<QString>("inFileName"); |
|
230 |
QTest::addColumn<QString>("outFileName"); |
|
231 |
QTest::addColumn<QString>("format"); |
|
232 |
||
233 |
QTest::newRow("broken utf8") << "test-broken-utf8.po" << "test-broken-utf8.po.out" << "po"; |
|
234 |
QTest::newRow("line joins") << "test-slurp.po" << "test-slurp.po.out" << "po"; |
|
235 |
QTest::newRow("escapes") << "test-escapes.po" << "test-escapes.po.out" << "po"; |
|
236 |
} |
|
237 |
||
238 |
void tst_lconvert::converts() |
|
239 |
{ |
|
240 |
QFETCH(QString, inFileName); |
|
241 |
QFETCH(QString, outFileName); |
|
242 |
QFETCH(QString, format); |
|
243 |
||
244 |
QString outFileNameFq = dataDir + outFileName; |
|
245 |
||
246 |
QProcess cvt; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
cvt.start(binDir + "/lconvert", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
QStringList() << "-i" << (dataDir + inFileName) << "-of" << format, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
QIODevice::ReadWrite | QIODevice::Text); |
0 | 250 |
doWait(&cvt, 0); |
251 |
if (QTest::currentTestFailed()) |
|
252 |
return; |
|
253 |
||
254 |
doCompare(&cvt, outFileNameFq); |
|
255 |
} |
|
256 |
||
257 |
Q_DECLARE_METATYPE(QList<QStringList>); |
|
258 |
||
259 |
#if 0 |
|
260 |
void tst_lconvert::chains_data() |
|
261 |
{ |
|
262 |
QTest::addColumn<QString>("inFileName"); |
|
263 |
QTest::addColumn<QString>("outFileName"); |
|
264 |
QTest::addColumn<QStringList>("stations"); |
|
265 |
QTest::addColumn<QList<QStringList> >("args"); |
|
266 |
||
267 |
} |
|
268 |
||
269 |
void tst_lconvert::chains() |
|
270 |
{ |
|
271 |
QFETCH(QString, inFileName); |
|
272 |
QFETCH(QString, outFileName); |
|
273 |
QFETCH(QStringList, stations); |
|
274 |
QFETCH(QList<QStringList>, args); |
|
275 |
||
276 |
convertChain(inFileName, outFileName, stations, args); |
|
277 |
} |
|
278 |
#endif |
|
279 |
||
280 |
void tst_lconvert::roundtrips_data() |
|
281 |
{ |
|
282 |
QTest::addColumn<QString>("fileName"); |
|
283 |
QTest::addColumn<QStringList>("stations"); |
|
284 |
QTest::addColumn<QList<QStringList> >("args"); |
|
285 |
||
286 |
QStringList poTsPo; poTsPo << "po" << "ts" << "po"; |
|
287 |
QStringList poXlfPo; poXlfPo << "po" << "xlf" << "po"; |
|
288 |
QStringList tsTs11Ts; tsTs11Ts << "ts" << "ts11" << "ts"; |
|
289 |
QStringList tsPoTs; tsPoTs << "ts" << "po" << "ts"; |
|
290 |
QStringList ts11PoTs11; ts11PoTs11 << "ts11" << "po" << "ts11"; |
|
291 |
QStringList tsXlfTs; tsXlfTs << "ts" << "xlf" << "ts"; |
|
292 |
QStringList tsQmTs; tsQmTs << "ts" << "qm" << "ts"; |
|
293 |
||
294 |
QList<QStringList> noArgs; |
|
295 |
QList<QStringList> filterPoArgs; filterPoArgs << QStringList() << (QStringList() << "-drop-tag" << "po:*"); |
|
296 |
QList<QStringList> outDeArgs; outDeArgs << QStringList() << (QStringList() << "-target-language" << "de"); |
|
297 |
QList<QStringList> outCnArgs; outCnArgs << QStringList() << (QStringList() << "-target-language" << "cn"); |
|
298 |
||
299 |
QTest::newRow("po-ts-po (translator comment)") << "test-translator-comment.po" << poTsPo << noArgs; |
|
300 |
QTest::newRow("po-xliff-po (translator comment)") << "test-translator-comment.po" << poXlfPo << noArgs; |
|
301 |
QTest::newRow("po-ts-po (developer comment)") << "test-developer-comment.po" << poTsPo << noArgs; |
|
302 |
QTest::newRow("po-xliff-po (developer comment)") << "test-developer-comment.po" << poXlfPo << noArgs; |
|
303 |
||
304 |
QTest::newRow("ts11-po-ts11") << "test11.ts" << ts11PoTs11 << filterPoArgs; |
|
305 |
QTest::newRow("ts20-po-ts20") << "test20.ts" << tsPoTs << filterPoArgs; |
|
306 |
QTest::newRow("po-ts-po (de)") << "test1-de.po" << poTsPo << noArgs; |
|
307 |
QTest::newRow("po-ts-po (cn)") << "test1-cn.po" << poTsPo << noArgs; |
|
308 |
QTest::newRow("po-xliff-po (de)") << "test1-de.po" << poXlfPo << noArgs; |
|
309 |
QTest::newRow("po-xliff-po (cn)") << "test1-cn.po" << poXlfPo << noArgs; |
|
310 |
||
311 |
QTest::newRow("po-ts-po (singular)") << "singular.po" << poTsPo << noArgs; |
|
312 |
QTest::newRow("po-ts-po (plural-1)") << "plural-1.po" << poTsPo << noArgs; |
|
313 |
QTest::newRow("po-ts-po (plural-2)") << "plural-2.po" << poTsPo << noArgs; |
|
314 |
QTest::newRow("po-ts-po (plural-3)") << "plural-3.po" << poTsPo << noArgs; |
|
315 |
QTest::newRow("po-xliff-po (singular)") << "singular.po" << poXlfPo << noArgs; |
|
316 |
QTest::newRow("po-xliff-po (plural-1)") << "plural-1.po" << poXlfPo << noArgs; |
|
317 |
QTest::newRow("po-xliff-po (plural-2)") << "plural-2.po" << poXlfPo << noArgs; |
|
318 |
QTest::newRow("po-xliff-po (plural-3)") << "plural-3.po" << poXlfPo << noArgs; |
|
319 |
||
320 |
QTest::newRow("ts20-ts11-ts20 (utf8)") << "codec-utf8.ts" << tsTs11Ts << noArgs; |
|
321 |
QTest::newRow("ts20-ts11-ts20 (cp1252)") << "codec-cp1252.ts" << tsTs11Ts << noArgs; |
|
322 |
QTest::newRow("ts20-ts11-ts20 (dual-encoding)") << "dual-encoding.ts" << tsTs11Ts << noArgs; |
|
323 |
||
324 |
QTest::newRow("ts-qm-ts (dual-encoding)") << "dual-encoding.ts" << tsQmTs << noArgs; |
|
325 |
QTest::newRow("ts-qm-ts (plurals-de)") << "plurals-de.ts" << tsQmTs << outDeArgs; |
|
326 |
QTest::newRow("ts-qm-ts (plurals-cn)") << "plurals-cn.ts" << tsQmTs << outCnArgs; |
|
327 |
QTest::newRow("ts-qm-ts (variants)") << "variants.ts" << tsQmTs << outDeArgs; |
|
328 |
QTest::newRow("ts-po-ts (msgid)") << "msgid.ts" << tsPoTs << noArgs; |
|
329 |
QTest::newRow("ts-xliff-ts (msgid)") << "msgid.ts" << tsXlfTs << noArgs; |
|
330 |
||
331 |
QTest::newRow("ts-po-ts (endless loop)") << "endless-po-loop.ts" << tsPoTs << noArgs; |
|
332 |
} |
|
333 |
||
334 |
void tst_lconvert::roundtrips() |
|
335 |
{ |
|
336 |
QFETCH(QString, fileName); |
|
337 |
QFETCH(QStringList, stations); |
|
338 |
QFETCH(QList<QStringList>, args); |
|
339 |
||
340 |
convertRoundtrip(fileName, stations, args); |
|
341 |
} |
|
342 |
||
343 |
QTEST_APPLESS_MAIN(tst_lconvert) |
|
344 |
||
345 |
#include "tst_lconvert.moc" |