Commit d313caf0 authored by Volker Krause's avatar Volker Krause
Browse files

Replace ancient ModelTest copy by QAbstractItemModelTester

parent bfb6f6ad
Pipeline #31065 passed with stage
in 22 minutes and 12 seconds
macro(add_libkdepim_freebusymodel_unittest _name)
ecm_add_test(${_name}.cpp modeltest.cpp
ecm_add_test(${_name}.cpp
TEST_NAME ${_name}
NAME_PREFIX "libkdepim-freebusymodel-"
LINK_LIBRARIES Qt5::Test KF5::AkonadiCore KF5::CalendarUtils KF5::CalendarCore KF5::CalendarSupport
......
This diff is collapsed.
/****************************************************************************
**
** SPDX-FileCopyrightText: 2007 Trolltech ASA. All rights reserved.
**
** SPDX-License-Identifier: GPL-2.0-only
**
****************************************************************************/
//krazy:excludeall=style
#ifndef MODELTEST_H
#define MODELTEST_H
#include <QObject>
#include <QAbstractItemModel>
#include <QStack>
class ModelTest : public QObject
{
Q_OBJECT
public:
explicit ModelTest(QAbstractItemModel *model, QObject *parent = nullptr);
private Q_SLOTS:
void nonDestructiveBasicTest();
void rowCount();
void columnCount();
void hasIndex();
void index();
void parent();
void data();
protected Q_SLOTS:
void runAllTests();
void layoutAboutToBeChanged();
void layoutChanged();
void modelAboutToBeReset();
void modelReset();
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
void rowsInserted(const QModelIndex &parent, int start, int end);
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void rowsRemoved(const QModelIndex &parent, int start, int end);
void rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int);
void rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int);
private:
void checkChildren(const QModelIndex &parent, int currentDepth = 0);
QAbstractItemModel *model = nullptr;
struct Changing {
QModelIndex parent;
int oldSize;
QVariant last;
QVariant next;
};
QStack<Changing> insert;
QStack<Changing> remove;
bool fetchingMore = false;
QList<QPersistentModelIndex> changing;
};
#endif
......@@ -6,12 +6,12 @@
*/
#include "testfreebusyitemmodel.h"
#include "modeltest.h"
#include "../freebusyitemmodel.h"
#include "../freebusyitem.h"
#include <KCalendarCore/Attendee>
#include <QAbstractItemModelTester>
#include <QTest>
using namespace CalendarSupport;
......@@ -23,7 +23,7 @@ QTEST_GUILESS_MAIN(FreeBusyItemModelTest)
void FreeBusyItemModelTest::testModelValidity()
{
FreeBusyItemModel *model = new FreeBusyItemModel(this);
new ModelTest(model, this);
new QAbstractItemModelTester(model, this);
QVERIFY(model->rowCount() == 0);
......@@ -76,7 +76,7 @@ void FreeBusyItemModelTest::testModelValidity()
void FreeBusyItemModelTest::testModelValidity2()
{
FreeBusyItemModel *model = new FreeBusyItemModel(this);
new ModelTest(model, this);
new QAbstractItemModelTester(model, this);
const QDateTime dt1(QDate(2010, 7, 24), QTime(7, 0, 0), Qt::UTC);
const QDateTime dt2(QDate(2010, 7, 24), QTime(10, 0, 0), Qt::UTC);
......@@ -199,7 +199,7 @@ void FreeBusyItemModelTest::testModelValidity2()
void FreeBusyItemModelTest::testInsertFreeBusy()
{
FreeBusyItemModel *model = new FreeBusyItemModel(this);
new ModelTest(model, this);
new QAbstractItemModelTester(model, this);
const QDateTime dt1(QDate(2010, 7, 24), QTime(7, 0, 0), Qt::UTC);
const QDateTime dt2(QDate(2010, 7, 24), QTime(10, 0, 0), Qt::UTC);
......
......@@ -6,12 +6,12 @@
*/
#include "testfreeperiodmodel.h"
#include "modeltest.h"
#include "../freeperiodmodel.h"
#include <KCalendarCore/Period>
#include <KCalendarCore/Duration>
#include <QAbstractItemModelTester>
#include <QTest>
using namespace CalendarSupport;
......@@ -23,7 +23,7 @@ QTEST_GUILESS_MAIN(FreePeriodModelTest)
void FreePeriodModelTest::testModelValidity()
{
FreePeriodModel *model = new FreePeriodModel(this);
new ModelTest(model, this);
new QAbstractItemModelTester(model, this);
const QDateTime dt1(QDate(2010, 7, 24), QTime(7, 0, 0), Qt::UTC);
const QDateTime dt2(QDate(2010, 7, 24), QTime(10, 0, 0), Qt::UTC);
......@@ -41,7 +41,7 @@ void FreePeriodModelTest::testModelValidity()
void FreePeriodModelTest::testSplitByDay()
{
FreePeriodModel *model = new FreePeriodModel(this);
new ModelTest(model, this);
new QAbstractItemModelTester(model, this);
const QDateTime startDt(QDate(2010, 7, 24), QTime(8, 0, 0), Qt::UTC);
const QDateTime endDt(QDate(2010, 7, 25), QTime(8, 0, 0), Qt::UTC);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment