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_mapplicationpage | |
parent | 8832674482d3b9a7fcf77b0cfdcb8e6fe4960b4d (diff) |
Changes: Renamed dui to meegotouch
By: Holger, Daniel, Janne
RevBy: Tomas, Holger
Diffstat (limited to 'tests/ut_mapplicationpage')
-rw-r--r-- | tests/ut_mapplicationpage/.gitignore | 1 | ||||
-rw-r--r-- | tests/ut_mapplicationpage/ut_mapplicationpage.cpp | 226 | ||||
-rw-r--r-- | tests/ut_mapplicationpage/ut_mapplicationpage.h | 67 | ||||
-rw-r--r-- | tests/ut_mapplicationpage/ut_mapplicationpage.pro | 11 |
4 files changed, 305 insertions, 0 deletions
diff --git a/tests/ut_mapplicationpage/.gitignore b/tests/ut_mapplicationpage/.gitignore new file mode 100644 index 00000000..bbc5e8b8 --- /dev/null +++ b/tests/ut_mapplicationpage/.gitignore @@ -0,0 +1 @@ +ut_duiapplicationpage diff --git a/tests/ut_mapplicationpage/ut_mapplicationpage.cpp b/tests/ut_mapplicationpage/ut_mapplicationpage.cpp new file mode 100644 index 00000000..eda35f5e --- /dev/null +++ b/tests/ut_mapplicationpage/ut_mapplicationpage.cpp @@ -0,0 +1,226 @@ +/*************************************************************************** +** +** 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_mapplicationpage.h" + +#include <MApplicationWindow> +#include <MApplication> +#include "mapplicationpage_p.h" +#include <MSceneManager> + +#include <MPannableViewport> +#include <MAction> +#include <MButton> +#include <MLayout> +#include <MGridLayoutPolicy> + +#include "mondisplaychangeevent.h" + +void Ut_MApplicationPage::initTestCase() +{ + static int argc = 1; + static char *app_name[1] = { (char *) "./ut_mapplicationpage" }; + app = new MApplication(argc, app_name); + appWin = new MApplicationWindow; + + qRegisterMetaType<MApplicationPage *>(); + qRegisterMetaType<MEscapeButtonPanelModel::EscapeMode>(); +} + +void Ut_MApplicationPage::cleanupTestCase() +{ + delete appWin; + delete app; +} + +void Ut_MApplicationPage::init() +{ + m_subject = new MApplicationPage; +} + +void Ut_MApplicationPage::cleanup() +{ + // important: testCentralWidget deletes m_subject on its own + if (m_subject) { + delete m_subject; + m_subject = 0; + } +} + +void Ut_MApplicationPage::testInitialValues() +{ + QCOMPARE(m_subject->title(), QString()); + QCOMPARE(m_subject->isContentCreated(), false); + QVERIFY(m_subject->centralWidget()); + + QCOMPARE(m_subject->isPannable(), true); + QCOMPARE(m_subject->escapeMode(), MApplicationPageModel::EscapeAuto); + QCOMPARE(m_subject->rememberPosition(), true); +} + +void Ut_MApplicationPage::testProperties() +{ + QString title("Title of the page"); + bool pannable = true; + Qt::Orientations panningDirection = Qt::Horizontal | Qt::Vertical; + bool autoMarginsForComponents = true; + MApplicationPageModel::PageEscapeMode escapeMode = MApplicationPageModel::EscapeManualBack; + bool rememberPosition = false; + + m_subject->setTitle(title); + QCOMPARE(m_subject->title(), title); + m_subject->setPannable(pannable); + QCOMPARE(m_subject->isPannable(), pannable); + m_subject->setPanningDirection(panningDirection); + QCOMPARE(m_subject->panningDirection(), panningDirection); + m_subject->setAutoMarginsForComponentsEnabled(autoMarginsForComponents); + QCOMPARE(m_subject->autoMarginsForComponentsEnabled(), autoMarginsForComponents); + m_subject->setEscapeMode(escapeMode); + QCOMPARE(m_subject->escapeMode(), escapeMode); + m_subject->setRememberPosition(rememberPosition); + QCOMPARE(m_subject->rememberPosition(), rememberPosition); +} + +void Ut_MApplicationPage::testCentralWidget() +{ + QPointer<MWidget> widget = new MWidget; + m_subject->setCentralWidget(widget); + QCOMPARE(m_subject->centralWidget(), widget.data()); + + // remove the current central widget and verify that it has been deleted + m_subject->setCentralWidget(0); + QCOMPARE(m_subject->centralWidget(), (MWidget *) 0); + QVERIFY(widget.isNull()); + + widget = new MWidget; + m_subject->setCentralWidget(widget); + QCOMPARE(m_subject->centralWidget(), widget.data()); + + // delete the page to see if the central widget is deleted + delete m_subject; + m_subject = 0; + QVERIFY(widget.isNull()); +} + +void Ut_MApplicationPage::testCreateContent() +{ + QVERIFY(!m_subject->isContentCreated()); + m_subject->createContent(); + QVERIFY(m_subject->isContentCreated()); +} + +void Ut_MApplicationPage::testPageTitleChanged() +{ + qRegisterMetaType< QList<const char *> >("QList<const char *>"); + + QSignalSpy spy(m_subject->model(), SIGNAL(modified(QList<const char *>))); + QString title("Title!"); + + m_subject->setTitle(m_subject->title()); + QCOMPARE(spy.count(), 0); + m_subject->setTitle(title); + QCOMPARE(spy.count(), 1); + QCOMPARE(m_subject->model()->title(), title); + m_subject->setTitle(title); + QCOMPARE(spy.count(), 1); + m_subject->setTitle(QString()); + QCOMPARE(spy.count(), 2); + QCOMPARE(m_subject->model()->title(), QString()); +} + +void Ut_MApplicationPage::testRememberPosition() +{ + m_subject->setRememberPosition(true); + m_subject->d_func()->pannableViewPort->setPosition(QPointF(0, 10)); + appWin->sceneManager()->appearSceneWindowNow(m_subject); + QCOMPARE(m_subject->d_func()->pannableViewPort->position() + QPointF(10, 10), QPointF(10, 20)); + QCOMPARE(m_subject->d_func()->pannableViewPort->physics()->position() + QPointF(10, 10), QPointF(10, 20)); +} + +void Ut_MApplicationPage::testForgetPosition() +{ + m_subject->setRememberPosition(false); + m_subject->d_func()->pannableViewPort->setPosition(QPointF(0, 10)); + appWin->sceneManager()->appearSceneWindowNow(m_subject); + QCOMPARE(m_subject->d_func()->pannableViewPort->position() + QPointF(10, 10), QPointF(10, 10)); + QCOMPARE(m_subject->d_func()->pannableViewPort->physics()->position() + QPointF(10, 10), QPointF(10, 10)); +} + +void Ut_MApplicationPage::testActionUpdated() +{ + m_subject->clearActions(); + QSignalSpy spy(m_subject, SIGNAL(actionUpdated(QActionEvent *))); + QCOMPARE(spy.count(), 0); + + m_subject->addAction(new MAction("test application page", m_subject)); + QCOMPARE(spy.count(), 1); + + m_subject->clearActions(); + QCOMPARE(spy.count(), 2); +} + +void Ut_MApplicationPage::testDefaultComponentDisplayModes() +{ + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::NavigationBar), MApplicationPageModel::Show); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::HomeButton), MApplicationPageModel::Show); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::EscapeButton), MApplicationPageModel::Show); +} + +void Ut_MApplicationPage::testSettingComponentsDisplayModes() +{ + MApplicationPageModel *model = m_subject->model(); + + m_subject->setComponentsDisplayMode(MApplicationPage::NavigationBar, MApplicationPageModel::Hide); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::NavigationBar), MApplicationPageModel::Hide); + QCOMPARE(model->navigationBarDisplayMode(), MApplicationPageModel::Hide); + + m_subject->setComponentsDisplayMode(MApplicationPage::HomeButton, MApplicationPageModel::AutoHide); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::HomeButton), MApplicationPageModel::AutoHide); + QCOMPARE(model->homeButtonDisplayMode(), MApplicationPageModel::AutoHide); +} + +void Ut_MApplicationPage::testSettingMultipleComponentsDisplayModes() +{ + MApplicationPageModel *model = m_subject->model(); + + m_subject->setComponentsDisplayMode(MApplicationPage::NavigationBar | MApplicationPage::HomeButton, + MApplicationPageModel::Hide); + + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::NavigationBar), MApplicationPageModel::Hide); + QCOMPARE(model->navigationBarDisplayMode(), MApplicationPageModel::Hide); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::HomeButton), MApplicationPageModel::Hide); + QCOMPARE(model->homeButtonDisplayMode(), MApplicationPageModel::Hide); +} + +void Ut_MApplicationPage::testSettingAllComponentsDisplayMode() +{ + m_subject->setComponentsDisplayMode(MApplicationPage::AllComponents, MApplicationPageModel::Hide); + + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::NavigationBar), MApplicationPageModel::Hide); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::HomeButton), MApplicationPageModel::Hide); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::EscapeButton), MApplicationPageModel::Hide); + + m_subject->setComponentsDisplayMode(MApplicationPage::AllComponents, MApplicationPageModel::Show); + + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::NavigationBar), MApplicationPageModel::Show); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::HomeButton), MApplicationPageModel::Show); + QCOMPARE(m_subject->componentDisplayMode(MApplicationPage::EscapeButton), MApplicationPageModel::Show); +} + +QTEST_APPLESS_MAIN(Ut_MApplicationPage) diff --git a/tests/ut_mapplicationpage/ut_mapplicationpage.h b/tests/ut_mapplicationpage/ut_mapplicationpage.h new file mode 100644 index 00000000..28dca4dc --- /dev/null +++ b/tests/ut_mapplicationpage/ut_mapplicationpage.h @@ -0,0 +1,67 @@ +/*************************************************************************** +** +** 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_MSCENEWINDOW_H +#define UT_MSCENEWINDOW_H + +#include <QtTest/QtTest> +#include <QObject> +#include <MApplicationPage> + +#define MAX_PARAMS 10 + +class MApplication; +class MApplicationWindow; + +Q_DECLARE_METATYPE(MApplicationPage *); +Q_DECLARE_METATYPE(MEscapeButtonPanelModel::EscapeMode); + +class Ut_MApplicationPage : public QObject +{ + Q_OBJECT + +private slots: + void init(); + void cleanup(); + void initTestCase(); + void cleanupTestCase(); + + void testInitialValues(); + void testProperties(); + void testCentralWidget(); + void testCreateContent(); + void testPageTitleChanged(); + void testRememberPosition(); + void testForgetPosition(); + void testActionUpdated(); + void testDefaultComponentDisplayModes(); + void testSettingComponentsDisplayModes(); + void testSettingMultipleComponentsDisplayModes(); + void testSettingAllComponentsDisplayMode(); + +private: + MApplicationPage *m_subject; + MApplicationWindow *appWin; + MApplication *app; + +}; + +//Q_DECLARE_METATYPE(MApplicationPage*); + +#endif diff --git a/tests/ut_mapplicationpage/ut_mapplicationpage.pro b/tests/ut_mapplicationpage/ut_mapplicationpage.pro new file mode 100644 index 00000000..ed001a83 --- /dev/null +++ b/tests/ut_mapplicationpage/ut_mapplicationpage.pro @@ -0,0 +1,11 @@ +include(../common_top.pri) +TARGET = ut_mapplicationpage +INCLUDEPATH += $$MSRCDIR/corelib/widgets \ + +SOURCES += \ + ut_mapplicationpage.cpp + +HEADERS += \ + ut_mapplicationpage.h + +include(../common_bot.pri) |