summaryrefslogtreecommitdiffstats
path: root/test/qt/ping.cpp
blob: 1777a804adfccb72543477b01dda39b086622005 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#define DBUS_API_SUBJECT_TO_CHANGE
#include <QtCore/QtCore>
#include <QtTest/QtTest>
#include <dbus/qdbus.h>

class Ping: public QObject
{
    Q_OBJECT

public slots:
    void initTestCase();
    void cleanupTestCase();

private slots:
    void sendPing_data();
    void sendPing();

private:
    QProcess proc;
};

void Ping::initTestCase()
{
    proc.start("./qpong");
    QVERIFY(proc.waitForStarted());
    QTest::qWait(2000);
}

void Ping::cleanupTestCase()
{
    proc.close();
}

Q_DECLARE_METATYPE(QVariant)

void Ping::sendPing_data()
{
    QTest::addColumn<QVariant>("value");

    QTest::newRow("string") << QVariant("ping");
    QTest::newRow("int") << QVariant(1);
    QTest::newRow("double") << QVariant(42.5);

    QStringList strings;
    strings << "hello" << "world";
    QTest::newRow("stringlist") << QVariant(strings);

    QList<QVariant> ints;
    ints << 42 << -43 << 44 << 45;
    QTest::newRow("intlist") << QVariant(ints);

    QList<QVariant> uints;
    uints << uint(12) << uint(13) << uint(14);
    QTest::newRow("uintlist") << QVariant(uints);

    QList<QVariant> llints;
    llints << Q_INT64_C(99) << Q_INT64_C(-100);
    QTest::newRow("llintlist") << QVariant(llints);

    QList<QVariant> ullints;
    ullints << Q_UINT64_C(66) << Q_UINT64_C(67);
    QTest::newRow("ullintlist") << QVariant(ullints);

    QList<QVariant> doubles;
    doubles << 1.2 << 2.2 << 4.4;
    QTest::newRow("doublelist") << QVariant(doubles);

    QList<QVariant> stackedInts;
    stackedInts << 4 << ints << 5;
    QTest::newRow("stackedInts") << QVariant(stackedInts);

    QList<QVariant> stackedUInts;
    stackedUInts << uint(3) << uints << uint(4);
    QTest::newRow("stackedUInts") << QVariant(stackedUInts);

    QList<QVariant> stackedLlints;
    stackedLlints << Q_INT64_C(49) << llints << Q_INT64_C(-160);
    QTest::newRow("stackedLlintlist") << QVariant(stackedLlints);

    QList<QVariant> stackedUllints;
    stackedUllints << Q_UINT64_C(56) << ullints << Q_UINT64_C(57);
    QTest::newRow("stackedullintlist") << QVariant(stackedUllints);

    QList<QVariant> stackedDoubles;
    stackedDoubles << 6.2 << doubles << 6.4;
    QTest::newRow("stackedDoublelist") << QVariant(stackedDoubles);

    QMap<QString, QVariant> map;
    map["foo"] = "bar";
    map["kde"] = "great";
    QTest::newRow("map") << QVariant(map);
    
    QList<QVariant> byteArrays;
    byteArrays << QByteArray("test1") << QByteArray("t2");
    QTest::newRow("bytearray") << QVariant(byteArrays);
    
    QList<QVariant> lists;
    lists << QVariant(byteArrays) << QVariant(byteArrays);
    QTest::newRow("listoflists") << QVariant(lists);
}

void Ping::sendPing()
{
    QFETCH(QVariant, value);

    QDBusConnection &con = QDBus::sessionBus();

    QVERIFY(con.isConnected());

    QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest",
            "/org/kde/selftest", "org.kde.selftest", "ping");
    msg << value;

    QDBusMessage reply = con.sendWithReply(msg);
 //   qDebug() << reply;

    QCOMPARE(reply.count(), msg.count());
    for (int i = 0; i < reply.count(); ++i)
        QCOMPARE(reply.at(i), msg.at(i));
}

QTEST_MAIN(Ping)
#include "ping.moc"