forked from qt-creator/qt-creator
UnitTests: Cleanup SymbolQuery test
Change-Id: Ieb4fe43c7b5cd27cc270f3c5d269c2d4812a0131 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "googletest.h"
|
||||
#include "documentparser-utility.h"
|
||||
#include "rundocumentparse-utility.h"
|
||||
#include "testenvironment.h"
|
||||
|
||||
#include <clangtranslationunit.h>
|
||||
@@ -84,7 +84,7 @@ struct Data {
|
||||
projectPart,
|
||||
Utf8StringVector(),
|
||||
documents};
|
||||
UnitTest::DocumentParser documentParser{document};
|
||||
UnitTest::RunDocumentParse _1{document};
|
||||
TranslationUnit translationUnit{filePath,
|
||||
filePath,
|
||||
document.translationUnit().cxIndex(),
|
||||
|
||||
@@ -41,38 +41,19 @@ namespace {
|
||||
using ClangRefactoring::QuerySqliteStatementFactory;
|
||||
using Sqlite::Database;
|
||||
|
||||
using StatementFactory = QuerySqliteStatementFactory<MockSqliteDatabase,
|
||||
using MockStatementFactory = QuerySqliteStatementFactory<MockSqliteDatabase,
|
||||
MockSqliteReadStatement>;
|
||||
using Query = ClangRefactoring::SymbolQuery<StatementFactory>;
|
||||
using MockQuery = ClangRefactoring::SymbolQuery<MockStatementFactory>;
|
||||
|
||||
struct Data
|
||||
{
|
||||
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
||||
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
|
||||
using StatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
||||
using RealStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
||||
Sqlite::ReadStatement>;
|
||||
using Query = ClangRefactoring::SymbolQuery<StatementFactory>;
|
||||
StatementFactory statementFactory{database};
|
||||
Query query{statementFactory};
|
||||
};
|
||||
using RealQuery = ClangRefactoring::SymbolQuery<RealStatementFactory>;
|
||||
|
||||
class SymbolQuery : public testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestCase()
|
||||
void SetUp() override
|
||||
{
|
||||
data = std::make_unique<Data>();
|
||||
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> data;
|
||||
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
||||
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
|
||||
RealStatementFactory realStatementFactory{database};
|
||||
RealQuery realQuery{realStatementFactory};
|
||||
NiceMock<MockSqliteDatabase> 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<Data> 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)
|
||||
|
||||
Reference in New Issue
Block a user