File: listenertest.cpp

package info (click to toggle)
libindicate-qt 0.2.5.91-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 388 kB
  • ctags: 262
  • sloc: cpp: 1,655; makefile: 6
file content (80 lines) | stat: -rw-r--r-- 2,257 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Qt wrapper for libindicate
 *
 * Copyright 2009 Canonical Ltd.
 *
 * Authors:
 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
 *
 * License: LGPL v2.1 or LGPL v3
 */
// Self
#include "listenertest.h"

// Qt
#include <QMetaType>
#include <QtTest>

// Local
#include <qindicateindicator.h>
#include <qindicatelistener.h>
#include <qindicateserver.h>

const QString SERVER_TYPE = "message";

QTEST_MAIN(ListenerTest)

void ListenerTest::initTestCase()
{
    qRegisterMetaType<QIndicate::Listener::Server*>("QIndicate::Listener::Server*");
    qRegisterMetaType<QIndicate::Listener::Indicator*>("QIndicate::Listener::Indicator*");
}

void ListenerTest::testServerAddedRemoved()
{
    QIndicate::Listener* listener = QIndicate::Listener::defaultInstance();

    QSignalSpy addedSpy(listener, SIGNAL(serverAdded(QIndicate::Listener::Server*, const QString&)));
    QSignalSpy removedSpy(listener, SIGNAL(serverRemoved(QIndicate::Listener::Server*, const QString&)));

    QIndicate::Server* server = QIndicate::Server::defaultInstance();
    server->setType(SERVER_TYPE);

    QCOMPARE(addedSpy.count(), 0);
    server->show();
    QTest::qWait(500);
    QCOMPARE(addedSpy.count(), 1);
    QCOMPARE(addedSpy.takeFirst()[1].toString(), SERVER_TYPE);

    // Quoting ted:
    // "the server hide doesn't work as there's a bug in dbus-glib that doesn't
    // really remove things off of the bus :("
    #if 0
    server->hide();
    QTest::qWait(500);
    QCOMPARE(removedSpy.count(), 1);
    #endif
}

void ListenerTest::testIndicatorAddedRemoved()
{
    QIndicate::Listener* listener = QIndicate::Listener::defaultInstance();

    QSignalSpy addedSpy(listener, SIGNAL(indicatorAdded(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*)));
    QSignalSpy removedSpy(listener, SIGNAL(indicatorRemoved(QIndicate::Listener::Server*, QIndicate::Listener::Indicator*)));

    QIndicate::Server* server = QIndicate::Server::defaultInstance();
    server->setType(SERVER_TYPE);

    QIndicate::Indicator* indicator = new QIndicate::Indicator(server);
    indicator->show();
    QTest::qWait(500);

    QCOMPARE(addedSpy.count(), 1);

    indicator->hide();
    QTest::qWait(500);
    QCOMPARE(removedSpy.count(), 1);
}

#include "listenertest.moc"