From b045705115e451666f0ce80afa1ddeac1bcee1f1 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 29 Nov 2017 18:18:42 +0100 Subject: [PATCH] UnitTests: Cleanup SymbolQuery test Change-Id: Ieb4fe43c7b5cd27cc270f3c5d269c2d4812a0131 Reviewed-by: Nikolai Kosjar --- src/plugins/clangrefactoring/symbolquery.h | 4 +- .../clangrefactoring/symbolqueryinterface.h | 4 +- tests/unit/unittest/mocksymbolquery.h | 4 +- tests/unit/unittest/sourcerange-test.cpp | 4 +- tests/unit/unittest/symbolquery-test.cpp | 51 ++++++------------- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h index 7a6a7ecf9ee..9286ca30bb2 100644 --- a/src/plugins/clangrefactoring/symbolquery.h +++ b/src/plugins/clangrefactoring/symbolquery.h @@ -46,7 +46,7 @@ public: : m_statementFactory(statementFactory) {} - SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) override + SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const override { ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation; @@ -58,7 +58,7 @@ public: utf8Column); } - CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) override + CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const override { ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation; diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h index 1e0ab915924..950e0c2411a 100644 --- a/src/plugins/clangrefactoring/symbolqueryinterface.h +++ b/src/plugins/clangrefactoring/symbolqueryinterface.h @@ -34,8 +34,8 @@ namespace ClangRefactoring { class SymbolQueryInterface { public: - virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) = 0; - virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) = 0; + virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0; + virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0; }; } // namespace ClangRefactoring diff --git a/tests/unit/unittest/mocksymbolquery.h b/tests/unit/unittest/mocksymbolquery.h index 5c954fd7e98..25543b2b751 100644 --- a/tests/unit/unittest/mocksymbolquery.h +++ b/tests/unit/unittest/mocksymbolquery.h @@ -32,6 +32,6 @@ class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface { public: - MOCK_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); - MOCK_METHOD3(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); + MOCK_CONST_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); + MOCK_CONST_METHOD3(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); }; diff --git a/tests/unit/unittest/sourcerange-test.cpp b/tests/unit/unittest/sourcerange-test.cpp index 3605d997fdf..32f960fd457 100644 --- a/tests/unit/unittest/sourcerange-test.cpp +++ b/tests/unit/unittest/sourcerange-test.cpp @@ -24,7 +24,7 @@ ****************************************************************************/ #include "googletest.h" -#include "documentparser-utility.h" +#include "rundocumentparse-utility.h" #include "testenvironment.h" #include @@ -84,7 +84,7 @@ struct Data { projectPart, Utf8StringVector(), documents}; - UnitTest::DocumentParser documentParser{document}; + UnitTest::RunDocumentParse _1{document}; TranslationUnit translationUnit{filePath, filePath, document.translationUnit().cxIndex(), diff --git a/tests/unit/unittest/symbolquery-test.cpp b/tests/unit/unittest/symbolquery-test.cpp index c402bd64e2f..59e64fb79a2 100644 --- a/tests/unit/unittest/symbolquery-test.cpp +++ b/tests/unit/unittest/symbolquery-test.cpp @@ -41,38 +41,19 @@ namespace { using ClangRefactoring::QuerySqliteStatementFactory; using Sqlite::Database; -using StatementFactory = QuerySqliteStatementFactory; -using Query = ClangRefactoring::SymbolQuery; +using MockStatementFactory = QuerySqliteStatementFactory; +using MockQuery = ClangRefactoring::SymbolQuery; -struct Data -{ - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - using StatementFactory = QuerySqliteStatementFactory; - using Query = ClangRefactoring::SymbolQuery; - StatementFactory statementFactory{database}; - Query query{statementFactory}; -}; +using RealQuery = ClangRefactoring::SymbolQuery; class SymbolQuery : public testing::Test { protected: - static void SetUpTestCase() + void SetUp() override { - data = std::make_unique(); - insertDataInDatabase(); - } - - static void TearDownTestCase() - { - data.reset(); - } - - static void insertDataInDatabase() - { - auto &database = data->database; database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\", 1)"); database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)"); database.execute("INSERT INTO directories VALUES (1, \"/path/to\")"); @@ -82,28 +63,28 @@ protected: } protected: - static std::unique_ptr data; + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; + RealStatementFactory realStatementFactory{database}; + RealQuery realQuery{realStatementFactory}; NiceMock mockDatabase; - StatementFactory statementFactory{mockDatabase}; - MockSqliteReadStatement &selectLocationsForSymbolLocation = statementFactory.selectLocationsForSymbolLocation; - MockSqliteReadStatement &selectSourceUsagesForSymbolLocation = statementFactory.selectSourceUsagesForSymbolLocation; + MockStatementFactory mockStatementFactory{mockDatabase}; + MockSqliteReadStatement &selectLocationsForSymbolLocation = mockStatementFactory.selectLocationsForSymbolLocation; + MockSqliteReadStatement &selectSourceUsagesForSymbolLocation = mockStatementFactory.selectSourceUsagesForSymbolLocation; SourceLocations locations{{{1, 1}, 1, 1}, {{1, 1}, 2, 3}, {{1, 2}, 1, 1}, {{1, 2}, 3, 1}, {{1, 4}, 1, 1}, {{1, 4}, 1, 3}}; - Query query{statementFactory}; - Data::Query &realQuery = data->query; + MockQuery mockQuery{mockStatementFactory}; }; -std::unique_ptr SymbolQuery::data; - TEST_F(SymbolQuery, LocationsAtCallsValues) { EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7)); - query.locationsAt({1, 42}, 14, 7); + mockQuery.locationsAt({1, 42}, 14, 7); } TEST_F(SymbolQuery, LocationsAt) @@ -119,7 +100,7 @@ TEST_F(SymbolQuery, SourceUsagesAtCallsValues) { EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7)); - query.sourceUsagesAt({1, 42}, 14, 7); + mockQuery.sourceUsagesAt({1, 42}, 14, 7); } TEST_F(SymbolQuery, SourceUsagesAt)