Skip to content

Commit

Permalink
Changes: Close event eater needs to ignore() the close events
Browse files Browse the repository at this point in the history
RevBy: TrustMe
  • Loading branch information
Vesa Halttunen committed Nov 4, 2010
1 parent 894a27c commit b8424d5
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/systemui/closeeventeater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/systemui/closeeventeater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
1 change: 1 addition & 0 deletions tests/ut_closeeventeater/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ut_closeeventeater
86 changes: 86 additions & 0 deletions tests/ut_closeeventeater/ut_closeeventeater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation ([email protected])
**
** This file is part of mhome.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
**
** 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 <QtTest/QtTest>
#include <MApplication>
#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<bool>("eventFilterReturnValue");
QTest::addColumn<bool>("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)
54 changes: 54 additions & 0 deletions tests/ut_closeeventeater/ut_closeeventeater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation ([email protected])
**
** This file is part of mhome.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
**
** 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 <QObject>

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
15 changes: 15 additions & 0 deletions tests/ut_closeeventeater/ut_closeeventeater.pro
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b8424d5

Please sign in to comment.