summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libgq/gconf/test-gconf.h
blob: 36eaeccca474885c69f297fdbb21cce4533e7512 (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
#include <QObject>
#include <QtTest/QtTest>
#include <QDebug>

#include "GConfItem"

// Helper class for listening to signals
class SignalListener : public QObject
{
    Q_OBJECT
public:
    int numberOfCalls;
    SignalListener() : numberOfCalls(0) {
    }

public slots:
    void valueChanged()
    {
        numberOfCalls++;
    }
};

// Tests for the public API
class GConfItemTests : public QObject
{
    Q_OBJECT

    // Stored pointers etc.
private:
    GConfItem *boolItem;
    GConfItem *intItem;
    GConfItem *stringItem;
    GConfItem *doubleItem;
    GConfItem *stringListItem;
    GConfItem *intListItem;
    GConfItem *doubleListItem;
    GConfItem *boolListItem;
    GConfItem *unsetBeforeItem;
    GConfItem *unsetAfterItem;

    SignalListener *signalSpy;

    QTimer timer;
    bool timed_out;

    // Tests
private slots:
    // Init and cleanup helper functions
    void initTestCase();
    void cleanupTestCase();
    void init();
    void cleanup();
    void timeout ();

    // Public API
    void path();
    void external_values();
    void set_bool();
    void set_int();
    void set_string();
    void set_unicode_string();
    void set_double();
    void set_string_list();
    void set_int_list();
    void set_double_list();
    void set_bool_list();
    void unset();
    void get_default();
    void list_dirs();
    void list_entries();
    void propagate();
    void set_external();
};

// Useful if you need to process some events until a condition becomes
// true.

#define QVERIFY_TIMEOUT(msecs, expr)                                        \
    do {                                                                    \
        timed_out = false;                                                  \
        timer.start(msecs);                                                 \
        while (!timed_out && !(expr)) {                                     \
            QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); \
        }                                                                   \
        QVERIFY((expr));                                                    \
    } while(0)