equal
deleted
inserted
replaced
|
1 #include <QObject> |
|
2 #include <QtTest/QtTest> |
|
3 #include <QDebug> |
|
4 |
|
5 #include "GConfItem" |
|
6 |
|
7 // Helper class for listening to signals |
|
8 class SignalListener : public QObject |
|
9 { |
|
10 Q_OBJECT |
|
11 public: |
|
12 int numberOfCalls; |
|
13 SignalListener() : numberOfCalls(0) { |
|
14 } |
|
15 |
|
16 public slots: |
|
17 void valueChanged() |
|
18 { |
|
19 numberOfCalls++; |
|
20 } |
|
21 }; |
|
22 |
|
23 // Tests for the public API |
|
24 class GConfItemTests : public QObject |
|
25 { |
|
26 Q_OBJECT |
|
27 |
|
28 // Stored pointers etc. |
|
29 private: |
|
30 GConfItem *boolItem; |
|
31 GConfItem *intItem; |
|
32 GConfItem *stringItem; |
|
33 GConfItem *doubleItem; |
|
34 GConfItem *stringListItem; |
|
35 GConfItem *intListItem; |
|
36 GConfItem *doubleListItem; |
|
37 GConfItem *boolListItem; |
|
38 GConfItem *unsetBeforeItem; |
|
39 GConfItem *unsetAfterItem; |
|
40 |
|
41 SignalListener *signalSpy; |
|
42 |
|
43 QTimer timer; |
|
44 bool timed_out; |
|
45 |
|
46 // Tests |
|
47 private slots: |
|
48 // Init and cleanup helper functions |
|
49 void initTestCase(); |
|
50 void cleanupTestCase(); |
|
51 void init(); |
|
52 void cleanup(); |
|
53 void timeout (); |
|
54 |
|
55 // Public API |
|
56 void path(); |
|
57 void external_values(); |
|
58 void set_bool(); |
|
59 void set_int(); |
|
60 void set_string(); |
|
61 void set_unicode_string(); |
|
62 void set_double(); |
|
63 void set_string_list(); |
|
64 void set_int_list(); |
|
65 void set_double_list(); |
|
66 void set_bool_list(); |
|
67 void unset(); |
|
68 void get_default(); |
|
69 void list_dirs(); |
|
70 void list_entries(); |
|
71 void propagate(); |
|
72 void set_external(); |
|
73 }; |
|
74 |
|
75 // Useful if you need to process some events until a condition becomes |
|
76 // true. |
|
77 |
|
78 #define QVERIFY_TIMEOUT(msecs, expr) \ |
|
79 do { \ |
|
80 timed_out = false; \ |
|
81 timer.start(msecs); \ |
|
82 while (!timed_out && !(expr)) { \ |
|
83 QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); \ |
|
84 } \ |
|
85 QVERIFY((expr)); \ |
|
86 } while(0) |