File indexing completed on 2024-05-12 17:08:23
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QTest> 0008 0009 #include <QDebug> 0010 #include <QFileInfo> 0011 #include <QJsonArray> 0012 #include <QJsonDocument> 0013 #include <QJsonObject> 0014 #include <QSignalSpy> 0015 0016 #include "iconmodel.h" 0017 #include "sortfiltermodel.h" 0018 0019 using namespace CuttleFish; 0020 0021 class IconModelTest : public QObject 0022 { 0023 Q_OBJECT 0024 0025 private Q_SLOTS: 0026 0027 void init() 0028 { 0029 m_iconModel = new IconModel(this); 0030 m_proxyModel = new SortFilterModel(this); 0031 m_proxyModel->setSourceModel(m_iconModel); 0032 } 0033 0034 void cleanup() 0035 { 0036 delete m_iconModel; 0037 delete m_proxyModel; 0038 } 0039 0040 void initTestCase(){}; 0041 0042 void testCategoryFilter() 0043 { 0044 const int _all = m_iconModel->rowCount(QModelIndex()); 0045 0046 m_proxyModel->setFilter("edit"); 0047 const int _edit = m_proxyModel->rowCount(QModelIndex()); 0048 0049 m_proxyModel->setCategory("actions"); 0050 const int _editactions = m_proxyModel->rowCount(QModelIndex()); 0051 0052 m_proxyModel->setCategory("all"); 0053 const int _alledit = m_proxyModel->rowCount(QModelIndex()); 0054 0055 QVERIFY(_all > _edit); 0056 QVERIFY(_all > _editactions); 0057 QVERIFY(_edit >= _editactions); 0058 QVERIFY(_alledit >= _editactions); 0059 } 0060 0061 private: // disable from here for testing just the above 0062 private: 0063 QJsonArray m_data; 0064 QJsonArray m_empty; 0065 0066 IconModel *m_iconModel; 0067 SortFilterModel *m_proxyModel; 0068 }; 0069 0070 QTEST_MAIN(IconModelTest) 0071 0072 #include "iconmodeltest.moc"