From b8424d5622418d7ef2f1a5003a0d3a4380279060 Mon Sep 17 00:00:00 2001 From: Vesa Halttunen Date: Thu, 4 Nov 2010 17:34:56 +0200 Subject: [PATCH] Changes: Close event eater needs to ignore() the close events RevBy: TrustMe --- src/systemui/closeeventeater.cpp | 2 +- src/systemui/closeeventeater.h | 4 + tests/ut_closeeventeater/.gitignore | 1 + .../ut_closeeventeater/ut_closeeventeater.cpp | 86 +++++++++++++++++++ tests/ut_closeeventeater/ut_closeeventeater.h | 54 ++++++++++++ .../ut_closeeventeater/ut_closeeventeater.pro | 15 ++++ 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 tests/ut_closeeventeater/.gitignore create mode 100644 tests/ut_closeeventeater/ut_closeeventeater.cpp create mode 100644 tests/ut_closeeventeater/ut_closeeventeater.h create mode 100644 tests/ut_closeeventeater/ut_closeeventeater.pro diff --git a/src/systemui/closeeventeater.cpp b/src/systemui/closeeventeater.cpp index e54445b3..724d7f8c 100644 --- a/src/systemui/closeeventeater.cpp +++ b/src/systemui/closeeventeater.cpp @@ -26,7 +26,7 @@ CloseEventEater::CloseEventEater(QObject *parent) : QObject(parent) bool CloseEventEater::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::Close) { - event->accept(); + event->ignore(); return true; } else { return QObject::eventFilter(obj, event); diff --git a/src/systemui/closeeventeater.h b/src/systemui/closeeventeater.h index ab01616d..90451dea 100644 --- a/src/systemui/closeeventeater.h +++ b/src/systemui/closeeventeater.h @@ -43,6 +43,10 @@ class CloseEventEater : public QObject //! \reimp bool eventFilter(QObject *obj, QEvent *event); //! \reimp_end + +#ifdef UNIT_TEST + friend class Ut_CloseEventEater; +#endif }; #endif /* CLOSEEVENTEATER_H_ */ diff --git a/tests/ut_closeeventeater/.gitignore b/tests/ut_closeeventeater/.gitignore new file mode 100644 index 00000000..76cd253f --- /dev/null +++ b/tests/ut_closeeventeater/.gitignore @@ -0,0 +1 @@ +ut_closeeventeater diff --git a/tests/ut_closeeventeater/ut_closeeventeater.cpp b/tests/ut_closeeventeater/ut_closeeventeater.cpp new file mode 100644 index 00000000..ce1265d6 --- /dev/null +++ b/tests/ut_closeeventeater/ut_closeeventeater.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of mhome. +** +** 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 "closeeventeater.h" +#include "ut_closeeventeater.h" + +bool qObjectEventFilterReturnValue = false; +bool QObject::eventFilter(QObject *, QEvent *) +{ + return qObjectEventFilterReturnValue; +} + +void Ut_CloseEventEater::initTestCase() +{ + static int argc = 1; + static char *app_name[1] = { (char *) "./ut_closeeventeater" }; + app = new MApplication(argc, app_name); +} + +void Ut_CloseEventEater::cleanupTestCase() +{ + delete app; +} + +void Ut_CloseEventEater::init() +{ + m_subject = new CloseEventEater(); +} + +void Ut_CloseEventEater::cleanup() +{ + delete m_subject; + qObjectEventFilterReturnValue = false; +} + +void Ut_CloseEventEater::testCloseEventIsIgnored() +{ + QCloseEvent event; + event.accept(); + QVERIFY(m_subject->eventFilter(this, &event)); + QVERIFY(!event.isAccepted()); +} + +void Ut_CloseEventEater::testOtherEventsArePassedOn_data() +{ + QTest::addColumn("eventFilterReturnValue"); + QTest::addColumn("accepted"); + + QTest::newRow("Event filter returns false, accepted was false") << false << false; + QTest::newRow("Event filter returns false, accepted was true") << false << true; + QTest::newRow("Event filter returns true, accepted was false") << true << false; + QTest::newRow("Event filter returns true, accepted was true") << true << true; +} + +void Ut_CloseEventEater::testOtherEventsArePassedOn() +{ + QFETCH(bool, eventFilterReturnValue); + QFETCH(bool, accepted); + + qObjectEventFilterReturnValue = eventFilterReturnValue; + + QEvent event(QEvent::None); + event.setAccepted(accepted); + QCOMPARE(m_subject->eventFilter(this, &event), eventFilterReturnValue); + QCOMPARE(event.isAccepted(), accepted); +} + +QTEST_APPLESS_MAIN(Ut_CloseEventEater) diff --git a/tests/ut_closeeventeater/ut_closeeventeater.h b/tests/ut_closeeventeater/ut_closeeventeater.h new file mode 100644 index 00000000..e1345230 --- /dev/null +++ b/tests/ut_closeeventeater/ut_closeeventeater.h @@ -0,0 +1,54 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of mhome. +** +** 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_CLOSEEVENTEATER_H +#define UT_CLOSEEVENTEATER_H + +#include + +class MApplication; +class CloseEventEater; + +class Ut_CloseEventEater : public QObject +{ + Q_OBJECT + +private slots: + // Called before the first testfunction is executed + void initTestCase(); + // Called after the last testfunction was executed + void cleanupTestCase(); + // Called before each testfunction is executed + void init(); + // Called after every testfunction + void cleanup(); + + // Test cases + void testCloseEventIsIgnored(); + void testOtherEventsArePassedOn_data(); + void testOtherEventsArePassedOn(); + +private: + // MApplication + MApplication *app; + // The object being tested + CloseEventEater *m_subject; +}; + +#endif diff --git a/tests/ut_closeeventeater/ut_closeeventeater.pro b/tests/ut_closeeventeater/ut_closeeventeater.pro new file mode 100644 index 00000000..9489aec9 --- /dev/null +++ b/tests/ut_closeeventeater/ut_closeeventeater.pro @@ -0,0 +1,15 @@ +include(../coverage.pri) +include(../common_top.pri) +TARGET = ut_closeeventeater + +# unit test and unit +SOURCES += \ + ut_closeeventeater.cpp \ + $$SRCDIR/closeeventeater.cpp + +# unit test and unit +HEADERS += \ + ut_closeeventeater.h \ + $$SRCDIR/closeeventeater.h + +include(../common_bot.pri)