diff options
author | Sergiy Dubovik <sergiy.dubovik@nokia.com> | 2010-07-28 10:46:55 +0300 |
---|---|---|
committer | Sergiy Dubovik <sergiy.dubovik@nokia.com> | 2010-07-28 10:46:55 +0300 |
commit | 32643df1eebe9a9f21a40fb5879822970a9f73ee (patch) | |
tree | dac2835d1c0e1c1d6d7c0151a50574184b4a84be /tests | |
parent | 7715f5ad7f697f587eebd62380d88ee9a3f111ad (diff) | |
parent | bde146b843e024c7425c4dd0076c2dc11ce6fc1c (diff) |
Merge commit 'refs/merge-requests/191' of git@gitorious.org:meegotouch/libmeegotouch into integration
Conflicts:
tests/tests.pro
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.pro | 4 | ||||
-rw-r--r-- | tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.cpp | 107 | ||||
-rw-r--r-- | tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.h | 46 | ||||
-rw-r--r-- | tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro | 31 | ||||
-rw-r--r-- | tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp | 134 | ||||
-rw-r--r-- | tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h | 46 | ||||
-rw-r--r-- | tests/ut_mremotethemedaemon/ut_mremotethemedaemon.pro | 19 | ||||
-rw-r--r-- | tests/ut_mtheme/ut_mtheme.cpp | 364 | ||||
-rw-r--r-- | tests/ut_mtheme/ut_mtheme.h | 51 | ||||
-rw-r--r-- | tests/ut_mtheme/ut_mtheme.pro | 41 |
10 files changed, 682 insertions, 161 deletions
diff --git a/tests/tests.pro b/tests/tests.pro index 1ddc531c..edd58631 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -56,8 +56,8 @@ SUBDIRS = \ ut_msliderview \ ut_mtextedit \ ut_mtexteditview \ -# ut_mtheme \ ut_mthemedaemonprotocol \ + ut_mtheme \ ut_mtoolbar \ ut_mtoolbarview \ ut_mwidget \ @@ -164,6 +164,8 @@ SUBDIRS = \ ut_mabstractitemmodel \ ut_phonenumberformatting \ ut_mlocationdatabase \ + ut_mlocalthemedaemon \ + ut_mremotethemedaemon \ # enable only when we have icu available diff --git a/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.cpp b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.cpp new file mode 100644 index 00000000..27a2e6a9 --- /dev/null +++ b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** +** +** 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_mlocalthemedaemon.h" + +#include <MApplication> +#include "mlocalthemedaemon.h" +#include <MTheme> +#include <QtTest> +#include <QSignalSpy> + +namespace { + const char *KnownIconId = "icon-m_framework-close"; +} + +void Ut_MLocalThemeDaemon::initTestCase() +{ + static int argc = 1; + static char *appName = (char*) "./Ut_MLocalThemeDaemon"; + m_app = new MApplication(argc, &appName); + + while (MTheme::hasPendingRequests()) { + usleep(10000); + QCoreApplication::processEvents(); + } + + m_themeDaemon = new MLocalThemeDaemon(appName); +} + +void Ut_MLocalThemeDaemon::cleanupTestCase() +{ + delete m_themeDaemon; + m_themeDaemon = 0; + + delete m_app; + m_app = 0; +} + +void Ut_MLocalThemeDaemon::testPixmapHandle() +{ + qRegisterMetaType<Qt::HANDLE>("Qt::HANDLE"); + + // MLocalThemeDaemon::pixmapHandle() for the local theme daemon is equal + // to MLocalThemeDaemon::pixmapHandleSync() and hence synchronous. + QSignalSpy spy(m_themeDaemon, SIGNAL(pixmapCreated(QString, QSize, Qt::HANDLE))); + m_themeDaemon->pixmapHandle(KnownIconId, QSize()); + QVERIFY(!spy.isEmpty()); + + m_themeDaemon->releasePixmap(KnownIconId, QSize()); +} + +void Ut_MLocalThemeDaemon::testPixmapHandleSync() +{ + qRegisterMetaType<Qt::HANDLE>("Qt::HANDLE"); + + QSignalSpy spy(m_themeDaemon, SIGNAL(pixmapCreated(QString, QSize, Qt::HANDLE))); + m_themeDaemon->pixmapHandleSync(KnownIconId, QSize()); + QVERIFY(!spy.isEmpty()); + + m_themeDaemon->releasePixmap(KnownIconId, QSize()); +} + +void Ut_MLocalThemeDaemon::testPixmapSearchList() +{ + // TODO: There is no easy way to verify whether the directory has been successfully + // added to be a new search path for pixmaps. Clarify whether this feature is used + // at all before investigating further work. + m_themeDaemon->addDirectoryToPixmapSearchList("foo", M::NonRecursive); + m_themeDaemon->clearPixmapSearchList(); +} + +void Ut_MLocalThemeDaemon::testThemeInheritanceChain() +{ + const QString currentTheme = m_themeDaemon->currentTheme(); + QVERIFY(!currentTheme.isEmpty()); + + const QStringList themeInheritanceChain = m_themeDaemon->themeInheritanceChain(); + QVERIFY(!themeInheritanceChain.isEmpty()); + QVERIFY(themeInheritanceChain.first().contains(currentTheme)); + QVERIFY(themeInheritanceChain.last().contains(QLatin1String("base"))); +} + +void Ut_MLocalThemeDaemon::testRegisterApplication() +{ + // TODO: There is no easy way to check whether registering the application + // has been successful. Verify whether it might be worth to extend/modify the API + // to being able to test this functionality. + m_themeDaemon->registerApplicationName("foo"); +} + +QTEST_MAIN(Ut_MLocalThemeDaemon) diff --git a/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.h b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.h new file mode 100644 index 00000000..d8dd967d --- /dev/null +++ b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.h @@ -0,0 +1,46 @@ +/*************************************************************************** +** +** 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_MLOCALTHEMEDAEMON_H +#define UT_MLOCALTHEMEDAEMON_H + +#include <QObject> + +class MApplication; +class MLocalThemeDaemon; + +class Ut_MLocalThemeDaemon : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void testPixmapHandle(); + void testPixmapHandleSync(); + void testPixmapSearchList(); + void testRegisterApplication(); + void testThemeInheritanceChain(); + +private: + MApplication *m_app; + MLocalThemeDaemon *m_themeDaemon; +}; +#endif diff --git a/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro new file mode 100644 index 00000000..0caf9adf --- /dev/null +++ b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro @@ -0,0 +1,31 @@ +include(../common_top.pri) + +TARGET = ut_mlocalthemedaemon + +INCLUDEPATH += $$MSRCDIR/corelib/theme +INCLUDEPATH += $$MSRCDIR/corelib/core + +SOURCES += \ + ut_mlocalthemedaemon.cpp \ + $$MSRCDIR/corelib/core/mcpumonitor.cpp \ + $$MSRCDIR/corelib/theme/mcommonpixmaps.cpp \ + $$MSRCDIR/corelib/theme/mimagedirectory.cpp \ + $$MSRCDIR/corelib/theme/mlocalthemedaemon.cpp \ + $$MSRCDIR/corelib/theme/mthemedaemon.cpp \ + $$MSRCDIR/corelib/theme/mthemedaemonclient.cpp \ + $$MSRCDIR/corelib/theme/mthemedaemonprotocol.cpp \ + $$MSRCDIR/corelib/theme/mthemeresourcemanager.cpp \ + +HEADERS += \ + ut_mlocalthemedaemon.h \ + $$MSRCDIR/corelib/core/mcpumonitor.h \ + $$MSRCDIR/corelib/theme/mcommonpixmaps.h \ + $$MSRCDIR/corelib/theme/mimagedirectory.h \ + $$MSRCDIR/corelib/theme/imthemedaemon.h \ + $$MSRCDIR/corelib/theme/mlocalthemedaemon.h \ + $$MSRCDIR/corelib/theme/mthemedaemon.h \ + $$MSRCDIR/corelib/theme/mthemedaemonprotocol.h \ + $$MSRCDIR/corelib/theme/mthemedaemonclient.h \ + $$MSRCDIR/corelib/theme/mthemeresourcemanager.h \ + +include(../common_bot.pri) diff --git a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp new file mode 100644 index 00000000..117be3d5 --- /dev/null +++ b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** +** +** 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_mremotethemedaemon.h" + +#include <MApplication> +#include "mremotethemedaemon.h" +#include "mremotethemedaemon_p.h" +#include <MTheme> +#include <QtTest> +#include <QSignalSpy> + +namespace { + const char *KnownIconId = "icon-m_framework-close"; +} + +void Ut_MRemoteThemeDaemon::initTestCase() +{ + static int argc = 1; + static char *appName = (char*) "./Ut_MRemoteThemeDaemon"; + m_app = new MApplication(argc, &appName); + + while (MTheme::hasPendingRequests()) { + usleep(10000); + QCoreApplication::processEvents(); + } + + m_themeDaemon = new MRemoteThemeDaemon(appName, 5000); +} + +void Ut_MRemoteThemeDaemon::cleanupTestCase() +{ + delete m_themeDaemon; + m_themeDaemon = 0; + + delete m_app; + m_app = 0; +} + +void Ut_MRemoteThemeDaemon::testPixmapHandle() +{ + qRegisterMetaType<Qt::HANDLE>("Qt::HANDLE"); + + // The signal pixmapCreated() will be emitted if the request could be fulfilled + // synchronously, otherwise pixmapChanged() will be emitted. + QSignalSpy createdSpy(m_themeDaemon, SIGNAL(pixmapCreated(QString, QSize, Qt::HANDLE))); + m_themeDaemon->pixmapHandle(KnownIconId, QSize()); + + bool gotPixmap = !createdSpy.isEmpty(); + if (!gotPixmap) { + QSignalSpy changedSpy(m_themeDaemon, SIGNAL(pixmapChanged(QString, QSize, Qt::HANDLE))); + while (m_themeDaemon->hasPendingRequests()) { + usleep(10000); + QCoreApplication::processEvents(); + } + gotPixmap = !changedSpy.isEmpty(); + } + + QVERIFY(gotPixmap); + + m_themeDaemon->releasePixmap(KnownIconId, QSize()); +} + +void Ut_MRemoteThemeDaemon::testPixmapHandleSync() +{ + qRegisterMetaType<Qt::HANDLE>("Qt::HANDLE"); + + QSignalSpy spy(m_themeDaemon, SIGNAL(pixmapCreated(QString, QSize, Qt::HANDLE))); + m_themeDaemon->pixmapHandleSync(KnownIconId, QSize()); + QVERIFY(!spy.isEmpty()); + + m_themeDaemon->releasePixmap(KnownIconId, QSize()); +} + +void Ut_MRemoteThemeDaemon::testPixmapSearchList() +{ + // TODO: There is no easy way to verify whether the directory has been successfully + // added to be a new search path for pixmaps. Clarify whether this feature is used + // at all before investigating further work. + + MRemoteThemeDaemonPrivate *d_ptr = m_themeDaemon->d_ptr; + const int oldSequenceCounter = int(d_ptr->sequenceCounter); + + m_themeDaemon->addDirectoryToPixmapSearchList("foo", M::NonRecursive); + QCOMPARE(int(d_ptr->sequenceCounter), oldSequenceCounter + 1); + + m_themeDaemon->clearPixmapSearchList(); + QCOMPARE(int(d_ptr->sequenceCounter), oldSequenceCounter + 2); +} + +void Ut_MRemoteThemeDaemon::testThemeInheritanceChain() +{ + const QString currentTheme = m_themeDaemon->currentTheme(); + QVERIFY(!currentTheme.isEmpty()); + + const QStringList themeInheritanceChain = m_themeDaemon->themeInheritanceChain(); + QVERIFY(!themeInheritanceChain.isEmpty()); + QVERIFY(themeInheritanceChain.first().contains(currentTheme)); + QVERIFY(themeInheritanceChain.last().contains(QLatin1String("base"))); +} + +void Ut_MRemoteThemeDaemon::testRegisterApplication() +{ + // TODO: There is no easy way to check whether registering the application + // has been successful. Verify whether it might be worth to extend/modify the API + // to being able to test this functionality. + + MRemoteThemeDaemonPrivate *d_ptr = m_themeDaemon->d_ptr; + const int oldSequenceCounter = int(d_ptr->sequenceCounter); + + m_themeDaemon->registerApplicationName("foo"); + QCOMPARE(int(d_ptr->sequenceCounter), oldSequenceCounter + 1); + + m_themeDaemon->registerApplicationName("foo"); + QCOMPARE(int(d_ptr->sequenceCounter), oldSequenceCounter + 2); +} + +QTEST_MAIN(Ut_MRemoteThemeDaemon) diff --git a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h new file mode 100644 index 00000000..b2cb6661 --- /dev/null +++ b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.h @@ -0,0 +1,46 @@ +/*************************************************************************** +** +** 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_MREMOTETHEMEDAEMON_H +#define UT_MREMOTETHEMEDAEMON_H + +#include <QObject> + +class MApplication; +class MRemoteThemeDaemon; + +class Ut_MRemoteThemeDaemon : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void testPixmapHandle(); + void testPixmapHandleSync(); + void testPixmapSearchList(); + void testRegisterApplication(); + void testThemeInheritanceChain(); + +private: + MApplication *m_app; + MRemoteThemeDaemon *m_themeDaemon; +}; +#endif diff --git a/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.pro b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.pro new file mode 100644 index 00000000..56227d88 --- /dev/null +++ b/tests/ut_mremotethemedaemon/ut_mremotethemedaemon.pro @@ -0,0 +1,19 @@ +include(../common_top.pri) + +TARGET = ut_mremotethemedaemon + +INCLUDEPATH += $$MSRCDIR/corelib/theme +INCLUDEPATH += $$MSRCDIR/corelib/core + +SOURCES += \ + ut_mremotethemedaemon.cpp \ + $$MSRCDIR/corelib/theme/mremotethemedaemon.cpp \ + $$MSRCDIR/corelib/theme/mthemedaemonprotocol.cpp \ + +HEADERS += \ + ut_mremotethemedaemon.h \ + $$MSRCDIR/corelib/theme/imthemedaemon.h \ + $$MSRCDIR/corelib/theme/mremotethemedaemon.h \ + $$MSRCDIR/corelib/theme/mthemedaemonprotocol.h \ + +include(../common_bot.pri) diff --git a/tests/ut_mtheme/ut_mtheme.cpp b/tests/ut_mtheme/ut_mtheme.cpp index a8f84b52..319d73e3 100644 --- a/tests/ut_mtheme/ut_mtheme.cpp +++ b/tests/ut_mtheme/ut_mtheme.cpp @@ -17,168 +17,310 @@ ** ****************************************************************************/ -#include <assert.h> - -#include <mpixmaploader_stub.h> -#include <mstylesheet_stub.h> -#include <mstylesheetparser_stub.h> -#include <mviewfactory_stub.h> -#include <mstyle_stub.h> -#include <mbuttoniconview_stub.h> -#include <mwidgetview_stub.h> -#include <mbuttonview_stub.h> -#include <msliderdotview_stub.h> -#include <mnavigationbarview_stub.h> -#include <mtoolbarview_stub.h> -#include <mapplicationmenuview_stub.h> - -#include <mtheme.h> - #include "ut_mtheme.h" -#include <X11/Xlib.h> -QImage::Format gQImageFormat = QImage::Format_Invalid; -XImage gImage; -QImage gQImage; -unsigned int gDepth; -int gBitsPerUnit; +#include "mtheme_p.h" + +#include <MApplication> +#include <MGConfItem> +#include <MLabel> +#include <MScalableImage> +#include <MTheme> + +#include <QEventLoop> +#include <QtTest> +#include <QString> +#include <QProcess> +#include <QSignalSpy> +namespace { + const char *KnownIconId = "meegotouch-combobox-indicator"; + const char *UnknownIconId = "xxx-unknown-icon-id"; +}; -Status XGetGeometry( - Display* /* display */, - Drawable /* drawable */, - Window* /* root_return */, - int* /* x_return */, - int* /* y_return */, - unsigned int* /* width_return */, - unsigned int* /* height_return */, - unsigned int* /* border_width_return */, - unsigned int *depth_return -) +void Ut_MTheme::initTestCase() { - *depth_return = gDepth; - qDebug() << "XGetGeometry() - called. Setting " << *depth_return << " as bit depth."; - return 1; + static int argc = 1; + static char *appName = (char*) "./Ut_MTheme"; + m_app = new MApplication(argc, &appName); + + while (MTheme::hasPendingRequests()) { + usleep(10000); + QCoreApplication::processEvents(); + } + + m_theme = MTheme::instance(); } -XImage *XGetImage( - Display* /* display */, - Drawable /* d */, - int /* x */, - int /* y */, - unsigned int /* width */, - unsigned int /* height */, - unsigned long /* plane_mask */, - int /* format */ -) +void Ut_MTheme::cleanupTestCase() { - qDebug() << "XGetImage() - called."; - return &gImage; + delete m_app; + m_app = 0; } - -int XBitmapUnit(Display * /*display*/) +void Ut_MTheme::testStyle() { - return gBitsPerUnit; + const MStyle *labelStyle1 = m_theme->style("MLabelStyle"); + QVERIFY(labelStyle1 != 0); + + const MStyle *labelStyle2 = m_theme->style("MLabelStyle", QString(), QString(), QString(), M::Landscape); + QVERIFY(labelStyle2 != 0); + + // Check overload behavior of MTheme::style() + QCOMPARE(labelStyle1, labelStyle2); + + const MStyle *labelStyle3 = m_theme->style("MLabelStyle", "MyButton", "active", "default", M::Landscape); + QVERIFY(labelStyle3 != 0); + + // Loading of invalid styles is not supported, qFatal() is triggered in this case + // const MStyle *invalidStyle = m_theme->style("InvalidStyle", "MyButton", "active", "default", M::Landscape); + // QVERIFY(invalidStyle == 0); + + m_theme->releaseStyle(labelStyle1); + m_theme->releaseStyle(labelStyle2); + m_theme->releaseStyle(labelStyle3); } +void Ut_MTheme::testThemeChangeCompleted() +{ + QSignalSpy spy(m_theme, SIGNAL(themeChangeCompleted())); + + MGConfItem themeNameItem("/meegotouch/theme/name"); + const QString currentThemeName = themeNameItem.value().toString(); + if (currentThemeName == QLatin1String("plankton")) { + themeNameItem.set("blanco"); + } else { + themeNameItem.set("plankton"); + } + + // Wait until the signal themeChangeCompleted() has been received + QEventLoop eventLoop; + connect(m_theme, SIGNAL(themeChangeCompleted()), &eventLoop, SLOT(quit())); + QTimer::singleShot(20000, &eventLoop, SLOT(quit())); // fallback if themeChangeCompleted() is not send + eventLoop.exec(); + + QCOMPARE(spy.count(), 1); + + // Reset theme again + themeNameItem.set(currentThemeName); + eventLoop.exec(); + QCOMPARE(spy.count(), 2); +} -QImage::QImage(const uchar *data, int width, int height, Format format) +void Ut_MTheme::testPixmap() { - Q_UNUSED(data); - Q_UNUSED(width); - Q_UNUSED(height); - Q_UNUSED(format); + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + + const QPixmap *pixmap = m_theme->pixmap(KnownIconId); + QVERIFY(pixmap != 0); + if (MTheme::hasPendingRequests()) { + QVERIFY(pixmap->size().isEmpty()); + QCOMPARE(spy.count(), 0); + } else { + QVERIFY(!pixmap->size().isEmpty()); + QCOMPARE(spy.count(), 1); + } + QVERIFY(isIconCached(KnownIconId, QSize())); + QCOMPARE(cachedIconCount(), 1); + + waitForPendingThemeRequests(); - qDebug() << "QImage::QImage() - called."; - gQImageFormat = format; + // Release icon + m_theme->releasePixmap(pixmap); + QVERIFY(!isIconCached(KnownIconId, pixmap->size())); + QCOMPARE(cachedIconCount(), 0); } -QImage::~QImage() +void Ut_MTheme::testPixmapWithSize() { + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + const QPixmap *fixedSizePixmap = m_theme->pixmap(KnownIconId, QSize(100, 150)); + QVERIFY(fixedSizePixmap != 0); + QCOMPARE(fixedSizePixmap->size(), QSize(100, 150)); + QCOMPARE(spy.count(), MTheme::hasPendingRequests() ? 0 : 1); + QVERIFY(isIconCached(KnownIconId, fixedSizePixmap->size())); + QCOMPARE(cachedIconCount(), 1); + + waitForPendingThemeRequests(); + + // Release icon + m_theme->releasePixmap(fixedSizePixmap); + QVERIFY(!isIconCached(KnownIconId, fixedSizePixmap->size())); + QCOMPARE(cachedIconCount(), 0); } -QImage &QImage::operator=(const QImage &) +void Ut_MTheme::testUnknownPixmap() { - qDebug() << "QImage::operator = () - called."; - return gQImage; + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + + const QPixmap *unknownPixmap = m_theme->pixmap(UnknownIconId); + QVERIFY(unknownPixmap != 0); + if (MTheme::hasPendingRequests()) { + QVERIFY(unknownPixmap->size().isEmpty()); + QCOMPARE(spy.count(), 0); + } else { + QVERIFY(!unknownPixmap->size().isEmpty()); + QCOMPARE(spy.count(), 1); + } + QVERIFY(isIconCached(UnknownIconId, QSize())); + QCOMPARE(cachedIconCount(), 1); + + waitForPendingThemeRequests(); + + // Release icon + m_theme->releasePixmap(unknownPixmap); + QVERIFY(!isIconCached(UnknownIconId, unknownPixmap->size())); + QCOMPARE(cachedIconCount(), 0); } -/* -QPixmap::QPixmap(const QPixmap &) +void Ut_MTheme::testPixmapCopy() { - qDebug() << "QPixmap::QPixmap() - called."; + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + + QPixmap *pixmap = m_theme->pixmapCopy(KnownIconId); + QVERIFY(pixmap != 0); + QVERIFY(!pixmap->size().isEmpty()); + QCOMPARE(spy.count(), 1); + QCOMPARE(cachedIconCount(), 0); + + m_theme->releasePixmap(pixmap); } -*/ -void Ut_MTheme::init() +void Ut_MTheme::testPixmapCopyWithSize() { - m_subject = MTheme::instance(); //new MTheme(); - gQImageFormat = QImage::Format_Invalid; - gDepth = 0; - gBitsPerUnit = 0; + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + + QPixmap *fixedSizePixmap = m_theme->pixmapCopy(KnownIconId, QSize(100, 150)); + QVERIFY(fixedSizePixmap != 0); + QCOMPARE(fixedSizePixmap->size(), QSize(100, 150)); + QCOMPARE(spy.count(), 1); + QCOMPARE(cachedIconCount(), 0); + + m_theme->releasePixmap(fixedSizePixmap); } -void Ut_MTheme::cleanupTestCase() +void Ut_MTheme::testUnknownPixmapCopy() { + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + + QPixmap *unknownPixmap = m_theme->pixmapCopy(UnknownIconId); + QVERIFY(unknownPixmap != 0); + QCOMPARE(unknownPixmap->size(), QSize(50, 50)); + QCOMPARE(spy.count(), 1); + QCOMPARE(cachedIconCount(), 0); + + m_theme->releasePixmap(unknownPixmap); } -void Ut_MTheme::initTestCase() +void Ut_MTheme::testPixmapCaching() { + QCOMPARE(cachedIconCount(), 0); + + const QPixmap *pixmap = m_theme->pixmap(KnownIconId); + QVERIFY(isIconCached(KnownIconId, QSize())); + QCOMPARE(cachedIconCount(), 1); + + const QPixmap *fixedSizePixmap = m_theme->pixmap(KnownIconId, QSize(100, 150)); + QVERIFY(isIconCached(KnownIconId, QSize(100, 150))); + QCOMPARE(cachedIconCount(), 2); + + const QPixmap *unknownPixmap = m_theme->pixmap(UnknownIconId); + QVERIFY(isIconCached(UnknownIconId, QSize())); + QCOMPARE(cachedIconCount(), 3); + + m_theme->releasePixmap(pixmap); + QVERIFY(!isIconCached(KnownIconId, QSize())); + QCOMPARE(cachedIconCount(), 2); + + m_theme->releasePixmap(fixedSizePixmap); + QVERIFY(!isIconCached(KnownIconId, QSize(100, 150))); + QCOMPARE(cachedIconCount(), 1); + + m_theme->releasePixmap(unknownPixmap); + QVERIFY(!isIconCached(UnknownIconId, QSize())); + QCOMPARE(cachedIconCount(), 0); } -void Ut_MTheme::loadCSS() +void Ut_MTheme::testScalableImage() { - // set MStyleSheetParser::load() to return true - gMStyleSheetParserStub->stubSetReturnValue<bool>("load", true); + const MScalableImage *image = m_theme->scalableImage(KnownIconId, 1, 2, 3, 4); + QVERIFY(image != 0); + + int left = -1; + int right = -1; + int top = -1; + int bottom = -1; + + image->borders(&left, &right, &top, &bottom); + QCOMPARE(left, 1); + QCOMPARE(right, 2); + QCOMPARE(top, 3); + QCOMPARE(bottom, 4); + + const MScalableImage *unknownImage = m_theme->scalableImage(UnknownIconId, 1, 2, 3, 4); + QVERIFY(unknownImage != 0); - QString myFilename("myCSSFile"); - m_subject->loadCSS(myFilename); + left = right = top = bottom = -1; + unknownImage->borders(&left, &right, &top, &bottom); + QCOMPARE(left, 1); + QCOMPARE(right, 2); + QCOMPARE(top, 3); + QCOMPARE(bottom, 4); - QCOMPARE(gMStyleSheetParserStub->stubLastParameters<const QString &>(0), myFilename); + m_theme->releaseScalableImage(image); + m_theme->releaseScalableImage(unknownImage); } -#if QT_VERSION < 0x040500 -void Ut_MTheme::testPixmapCreationWithAllBitDepths() +void Ut_MTheme::testView() { - QPixmap *pixmap; + MLabel label(0, 0); + MWidgetView *view = m_theme->view(&label); + QVERIFY(view != 0); +} - // Test pixmap from handle with 8 bit pixmap - gDepth = 8; - pixmap = m_subject->pixmapFromHandle(8); - QCOMPARE(gQImageFormat, QImage::Format_Indexed8); +bool Ut_MTheme::isIconCached(const QString &id, const QSize &size) const +{ + const QSize usedSize = size.isEmpty() ? QSize(0, 0) : size; - // Test pixmap from handle with 16 bit pixmap - gDepth = 16; - pixmap = m_subject->pixmapFromHandle(16); - QCOMPARE(gQImageFormat, QImage::Format_RGB16); + MThemePrivate *d_ptr = m_theme->d_ptr; - // Test pixmap from handle with 24 bit pixmap, no padding - gDepth = 24; - gBitsPerUnit = 24; - pixmap = m_subject->pixmapFromHandle(24); - QCOMPARE(gQImageFormat, QImage::Format_RGB888); + QHash<QString, CachedPixmap> pixmapIdentifiers = d_ptr->pixmapIdentifiers; + QHashIterator<QString, CachedPixmap> it(pixmapIdentifiers); + while (it.hasNext()) { + it.next(); + if (it.value().imageId == id) { + const QString sizeString = QLatin1Char('_') + + QString::number(usedSize.width()) + + QLatin1Char('_') + + QString::number(usedSize.height()); + if (it.key().endsWith(sizeString)) { + return true; + } + } + } - // Test pixmap from handle with 24 bit pixmap, padding - gDepth = 24; - gBitsPerUnit = 32; - pixmap = m_subject->pixmapFromHandle(24); - QCOMPARE(gQImageFormat, QImage::Format_RGB32); - gBitsPerUnit = 0; // reset + return false; +} - // Test pixmap from handle with 32 bit pixmap - gDepth = 32; - pixmap = m_subject->pixmapFromHandle(32); - QCOMPARE(gQImageFormat, QImage::Format_ARGB32); +int Ut_MTheme::cachedIconCount() const +{ + MThemePrivate *d_ptr = m_theme->d_ptr; + return d_ptr->pixmapIdentifiers.count(); } -#endif // QT_VERSION >= 0x040500 -void Ut_MTheme::cleanup() +void Ut_MTheme::waitForPendingThemeRequests() { - // Don't delete, it's a singleton! - //delete m_subject; - //m_subject = 0; + if (MTheme::hasPendingRequests()) { + QSignalSpy spy(m_theme, SIGNAL(pixmapRequestsFinished())); + + QEventLoop eventLoop; + connect(m_theme, SIGNAL(pixmapRequestsFinished()), &eventLoop, SLOT(quit())); + QTimer::singleShot(5000, &eventLoop, SLOT(quit())); // fallback if pixmapRequestsFinished() is not send + eventLoop.exec(); + + QCOMPARE(spy.count(), 1); + } } QTEST_MAIN(Ut_MTheme) diff --git a/tests/ut_mtheme/ut_mtheme.h b/tests/ut_mtheme/ut_mtheme.h index db0ffedc..96cf62ee 100644 --- a/tests/ut_mtheme/ut_mtheme.h +++ b/tests/ut_mtheme/ut_mtheme.h @@ -21,28 +21,53 @@ #define UT_MTHEME_H #include <QObject> -#include <QtTest/QtTest> - -#include "mtheme.h" +class MApplication; +class MTheme; +class QSize; class Ut_MTheme : public QObject { Q_OBJECT private slots: - void init(); // Executed before each test function - void cleanup(); // Executed after each test function - void initTestCase(); // Executed before all - void cleanupTestCase(); // Executed after all tests have been run + void initTestCase(); + void cleanupTestCase(); + + void testStyle(); + void testThemeChangeCompleted(); + + void testPixmap(); + void testPixmapWithSize(); + void testUnknownPixmap(); + + void testPixmapCopy(); + void testPixmapCopyWithSize(); + void testUnknownPixmapCopy(); - // Actual test functions - void loadCSS(); -#if QT_VERSION < 0x040500 - void testPixmapCreationWithAllBitDepths(); -#endif // QT_VERSION < 0x040500 + void testPixmapCaching(); + + void testScalableImage(); + void testView(); private: - MTheme *m_subject; + /** + * @return True, if the given icon has been cached in the theme daemon. + * + * @param id Identifier of the icon that has been requested with + * MTheme::pixmap() or pixmapCopy() + * @param size Size that has been requested (not the actual size of the pixmap!). + */ + bool isIconCached(const QString &id, const QSize &size) const; + + int cachedIconCount() const; + + /** + * Waits until the signal pixmapRequestsFinished() has been emitted. + */ + void waitForPendingThemeRequests(); + + MTheme *m_theme; + MApplication *m_app; }; #endif diff --git a/tests/ut_mtheme/ut_mtheme.pro b/tests/ut_mtheme/ut_mtheme.pro index cf851acb..3733e0cc 100644 --- a/tests/ut_mtheme/ut_mtheme.pro +++ b/tests/ut_mtheme/ut_mtheme.pro @@ -1,45 +1,14 @@ include(../common_top.pri) -SOURCES += \ - ut_mtheme.cpp \ -# $$MSRCDIR/mtheme.cpp \ -# $$MSRCDIR/mstyledata.cpp \ -# $$MSRCDIR/mstyledescription.cpp \ +TARGET = ut_mtheme -SOURCES += \ - $$STUBSDIR/stubbase.cpp \ +INCLUDEPATH += $$MSRCDIR/corelib/theme -HEADERS += \ - ut_mtheme.h \ -# $$MSRCDIR/mtheme.h \ +SOURCES += \ + ut_mtheme.cpp \ HEADERS += \ - $$STUBSDIR/stubbase.h \ + ut_mtheme.h \ -HEADERS += \ -# $$MSRCDIR/mapplicationmenuview.h \ -# $$MSRCDIR/mbuttoniconview.h \ -# $$MSRCDIR/mbuttonview.h \ -# $$MSRCDIR/mnavigationbarview.h \ -# $$MSRCDIR/mpixmaploader.h \ -# $$MSRCDIR/msliderdotview.h \ -# $$MSRCDIR/mstyle.h \ -# $$MSRCDIR/mstylesheet.h \ -# $$MSRCDIR/mstylesheetparser.h \ -# $$MSRCDIR/mtoolbarview.h \ -# $$MSRCDIR/mviewfactory.h \ -# $$MSRCDIR/mwidgetview.h \ - $$STUBSDIR/mapplicationmenuview_stub.h \ - $$STUBSDIR/mbuttoniconview_stub.h \ - $$STUBSDIR/mbuttonview_stub.h \ - $$STUBSDIR/mnavigationbarview_stub.h \ - $$STUBSDIR/mpixmaploader_stub.h \ - $$STUBSDIR/msliderdotview_stub.h \ - $$STUBSDIR/mstylesheetparser_stub.h \ - $$STUBSDIR/mstylesheet_stub.h \ - $$STUBSDIR/mstyle_stub.h \ - $$STUBSDIR/mtoolbarview_stub.h \ - $$STUBSDIR/mviewfactory_stub.h \ - $$STUBSDIR/mwidgetview_stub.h \ include(../common_bot.pri) |