File indexing completed on 2025-01-05 04:59:55
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include <testlib/qtest_zanshin.h> 0008 0009 #include "domain/datasource.h" 0010 0011 using namespace Domain; 0012 0013 class DataSourceTest : public QObject 0014 { 0015 Q_OBJECT 0016 public: 0017 explicit DataSourceTest(QObject *parent = nullptr) 0018 : QObject(parent) 0019 { 0020 qRegisterMetaType<DataSource::ContentTypes>(); 0021 } 0022 0023 private slots: 0024 void shouldHaveEmptyPropertiesByDefault() 0025 { 0026 DataSource ds; 0027 QCOMPARE(ds.name(), QString()); 0028 QCOMPARE(ds.iconName(), QString()); 0029 QCOMPARE(ds.contentTypes(), DataSource::NoContent); 0030 QVERIFY(!ds.isSelected()); 0031 } 0032 0033 void shouldNotifyNameChanges() 0034 { 0035 DataSource ds; 0036 QSignalSpy spy(&ds, &DataSource::nameChanged); 0037 ds.setName(QStringLiteral("Foo")); 0038 QCOMPARE(spy.count(), 1); 0039 QCOMPARE(spy.first().first().toString(), QStringLiteral("Foo")); 0040 } 0041 0042 void shouldNotNotifyIdenticalNameChanges() 0043 { 0044 DataSource ds; 0045 ds.setName(QStringLiteral("Foo")); 0046 QSignalSpy spy(&ds, &DataSource::nameChanged); 0047 ds.setName(QStringLiteral("Foo")); 0048 QCOMPARE(spy.count(), 0); 0049 } 0050 0051 void shouldNotifyIconNameChanges() 0052 { 0053 DataSource ds; 0054 QSignalSpy spy(&ds, &DataSource::iconNameChanged); 0055 ds.setIconName(QStringLiteral("Foo")); 0056 QCOMPARE(spy.count(), 1); 0057 QCOMPARE(spy.first().first().toString(), QStringLiteral("Foo")); 0058 } 0059 0060 void shouldNotNotifyIdenticalIconNameChanges() 0061 { 0062 DataSource ds; 0063 ds.setIconName(QStringLiteral("Foo")); 0064 QSignalSpy spy(&ds, &DataSource::iconNameChanged); 0065 ds.setIconName(QStringLiteral("Foo")); 0066 QCOMPARE(spy.count(), 0); 0067 } 0068 0069 void shouldNotifyContentTypesChanges() 0070 { 0071 DataSource ds; 0072 QSignalSpy spy(&ds, &DataSource::contentTypesChanged); 0073 ds.setContentTypes(Domain::DataSource::Tasks); 0074 QCOMPARE(spy.count(), 1); 0075 QCOMPARE(spy.first().first().value<Domain::DataSource::ContentTypes>(), 0076 Domain::DataSource::Tasks); 0077 } 0078 0079 void shouldNotNotifyIdenticalContentTypesChanges() 0080 { 0081 DataSource ds; 0082 ds.setContentTypes(Domain::DataSource::Tasks); 0083 QSignalSpy spy(&ds, &DataSource::contentTypesChanged); 0084 ds.setContentTypes(Domain::DataSource::Tasks); 0085 QCOMPARE(spy.count(), 0); 0086 } 0087 0088 void shouldNotifySelectedChanges() 0089 { 0090 DataSource ds; 0091 QSignalSpy spy(&ds, &DataSource::selectedChanged); 0092 ds.setSelected(true); 0093 QCOMPARE(spy.count(), 1); 0094 QVERIFY(spy.first().first().toBool()); 0095 } 0096 0097 void shouldNotNotifyIdenticalSelectedChanges() 0098 { 0099 DataSource ds; 0100 ds.setSelected(true); 0101 QSignalSpy spy(&ds, &DataSource::selectedChanged); 0102 ds.setSelected(true); 0103 QCOMPARE(spy.count(), 0); 0104 } 0105 }; 0106 0107 ZANSHIN_TEST_MAIN(DataSourceTest) 0108 0109 #include "datasourcetest.moc"