diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-07-25 11:11:25 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-08-13 09:23:02 +0200 |
commit | f23fed601b9a0080b93e87f893db5933dcffd040 (patch) | |
tree | ff5d4e1e68b73079d4a6b7b48b032e1bf2e11203 | |
parent | deb4fbe768b26918d9b23dfeac91e77cf382f3e2 (diff) | |
download | qt-creator-f23fed601b9a0080b93e87f893db5933dcffd040.tar.gz |
CppTools: Tests: Move test includes utils into helper class
Change-Id: Ia679f3d2ae5fce0978a4e320fa18b28f1a7bed71
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r-- | src/plugins/cppeditor/cppquickfix_test.cpp | 109 | ||||
-rw-r--r-- | src/plugins/cpptools/cpppreprocessertesthelper.cpp | 56 | ||||
-rw-r--r-- | src/plugins/cpptools/cpppreprocessertesthelper.h | 53 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptools.pro | 2 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptools.qbs | 1 |
5 files changed, 157 insertions, 64 deletions
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 351536db42..319f01d25c 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -34,6 +34,8 @@ #include "cppquickfixassistant.h" #include "cppquickfixes.h" +#include <cpptools/cpppreprocessertesthelper.h> + #include <cpptools/cppcodestylepreferences.h> #include <cpptools/cppmodelmanager.h> #include <cpptools/cpppreprocessor.h> @@ -346,27 +348,6 @@ private: const QString m_include; }; -QString includeBaseDirectory() -{ - return QLatin1String(SRCDIR) - + QLatin1String("/../../../tests/auto/cplusplus/preprocessor/data/include-data"); -} - -QString globalQtCoreIncludePath() -{ - return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/QtCore")); -} - -QString globalIncludePath() -{ - return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/global")); -} - -QString directoryOfTestFile() -{ - return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/local")); -} - } // anonymous namespace /// Checks: @@ -1283,7 +1264,7 @@ void CppEditorPlugin::test_quickfix_InsertDeclFromDef() QList<Include> includesForSource(const QByteArray &source) { - const QString fileName = directoryOfTestFile() + QLatin1String("/file.cpp"); + const QString fileName = TestIncludePaths::TestIncludePaths::directoryOfTestFile() + QLatin1String("/file.cpp"); Utils::FileSaver srcSaver(fileName); srcSaver.write(source); srcSaver.finalize(); @@ -1293,7 +1274,7 @@ QList<Include> includesForSource(const QByteArray &source) CppModelManager *cmm = CppModelManager::instance(); cmm->GC(); CppPreprocessor pp((QPointer<CppModelManager>(cmm))); - pp.setIncludePaths(QStringList(globalIncludePath())); + pp.setIncludePaths(QStringList(TestIncludePaths::globalIncludePath())); pp.run(fileName); Document::Ptr document = cmm->snapshot().document(fileName); @@ -1450,7 +1431,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_normal() // Header File original = "class Foo {};\n"; expected = original + "\n"; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("afile.h")); // Source File @@ -1472,12 +1453,12 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_normal() "}\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("afile.cpp")); // Do not use the test factory, at least once we want to go through the "full stack". AddIncludeForUndefinedIdentifier factory; - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1500,11 +1481,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc() "#include \"file.moc\";\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1527,11 +1508,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop( "#include \"z.h\"\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1554,11 +1535,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingMidd "#include \"z.h\"\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1581,11 +1562,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingBott "#include \"file.h\"\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1608,11 +1589,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_appendToUns "#include \"file.h\"\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1636,11 +1617,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstLocalI "#include <b.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1667,11 +1648,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstGlobal "void f();\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<file.h>")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1698,11 +1679,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_preferGroup "#include \"foo.h\"\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"prefixc.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1726,11 +1707,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_newGroupIfO "#include \"file.h\"\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1755,11 +1736,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsSo "#include <utils/file.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<firstlib/file.h>")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1784,11 +1765,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsUn "#include <lastlib/file.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lastlib/file.h>")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1811,11 +1792,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud "#include <global.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"z.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1838,11 +1819,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud "#include <global.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"a.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1865,11 +1846,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud "#include <global.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"lib/file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1892,11 +1873,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud "#include <lib/file.h>\n" "\n\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lib/file.h>")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1917,11 +1898,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_noinclude() "void f();\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1948,11 +1929,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn "void @f();\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -1983,11 +1964,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn "void @f();\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(globalIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); data.run(&factory); } @@ -2009,11 +1990,11 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomet "QDir dir;\n" "\n" ; - testFiles << TestDocument::create(original, expected, directoryOfTestFile() + QLatin1Char('/') + testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + QLatin1String("file.cpp")); AddIncludeForUndefinedIdentifier factory; - TestCase data(testFiles, QStringList(globalQtCoreIncludePath())); + TestCase data(testFiles, QStringList(TestIncludePaths::globalQtCoreIncludePath())); data.run(&factory); } diff --git a/src/plugins/cpptools/cpppreprocessertesthelper.cpp b/src/plugins/cpptools/cpppreprocessertesthelper.cpp new file mode 100644 index 0000000000..dc1f48df35 --- /dev/null +++ b/src/plugins/cpptools/cpppreprocessertesthelper.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "cpppreprocessertesthelper.h" + +#include <QDir> + +using namespace CppTools; + +QString TestIncludePaths::includeBaseDirectory() +{ + return QLatin1String(SRCDIR) + + QLatin1String("/../../../tests/auto/cplusplus/preprocessor/data/include-data"); +} + +QString TestIncludePaths::globalQtCoreIncludePath() +{ + return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/QtCore")); +} + +QString TestIncludePaths::globalIncludePath() +{ + return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/global")); +} + +QString TestIncludePaths::directoryOfTestFile() +{ + return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/local")); +} diff --git a/src/plugins/cpptools/cpppreprocessertesthelper.h b/src/plugins/cpptools/cpppreprocessertesthelper.h new file mode 100644 index 0000000000..c4eea5059e --- /dev/null +++ b/src/plugins/cpptools/cpppreprocessertesthelper.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#ifndef CPPPREPROCESSERTESTHELPER_H +#define CPPPREPROCESSERTESTHELPER_H + +#include "cpptools_global.h" + +#include <QtGlobal> + +QT_FORWARD_DECLARE_CLASS(QString) + +namespace CppTools { + +class CPPTOOLS_EXPORT TestIncludePaths +{ +public: + static QString includeBaseDirectory(); + static QString globalQtCoreIncludePath(); + static QString globalIncludePath(); + static QString directoryOfTestFile(); +}; + +} // namespace CppTools + +#endif // CPPPREPROCESSERTESTHELPER_H diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index a766102d2e..8eb46302f9 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -97,6 +97,7 @@ FORMS += completionsettingspage.ui \ equals(TEST, 1) { SOURCES += \ + cpppreprocessertesthelper.cpp \ cppcodegen_test.cpp \ cppcompletion_test.cpp \ cppmodelmanager_test.cpp \ @@ -104,6 +105,7 @@ equals(TEST, 1) { cpppointerdeclarationformatter_test.cpp HEADERS += \ + cpppreprocessertesthelper.h \ modelmanagertesthelper.h DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index 10b56aa9d3..240880d462 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -116,6 +116,7 @@ QtcPlugin { files: [ "cppcodegen_test.cpp", "cppcompletion_test.cpp", + "cpppreprocessertesthelper.cpp", "cpppreprocessertesthelper.h", "cppmodelmanager_test.cpp", "modelmanagertesthelper.cpp", "modelmanagertesthelper.h", "cpppointerdeclarationformatter_test.cpp" |