File indexing completed on 2024-12-15 04:02:44

0001 /*
0002  * SPDX-FileCopyrightText: 2018 Dag Andersen <danders@get2net.dk>
0003  *
0004  * This file is part of the KGantt library.
0005  * 
0006  * SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 #include "TestKGanttConstraintModel.h"
0010 
0011 #include "kganttglobal.h"
0012 #include <kganttconstraintmodel.h>
0013 
0014 
0015 using namespace KGantt;
0016 
0017 void TestKGanttConstraintModel::initTestCase()
0018 {
0019     itemModel = new QStandardItemModel(100, 100);
0020 }
0021 
0022 void TestKGanttConstraintModel::cleanupTestCase()
0023 {
0024     delete itemModel;
0025 }
0026 
0027 void TestKGanttConstraintModel::testModel()
0028 {
0029     ConstraintModel model;
0030     
0031     QCOMPARE(model.constraints().count(), 0);
0032     
0033     model.addConstraint(Constraint(QModelIndex(), QModelIndex()));
0034     QCOMPARE(model.constraints().count(), 1);
0035     
0036     model.addConstraint(Constraint(QModelIndex(), QModelIndex()));
0037     QCOMPARE(model.constraints().count(), 1);
0038     
0039     QPersistentModelIndex idx1 = itemModel->index(7, 17, QModelIndex());
0040     QPersistentModelIndex idx2 = itemModel->index(42, 17, QModelIndex());
0041     
0042     model.addConstraint(Constraint(idx1, idx2));
0043     QCOMPARE(model.constraints().count(), 2);
0044     QVERIFY(model.hasConstraint(Constraint(idx1, idx2)));
0045     
0046     QCOMPARE(model.constraintsForIndex(QModelIndex()).count(), 1);
0047     
0048     QCOMPARE(model.constraints().count(), 2);
0049     model.removeConstraint(Constraint(QModelIndex(), QModelIndex()));
0050     QCOMPARE(model.constraints().count(), 1);
0051     QVERIFY(!model.hasConstraint(Constraint(QModelIndex(), QModelIndex())));
0052     
0053     model.removeConstraint(Constraint(QModelIndex(), QModelIndex()));
0054     QCOMPARE(model.constraints().count(), 1);
0055     
0056     model.removeConstraint(Constraint(idx1, idx2));
0057     QCOMPARE(model.constraints().count(), 0);
0058     QVERIFY(!model.hasConstraint(Constraint(idx1, idx2)));
0059     
0060     model.addConstraint(Constraint(idx1, idx2));
0061     QVERIFY(model.hasConstraint(Constraint(idx1, idx2)));
0062     itemModel->removeRow(8);
0063     QVERIFY(idx2 == itemModel->index(41, 17, QModelIndex()));
0064     QVERIFY(model.hasConstraint(Constraint(idx1, idx2)));
0065     itemModel->removeRow(7);
0066     QVERIFY(!idx1.isValid());
0067     QVERIFY(idx2 == itemModel->index(40, 17, QModelIndex()));
0068     QVERIFY(model.hasConstraint(Constraint(idx1, idx2)));
0069 }
0070 
0071 QTEST_GUILESS_MAIN(TestKGanttConstraintModel)