diff options
author | Daniel d'Andrada <daniel.dandrada@nokia.com> | 2010-11-19 17:09:48 +0200 |
---|---|---|
committer | Daniel d'Andrada <daniel.dandrada@nokia.com> | 2010-11-23 11:23:19 +0200 |
commit | 55261fec9575ceaf96c6da80e80e3a07eee9f799 (patch) | |
tree | cb83ae8be7a1e50c49988fc31d2181ce8052c474 /tests | |
parent | 5a3a0084d29ec98f6ee3f5967663f974c596cc57 (diff) |
Changes: Refactoring MNavigationBar "isEmpty" property
RevBy: Marcin Miklas
Details: MNavigationBar.property("isEmpty") was returning "true" even if
the navigation bar was holding a pupulated toolbar.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.pro | 1 | ||||
-rw-r--r-- | tests/ut_mdynamicpropertywatcher/.gitignore | 1 | ||||
-rw-r--r-- | tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.cpp | 55 | ||||
-rw-r--r-- | tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.h | 37 | ||||
-rw-r--r-- | tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.pro | 15 | ||||
-rw-r--r-- | tests/ut_mnavigationbarview/ut_mnavigationbarview.cpp | 157 | ||||
-rw-r--r-- | tests/ut_mnavigationbarview/ut_mnavigationbarview.h | 5 |
7 files changed, 264 insertions, 7 deletions
diff --git a/tests/tests.pro b/tests/tests.pro index deeae2ba..65b5071b 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -186,6 +186,7 @@ SUBDIRS = \ ut_mremotethemedaemon \ ut_mswiperecognizer \ ut_mstylablewidget \ + ut_mdynamicpropertywatcher \ # enable only when we have icu available diff --git a/tests/ut_mdynamicpropertywatcher/.gitignore b/tests/ut_mdynamicpropertywatcher/.gitignore new file mode 100644 index 00000000..09ddb5e3 --- /dev/null +++ b/tests/ut_mdynamicpropertywatcher/.gitignore @@ -0,0 +1 @@ +ut_mdynamicpropertywatcher diff --git a/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.cpp b/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.cpp new file mode 100644 index 00000000..ffea0014 --- /dev/null +++ b/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.cpp @@ -0,0 +1,55 @@ +/*************************************************************************** +** +** 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 "ut_mdynamicpropertywatcher.h" +#include <mdynamicpropertywatcher.h> + +void Ut_MDynamicPropertyWatcher::testDontEmitSignalIfPropertySetToSameValue() +{ + MDynamicPropertyWatcher propertyWatcher; + QObject object; + QSignalSpy propertyChangedSpy(&propertyWatcher, SIGNAL(propertyChanged())); + + propertyWatcher.watch(&object); + propertyWatcher.setPropertyName("foo"); + + object.setProperty("foo", true); + QCOMPARE(propertyChangedSpy.count(), 1); + + object.setProperty("foo", true); + QCOMPARE(propertyChangedSpy.count(), 1); // no new signal emitted +} + +void Ut_MDynamicPropertyWatcher::testEmitSignalIfPropertySetToDifferentValue() +{ + MDynamicPropertyWatcher propertyWatcher; + QObject object; + QSignalSpy propertyChangedSpy(&propertyWatcher, SIGNAL(propertyChanged())); + + propertyWatcher.watch(&object); + propertyWatcher.setPropertyName("foo"); + + object.setProperty("foo", true); + QCOMPARE(propertyChangedSpy.count(), 1); + + object.setProperty("foo", false); + QCOMPARE(propertyChangedSpy.count(), 2); +} + +QTEST_MAIN(Ut_MDynamicPropertyWatcher)
\ No newline at end of file diff --git a/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.h b/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.h new file mode 100644 index 00000000..ef6a7c5a --- /dev/null +++ b/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.h @@ -0,0 +1,37 @@ +/*************************************************************************** +** +** 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_MDYNAMICPROPERTYWATCHER_H +#define UT_MDYNAMICPROPERTYWATCHER_H + +#include <QtTest/QtTest> +#include <QObject> + +class Ut_MDynamicPropertyWatcher : public QObject +{ + Q_OBJECT + +private slots: + void testDontEmitSignalIfPropertySetToSameValue(); + void testEmitSignalIfPropertySetToDifferentValue(); + +private: +}; + +#endif diff --git a/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.pro b/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.pro new file mode 100644 index 00000000..0e9f2f8b --- /dev/null +++ b/tests/ut_mdynamicpropertywatcher/ut_mdynamicpropertywatcher.pro @@ -0,0 +1,15 @@ +include(../common_top.pri) + +INCLUDEPATH += $$MSRCDIR/corelib/core + +TARGET = ut_mdynamicpropertywatcher + +SOURCES += \ + ut_mdynamicpropertywatcher.cpp \ + $$MSRCDIR/corelib/core/mdynamicpropertywatcher.cpp \ + +HEADERS += \ + ut_mdynamicpropertywatcher.h \ + $$MSRCDIR/corelib/core/mdynamicpropertywatcher.h \ + +include(../common_bot.pri) diff --git a/tests/ut_mnavigationbarview/ut_mnavigationbarview.cpp b/tests/ut_mnavigationbarview/ut_mnavigationbarview.cpp index fecbf9c8..bdca9bbd 100644 --- a/tests/ut_mnavigationbarview/ut_mnavigationbarview.cpp +++ b/tests/ut_mnavigationbarview/ut_mnavigationbarview.cpp @@ -23,13 +23,23 @@ #include <QGraphicsLayout> #include <MLinearLayoutPolicy> +#include <mnavigationbarstyle.h> +#include <MToolBar> + +Q_DECLARE_METATYPE(MNavigationBarModel::EscapeButtonModeEnum) void Ut_MNavigationBarView::init() { + controller = new MNavigationBar(); + subject = new MNavigationBarView(controller); + controller->setView(subject); + model = controller->model(); } void Ut_MNavigationBarView::cleanup() { + delete controller; + controller = 0; } void Ut_MNavigationBarView::initTestCase() @@ -38,17 +48,11 @@ void Ut_MNavigationBarView::initTestCase() static char *app_name[1] = { (char *) "./ut_mnavigationbarview" }; app = new MApplication(argc, app_name); - controller = new MNavigationBar(); - subject = new MNavigationBarView(controller); - controller->setView(subject); - model = controller->model(); + } void Ut_MNavigationBarView::cleanupTestCase() { - delete controller; - controller = 0; - delete app; app = 0; } @@ -92,4 +96,143 @@ void Ut_MNavigationBarView::testCustomContentPolicySelection() delete customContent; } +void Ut_MNavigationBarView::testIsEmptyProperty_data() +{ + QTest::addColumn<bool>("hasTitle"); + QTest::addColumn<bool>("hasCloseButton"); + QTest::addColumn<bool>("hasToolBar"); + QTest::addColumn<bool>("toolBarIsEmpty"); + QTest::addColumn<MNavigationBarModel::EscapeButtonModeEnum>("escapeButtonMode"); + QTest::addColumn<bool>("hasCustomContent"); + QTest::addColumn<bool>("isEmptyExpectedValue"); + + QTest::newRow("not empty when with custom content") + << false // hasTitle + << false // hasCloseButton + << false // hasToolBar + << true // toolBarIsEmpty + << MNavigationBarModel::EscapeButtonClose // escapeButtonMode + << true // hasCustomContent + << false /* isEmptyExpectedValue */; + + QTest::newRow("not empty when it has only a title") + << true // hasTitle + << false // hasCloseButton + << false // hasToolBar + << true // toolBarIsEmpty + << MNavigationBarModel::EscapeButtonClose // escapeButtonMode + << false // hasCustomContent + << false /* isEmptyExpectedValue */; + + QTest::newRow("empty when there's not even a close button") + << false // hasTitle + << false // hasCloseButton + << false // hasToolBar + << true // toolBarIsEmpty + << MNavigationBarModel::EscapeButtonClose // escapeButtonMode + << false // hasCustomContent + << true /* isEmptyExpectedValue */; + + QTest::newRow("not empty when there's no close button but we are in back mode") + << false // hasTitle + << false // hasCloseButton + << false // hasToolBar + << true // toolBarIsEmpty + << MNavigationBarModel::EscapeButtonBack // escapeButtonMode + << false // hasCustomContent + << false /* isEmptyExpectedValue */; + + QTest::newRow("not empty when there's only a populated tool bar") + << false // hasTitle + << false // hasCloseButton + << true // hasToolBar + << false // toolBarIsEmpty + << MNavigationBarModel::EscapeButtonClose // escapeButtonMode + << false // hasCustomContent + << true /* isEmptyExpectedValue */; + + QTest::newRow("empty when there's only an empty tool bar") + << false // hasTitle + << false // hasCloseButton + << true // hasToolBar + << true // toolBarIsEmpty + << MNavigationBarModel::EscapeButtonClose // escapeButtonMode + << false // hasCustomContent + << true /* isEmptyExpectedValue */; +} + +void Ut_MNavigationBarView::testIsEmptyProperty() +{ + MToolBar *toolBar = 0; + QFETCH(bool, hasTitle); + QFETCH(bool, hasCloseButton); + QFETCH(bool, hasToolBar); + QFETCH(bool, toolBarIsEmpty); + QFETCH(MNavigationBarModel::EscapeButtonModeEnum, escapeButtonMode); + QFETCH(bool, hasCustomContent); + QFETCH(bool, isEmptyExpectedValue); + + MNavigationBarStyle *style = (MNavigationBarStyle *)subject->style().operator->(); + + style->setHasTitle(hasTitle); + style->setHasCloseButton(hasCloseButton); + subject->applyStyle(); + + if (hasToolBar) { + toolBar = new MToolBar; + toolBar->setProperty("isEmpty", toolBarIsEmpty); + model->setToolBar(toolBar); + } + + model->setEscapeButtonMode(escapeButtonMode); + + if (hasCustomContent) { + model->setCustomContent(new QGraphicsWidget); + } else { + model->setCustomContent(0); + } + + QCOMPARE(controller->property("isEmpty").toBool(), isEmptyExpectedValue); + + // clean up + if (toolBar) { + model->setToolBar(0); + delete toolBar; + } +} + +void Ut_MNavigationBarView::testDockedToolBarChangingItsIsEmptyProperty() +{ + MToolBar *toolBar = new MToolBar; + MNavigationBarStyle *style = (MNavigationBarStyle *)subject->style().operator->(); + + style->setHasTitle(false); + style->setHasCloseButton(false); + subject->applyStyle(); + + model->setToolBar(toolBar); + model->setEscapeButtonMode(MNavigationBarModel::EscapeButtonClose); + + // Since navigation bar is populated only by its docked toolbar, its isEmpty + // property will follow toolbar's one. + + toolBar->setProperty("isEmpty", true); + QCOMPARE(controller->property("isEmpty").toBool(), true); + + toolBar->setProperty("isEmpty", false); + QCOMPARE(controller->property("isEmpty").toBool(), false); + + toolBar->setProperty("isEmpty", true); + QCOMPARE(controller->property("isEmpty").toBool(), true); + + model->setToolBar(0); + toolBar->setProperty("isEmpty", false); + + // tool bar is no longer docked, thus navigation bar should no longer follow it + QCOMPARE(controller->property("isEmpty").toBool(), true); + + // clean up + delete toolBar; +} + QTEST_APPLESS_MAIN(Ut_MNavigationBarView) diff --git a/tests/ut_mnavigationbarview/ut_mnavigationbarview.h b/tests/ut_mnavigationbarview/ut_mnavigationbarview.h index 37c7ed84..d00cb24f 100644 --- a/tests/ut_mnavigationbarview/ut_mnavigationbarview.h +++ b/tests/ut_mnavigationbarview/ut_mnavigationbarview.h @@ -39,6 +39,11 @@ private slots: void testCustomContentOwnershipTransfer(); void testCustomContentPolicySelection(); + // test "isEmpty" property + void testIsEmptyProperty(); + void testIsEmptyProperty_data(); + void testDockedToolBarChangingItsIsEmptyProperty(); + private: MNavigationBarView *subject; MNavigationBar *controller; |