File indexing completed on 2024-05-12 05:40:50
0001 /*************************************************************************** 0002 * Copyright (C) 2011 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * Rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #include <QtCore/QString> 0022 #include <QtTest/QtTest> 0023 0024 #include "data/character.h" 0025 #include "model/genericmodel.h" 0026 0027 #define COUNT_TURN 2000 0028 class FieldModelTest : public QObject 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 FieldModelTest(); 0034 0035 private Q_SLOTS: 0036 void testHeader(); 0037 void testAdd(); 0038 void testDelete(); 0039 void initTestCase(); 0040 0041 private: 0042 std::unique_ptr<GenericModel> m_model; 0043 CharacterProperty propriety; 0044 CharacterProperty propriety1; 0045 CharacterProperty propriety2; 0046 }; 0047 0048 FieldModelTest::FieldModelTest() {} 0049 void FieldModelTest::initTestCase() 0050 { 0051 QStringList list; 0052 list << "column1" 0053 << "column2"; 0054 m_model.reset(new GenericModel(list, QVector<int>(), this)); 0055 } 0056 0057 void FieldModelTest::testHeader() 0058 { 0059 QVERIFY(m_model->columnCount() == 2); 0060 auto col1= m_model->headerData(0, Qt::Horizontal, Qt::DisplayRole).toString(); 0061 auto col2= m_model->headerData(1, Qt::Horizontal, Qt::DisplayRole).toString(); 0062 0063 QVERIFY(col1 == "column1"); 0064 QVERIFY(col2 == "column2"); 0065 } 0066 void FieldModelTest::testAdd() 0067 { 0068 QSignalSpy spy(m_model.get(), &GenericModel::rowsAboutToBeInserted); 0069 QVERIFY(m_model->rowCount() == 0); 0070 m_model->addData(&propriety); 0071 QVERIFY(m_model->rowCount() == 1); 0072 m_model->addData(&propriety1); 0073 QVERIFY(m_model->rowCount() == 2); 0074 m_model->addData(&propriety2); 0075 QVERIFY(m_model->rowCount() == 3); 0076 0077 QVERIFY(spy.count() == 3); 0078 } 0079 void FieldModelTest::testDelete() 0080 { 0081 QSignalSpy spy(m_model.get(), &GenericModel::rowsAboutToBeRemoved); 0082 QVERIFY(m_model->rowCount() == 3); 0083 0084 m_model->removeData(m_model->index(0, 0)); 0085 QVERIFY(m_model->rowCount() == 2); 0086 m_model->removeData(m_model->index(0, 0)); 0087 QVERIFY(m_model->rowCount() == 1); 0088 m_model->removeData(m_model->index(0, 0)); 0089 QVERIFY(m_model->rowCount() == 0); 0090 0091 QVERIFY(spy.count() == 3); 0092 } 0093 0094 QTEST_MAIN(FieldModelTest); 0095 0096 #include "tst_fieldmodel.moc"