File: KPropertySetTest.cpp

package info (click to toggle)
kproperty 3.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,660 kB
  • sloc: cpp: 9,998; xml: 182; sh: 110; makefile: 7
file content (171 lines) | stat: -rw-r--r-- 6,990 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* This file is part of the KDE project
   Copyright (C) 2017 Jarosław Staniek <staniek@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <QtTest>
#include <KPropertySet>

namespace QTest {
//! For convenience.
bool qCompare(const QByteArray &val1, const char* val2, const char *actual,
                                      const char *expected, const char *file, int line)
{
    return QTest::qCompare(val1, QByteArray(val2), actual, expected, file, line);
}
}

class KPropertySetTest : public QObject
{
    Q_OBJECT
private Q_SLOTS:
    void testEmpty();
    void testGroupNameForProperty();
private:
    void testPropertiesForEmpty(const KPropertySet &set, const char *context);
};

void KPropertySetTest::testEmpty()
{
    KPropertySet empty;
    testPropertiesForEmpty(empty, "empty");
    empty.clear();
    testPropertiesForEmpty(empty, "after empty.clear()");

    KPropertySet emptyCopy(empty);
    testPropertiesForEmpty(emptyCopy, "emptyCopy");
    emptyCopy.clear();
    testPropertiesForEmpty(emptyCopy, "after emptyCopy.clear()");

    KPropertySet emptyCopy2;
    emptyCopy2 = KPropertySet();
    testPropertiesForEmpty(emptyCopy2, "emptyCopy2");
    emptyCopy2.clear();
    testPropertiesForEmpty(emptyCopy2, "after emptyCopy2.clear()");

    QObject parent;
    const KPropertySet emptyWithParent(&parent);
    QCOMPARE(&parent, emptyWithParent.parent());
}

void KPropertySetTest::testPropertiesForEmpty(const KPropertySet &set, const char *context)
{
    qDebug() << context;
    QVERIFY(!set.parent());
    QVERIFY(set.isEmpty());
    QCOMPARE(set.count(), 0);
    QVERIFY(!set.isReadOnly());
    QVERIFY(!set.hasVisibleProperties());
    QCOMPARE(set.groupNames().count(), 0);
    QVERIFY(set.propertyValues().isEmpty());
}

void KPropertySetTest::testGroupNameForProperty()
{
    {
        KPropertySet set;
        QVERIFY2(set.groupNameForProperty("foo").isEmpty(), "No property in empty");
    }
    {
        KPropertySet set;
        KProperty *foo = new KProperty("foo");
        set.addProperty(foo);
        QCOMPARE(set.groupNameForProperty("foo"), "common");
        QCOMPARE(set.groupNameForProperty(*foo), "common");
        QVERIFY2(set.groupNameForProperty("bar").isEmpty(), "No property in !empty");

        set.removeProperty(foo);
        QVERIFY2(set.groupNameForProperty("foo").isEmpty(), "No property after removal");
        foo = new KProperty("foo");
        set.addProperty(foo);
        set.removeProperty("foo");
        QVERIFY2(set.groupNameForProperty("foo").isEmpty(), "No property after removal 2");

        foo = new KProperty("foo");
        set.addProperty(foo, "someGroup");
        QCOMPARE(set.groupNameForProperty(*foo), "somegroup");
        QCOMPARE(set.groupNameForProperty("foo"), "somegroup");

        KProperty bar("bar");
        QVERIFY2(set.groupNameForProperty(bar).isEmpty(), "No property in !empty 2");
    }
}

/* TODO
    KPropertySelector::KPropertySelector()
    KPropertySetIterator::KPropertySetIterator(KPropertySet const&)
    KPropertySetIterator::KPropertySetIterator(KPropertySet const&, KPropertySelector const&)
    KPropertySetIterator::operator++()
    KPropertySetIterator::setOrder(KPropertySetIterator::Order)
    KPropertySetIterator::skipNotAcceptable()
    KPropertySetPrivate::KPropertySetPrivate(KPropertySet*)
    KPropertySetPrivate::addProperty(KProperty*, QByteArray const&)
    KPropertySetPrivate::addRelatedProperty(KProperty*, KProperty*) const
    KPropertySetPrivate::addToGroup(QByteArray const&, KProperty*)
    KPropertySetPrivate::clear()
    KPropertySetPrivate::copyAttributesFrom(KPropertySetPrivate const&)
    KPropertySetPrivate::copyPropertiesFrom(QList<KProperty*>::const_iterator const&, QList<KProperty*>::const_iterator const&, KPropertySet const&)
    KPropertySetPrivate::hasGroups() const
    KPropertySetPrivate::indexOfPropertyInGroup(KProperty const*) const
    KPropertySetPrivate::indexOfProperty(KProperty const*) const
    KPropertySetPrivate::informAboutClearing(bool*)
    KPropertySetPrivate::removeFromGroup(KProperty*)
    KPropertySetPrivate::removeProperty(KProperty*)
+    KPropertySet::KPropertySet(KPropertySet const&)
OK    KPropertySet::KPropertySet(QObject*)
    KPropertySet::aboutToBeCleared()
    KPropertySet::aboutToBeDeleted()
    KPropertySet::aboutToDeleteProperty(KPropertySet&, KProperty&)
    KPropertySet::addProperty(KProperty*, QByteArray const&)
    KPropertySet::changePropertyIfExists(QByteArray const&, QVariant const&)
    KPropertySet::changeProperty(QByteArray const&, QVariant const&)
    KPropertySet::clear()
    KPropertySet::contains(QByteArray const&) const
    KPropertySet::count(KPropertySelector const&) const
    KPropertySet::count() const
    KPropertySet::debug() const
    KPropertySet::groupCaption(QByteArray const&) const
    KPropertySet::groupIconName(QByteArray const&) const
OK    KPropertySet::groupNameForProperty(const QByteArray &propertyName) const;
OK    KPropertySet::groupNameForProperty(const KProperty &property) const;
    KPropertySet::groupNames() const
    KPropertySet::hasProperties(KPropertySelector const&) const
    KPropertySet::hasVisibleProperties() const
+    KPropertySet::isEmpty() const
    KPropertySet::isReadOnly() const
    KPropertySet::operator=(KPropertySet const&)
    KPropertySet::operator[](QByteArray const&) const
    KPropertySet::previousSelection() const
    KPropertySet::propertyChangedInternal(KPropertySet&, KProperty&)
    KPropertySet::propertyChanged(KPropertySet&, KProperty&)
    KPropertySet::propertyNamesForGroup(QByteArray const&) const
    KPropertySet::propertyReset(KPropertySet&, KProperty&)
    KPropertySet::propertyValues() const
    KPropertySet::propertyValue(QByteArray const&, QVariant const&) const
    KPropertySet::property(QByteArray const&) const
    KPropertySet::readOnlyFlagChanged()
    KPropertySet::removeProperty(KProperty*)
    KPropertySet::removeProperty(QByteArray const&)
    KPropertySet::setGroupCaption(QByteArray const&, QString const&)
    KPropertySet::setGroupIconName(QByteArray const&, QString const&)
    KPropertySet::setPreviousSelection(QByteArray const&)
    KPropertySet::setReadOnly(bool)
*/

QTEST_GUILESS_MAIN(KPropertySetTest)

#include "KPropertySetTest.moc"