1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <QtCore/QtCore>
//TESTED_CLASS=
//TESTED_FILES=
#include "tst_linguist.h"
void tst_linguist::fetchtr()
{
// FIXME: This probably should use some yet-to-be-invented
// binary interface to 'lupdate' instead of playing around
// with the filesystem,
QRegExp reg("\\s*");
QString lupdate("lupdate");
QFETCH(QString, input);
QFETCH(QString, name);
QFETCH(QString, file);
QFETCH(QString, line);
QFETCH(QString, src);
QString result;
QTemporaryFile profile("tst_lu_XXXXXX.pro");
QTemporaryFile cppfile("tst_lu_XXXXXX.cpp");
QTemporaryFile tsfile("tst_lu_XXXXXX.ts");
profile.open();
cppfile.open();
tsfile.open();
#if 0
profile.setAutoRemove(false);
cppfile.setAutoRemove(false);
tsfile.setAutoRemove(false);
qDebug() << ".pro: " << profile.fileName();
qDebug() << ".cpp: " << cppfile.fileName();
qDebug() << ".ts: " << tsfile.fileName();
#endif
QTextStream prots(&profile);
prots << "SOURCES += " << cppfile.fileName() << "\n";
prots << "TRANSLATIONS += " << tsfile.fileName() << "\n";
prots.flush();
QTextStream cppts(&cppfile);
cppts.setCodec("ISO 8859-1");
cppts << input << '\n';
cppts.flush();
QProcess proc;
proc.start(lupdate, QStringList() << profile.fileName());
proc.waitForFinished();
result = tsfile.readAll();
static QRegExp re(
"<name>(.+)</name>\\s*"
"<message.*>\\s*" // there might be a numerus="yes" attribiute
"<location filename=\"(.+)\" line=\"(\\d+)\"/>\\s*"
"<source>(.+)</source>\\s*"
"<translation type=\"unfinished\">.*</translation>\\s*"
);
re.indexIn(result);
QString resname = re.cap(1);
//QString resfile = re.cap(2);
QString resline = re.cap(3);
QString ressrc = re.cap(4);
//qDebug() << "pattern:" << re.pattern();
//qDebug() << "result:" << result;
//qDebug() << "resname:" << resname;
////qDebug() << "resfile:" << resfile;
//qDebug() << "resline:" << resline;
//qDebug() << "ressource:" << ressrc;
QCOMPARE(src + ": " + resname, src + ": " + name);
QCOMPARE(src + ": " + resline, src + ": " + line);
QCOMPARE(src + ": " + ressrc, src + ": " + src);
}
void tst_linguist::fetchtr_data()
{
using namespace QTest;
addColumn<QString>("input");
addColumn<QString>("name");
addColumn<QString>("file");
addColumn<QString>("line");
addColumn<QString>("src");
// plain stuff
newRow("00") << "int main() { tr(\"foo\"); }"
<< "@default" << "XXXXXX" << "1" << "foo";
// space at beginning of text
newRow("01") << "int main() { tr(\" foo\"); }"
<< "@default" << "XXXXXX" << "1" << " foo";
// space at end of text
newRow("02") << "int main() { tr(\"foo \"); }"
<< "@default" << "XXXXXX" << "1" << "foo ";
// space in the middle of the text
newRow("03") << "int main() { tr(\"foo bar\"); }"
<< "@default" << "XXXXXX" << "1" << "foo bar";
// tab at beginning of text
newRow("04") << "int main() { tr(\"\tfoo\"); }"
<< "@default" << "XXXXXX" << "1" << "<byte value=\"x9\"/>foo";
// tab at end of text
newRow("05") << "int main() { tr(\"foo\t\"); }"
<< "@default" << "XXXXXX" << "1" << "foo<byte value=\"x9\"/>";
// tab in the middle of the text
newRow("06") << "int main() { tr(\"foo\tbar\"); }"
<< "@default" << "XXXXXX" << "1" << "foo<byte value=\"x9\"/>bar";
// check for unicode
newRow("07") << "int main() { tr(\"\32\"); }" // 26 dec
<< "@default" << "XXXXXX" << "1" << "<byte value=\"x1a\"/>";
// check for unicode
newRow("08") << "int main() { tr(\"\33\"); }" // 27 dec
<< "@default" << "XXXXXX" << "1" << "<byte value=\"x1b\"/>";
// check for unicode
newRow("09") << "int main() { tr(\"\176\"); }" // 124 dec
<< "@default" << "XXXXXX" << "1" << "~";
// check for unicode
newRow("10") << "int main() { tr(\"\301\"); }" // 193 dec
<< "@default" << "XXXXXX" << "1" << "Á";
// Bug 162562: lupdate does not find QCoreApplication::translate() strings
newRow("11") << "int main() { QString s = QCoreApplication::translate"
"(\"mycontext\", \"msg\", \"\", QCoreApplication::CodecForTr, 2);"
<< "mycontext" << "XXXXXX" << "1" << "msg";
// Bug 161504: lupdate produces wrong ts file with context "N::QObject"
newRow("12") << "namespace N { QString foo() "
"{ return QObject::tr(\"msg\"); }"
<< "QObject" << "XXXXXX" << "1" << "msg";
// Correct example from 161504:
newRow("13") << "namespace N { QString foo(); }"
"QString N::anyfunc() { return QObject::tr(\"msg\"); }"
<< "QObject" << "XXXXXX" << "1" << "msg";
// Bug 161106: When specifying ::QObject::tr() then lupdate will
// take the previous word as being the namespace
newRow("14") << " std::cout << ::QObject::tr(\"msg\");"
<< "QObject" << "XXXXXX" << "1" << "msg";
}
|