diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index 2628c0698d1..189099a421d 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -204,7 +204,7 @@ void AutoTestUnitTests::testCodeParserGTest() QVERIFY(parserSpy.wait(20000)); QVERIFY(modelUpdateSpy.wait()); - QCOMPARE(m_model->gtestNamesCount(), 6); + QCOMPARE(m_model->gtestNamesCount(), 7); QMultiMap expectedNamesAndSets; expectedNamesAndSets.insert(QStringLiteral("FactorialTest"), 3); @@ -213,6 +213,7 @@ void AutoTestUnitTests::testCodeParserGTest() expectedNamesAndSets.insert(QStringLiteral("QueueTest"), 2); expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as parameterized test expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as 'normal' test + expectedNamesAndSets.insert(QStringLiteral("NamespaceTest"), 1); QMultiMap foundNamesAndSets = m_model->gtestNamesAndSets(); QCOMPARE(expectedNamesAndSets.size(), foundNamesAndSets.size()); diff --git a/src/plugins/autotest/gtest/gtestvisitors.cpp b/src/plugins/autotest/gtest/gtestvisitors.cpp index e954018e5b4..7d5293d24d9 100644 --- a/src/plugins/autotest/gtest/gtestvisitors.cpp +++ b/src/plugins/autotest/gtest/gtestvisitors.cpp @@ -27,6 +27,7 @@ #include "gtest_utils.h" #include +#include namespace Autotest { namespace Internal { @@ -48,7 +49,15 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast) return false; CPlusPlus::LookupContext lc; - const QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol)); + QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol)); + + // get surrounding namespace(s) and strip them out + const QString namespaces = enclosingNamespaces(ast->symbol); + if (!namespaces.isEmpty()) { + QTC_CHECK(prettyName.startsWith(namespaces)); + prettyName = prettyName.mid(namespaces.length()); + } + if (!GTestUtils::isGTestMacro(prettyName)) return false; @@ -83,5 +92,20 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast) return false; } +QString GTestVisitor::enclosingNamespaces(CPlusPlus::Symbol *symbol) const +{ + QString enclosing; + if (!symbol) + return enclosing; + + CPlusPlus::Symbol *currentSymbol = symbol; + while (CPlusPlus::Namespace *ns = currentSymbol->enclosingNamespace()) { + if (ns->name()) // handle anonymous namespaces as well + enclosing.prepend(m_overview.prettyName(ns->name()).append("::")); + currentSymbol = ns; + } + return enclosing; +} + } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/gtest/gtestvisitors.h b/src/plugins/autotest/gtest/gtestvisitors.h index 5c74b6c8a0a..26015ce9433 100644 --- a/src/plugins/autotest/gtest/gtestvisitors.h +++ b/src/plugins/autotest/gtest/gtestvisitors.h @@ -63,6 +63,8 @@ public: QMap gtestFunctions() const { return m_gtestFunctions; } private: + QString enclosingNamespaces(CPlusPlus::Symbol *symbol) const; + CPlusPlus::Document::Ptr m_document; CPlusPlus::Overview m_overview; QMap m_gtestFunctions; diff --git a/src/plugins/autotest/unit_test/simple_gt/tests/gt1/further.cpp b/src/plugins/autotest/unit_test/simple_gt/tests/gt1/further.cpp index 977fda04da5..292ba12b549 100644 --- a/src/plugins/autotest/unit_test/simple_gt/tests/gt1/further.cpp +++ b/src/plugins/autotest/unit_test/simple_gt/tests/gt1/further.cpp @@ -46,3 +46,16 @@ TEST(FactorialTest, DISABLED_Fake) { EXPECT_EQ(-4, sum(-2, -2)); } + +namespace Dummy { +namespace { +namespace Internal { + +TEST(NamespaceTest, Valid) +{ + EXPECT_EQ(1, 1); +} + +} // namespace Internal +} // anon namespace +} // namespace Dummy