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 <QtTest/QtTest>
|
|
43 |
#include <QtCore/QtCore>
|
|
44 |
|
|
45 |
//TESTED_CLASS=
|
|
46 |
//TESTED_FILES=
|
|
47 |
|
|
48 |
#include "tst_linguist.h"
|
|
49 |
|
|
50 |
void tst_linguist::fetchtr()
|
|
51 |
{
|
|
52 |
// FIXME: This probably should use some yet-to-be-invented
|
|
53 |
// binary interface to 'lupdate' instead of playing around
|
|
54 |
// with the filesystem,
|
|
55 |
|
|
56 |
QRegExp reg("\\s*");
|
|
57 |
QString lupdate("lupdate");
|
|
58 |
|
|
59 |
QFETCH(QString, input);
|
|
60 |
|
|
61 |
QFETCH(QString, name);
|
|
62 |
QFETCH(QString, file);
|
|
63 |
QFETCH(QString, line);
|
|
64 |
QFETCH(QString, src);
|
|
65 |
|
|
66 |
QString result;
|
|
67 |
|
|
68 |
QTemporaryFile profile("tst_lu_XXXXXX.pro");
|
|
69 |
QTemporaryFile cppfile("tst_lu_XXXXXX.cpp");
|
|
70 |
QTemporaryFile tsfile("tst_lu_XXXXXX.ts");
|
|
71 |
|
|
72 |
profile.open();
|
|
73 |
cppfile.open();
|
|
74 |
tsfile.open();
|
|
75 |
|
|
76 |
#if 0
|
|
77 |
profile.setAutoRemove(false);
|
|
78 |
cppfile.setAutoRemove(false);
|
|
79 |
tsfile.setAutoRemove(false);
|
|
80 |
|
|
81 |
qDebug() << ".pro: " << profile.fileName();
|
|
82 |
qDebug() << ".cpp: " << cppfile.fileName();
|
|
83 |
qDebug() << ".ts: " << tsfile.fileName();
|
|
84 |
#endif
|
|
85 |
|
|
86 |
QTextStream prots(&profile);
|
|
87 |
prots << "SOURCES += " << cppfile.fileName() << "\n";
|
|
88 |
prots << "TRANSLATIONS += " << tsfile.fileName() << "\n";
|
|
89 |
prots.flush();
|
|
90 |
|
|
91 |
QTextStream cppts(&cppfile);
|
|
92 |
cppts.setCodec("ISO 8859-1");
|
|
93 |
cppts << input << '\n';
|
|
94 |
cppts.flush();
|
|
95 |
|
|
96 |
QProcess proc;
|
|
97 |
proc.start(lupdate, QStringList() << profile.fileName());
|
|
98 |
proc.waitForFinished();
|
|
99 |
|
|
100 |
result = tsfile.readAll();
|
|
101 |
|
|
102 |
static QRegExp re(
|
|
103 |
"<name>(.+)</name>\\s*"
|
|
104 |
"<message.*>\\s*" // there might be a numerus="yes" attribiute
|
|
105 |
"<location filename=\"(.+)\" line=\"(\\d+)\"/>\\s*"
|
|
106 |
"<source>(.+)</source>\\s*"
|
|
107 |
"<translation type=\"unfinished\">.*</translation>\\s*"
|
|
108 |
);
|
|
109 |
|
|
110 |
re.indexIn(result);
|
|
111 |
QString resname = re.cap(1);
|
|
112 |
//QString resfile = re.cap(2);
|
|
113 |
QString resline = re.cap(3);
|
|
114 |
QString ressrc = re.cap(4);
|
|
115 |
|
|
116 |
//qDebug() << "pattern:" << re.pattern();
|
|
117 |
//qDebug() << "result:" << result;
|
|
118 |
//qDebug() << "resname:" << resname;
|
|
119 |
////qDebug() << "resfile:" << resfile;
|
|
120 |
//qDebug() << "resline:" << resline;
|
|
121 |
//qDebug() << "ressource:" << ressrc;
|
|
122 |
|
|
123 |
QCOMPARE(src + ": " + resname, src + ": " + name);
|
|
124 |
QCOMPARE(src + ": " + resline, src + ": " + line);
|
|
125 |
QCOMPARE(src + ": " + ressrc, src + ": " + src);
|
|
126 |
}
|
|
127 |
|
|
128 |
void tst_linguist::fetchtr_data()
|
|
129 |
{
|
|
130 |
using namespace QTest;
|
|
131 |
|
|
132 |
addColumn<QString>("input");
|
|
133 |
addColumn<QString>("name");
|
|
134 |
addColumn<QString>("file");
|
|
135 |
addColumn<QString>("line");
|
|
136 |
addColumn<QString>("src");
|
|
137 |
|
|
138 |
// plain stuff
|
|
139 |
newRow("00") << "int main() { tr(\"foo\"); }"
|
|
140 |
<< "@default" << "XXXXXX" << "1" << "foo";
|
|
141 |
|
|
142 |
// space at beginning of text
|
|
143 |
newRow("01") << "int main() { tr(\" foo\"); }"
|
|
144 |
<< "@default" << "XXXXXX" << "1" << " foo";
|
|
145 |
// space at end of text
|
|
146 |
newRow("02") << "int main() { tr(\"foo \"); }"
|
|
147 |
<< "@default" << "XXXXXX" << "1" << "foo ";
|
|
148 |
// space in the middle of the text
|
|
149 |
newRow("03") << "int main() { tr(\"foo bar\"); }"
|
|
150 |
<< "@default" << "XXXXXX" << "1" << "foo bar";
|
|
151 |
|
|
152 |
// tab at beginning of text
|
|
153 |
newRow("04") << "int main() { tr(\"\tfoo\"); }"
|
|
154 |
<< "@default" << "XXXXXX" << "1" << "<byte value=\"x9\"/>foo";
|
|
155 |
// tab at end of text
|
|
156 |
newRow("05") << "int main() { tr(\"foo\t\"); }"
|
|
157 |
<< "@default" << "XXXXXX" << "1" << "foo<byte value=\"x9\"/>";
|
|
158 |
// tab in the middle of the text
|
|
159 |
newRow("06") << "int main() { tr(\"foo\tbar\"); }"
|
|
160 |
<< "@default" << "XXXXXX" << "1" << "foo<byte value=\"x9\"/>bar";
|
|
161 |
|
|
162 |
// check for unicode
|
|
163 |
newRow("07") << "int main() { tr(\"\32\"); }" // 26 dec
|
|
164 |
<< "@default" << "XXXXXX" << "1" << "<byte value=\"x1a\"/>";
|
|
165 |
// check for unicode
|
|
166 |
newRow("08") << "int main() { tr(\"\33\"); }" // 27 dec
|
|
167 |
<< "@default" << "XXXXXX" << "1" << "<byte value=\"x1b\"/>";
|
|
168 |
// check for unicode
|
|
169 |
newRow("09") << "int main() { tr(\"\176\"); }" // 124 dec
|
|
170 |
<< "@default" << "XXXXXX" << "1" << "~";
|
|
171 |
// check for unicode
|
|
172 |
newRow("10") << "int main() { tr(\"\301\"); }" // 193 dec
|
|
173 |
<< "@default" << "XXXXXX" << "1" << "Á";
|
|
174 |
|
|
175 |
// Bug 162562: lupdate does not find QCoreApplication::translate() strings
|
|
176 |
newRow("11") << "int main() { QString s = QCoreApplication::translate"
|
|
177 |
"(\"mycontext\", \"msg\", \"\", QCoreApplication::CodecForTr, 2);"
|
|
178 |
<< "mycontext" << "XXXXXX" << "1" << "msg";
|
|
179 |
|
|
180 |
// Bug 161504: lupdate produces wrong ts file with context "N::QObject"
|
|
181 |
newRow("12") << "namespace N { QString foo() "
|
|
182 |
"{ return QObject::tr(\"msg\"); }"
|
|
183 |
<< "QObject" << "XXXXXX" << "1" << "msg";
|
|
184 |
|
|
185 |
// Correct example from 161504:
|
|
186 |
newRow("13") << "namespace N { QString foo(); }"
|
|
187 |
"QString N::anyfunc() { return QObject::tr(\"msg\"); }"
|
|
188 |
<< "QObject" << "XXXXXX" << "1" << "msg";
|
|
189 |
|
|
190 |
// Bug 161106: When specifying ::QObject::tr() then lupdate will
|
|
191 |
// take the previous word as being the namespace
|
|
192 |
newRow("14") << " std::cout << ::QObject::tr(\"msg\");"
|
|
193 |
<< "QObject" << "XXXXXX" << "1" << "msg";
|
|
194 |
|
|
195 |
}
|