File indexing completed on 2024-04-14 14:53:38

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 <KProperty>
0022 
0023 class KPropertyTest : public QObject
0024 {
0025     Q_OBJECT
0026 private Q_SLOTS:
0027     void testNull();
0028 private:
0029 };
0030 
0031 void KPropertyTest::testNull()
0032 {
0033     {
0034         // isNull
0035         const KProperty nullProperty;
0036         QVERIFY(nullProperty.isNull());
0037         const KProperty nullPropertyCopy(nullProperty);
0038         QVERIFY(nullPropertyCopy.isNull());
0039         QVERIFY2(nullProperty == nullPropertyCopy, "two null properties are equal");
0040         QVERIFY2(nullProperty == KProperty(), "two null properties are equal v2");
0041         QVERIFY2(!(nullProperty != nullPropertyCopy), "two null properties are equal v2");
0042     }
0043     {
0044         // name
0045         const KProperty nullProperty;
0046         const KProperty nullPropertyCopy(nullProperty);
0047         KProperty notNullProperty("notNull");
0048         QVERIFY(!notNullProperty.isNull());
0049         QVERIFY2(!(nullProperty == notNullProperty), "null property is not equal to not null property");
0050         notNullProperty.setName(QByteArray());
0051         QVERIFY2(notNullProperty.isNull(), "Not null property becomes null after setting empty name");
0052         notNullProperty.setName("");
0053         QVERIFY2(notNullProperty.isNull(), "Not null property becomes null after setting empty name v2");
0054         notNullProperty.setName("other");
0055         QVERIFY2(!notNullProperty.isNull(), "Null property becomes not-null after setting non-empty name");
0056         QVERIFY(nullProperty.name().isEmpty());
0057         QVERIFY(nullPropertyCopy.name().isEmpty());
0058     }
0059     {
0060         // caption
0061         const KProperty nullProperty;
0062         const KProperty nullPropertyCopy(nullProperty);
0063         KProperty notNullProperty("notNull");
0064         QVERIFY(nullProperty.caption().isEmpty());
0065         QVERIFY(nullPropertyCopy.caption().isEmpty());
0066         QVERIFY(notNullProperty.caption().isEmpty());
0067         KProperty propertyWithCaption("withCaption", 17, "My caption");
0068         QVERIFY(!propertyWithCaption.isNull());
0069         propertyWithCaption.setName(QByteArray());
0070         QVERIFY2(propertyWithCaption.isNull(), "Property with name and caption is null after setting "
0071                                                "empty name");
0072     }
0073     {
0074         // caption does not influence null
0075         KProperty propertyWithCaption("withCaption", 17, "My caption");
0076         propertyWithCaption.setCaption(QByteArray());
0077         QVERIFY2(!propertyWithCaption.isNull(), "Property with name and caption is still not null "
0078                                                 "after setting empty caption");
0079     }
0080     {
0081         // description
0082         KProperty nullProperty;
0083         nullProperty.setDescription("My desc");
0084         QVERIFY2(nullProperty.isNull(), "Null property with non-empty description is still null");
0085     }
0086     {
0087         // value
0088         KProperty nullProperty;
0089         QTest::ignoreMessage(QtWarningMsg, "COULD NOT SET value to a null property");
0090         nullProperty.setValue(0.123);
0091         QTest::ignoreMessage(QtWarningMsg, "COULD NOT SET value to a null property");
0092         KProperty nullPropertyWithValue(QByteArray(), 177);
0093         QVERIFY2(nullPropertyWithValue.isNull(), "Null property with value set from ctor is still null");
0094         QVERIFY2(nullPropertyWithValue.value().isNull(), "Null property with value set from "
0095                                                                 "ctor still has no value");
0096     }
0097 }
0098 
0099 /* TODO
0100     KProperty::KProperty(KProperty const&)
0101     KProperty::KProperty(QByteArray const&, KPropertyListData*, QVariant const&, QString const&, QString const&, int, KProperty*)
0102     KProperty::KProperty(QByteArray const&, QStringList const&, QStringList const&, QVariant const&, QString const&, QString const&, int, KProperty*)
0103     KProperty::KProperty(QByteArray const&, QVariant const&, QString const&, QString const&, int, KProperty*)
0104     KProperty::KProperty()
0105     KProperty::captionForDisplaying() const
0106     KProperty::caption() const
0107     KProperty::childValueChanged(KProperty*, QVariant const&, bool)
0108     KProperty::children() const
0109     KProperty::child(QByteArray const&)
0110     KProperty::clearModifiedFlag()
0111     KProperty::composedProperty() const
0112     KProperty::description() const
0113     KProperty::hasOptions() const
0114     KProperty::iconName() const
0115     KProperty::isModified() const
0116 OK  KProperty::isNull() const
0117     KProperty::isReadOnly() const
0118     KProperty::isStorable() const
0119     KProperty::isVisible() const
0120     KProperty::listData() const
0121     KProperty::name() const
0122     KProperty::oldValue() const
0123     KProperty::operator=(KProperty const&)
0124     KProperty::operator=(QVariant const&)
0125     KProperty::operator==(KProperty const&) const
0126     KProperty::option(char const*, QVariant const&) const
0127     KProperty::parent() const
0128     KProperty::resetValue()
0129     KProperty::setCaption(QString const&)
0130     KProperty::setComposedProperty(KComposedPropertyInterface*)
0131     KProperty::setDescription(QString const&)
0132     KProperty::setIconName(QString const&)
0133     KProperty::setListData(KPropertyListData*)
0134     KProperty::setListData(QStringList const&, QStringList const&)
0135     KProperty::setName(QByteArray const&)
0136     KProperty::setOption(char const*, QVariant const&)
0137     KProperty::setReadOnly(bool)
0138     KProperty::setStorable(bool)
0139     KProperty::setType(int)
0140     KProperty::setValueSyncPolicy(KProperty::ValueSyncPolicy)
0141     KProperty::setValue(QVariant const&, QFlags<KProperty::ValueOption>)
0142     KProperty::setVisible(bool)
0143     KProperty::type() const
0144     KProperty::valueEqualsTo(QVariant const&, QFlags<KProperty::ValueOption>) const
0145     KProperty::valueSyncPolicy() const
0146     KProperty::value() const
0147 
0148     KPropertyListData::~KPropertyListData()
0149     KPropertyListData::KPropertyListData(QList<QVariant>, QStringList const&)
0150     KPropertyListData::KPropertyListData(QStringList const&, QStringList const&)
0151     KPropertyListData::KPropertyListData()
0152     KPropertyListData::keysAsStringList() const
0153     KPropertyListData::setKeysAsStringList(QStringList const&)
0154 */
0155 
0156 /* Full API TODO:
0157 
0158 KComposedPropertyCreatorInterface::~KComposedPropertyCreatorInterface()
0159 KComposedPropertyCreatorInterface::KComposedPropertyCreatorInterface()
0160 KComposedPropertyInterface::~KComposedPropertyInterface()
0161 KComposedPropertyInterface::KComposedPropertyInterface(KProperty*)
0162 KPropertySetBuffer::KPropertySetBuffer(KPropertySet const&)
0163 KPropertySetBuffer::KPropertySetBuffer()
0164 KPropertySetBuffer::init(KPropertySet const&)
0165 KPropertySetBuffer::intersectedChanged(KPropertySet&, KProperty&)
0166 KPropertySetBuffer::intersectedReset(KPropertySet&, KProperty&)
0167 KPropertySetBuffer::intersect(KPropertySet const&)
0168 KPropertyFactoryManager::~KPropertyFactoryManager()
0169 KPropertyFactoryManager::KPropertyFactoryManager()
0170 KPropertyFactoryManager::addInitFunction(void (*)())
0171 KPropertyFactoryManager::canConvertValueToText(KProperty const*) const
0172 KPropertyFactoryManager::canConvertValueToText(int) const
0173 KPropertyFactoryManager::createComposedProperty(KProperty*)
0174 KPropertyFactoryManager::propertyValueToLocalizedString(KProperty const*) const
0175 KPropertyFactoryManager::propertyValueToString(KProperty const*) const
0176 KPropertyFactoryManager::registerFactory(KPropertyFactory*)
0177 KPropertyFactoryManager::self()
0178 KPropertyFactoryManager::valueToLocalizedString(int, QVariant const&) const
0179 KPropertyFactoryManager::valueToString(int, QVariant const&) const
0180 KPropertyFactory::~KPropertyFactory()
0181 KPropertyFactory::KPropertyFactory()
0182 KPropertyFactory::addComposedPropertyCreatorInternal(int, KComposedPropertyCreatorInterface*, bool)
0183 KPropertyFactory::addComposedPropertyCreator(int, KComposedPropertyCreatorInterface*)
0184 KPropertyFactory::addDisplayInternal(int, KPropertyValueDisplayInterface*, bool)
0185 KPropertyFactory::addDisplay(int, KPropertyValueDisplayInterface*)
0186 KPropertyFactory::composedPropertyCreators() const
0187 KPropertyFactory::valueDisplays() const
0188 KPropertyUtils::keyForEnumValue(char const*, int)
0189 KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface()
0190 KPropertyValueDisplayInterface::KPropertyValueDisplayInterface()
0191 KPropertyValueDisplayInterface::maxStringValueLength()
0192 KPropertyValueDisplayInterface::valueToLocalizedString(QVariant const&)
0193 */
0194 
0195 QTEST_GUILESS_MAIN(KPropertyTest)
0196 
0197 #include "KPropertyTest.moc"