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)
|
: 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;
|
ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
utf8Column);
|
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;
|
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ namespace ClangRefactoring {
|
|||||||
class SymbolQueryInterface
|
class SymbolQueryInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual SourceLocations locationsAt(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) = 0;
|
virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangRefactoring
|
} // namespace ClangRefactoring
|
||||||
|
|||||||
@@ -32,6 +32,6 @@
|
|||||||
class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface
|
class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column));
|
MOCK_CONST_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(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
#include "documentparser-utility.h"
|
#include "rundocumentparse-utility.h"
|
||||||
#include "testenvironment.h"
|
#include "testenvironment.h"
|
||||||
|
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
@@ -84,7 +84,7 @@ struct Data {
|
|||||||
projectPart,
|
projectPart,
|
||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
documents};
|
documents};
|
||||||
UnitTest::DocumentParser documentParser{document};
|
UnitTest::RunDocumentParse _1{document};
|
||||||
TranslationUnit translationUnit{filePath,
|
TranslationUnit translationUnit{filePath,
|
||||||
filePath,
|
filePath,
|
||||||
document.translationUnit().cxIndex(),
|
document.translationUnit().cxIndex(),
|
||||||
|
|||||||
@@ -41,38 +41,19 @@ namespace {
|
|||||||
using ClangRefactoring::QuerySqliteStatementFactory;
|
using ClangRefactoring::QuerySqliteStatementFactory;
|
||||||
using Sqlite::Database;
|
using Sqlite::Database;
|
||||||
|
|
||||||
using StatementFactory = QuerySqliteStatementFactory<MockSqliteDatabase,
|
using MockStatementFactory = QuerySqliteStatementFactory<MockSqliteDatabase,
|
||||||
MockSqliteReadStatement>;
|
MockSqliteReadStatement>;
|
||||||
using Query = ClangRefactoring::SymbolQuery<StatementFactory>;
|
using MockQuery = ClangRefactoring::SymbolQuery<MockStatementFactory>;
|
||||||
|
|
||||||
struct Data
|
using RealStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
||||||
{
|
|
||||||
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
|
||||||
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
|
|
||||||
using StatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
|
|
||||||
Sqlite::ReadStatement>;
|
Sqlite::ReadStatement>;
|
||||||
using Query = ClangRefactoring::SymbolQuery<StatementFactory>;
|
using RealQuery = ClangRefactoring::SymbolQuery<RealStatementFactory>;
|
||||||
StatementFactory statementFactory{database};
|
|
||||||
Query query{statementFactory};
|
|
||||||
};
|
|
||||||
|
|
||||||
class SymbolQuery : public testing::Test
|
class SymbolQuery : public testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
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 (1, 1, \"filename.h\", 1)");
|
||||||
database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)");
|
database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)");
|
||||||
database.execute("INSERT INTO directories VALUES (1, \"/path/to\")");
|
database.execute("INSERT INTO directories VALUES (1, \"/path/to\")");
|
||||||
@@ -82,28 +63,28 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
NiceMock<MockSqliteDatabase> mockDatabase;
|
||||||
StatementFactory statementFactory{mockDatabase};
|
MockStatementFactory mockStatementFactory{mockDatabase};
|
||||||
MockSqliteReadStatement &selectLocationsForSymbolLocation = statementFactory.selectLocationsForSymbolLocation;
|
MockSqliteReadStatement &selectLocationsForSymbolLocation = mockStatementFactory.selectLocationsForSymbolLocation;
|
||||||
MockSqliteReadStatement &selectSourceUsagesForSymbolLocation = statementFactory.selectSourceUsagesForSymbolLocation;
|
MockSqliteReadStatement &selectSourceUsagesForSymbolLocation = mockStatementFactory.selectSourceUsagesForSymbolLocation;
|
||||||
SourceLocations locations{{{1, 1}, 1, 1},
|
SourceLocations locations{{{1, 1}, 1, 1},
|
||||||
{{1, 1}, 2, 3},
|
{{1, 1}, 2, 3},
|
||||||
{{1, 2}, 1, 1},
|
{{1, 2}, 1, 1},
|
||||||
{{1, 2}, 3, 1},
|
{{1, 2}, 3, 1},
|
||||||
{{1, 4}, 1, 1},
|
{{1, 4}, 1, 1},
|
||||||
{{1, 4}, 1, 3}};
|
{{1, 4}, 1, 3}};
|
||||||
Query query{statementFactory};
|
MockQuery mockQuery{mockStatementFactory};
|
||||||
Data::Query &realQuery = data->query;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Data> SymbolQuery::data;
|
|
||||||
|
|
||||||
TEST_F(SymbolQuery, LocationsAtCallsValues)
|
TEST_F(SymbolQuery, LocationsAtCallsValues)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7));
|
EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7));
|
||||||
|
|
||||||
query.locationsAt({1, 42}, 14, 7);
|
mockQuery.locationsAt({1, 42}, 14, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolQuery, LocationsAt)
|
TEST_F(SymbolQuery, LocationsAt)
|
||||||
@@ -119,7 +100,7 @@ TEST_F(SymbolQuery, SourceUsagesAtCallsValues)
|
|||||||
{
|
{
|
||||||
EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7));
|
EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7));
|
||||||
|
|
||||||
query.sourceUsagesAt({1, 42}, 14, 7);
|
mockQuery.sourceUsagesAt({1, 42}, 14, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolQuery, SourceUsagesAt)
|
TEST_F(SymbolQuery, SourceUsagesAt)
|
||||||
|
|||||||
Reference in New Issue
Block a user