We now have a current svn snapshot of libqxt in our contrib dir, and
[quassel.git] / src / contrib / libqxt-2007-10-24 / tests / job / main.cpp
1 /** ***** QxtJob test ***** */
2 #include <QTest>
3 #include <QThread>
4 class Q43Thread : public QThread{public:void run(){exec();}}; /// qt < 4.3 backwards compatibility
5
6 #include <QSignalSpy>
7 #include <QxtJob>
8 #include <qxtsignalwaiter.h>
9
10
11
12 class TestJob : public QxtJob
13 {
14 public:
15     bool b;
16     TestJob():QxtJob()
17     {
18         b=false;
19     }
20     virtual void run()
21     {
22         qDebug("job on on %p",QThread::currentThread ());
23         b=true;
24     }
25 };
26
27 class QxtJobTest : public QObject
28 {
29 Q_OBJECT
30 private:
31     Q43Thread t;
32 private slots:
33     void initTestCase()
34     {
35         t.start();
36     }
37
38     void lined()
39     {
40         
41         TestJob l;
42         QSignalSpy spy(&l, SIGNAL(done()));
43         QxtSignalWaiter w(&l,SIGNAL(done()));
44
45         l.exec(&t);
46
47         QVERIFY(w.wait(50));
48         QCOMPARE(spy.count(), 1);
49         QVERIFY(l.b);
50     }
51
52     void joined()
53     {
54         TestJob l;
55         l.exec(&t);
56         QxtSignalWaiter w(&l,SIGNAL(done()));
57         l.join();
58         QVERIFY(w.wait(100));
59         QVERIFY(l.b);
60     }
61
62     void cleanupTestCase()
63     {
64         t.quit();
65         QVERIFY(t.wait(50));
66     }
67 };
68
69
70 int main(int argc, char ** argv)
71 {
72     QCoreApplication app(argc,argv);
73     QxtJobTest test1;
74     return QTest::qExec(&test1,argc,argv);
75 }
76
77
78 #include "main.moc"