feat(StatusQ/Tests): Added isNotSame(...) method for comparing models
It works similarly as isSame(...) but doesn't print warnings when mismatch is found. Thanks to that may be used conveniently whenever we expect differing models in a test.
This commit is contained in:
parent
6d502427e5
commit
1bcbb482a1
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QSignalSpy>
|
||||
|
||||
class ModelSignalsSpy
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
namespace {
|
||||
|
||||
bool isSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
||||
bool recursive)
|
||||
bool recursive, bool printWarning)
|
||||
{
|
||||
auto count1 = model1.rowCount();
|
||||
auto count2 = model2.rowCount();
|
||||
|
@ -35,11 +36,13 @@ bool isSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
|||
auto submodel2 = data2.value<QAbstractItemModel*>();
|
||||
|
||||
if (!isSame(*submodel1, *submodel2, true)) {
|
||||
qDebug() << "submodels are not the same, index:"
|
||||
if (printWarning)
|
||||
qWarning() << "submodels are not the same, index:"
|
||||
<< i << roleNames1[role];
|
||||
return false;
|
||||
}
|
||||
} else if (data1 != data2) {
|
||||
if (printWarning)
|
||||
qWarning()
|
||||
<< QString("Mismatch at row %1, role '%2'. Model 1: %3, model 2: %4")
|
||||
.arg(QString::number(i), QString(roleNames1[role]),
|
||||
|
@ -52,8 +55,29 @@ bool isSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
|||
return true;
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
bool isSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
||||
bool recursive)
|
||||
{
|
||||
return isSame(model1, model2, recursive, true);
|
||||
}
|
||||
|
||||
bool isSame(const QAbstractItemModel* model1, const QAbstractItemModel* model2,
|
||||
bool recursive)
|
||||
{
|
||||
return isSame(*model1, *model2, recursive);
|
||||
}
|
||||
|
||||
bool isNotSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
||||
bool recursive)
|
||||
{
|
||||
return !isSame(model1, model2, recursive, false);
|
||||
}
|
||||
|
||||
bool isNotSame(const QAbstractItemModel* model1, const QAbstractItemModel* model2,
|
||||
bool recursive)
|
||||
{
|
||||
return isNotSame(*model1, *model2, recursive);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,3 +7,8 @@ bool isSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
|||
bool recursive = true);
|
||||
bool isSame(const QAbstractItemModel* model1, const QAbstractItemModel* model2,
|
||||
bool recursive = true);
|
||||
|
||||
bool isNotSame(const QAbstractItemModel& model1, const QAbstractItemModel& model2,
|
||||
bool recursive = true);
|
||||
bool isNotSame(const QAbstractItemModel* model1, const QAbstractItemModel* model2,
|
||||
bool recursive = true);
|
||||
|
|
Loading…
Reference in New Issue