File indexing completed on 2024-05-19 15:45:00
0001 /* 0002 SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "test_duchainutils.h" 0008 0009 #include <language/duchain/duchainlock.h> 0010 #include <tests/testcore.h> 0011 #include <tests/autotestshell.h> 0012 #include <tests/testfile.h> 0013 #include <tests/testhelpers.h> 0014 0015 #include "../duchain/duchainutils.h" 0016 0017 #include <QLoggingCategory> 0018 #include <QTest> 0019 0020 using namespace KDevelop; 0021 0022 QTEST_GUILESS_MAIN(TestDUChainUtils) 0023 0024 void TestDUChainUtils::initTestCase() 0025 { 0026 QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevelop.plugins.clang.debug=true\n")); 0027 AutoTestShell::init(); 0028 TestCore::initialize(Core::NoUi); 0029 } 0030 0031 void TestDUChainUtils::cleanupTestCase() 0032 { 0033 TestCore::shutdown(); 0034 } 0035 0036 void TestDUChainUtils::getFunctionSignatureRange() 0037 { 0038 QFETCH(QString, code); 0039 QFETCH(KTextEditor::Range, expectedRange); 0040 { 0041 TestFile file(code, QStringLiteral("cpp")); 0042 file.parse(); 0043 QVERIFY(file.waitForParsed()); 0044 0045 DUChainReadLocker lock; 0046 QVERIFY(file.topContext()); 0047 0048 const auto functionDecl = file.topContext()->localDeclarations()[0]; 0049 const auto range = ClangIntegration::DUChainUtils::functionSignatureRange(functionDecl); 0050 QCOMPARE(range, expectedRange); 0051 } 0052 } 0053 0054 void TestDUChainUtils::getFunctionSignatureRange_data() 0055 { 0056 QTest::addColumn<QString>("code"); 0057 QTest::addColumn<KTextEditor::Range>("expectedRange"); 0058 0059 QTest::newRow("function-declaration") 0060 << "void func(\nint a, int b\n);\n" 0061 << KTextEditor::Range(0, 0, 2, 1); 0062 QTest::newRow("function-definition") 0063 << "void func(\nint a, int b\n) {}\n" 0064 << KTextEditor::Range(0, 0, 2, 2); 0065 0066 } 0067 0068 #include "moc_test_duchainutils.cpp"