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 <QtCore/QDir> |
|
43 |
#include <QtCore/QDebug> |
|
44 |
#include <QtCore/QFile> |
|
45 |
#include <QtCore/QByteArray> |
|
46 |
||
47 |
#include <QtTest/QtTest> |
|
48 |
||
49 |
class tst_lrelease : public QObject |
|
50 |
{ |
|
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
tst_lrelease() : binDir(QLibraryInfo::location(QLibraryInfo::BinariesPath)) {} |
|
55 |
||
56 |
private: |
|
57 |
||
58 |
private slots: |
|
59 |
void translate(); |
|
60 |
void mixedcodecs(); |
|
61 |
void compressed(); |
|
62 |
void idbased(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
void markuntranslated(); |
0 | 64 |
void dupes(); |
65 |
||
66 |
private: |
|
67 |
void doCompare(const QStringList &actual, const QString &expectedFn); |
|
68 |
||
69 |
QString binDir; |
|
70 |
}; |
|
71 |
||
72 |
void tst_lrelease::doCompare(const QStringList &actual, const QString &expectedFn) |
|
73 |
{ |
|
74 |
QFile file(expectedFn); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
QStringList expected = QString(file.readAll()).trimmed().split('\n'); |
0 | 77 |
|
78 |
int i = 0, ei = expected.size(), gi = actual.size(); |
|
79 |
for (; ; i++) { |
|
80 |
if (i == gi) { |
|
81 |
if (i == ei) |
|
82 |
return; |
|
83 |
gi = 0; |
|
84 |
break; |
|
85 |
} else if (i == ei) { |
|
86 |
ei = 0; |
|
87 |
break; |
|
88 |
} else if (!QRegExp(expected.at(i)).exactMatch(actual.at(i))) { |
|
89 |
while ((ei - 1) >= i && (gi - 1) >= i && |
|
90 |
(QRegExp(expected.at(ei - 1)).exactMatch(actual.at(gi - 1)))) |
|
91 |
ei--, gi--; |
|
92 |
break; |
|
93 |
} |
|
94 |
} |
|
95 |
QByteArray diff; |
|
96 |
for (int j = qMax(0, i - 3); j < i; j++) |
|
97 |
diff += expected.at(j) + '\n'; |
|
98 |
diff += "<<<<<<< got\n"; |
|
99 |
for (int j = i; j < gi; j++) { |
|
100 |
diff += actual.at(j) + '\n'; |
|
101 |
if (j >= i + 5) { |
|
102 |
diff += "...\n"; |
|
103 |
break; |
|
104 |
} |
|
105 |
} |
|
106 |
diff += "=========\n"; |
|
107 |
for (int j = i; j < ei; j++) { |
|
108 |
diff += expected.at(j) + '\n'; |
|
109 |
if (j >= i + 5) { |
|
110 |
diff += "...\n"; |
|
111 |
break; |
|
112 |
} |
|
113 |
} |
|
114 |
diff += ">>>>>>> expected\n"; |
|
115 |
for (int j = ei; j < qMin(ei + 3, expected.size()); j++) |
|
116 |
diff += expected.at(j) + '\n'; |
|
117 |
QFAIL(qPrintable("Output for " + expectedFn + " does not meet expectations:\n" + diff)); |
|
118 |
} |
|
119 |
||
120 |
void tst_lrelease::translate() |
|
121 |
{ |
|
122 |
QVERIFY(!QProcess::execute(binDir + "/lrelease testdata/translate.ts")); |
|
123 |
||
124 |
QTranslator translator; |
|
125 |
QVERIFY(translator.load("testdata/translate.qm")); |
|
126 |
qApp->installTranslator(&translator); |
|
127 |
||
128 |
QCOMPARE(QObject::tr("\nnewline at the start"), QString("\nNEWLINE AT THE START")); |
|
129 |
QCOMPARE(QObject::tr("newline at the end\n"), QString("NEWLINE AT THE END\n")); |
|
130 |
QCOMPARE(QObject::tr("newline and space at the end\n "), QString("NEWLINE AND SPACE AT THE END\n ")); |
|
131 |
QCOMPARE(QObject::tr("space and newline at the end \n"), QString("SPACE AND NEWLINE AT THE END \n")); |
|
132 |
QCOMPARE(QObject::tr("\ttab at the start and newline at the end\n"), QString("\tTAB AT THE START AND NEWLINE AT THE END\n")); |
|
133 |
QCOMPARE(QObject::tr("\n\tnewline and tab at the start"), QString("\n\tNEWLINE AND TAB AT THE START")); |
|
134 |
QCOMPARE(QObject::tr(" \tspace and tab at the start"), QString(" \tSPACE AND TAB AT THE START")); |
|
135 |
QCOMPARE(QObject::tr(" string that does not exist"), QString(" string that does not exist")); |
|
136 |
||
137 |
QCOMPARE(QCoreApplication::translate("CubeForm", "Test"), QString::fromAscii("BBBB")); |
|
138 |
QCOMPARE(QCoreApplication::translate("", "Test", "Empty context"), QString("AAAA")); |
|
139 |
||
140 |
// Test plurals |
|
141 |
QString txed = QCoreApplication::translate("Plurals", "There are %n houses", 0, QCoreApplication::UnicodeUTF8, 0); |
|
142 |
QCOMPARE(QString::fromAscii("[%1]").arg(txed), QString("[There are 0 houses]")); |
|
143 |
QCOMPARE(QCoreApplication::translate("Plurals", "There are %n houses", 0, QCoreApplication::UnicodeUTF8, 1), QString("There is 1 house")); |
|
144 |
QCOMPARE(QCoreApplication::translate("Plurals", "There are %n houses", 0, QCoreApplication::UnicodeUTF8, 2), QString("There are 2 houses")); |
|
145 |
QCOMPARE(QCoreApplication::translate("Plurals", "There are %n houses", 0, QCoreApplication::UnicodeUTF8, 3), QString("There are 3 houses")); |
|
146 |
||
147 |
||
148 |
// More plurals |
|
149 |
QCOMPARE(tr("There are %n cars", "More Plurals", 0) , QString("There are 0 cars")); |
|
150 |
QCOMPARE(tr("There are %n cars", "More Plurals", 1) , QString("There is 1 car")); |
|
151 |
QCOMPARE(tr("There are %n cars", "More Plurals", 2) , QString("There are 2 cars")); |
|
152 |
QCOMPARE(tr("There are %n cars", "More Plurals", 3) , QString("There are 3 cars")); |
|
153 |
||
154 |
||
155 |
QCOMPARE(QCoreApplication::translate("no_en", "Kj\370r K\345re, kj\346re"), QString::fromAscii("Drive K\345re, dear")); |
|
156 |
QCOMPARE(QCoreApplication::translate("en_no", "Drive K\345re, dear"), QString::fromAscii("Kj\370r K\345re, kj\346re")); |
|
157 |
QCOMPARE(QCoreApplication::translate("en_ch", "Chinese symbol:"), QString::fromAscii("Chinese symbol:%1").arg(QChar(0x7c1f))); |
|
158 |
||
159 |
// printf("halo\r\nhallo"); |
|
160 |
// QCOMPARE(tr("This\r\nwill fail"), QString("THIS\nWILL FAIL")); // \r\n = 0d 0a |
|
161 |
||
162 |
QCOMPARE(tr("Completely random string"), |
|
163 |
QString::fromLatin1("Super-lange Uebersetzung mit Schikanen\x9c" |
|
164 |
"Mittlere Uebersetung\x9c" |
|
165 |
"Kurze Uebers.")); |
|
166 |
||
167 |
qApp->removeTranslator(&translator); |
|
168 |
} |
|
169 |
||
170 |
void tst_lrelease::mixedcodecs() |
|
171 |
{ |
|
172 |
QVERIFY(!QProcess::execute(binDir + "/lrelease testdata/mixedcodecs-ts11.ts")); |
|
173 |
QVERIFY(!QProcess::execute(binDir + "/lrelease testdata/mixedcodecs-ts20.ts")); |
|
174 |
QVERIFY(!QProcess::execute("cmp testdata/mixedcodecs-ts11.qm testdata/mixedcodecs-ts20.qm")); |
|
175 |
QTranslator translator; |
|
176 |
QVERIFY(translator.load("testdata/mixedcodecs-ts11.qm")); |
|
177 |
qApp->installTranslator(&translator); |
|
178 |
||
179 |
QCOMPARE(QCoreApplication::translate("FooBar", "this contains an umlaut \xfc ü"), |
|
180 |
QString::fromAscii("random stuff with umlaut")); |
|
181 |
QCOMPARE(QCoreApplication::translate("FooBar", "umlaut \xc3\xbc ü in utf8"), |
|
182 |
QString::fromAscii("more random stuff with umlaut")); |
|
183 |
} |
|
184 |
||
185 |
void tst_lrelease::compressed() |
|
186 |
{ |
|
187 |
QVERIFY(!QProcess::execute(binDir + "/lrelease -compress testdata/compressed.ts")); |
|
188 |
||
189 |
QTranslator translator; |
|
190 |
QVERIFY(translator.load("testdata/compressed.qm")); |
|
191 |
qApp->installTranslator(&translator); |
|
192 |
||
193 |
QCOMPARE(QCoreApplication::translate("Context1", "Foo"), QString::fromAscii("in first context")); |
|
194 |
QCOMPARE(QCoreApplication::translate("Context2", "Bar"), QString::fromAscii("in second context")); |
|
195 |
||
196 |
QCOMPARE(QCoreApplication::translate("Action1", "Component Name"), QString::fromAscii("translation in first context")); |
|
197 |
QCOMPARE(QCoreApplication::translate("Action2", "Component Name"), QString::fromAscii("translation in second context")); |
|
198 |
QCOMPARE(QCoreApplication::translate("Action3", "Component Name"), QString::fromAscii("translation in third context")); |
|
199 |
||
200 |
} |
|
201 |
||
202 |
void tst_lrelease::idbased() |
|
203 |
{ |
|
204 |
QVERIFY(!QProcess::execute(binDir + "/lrelease -idbased testdata/idbased.ts")); |
|
205 |
||
206 |
QTranslator translator; |
|
207 |
QVERIFY(translator.load("testdata/idbased.qm")); |
|
208 |
qApp->installTranslator(&translator); |
|
209 |
||
210 |
QCOMPARE(qtTrId("test_id"), QString::fromAscii("This is a test string.")); |
|
211 |
QCOMPARE(qtTrId("untranslated_id"), QString::fromAscii("This has no translation.")); |
|
212 |
} |
|
213 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
void tst_lrelease::markuntranslated() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
QVERIFY(!QProcess::execute(binDir + "/lrelease -markuntranslated # -idbased testdata/idbased.ts")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
QTranslator translator; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
QVERIFY(translator.load("testdata/idbased.qm")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
qApp->installTranslator(&translator); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
QCOMPARE(qtTrId("test_id"), QString::fromAscii("This is a test string.")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
QCOMPARE(qtTrId("untranslated_id"), QString::fromAscii("#This has no translation.")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
|
0 | 226 |
void tst_lrelease::dupes() |
227 |
{ |
|
228 |
QProcess proc; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
proc.start(binDir + "/lrelease testdata/dupes.ts", QIODevice::ReadWrite | QIODevice::Text); |
0 | 230 |
QVERIFY(proc.waitForFinished()); |
231 |
QVERIFY(proc.exitStatus() == QProcess::NormalExit); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
doCompare(QString(proc.readAllStandardError()).trimmed().split('\n'), "testdata/dupes.errors"); |
0 | 233 |
} |
234 |
||
235 |
QTEST_MAIN(tst_lrelease) |
|
236 |
#include "tst_lrelease.moc" |