diff options
author | Marja Hassinen <ext-marja.2.hassinen@nokia.com> | 2009-10-27 15:08:30 +0200 |
---|---|---|
committer | Marja Hassinen <ext-marja.2.hassinen@nokia.com> | 2009-10-27 15:08:30 +0200 |
commit | 79dcc67663fca09c7bcb919db94536e685ce8f61 (patch) | |
tree | ce268e5da880af828b207a3d887e63601a1f2f43 | |
parent | f7f7fed6d7c2c6ba785cdc2a5f62c637ff8ddc6e (diff) |
libcontextprovider, protocol change: Updating unit tests.
5 files changed, 35 insertions, 92 deletions
diff --git a/libcontextprovider/unit-tests/property/.gitignore b/libcontextprovider/unit-tests/property/.gitignore index 87499d5a..e1526e46 100644 --- a/libcontextprovider/unit-tests/property/.gitignore +++ b/libcontextprovider/unit-tests/property/.gitignore @@ -1,5 +1,6 @@ propertyunittest property.cpp +propertyprivate.cpp sconnect.h logging.h logging.cpp diff --git a/libcontextprovider/unit-tests/property/Makefile.am b/libcontextprovider/unit-tests/property/Makefile.am index 60400c39..790caccd 100644 --- a/libcontextprovider/unit-tests/property/Makefile.am +++ b/libcontextprovider/unit-tests/property/Makefile.am @@ -3,7 +3,7 @@ check_PROGRAMS = propertyunittest # test's sources propertyunittest_SOURCES = propertyunittest.cpp service.h servicebackend.h property.h propertyprivate.h -COVERAGE_FILES = property.cpp propretyprivate.cpp +COVERAGE_FILES = property.cpp propertyprivate.cpp # do the testing, coverage, etc. stuff # tests.am is using +=, so we have to set a value here for these four always diff --git a/libcontextprovider/unit-tests/property/propertyprivate.h b/libcontextprovider/unit-tests/property/propertyprivate.h index 1866889b..591045e9 100644 --- a/libcontextprovider/unit-tests/property/propertyprivate.h +++ b/libcontextprovider/unit-tests/property/propertyprivate.h @@ -41,6 +41,9 @@ public: explicit PropertyPrivate(ServiceBackend* serviceBackend, const QString &key, QObject *parent = 0); void setValue(const QVariant& v); + void updateOverheardValue(const QVariantList&, const quint64&); + void setSubscribed(); + void setUnsubscribed(); signals: void valueChanged(const QVariantList& values, const qlonglong& timestamp); @@ -48,13 +51,23 @@ signals: void lastSubscriberDisappeared(const QString& key); private: - static qlonglong currentTimestamp(); + static quint64 currentTimestamp(); + void emitValue(); + int refCount; ///< Number of Property instance sharing this PropertyPrivate ServiceBackend* serviceBackend; ///< Pointer to the serviceBackend taking care of D-Bus related things QString key; ///< Key of this property - QVariant value; ///< Current value of the property, QVariant() if null - qlonglong timestamp; ///< Time when the value was set + QVariant value; ///< Current value of the property, set by this provider. QVariant() if null. + quint64 timestamp; ///< Time when the value was set + + bool subscribed; ///< True if this Property is subscribed to by the clients. + QVariant emittedValue; ///< Last value emitted by this provider. + quint64 emittedTimestamp; ///< Time when the emittedValue was emitted. + bool overheard; ///< True if provider overheard a value over D-Bus (must be different and more recent than emitted) + + /// Map of PropertyPrivate instances static QHash<QPair<ServiceBackend*, QString>, PropertyPrivate*> propertyPrivateMap; + friend class Property; friend class PropertyAdaptor; diff --git a/libcontextprovider/unit-tests/property/propertyunittest.cpp b/libcontextprovider/unit-tests/property/propertyunittest.cpp index be3402b3..9ba2de78 100644 --- a/libcontextprovider/unit-tests/property/propertyunittest.cpp +++ b/libcontextprovider/unit-tests/property/propertyunittest.cpp @@ -19,80 +19,19 @@ * */ +#include "service.h" // mock +#include "servicebackend.h" // mock + +#include "property.h" // to be tested +#include "propertyprivate.h" // to be tested + #include <QtTest/QtTest> #include <QtCore> #include <stdlib.h> -#include "service.h" -#include "property.h" -#include "manager.h" namespace ContextProvider { -Manager *manager; ServiceBackend *serviceBackend; -QVariant *lastVariantSet = NULL; - -void resetVariants() -{ - delete lastVariantSet; - lastVariantSet = NULL; -} - -bool Manager::keyIsValid(const QString &key) const -{ - return (keys.contains(key)); -} - -void Manager::increaseSubscriptionCount(const QString &key) -{ -} - -void Manager::decreaseSubscriptionCount(const QString &key) -{ -} - -const QVariant Manager::keyValue(const QString &key) -{ - return QVariant(); -} - -void Manager::setKeyValue(const QString &key, const QVariant &v) -{ - delete lastVariantSet; - lastVariantSet = new QVariant(v); -} - -QStringList Manager::getKeys() -{ - return keys; -} - -QVariant Manager::getKeyValue(const QString &key) -{ - if (lastVariantSet) - return QVariant(*lastVariantSet); - else - return QVariant(); -} - -void Manager::fakeFirst(const QString &key) -{ - emit firstSubscriberAppeared(key); -} - -void Manager::fakeLast(const QString &key) -{ - emit lastSubscriberDisappeared(key); -} - -Manager::Manager() -{ -} - -void Manager::addKey(const QString &key) -{ - keys << key; -} // Mock implementation of Service @@ -104,9 +43,8 @@ Service::Service() // Mock implementation of ServiceBackend ServiceBackend* ServiceBackend::defaultServiceBackend = NULL; -Manager *ServiceBackend::manager() +void ServiceBackend::addProperty(const QString& key, PropertyPrivate* prop) { - return ContextProvider::manager; } class PropertyUnitTest : public QObject @@ -138,7 +76,6 @@ void PropertyUnitTest::initTestCase() void PropertyUnitTest::init() { - manager = new Manager(); battery_voltage = new Property(service, "Battery.Voltage"); battery_is_charging = new Property(service, "Battery.IsCharging"); } @@ -147,7 +84,6 @@ void PropertyUnitTest::cleanup() { delete battery_voltage; battery_voltage = NULL; delete battery_is_charging; battery_is_charging = NULL; - delete manager; manager = NULL; } void PropertyUnitTest::getProperty() @@ -157,18 +93,17 @@ void PropertyUnitTest::getProperty() void PropertyUnitTest::checkSignals() { - resetVariants(); - QSignalSpy spy1(battery_voltage, SIGNAL(firstSubscriberAppeared(QString))); QSignalSpy spy2(battery_voltage, SIGNAL(lastSubscriberDisappeared(QString))); - manager->fakeFirst("Battery.Voltage"); + QVERIFY(battery_voltage->priv); + emit battery_voltage->priv->firstSubscriberAppeared("Battery.Voltage"); QCOMPARE(spy1.count(), 1); QList<QVariant> args1 = spy1.takeFirst(); QCOMPARE(args1.at(0).toString(), QString("Battery.Voltage")); - manager->fakeLast("Battery.Voltage"); + emit battery_voltage->priv->lastSubscriberDisappeared("Battery.Voltage"); QCOMPARE(spy2.count(), 1); QList<QVariant> args2 = spy2.takeFirst(); @@ -177,57 +112,52 @@ void PropertyUnitTest::checkSignals() void PropertyUnitTest::setGetBool() { - resetVariants(); battery_is_charging->setValue(true); - QCOMPARE(*lastVariantSet, QVariant(true)); QCOMPARE(battery_is_charging->value(), QVariant(true)); + QCOMPARE(battery_is_charging->priv->value, QVariant(true)); } void PropertyUnitTest::setGetInt() { - resetVariants(); battery_voltage->setValue(666); - QCOMPARE(*lastVariantSet, QVariant(666)); QCOMPARE(battery_voltage->value(), QVariant(666)); + QCOMPARE(battery_voltage->priv->value, QVariant(666)); QVERIFY(battery_voltage->isSet()); } void PropertyUnitTest::setGetDouble() { - resetVariants(); battery_voltage->setValue(0.456); - QCOMPARE(*lastVariantSet, QVariant(0.456)); QCOMPARE(battery_voltage->value(), QVariant(0.456)); + QCOMPARE(battery_voltage->priv->value, QVariant(0.456)); QVERIFY(battery_voltage->isSet()); } void PropertyUnitTest::setGetString() { - resetVariants(); battery_voltage->setValue(QString("Hello!")); - QCOMPARE(*lastVariantSet, QVariant(QString("Hello!"))); QCOMPARE(battery_voltage->value(), QVariant("Hello!")); + QCOMPARE(battery_voltage->priv->value, QVariant("Hello!")); QVERIFY(battery_voltage->isSet()); } void PropertyUnitTest::setGetQVariant() { - resetVariants(); battery_voltage->setValue(QVariant(123)); - QCOMPARE(*lastVariantSet, QVariant(123)); QCOMPARE(battery_voltage->value(), QVariant(123)); + QCOMPARE(battery_voltage->priv->value, QVariant(123)); QVERIFY(battery_voltage->isSet()); } void PropertyUnitTest::unset() { - resetVariants(); - QVERIFY(battery_voltage->isSet() == false); battery_voltage->setValue(QVariant(123)); QVERIFY(battery_voltage->isSet()); QCOMPARE(battery_voltage->value(), QVariant(123)); + QCOMPARE(battery_voltage->priv->value, QVariant(123)); battery_voltage->unsetValue(); QCOMPARE(battery_voltage->value(), QVariant()); + QCOMPARE(battery_voltage->priv->value, QVariant()); QVERIFY(!battery_voltage->isSet()); } diff --git a/libcontextprovider/unit-tests/property/service.h b/libcontextprovider/unit-tests/property/service.h index cbb14c34..4947df02 100644 --- a/libcontextprovider/unit-tests/property/service.h +++ b/libcontextprovider/unit-tests/property/service.h @@ -24,7 +24,6 @@ namespace ContextProvider { class Property; -class Manager; class Service : public QObject { |