forked from qt-creator/qt-creator
Sqlite: Use a more efficient update hook
Change-Id: Ic6df1f4ba6b914c7751faf7cf89083fa50a92793 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
namespace Sqlite {
|
namespace Sqlite {
|
||||||
|
|
||||||
|
template<unsigned int TableCount = 0>
|
||||||
class LastChangedRowId
|
class LastChangedRowId
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -40,86 +41,82 @@ public:
|
|||||||
: database(database)
|
: database(database)
|
||||||
|
|
||||||
{
|
{
|
||||||
callback = [=](ChangeType, char const *, char const *, long long rowId) {
|
database.setUpdateHook(this, callbackOnlyRowId);
|
||||||
this->lastRowId = rowId;
|
|
||||||
};
|
|
||||||
|
|
||||||
database.setUpdateHook(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LastChangedRowId(DatabaseInterface &database, Utils::SmallStringView databaseName)
|
LastChangedRowId(DatabaseInterface &database, Utils::SmallStringView databaseName)
|
||||||
: database(database)
|
: database(database)
|
||||||
|
, databaseName(databaseName)
|
||||||
{
|
{
|
||||||
callback = [=](ChangeType, char const *database, char const *, long long rowId) {
|
database.setUpdateHook(this, callbackWithDatabase);
|
||||||
if (databaseName == database)
|
|
||||||
this->lastRowId = rowId;
|
|
||||||
};
|
|
||||||
|
|
||||||
database.setUpdateHook(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename... Tables>
|
||||||
LastChangedRowId(DatabaseInterface &database,
|
LastChangedRowId(DatabaseInterface &database,
|
||||||
Utils::SmallStringView databaseName,
|
Utils::SmallStringView databaseName,
|
||||||
Utils::SmallStringView tableName)
|
Tables... tableNames)
|
||||||
: database(database)
|
: database(database)
|
||||||
|
, databaseName(databaseName)
|
||||||
|
, tableNames({tableNames...})
|
||||||
{
|
{
|
||||||
callback = [=](ChangeType, char const *database, char const *table, long long rowId) {
|
database.setUpdateHook(this, callbackWithTables);
|
||||||
if (databaseName == database && tableName == table)
|
|
||||||
this->lastRowId = rowId;
|
|
||||||
};
|
|
||||||
|
|
||||||
database.setUpdateHook(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
LastChangedRowId(DatabaseInterface &database,
|
|
||||||
Utils::SmallStringView databaseName,
|
|
||||||
Utils::SmallStringView tableName,
|
|
||||||
Utils::SmallStringView tableName2)
|
|
||||||
: database(database)
|
|
||||||
|
|
||||||
{
|
|
||||||
callback = [=](ChangeType, char const *database, char const *table, long long rowId) {
|
|
||||||
if (databaseName == database && (tableName == table || tableName2 == table))
|
|
||||||
this->lastRowId = rowId;
|
|
||||||
};
|
|
||||||
|
|
||||||
database.setUpdateHook(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
LastChangedRowId(DatabaseInterface &database,
|
|
||||||
Utils::SmallStringView databaseName,
|
|
||||||
Utils::SmallStringView tableName,
|
|
||||||
Utils::SmallStringView tableName2,
|
|
||||||
Utils::SmallStringView tableName3)
|
|
||||||
: database(database)
|
|
||||||
|
|
||||||
{
|
|
||||||
callback = [=](ChangeType, char const *database, char const *table, long long rowId) {
|
|
||||||
if (databaseName == database
|
|
||||||
&& (tableName == table || tableName2 == table || tableName3 == table))
|
|
||||||
this->lastRowId = rowId;
|
|
||||||
};
|
|
||||||
|
|
||||||
database.setUpdateHook(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~LastChangedRowId() { database.resetUpdateHook(); }
|
~LastChangedRowId() { database.resetUpdateHook(); }
|
||||||
|
|
||||||
long long takeLastRowId()
|
void operator()(long long rowId) { lastRowId = rowId; }
|
||||||
|
|
||||||
|
static void callbackOnlyRowId(void *object, int, char const *, char const *, long long rowId)
|
||||||
{
|
{
|
||||||
long long rowId = lastRowId;
|
(*static_cast<LastChangedRowId *>(object))(rowId);
|
||||||
lastRowId = -1;
|
|
||||||
return rowId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lastRowIdIsValid() { return lastRowId >= 0; }
|
bool containsTable(Utils::SmallStringView table)
|
||||||
|
{
|
||||||
|
return std::find(tableNames.begin(), tableNames.end(), table) != tableNames.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()(Utils::SmallStringView database, long long rowId)
|
||||||
|
{
|
||||||
|
if (databaseName == database)
|
||||||
|
lastRowId = rowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void callbackWithDatabase(
|
||||||
|
void *object, int, char const *database, char const *, long long rowId)
|
||||||
|
{
|
||||||
|
(*static_cast<LastChangedRowId *>(object))(Utils::SmallStringView{database}, rowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()(Utils::SmallStringView database, Utils::SmallStringView table, long long rowId)
|
||||||
|
{
|
||||||
|
if (databaseName == database && containsTable(table))
|
||||||
|
lastRowId = rowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void callbackWithTables(
|
||||||
|
void *object, int, char const *database, char const *table, long long rowId)
|
||||||
|
{
|
||||||
|
(*static_cast<LastChangedRowId *>(
|
||||||
|
object))(Utils::SmallStringView{database}, Utils::SmallStringView{table}, rowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
long long takeLastRowId()
|
||||||
|
{
|
||||||
|
long long lastId = lastRowId;
|
||||||
|
|
||||||
|
lastRowId = -1;
|
||||||
|
|
||||||
|
return lastId;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lastRowIdIsValid() const { return lastRowId >= 0; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DatabaseInterface &database;
|
DatabaseInterface &database;
|
||||||
DatabaseInterface::UpdateCallback callback;
|
|
||||||
long long lastRowId = -1;
|
long long lastRowId = -1;
|
||||||
|
Utils::SmallStringView databaseName;
|
||||||
|
std::array<Utils::SmallStringView, TableCount> tableNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Sqlite
|
} // namespace Sqlite
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public:
|
|||||||
void setOpenMode(OpenMode openMode);
|
void setOpenMode(OpenMode openMode);
|
||||||
OpenMode openMode() const;
|
OpenMode openMode() const;
|
||||||
|
|
||||||
void execute(Utils::SmallStringView sqlStatement);
|
void execute(Utils::SmallStringView sqlStatement) override;
|
||||||
|
|
||||||
DatabaseBackend &backend();
|
DatabaseBackend &backend();
|
||||||
|
|
||||||
@@ -116,15 +116,20 @@ public:
|
|||||||
m_databaseBackend.walCheckpointFull();
|
m_databaseBackend.walCheckpointFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUpdateHook(DatabaseBackend::UpdateCallback &callback)
|
void setUpdateHook(void *object,
|
||||||
|
void (*callback)(void *object,
|
||||||
|
int,
|
||||||
|
char const *database,
|
||||||
|
char const *,
|
||||||
|
long long rowId)) override
|
||||||
{
|
{
|
||||||
m_databaseBackend.setUpdateHook(callback);
|
m_databaseBackend.setUpdateHook(object, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetUpdateHook() { m_databaseBackend.resetUpdateHook(); }
|
void resetUpdateHook() override { m_databaseBackend.resetUpdateHook(); }
|
||||||
|
|
||||||
void setAttachedTables(const Utils::SmallStringVector &tables);
|
void setAttachedTables(const Utils::SmallStringVector &tables) override;
|
||||||
void applyAndUpdateSessions();
|
void applyAndUpdateSessions() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void deferredBegin() override;
|
void deferredBegin() override;
|
||||||
|
|||||||
@@ -400,22 +400,11 @@ void DatabaseBackend::walCheckpointFull()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
void DatabaseBackend::setUpdateHook(
|
||||||
void updateCallback(
|
void *object,
|
||||||
void *callback, int type, char const *database, char const *table, sqlite3_int64 row)
|
void (*callback)(void *object, int, char const *database, char const *, long long rowId))
|
||||||
{
|
{
|
||||||
auto &function = *reinterpret_cast<DatabaseBackend::UpdateCallback *>(callback);
|
sqlite3_update_hook(m_databaseHandle, callback, object);
|
||||||
|
|
||||||
function(static_cast<ChangeType>(type), database, table, row);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void DatabaseBackend::setUpdateHook(UpdateCallback &callback)
|
|
||||||
{
|
|
||||||
if (callback)
|
|
||||||
sqlite3_update_hook(m_databaseHandle, updateCallback, &callback);
|
|
||||||
else
|
|
||||||
sqlite3_update_hook(m_databaseHandle, nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseBackend::resetUpdateHook()
|
void DatabaseBackend::resetUpdateHook()
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ public:
|
|||||||
|
|
||||||
void walCheckpointFull();
|
void walCheckpointFull();
|
||||||
|
|
||||||
void setUpdateHook(UpdateCallback &callback);
|
void setUpdateHook(
|
||||||
|
void *object,
|
||||||
|
void (*callback)(void *object, int, char const *database, char const *, long long rowId));
|
||||||
void resetUpdateHook();
|
void resetUpdateHook();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ public:
|
|||||||
|
|
||||||
virtual void walCheckpointFull() = 0;
|
virtual void walCheckpointFull() = 0;
|
||||||
virtual void execute(Utils::SmallStringView sqlStatement) = 0;
|
virtual void execute(Utils::SmallStringView sqlStatement) = 0;
|
||||||
virtual void setUpdateHook(UpdateCallback &callback) = 0;
|
virtual void setUpdateHook(
|
||||||
|
void *object,
|
||||||
|
void (*)(void *object, int, char const *database, char const *, long long rowId))
|
||||||
|
= 0;
|
||||||
virtual void resetUpdateHook() = 0;
|
virtual void resetUpdateHook() = 0;
|
||||||
virtual void applyAndUpdateSessions() = 0;
|
virtual void applyAndUpdateSessions() = 0;
|
||||||
virtual void setAttachedTables(const Utils::SmallStringVector &tables) = 0;
|
virtual void setAttachedTables(const Utils::SmallStringVector &tables) = 0;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ HEADERS += \
|
|||||||
$$PWD/clangqueryhighlighter.h \
|
$$PWD/clangqueryhighlighter.h \
|
||||||
$$PWD/clangqueryhighlightmarker.h \
|
$$PWD/clangqueryhighlightmarker.h \
|
||||||
$$PWD/clangqueryprojectsfindfilter.h \
|
$$PWD/clangqueryprojectsfindfilter.h \
|
||||||
|
$$PWD/clangsymbolsfindfilter.h \
|
||||||
$$PWD/projectpartutilities.h \
|
$$PWD/projectpartutilities.h \
|
||||||
$$PWD/refactoringclient.h \
|
$$PWD/refactoringclient.h \
|
||||||
$$PWD/refactoringconnectionclient.h \
|
$$PWD/refactoringconnectionclient.h \
|
||||||
@@ -13,7 +14,6 @@ HEADERS += \
|
|||||||
$$PWD/refactoringprojectupdater.h \
|
$$PWD/refactoringprojectupdater.h \
|
||||||
$$PWD/searchinterface.h \
|
$$PWD/searchinterface.h \
|
||||||
$$PWD/searchhandle.h \
|
$$PWD/searchhandle.h \
|
||||||
$$PWD/symbolsfindfilter.h \
|
|
||||||
$$PWD/symbolqueryinterface.h \
|
$$PWD/symbolqueryinterface.h \
|
||||||
$$PWD/symbol.h \
|
$$PWD/symbol.h \
|
||||||
$$PWD/projectpartproviderinterface.h \
|
$$PWD/projectpartproviderinterface.h \
|
||||||
@@ -24,11 +24,11 @@ SOURCES += \
|
|||||||
$$PWD/clangqueryexamplehighlighter.cpp \
|
$$PWD/clangqueryexamplehighlighter.cpp \
|
||||||
$$PWD/clangqueryhighlighter.cpp \
|
$$PWD/clangqueryhighlighter.cpp \
|
||||||
$$PWD/clangqueryprojectsfindfilter.cpp \
|
$$PWD/clangqueryprojectsfindfilter.cpp \
|
||||||
|
$$PWD/clangsymbolsfindfilter.cpp \
|
||||||
$$PWD/projectpartutilities.cpp \
|
$$PWD/projectpartutilities.cpp \
|
||||||
$$PWD/refactoringclient.cpp \
|
$$PWD/refactoringclient.cpp \
|
||||||
$$PWD/refactoringconnectionclient.cpp \
|
$$PWD/refactoringconnectionclient.cpp \
|
||||||
$$PWD/refactoringengine.cpp \
|
$$PWD/refactoringengine.cpp \
|
||||||
$$PWD/refactoringprojectupdater.cpp \
|
$$PWD/refactoringprojectupdater.cpp \
|
||||||
$$PWD/searchhandle.cpp \
|
$$PWD/searchhandle.cpp \
|
||||||
$$PWD/symbolsfindfilter.cpp \
|
|
||||||
$$PWD/locatorfilter.cpp
|
$$PWD/locatorfilter.cpp
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "symbolsfindfilter.h"
|
#include "clangsymbolsfindfilter.h"
|
||||||
|
|
||||||
#include <cpptools/cpptoolsconstants.h>
|
#include <cpptools/cpptoolsconstants.h>
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "symbolsfindfilter.h"
|
#include "clangsymbolsfindfilter.h"
|
||||||
|
|
||||||
namespace ClangRefactoring {
|
namespace ClangRefactoring {
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include "symbolsfindfilterconfigwidget.h"
|
#include "symbolsfindfilterconfigwidget.h"
|
||||||
|
|
||||||
#include "symbolsfindfilter.h"
|
#include "clangsymbolsfindfilter.h"
|
||||||
|
|
||||||
namespace ClangRefactoring {
|
namespace ClangRefactoring {
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ include($$PWD/../../../src/plugins/clangpchmanager/clangpchmanager-source.pri)
|
|||||||
include($$PWD/../../../src/plugins/cpptools/cpptoolsunittestfiles.pri)
|
include($$PWD/../../../src/plugins/cpptools/cpptoolsunittestfiles.pri)
|
||||||
include($$PWD/../../../src/plugins/debugger/debuggerunittestfiles.pri)
|
include($$PWD/../../../src/plugins/debugger/debuggerunittestfiles.pri)
|
||||||
include($$PWD/../../../src/plugins/compilationdatabaseprojectmanager/compilationdatabaseunittestfiles.pri)
|
include($$PWD/../../../src/plugins/compilationdatabaseprojectmanager/compilationdatabaseunittestfiles.pri)
|
||||||
include(cplusplus.pri)
|
!isEmpty(QTC_UNITTEST_BUILD_CPP_PARSER):include(cplusplus.pri)
|
||||||
!isEmpty(LLVM_VERSION) {
|
!isEmpty(LLVM_VERSION) {
|
||||||
include($$PWD/../../../src/plugins/clangtools/clangtoolsunittestfiles.pri)
|
include($$PWD/../../../src/plugins/clangtools/clangtoolsunittestfiles.pri)
|
||||||
include($$PWD/../../../src/shared/clang/clang_defines.pri)
|
include($$PWD/../../../src/shared/clang/clang_defines.pri)
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ class LastChangedRowId : public testing::Test
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"};
|
Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LastChangedRowId, SetUpdateHookInContructor)
|
TEST_F(LastChangedRowId, SetUpdateHookInContructor)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_));
|
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _));
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"};
|
Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowId, ResetUpdateHookInDestructor)
|
TEST_F(LastChangedRowId, ResetUpdateHookInDestructor)
|
||||||
@@ -57,42 +57,42 @@ TEST_F(LastChangedRowId, GetMinusOneAsRowIdIfNoCallbackWasCalled)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowId, CallbackSetsLastRowId)
|
TEST_F(LastChangedRowId, CallbackSetsLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowId, CallbackChecksDatabaseName)
|
TEST_F(LastChangedRowId, CallbackChecksDatabaseName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42);
|
lastRowId("temp", "foo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowId, CallbackChecksTableName)
|
TEST_F(LastChangedRowId, CallbackChecksTableName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42);
|
lastRowId("main", "bar", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowId, LastCallSetsRowId)
|
TEST_F(LastChangedRowId, LastCallSetsRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
lastRowId.callback(Sqlite::ChangeType::Insert, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Delete, "main", "foo", 66);
|
lastRowId("main", "foo", 66);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 66);
|
ASSERT_THAT(lastRowId.lastRowId, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowId, TakeLastRowId)
|
TEST_F(LastChangedRowId, TakeLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ TEST_F(LastChangedRowId, TakeLastRowId)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowId, TakeLastRowIdResetsRowIdToMinusOne)
|
TEST_F(LastChangedRowId, TakeLastRowIdResetsRowIdToMinusOne)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
lastRowId.takeLastRowId();
|
lastRowId.takeLastRowId();
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
@@ -114,14 +114,14 @@ class LastChangedRowIdWithTwoTables : public testing::Test
|
|||||||
protected:
|
protected:
|
||||||
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo", "bar"};
|
Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, SetUpdateHookInContructor)
|
TEST_F(LastChangedRowIdWithTwoTables, SetUpdateHookInContructor)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_));
|
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _));
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"};
|
Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, ResetUpdateHookInDestructor)
|
TEST_F(LastChangedRowIdWithTwoTables, ResetUpdateHookInDestructor)
|
||||||
@@ -136,48 +136,48 @@ TEST_F(LastChangedRowIdWithTwoTables, GetMinusOneAsRowIdIfNoCallbackWasCalled)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdFirstTable)
|
TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdFirstTable)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdSecondTable)
|
TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdSecondTable)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 66);
|
lastRowId("main", "bar", 66);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 66);
|
ASSERT_THAT(lastRowId.lastRowId, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksDatabaseName)
|
TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksDatabaseName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42);
|
lastRowId("temp", "foo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksTableName)
|
TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksTableName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "zoo", 42);
|
lastRowId("main", "zoo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, LastCallSetsRowId)
|
TEST_F(LastChangedRowIdWithTwoTables, LastCallSetsRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Delete, "main", "bar", 66);
|
lastRowId("main", "bar", 66);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 66);
|
ASSERT_THAT(lastRowId.lastRowId, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowId)
|
TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowId)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowIdResetsRowIdToMinusOne)
|
TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowIdResetsRowIdToMinusOne)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
lastRowId.takeLastRowId();
|
lastRowId.takeLastRowId();
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
@@ -199,14 +199,14 @@ class LastChangedRowIdWithThreeTables : public testing::Test
|
|||||||
protected:
|
protected:
|
||||||
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"};
|
Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, SetUpdateHookInContructor)
|
TEST_F(LastChangedRowIdWithThreeTables, SetUpdateHookInContructor)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_));
|
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _));
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"};
|
Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, ResetUpdateHookInDestructor)
|
TEST_F(LastChangedRowIdWithThreeTables, ResetUpdateHookInDestructor)
|
||||||
@@ -221,56 +221,56 @@ TEST_F(LastChangedRowIdWithThreeTables, GetMinusOneAsRowIdIfNoCallbackWasCalled)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdFirstTable)
|
TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdFirstTable)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdSecondTable)
|
TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdSecondTable)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42);
|
lastRowId("main", "bar", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdThirdTable)
|
TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdThirdTable)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "too", 42);
|
lastRowId("main", "too", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksDatabaseName)
|
TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksDatabaseName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42);
|
lastRowId("temp", "foo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksTableName)
|
TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksTableName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", "foo", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "zoo", 42);
|
lastRowId("main", "zoo", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, LastCallSetsRowId)
|
TEST_F(LastChangedRowIdWithThreeTables, LastCallSetsRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42);
|
lastRowId("main", "bar", 42);
|
||||||
lastRowId.callback(Sqlite::ChangeType::Insert, "main", "too", 33);
|
lastRowId("main", "too", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Delete, "main", "too", 66);
|
lastRowId("main", "too", 66);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 66);
|
ASSERT_THAT(lastRowId.lastRowId, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowId)
|
TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowId)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowIdResetsRowIdToMinusOne)
|
TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowIdResetsRowIdToMinusOne)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", "foo", 42);
|
||||||
lastRowId.takeLastRowId();
|
lastRowId.takeLastRowId();
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
@@ -291,14 +291,14 @@ class LastChangedRowIdWithNoDatabaseAndTable : public testing::Test
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase};
|
Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, SetUpdateHookInContructor)
|
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, SetUpdateHookInContructor)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_));
|
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _));
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"};
|
Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, ResetUpdateHookInDestructor)
|
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, ResetUpdateHookInDestructor)
|
||||||
@@ -313,42 +313,24 @@ TEST_F(LastChangedRowIdWithNoDatabaseAndTable, GetMinusOneAsRowIdIfNoCallbackWas
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackSetsLastRowId)
|
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackSetsLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId(42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackDoNotChecksDatabaseName)
|
|
||||||
{
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42);
|
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackDoNotChecksTableName)
|
|
||||||
{
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42);
|
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, LastCallSetsRowId)
|
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, LastCallSetsRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId(42);
|
||||||
lastRowId.callback(Sqlite::ChangeType::Insert, "main", "foo", 33);
|
lastRowId(33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Delete, "main", "foo", 66);
|
lastRowId(66);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 66);
|
ASSERT_THAT(lastRowId.lastRowId, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowId)
|
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId(42);
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
|
|
||||||
@@ -357,7 +339,7 @@ TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowId)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowIdResetsRowIdToMinusOne)
|
TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowIdResetsRowIdToMinusOne)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId(42);
|
||||||
lastRowId.takeLastRowId();
|
lastRowId.takeLastRowId();
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
@@ -369,14 +351,14 @@ class LastChangedRowIdWithNoTable : public testing::Test
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main"};
|
Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, SetUpdateHookInContructor)
|
TEST_F(LastChangedRowIdWithNoTable, SetUpdateHookInContructor)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_));
|
EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _));
|
||||||
|
|
||||||
Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"};
|
Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, ResetUpdateHookInDestructor)
|
TEST_F(LastChangedRowIdWithNoTable, ResetUpdateHookInDestructor)
|
||||||
@@ -391,42 +373,33 @@ TEST_F(LastChangedRowIdWithNoTable, GetMinusOneAsRowIdIfNoCallbackWasCalled)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, CallbackSetsLastRowId)
|
TEST_F(LastChangedRowIdWithNoTable, CallbackSetsLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
ASSERT_THAT(lastRowId.lastRowId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, CallbackChecksDatabaseName)
|
TEST_F(LastChangedRowIdWithNoTable, CallbackChecksDatabaseName)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
lastRowId("main", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42);
|
lastRowId("temp", 42);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 33);
|
ASSERT_THAT(lastRowId.lastRowId, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, CallbackDoNotChecksTableName)
|
|
||||||
{
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33);
|
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42);
|
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 42);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, LastCallSetsRowId)
|
TEST_F(LastChangedRowIdWithNoTable, LastCallSetsRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", 42);
|
||||||
lastRowId.callback(Sqlite::ChangeType::Insert, "main", "foo", 33);
|
lastRowId("main", 33);
|
||||||
|
|
||||||
lastRowId.callback(Sqlite::ChangeType::Delete, "main", "foo", 66);
|
lastRowId("main", 66);
|
||||||
|
|
||||||
ASSERT_THAT(lastRowId.lastRowId, 66);
|
ASSERT_THAT(lastRowId.lastRowId, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, TakeLastRowId)
|
TEST_F(LastChangedRowIdWithNoTable, TakeLastRowId)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", 42);
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
|
|
||||||
@@ -435,7 +408,7 @@ TEST_F(LastChangedRowIdWithNoTable, TakeLastRowId)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, TakeLastRowIdResetsRowIdToMinusOne)
|
TEST_F(LastChangedRowIdWithNoTable, TakeLastRowIdResetsRowIdToMinusOne)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42);
|
lastRowId("main", 42);
|
||||||
lastRowId.takeLastRowId();
|
lastRowId.takeLastRowId();
|
||||||
|
|
||||||
auto id = lastRowId.takeLastRowId();
|
auto id = lastRowId.takeLastRowId();
|
||||||
@@ -452,7 +425,7 @@ TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsNotValidForNegativeValues)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull)
|
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 0);
|
lastRowId("main", 0);
|
||||||
|
|
||||||
auto isValid = lastRowId.lastRowIdIsValid();
|
auto isValid = lastRowId.lastRowIdIsValid();
|
||||||
|
|
||||||
@@ -461,7 +434,7 @@ TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull)
|
|||||||
|
|
||||||
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForPositiveValues)
|
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForPositiveValues)
|
||||||
{
|
{
|
||||||
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 777);
|
lastRowId("main", 777);
|
||||||
|
|
||||||
auto isValid = lastRowId.lastRowIdIsValid();
|
auto isValid = lastRowId.lastRowIdIsValid();
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ public:
|
|||||||
|
|
||||||
MOCK_METHOD0(walCheckpointFull, void());
|
MOCK_METHOD0(walCheckpointFull, void());
|
||||||
|
|
||||||
MOCK_METHOD1(setUpdateHook, void(Sqlite::DatabaseInterface::UpdateCallback &));
|
MOCK_METHOD2(setUpdateHook,
|
||||||
|
void(void *object,
|
||||||
|
void (*)(void *object, int, char const *database, char const *, long long rowId)));
|
||||||
|
|
||||||
MOCK_METHOD0(resetUpdateHook, void());
|
MOCK_METHOD0(resetUpdateHook, void());
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ protected:
|
|||||||
return Sqlite::ReadStatement("SELECT name FROM test", database).values<Utils::SmallString>(8);
|
return Sqlite::ReadStatement("SELECT name FROM test", database).values<Utils::SmallString>(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void updateHookCallback(
|
||||||
|
void *object, int type, char const *database, char const *table, long long rowId)
|
||||||
|
{
|
||||||
|
static_cast<SqliteDatabase *>(object)->callback(static_cast<Sqlite::ChangeType>(type),
|
||||||
|
database,
|
||||||
|
table,
|
||||||
|
rowId);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SpyDummy spyDummy;
|
SpyDummy spyDummy;
|
||||||
QString databaseFilePath{":memory:"};
|
QString databaseFilePath{":memory:"};
|
||||||
@@ -232,7 +241,7 @@ TEST_F(SqliteDatabase, Rollback)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, SetUpdateHookSet)
|
TEST_F(SqliteDatabase, SetUpdateHookSet)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(_, _, _, _));
|
EXPECT_CALL(callbackMock, Call(_, _, _, _));
|
||||||
Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42);
|
Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42);
|
||||||
@@ -240,10 +249,10 @@ TEST_F(SqliteDatabase, SetUpdateHookSet)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, SetNullUpdateHook)
|
TEST_F(SqliteDatabase, SetNullUpdateHook)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
Sqlite::Database::UpdateCallback newCallback;
|
Sqlite::Database::UpdateCallback newCallback;
|
||||||
|
|
||||||
database.setUpdateHook(newCallback);
|
database.setUpdateHook(nullptr, nullptr);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(_, _, _, _)).Times(0);
|
EXPECT_CALL(callbackMock, Call(_, _, _, _)).Times(0);
|
||||||
Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42);
|
Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42);
|
||||||
@@ -251,8 +260,7 @@ TEST_F(SqliteDatabase, SetNullUpdateHook)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, ResetUpdateHook)
|
TEST_F(SqliteDatabase, ResetUpdateHook)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
Sqlite::Database::UpdateCallback newCallback;
|
|
||||||
|
|
||||||
database.resetUpdateHook();
|
database.resetUpdateHook();
|
||||||
|
|
||||||
@@ -263,7 +271,7 @@ TEST_F(SqliteDatabase, ResetUpdateHook)
|
|||||||
TEST_F(SqliteDatabase, DeleteUpdateHookCall)
|
TEST_F(SqliteDatabase, DeleteUpdateHookCall)
|
||||||
{
|
{
|
||||||
Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42);
|
Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42);
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Delete), _, _, _));
|
EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Delete), _, _, _));
|
||||||
|
|
||||||
@@ -272,7 +280,7 @@ TEST_F(SqliteDatabase, DeleteUpdateHookCall)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, InsertUpdateHookCall)
|
TEST_F(SqliteDatabase, InsertUpdateHookCall)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Insert), _, _, _));
|
EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Insert), _, _, _));
|
||||||
|
|
||||||
@@ -281,7 +289,7 @@ TEST_F(SqliteDatabase, InsertUpdateHookCall)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, UpdateUpdateHookCall)
|
TEST_F(SqliteDatabase, UpdateUpdateHookCall)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Insert), _, _, _));
|
EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Insert), _, _, _));
|
||||||
|
|
||||||
@@ -290,7 +298,7 @@ TEST_F(SqliteDatabase, UpdateUpdateHookCall)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, RowIdUpdateHookCall)
|
TEST_F(SqliteDatabase, RowIdUpdateHookCall)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(_, _, _, Eq(42)));
|
EXPECT_CALL(callbackMock, Call(_, _, _, Eq(42)));
|
||||||
|
|
||||||
@@ -299,7 +307,7 @@ TEST_F(SqliteDatabase, RowIdUpdateHookCall)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, DatabaseUpdateHookCall)
|
TEST_F(SqliteDatabase, DatabaseUpdateHookCall)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(_, StrEq("main"), _, _));
|
EXPECT_CALL(callbackMock, Call(_, StrEq("main"), _, _));
|
||||||
|
|
||||||
@@ -308,7 +316,7 @@ TEST_F(SqliteDatabase, DatabaseUpdateHookCall)
|
|||||||
|
|
||||||
TEST_F(SqliteDatabase, TableUpdateHookCall)
|
TEST_F(SqliteDatabase, TableUpdateHookCall)
|
||||||
{
|
{
|
||||||
database.setUpdateHook(callback);
|
database.setUpdateHook(this, updateHookCallback);
|
||||||
|
|
||||||
EXPECT_CALL(callbackMock, Call(_, _, StrEq("test"), _));
|
EXPECT_CALL(callbackMock, Call(_, _, StrEq("test"), _));
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
#include <clangrefactoring/symbolsfindfilter.h>
|
#include <clangrefactoring/clangsymbolsfindfilter.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
INCLUDEPATH += ../mockup
|
INCLUDEPATH += ../mockup
|
||||||
|
|
||||||
QT += core network testlib widgets
|
QT += core network testlib widgets
|
||||||
CONFIG += console c++14 testcase object_parallel_to_source
|
CONFIG += console c++14 testcase
|
||||||
CONFIG -= app_bundle shared
|
CONFIG -= app_bundle shared
|
||||||
|
|
||||||
|
QTC_UNITTEST_BUILD_CPP_PARSER = $$(QTC_UNITTEST_BUILD_CPP_PARSER)
|
||||||
|
|
||||||
include(gmock_dependency.pri)
|
include(gmock_dependency.pri)
|
||||||
include(clang_dependency.pri)
|
include(clang_dependency.pri)
|
||||||
include(creator_dependency.pri)
|
include(creator_dependency.pri)
|
||||||
@@ -11,8 +13,6 @@ include(benchmark_dependency.pri)
|
|||||||
|
|
||||||
requires(isEmpty(QTC_CLANG_BUILDMODE_MISMATCH))
|
requires(isEmpty(QTC_CLANG_BUILDMODE_MISMATCH))
|
||||||
|
|
||||||
OBJECTS_DIR = $$OUT_PWD/obj # workaround for qmake bug in object_parallel_to_source
|
|
||||||
|
|
||||||
!msvc:force_debug_info:QMAKE_CXXFLAGS += -fno-omit-frame-pointer
|
!msvc:force_debug_info:QMAKE_CXXFLAGS += -fno-omit-frame-pointer
|
||||||
|
|
||||||
DEFINES += \
|
DEFINES += \
|
||||||
@@ -66,7 +66,6 @@ SOURCES += \
|
|||||||
lastchangedrowid-test.cpp \
|
lastchangedrowid-test.cpp \
|
||||||
lineprefixer-test.cpp \
|
lineprefixer-test.cpp \
|
||||||
locatorfilter-test.cpp \
|
locatorfilter-test.cpp \
|
||||||
matchingtext-test.cpp \
|
|
||||||
mimedatabase-utilities.cpp \
|
mimedatabase-utilities.cpp \
|
||||||
pchmanagerclientserverinprocess-test.cpp \
|
pchmanagerclientserverinprocess-test.cpp \
|
||||||
pchmanagerclient-test.cpp \
|
pchmanagerclient-test.cpp \
|
||||||
@@ -133,6 +132,8 @@ SOURCES += \
|
|||||||
sqlstatementbuilder-test.cpp \
|
sqlstatementbuilder-test.cpp \
|
||||||
createtablesqlstatementbuilder-test.cpp
|
createtablesqlstatementbuilder-test.cpp
|
||||||
|
|
||||||
|
!isEmpty(QTC_UNITTEST_BUILD_CPP_PARSER):matchingtext-test.cpp
|
||||||
|
|
||||||
!isEmpty(LIBCLANG_LIBS) {
|
!isEmpty(LIBCLANG_LIBS) {
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
activationsequencecontextprocessor-test.cpp \
|
activationsequencecontextprocessor-test.cpp \
|
||||||
|
|||||||
Reference in New Issue
Block a user