Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ut_UnlockNotifications: A new unit test.

  • Loading branch information...
commit a975e4454cbbce2bd6069ccd82ce2928f0eb9fba 1 parent e8e5939
László Pere authored
View
2  gen-coverage.sh
@@ -17,13 +17,13 @@ fi
rm -fr ./coverage/*
-./configure
echo "qmake BUILD_FEATURES=coverage"
qmake BUILD_FEATURES=coverage
echo "make coverage"
make clean
+./configure
make coverage
ls -lh ./coverage/index.html
View
1  src/unlocknotifications.cpp
@@ -137,7 +137,6 @@ UnlockNotifications::orientationChangeEvent (MOrientationChangeEvent *event)
m_icon_layout->insertItem (0, m_last_subject);
m_mostrecent_layout->removeItem (m_last_icon);
m_icon_layout->insertItem (0, m_last_icon);
-
/*
* Re-size the other events area a bit bigger...
*/
View
3  src/unlocknotifications.h
@@ -50,6 +50,9 @@ private slots:
* main vbox
*/
QGraphicsLinearLayout *m_vbox;
+ #ifdef UNIT_TEST
+ friend class Ut_UnlockNotifications;
+ #endif
};
View
85 tests/common/MTester.cpp
@@ -0,0 +1,85 @@
+/* -*- Mode: C; indent-tabs-mode: s; c-basic-offset: 4; tab-width: 4 -*- */
+/* vim:set et ai sw=4 ts=4 sts=4: tw=80 cino="(0,W2s,i2s,t0,l1,:0" */
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of systemui.
+**
+** 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 "MTester.h"
+
+#include <QGraphicsLayout>
+#include <QGraphicsLayoutItem>
+#include <QGraphicsWidget>
+#include <QString>
+
+#define DEBUG
+#include "../../src/debug.h"
+
+bool
+MTester::isLayoutContains (
+ QGraphicsLayout *layout,
+ QGraphicsLayoutItem *item)
+{
+ bool found = false;
+
+ #if 0
+ SYS_DEBUG ("*** layout = %p", layout);
+ SYS_DEBUG ("*** item = %p", item);
+ SYS_DEBUG ("*** count = %d", layout->count());
+ #endif
+ for (int n = 0; n < layout->count(); ++n) {
+ QGraphicsLayoutItem *child = layout->itemAt (n);
+
+ if (item == child)
+ found = true;
+
+ #if 0
+ QGraphicsWidget* widget = (QGraphicsWidget*) child;
+ SYS_DEBUG ("**********************************************");
+ SYS_DEBUG ("*** child = %p", child);
+ SYS_DEBUG ("*** widget = %p", child->graphicsItem ());
+ SYS_DEBUG ("*** name = %s", SYS_STR(widget->objectName()));
+ #endif
+ }
+
+ if (!found) {
+ QGraphicsWidget* widget = (QGraphicsWidget*) item;
+ SYS_WARNING ("Layout at %p should contain widget %p/%s.",
+ layout,
+ item,
+ SYS_STR(widget->objectName()));
+ }
+
+ return found;
+}
+
+bool
+MTester::objectnameIs (
+ QGraphicsWidget *widget,
+ const QString &name)
+{
+ bool retval = widget->objectName() == name;
+
+ if (!retval) {
+ QString realName = widget->objectName();
+ SYS_WARNING ("Widget at %p should have the name %s, but it is %s.",
+ widget,
+ SYS_STR(name),
+ realName.isEmpty() ? "(empty)" : SYS_STR(realName));
+ }
+
+ return retval;
+}
View
44 tests/common/MTester.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; indent-tabs-mode: s; c-basic-offset: 4; tab-width: 4 -*- */
+/* vim:set et ai sw=4 ts=4 sts=4: tw=80 cino="(0,W2s,i2s,t0,l1,:0" */
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of systemui.
+**
+** 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 MTESTER_H
+#define MTESTER_H
+
+#include <QObject>
+
+class QGraphicsLayout;
+class QGraphicsLayoutItem;
+class QGraphicsWidget;
+class QString;
+
+class MTester : public QObject
+{
+ Q_OBJECT
+
+public:
+ bool isLayoutContains (
+ QGraphicsLayout *layout,
+ QGraphicsLayoutItem *item);
+
+ bool objectnameIs (
+ QGraphicsWidget *widget,
+ const QString &name);
+};
+#endif
View
6 tests/tests.pro
@@ -8,8 +8,12 @@ TEMPLATE = subdirs
# using the 'disabled' file).
#
contains(BUILD_FEATURES,coverage) {
+ #
+ # Sometimes if is faster like this, when you are working on a single unit
+ # test for a while.
+ #
+ #SUBDIRS = $$system(ls -1d ut_unlocknotifications)
SUBDIRS = $$system(ls -1d ut_*/ | grep -v ut_template)
- #SUBDIRS = $$system(ls -1d ut_*/*.pro 2>/dev/null | sed 's!/.*!!')
} else {
SUBDIRS = $$system(ls -1d ut_*/*.pro ft_*/*.pro 2>/dev/null | sed 's!/.*!!')
}
View
152 tests/ut_unlocknotifications/ut_unlocknotifications.cpp
@@ -0,0 +1,152 @@
+/* -*- Mode: C; indent-tabs-mode: s; c-basic-offset: 4; tab-width: 4 -*- */
+/* vim:set et ai sw=4 ts=4 sts=4: tw=80 cino="(0,W2s,i2s,t0,l1,:0" */
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of systemui.
+**
+** 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_unlocknotifications.h"
+
+#include <notification.h>
+#include <notificationparameters.h>
+#include <genericnotificationparameterfactory.h>
+
+#include "unlockmissedevents_stub.h"
+#include "unlocknotifications.h"
+
+#include <MApplication>
+#include <MOrientationChangeEvent>
+
+#include <QGraphicsLinearLayout>
+#include <MImageWidget>
+#include <MLabel>
+
+#include <QtTest/QtTest>
+#include <QList>
+#include <QVariant>
+
+
+#define DEBUG
+#include "../../src/debug.h"
+
+static int argc = 1;
+static char *app_name = (char *) "./ut_unlocknotificationsink";
+
+void
+Ut_UnlockNotifications::initTestCase ()
+{
+ // Create a MAapplication
+ app = new MApplication (argc, &app_name);
+}
+
+void
+Ut_UnlockNotifications::cleanupTestCase ()
+{
+ // Destroy MApplication
+ delete app;
+}
+
+void
+Ut_UnlockNotifications::init ()
+{
+ m_Subject = new UnlockNotifications ();
+}
+
+void
+Ut_UnlockNotifications::cleanup ()
+{
+ delete m_Subject;
+}
+
+void
+Ut_UnlockNotifications::testDefaultValues ()
+{
+ if (m_Subject) {
+ delete m_Subject;
+ }
+
+ m_Subject = new UnlockNotifications ();
+
+ QVERIFY (m_Subject->m_otherevents_area);
+ QVERIFY (m_Subject->m_mostrecent_layout);
+ QVERIFY (m_Subject->m_last_icon);
+ QVERIFY (m_Subject->m_last_subject);
+ QVERIFY (m_Subject->m_icon_layout);
+ QVERIFY (m_Subject->m_mostrecent_area);
+ QVERIFY (m_Subject->m_vbox);
+
+ QVERIFY (m_Tester.objectnameIs (
+ m_Subject->m_otherevents_area,
+ "LockOtherEventsArea"));
+ QVERIFY (m_Tester.objectnameIs (
+ m_Subject->m_last_icon,
+ "LockMostRecentIcon"));
+ QVERIFY (m_Tester.objectnameIs (
+ m_Subject->m_last_subject,
+ "LockMostRecentLabel"));
+ QVERIFY (m_Tester.objectnameIs (
+ m_Subject->m_mostrecent_area,
+ "LockMostRecentArea"));
+}
+
+void
+Ut_UnlockNotifications::testOrientationChanged ()
+{
+ if (!m_Subject)
+ m_Subject = new UnlockNotifications ();
+
+ /*
+ * Testing the layout in landscape.
+ */
+ MOrientationChangeEvent landscapeEvent (M::Landscape);
+ m_Subject->orientationChangeEvent (&landscapeEvent);
+ QVERIFY (m_Tester.isLayoutContains(
+ m_Subject->m_icon_layout,
+ m_Subject->m_last_icon));
+ QVERIFY (m_Tester.isLayoutContains(
+ m_Subject->m_icon_layout,
+ m_Subject->m_last_subject));
+
+ /*
+ * testing the layout in portrait.
+ */
+ MOrientationChangeEvent portraitEvent (M::Portrait);
+ m_Subject->orientationChangeEvent (&portraitEvent);
+
+ QVERIFY (m_Tester.isLayoutContains(
+ m_Subject->m_mostrecent_layout,
+ m_Subject->m_last_icon));
+ QVERIFY (m_Tester.isLayoutContains(
+ m_Subject->m_mostrecent_layout,
+ m_Subject->m_last_subject));
+
+ QVERIFY (m_Tester.isLayoutContains(
+ m_Subject->m_vbox,
+ m_Subject->m_mostrecent_area));
+}
+
+void
+Ut_UnlockNotifications::testUpdateContents ()
+{
+ if (!m_Subject)
+ m_Subject = new UnlockNotifications ();
+
+ m_Subject->updateContents ();
+}
+
+
+QTEST_APPLESS_MAIN(Ut_UnlockNotifications)
+
View
54 tests/ut_unlocknotifications/ut_unlocknotifications.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; indent-tabs-mode: s; c-basic-offset: 4; tab-width: 4 -*- */
+/* vim:set et ai sw=4 ts=4 sts=4: tw=80 cino="(0,W2s,i2s,t0,l1,:0" */
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of systemui.
+**
+** 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_UNLOCKNOTIFICATIONS_H
+#define UT_UNLOCKNOTIFICATIONS_H
+
+#include <QObject>
+#include <QGraphicsLayoutItem>
+
+#include "../common/MTester.h"
+
+#include "unlocknotifications.h"
+
+class MApplication;
+
+class Ut_UnlockNotifications : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void init ();
+ void cleanup ();
+ void initTestCase ();
+ void cleanupTestCase ();
+
+ void testDefaultValues ();
+ void testOrientationChanged ();
+ void testUpdateContents ();
+
+private:
+ MTester m_Tester;
+ MApplication *app;
+ UnlockNotifications *m_Subject;
+};
+
+#endif
+
View
33 tests/ut_unlocknotifications/ut_unlocknotifications.pro
@@ -0,0 +1,33 @@
+include(../coverage.pri)
+include(../common_top.pri)
+
+TARGET = ut_unlocknotifications
+INCLUDEPATH += $$SRCDIR/notifications $$SRCDIR $$STUBSDIR
+DEFINES += NOTIFICATIONS_EVENT_TYPES=\'$$quote(\"$$M_NOTIFICATIONS_EVENT_TYPES_DIR\")\'
+
+SOURCES += \
+ ../common/MTester.cpp \
+ ut_unlocknotifications.cpp \
+ $$SRCDIR/unlocknotifications.cpp \
+ $$SRCDIR/debug.cpp \
+ $$STUBSDIR/stubbase.cpp \
+ $$SRCDIR/notifications/notificationsink.cpp \
+ $$SRCDIR/notifications/notification.cpp \
+ $$SRCDIR/notifications/notificationgroup.cpp \
+ $$SRCDIR/notifications/notificationparameter.cpp \
+ $$SRCDIR/notifications/notificationparameters.cpp
+
+HEADERS += \
+ ../common/MTester.h \
+ ut_unlocknotifications.h \
+ $$SRCDIR/unlocknotifications.h \
+ $$SRCDIR/debug.h \
+ $$SRCDIR/unlockmissedevents.h \
+ $$STUBSDIR/unlockmissedevents_stub.h \
+ $$SRCDIR/notifications/notificationsink.h \
+ $$SRCDIR/notifications/notification.h \
+ $$SRCDIR/notifications/notificationgroup.h \
+ $$SRCDIR/notifications/notificationparameter.h \
+ $$SRCDIR/notifications/notificationparameters.h
+
+include(../common_bot.pri)
Please sign in to comment.
Something went wrong with that request. Please try again.