Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ut_UnlockNotifications: A new unit test.
  • Loading branch information
László Pere committed Jun 14, 2010
1 parent e8e5939 commit a975e44
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gen-coverage.sh
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/unlocknotifications.cpp
Expand Up @@ -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...
*/
Expand Down
3 changes: 3 additions & 0 deletions src/unlocknotifications.h
Expand Up @@ -50,6 +50,9 @@ private slots:
* main vbox
*/
QGraphicsLinearLayout *m_vbox;
#ifdef UNIT_TEST
friend class Ut_UnlockNotifications;
#endif
};


Expand Down
85 changes: 85 additions & 0 deletions 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;
}
44 changes: 44 additions & 0 deletions 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
6 changes: 5 additions & 1 deletion tests/tests.pro
Expand Up @@ -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!/.*!!')
}
Expand Down
152 changes: 152 additions & 0 deletions 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)

54 changes: 54 additions & 0 deletions 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

0 comments on commit a975e44

Please sign in to comment.