diff options
author | Tomas Junnonen <tomas.junnonen@nokia.com> | 2010-04-12 13:50:25 +0300 |
---|---|---|
committer | Tomas Junnonen <tomas.junnonen@nokia.com> | 2010-04-12 13:52:31 +0300 |
commit | da73676c8a5af66b55523a9cdfbfbea2baa88a2a (patch) | |
tree | 0a3b8933a1817c152116da5fa8a7b5cdd8102e60 /tests/ut_maggregatedataaccess | |
parent | 8832674482d3b9a7fcf77b0cfdcb8e6fe4960b4d (diff) |
Changes: Renamed dui to meegotouch
By: Holger, Daniel, Janne
RevBy: Tomas, Holger
Diffstat (limited to 'tests/ut_maggregatedataaccess')
4 files changed, 274 insertions, 0 deletions
diff --git a/tests/ut_maggregatedataaccess/.gitignore b/tests/ut_maggregatedataaccess/.gitignore new file mode 100644 index 00000000..1001d758 --- /dev/null +++ b/tests/ut_maggregatedataaccess/.gitignore @@ -0,0 +1,2 @@ +ut_duiaggregatedataaccess + diff --git a/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.cpp b/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.cpp new file mode 100644 index 00000000..8bece158 --- /dev/null +++ b/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#include <maggregatedataaccess.h> +#include <mdataaccess.h> +#include "ut_maggregatedataaccess.h" +#include "../stubs/mockdatastore.h" + +void Ut_MAggregateDataAccess::init() +{ + primaryAccess = new MockDataStore; + secondaryAccess = new MockDataStore; + testAccess = new MAggregateDataAccess(*primaryAccess, *secondaryAccess); +} + +void Ut_MAggregateDataAccess::cleanup() +{ + valueChangedSignals.clear(); + delete testAccess; + delete primaryAccess; + delete secondaryAccess; +} + +void Ut_MAggregateDataAccess::testAccessValueChanged(const QString &key, const QVariant &value) +{ + valueChangedSignals.append(QPair<QString, QVariant>(key, value)); +} + +void Ut_MAggregateDataAccess::testSettingValueInPrimaryAccess() +{ + primaryAccess->createValue(QString("primaryKey"), QVariant(1)); + testAccess->setValue(QString("primaryKey"), QVariant(2)); + + QCOMPARE(primaryAccess->value(QString("primaryKey")), QVariant(2)); +} + +void Ut_MAggregateDataAccess::testSettingValueInSecondaryAccess() +{ + secondaryAccess->createValue(QString("secondaryKey"), QVariant(1)); + testAccess->setValue(QString("secondaryKey"), QVariant(2)); + + QCOMPARE(secondaryAccess->value(QString("secondaryKey")), QVariant(2)); +} + +void Ut_MAggregateDataAccess::testSettingValueDefinedInPrimaryAndSecondaryAccess() +{ + primaryAccess->createValue(QString("sharedKey"), QVariant(1)); + secondaryAccess->createValue(QString("sharedKey"), QVariant(1)); + testAccess->setValue(QString("sharedKey"), QVariant(2)); + + QCOMPARE(primaryAccess->value(QString("sharedKey")), QVariant(2)); + QCOMPARE(secondaryAccess->value(QString("sharedKey")), QVariant(1)); +} + +void Ut_MAggregateDataAccess::testGettingAggregateKeyList() +{ + primaryAccess->createValue(QString("primaryKey"), QVariant(1)); + secondaryAccess->createValue(QString("secondaryKey"), QVariant(1)); + + QCOMPARE(testAccess->allKeys().count(), 2); + QCOMPARE(testAccess->allKeys().contains("primaryKey"), QBool(true)); + QCOMPARE(testAccess->allKeys().contains("secondaryKey"), QBool(true)); +} + +void Ut_MAggregateDataAccess::testGettingAggregateKeyListWithoutDuplicates() +{ + primaryAccess->createValue(QString("sharedKey"), QVariant(1)); + secondaryAccess->createValue(QString("sharedKey"), QVariant(2)); + + QCOMPARE(testAccess->allKeys().count(), 1); + QCOMPARE(testAccess->allKeys().contains("sharedKey"), QBool(true)); +} + +void Ut_MAggregateDataAccess::testContainsKeyInPrimaryAccess() +{ + primaryAccess->createValue(QString("primaryKey"), QVariant(1)); + + QCOMPARE(testAccess->contains(QString("primaryKey")), true); + QCOMPARE(testAccess->contains(QString("secondaryKey")), false); +} + +void Ut_MAggregateDataAccess::testContainsKeyInSecondaryAccess() +{ + secondaryAccess->createValue(QString("secondaryKey"), QVariant(1)); + + QCOMPARE(testAccess->contains(QString("primaryKey")), false); + QCOMPARE(testAccess->contains(QString("secondaryKey")), true); +} + +void Ut_MAggregateDataAccess::testContainsKeyDefinedInPrimaryAndSecondaryAccess() +{ + primaryAccess->createValue(QString("sharedKey"), QVariant(1)); + secondaryAccess->createValue(QString("sharedKey"), QVariant(2)); + + QCOMPARE(testAccess->contains(QString("sharedKey")), true); +} + +void Ut_MAggregateDataAccess::testAcquiringValueFromPrimaryAccess() +{ + primaryAccess->createValue(QString("primaryKey"), QVariant(3)); + + QCOMPARE(testAccess->value(QString("primaryKey")), QVariant(3)); +} + +void Ut_MAggregateDataAccess::testAcquiringValueFromSecondaryAccess() +{ + secondaryAccess->createValue(QString("secondaryKey"), QVariant(3)); + + QCOMPARE(testAccess->value(QString("secondaryKey")), QVariant(3)); +} + +void Ut_MAggregateDataAccess::testAcquiringValueDefinedInPrimaryAndSecondaryAccess() +{ + primaryAccess->createValue(QString("sharedKey"), QVariant(3)); + secondaryAccess->createValue(QString("sharedKey"), QVariant(2)); + + QCOMPARE(testAccess->value(QString("sharedKey")), QVariant(3)); +} + +void Ut_MAggregateDataAccess::testValueChangedEmittedFromPrimaryAccess() +{ + connect(testAccess, SIGNAL(valueChanged(QString, QVariant)), this, SLOT(testAccessValueChanged(QString, QVariant))); + primaryAccess->createValue(QString("primaryKey"), QVariant(3)); + + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("primaryKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 3); + valueChangedSignals.clear(); + + primaryAccess->setValue(QString("primaryKey"), QVariant(5)); + + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("primaryKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 5); +} + +void Ut_MAggregateDataAccess::testValueChangedEmittedFromSecondaryAccess() +{ + connect(testAccess, SIGNAL(valueChanged(QString, QVariant)), this, SLOT(testAccessValueChanged(QString, QVariant))); + secondaryAccess->createValue(QString("secondaryKey"), QVariant(2)); + + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("secondaryKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 2); + valueChangedSignals.clear(); + + secondaryAccess->setValue(QString("secondaryKey"), QVariant(8)); + + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("secondaryKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 8); +} + +void Ut_MAggregateDataAccess::testValueChangedEmittedFromSharedKey() +{ + connect(testAccess, SIGNAL(valueChanged(QString, QVariant)), this, SLOT(testAccessValueChanged(QString, QVariant))); + + secondaryAccess->createValue(QString("sharedKey"), QVariant(2)); + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("sharedKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 2); + valueChangedSignals.clear(); + + primaryAccess->createValue(QString("sharedKey"), QVariant(4)); + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("sharedKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 4); + valueChangedSignals.clear(); + + secondaryAccess->setValue(QString("sharedKey"), QVariant(3)); + QCOMPARE(valueChangedSignals.count(), 0); + + primaryAccess->setValue(QString("sharedKey"), QVariant(7)); + QCOMPARE(valueChangedSignals.count(), 1); + QCOMPARE(valueChangedSignals.at(0).first, QString("sharedKey")); + QCOMPARE(valueChangedSignals.at(0).second.toInt(), 7); +} + +QTEST_MAIN(Ut_MAggregateDataAccess) diff --git a/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.h b/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.h new file mode 100644 index 00000000..2f6d3a6a --- /dev/null +++ b/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.h @@ -0,0 +1,65 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#ifndef UT_MAGGREGATEDATAACCESS_H +#define UT_MAGGREGATEDATAACCESS_H + +#include <QtTest/QtTest> +#include <QObject> + +class MockDataStore; +class MDataAccess; + +class Ut_MAggregateDataAccess : public QObject +{ + Q_OBJECT + +private slots: + void init(); + void cleanup(); + void testSettingValueInPrimaryAccess(); + void testSettingValueInSecondaryAccess(); + void testSettingValueDefinedInPrimaryAndSecondaryAccess(); + void testAcquiringValueFromPrimaryAccess(); + void testAcquiringValueFromSecondaryAccess(); + void testAcquiringValueDefinedInPrimaryAndSecondaryAccess(); + void testGettingAggregateKeyList(); + void testGettingAggregateKeyListWithoutDuplicates(); + void testContainsKeyInPrimaryAccess(); + void testContainsKeyInSecondaryAccess(); + void testContainsKeyDefinedInPrimaryAndSecondaryAccess(); + void testValueChangedEmittedFromPrimaryAccess(); + void testValueChangedEmittedFromSecondaryAccess(); + void testValueChangedEmittedFromSharedKey(); + + /*! + * Connected to the valueChanged signal of the testAccess object + * This method will append the value changed signal contents to the + * valueChangedSignals list. + */ + void testAccessValueChanged(const QString &, const QVariant &); + +private: + MockDataStore *primaryAccess; + MockDataStore *secondaryAccess; + MDataAccess *testAccess; + QList< QPair<QString, QVariant> > valueChangedSignals; +}; + +#endif diff --git a/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.pro b/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.pro new file mode 100644 index 00000000..b2e9ec23 --- /dev/null +++ b/tests/ut_maggregatedataaccess/ut_maggregatedataaccess.pro @@ -0,0 +1,12 @@ +include(../common_top.pri) +include(../common_mextensions.pri) + +# unit test and unit +SOURCES += \ + ut_maggregatedataaccess.cpp + +# unit test and unit +HEADERS += \ + ut_maggregatedataaccess.h + +include(../common_bot.pri) |