File indexing completed on 2024-09-15 12:02:01
0001 /* 0002 SPDX-FileCopyrightText: 2015 Aleix Pol i Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "personsproxymodeltest.h" 0008 0009 #include "fakecontactsource.h" 0010 0011 // private includes 0012 #include "personmanager_p.h" 0013 0014 // public kpeople includes 0015 #include <personpluginmanager.h> 0016 #include <personsmodel.h> 0017 #include <personssortfilterproxymodel.h> 0018 0019 #include <QSignalSpy> 0020 #include <QTest> 0021 0022 QTEST_GUILESS_MAIN(PersonsProxyModelTest) 0023 0024 using namespace KPeople; 0025 0026 void PersonsProxyModelTest::initTestCase() 0027 { 0028 QVERIFY(m_database.open()); 0029 0030 // Called before the first testfunction is executed 0031 PersonManager::instance(m_database.fileName()); 0032 m_source = new FakeContactSource(nullptr); // don't own. PersonPluginManager removes it on destruction 0033 QHash<QString, BasePersonsDataSource *> sources; 0034 sources[QStringLiteral("fakesource")] = m_source; 0035 PersonPluginManager::setDataSourcePlugins(sources); 0036 0037 m_model = new KPeople::PersonsModel(this); 0038 QSignalSpy modelInit(m_model, SIGNAL(modelInitialized(bool))); 0039 0040 QTRY_COMPARE(modelInit.count(), 1); 0041 QCOMPARE(modelInit.first().at(0).toBool(), true); 0042 } 0043 0044 void PersonsProxyModelTest::cleanupTestCase() 0045 { 0046 // Called after the last testfunction was executed 0047 m_database.close(); 0048 } 0049 0050 void PersonsProxyModelTest::testFiltering() 0051 { 0052 PersonsSortFilterProxyModel proxy; 0053 proxy.setSourceModel(m_model); 0054 0055 QCOMPARE(proxy.rowCount(), 4); 0056 0057 proxy.setRequiredProperties(QStringList() << AbstractContact::PhoneNumberProperty); 0058 0059 QCOMPARE(proxy.rowCount(), 2); 0060 0061 proxy.setRequiredProperties(QStringList() << AbstractContact::PhoneNumberProperty << KPeople::AbstractContact::PresenceProperty); 0062 0063 QCOMPARE(proxy.rowCount(), 3); 0064 } 0065 0066 #include "moc_personsproxymodeltest.cpp"