From da73676c8a5af66b55523a9cdfbfbea2baa88a2a Mon Sep 17 00:00:00 2001 From: Tomas Junnonen Date: Mon, 12 Apr 2010 13:50:25 +0300 Subject: Changes: Renamed dui to meegotouch By: Holger, Daniel, Janne RevBy: Tomas, Holger --- tests/ut_mbuttonview/.gitignore | 1 + tests/ut_mbuttonview/mtheme.cpp | 63 ++++++ tests/ut_mbuttonview/ut_mbuttonview.cpp | 335 ++++++++++++++++++++++++++++++++ tests/ut_mbuttonview/ut_mbuttonview.h | 62 ++++++ tests/ut_mbuttonview/ut_mbuttonview.pro | 12 ++ 5 files changed, 473 insertions(+) create mode 100644 tests/ut_mbuttonview/.gitignore create mode 100644 tests/ut_mbuttonview/mtheme.cpp create mode 100644 tests/ut_mbuttonview/ut_mbuttonview.cpp create mode 100644 tests/ut_mbuttonview/ut_mbuttonview.h create mode 100644 tests/ut_mbuttonview/ut_mbuttonview.pro (limited to 'tests/ut_mbuttonview') diff --git a/tests/ut_mbuttonview/.gitignore b/tests/ut_mbuttonview/.gitignore new file mode 100644 index 00000000..47f987f6 --- /dev/null +++ b/tests/ut_mbuttonview/.gitignore @@ -0,0 +1 @@ +ut_duibuttonview diff --git a/tests/ut_mbuttonview/mtheme.cpp b/tests/ut_mbuttonview/mtheme.cpp new file mode 100644 index 00000000..268a4f79 --- /dev/null +++ b/tests/ut_mbuttonview/mtheme.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** +** +** 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 +#include +#include +#include + +#include +#include "ut_mbuttonview.h" // for themePixmap + +MTheme::MTheme() +{ +} + +MTheme::~MTheme() +{ +} + +MTheme *MTheme::instance() +{ + static MTheme singleton; + return &singleton; +} + +QPixmap *MTheme::pixmap(const QString &name, int width, int height) +{ + Q_UNUSED(name); + QPixmap *retVal = 0; + + if (!MButtonViewTest::themePixmap.contains(name)) + MButtonViewTest::themePixmap[ name ] = new QPixmap(width, height); + + retVal = MButtonViewTest::themePixmap[ name ]; + + return retVal; +} + +QPixmap *MTheme::pixmap(const QString &name, const QSizeF &size) +{ + return pixmap(name, (int)size.width(), (int)size.height()); +} + +QPixmap *MTheme::pixmap(const QString &name, const QSize &size) +{ + return pixmap(name, size.width(), size.height()); +} diff --git a/tests/ut_mbuttonview/ut_mbuttonview.cpp b/tests/ut_mbuttonview/ut_mbuttonview.cpp new file mode 100644 index 00000000..8cfb92e3 --- /dev/null +++ b/tests/ut_mbuttonview/ut_mbuttonview.cpp @@ -0,0 +1,335 @@ +/*************************************************************************** +** +** 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 +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include "ut_mbuttonview.h" +#include "mapplication.h" + +#include "mcancelevent.h" + +MApplication *app; + +void Ut_MButtonView::initTestCase() +{ + static int argc = 1; + static char *app_name[1] = { (char *) "./ut_mbuttonview" }; + app = new MApplication(argc, app_name); + + m_button = new MButton(); + m_subject = new MButtonIconView(m_button); + m_button->setView(m_subject); +} + +void Ut_MButtonView::cleanupTestCase() +{ + delete m_button; + m_button = 0; + + delete app; +} + +void Ut_MButtonView::testDrawText_data() +{ + QTest::addColumn("font"); + QTest::addColumn("textColor"); + QTest::addColumn("horizontalTextAlign"); + QTest::addColumn("verticalTextAlign"); + QTest::addColumn("textMarginLeft"); + QTest::addColumn("textMarginRight"); + QTest::addColumn("textMarginTop"); + QTest::addColumn("textMarginBottom"); + + QTest::newRow("testDrawText1") << QFont() << QColor(255, 255, 255) << (int)Qt::AlignLeft << (int)Qt::AlignTop << 0 << 0 << 0 << 0; + //QTest::newRow("testDrawText2") << QFont() << QColor(255,255,255) << Qt::AlignLeft << Qt::AlignTop << 0 << 0 << 0 << 0; + //QTest::newRow("testDrawText3") << QFont() << QColor(255,255,255) << Qt::AlignLeft << Qt::AlignTop << 0 << 0 << 0 << 0; + //QTest::newRow("testDrawText4") << QFont() << QColor(255,255,255) << Qt::AlignLeft << Qt::AlignTop << 0 << 0 << 0 << 0; +} + +void Ut_MButtonView::testDrawText() +{ + QFETCH(QFont, font); + QFETCH(QColor, textColor); + QFETCH(int, horizontalTextAlign); + QFETCH(int, verticalTextAlign); + QFETCH(int, textMarginLeft); + QFETCH(int, textMarginRight); + QFETCH(int, textMarginTop); + QFETCH(int, textMarginBottom); + + + m_button->setTextVisible(true); + m_button->setIconVisible(false); + m_button->setText("test1"); + + QRectF iconRect, textRect; + + QRectF rect = QRectF(0, 0, 200, 100); + m_button->setGeometry(rect); + + int buttonWidth = m_button->size().width(); + int buttonHeight = m_button->size().height(); + + MButtonStyle *s = (MButtonStyle *)m_subject->style().operator->(); + + s->setFont(font); + s->setTextColor(textColor); + s->setHorizontalTextAlign((Qt::Alignment)horizontalTextAlign); + s->setVerticalTextAlign((Qt::Alignment)verticalTextAlign); + s->setTextMarginLeft(textMarginLeft); + s->setTextMarginRight(textMarginRight); + s->setTextMarginTop(textMarginTop); + s->setTextMarginBottom(textMarginBottom); + m_subject->applyStyle(); + + QPixmap pm(QSize(buttonWidth, buttonHeight)); + QPainter p(&pm); + m_subject->drawContents(&p, NULL); +} + +void Ut_MButtonView::testDrawIcon_data() +{ + QTest::addColumn("iconAlign"); + QTest::addColumn("icon"); + QTest::addColumn("toggledIcon"); + QTest::addColumn("iconSize"); + QTest::addColumn("checkable"); + + + QTest::newRow("testDrawIcon1") << (int)Qt::AlignLeft << "Icon-close" << "Icon-close" << QSize(16, 16) << false; + QTest::newRow("testDrawIcon2") << (int)Qt::AlignRight << "Icon-close" << "Icon-close" << QSize(32, 32) << true; + QTest::newRow("testDrawIcon3") << (int)Qt::AlignBottom << "Icon-close" << "Icon-close" << QSize(64, 64) << false; + QTest::newRow("testDrawIcon4") << (int)Qt::AlignTop << "Icon-close" << "Icon-close" << QSize(128, 128) << true; +} + +void Ut_MButtonView::testDrawIcon() +{ + QFETCH(int, iconAlign); + QFETCH(QString, icon); + QFETCH(QString, toggledIcon); + QFETCH(QSize, iconSize); + QFETCH(bool, checkable); + + m_button->setTextVisible(false); + m_button->setIconVisible(true); + m_button->setCheckable(checkable); + m_button->setIconID(icon); + m_button->setToggledIconID(toggledIcon); + + QRectF iconRect, textRect; + + QRectF rect = QRectF(0, 0, 200, 100); + m_button->setGeometry(rect); + + int buttonWidth = m_button->size().width(); + int buttonHeight = m_button->size().height(); + + MButtonStyle *s = (MButtonStyle *)m_subject->style().operator->(); + + s->setIconAlign((Qt::Alignment)iconAlign); + s->setIconSize(iconSize); + s->setPreferredSize(QSize(-1, -1)); + m_subject->applyStyle(); + + QPixmap pm(QSize(buttonWidth, buttonHeight)); + QPainter p(&pm); + m_subject->drawContents(&p, NULL); + + m_button->model()->setDown(true); + m_subject->drawContents(&p, NULL); + m_button->model()->setDown(false); +} + +void Ut_MButtonView::testDrawIconText_data() +{ + QTest::addColumn("iconAlign"); + QTest::addColumn("icon"); + QTest::addColumn("toggledIcon"); + QTest::addColumn("iconSize"); + + QTest::newRow("testDrawIcon1") << (int)Qt::AlignLeft << "Icon-close" << "Icon-close" << QSize(16, 16); + QTest::newRow("testDrawIcon2") << (int)Qt::AlignRight << "Icon-close" << "Icon-close" << QSize(32, 32); + QTest::newRow("testDrawIcon3") << (int)Qt::AlignBottom << "Icon-close" << "Icon-close" << QSize(64, 64); + QTest::newRow("testDrawIcon4") << (int)Qt::AlignTop << "Icon-close" << "Icon-close" << QSize(128, 128); +} + +void Ut_MButtonView::testDrawIconText() +{ + QFETCH(int, iconAlign); + QFETCH(QString, icon); + QFETCH(QString, toggledIcon); + QFETCH(QSize, iconSize); + + m_button->setTextVisible(true); + m_button->setIconVisible(true); + m_button->setIconID(icon); + m_button->setToggledIconID(toggledIcon); + m_button->setText("button"); + + QRectF iconRect, textRect; + + QRectF rect = QRectF(0, 0, 200, 100); + m_button->setGeometry(rect); + + int buttonWidth = m_button->size().width(); + int buttonHeight = m_button->size().height(); + + MButtonStyle *s = (MButtonStyle *)m_subject->style().operator->(); + + s->setIconAlign((Qt::Alignment)iconAlign); + s->setIconSize(iconSize); + s->setPreferredSize(QSize(-1, -1)); + m_subject->applyStyle(); + + QPixmap pm(QSize(buttonWidth, buttonHeight)); + QPainter p(&pm); + m_button->paint(&p, NULL, NULL); + + m_button->model()->setDown(true); + m_button->paint(&p, NULL, NULL); + m_button->model()->setDown(false); +} + +void Ut_MButtonView::testMouseEvents() +{ + QRectF rect = QRectF(0, 0, 200, 100); + m_button->setGeometry(rect); + + //press + QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); + m_subject->mousePressEvent(&pressEvent); + QVERIFY(m_button->isDown() == true); + m_subject->mousePressEvent(&pressEvent); + + //release + QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); + m_subject->mouseReleaseEvent(&releaseEvent); + QVERIFY(m_button->isDown() == false); + m_subject->mouseReleaseEvent(&releaseEvent); + + //cancel + m_subject->mousePressEvent(&pressEvent); + MCancelEvent event; + m_subject->cancelEvent(&event); + QVERIFY(m_button->isDown() == false); + m_subject->cancelEvent(&event); + + //move + m_subject->mousePressEvent(&pressEvent); + + QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove); + moveEvent.setScenePos(QPointF(300,300)); + + m_subject->mouseMoveEvent(&moveEvent); + QVERIFY(m_button->isDown() == false); + m_subject->mouseReleaseEvent(&releaseEvent); +} + +void Ut_MButtonView::testSwitchView() +{ + m_button->setCheckable(true); + m_button->setChecked(false); + m_button->setViewType(MButton::switchType); + QRectF rect = QRectF(0, 0, 200, 100); + m_button->setGeometry(rect); + + //draw unchecked + QImage img0 = captureImage(m_button); + + //draw checked + m_button->setChecked(true); + QImage img1 = captureImage(m_button); + + //draw checked down + m_button->setDown(true); + QImage img2 = captureImage(m_button); + + //draw down + m_button->setChecked(false); + QImage img3 = captureImage(m_button); + + m_button->setDown(false); + + /*QVERIFY(img0 != img1); + QVERIFY(img0 != img2); + QVERIFY(img0 == img3); + + QVERIFY(img1 == img2); + QVERIFY(img1 != img3); + + QVERIFY(img2 != img3);*/ +} + +void Ut_MButtonView::testCheckboxView() +{ + m_button->setCheckable(true); + m_button->setChecked(false); + m_button->setViewType(MButton::checkboxType); + QRectF rect = QRectF(0, 0, 200, 100); + m_button->setGeometry(rect); + + //draw unchecked + QImage img0 = captureImage(m_button); + + //draw checked + m_button->setChecked(true); + QImage img1 = captureImage(m_button); + + //draw checked down + m_button->setDown(true); + QImage img2 = captureImage(m_button); + + //draw down + m_button->setChecked(false); + QImage img3 = captureImage(m_button); + + m_button->setDown(false); + + /*QVERIFY(img0 != img1); + QVERIFY(img0 != img2); + QVERIFY(img0 != img3); + + QVERIFY(img1 != img2); + QVERIFY(img1 != img3); + + QVERIFY(img2 != img3);*/ +} + +QImage Ut_MButtonView::captureImage(MButton *button) +{ + QPixmap pixmap(button->size().toSize()); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); + button->paint(&painter, NULL, NULL); + + return pixmap.toImage(); +} + +QTEST_APPLESS_MAIN(Ut_MButtonView) diff --git a/tests/ut_mbuttonview/ut_mbuttonview.h b/tests/ut_mbuttonview/ut_mbuttonview.h new file mode 100644 index 00000000..29ad866c --- /dev/null +++ b/tests/ut_mbuttonview/ut_mbuttonview.h @@ -0,0 +1,62 @@ +/*************************************************************************** +** +** 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_MBUTTONVIEW_H +#define UT_MBUTTONVIEW_H + +#include +#include + +class MButton; +class MButtonView; + +class Ut_MButtonView : public QObject +{ + Q_OBJECT +public: + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void testDrawText_data(); + void testDrawText(); + + void testDrawIcon_data(); + void testDrawIcon(); + + void testDrawIconText_data(); + void testDrawIconText(); + + void testMouseEvents(); + + void testSwitchView(); + void testCheckboxView(); + +private: + + QImage captureImage(MButton *button); + + + MButton *m_button; + MButtonView *m_subject; +}; + +#endif + diff --git a/tests/ut_mbuttonview/ut_mbuttonview.pro b/tests/ut_mbuttonview/ut_mbuttonview.pro new file mode 100644 index 00000000..5b876e01 --- /dev/null +++ b/tests/ut_mbuttonview/ut_mbuttonview.pro @@ -0,0 +1,12 @@ + +include(../common_top.pri) +INCLUDEPATH += $$MSRCDIR/corelib/widgets $$MSRCDIR/corelib/style + +TARGET = ut_mbuttonview + +SOURCES += \ + ut_mbuttonview.cpp \ + +HEADERS += \ + ut_mbuttonview.h +include(../common_bot.pri) -- cgit v1.2.3