simple_test_app.cpp 166 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** 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.
**
con's avatar
con committed
28
**
29
**************************************************************************/
con's avatar
con committed
30

hjk's avatar
hjk committed
31
32
33
34
35
36
////////////////  Some global configuration below ////////////////


// The following defines can be used to steer the kind of tests that
// can be done.

37
38
39
40
41
// With USE_AUTORUN, creator will automatically "execute" the commands
// in a comment following a BREAK_HERE line.
// The following commands are supported:
//   // Check <name> <value> <type>
//         - Checks whether the local variable is displayed with value and type.
hjk's avatar
hjk committed
42
43
44
45
46
47
48
//   // CheckType <name> <type>
//         - Checks whether the local variable is displayed with type.
//           The value is untested, so it can be used with pointers values etc.
//           that would change between test runs
//   // Continue
//       - Continues execution
// On the TODO list:
49
//   // Expand <name1>[ <name2> ...].
hjk's avatar
hjk committed
50
//         - Expands local variables with given names.
51
52
//           There should be at most one "Expand" line per BREAK_HERE,
//           and this should placed on the line following the BREAK_HERE
hjk's avatar
hjk committed
53
54
55
//           FIXME: Not implemented yet.


David Schulz's avatar
David Schulz committed
56
// Value: 1
57
58
// If the line after a BREAK_HERE line does not contain one of the
// supported commands, the test stops.
David Schulz's avatar
David Schulz committed
59
60
61
// Value: 2
// Same as 1, except that the debugger will stop automatically when
// a test after a BREAK_HERE failed
62
// Default: 0
63
64
// Before using this, make sure that "Show a message box when receiving a signal"
// is disabled in "Tools" -> "Options..." -> "Debugger" -> "GDB".
hjk's avatar
hjk committed
65
#ifndef USE_AUTORUN
66
#define USE_AUTORUN 0
hjk's avatar
hjk committed
67
68
69
70
71
72
73
74
75
#endif

// With USE_AUTOBREAK, the debugger will stop automatically on all
// lines containing the BREAK_HERE macro. This should be enabled
// during manual testing.
// Default: 0
#ifndef USE_AUTOBREAK
#define USE_AUTOBREAK 0
#endif
76

hjk's avatar
hjk committed
77
// With USE_UNINITIALIZED_AUTOBREAK, the debugger will stop automatically
hjk's avatar
hjk committed
78
79
// on all lines containing the BREAK_UNINITIALIZED_HERE macro.
// This should be enabled during manual testing.
80
// Default: 0
hjk's avatar
hjk committed
81
#ifndef USE_UNINITIALIZED_AUTOBREAK
82
#define USE_UNINITIALIZED_AUTOBREAK 0
hjk's avatar
hjk committed
83
#endif
hjk's avatar
hjk committed
84

hjk's avatar
hjk committed
85
86
87

////////////// No further global configuration below ////////////////

hjk's avatar
hjk committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// AUTORUN is only sensibly with AUTOBREAK and without UNINITIALIZED_AUTOBREAK
#if USE_AUTORUN
#if !(USE_AUTOBREAK)
#undef USE_AUTOBREAK
#define USE_AUTOBREAK 1
#warning Switching on USE_AUTOBREAK
#endif // !USE_AUTOBREAK
#if USE_UNINITIALIZED_AUTOBREAK
#undef USE_UNINITIALIZED_AUTOBREAK
#define USE_UNINITIALIZED_AUTOBREAK 0
#warning Switching off USE_AUTOBREAK
#endif // USE_UNINITIALIZED_AUTOBREAK
#endif

102
#ifdef QT_SCRIPT_LIB
103
104
105
106
107
#define USE_SCRIPTLIB 1
#else
#define USE_SCRIPTLIB 0
#endif

108
109
110
111
112
113
#ifdef QT_WEBKIT_LIB
#define USE_WEBKITLIB 1
#else
#define USE_WEBKITLIB 0
#endif

114
115
116
117
118
#if QT_VERSION >= 0x040500
#define USE_SHARED_POINTER 1
#else
#define USE_SHARED_POINTER 0
#endif
119

hjk's avatar
hjk committed
120
void dummyStatement(...) {}
hjk's avatar
hjk committed
121

122
123
124
125
#if USE_CXX11 && defined(__GNUC__) && defined(__STRICT_ANSI__)
#undef __STRICT_ANSI__ // working around compile error with MinGW
#endif

126
#include <QCoreApplication>
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <QDebug>
#include <QDateTime>
#include <QDir>
#include <QHash>
#include <QLibrary>
#include <QLinkedList>
#include <QList>
#include <QMap>
#include <QPointer>
#include <QProcess>
#include <QRegExp>
#include <QString>
#include <QStringList>
#include <QSettings>
#include <QStack>
#include <QThread>
#include <QVariant>
#include <QVector>
#include <QUrl>
146
#if USE_SHARED_POINTER
147
#include <QSharedPointer>
148
#endif
con's avatar
con committed
149

150
151
152
#if USE_GUILIB
#include <QAction>
#include <QApplication> // QWidgets: Separate module as of Qt 5
153
154
#include <QColor>
#include <QFont>
155
#include <QLabel>
156
157
158
#include <QPainter>
#include <QPainterPath>
#include <QRegion>
159
#include <QStandardItemModel>
160
161
#include <QTextCursor>
#include <QTextDocument>
162
#endif
con's avatar
con committed
163

164
#if USE_SCRIPTLIB
165
166
#include <QScriptEngine>
#include <QScriptValue>
167
#endif
168

169
170
171
172
#if USE_WEBKITLIB
#include <QWebPage>
#endif

173
#include <QXmlAttributes>
hjk's avatar
hjk committed
174

175
176
#include <QHostAddress>
#include <QNetworkRequest>
con's avatar
con committed
177

178
179
180
#if USE_CXX11
#include <array>
#endif
181
#include <complex>
hjk's avatar
hjk committed
182
#include <deque>
con's avatar
con committed
183
#include <iostream>
hjk's avatar
hjk committed
184
#include <iterator>
185
#include <fstream>
186
#include <map>
187
#include <memory>
hjk's avatar
hjk committed
188
#include <list>
189
#include <limits>
190
#include <set>
hjk's avatar
hjk committed
191
#include <stack>
con's avatar
con committed
192
193
194
#include <string>
#include <vector>

hjk's avatar
hjk committed
195
196
#include <stdarg.h>

197
198
#include "../simple/deep/deep/simple_test_app.h"

199
200

#if USE_BOOST
201
#include <boost/optional.hpp>
202
#include <boost/shared_ptr.hpp>
203
#include <boost/date_time.hpp>
204
#include <boost/date_time/gregorian/gregorian.hpp>
205
#include <boost/date_time/posix_time/posix_time.hpp>
206
#include <boost/bimap.hpp>
207
#endif
208

hjk's avatar
hjk committed
209
210
211
212
#if USE_EIGEN
#include <eigen2/Eigen/Core>
#endif

213
#if USE_PRIVATE
214
#include <private/qobject_p.h>
215
216
#endif

217
#if defined(__GNUC__) && !defined(__llvm__) && !defined(Q_OS_MAC)
218
#    define USE_GCC_EXT 1
219
#    undef __DEPRECATED
220
#    include <ext/hash_set>
221
222
#endif

con's avatar
con committed
223
224
#ifdef Q_OS_WIN
#include <windows.h>
225
226
#undef min
#undef max
con's avatar
con committed
227
228
#endif

229
#ifdef __SSE__
hjk's avatar
hjk committed
230
231
232
#include <xmmintrin.h>
#include <stddef.h>
#endif
233

hjk's avatar
hjk committed
234
#if USE_AUTOBREAK
235
#   ifdef Q_CC_MSVC
hjk's avatar
hjk committed
236
237
238
239
240
#       define BREAK_HERE __asm { int 3 }; __asm { mov eax, eax }
#   else
#       define BREAK_HERE asm("int $3; mov %eax, %eax")
#   endif
#else
241
#   define BREAK_HERE dummyStatement()
hjk's avatar
hjk committed
242
243
#endif

hjk's avatar
hjk committed
244
#if USE_UNINITIALIZED_AUTOBREAK
245
#   ifdef Q_CC_MSVC
hjk's avatar
hjk committed
246
247
248
249
250
#       define BREAK_UNINITIALIZED_HERE __asm { int 3 }; __asm { mov eax, eax }
#   else
#       define BREAK_UNINITIALIZED_HERE asm("int $3; mov %eax, %eax")
#   endif
#else
251
#   define BREAK_UNINITIALIZED_HERE dummyStatement()
hjk's avatar
hjk committed
252
253
254
#endif


255
QT_BEGIN_NAMESPACE
hjk's avatar
hjk committed
256
257
uint qHash(const QMap<int, int> &) { return 0; }
uint qHash(const double & f) { return int(f); }
258
uint qHash(const QPointer<QObject> &p) { return (ulong)p.data(); }
259
260
261
262
263
264
265
266
267
268
269
270
271
272
QT_END_NAMESPACE


namespace nsA {
namespace nsB {

struct SomeType
{
    SomeType(int a) : a(a) {}
    int a;
};

} // namespace nsB
} // namespace nsA
hjk's avatar
hjk committed
273
274


275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
struct BaseClass
{
    BaseClass() : a(1) {}
    virtual ~BaseClass() {}
    virtual int foo() { return a; }
    int a;
};

struct DerivedClass : BaseClass
{
    DerivedClass() : b(2) {}
    int foo() { return b; }
    int b;
};

290
namespace multibp {
291

292
    // This tests multiple breakpoints.
293
294
295
296
297
    template <typename T> class Vector
    {
    public:
        explicit Vector(int size)
            : m_size(size), m_data(new T[size])
298
299
        {
            BREAK_HERE;
300
301
            // Check size 10 int.
            // Continue.
302
303
            // Manual: Add a breakpoint in the constructor
            // Manual: Check there are multiple entries in the Breakpoint view.
hjk's avatar
hjk committed
304
            dummyStatement(this);
305
        }
306
307
308
309
310
311
312
        ~Vector() { delete [] m_data; }
        int size() const { return m_size; }
    private:
        int m_size;
        T *m_data;
    };

hjk's avatar
hjk committed
313
    void testMultiBp()
314
315
316
317
318
    {
        Vector<int> vi(10);
        Vector<float> vf(10);
        Vector<double> vd(10);
        Vector<char> vc(10);
hjk's avatar
hjk committed
319
        dummyStatement(&vi, &vf, &vd, &vc);
320
    }
321
322

} // namespace multibp
323

hjk's avatar
hjk committed
324

325

hjk's avatar
hjk committed
326

hjk's avatar
hjk committed
327
class Foo
con's avatar
con committed
328
329
{
public:
hjk's avatar
hjk committed
330
    Foo(int i = 0)
con's avatar
con committed
331
332
333
334
335
        : a(i), b(2)
    {
        int s = 1;
        int t = 2;
        b = 2 + s + t;
hjk's avatar
hjk committed
336
        dummyStatement(&s, &t);
con's avatar
con committed
337
    }
338

339
    virtual ~Foo()
340
341
342
343
    {
        a = 5;
    }

con's avatar
con committed
344
345
346
347
348
349
350
351
    void doit()
    {
        static QObject ob;
        m["1"] = "2";
        h[&ob] = m.begin();

        a += 1;
        --b;
352
        dummyStatement(&a, &b);
con's avatar
con committed
353
354
355
356
357
358
359
360
361
362
363
364
    }

public:
    int a, b;
    char x[6];

private:
    typedef QMap<QString, QString> Map;
    Map m;
    QHash<QObject *, Map::iterator> h;
};

365
366
367
368
369
370
371
class Fooooo : public Foo
{
public:
    Fooooo(int x) : Foo(x), a(x + 2) {}
    int a;
};

hjk's avatar
hjk committed
372
class X : virtual public Foo { public: X() { } };
hjk's avatar
hjk committed
373

hjk's avatar
hjk committed
374
class XX : virtual public Foo { public: XX() { } };
375

hjk's avatar
hjk committed
376
class Y : virtual public Foo { public: Y() { } };
hjk's avatar
hjk committed
377

hjk's avatar
hjk committed
378
class D : public X, public Y { int diamond; };
379

hjk's avatar
hjk committed
380
381
382
383

namespace peekandpoke {

    void testAnonymousStructs()
hjk's avatar
hjk committed
384
    {
hjk's avatar
hjk committed
385
        #ifndef Q_CC_RVCT
hjk's avatar
hjk committed
386
387
388
389
        union {
            struct { int i; int b; };
            struct { float f; };
            double d;
390
        } a = { { 42, 43 } };
hjk's avatar
hjk committed
391
        BREAK_HERE;
392
        // Expand a.
393
        // CheckType a union {...}.
394
395
396
397
        // Check a.b 43 int.
        // Check a.d 9.1245819032257467e-313 double.
        // Check a.f 5.88545355e-44 float.
        // Check a.i 42 int.
398
399
        // Continue.

hjk's avatar
hjk committed
400
401
        a.i = 1;
        BREAK_HERE;
402
        // Expand a.
403
        // CheckType a union {...}.
404
405
406
407
        // Check a.b 43 int.
        // Check a.d 9.1245819012000775e-313 double.
        // Check a.f 1.40129846e-45 float.
        // Check a.i 1 int.
408
        // Continue.
409

hjk's avatar
hjk committed
410
411
        a.i = 2;
        BREAK_HERE;
412
        // Expand a.
413
        // CheckType a union {...}.
414
415
416
417
        // Check a.b 43 int.
        // Check a.d 9.1245819012494841e-313 double.
        // Check a.f 2.80259693e-45 float.
        // Check a.i 2 int.
418
        // Continue.
419

hjk's avatar
hjk committed
420
421
        dummyStatement(&a);
        #endif
hjk's avatar
hjk committed
422
423
    }

hjk's avatar
hjk committed
424
    void testComplexWatchers()
hjk's avatar
hjk committed
425
426
    {
        struct S { int a; double b; } s[10];
hjk's avatar
hjk committed
427
        BREAK_HERE;
428
        // Expand s and s[0].
429
430
431
        // CheckType s peekandpoke::S [10].
        // Continue.

432
433
434
435
        // Manual: Watcher Context: "Add New Watcher".
        // Manual: Type    ['s[%d].a' % i for i in range(5)]
        // Manual: Expand it, continue stepping. This should result in a list
        // Manual: of five items containing the .a fields of s[0]..s[4].
436
437
438
        for (int i = 0; i != 10; ++i)
            s[i].a = i;

hjk's avatar
hjk committed
439
        dummyStatement(&s);
hjk's avatar
hjk committed
440
    }
hjk's avatar
hjk committed
441

hjk's avatar
hjk committed
442
    void testQImageDisplay()
hjk's avatar
hjk committed
443
    {
444
        #if USE_GUILIB
hjk's avatar
hjk committed
445
446
447
448
449
        QImage im(QSize(200, 200), QImage::Format_RGB32);
        im.fill(QColor(200, 10, 30).rgba());
        QPainter pain;
        pain.begin(&im);
        pain.setPen(QPen(Qt::black, 5.0, Qt::SolidLine, Qt::RoundCap));
hjk's avatar
hjk committed
450
        BREAK_HERE;
451
452
453
        // Check im (200x200) QImage.
        // CheckType pain QPainter.
        // Continue.
454

hjk's avatar
hjk committed
455
456
        pain.drawEllipse(20, 20, 160, 160);
        BREAK_HERE;
457
        // Continue.
458
459
460

        // Manual: Toggle between "Normal" and "Displayed" in L&W Context Menu,
        // Manual: entry "Display of Type QImage".
hjk's avatar
hjk committed
461
        pain.drawArc(70, 115, 60, 30, 200 * 16, 140 * 16);
hjk's avatar
hjk committed
462
        BREAK_HERE;
463
        // Continue.
464

hjk's avatar
hjk committed
465
        pain.setBrush(Qt::black);
hjk's avatar
hjk committed
466
        BREAK_HERE;
467
        // Continue.
468

hjk's avatar
hjk committed
469
470
        pain.drawEllipse(65, 70, 15, 15);
        BREAK_HERE;
471
        // Continue.
472
473
474

        // Manual: Toggle between "Normal" and "Displayed" in L&W Context Menu,
        // Manual: entry "Display of Type QImage".
hjk's avatar
hjk committed
475
476
        pain.drawEllipse(120, 70, 15, 15);
        BREAK_HERE;
477
        // Continue.
478

hjk's avatar
hjk committed
479
        pain.end();
hjk's avatar
hjk committed
480
        dummyStatement(&pain);
481
        #endif
hjk's avatar
hjk committed
482
483
    }

hjk's avatar
hjk committed
484
485
486
487
488
489
490
491
    void testPeekAndPoke3()
    {
        testAnonymousStructs();
        testComplexWatchers();
        testQImageDisplay();
    }

} // namespace peekandpoke
492

493

hjk's avatar
hjk committed
494
namespace anon {
495

hjk's avatar
hjk committed
496
497
    #ifndef Q_CC_RVCT
    struct TestAnonymous
498
    {
hjk's avatar
hjk committed
499
500
501
502
503
504
        union {
            struct { int i; int b; };
            struct { float f; };
            double d;
        };
    };
505

hjk's avatar
hjk committed
506
    namespace {
507

hjk's avatar
hjk committed
508
509
510
        struct Something
        {
            Something() { a = b = 1; }
511

hjk's avatar
hjk committed
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
            void foo()
            {
                a = 42;
                b = 43;
            }

            int a, b;
        };

    }
    #endif

    void testAnonymous()
    {
    #ifndef Q_CC_RVCT
        TestAnonymous a;
528
        BREAK_HERE;
529
        // Expand a a.#1 a.#2.
530
531
532
533
534
535
536
        // CheckType a anon::TestAnonymous.
        // Check a.#1   {...}.
        // CheckType a.#1.b int.
        // CheckType a.#1.i int.
        // CheckType a.#2.f float.
        // CheckType a.d double.
        // Continue.
hjk's avatar
hjk committed
537
538
539
        a.i = 1;
        a.i = 2;
        a.i = 3;
540

hjk's avatar
hjk committed
541
        Something s;
542
        BREAK_HERE;
543
        // Expand s.
544
        // CheckType s anon::(anonymous namespace)::Something.
545
546
        // Check s.a 1 int.
        // Check s.b 1 int.
547
        // Continue.
548

hjk's avatar
hjk committed
549
        s.foo();
550
551
552
553
554
        BREAK_HERE;
        // Expand s.
        // Check s.a 42 int.
        // Check s.b 43 int.
        // Continue.
555
556
557
558
559
560
561

        std::map<int, Something> m;
        BREAK_HERE;
        // CheckType m std::map<int, anon::{anonymous}::Something>.
        // Continue.

        dummyStatement(&a, &s, &m);
hjk's avatar
hjk committed
562
563
564
565
    #endif
    }

} // namespace anon
566

567

hjk's avatar
hjk committed
568
namespace qbytearray {
hjk's avatar
hjk committed
569

hjk's avatar
hjk committed
570
571
572
    void testQByteArray1()
    {
        QByteArray ba;
573
        BREAK_HERE;
574
575
        // Check ba "" QByteArray.
        // Continue.
hjk's avatar
hjk committed
576
577
578
579
580
581
        ba += "Hello";
        ba += '"';
        ba += "World";
        ba += char(0);
        ba += 1;
        ba += 2;
582
        BREAK_HERE;
583
        // Expand ba.
584
        // Check ba "Hello"World" QByteArray.
585
586
587
588
        // Check ba.0 72 'H' char.
        // Check ba.11 0 '\0' char.
        // Check ba.12 1 char.
        // Check ba.13 2 char.
589
        // Continue.
hjk's avatar
hjk committed
590
591
592
593
594
595
596
597
598
599
        dummyStatement(&ba);
    }

    void testQByteArray2()
    {
        QByteArray ba;
        for (int i = 256; --i >= 0; )
            ba.append(char(i));
        QString s(10000, 'x');
        std::string ss(10000, 'c');
600
        BREAK_HERE;
601
        // CheckType ba QByteArray.
602
603
604
        // Check s "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx..." QString.
        // Check ss "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc..." std::string.
        // Continue.
hjk's avatar
hjk committed
605
606
607
608
609
610
611
612
613
614
615
        dummyStatement(&ba, &ss, &s);
    }

    void testQByteArray3()
    {
        const char *str1 = "\356";
        const char *str2 = "\xee";
        const char *str3 = "\\ee";
        QByteArray buf1(str1);
        QByteArray buf2(str2);
        QByteArray buf3(str3);
616
        BREAK_HERE;
617
618
619
        // Check buf1 "î" QByteArray.
        // Check buf2 "î" QByteArray.
        // Check buf3 "\ee" QByteArray.
620
621
        // CheckType str1 char *.
        // Continue.
hjk's avatar
hjk committed
622
623
624
        dummyStatement(&buf1, &buf2, &buf3);
    }

625
626
627
628
629
630
631
632
633
634
635
636
    void testQByteArray4()
    {
        char data[] = { 'H', 'e', 'l', 'l', 'o' };
        QByteArray ba1 = QByteArray::fromRawData(data, 4);
        QByteArray ba2 = QByteArray::fromRawData(data + 1, 4);
        BREAK_HERE;
        // Check ba1 "Hell" QByteArray.
        // Check ba2 "ello" QByteArray.
        // Continue.
        dummyStatement(&ba1, &ba2, &data);
    }

hjk's avatar
hjk committed
637
638
639
640
641
    void testQByteArray()
    {
        testQByteArray1();
        testQByteArray2();
        testQByteArray3();
642
        testQByteArray4();
hjk's avatar
hjk committed
643
644
645
    }

} // namespace qbytearray
con's avatar
con committed
646

647

648
namespace catchthrow {
649

650
651
652
    static void throwit1()
    {
        BREAK_HERE;
653
        // Continue.
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
        // Set a breakpoint on "throw" in the BreakWindow context menu
        // before stepping further.
        throw 14;
    }

    static void throwit()
    {
        throwit1();
    }

    void testCatchThrow()
    {
        int gotit = 0;
        try {
            throwit();
        } catch (int what) {
            gotit = what;
        }
        dummyStatement(&gotit);
    }

} // namespace catchthrow
676
677


hjk's avatar
hjk committed
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
namespace undefined {

    void testUndefined()
    {
        int *i = new int;
        delete i;
        BREAK_HERE;
        // Manual: Uncomment the following line. Step.
        // On Linux, a SIGABRT should be received.
        //delete i;
        // Continue.
        dummyStatement(&i);
    }

} // namespace undefined


hjk's avatar
hjk committed
695
namespace qdatetime {
696

hjk's avatar
hjk committed
697
698
699
    void testQDate()
    {
        QDate date;
700
        BREAK_HERE;
701
        // Expand date.
702
        // CheckType date QDate.
703
704
705
706
        // Check date.(ISO) "" QString.
        // Check date.(Locale) "" QString.
        // Check date.(SystemLocale) "" QString.
        // Check date.toString "" QString.
707
708
        // Continue.

hjk's avatar
hjk committed
709
710
711
712
713
714
        // Step, check display.
        date = QDate::currentDate();
        date = date.addDays(5);
        date = date.addDays(5);
        dummyStatement(&date);
    }
715

hjk's avatar
hjk committed
716
717
718
    void testQTime()
    {
        QTime time;
719
        BREAK_HERE;
720
721
722
723
724
725
        // Expand time.
        // CheckType time QTime.
        // Check time.(ISO) "" QString.
        // Check time.(Locale) "" QString.
        // Check time.(SystemLocale) "" QString.
        // Check time.toString "" QString.
726
        // Continue.
727

hjk's avatar
hjk committed
728
729
730
731
732
733
734
735
736
737
        // Step, check display.
        time = QTime::currentTime();
        time = time.addSecs(5);
        time = time.addSecs(5);
        dummyStatement(&time);
    }

    void testQDateTime()
    {
        QDateTime date;
738
        BREAK_HERE;
739
        // Expand date.
740
        // CheckType date QDateTime.
741
742
743
744
        // Check date.(ISO) "" QString.
        // Check date.(Locale) "" QString.
        // Check date.(SystemLocale) "" QString.
        // Check date.toString "" QString.
745
        // Check date.toUTC  QDateTime.
746
        // Continue.
747

748
        // Step, check display
hjk's avatar
hjk committed
749
        date = QDateTime::currentDateTime();
750
751
        date = date.addDays(5);
        date = date.addDays(5);
hjk's avatar
hjk committed
752
753
754
755
756
757
758
759
760
761
762
        dummyStatement(&date);
    }

    void testDateTime()
    {
        testQDate();
        testQDateTime();
        testQTime();
    }

} // namespace qdatetime
763

764

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
namespace qdir {

    void testQDir()
    {
        QDir dir("/tmp");
        dir.absolutePath();
        BREAK_HERE;
        // Check dir "/tmp" QDir.
        // Check dir.absolutePath "/tmp" QString.
        // Check dir.canonicalPath "/tmp" QString.
        // Continue.
        dummyStatement(&dir);
    }

} // namespace qdir


hjk's avatar
hjk committed
782
783
784
785
786
namespace qfileinfo {

    void testQFileInfo()
    {
        QFile file("/tmp/t");
hjk's avatar
hjk committed
787
788
        file.setObjectName("A QFile instance");
        QFileInfo fi("/tmp/tt");
hjk's avatar
hjk committed
789
        QString s = fi.absoluteFilePath();
hjk's avatar
hjk committed
790
791
792
        BREAK_HERE;
        // Check fi "/tmp/tt" QFileInfo.
        // Check file "/tmp/t" QFile.
793
        // Check s "/tmp/tt" QString.
hjk's avatar
hjk committed
794
        // Continue.
hjk's avatar
hjk committed
795
796
797
798
799
        dummyStatement(&file, &s);
    }

} // namespace qfileinfo

800

801
802
803
804
805
806
807
808
809
810
namespace qhash {

    void testQHash1()
    {
        QHash<QString, QList<int> > hash;
        hash.insert("Hallo", QList<int>());
        hash.insert("Welt", QList<int>() << 1);
        hash.insert("!", QList<int>() << 1 << 2);
        hash.insert("!", QList<int>() << 1 << 2);
        BREAK_HERE;
811
        // Expand hash hash.0 hash.1 hash.1.value hash.2 hash.2.value.
812
        // Check hash <3 items> QHash<QString, QList<int>>.
813
814
815
816
817
818
819
820
821
822
823
824
        // Check hash.0   QHashNode<QString, QList<int>>.
        // Check hash.0.key "Hallo" QString.
        // Check hash.0.value <0 items> QList<int>.
        // Check hash.1   QHashNode<QString, QList<int>>.
        // Check hash.1.key "Welt" QString.
        // Check hash.1.value <1 items> QList<int>.
        // Check hash.1.value.0 1 int.
        // Check hash.2   QHashNode<QString, QList<int>>.
        // Check hash.2.key "!" QString.
        // Check hash.2.value <2 items> QList<int>.
        // Check hash.2.value.0 1 int.
        // Check hash.2.value.1 2 int.
825
        // Continue.
826
827
828
829
830
831
832
833
834
        dummyStatement(&hash);
    }

    void testQHash2()
    {
        QHash<int, float> hash;
        hash[11] = 11.0;
        hash[22] = 22.0;
        BREAK_HERE;
835
        // Expand hash.
836
        // Check hash <2 items> QHash<int, float>.
837
838
        // Check hash.22 22 float.
        // Check hash.11 11 float.
839
        // Continue.
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
        dummyStatement(&hash);
    }

    void testQHash3()
    {
        QHash<QString, int> hash;
        hash["22.0"] = 22.0;
        hash["123.0"] = 22.0;
        hash["111111ss111128.0"] = 28.0;
        hash["11124.0"] = 22.0;
        hash["1111125.0"] = 22.0;
        hash["11111126.0"] = 22.0;
        hash["111111127.0"] = 27.0;
        hash["111111111128.0"] = 28.0;
        hash["111111111111111111129.0"] = 29.0;
        BREAK_HERE;
856
        // Expand hash hash.0 hash.8.
857
        // Check hash <9 items> QHash<QString, int>.
858
859
860
861
862
863
        // Check hash.0   QHashNode<QString, int>.
        // Check hash.0.key "123.0" QString.
        // Check hash.0.value 22 int.
        // Check hash.8   QHashNode<QString, int>.
        // Check hash.8.key "11124.0" QString.
        // Check hash.8.value 22 int.
864
        // Continue.
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
        dummyStatement(&hash);
    }

    void testQHash4()
    {
        QHash<QByteArray, float> hash;
        hash["22.0"] = 22.0;
        hash["123.0"] = 22.0;
        hash["111111ss111128.0"] = 28.0;
        hash["11124.0"] = 22.0;
        hash["1111125.0"] = 22.0;
        hash["11111126.0"] = 22.0;
        hash["111111127.0"] = 27.0;
        hash["111111111128.0"] = 28.0;
        hash["111111111111111111129.0"] = 29.0;
        BREAK_HERE;
881
        // Expand hash hash.0 hash.8/
882
        // Check hash <9 items> QHash<QByteArray, float>.
883
884
885
886
887
888
        // Check hash.0   QHashNode<QByteArray, float>.
        // Check hash.0.key "123.0" QByteArray.
        // Check hash.0.value 22 float.
        // Check hash.8   QHashNode<QByteArray, float>.
        // Check hash.8.key "11124.0" QByteArray.
        // Check hash.8.value 22 float.
889
        // Continue.
890
891
892
893
894
895
896
897
        dummyStatement(&hash);
    }

    void testQHash5()
    {
        QHash<int, QString> hash;
        hash[22] = "22.0";
        BREAK_HERE;
898
        // Expand hash hash.0.
899
        // Check hash <1 items> QHash<int, QString>.
900
901
902
        // Check hash.0   QHashNode<int, QString>.
        // Check hash.0.key 22 int.
        // Check hash.0.value "22.0" QString.
903
        // Continue.
904
905
906
907
908
909
910
911
912
        dummyStatement(&hash);
    }

    void testQHash6()
    {
        QHash<QString, Foo> hash;
        hash["22.0"] = Foo(22);
        hash["33.0"] = Foo(33);
        BREAK_HERE;
913
        // Expand hash hash.0 hash.0.value hash.1.
914
        // Check hash <2 items> QHash<QString, Foo>.
915
916
917
918
919
920
921
        // Check hash.0   QHashNode<QString, Foo>.
        // Check hash.0.key "22.0" QString.
        // CheckType hash.0.value Foo.
        // Check hash.0.value.a 22 int.
        // Check hash.1   QHashNode<QString, Foo>.
        // Check hash.1.key "33.0" QString.
        // CheckType hash.1.value Foo.
922
        // Continue.
923
924
925
926
927
928
929
930
931
932
933
        dummyStatement(&hash);
    }

    void testQHash7()
    {
        QObject ob;
        QHash<QString, QPointer<QObject> > hash;
        hash.insert("Hallo", QPointer<QObject>(&ob));
        hash.insert("Welt", QPointer<QObject>(&ob));
        hash.insert(".", QPointer<QObject>(&ob));
        BREAK_HERE;
934
        // Expand hash hash.0 hash.0.value hash.2.
935
        // Check hash <3 items> QHash<QString, QPointer<QObject>>.
936
937
938
939
940
941
942
        // Check hash.0   QHashNode<QString, QPointer<QObject>>.
        // Check hash.0.key "Hallo" QString.
        // CheckType hash.0.value QPointer<QObject>.
        // CheckType hash.0.value.o QObject.
        // Check hash.2   QHashNode<QString, QPointer<QObject>>.
        // Check hash.2.key "." QString.
        // CheckType hash.2.value QPointer<QObject>.
943
        // Continue.
944
945
946
        dummyStatement(&hash, &ob);
    }

947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
    void testQHashIntFloatIterator()
    {
        typedef QHash<int, float> Hash;
        Hash hash;
        hash[11] = 11.0;
        hash[22] = 22.0;
        hash[33] = 33.0;
        hash[44] = 44.0;
        hash[55] = 55.0;
        hash[66] = 66.0;

        Hash::iterator it1 = hash.begin();
        Hash::iterator it2 = it1; ++it2;
        Hash::iterator it3 = it2; ++it2;
        Hash::iterator it4 = it3; ++it3;
        Hash::iterator it5 = it4; ++it4;
        Hash::iterator it6 = it5; ++it5;

        BREAK_HERE;
        // Expand hash.
        // Check hash <6 items> Hash.
        // Check hash.11 11 float.
        // Check it1.first 11 int.
        // Check it1.second 11 float.
        // Check it1.first 55 int.
        // Check it1.second 55 float.
        // Continue.
        dummyStatement(&hash, &it1, &it2, &it3, &it4, &it5, &it6);
    }

977
978
979
980
981
982
983
984
985
    void testQHash()
    {
        testQHash1();
        testQHash2();
        testQHash3();
        testQHash4();
        testQHash5();
        testQHash6();
        testQHash7();
986
        testQHashIntFloatIterator();
987
988
989
990
    }

} // namespace qhash

991

992
993
994
995
namespace qhostaddress {

    void testQHostAddress()
    {
hjk's avatar
hjk committed
996
        QHostAddress ha1(129u * 256u * 256u * 256u + 130u);
997
        QHostAddress ha2("127.0.0.1");
998
        BREAK_HERE;
999
1000
1001
        // Check ha1 129.0.0.130 QHostAddress.
        // Check ha2 "127.0.0.1" QHostAddress.
        // Continue.
1002
1003
1004
1005
1006
        dummyStatement(&ha1, &ha2);
    }

} // namespace qhostaddress

con's avatar
con committed
1007

1008
namespace painting {
1009

1010
1011
    void testQImage()
    {
1012
        #if USE_GUILIB
1013
1014
1015
1016
1017
1018
        // only works with Python dumper
        QImage im(QSize(200, 200), QImage::Format_RGB32);
        im.fill(QColor(200, 100, 130).rgba());
        QPainter pain;
        pain.begin(&im);
        BREAK_HERE;
1019
1020
1021
        // Check im (200x200) QImage.
        // CheckType pain QPainter.
        // Continue.
1022
1023
1024
1025
1026
1027
        // Step.
        pain.drawLine(2, 2, 130, 130);
        pain.drawLine(4, 2, 130, 140);
        pain.drawRect(30, 30, 80, 80);
        pain.end();
        dummyStatement(&pain, &im);
1028
        #endif
1029
    }
con's avatar
con committed
1030

1031
1032
    void testQPixmap()
    {
1033
        #if USE_GUILIB
1034
1035
1036
1037
1038
1039
1040
1041
        QImage im(QSize(200, 200), QImage::Format_RGB32);
        im.fill(QColor(200, 100, 130).rgba());
        QPainter pain;
        pain.begin(&im);
        pain.drawLine(2, 2, 130, 130);
        pain.end();
        QPixmap pm = QPixmap::fromImage(im);
        BREAK_HERE;
1042
1043
1044
1045
        // Check im (200x200) QImage.
        // CheckType pain QPainter.
        // Check pm (200x200) QPixmap.
        // Continue.
1046
        dummyStatement(&im, &pm);
1047
        #endif
1048
    }
con's avatar
con committed
1049

1050
1051
1052
1053
1054
    void testPainting()
    {
        testQImage();
        testQPixmap();
    }
1055

1056
} // namespace painting
1057

1058

1059
namespace qlinkedlist {
1060

1061
1062
1063
1064
1065
1066
    void testQLinkedListInt()
    {
        QLinkedList<int> list;
        list.append(101);
        list.append(102);
        BREAK_HERE;
1067
        // Expand list.
1068
        // Check list <2 items> QLinkedList<int>.
1069
1070
        // Check list.0 101 int.
        // Check list.1 102 int.
1071
        // Continue.
1072
1073
        dummyStatement(&list);
    }