File indexing completed on 2023-09-24 08:38:03

0001 /* This file is part of the KDE project
0002    Copyright (C) 2017 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include <QtTest>
0021 #include <KPropertySet>
0022 
0023 namespace QTest {
0024 //! For convenience.
0025 bool qCompare(const QByteArray &val1, const char* val2, const char *actual,
0026                                       const char *expected, const char *file, int line)
0027 {
0028     return QTest::qCompare(val1, QByteArray(val2), actual, expected, file, line);
0029 }
0030 }
0031 
0032 class KPropertySetTest : public QObject
0033 {
0034     Q_OBJECT
0035 private Q_SLOTS:
0036     void testEmpty();
0037     void testGroupNameForProperty();
0038 private:
0039     void testPropertiesForEmpty(const KPropertySet &set, const char *context);
0040 };
0041 
0042 void KPropertySetTest::testEmpty()
0043 {
0044     KPropertySet empty;
0045     testPropertiesForEmpty(empty, "empty");
0046     empty.clear();
0047     testPropertiesForEmpty(empty, "after empty.clear()");
0048 
0049     KPropertySet emptyCopy(empty);
0050     testPropertiesForEmpty(emptyCopy, "emptyCopy");
0051     emptyCopy.clear();
0052     testPropertiesForEmpty(emptyCopy, "after emptyCopy.clear()");
0053 
0054     KPropertySet emptyCopy2;
0055     emptyCopy2 = KPropertySet();
0056     testPropertiesForEmpty(emptyCopy2, "emptyCopy2");
0057     emptyCopy2.clear();
0058     testPropertiesForEmpty(emptyCopy2, "after emptyCopy2.clear()");
0059 
0060     QObject parent;
0061     const KPropertySet emptyWithParent(&parent);
0062     QCOMPARE(&parent, emptyWithParent.parent());
0063 }
0064 
0065 void KPropertySetTest::testPropertiesForEmpty(const KPropertySet &set, const char *context)
0066 {
0067     qDebug() << context;
0068     QVERIFY(!set.parent());
0069     QVERIFY(set.isEmpty());
0070     QCOMPARE(set.count(), 0);
0071     QVERIFY(!set.isReadOnly());
0072     QVERIFY(!set.hasVisibleProperties());
0073     QCOMPARE(set.groupNames().count(), 0);
0074     QVERIFY(set.propertyValues().isEmpty());
0075 }
0076 
0077 void KPropertySetTest::testGroupNameForProperty()
0078 {
0079     {
0080         KPropertySet set;
0081         QVERIFY2(set.groupNameForProperty("foo").isEmpty(), "No property in empty");
0082     }
0083     {
0084         KPropertySet set;
0085         KProperty *foo = new KProperty("foo");
0086         set.addProperty(foo);
0087         QCOMPARE(set.groupNameForProperty("foo"), "common");
0088         QCOMPARE(set.groupNameForProperty(*foo), "common");
0089         QVERIFY2(set.groupNameForProperty("bar").isEmpty(), "No property in !empty");
0090 
0091         set.removeProperty(foo);
0092         QVERIFY2(set.groupNameForProperty("foo").isEmpty(), "No property after removal");
0093         foo = new KProperty("foo");
0094         set.addProperty(foo);
0095         set.removeProperty("foo");
0096         QVERIFY2(set.groupNameForProperty("foo").isEmpty(), "No property after removal 2");
0097 
0098         foo = new KProperty("foo");
0099         set.addProperty(foo, "someGroup");
0100         QCOMPARE(set.groupNameForProperty(*foo), "somegroup");
0101         QCOMPARE(set.groupNameForProperty("foo"), "somegroup");
0102 
0103         KProperty bar("bar");
0104         QVERIFY2(set.groupNameForProperty(bar).isEmpty(), "No property in !empty 2");
0105     }
0106 }
0107 
0108 /* TODO
0109     KPropertySelector::KPropertySelector()
0110     KPropertySetIterator::KPropertySetIterator(KPropertySet const&)
0111     KPropertySetIterator::KPropertySetIterator(KPropertySet const&, KPropertySelector const&)
0112     KPropertySetIterator::operator++()
0113     KPropertySetIterator::setOrder(KPropertySetIterator::Order)
0114     KPropertySetIterator::skipNotAcceptable()
0115     KPropertySetPrivate::KPropertySetPrivate(KPropertySet*)
0116     KPropertySetPrivate::addProperty(KProperty*, QByteArray const&)
0117     KPropertySetPrivate::addRelatedProperty(KProperty*, KProperty*) const
0118     KPropertySetPrivate::addToGroup(QByteArray const&, KProperty*)
0119     KPropertySetPrivate::clear()
0120     KPropertySetPrivate::copyAttributesFrom(KPropertySetPrivate const&)
0121     KPropertySetPrivate::copyPropertiesFrom(QList<KProperty*>::const_iterator const&, QList<KProperty*>::const_iterator const&, KPropertySet const&)
0122     KPropertySetPrivate::hasGroups() const
0123     KPropertySetPrivate::indexOfPropertyInGroup(KProperty const*) const
0124     KPropertySetPrivate::indexOfProperty(KProperty const*) const
0125     KPropertySetPrivate::informAboutClearing(bool*)
0126     KPropertySetPrivate::removeFromGroup(KProperty*)
0127     KPropertySetPrivate::removeProperty(KProperty*)
0128 +    KPropertySet::KPropertySet(KPropertySet const&)
0129 OK    KPropertySet::KPropertySet(QObject*)
0130     KPropertySet::aboutToBeCleared()
0131     KPropertySet::aboutToBeDeleted()
0132     KPropertySet::aboutToDeleteProperty(KPropertySet&, KProperty&)
0133     KPropertySet::addProperty(KProperty*, QByteArray const&)
0134     KPropertySet::changePropertyIfExists(QByteArray const&, QVariant const&)
0135     KPropertySet::changeProperty(QByteArray const&, QVariant const&)
0136     KPropertySet::clear()
0137     KPropertySet::contains(QByteArray const&) const
0138     KPropertySet::count(KPropertySelector const&) const
0139     KPropertySet::count() const
0140     KPropertySet::debug() const
0141     KPropertySet::groupCaption(QByteArray const&) const
0142     KPropertySet::groupIconName(QByteArray const&) const
0143 OK    KPropertySet::groupNameForProperty(const QByteArray &propertyName) const;
0144 OK    KPropertySet::groupNameForProperty(const KProperty &property) const;
0145     KPropertySet::groupNames() const
0146     KPropertySet::hasProperties(KPropertySelector const&) const
0147     KPropertySet::hasVisibleProperties() const
0148 +    KPropertySet::isEmpty() const
0149     KPropertySet::isReadOnly() const
0150     KPropertySet::operator=(KPropertySet const&)
0151     KPropertySet::operator[](QByteArray const&) const
0152     KPropertySet::previousSelection() const
0153     KPropertySet::propertyChangedInternal(KPropertySet&, KProperty&)
0154     KPropertySet::propertyChanged(KPropertySet&, KProperty&)
0155     KPropertySet::propertyNamesForGroup(QByteArray const&) const
0156     KPropertySet::propertyReset(KPropertySet&, KProperty&)
0157     KPropertySet::propertyValues() const
0158     KPropertySet::propertyValue(QByteArray const&, QVariant const&) const
0159     KPropertySet::property(QByteArray const&) const
0160     KPropertySet::readOnlyFlagChanged()
0161     KPropertySet::removeProperty(KProperty*)
0162     KPropertySet::removeProperty(QByteArray const&)
0163     KPropertySet::setGroupCaption(QByteArray const&, QString const&)
0164     KPropertySet::setGroupIconName(QByteArray const&, QString const&)
0165     KPropertySet::setPreviousSelection(QByteArray const&)
0166     KPropertySet::setReadOnly(bool)
0167 */
0168 
0169 QTEST_GUILESS_MAIN(KPropertySetTest)
0170 
0171 #include "KPropertySetTest.moc"