summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucie Gerard <lucie.gerard@qt.io>2020-09-15 12:05:12 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-30 13:51:36 +0000
commit51a8efb46aaaa7d4f50838b95ae1ca52e8e81290 (patch)
tree5d218bc0e22d19774d55a20b00c4af9433594f71
parent0e2ccdf0df7b97f41164e9bd07878540bbcb6354 (diff)
downloadqttools-51a8efb46aaaa7d4f50838b95ae1ca52e8e81290.tar.gz
Add test files for QT_TR_NOOP context
Change-Id: I7cf76aa8ff774c8eff7956739909104dd390f6a8 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 62a3420631881d0b651358de07c3a0854b1b9b1d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt4
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h33
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro4
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result114
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp165
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp165
-rw-r--r--tests/auto/linguist/lupdate/tst_lupdate.cpp2
7 files changed, 486 insertions, 1 deletions
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt
new file mode 100644
index 000000000..7d66b2066
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt
@@ -0,0 +1,4 @@
+.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context.cpp:51:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
+.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context.cpp:91:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
+.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context_bis.cpp:51:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
+.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context_bis.cpp:91:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h
new file mode 100644
index 000000000..53fc989e3
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h
@@ -0,0 +1,33 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtCore>
+
+class Foo
+{
+ Q_OBJECT
+};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro
new file mode 100644
index 000000000..6d72286b6
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro
@@ -0,0 +1,4 @@
+SOURCES += test_QT_TR_NOOP_context.cpp
+SOURCES += test_QT_TR_NOOP_context_bis.cpp
+
+TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result
new file mode 100644
index 000000000..0701b9b58
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1">
+<context>
+ <name>Foo</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="37"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="37"/>
+ <source>context Foo. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>IN_NESTED</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="61"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="61"/>
+ <source>context IN_NESTED. tr</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="62"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="62"/>
+ <source>context IN_NESTED. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>ONLY_Q</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="44"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="44"/>
+ <source>context ONLY_Q. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message numerus="yes">
+ <location filename="test_QT_TR_NOOP_context.cpp" line="45"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="45"/>
+ <source>context ONLY_Q. noop N</source>
+ <translation type="unfinished">
+ <numerusform></numerusform>
+ </translation>
+ </message>
+</context>
+<context>
+ <name>WithQDeclareTr::Nested</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="74"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="74"/>
+ <source>context WithQDeclareTr::Nested. tr</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="75"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="75"/>
+ <source>context WithQDeclareTr::Nested. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>my_arg</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="63"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="63"/>
+ <source>context my_arg. translate_noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>test2::BB</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="114"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="114"/>
+ <source>context test2::BB. tr</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="115"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="115"/>
+ <source>context test2::BB. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>test3::D</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="137"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="137"/>
+ <source>context test3::D. tr</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="138"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="138"/>
+ <source>context test3::D. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>test4::A::B::C</name>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="158"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="158"/>
+ <source>context is test4::A::B::C. tr</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="test_QT_TR_NOOP_context.cpp" line="159"/>
+ <location filename="test_QT_TR_NOOP_context_bis.cpp" line="159"/>
+ <source>context is test4::A::B::C. noop</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp
new file mode 100644
index 000000000..ea48000ac
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include "my_include.h"
+
+int X = 111222332444;
+
+// Q_OBJECT declared in an other file
+class FooChild : public Foo
+{
+ const char *c_noop = QT_TR_NOOP("context Foo. noop");
+};
+
+// No Q_OBJECT. Q_DECLARE_TR_FUNCTIONS. It is enough for tr, it is enough for QT_TR_NOOP
+class OnlyQDeclare
+{
+ Q_DECLARE_TR_FUNCTIONS(ONLY_Q)
+ const char *c_noop = QT_TR_NOOP("context ONLY_Q. noop");
+ const char *c_noop_n = QT_TR_N_NOOP("context ONLY_Q. noop N");
+};
+
+// Show the message warning that the QT_TR_NOOP is ignored because no context could be found.
+class Nothing
+{
+ const char *c_noop = QT_TR_NOOP("context Nothing. noop with no Q_OBJECT nor Q_DECLARE_TR_FUNCTIONS");
+};
+
+// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
+class WithQObject
+{
+ Q_OBJECT
+ class Nested
+ {
+ Q_DECLARE_TR_FUNCTIONS(IN_NESTED)
+ QString c_tr = tr("context IN_NESTED. tr");
+ const char *c_noop = QT_TR_NOOP("context IN_NESTED. noop");
+ const char *c_noop_translate = QT_TRANSLATE_NOOP("my_arg", "context my_arg. translate_noop");
+ };
+};
+
+// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
+class WithQDeclareTr
+{
+ Q_DECLARE_TR_FUNCTIONS(A_CONTEXT)
+ class Nested
+ {
+ Q_OBJECT
+ QString c_tr = tr("context WithQDeclareTr::Nested. tr");
+ const char *c_noop = QT_TR_NOOP("context WithQDeclareTr::Nested. noop");
+ };
+};
+
+// Case where Q_OBJECT is not seen. Behavior reproduces tr function behavior
+namespace test1 {
+ class AA
+ {
+ Q_OBJECT
+ public:
+ class A {};
+ };
+
+ class B : public AA::A
+ {
+ //QString c_tr = tr(" the Q_OBJECT is not seen"); // this will generate an error.
+ const char *c_noop = QT_TR_NOOP("the Q_OBJECT is not seen"); // Once exploring the bases of B (that is AA:A)
+ // we are not looking for the parents
+ // AA is the parent of A in terms of CXXContextDecl::getParent()
+ // This reproduced tr behavior.
+ };
+}
+
+namespace test2 {
+ class AA
+ {
+ Q_OBJECT
+ public:
+ class A {};
+ };
+
+ class C {};
+
+ class BB
+ {
+ Q_OBJECT
+ public:
+ class B : public AA::A, public C
+ {
+ QString c_tr = tr("context test2::BB. tr");
+ const char *c_noop = QT_TR_NOOP("context test2::BB. noop");
+ };
+ };
+}
+
+namespace test3 {
+ class AA
+ {
+ Q_OBJECT
+ public:
+ class A {};
+ };
+
+ class D {Q_OBJECT};
+ class C : public D {};
+
+ class BB
+ {
+ Q_OBJECT
+ public:
+ class B : public AA::A, public C
+ {
+ QString c_tr = tr("context test3::D. tr");
+ const char *c_noop = QT_TR_NOOP("context test3::D. noop");
+ };
+ };
+}
+
+namespace test4 {
+
+ class A
+ {
+ Q_OBJECT
+ public:
+ class B
+ {
+ public:
+ class C
+ {
+ Q_OBJECT
+ public:
+ class D
+ {
+ QString c_tr = tr("context is test4::A::B::C. tr");
+ const char *c_noop = QT_TR_NOOP("context is test4::A::B::C. noop");
+ };
+ };
+ };
+ };
+
+}
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp
new file mode 100644
index 000000000..8df5893ed
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include "my_include.h"
+// Testing with two files to check that patch https://codereview.qt-project.org/c/qt/qttools/+/338709/1..3 still works
+int X = 111222332444;
+
+// Q_OBJECT declared in an other file
+class FooChild : public Foo
+{
+ const char *c_noop = QT_TR_NOOP("context Foo. noop");
+};
+
+// No Q_OBJECT. Q_DECLARE_TR_FUNCTIONS. It is enough for tr, it is enough for QT_TR_NOOP
+class OnlyQDeclare
+{
+ Q_DECLARE_TR_FUNCTIONS(ONLY_Q)
+ const char *c_noop = QT_TR_NOOP("context ONLY_Q. noop");
+ const char *c_noop_n = QT_TR_N_NOOP("context ONLY_Q. noop N");
+};
+
+// Show the message warning that the QT_TR_NOOP is ignored because no context could be found.
+class Nothing
+{
+ const char *c_noop = QT_TR_NOOP("context Nothing. noop with no Q_OBJECT nor Q_DECLARE_TR_FUNCTIONS");
+};
+
+// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
+class WithQObject
+{
+ Q_OBJECT
+ class Nested
+ {
+ Q_DECLARE_TR_FUNCTIONS(IN_NESTED)
+ QString c_tr = tr("context IN_NESTED. tr");
+ const char *c_noop = QT_TR_NOOP("context IN_NESTED. noop");
+ const char *c_noop_translate = QT_TRANSLATE_NOOP("my_arg", "context my_arg. translate_noop");
+ };
+};
+
+// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
+class WithQDeclareTr
+{
+ Q_DECLARE_TR_FUNCTIONS(A_CONTEXT)
+ class Nested
+ {
+ Q_OBJECT
+ QString c_tr = tr("context WithQDeclareTr::Nested. tr");
+ const char *c_noop = QT_TR_NOOP("context WithQDeclareTr::Nested. noop");
+ };
+};
+
+// Case where Q_OBJECT is not seen. Behavior reproduces tr function behavior
+namespace test1 {
+ class AA
+ {
+ Q_OBJECT
+ public:
+ class A {};
+ };
+
+ class B : public AA::A
+ {
+ //QString c_tr = tr(" the Q_OBJECT is not seen"); // this will generate an error.
+ const char *c_noop = QT_TR_NOOP("the Q_OBJECT is not seen"); // Once exploring the bases of B (that is AA:A)
+ // we are not looking for the parents
+ // AA is the parent of A in terms of CXXContextDecl::getParent()
+ // This reproduced tr behavior.
+ };
+}
+
+namespace test2 {
+ class AA
+ {
+ Q_OBJECT
+ public:
+ class A {};
+ };
+
+ class C {};
+
+ class BB
+ {
+ Q_OBJECT
+ public:
+ class B : public AA::A, public C
+ {
+ QString c_tr = tr("context test2::BB. tr");
+ const char *c_noop = QT_TR_NOOP("context test2::BB. noop");
+ };
+ };
+}
+
+namespace test3 {
+ class AA
+ {
+ Q_OBJECT
+ public:
+ class A {};
+ };
+
+ class D {Q_OBJECT};
+ class C : public D {};
+
+ class BB
+ {
+ Q_OBJECT
+ public:
+ class B : public AA::A, public C
+ {
+ QString c_tr = tr("context test3::D. tr");
+ const char *c_noop = QT_TR_NOOP("context test3::D. noop");
+ };
+ };
+}
+
+namespace test4 {
+
+ class A
+ {
+ Q_OBJECT
+ public:
+ class B
+ {
+ public:
+ class C
+ {
+ Q_OBJECT
+ public:
+ class D
+ {
+ QString c_tr = tr("context is test4::A::B::C. tr");
+ const char *c_noop = QT_TR_NOOP("context is test4::A::B::C. noop");
+ };
+ };
+ };
+ };
+
+}
diff --git a/tests/auto/linguist/lupdate/tst_lupdate.cpp b/tests/auto/linguist/lupdate/tst_lupdate.cpp
index 10d640482..57d7c087f 100644
--- a/tests/auto/linguist/lupdate/tst_lupdate.cpp
+++ b/tests/auto/linguist/lupdate/tst_lupdate.cpp
@@ -235,7 +235,7 @@ void tst_lupdate::good_data()
QSet<QString> ignoredTests = {
"lacksqobject_clang_parser", "parsecontexts_clang_parser", "parsecpp2_clang_parser",
"parsecpp_clang_parser", "prefix_clang_parser", "preprocess_clang_parser",
- };
+ "parsecpp_clang_only"};
// Add test rows for the "classic" lupdate
for (const QString &dir : dirs) {