summaryrefslogtreecommitdiffstats
path: root/tests/auto/integrationtests/exceptionsafety/tst_exceptionsafety.cpp
blob: 27db9ea7f733a4c0ca6b21cb44d46f53e637e20c (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/


#include <QtTest/QtTest>

QT_USE_NAMESPACE

class tst_ExceptionSafety: public QObject
{
    Q_OBJECT
private slots:
#ifdef QT_NO_EXCEPTIONS
    void initTestCase();
#else
    void exceptionInSlot();
    void exceptionVector();
    void exceptionHash();
    void exceptionMap();
    void exceptionList();
    void exceptionLinkedList();
//    void exceptionEventLoop();
//    void exceptionSignalSlot();
#endif
};

#ifdef QT_NO_EXCEPTIONS
void tst_ExceptionSafety::initTestCase()
{
    QSKIP("This test requires exception support", SkipAll);
}

#else

class Emitter : public QObject
{
    Q_OBJECT
public:
    inline void emitTestSignal() { emit testSignal(); }
signals:
    void testSignal();
};

class ExceptionThrower : public QObject
{
    Q_OBJECT
public slots:
    void thrower() { throw 5; }
};

class Receiver : public QObject
{
    Q_OBJECT
public:
    Receiver()
        : received(0) {}
    int received;

public slots:
    void receiver() { ++received; }
};

enum ThrowType { ThrowNot = 0, ThrowAtCreate = 1, ThrowAtCopy = 2, ThrowLater = 3, ThrowAtComparison = 4 };

ThrowType throwType = ThrowNot; // global flag to indicate when an exception should be throw. Will be reset when the exception has been generated.

int objCounter = 0;

/*! Class that does not throw any exceptions. Used as baseclass for all the other ones.
 */
template <int T>
class FlexibleThrower
{
    public:
        FlexibleThrower() : _value(-1) {
            if( throwType == ThrowAtCreate ) {
                throwType = ThrowNot;
                throw ThrowAtCreate;
            }
            objCounter++;
        }

        FlexibleThrower( short value ) : _value(value) {
            if( throwType == ThrowAtCreate ) {
                throwType = ThrowNot;
                throw ThrowAtCreate;
            }
            objCounter++;
        }

        FlexibleThrower(FlexibleThrower const& other ) {
            // qDebug("cc");

            if( throwType == ThrowAtCopy ) {
                throwType = ThrowNot;
                throw ThrowAtCopy;

            } else if( throwType == ThrowLater ) {
                throwType = ThrowAtCopy;
            }

            objCounter++;
            _value = other.value();
        }

        ~FlexibleThrower() { objCounter--; }

        bool operator==(const FlexibleThrower<T> &t) const
        {
            // qDebug("vv == %d %d", value(), t.value());
            if( throwType == ThrowAtComparison ) {
                throwType = ThrowNot;
                throw ThrowAtComparison;
            }
            return value()==t.value();
        }

        bool operator<(const FlexibleThrower<T> &t) const
        {
            // qDebug("vv < %d %d", value(), t.value());
            if( throwType == ThrowAtComparison ) {
                throwType = ThrowNot;
                throw ThrowAtComparison;
            }
            return value()<t.value();
        }

        int value() const
        { return (int)_value; }

        short _value;
        char dummy[T];
};

uint qHash(const FlexibleThrower<2>& t)
{
    // qDebug("ha");
    if( throwType == ThrowAtComparison ) {
        throwType = ThrowNot;
        throw ThrowAtComparison;
    }
    return (uint)t.value();
}

typedef FlexibleThrower<2> FlexibleThrowerSmall;
typedef QMap<FlexibleThrowerSmall,FlexibleThrowerSmall> MyMap;
typedef QHash<FlexibleThrowerSmall,FlexibleThrowerSmall> MyHash;

// connect a signal to a slot that throws an exception
// run this through valgrind to make sure it doesn't corrupt
void tst_ExceptionSafety::exceptionInSlot()
{
    Emitter emitter;
    ExceptionThrower thrower;

    connect(&emitter, SIGNAL(testSignal()), &thrower, SLOT(thrower()));

    try {
        emitter.emitTestSignal();
    } catch (int i) {
        QCOMPARE(i, 5);
    }
}

void tst_ExceptionSafety::exceptionList() {

    {
        QList<FlexibleThrowerSmall> list;
        QList<FlexibleThrowerSmall> list2;
        QList<FlexibleThrowerSmall> list3;

        for( int i = 0; i<10; i++ )
            list.append( FlexibleThrowerSmall(i) );

        try {
            throwType = ThrowAtCopy;
            list.append( FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( list.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            list.prepend( FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( list.at(0).value(), 0 );
        QCOMPARE( list.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            list.insert( 8, FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( list.at(7).value(), 7 );
        QCOMPARE( list.at(8).value(), 8 );
        QCOMPARE( list.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            FlexibleThrowerSmall t = list.takeAt( 6 );
        } catch (...) {
        }
        QCOMPARE( list.at(6).value(), 6 );
        QCOMPARE( list.at(7).value(), 7 );
        QCOMPARE( list.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            list3 = list;
        } catch (...) {
        }
        QCOMPARE( list.at(0).value(), 0 );
        QCOMPARE( list.at(7).value(), 7 );
        QCOMPARE( list.size(), 10 );
        QCOMPARE( list3.at(0).value(), 0 );
        QCOMPARE( list3.at(7).value(), 7 );
        QCOMPARE( list3.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            list3.append( FlexibleThrowerSmall(11) );
        } catch (...) {
        }
        QCOMPARE( list.at(0).value(), 0 );
        QCOMPARE( list.at(7).value(), 7 );
        QCOMPARE( list.size(), 10 );
        QCOMPARE( list3.at(0).value(), 0 );
        QCOMPARE( list3.at(7).value(), 7 );
        QCOMPARE( list3.size(), 10 );

        try {
            list2.clear();
            list2.append( FlexibleThrowerSmall(11));
            throwType = ThrowAtCopy;
            list3 = list+list2;
        } catch (...) {
        }
        QCOMPARE( list.at(0).value(), 0 );
        QCOMPARE( list.at(7).value(), 7 );
        QCOMPARE( list.size(), 10 );

        // check that copy on write works atomar
        list2.clear();
        list2.append( FlexibleThrowerSmall(11));
        list3 = list+list2;
        try {
            throwType = ThrowAtCreate;
            list3[7]=FlexibleThrowerSmall(12);
        } catch (...) {
        }
        QCOMPARE( list.at(7).value(), 7 );
        QCOMPARE( list.size(), 10 );
        QCOMPARE( list3.at(7).value(), 7 );
        QCOMPARE( list3.size(), 11 );

    }
    QCOMPARE(objCounter, 0 ); // check that every object has been freed
}

void tst_ExceptionSafety::exceptionLinkedList() {

    {
        QLinkedList<FlexibleThrowerSmall> list;
        QLinkedList<FlexibleThrowerSmall> list2;
        QLinkedList<FlexibleThrowerSmall> list3;

        for( int i = 0; i<10; i++ )
            list.append( FlexibleThrowerSmall(i) );

        try {
            throwType = ThrowAtCopy;
            list.append( FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( list.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            list.prepend( FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( list.first().value(), 0 );
        QCOMPARE( list.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            list3 = list;
            list3.append( FlexibleThrowerSmall(11) );
        } catch (...) {
        }
        QCOMPARE( list.first().value(), 0 );
        QCOMPARE( list.size(), 10 );
        QCOMPARE( list3.size(), 10 );
    }
    QCOMPARE(objCounter, 0 ); // check that every object has been freed
}

void tst_ExceptionSafety::exceptionVector() {

    {
        QVector<FlexibleThrowerSmall> vector;
        QVector<FlexibleThrowerSmall> vector2;
        QVector<FlexibleThrowerSmall> vector3;

        for (int i = 0; i<10; i++)
            vector.append( FlexibleThrowerSmall(i) );

        try {
            throwType = ThrowAtCopy;
            vector.append( FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( vector.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            vector.prepend( FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( vector.at(0).value(), 0 );
        QCOMPARE( vector.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            vector.insert( 8, FlexibleThrowerSmall(10));
        } catch (...) {
        }
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.at(8).value(), 8 );
        QCOMPARE( vector.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            vector3 = vector;
        } catch (...) {
        }
        QCOMPARE( vector.at(0).value(), 0 );
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.size(), 10 );
        QCOMPARE( vector3.at(0).value(), 0 );
        QCOMPARE( vector3.at(7).value(), 7 );
        QCOMPARE( vector3.size(), 10 );

        try {
            throwType = ThrowAtCopy;
            vector3.append( FlexibleThrowerSmall(11) );
        } catch (...) {
        }
        QCOMPARE( vector.at(0).value(), 0 );
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.size(), 10 );
        QCOMPARE( vector3.at(0).value(), 0 );
        QCOMPARE( vector3.at(7).value(), 7 );

        try {
            vector2.clear();
            vector2.append( FlexibleThrowerSmall(11));
            throwType = ThrowAtCopy;
            vector3 = vector+vector2;
        } catch (...) {
        }
        QCOMPARE( vector.at(0).value(), 0 );
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.size(), 10 );

        // check that copy on write works atomar
        vector2.clear();
        vector2.append( FlexibleThrowerSmall(11));
        vector3 = vector+vector2;
        try {
            throwType = ThrowAtCreate;
            vector3[7]=FlexibleThrowerSmall(12);
        } catch (...) {
        }
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.size(), 10 );
        QCOMPARE( vector3.at(7).value(), 7 );
        QCOMPARE( vector3.size(), 11 );

        try {
            throwType = ThrowAtCreate;
            vector.resize(15);
        } catch (...) {
        }
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.size(), 10 );

        try {
            throwType = ThrowAtCreate;
            vector.resize(15);
        } catch (...) {
        }
        QCOMPARE( vector.at(7).value(), 7 );
        QCOMPARE( vector.size(), 10 );

        try {
            throwType = ThrowLater;
            vector.fill(FlexibleThrowerSmall(1), 15);
        } catch (...) {
        }
        QCOMPARE( vector.at(0).value(), 0 );
        QCOMPARE( vector.size(), 10 );


    }
    QCOMPARE(objCounter, 0 ); // check that every object has been freed
}


void tst_ExceptionSafety::exceptionMap() {

    {
        MyMap map;
        MyMap map2;
        MyMap map3;

        throwType = ThrowNot;
        for (int i = 0; i<10; i++)
            map[ FlexibleThrowerSmall(i) ] = FlexibleThrowerSmall(i);

        return; // further test are deactivated until Map is fixed.

        for( int i = ThrowAtCopy; i<=ThrowAtComparison; i++ ) {
            try {
                throwType = (ThrowType)i;
                map[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
            } catch(...) {
            }
            QCOMPARE( map.size(), 10 );
            QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        }

        map2 = map;
        try {
            throwType = ThrowLater;
            map2[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
        } catch(...) {
        }
        /* qDebug("%d %d", map.size(), map2.size() );
        for( int i=0; i<map.size(); i++ )
            qDebug( "Value at %d: %d",i, map.value(FlexibleThrowerSmall(i), FlexibleThrowerSmall()).value() );
        QCOMPARE( map.value(FlexibleThrowerSmall(1), FlexibleThrowerSmall()), FlexibleThrowerSmall(1) );
        qDebug( "Value at %d: %d",1, map[FlexibleThrowerSmall(1)].value() );
        qDebug("%d %d", map.size(), map2.size() );
        */
        QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        QCOMPARE( map.size(), 10 );
        QCOMPARE( map2[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        QCOMPARE( map2.size(), 10 );

    }
    QCOMPARE(objCounter, 0 ); // check that every object has been freed
}

void tst_ExceptionSafety::exceptionHash() {

    {
        MyHash hash;
        MyHash hash2;
        MyHash hash3;

        for( int i = 0; i<10; i++ )
            hash[ FlexibleThrowerSmall(i) ] = FlexibleThrowerSmall(i);

        for( int i = ThrowAtCopy; i<=ThrowAtComparison; i++ ) {
            try {
                throwType = (ThrowType)i;
                hash[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
            } catch(...) {
            }
            QCOMPARE( hash.size(), 10 );
        }

        hash2 = hash;
        try {
            throwType = ThrowLater;
            hash2[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
        } catch(...) {
        }
        QCOMPARE( hash[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        QCOMPARE( hash.size(), 10 );
        QCOMPARE( hash2[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        QCOMPARE( hash2.size(), 10 );

        hash2.clear();
        try {
            throwType = ThrowLater;
            hash2.reserve(30);
        } catch(...) {
        }
        QCOMPARE( hash2.size(), 0 );

        /*
           try {
           throwType = ThrowAtCopy;
           hash.prepend( FlexibleThrowerSmall(10));
           } catch (...) {
           }
           QCOMPARE( hash.at(0).value(), 0 );
           QCOMPARE( hash.size(), 10 );

           try {
           throwType = ThrowAtCopy;
           hash.insert( 8, FlexibleThrowerSmall(10));
           } catch (...) {
           }
           QCOMPARE( hash.at(7).value(), 7 );
           QCOMPARE( hash.at(8).value(), 8 );
           QCOMPARE( hash.size(), 10 );

           qDebug("val");
           try {
           throwType = ThrowAtCopy;
           hash3 = hash;
           } catch (...) {
           }
           QCOMPARE( hash.at(0).value(), 0 );
           QCOMPARE( hash.at(7).value(), 7 );
           QCOMPARE( hash.size(), 10 );
           QCOMPARE( hash3.at(0).value(), 0 );
           QCOMPARE( hash3.at(7).value(), 7 );
           QCOMPARE( hash3.size(), 10 );

           try {
           throwType = ThrowAtCopy;
           hash3.append( FlexibleThrowerSmall(11) );
           } catch (...) {
           }
           QCOMPARE( hash.at(0).value(), 0 );
           QCOMPARE( hash.at(7).value(), 7 );
           QCOMPARE( hash.size(), 10 );
           QCOMPARE( hash3.at(0).value(), 0 );
           QCOMPARE( hash3.at(7).value(), 7 );
           QCOMPARE( hash3.at(11).value(), 11 );

           try {
           hash2.clear();
           hash2.append( FlexibleThrowerSmall(11));
           throwType = ThrowAtCopy;
           hash3 = hash+hash2;
           } catch (...) {
           }
           QCOMPARE( hash.at(0).value(), 0 );
           QCOMPARE( hash.at(7).value(), 7 );
           QCOMPARE( hash.size(), 10 );

        // check that copy on write works atomar
        hash2.clear();
        hash2.append( FlexibleThrowerSmall(11));
        hash3 = hash+hash2;
        try {
        throwType = ThrowAtCopy;
        hash3[7]=FlexibleThrowerSmall(12);
        } catch (...) {
        }
        QCOMPARE( hash.at(7).value(), 7 );
        QCOMPARE( hash.size(), 10 );
        QCOMPARE( hash3.at(7).value(), 7 );
        QCOMPARE( hash3.size(), 11 );
        */


    }
    QCOMPARE(objCounter, 0 ); // check that every object has been freed
}

// Disable these tests until the level of exception safety in event loops is clear
#if 0
enum
{
    ThrowEventId = QEvent::User + 42,
    NoThrowEventId = QEvent::User + 43
};

class ThrowEvent : public QEvent
{
public:
    ThrowEvent()
        : QEvent(static_cast<QEvent::Type>(ThrowEventId))
    {
    }
};

class NoThrowEvent : public QEvent
{
public:
    NoThrowEvent()
        : QEvent(static_cast<QEvent::Type>(NoThrowEventId))
    {}
};

struct IntEx : public std::exception
{
    IntEx(int aEx) : ex(aEx) {}
    int ex;
};

class TestObject : public QObject
{
public:
    TestObject()
        : throwEventCount(0), noThrowEventCount(0) {}

    int throwEventCount;
    int noThrowEventCount;

protected:
    bool event(QEvent *event)
    {
        if (int(event->type()) == ThrowEventId) {
             throw IntEx(++throwEventCount);
        } else if (int(event->type()) == NoThrowEventId) {
            ++noThrowEventCount;
        }
        return QObject::event(event);
    }
};

void tst_ExceptionSafety::exceptionEventLoop()
{
    // send an event that throws
    TestObject obj;
    ThrowEvent throwEvent;
    try {
        qApp->sendEvent(&obj, &throwEvent);
    } catch (IntEx code) {
        QCOMPARE(code.ex, 1);
    }
    QCOMPARE(obj.throwEventCount, 1);

    // post an event that throws
    qApp->postEvent(&obj, new ThrowEvent);

    try {
        qApp->processEvents();
    } catch (IntEx code) {
        QCOMPARE(code.ex, 2);
    }
    QCOMPARE(obj.throwEventCount, 2);

    // post a normal event, then a throwing event, then a normal event
    // run this in valgrind to ensure that it doesn't leak.

    qApp->postEvent(&obj, new NoThrowEvent);
    qApp->postEvent(&obj, new ThrowEvent);
    qApp->postEvent(&obj, new NoThrowEvent);

    try {
        qApp->processEvents();
    } catch (IntEx code) {
        QCOMPARE(code.ex, 3);
    }
    // here, we should have received on non-throwing event and one throwing one
    QCOMPARE(obj.throwEventCount, 3);
    QCOMPARE(obj.noThrowEventCount, 1);

    // spin the event loop again
    qApp->processEvents();

    // now, we should have received the second non-throwing event
    QCOMPARE(obj.noThrowEventCount, 2);
}

void tst_ExceptionSafety::exceptionSignalSlot()
{
    Emitter e;
    ExceptionThrower thrower;
    Receiver r1;
    Receiver r2;

    // connect a signal to a normal object, a thrower and a normal object again
    connect(&e, SIGNAL(testSignal()), &r1, SLOT(receiver()));
    connect(&e, SIGNAL(testSignal()), &thrower, SLOT(thrower()));
    connect(&e, SIGNAL(testSignal()), &r2, SLOT(receiver()));

    int code = 0;
    try {
        e.emitTestSignal();
    } catch (int c) {
        code = c;
    }

    // 5 is the magic number that's thrown by thrower
    QCOMPARE(code, 5);

    // assumption: slots are called in the connection order
    QCOMPARE(r1.received, 1);
    QCOMPARE(r2.received, 0);
}
#endif

#endif

QTEST_MAIN(tst_ExceptionSafety)
#include "tst_exceptionsafety.moc"