diff --git a/kdevplatform/shell/tests/test_plugincontroller.cpp b/kdevplatform/shell/tests/test_plugincontroller.cpp index 2a45fa30f0..3c930bfbba 100644 --- a/kdevplatform/shell/tests/test_plugincontroller.cpp +++ b/kdevplatform/shell/tests/test_plugincontroller.cpp @@ -1,108 +1,100 @@ /*************************************************************************** * Copyright 2008 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "test_plugincontroller.h" #include "nonguiinterfaceplugin.h" #include "testfilepaths.h" #include #include #include #include #include "../core.h" #include "../plugincontroller.h" using namespace KDevelop; void TestPluginController::initTestCase() { qApp->addLibraryPath(QStringLiteral(TEST_PLUGIN_DIR)); AutoTestShell::init({QStringLiteral("kdevnonguiinterface")}); TestCore::initialize( Core::NoUi ); m_pluginCtrl = Core::self()->pluginControllerInternal(); } void TestPluginController::cleanupTestCase() { TestCore::shutdown(); } -void TestPluginController::init() -{ -} - -void TestPluginController::cleanup() -{ -} - void TestPluginController::pluginInfo() { IPlugin* plugin = m_pluginCtrl->loadPlugin( QStringLiteral("kdevnonguiinterface") ); QVERIFY(plugin); KPluginMetaData pluginInfo = m_pluginCtrl->pluginInfo(plugin); QCOMPARE(pluginInfo.pluginId(), QStringLiteral("kdevnonguiinterface")); } void TestPluginController::loadUnloadPlugin() { QSignalSpy spy(m_pluginCtrl, SIGNAL(pluginLoaded(KDevelop::IPlugin*))); QSignalSpy spyloading(m_pluginCtrl, SIGNAL(loadingPlugin(QString))); QVERIFY(spy.isValid()); QVERIFY(spyloading.isValid()); m_pluginCtrl->loadPlugin( QStringLiteral( "kdevnonguiinterface" ) ); QVERIFY( m_pluginCtrl->plugin( QStringLiteral( "kdevnonguiinterface" ) ) ); QCOMPARE(spy.size(), 1); QCOMPARE(spyloading.size(), 1); QList args = spyloading.takeFirst(); QCOMPARE( args.at(0).toString(), QStringLiteral( "kdevnonguiinterface" ) ); QSignalSpy spy2(m_pluginCtrl, SIGNAL(pluginUnloaded(KDevelop::IPlugin*)) ); QSignalSpy spy3(m_pluginCtrl, SIGNAL(unloadingPlugin(KDevelop::IPlugin*)) ); QVERIFY(spy2.isValid()); QVERIFY(spy3.isValid()); m_pluginCtrl->unloadPlugin( QStringLiteral("kdevnonguiinterface") ); QVERIFY( !m_pluginCtrl->plugin( QStringLiteral( "kdevnonguiinterface" ) ) ); QCOMPARE(spy2.size(), 1); QCOMPARE(spy3.size(), 1); } void TestPluginController::loadFromExtension() { IPlugin* plugin = m_pluginCtrl->pluginForExtension( QStringLiteral("org.kdevelop.ITestNonGuiInterface") ); QVERIFY( plugin ); QVERIFY( plugin->inherits("org.kdevelop.ITestNonGuiInterface") ); QVERIFY( plugin->extension()); } void TestPluginController::benchPluginForExtension() { QBENCHMARK { IPlugin* plugin = m_pluginCtrl->pluginForExtension( QStringLiteral("org.kdevelop.ITestNonGuiInterface") ); QVERIFY( plugin ); } } QTEST_MAIN( TestPluginController) diff --git a/kdevplatform/shell/tests/test_plugincontroller.h b/kdevplatform/shell/tests/test_plugincontroller.h index 0675ae5d2c..f09279c135 100644 --- a/kdevplatform/shell/tests/test_plugincontroller.h +++ b/kdevplatform/shell/tests/test_plugincontroller.h @@ -1,49 +1,48 @@ /*************************************************************************** * Copyright 2008 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef KDEVPLATFORM_TEST_PLUGINCONTROLLER_H #define KDEVPLATFORM_TEST_PLUGINCONTROLLER_H #include namespace KDevelop { class Core; class PluginController; } class TestPluginController : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); - void init(); - void cleanup(); + void loadUnloadPlugin(); void loadFromExtension(); void pluginInfo(); void benchPluginForExtension(); private: KDevelop::PluginController* m_pluginCtrl; }; #endif // KDEVPLATFORM_TEST_PLUGINCONTROLLER_H diff --git a/plugins/clang/tests/test_refactoring.cpp b/plugins/clang/tests/test_refactoring.cpp index 4c819518ff..6145940e3a 100644 --- a/plugins/clang/tests/test_refactoring.cpp +++ b/plugins/clang/tests/test_refactoring.cpp @@ -1,144 +1,136 @@ /* * Copyright 2017 Kevin Funk * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "test_refactoring.h" #include #include #include #include #include #include "codegen/clangrefactoring.h" #include #include #include #include #include #include QTEST_MAIN(TestRefactoring); using namespace KDevelop; TestRefactoring::~TestRefactoring() = default; void TestRefactoring::initTestCase() { QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevelop.plugins.clang.debug=true\n")); QVERIFY(qputenv("KDEV_CLANG_DISPLAY_DIAGS", "1")); AutoTestShell::init({QStringLiteral("kdevclangsupport")}); auto core = TestCore::initialize(); delete core->projectController(); m_projectController = new TestProjectController(core); core->setProjectController(m_projectController); } void TestRefactoring::cleanupTestCase() { TestCore::shutdown(); } -void TestRefactoring::cleanup() -{ -} - -void TestRefactoring::init() -{ -} - void TestRefactoring::testClassRename() { const QString codeBefore(QStringLiteral(R"( class Foo { public: Foo(); ~Foo(); }; Foo::Foo() { } Foo::~Foo() { } )")); const QString codeAfter(QStringLiteral(R"( class FooNew { public: FooNew(); ~FooNew(); }; FooNew::FooNew() { } FooNew::~FooNew() { } )")); QTemporaryDir dir; auto project = new TestProject(Path(dir.path()), this); m_projectController->addProject(project); TestFile file(codeBefore, QStringLiteral("cpp"), project, dir.path()); QVERIFY(file.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses)); DUChainReadLocker lock; auto top = file.topContext(); QVERIFY(top); auto declaration = top->localDeclarations().first(); QVERIFY(declaration); const QString originalName = declaration->identifier().identifier().str(); const QString newName = QStringLiteral("FooNew"); QSharedPointer collector(new BasicRefactoringCollector(declaration)); // TODO: Do this without GUI? UsesWidget uses(declaration, collector); lock.unlock(); for (int i = 0; i < 30000; i += 1000) { if (collector->isReady()) { break; } QTest::qWait(1000); } QVERIFY(collector->isReady()); BasicRefactoring::NameAndCollector nameAndCollector{newName, collector}; auto languages = ICore::self()->languageController()->languagesForUrl(file.url().toUrl()); QVERIFY(!languages.isEmpty()); auto clangLanguageSupport = languages.first(); QVERIFY(clangLanguageSupport); auto clangRefactoring = qobject_cast(clangLanguageSupport->refactoring()); QVERIFY(clangRefactoring); clangRefactoring->renameCollectedDeclarations(nameAndCollector.collector.data(), newName, originalName); QCOMPARE(file.fileContents(), codeAfter); m_projectController->closeAllProjects(); } diff --git a/plugins/clang/tests/test_refactoring.h b/plugins/clang/tests/test_refactoring.h index c9805609b8..cca87fe01b 100644 --- a/plugins/clang/tests/test_refactoring.h +++ b/plugins/clang/tests/test_refactoring.h @@ -1,49 +1,46 @@ /* * Copyright 2017 Kevin Funk * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TEST_REFACTORING_H #define TEST_REFACTORING_H #include namespace KDevelop { class TestProjectController; } class TestRefactoring : public QObject { Q_OBJECT public: ~TestRefactoring() override; private Q_SLOTS: void initTestCase(); void cleanupTestCase(); - void init(); - void cleanup(); - void testClassRename(); private: KDevelop::TestProjectController* m_projectController; }; #endif // TEST_REFACTORING_H diff --git a/plugins/qmakemanager/parser/tests/lexertest.cpp b/plugins/qmakemanager/parser/tests/lexertest.cpp index 2c220912e4..ca9f6e4643 100644 --- a/plugins/qmakemanager/parser/tests/lexertest.cpp +++ b/plugins/qmakemanager/parser/tests/lexertest.cpp @@ -1,429 +1,421 @@ /* KDevelop * * Copyright 2007 Andreas Pakulat * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #include "lexertest.h" #include "qmakelexer.h" #include "qmakeparser.h" QTEST_MAIN(LexerTest) LexerTest::LexerTest(QObject* parent) : QObject(parent) { } LexerTest::~LexerTest() { } -void LexerTest::init() -{ -} - -void LexerTest::cleanup() -{ -} - void LexerTest::varAssignment() { QFETCH(QString, project); QFETCH(QList, expectedtokens); QFETCH(QList, expectedbegins); QFETCH(QList, expectedends); QMake::Lexer l(nullptr, project); QList tokens; QList begins; QList ends; int token = 0; do { token = l.nextTokenKind(); tokens << token; begins << qulonglong(l.tokenBegin()); ends << qulonglong(l.tokenEnd()); } while (token != 0); tokens.removeLast(); begins.removeLast(); ends.removeLast(); QVERIFY(tokens == expectedtokens); QVERIFY(begins == expectedbegins); QVERIFY(ends == expectedends); } void LexerTest::varAssignment_data() { QTest::addColumn("project"); QTest::addColumn>("expectedtokens"); QTest::addColumn>("expectedbegins"); QTest::addColumn>("expectedends"); QList expectedtokens; QList expectedbegins; QList expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7; expectedends << 2 << 5 << 9; QTest::newRow("row1") << "FOO += bar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 10 << 11 << 12; expectedends << 2 << 5 << 9 << 10 << 11 << 14; QTest::newRow("row2") << "FOO += bar\\\nbaz" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 14 << 15 << 21 << 22 << 23; expectedends << 2 << 5 << 9 << 14 << 15 << 21 << 22 << 25; QTest::newRow("row3") << "FOO += bar \\\n \\\nbaz" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 14 << 20 << 26; expectedends << 2 << 5 << 9 << 14 << 20 << 28; QTest::newRow("row4") << "FOO += bar \\ \n baz" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 4 << 8 << 11; expectedends << 6 << 9 << 13; QTest::newRow("row5") << " FOO += bar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7; expectedends << 2 << 5 << 9; QTest::newRow("row6") << "FOO += bar#ffoo" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedbegins << 0 << 4 << 7 << 10 << 11; expectedends << 2 << 5 << 9 << 10 << 11; QTest::newRow("row7") << "FOO += bar\\\n#baz" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 10 << 11 << 17; expectedends << 2 << 5 << 9 << 10 << 11 << 19; QTest::newRow("row8") << "FOO += bar\\\n#baz\nbar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_CONT; expectedtokens << QMake::Parser::Token_NEWLINE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 10 << 15 << 16; expectedends << 2 << 5 << 9 << 10 << 15 << 18; QTest::newRow("row9") << "FOO += bar\\#far\nbaz" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 11; expectedends << 2 << 5 << 9 << 26; QTest::newRow("row10") << "FOO += bar \"fsfsd sadfsd\"" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7 << 11; expectedends << 2 << 5 << 9 << 18; QTest::newRow("row11") << "FOO += bar \"fsfsd # sadfsd\"" << expectedtokens << expectedbegins << expectedends; } void LexerTest::functions() { QFETCH(QString, project); QFETCH(QList, expectedtokens); QFETCH(QList, expectedbegins); QFETCH(QList, expectedends); QMake::Lexer l(nullptr, project); QList tokens; QList begins; QList ends; int token = 0; do { token = l.nextTokenKind(); tokens << token; begins << qulonglong(l.tokenBegin()); ends << qulonglong(l.tokenEnd()); } while (token != 0); tokens.removeLast(); begins.removeLast(); ends.removeLast(); QVERIFY(tokens == expectedtokens); QVERIFY(begins == expectedbegins); QVERIFY(ends == expectedends); } void LexerTest::functions_data() { QTest::addColumn("project"); QTest::addColumn>("expectedtokens"); QTest::addColumn>("expectedbegins"); QTest::addColumn>("expectedends"); QList expectedtokens; QList expectedbegins; QList expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LPAREN; expectedtokens << QMake::Parser::Token_RPAREN; expectedbegins << 0 << 3 << 4; expectedends << 2 << 3 << 4; QTest::newRow("row1") << "foo()" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LPAREN; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_RPAREN; expectedbegins << 0 << 3 << 4 << 8; expectedends << 2 << 3 << 7 << 8; QTest::newRow("row2") << "foo(arg1)" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LPAREN; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_COMMA; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_RPAREN; expectedbegins << 0 << 3 << 4 << 8 << 9 << 13; expectedends << 2 << 3 << 7 << 8 << 12 << 13; QTest::newRow("row3") << "foo(arg1,arg3)" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LPAREN; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_RPAREN; expectedbegins << 0 << 3 << 4 << 20; expectedends << 2 << 3 << 19 << 20; QTest::newRow("row4") << "foo( arg1 arg2 )" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LPAREN; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_RPAREN; expectedbegins << 0 << 3 << 4 << 22; expectedends << 2 << 3 << 21 << 22; QTest::newRow("row5") << "foo( arg1 \\\n arg2 )" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LPAREN; expectedtokens << QMake::Parser::Token_VALUE; expectedtokens << QMake::Parser::Token_RPAREN; expectedtokens << QMake::Parser::Token_LBRACE; expectedbegins << 0 << 3 << 4 << 8 << 10; expectedends << 2 << 3 << 7 << 8 << 10; QTest::newRow("row5") << "foo(arg1) {" << expectedtokens << expectedbegins << expectedends; } void LexerTest::operators() { QFETCH(QString, project); QFETCH(QList, expectedtokens); QFETCH(QList, expectedbegins); QFETCH(QList, expectedends); QMake::Lexer l(nullptr, project); QList tokens; QList begins; QList ends; int token = 0; do { token = l.nextTokenKind(); tokens << token; begins << qulonglong(l.tokenBegin()); ends << qulonglong(l.tokenEnd()); } while (token != 0); tokens.removeLast(); begins.removeLast(); ends.removeLast(); qDebug() << project; qDebug() << tokens << expectedtokens; qDebug() << begins << expectedbegins; qDebug() << ends << expectedends; QVERIFY(tokens == expectedtokens); QVERIFY(begins == expectedbegins); QVERIFY(ends == expectedends); } void LexerTest::operators_data() { QTest::addColumn("project"); QTest::addColumn>("expectedtokens"); QTest::addColumn>("expectedbegins"); QTest::addColumn>("expectedends"); QList expectedtokens; QList expectedbegins; QList expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_EQUAL; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 6; expectedends << 2 << 4 << 8; QTest::newRow("row1") << "foo = bar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_PLUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7; expectedends << 2 << 5 << 9; QTest::newRow("row2") << "foo += bar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_MINUSEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7; expectedends << 2 << 5 << 9; QTest::newRow("row3") << "foo -= bar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_TILDEEQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7; expectedends << 2 << 5 << 9; QTest::newRow("row4") << "foo ~= bar" << expectedtokens << expectedbegins << expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_STAREQ; expectedtokens << QMake::Parser::Token_VALUE; expectedbegins << 0 << 4 << 7; expectedends << 2 << 5 << 9; QTest::newRow("row5") << "foo *= bar" << expectedtokens << expectedbegins << expectedends; } void LexerTest::scope() { QFETCH(QString, project); QFETCH(QList, expectedtokens); QFETCH(QList, expectedbegins); QFETCH(QList, expectedends); QMake::Lexer l(nullptr, project); QList tokens; QList begins; QList ends; int token = 0; do { token = l.nextTokenKind(); tokens << token; begins << qulonglong(l.tokenBegin()); ends << qulonglong(l.tokenEnd()); } while (token != 0); tokens.removeLast(); begins.removeLast(); ends.removeLast(); QVERIFY(tokens == expectedtokens); QVERIFY(begins == expectedbegins); QVERIFY(ends == expectedends); } void LexerTest::scope_data() { QTest::addColumn("project"); QTest::addColumn>("expectedtokens"); QTest::addColumn>("expectedbegins"); QTest::addColumn>("expectedends"); QList expectedtokens; QList expectedbegins; QList expectedends; expectedtokens.clear(); expectedbegins.clear(); expectedends.clear(); expectedtokens << QMake::Parser::Token_IDENTIFIER; expectedtokens << QMake::Parser::Token_LBRACE; expectedbegins << 0 << 3; expectedends << 2 << 3; QTest::newRow("row1") << "foo{" << expectedtokens << expectedbegins << expectedends; } diff --git a/plugins/qmakemanager/parser/tests/lexertest.h b/plugins/qmakemanager/parser/tests/lexertest.h index 0259629349..495037a03e 100644 --- a/plugins/qmakemanager/parser/tests/lexertest.h +++ b/plugins/qmakemanager/parser/tests/lexertest.h @@ -1,48 +1,46 @@ /* KDevelop * * Copyright 2007 Andreas Pakulat * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #ifndef LEXERTEST_H #define LEXERTEST_H #include #include class LexerTest : public QObject { Q_OBJECT public: explicit LexerTest( QObject* parent = nullptr ); ~LexerTest() override; private Q_SLOTS: - void init(); - void cleanup(); void varAssignment(); void varAssignment_data(); void operators(); void operators_data(); void scope(); void scope_data(); void functions(); void functions_data(); }; #endif