StatusQ: ModelSignalsSpy testing utility
This commit is contained in:
parent
8ac6c21782
commit
001e90a4c6
|
@ -17,11 +17,13 @@ add_library(StatusQTestLib
|
|||
src/TestHelpers/listmodelwrapper.h
|
||||
src/TestHelpers/modelaccessobserverproxy.cpp
|
||||
src/TestHelpers/modelaccessobserverproxy.h
|
||||
src/TestHelpers/modelsignalsspy.cpp
|
||||
src/TestHelpers/modelsignalsspy.h
|
||||
src/TestHelpers/testmodel.cpp
|
||||
src/TestHelpers/testmodel.h
|
||||
)
|
||||
|
||||
target_link_libraries(StatusQTestLib PUBLIC Qt5::Core Qt5::Quick)
|
||||
target_link_libraries(StatusQTestLib PUBLIC Qt5::Core Qt5::Quick Qt5::Test)
|
||||
target_include_directories(StatusQTestLib PUBLIC src)
|
||||
|
||||
enable_testing()
|
||||
|
@ -51,31 +53,31 @@ add_test(NAME QmlTests WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|||
###########
|
||||
|
||||
add_executable(RolesRenamingModelTest tst_RolesRenamingModel.cpp)
|
||||
target_link_libraries(RolesRenamingModelTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(RolesRenamingModelTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME RolesRenamingModelTest COMMAND RolesRenamingModelTest)
|
||||
|
||||
add_executable(LeftJoinModelTest tst_LeftJoinModel.cpp)
|
||||
target_link_libraries(LeftJoinModelTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(LeftJoinModelTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME LeftJoinModelTest COMMAND LeftJoinModelTest)
|
||||
|
||||
add_executable(SubmodelProxyModelTest tst_SubmodelProxyModel.cpp)
|
||||
target_link_libraries(SubmodelProxyModelTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(SubmodelProxyModelTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME SubmodelProxyModelTest COMMAND SubmodelProxyModelTest)
|
||||
|
||||
add_executable(AggregatorTest tst_Aggregator.cpp)
|
||||
target_link_libraries(AggregatorTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(AggregatorTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME AggregatorTest COMMAND AggregatorTest)
|
||||
|
||||
add_executable(SingleRoleAggregatorTest tst_SingleRoleAggregator.cpp)
|
||||
target_link_libraries(SingleRoleAggregatorTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(SingleRoleAggregatorTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME SingleRoleAggregatorTest COMMAND SingleRoleAggregatorTest)
|
||||
|
||||
add_executable(SumAggregatorTest tst_SumAggregator.cpp)
|
||||
target_link_libraries(SumAggregatorTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(SumAggregatorTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME SumAggregatorTest COMMAND SumAggregatorTest)
|
||||
|
||||
add_executable(ConcatModelTest tst_ConcatModel.cpp)
|
||||
target_link_libraries(ConcatModelTest PRIVATE Qt5::Test StatusQ StatusQTestLib)
|
||||
target_link_libraries(ConcatModelTest PRIVATE StatusQ StatusQTestLib)
|
||||
add_test(NAME ConcatModelTest COMMAND ConcatModelTest)
|
||||
|
||||
add_executable(WritableProxyModelTest tst_WritableProxyModel.cpp)
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#include "modelsignalsspy.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using QAIM = QAbstractItemModel;
|
||||
|
||||
void registerMetaTypes() {
|
||||
// register types to avoid warnings regarding signal params
|
||||
qRegisterMetaType<QList<QPersistentModelIndex>>();
|
||||
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
|
||||
qRegisterMetaType<Qt::Orientation>();
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
ModelSignalsSpy::ModelSignalsSpy(QAbstractItemModel* model)
|
||||
: columnsAboutToBeInsertedSpy((registerMetaTypes(), model),
|
||||
&QAIM::columnsAboutToBeInserted),
|
||||
columnsAboutToBeMovedSpy(model, &QAIM::columnsAboutToBeInserted),
|
||||
columnsAboutToBeRemovedSpy(model, &QAIM::columnsAboutToBeRemoved),
|
||||
columnsInsertedSpy(model, &QAIM::columnsInserted),
|
||||
columnsMovedSpy(model, &QAIM::columnsMoved),
|
||||
columnsRemovedSpy(model, &QAIM::columnsRemoved),
|
||||
dataChangedSpy(model, &QAIM::dataChanged),
|
||||
headerDataChangedSpy(model, &QAIM::headerDataChanged),
|
||||
layoutAboutToBeChangedSpy(model, &QAIM::layoutAboutToBeChanged),
|
||||
layoutChangedSpy(model, &QAIM::layoutChanged),
|
||||
modelAboutToBeResetSpy(model, &QAIM::modelAboutToBeReset),
|
||||
modelResetSpy(model, &QAIM::modelReset),
|
||||
rowsAboutToBeInsertedSpy(model, &QAIM::rowsAboutToBeInserted),
|
||||
rowsAboutToBeMovedSpy(model, &QAIM::rowsAboutToBeMoved),
|
||||
rowsAboutToBeRemovedSpy(model, &QAIM::rowsAboutToBeRemoved),
|
||||
rowsInsertedSpy(model, &QAIM::rowsInserted),
|
||||
rowsMovedSpy(model, &QAIM::rowsMoved),
|
||||
rowsRemovedSpy(model, &QAIM::rowsRemoved)
|
||||
{
|
||||
}
|
||||
|
||||
int ModelSignalsSpy::count() const
|
||||
{
|
||||
return columnsAboutToBeInsertedSpy.count()
|
||||
+ columnsAboutToBeMovedSpy.count()
|
||||
+ columnsAboutToBeRemovedSpy.count()
|
||||
+ columnsInsertedSpy.count()
|
||||
+ columnsMovedSpy.count()
|
||||
+ columnsRemovedSpy.count()
|
||||
+ dataChangedSpy.count()
|
||||
+ headerDataChangedSpy.count()
|
||||
+ layoutAboutToBeChangedSpy.count()
|
||||
+ layoutChangedSpy.count()
|
||||
+ modelAboutToBeResetSpy.count()
|
||||
+ modelResetSpy.count()
|
||||
+ rowsAboutToBeInsertedSpy.count()
|
||||
+ rowsAboutToBeMovedSpy.count()
|
||||
+ rowsAboutToBeRemovedSpy.count()
|
||||
+ rowsInsertedSpy.count()
|
||||
+ rowsMovedSpy.count()
|
||||
+ rowsRemovedSpy.count();
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QSignalSpy>
|
||||
|
||||
class ModelSignalsSpy
|
||||
{
|
||||
public:
|
||||
explicit ModelSignalsSpy(QAbstractItemModel* model);
|
||||
|
||||
const QSignalSpy columnsAboutToBeInsertedSpy;
|
||||
const QSignalSpy columnsAboutToBeMovedSpy;
|
||||
const QSignalSpy columnsAboutToBeRemovedSpy;
|
||||
const QSignalSpy columnsInsertedSpy;
|
||||
const QSignalSpy columnsMovedSpy;
|
||||
const QSignalSpy columnsRemovedSpy;
|
||||
const QSignalSpy dataChangedSpy;
|
||||
const QSignalSpy headerDataChangedSpy;
|
||||
const QSignalSpy layoutAboutToBeChangedSpy;
|
||||
const QSignalSpy layoutChangedSpy;
|
||||
const QSignalSpy modelAboutToBeResetSpy;
|
||||
const QSignalSpy modelResetSpy;
|
||||
const QSignalSpy rowsAboutToBeInsertedSpy;
|
||||
const QSignalSpy rowsAboutToBeMovedSpy;
|
||||
const QSignalSpy rowsAboutToBeRemovedSpy;
|
||||
const QSignalSpy rowsInsertedSpy;
|
||||
const QSignalSpy rowsMovedSpy;
|
||||
const QSignalSpy rowsRemovedSpy;
|
||||
|
||||
int count() const;
|
||||
};
|
Loading…
Reference in New Issue