simple_gdbtest_app.cpp 44 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, 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.
24
**
con's avatar
con committed
25 26 27 28 29 30
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
31
**
32
**************************************************************************/
con's avatar
con committed
33

34 35 36 37
//#include <complex>

//template <typename T> class B;  B foo() {}

con's avatar
con committed
38
#include <QtCore/QDebug>
39
#include <QtCore/QDateTime>
con's avatar
con committed
40 41 42
#include <QtCore/QDir>
#include <QtCore/QHash>
#include <QtCore/QLibrary>
43 44
#include <QtCore/QLinkedList>
#include <QtCore/QList>
con's avatar
con committed
45 46 47
#include <QtCore/QMap>
#include <QtCore/QPointer>
#include <QtCore/QString>
48
#include <QtCore/QStringList>
hjk's avatar
hjk committed
49
#include <QtCore/QSettings>
hjk's avatar
hjk committed
50
#include <QtCore/QStack>
con's avatar
con committed
51 52 53
#include <QtCore/QThread>
#include <QtCore/QVariant>
#include <QtCore/QVector>
hjk's avatar
hjk committed
54
#include <QtCore/QUrl>
55
#if QT_VERSION >= 0x040500
56
#include <QtCore/QSharedPointer>
57
#endif
con's avatar
con committed
58 59 60 61 62 63

#include <QtGui/QApplication>
#include <QtGui/QAction>
#include <QtGui/QColor>
#include <QtGui/QFont>
#include <QtGui/QLabel>
hjk's avatar
hjk committed
64
//#include <QtGui/private/qfixed_p.h>
con's avatar
con committed
65 66
#include <QtGui/QPainter>
#include <QtGui/QPainterPath>
67
#include <QtGui/QRegion>
68
#include <QtGui/QStandardItemModel>
69 70
#include <QtGui/QTextCursor>
#include <QtGui/QTextDocument>
con's avatar
con committed
71

72 73 74
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptValue>

con's avatar
con committed
75 76
#include <QtNetwork/QHostAddress>

hjk's avatar
hjk committed
77
#include <deque>
con's avatar
con committed
78
#include <iostream>
79
#include <map>
hjk's avatar
hjk committed
80
#include <list>
81
#include <set>
hjk's avatar
hjk committed
82
#include <stack>
con's avatar
con committed
83 84 85
#include <string>
#include <vector>

86
#if defined(__GNUC__) && !defined(__llvm__) && !defined(Q_OS_MAC)
87
#    define USE_GCC_EXT 1
88
#    undef __DEPRECATED
89
#    include <ext/hash_set>
90 91
#endif

con's avatar
con committed
92 93
#ifdef Q_OS_WIN
#include <windows.h>
94 95
#undef min
#undef max
con's avatar
con committed
96 97
#endif

98
#ifdef __SSE__
hjk's avatar
hjk committed
99 100 101 102
#include <xmmintrin.h>
#include <stddef.h>
#endif

103 104 105 106 107 108 109 110
Q_DECLARE_METATYPE(QHostAddress)
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QStringList)

typedef QMap<uint, QStringList> MyType;
#define COMMA ,
Q_DECLARE_METATYPE(QMap<uint COMMA QStringList>)

111 112 113 114 115 116 117 118 119 120 121 122
template <typename T> class Vector
{
public:
    explicit Vector(int size) : m_size(size), m_data(new T[size]) {}
    ~Vector() { delete [] m_data; }
    //...
private:
    int m_size;
    T *m_data;
};


123 124 125 126 127 128 129 130 131 132 133 134
namespace nsX {
namespace nsY {
int z;
}
}

namespace nsXY = nsX::nsY;

int qwert()
{
    return nsXY::z;
}
con's avatar
con committed
135 136 137 138 139 140 141 142 143 144 145

uint qHash(const QMap<int, int> &)
{
    return 0;
}

uint qHash(const double & f)
{
    return int(f);
}

hjk's avatar
hjk committed
146

hjk's avatar
hjk committed
147
class Foo
con's avatar
con committed
148 149
{
public:
hjk's avatar
hjk committed
150
    Foo(int i = 0)
con's avatar
con committed
151 152 153 154 155 156
        : a(i), b(2)
    {
        int s = 1;
        int t = 2;
        b = 2 + s + t;
        a += 1;
157 158 159 160 161 162 163 164 165 166 167 168 169 170
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
        a += 1;
con's avatar
con committed
171
    }
172

173
    virtual ~Foo()
174 175 176 177
    {
        a = 5;
    }

con's avatar
con committed
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
    void doit()
    {
        static QObject ob;
        m["1"] = "2";
        h[&ob] = m.begin();

        a += 1;
        --b;
        //s += 'x';
    }


    struct Bar {
        Bar() : ob(0) {}
        QObject *ob;
    };

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

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

206
class X : public Foo
hjk's avatar
hjk committed
207 208 209 210 211 212
{
public:
    X() {
    }
};

213 214 215 216 217 218 219
class XX : virtual public Foo
{
public:
    XX() {
    }
};

hjk's avatar
hjk committed
220 221 222 223 224 225 226
class Y : virtual public Foo
{
public:
    Y() {
    }
};

227 228 229 230 231
class D : public X, public Y
{
    int diamond;
};

con's avatar
con committed
232 233
void testArray()
{
234 235 236 237
#if 1
    X x;
    XX xx;
    D diamond;
238
    Q_UNUSED(diamond);
239
    Foo *f = &xx;
240
    Q_UNUSED(f);
241
    Foo ff;
242
    Q_UNUSED(ff);
243 244 245 246
    double d[3][3];
    for (int i = 0; i != 3; ++i)
        for (int j = 0; j != 3; ++j)
            d[i][j] = i + j;
247
    Q_UNUSED(d);
248
#endif
249

250
#if 1
hjk's avatar
hjk committed
251 252 253 254 255
    char c[20];
    c[0] = 'a';
    c[1] = 'b';
    c[2] = 'c';
    c[3] = 'd';
256
    Q_UNUSED(c);
257
#endif
hjk's avatar
hjk committed
258

259 260 261 262 263 264
#if 1
    QString s[20];
    s[0] = "a";
    s[1] = "b";
    s[2] = "c";
    s[3] = "d";
265
    Q_UNUSED(s);
266
#endif
con's avatar
con committed
267

268 269 270 271 272 273
#if 1
    QByteArray b[20];
    b[0] = "a";
    b[1] = "b";
    b[2] = "c";
    b[3] = "d";
274
    Q_UNUSED(b);
275 276 277
#endif

#if 1
con's avatar
con committed
278 279 280 281 282 283
    Foo foo[10];
    //for (int i = 0; i != sizeof(foo)/sizeof(foo[0]); ++i) {
    for (int i = 0; i < 5; ++i) {
        foo[i].a = i;
        foo[i].doit();
    }
284
#endif
con's avatar
con committed
285 286
}

287
#ifndef Q_CC_RVCT
288 289 290 291 292 293 294 295
struct TestAnonymous
{
    union {
        struct { int i; int b; };
        struct { float f; };
        double d;
    };
};
296
#endif
hjk's avatar
hjk committed
297 298 299 300 301

void testPeekAndPoke3()
{
    // Anonymous structs
    {
302
#ifndef Q_CC_RVCT
hjk's avatar
hjk committed
303 304 305 306
        union {
            struct { int i; int b; };
            struct { float f; };
            double d;
307
        } a = { { 42, 43 } };
hjk's avatar
hjk committed
308 309 310
        a.i = 1; // Break here. Expand a. Step.
        a.i = 2; // Change a.i in Locals view to 0. This changes f, d but expectedly not b. Step.
        a.i = 3; // Continue.
311
        Q_UNUSED(a);
312
#endif
hjk's avatar
hjk committed
313 314 315 316 317 318 319 320 321
    }

    // Complex watchers
    {
        struct S { int a; double b; } s[10];
        for (int i = 0; i != 10; ++i) {
            s[i].a = i;  // Break here. Expand s and s[0]. Step.
            // Watcher Context: "Add New Watcher".
            // Type    ['s[%d].a' % i for i in range(5)]
322 323
            // Expand it, continue stepping. This should result in a list
            // of five items containing the .a fields of s[0]..s[4].
hjk's avatar
hjk committed
324
        }
325
        Q_UNUSED(s);
hjk's avatar
hjk committed
326
    }
hjk's avatar
hjk committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

    // QImage display
    {
        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));
        pain.drawEllipse(20, 20, 160, 160); // Break here. Step.
        // Toggle between "Normal" and "Displayed" in L&W Context Menu, entry "Display of Type QImage". Step.
        pain.drawArc(70, 115, 60, 30, 200 * 16, 140 * 16);
        pain.setBrush(Qt::black);
        pain.drawEllipse(65, 70, 15, 15); // Step.
        pain.drawEllipse(120, 70, 15, 15); // Step.
        pain.end();
    }

hjk's avatar
hjk committed
344
}
345

346 347

#ifndef Q_CC_RVCT
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
namespace { // anon

struct Something
{
    Something() { a = b = 1; }

    void foo()
    {
        a = 42;
        b = 43;
    }

    int a, b;
};

} // anon
364 365
#endif

366

367 368
void testAnonymous()
{
369
#ifndef Q_CC_RVCT
370 371 372 373
    TestAnonymous a;
    a.i = 1;
    a.i = 2;
    a.i = 3;
374
    Q_UNUSED(a);
375 376 377

    Something s;
    s.foo();
378
    Q_UNUSED(s);
379
#endif
380 381
}

382 383
typedef void (*func_t)();
func_t testFunctionPointer()
384 385
{
    func_t f1 = testAnonymous;
386 387
    func_t f2 = testPeekAndPoke3;
    func_t f3 = testPeekAndPoke3;
388 389 390
    Q_UNUSED(f1);
    Q_UNUSED(f2);
    Q_UNUSED(f3);
391
    return f1;
392 393
}

394
void testQByteArray()
con's avatar
con committed
395 396 397 398
{
    QByteArray ba = "Hello";
    ba += '"';
    ba += "World";
hjk's avatar
hjk committed
399 400 401 402 403 404 405 406

    const char *str1 = "\356";
    const char *str2 = "\xee";
    const char *str3 = "\\ee";
    QByteArray buf1( str1 );
    QByteArray buf2( str2 );
    QByteArray buf3( str3 );

con's avatar
con committed
407 408 409 410 411
    ba += char(0);
    ba += 1;
    ba += 2;
}

412 413 414 415 416 417 418 419
int testQByteArray2()
{
    QByteArray ba;
    for (int i = 256; --i >= 0; )
        ba.append(char(i));
    return ba.size();
}

420 421 422 423 424 425 426 427 428 429 430 431
static void throwit1()
{
    throw 14;
}

static void throwit()
{
    throwit1();
}

int testCatchThrow()
{
432 433
    // Set a breakpoint on "throw" in the BreakWindow context menu
    // before stepping further.
434 435 436 437 438 439 440 441 442
    int gotit = 0;
    try {
        throwit();
    } catch (int what) {
        gotit = what;
    }
    return gotit;
}

443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
void testQDate()
{
    QDate date;
    date = QDate::currentDate();
    date = date.addDays(5);
    date = date.addDays(5);
    date = date.addDays(5);
    date = date.addDays(5);
}

void testQTime()
{
    QTime time;
    time = QTime::currentTime();
    time = time.addSecs(5);
    time = time.addSecs(5);
    time = time.addSecs(5);
    time = time.addSecs(5);
}

void testQDateTime()
464 465 466 467 468 469 470 471 472
{
    QDateTime date;
    date = QDateTime::currentDateTime();
    date = date.addSecs(5);
    date = date.addSecs(5);
    date = date.addSecs(5);
    date = date.addSecs(5);
}

473
QFileInfo testQFileInfo()
474 475 476
{
    QFileInfo fi("/tmp/t");
    QString s = fi.absoluteFilePath();
477 478 479
    s = fi.bundleName();
    s = fi.bundleName();
    s = fi.bundleName();
480 481 482

    QFileInfo result("/tmp/t");
    return result;
483 484
}

hjk's avatar
hjk committed
485 486
void testQFixed()
{
hjk's avatar
hjk committed
487
/*
hjk's avatar
hjk committed
488 489 490 491 492 493 494
    QFixed f = QFixed::fromReal(4.2);
    f += 1;
    f += 1;
    f *= -1;
    f += 1;
    f += 1;
*/
495 496
}

497
QHash<int, float> testQHash()
con's avatar
con committed
498
{
hjk's avatar
hjk committed
499
#if 1
con's avatar
con committed
500 501 502
    QHash<int, float> hgg0;
    hgg0[11] = 11.0;
    hgg0[22] = 22.0;
503 504 505 506 507
    hgg0[22] = 22.0;
    hgg0[22] = 22.0;
    hgg0[22] = 22.0;
    hgg0[22] = 22.0;
    hgg0[22] = 22.0;
con's avatar
con committed
508

509 510 511
#endif

#if 1
con's avatar
con committed
512

513
    QHash<QString, int> hgg1;
con's avatar
con committed
514
    hgg1["22.0"] = 22.0;
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
    hgg1["123.0"] = 22.0;
    hgg1["111111ss111128.0"] = 28.0;
    hgg1["11124.0"] = 22.0;
    hgg1["1111125.0"] = 22.0;
    hgg1["11111126.0"] = 22.0;
    hgg1["111111127.0"] = 27.0;
    hgg1["111111111128.0"] = 28.0;
    hgg1["111111111111111111129.0"] = 29.0;

    QHash<QByteArray, float> hgx1;
    hgx1["22.0"] = 22.0;
    hgx1["123.0"] = 22.0;
    hgx1["111111ss111128.0"] = 28.0;
    hgx1["11124.0"] = 22.0;
    hgx1["1111125.0"] = 22.0;
    hgx1["11111126.0"] = 22.0;
    hgx1["111111127.0"] = 27.0;
    hgx1["111111111128.0"] = 28.0;
    hgx1["111111111111111111129.0"] = 29.0;
534
#endif
535
#if 1
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
536 537
    QHash<int, QString> hgg2;
    hgg2[22] = "22.0";
con's avatar
con committed
538 539 540 541 542 543 544 545 546 547

    QHash<QString, Foo> hgg3;
    hgg3["22.0"] = Foo(22);
    hgg3["33.0"] = Foo(33);

    QObject ob;
    QHash<QString, QPointer<QObject> > hash;
    hash.insert("Hallo", QPointer<QObject>(&ob));
    hash.insert("Welt", QPointer<QObject>(&ob));
    hash.insert(".", QPointer<QObject>(&ob));
548
#endif
549 550
    QHash<int, float> result;
    return result;
con's avatar
con committed
551 552
}

553
void testQImage()
con's avatar
con committed
554
{
555
    // only works with Python dumper
con's avatar
con committed
556 557 558 559 560 561 562 563 564 565
    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.drawLine(4, 2, 130, 140);
    pain.drawRect(30, 30, 80, 80);
    pain.end();
}

566 567 568 569 570 571 572 573 574 575 576 577
struct Function
{
    Function(QByteArray var, QByteArray f, double min, double max)
      : var(var), f(f), min(min), max(max) {}
    QByteArray var;
    QByteArray f;
    double min;
    double max;
};

void testFunction()
{
hjk's avatar
hjk committed
578
    // In order to use this, switch on the 'qDump__Function' in gdbmacros.py
579 580 581 582 583 584 585 586 587 588
    Function func("x", "sin(x)", 0, 1);
    func.max = 10;
    func.f = "cos(x)";
    func.max = 4;
    func.max = 5;
    func.max = 6;
    func.max = 7;
    func.max = 8;
}

589
void testOutput()
con's avatar
con committed
590 591 592 593
{
    qDebug() << "qDebug() 1";
    qDebug() << "qDebug() 2";
    qDebug() << "qDebug() 3";
594
    qDebug() << "qDebug <foo & bar>";
con's avatar
con committed
595 596 597 598

    std::cout << "std::cout @@ 1" << std::endl;
    std::cout << "std::cout @@ 2\n";
    std::cout << "std::cout @@ 3" << std::endl;
599
    std::cout << "std::cout <foo & bar>\n";
con's avatar
con committed
600 601 602 603

    std::cerr << "std::cerr 1\n";
    std::cerr << "std::cerr 2\n";
    std::cerr << "std::cerr 3\n";
604
    std::cerr << "std::cerr <foo & bar>\n";
con's avatar
con committed
605 606
}

607 608 609 610 611 612 613 614 615 616 617 618
void testInput()
{
#if 0
    // This works only when "Run in terminal" is selected
    // in the Run Configuration.
    int i;
    std::cin >> i;
    int j;
    std::cin >> j;
#endif
}

619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
void testQLinkedList()
{
#if 1
    QLinkedList<int> li;
    QLinkedList<uint> lu;

    for (int i = 0; i != 3; ++i)
        li.append(i);
    li.append(102);


    lu.append(102);
    lu.append(102);
    lu.append(102);

hjk's avatar
hjk committed
634 635 636 637 638
    QLinkedList<Foo *> lpi;
    lpi.append(new Foo(1));
    lpi.append(0);
    lpi.append(new Foo(3));

639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
    QLinkedList<qulonglong> l;
    l.append(42);
    l.append(43);
    l.append(44);
    l.append(45);

    QLinkedList<Foo> f;
    f.append(Foo(1));
    f.append(Foo(2));
#endif
    QLinkedList<std::string> v;
    v.push_back("aa");
    v.push_back("bb");
    v.push_back("cc");
    v.push_back("dd");
 }
con's avatar
con committed
655

656 657 658
void testQLocale()
{
    QLocale loc = QLocale::system();
659
    //QString s = loc.name();
660
    //QVariant v = loc;
661
    QLocale::MeasurementSystem m = loc.measurementSystem();
662
    Q_UNUSED(m);
663 664
}

665
void testQList()
con's avatar
con committed
666
{
667 668 669 670 671 672 673 674 675 676
    QList<int> big;
    for (int i = 0; i < 10000; ++i)
        big.push_back(i);

    QList<Foo> flist;
    for (int i = 0; i < 100; ++i)
        flist.push_back(i + 15);
    flist.push_back(1000);
    flist.push_back(1001);
    flist.push_back(1002);
677
#if 1
con's avatar
con committed
678 679 680
    QList<int> li;
    QList<uint> lu;

681
    for (int i = 0; i != 30; ++i) {
con's avatar
con committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
        li.append(i);
    }
    li.append(101);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);
    li.append(102);

699 700 701 702 703
    QList<int *> lpi;
    lpi.append(new int(1));
    lpi.append(new int(2));
    lpi.append(new int(3));

con's avatar
con committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718

    for (int i = 0; i != 3; ++i) {
        lu.append(i);
    }
    lu.append(101);
    lu.append(102);
    lu.append(102);
    lu.append(102);

    QList<uint> i;
    i.append(42);
    i.append(43);
    i.append(44);
    i.append(45);

719 720 721 722 723 724 725 726 727 728 729 730
    QList<ushort> ls;
    ls.append(42);
    ls.append(43);
    ls.append(44);
    ls.append(45);

    QList<QChar> lc;
    lc.append(QChar('a'));
    lc.append(QChar('b'));
    lc.append(QChar('c'));
    lc.append(QChar('d'));

con's avatar
con committed
731 732 733 734 735 736 737 738 739 740
    QList<qulonglong> l;
    l.append(42);
    l.append(43);
    l.append(44);
    l.append(45);

    QList<Foo> f;
    f.append(Foo(1));
    f.append(Foo(2));

741
    QList<std::string> v;
con's avatar
con committed
742 743 744 745
    v.push_back("aa");
    v.push_back("bb");
    v.push_back("cc");
    v.push_back("dd");
746
#endif
con's avatar
con committed
747 748
 }

749 750 751 752 753 754 755 756 757 758 759 760
namespace A {
namespace B {

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

} // namespace B
} // namespace A

761
void testQMap()
con's avatar
con committed
762
{
763
#if 0
con's avatar
con committed
764 765 766 767 768 769 770 771
    QMap<uint, QStringList> ggl;
    ggl[11] = QStringList() << "11";
    ggl[22] = QStringList() << "22";

    typedef QMap<uint, QStringList> T;
    T ggt;
    ggt[11] = QStringList() << "11";
    ggt[22] = QStringList() << "22";
772
#endif
con's avatar
con committed
773

774
#if 0
con's avatar
con committed
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
    QMap<uint, float> gg0;
    gg0[11] = 11.0;
    gg0[22] = 22.0;


    QMap<QString, float> gg1;
    gg1["22.0"] = 22.0;

    QMap<int, QString> gg2;
    gg2[22] = "22.0";

    QMap<QString, Foo> gg3;
    gg3["22.0"] = Foo(22);
    gg3["33.0"] = Foo(33);

    QObject ob;
    QMap<QString, QPointer<QObject> > map;
    map.insert("Hallo", QPointer<QObject>(&ob));
    map.insert("Welt", QPointer<QObject>(&ob));
    map.insert(".", QPointer<QObject>(&ob));
#endif
796 797 798 799 800 801 802 803 804 805 806 807

#if 1
    QList<A::B::SomeType *> x;
    x.append(new A::B::SomeType(1));
    x.append(new A::B::SomeType(2));
    x.append(new A::B::SomeType(3));
    QMap<QString, QList<A::B::SomeType *> > mlt;
    mlt["foo"] = x;
    mlt["bar"] = x;
    mlt["1"] = x;
    mlt["2"] = x;
#endif
con's avatar
con committed
808 809
}

hjk's avatar
hjk committed
810 811 812 813 814 815
void testQMultiMap()
{
    QMultiMap<uint, float> gg0;
    gg0.insert(11, 11.0);
    gg0.insert(22, 22.0);
    gg0.insert(22, 33.0);
hjk's avatar
hjk committed
816 817 818 819
    gg0.insert(22, 34.0);
    gg0.insert(22, 35.0);
    gg0.insert(22, 36.0);
#if 1
hjk's avatar
hjk committed
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
    QMultiMap<QString, float> gg1;
    gg1.insert("22.0", 22.0);

    QMultiMap<int, QString> gg2;
    gg2.insert(22, "22.0");

    QMultiMap<QString, Foo> gg3;
    gg3.insert("22.0", Foo(22));
    gg3.insert("33.0", Foo(33));
    gg3.insert("22.0", Foo(22));

    QObject ob;
    QMultiMap<QString, QPointer<QObject> > map;
    map.insert("Hallo", QPointer<QObject>(&ob));
    map.insert("Welt", QPointer<QObject>(&ob));
    map.insert(".", QPointer<QObject>(&ob));
    map.insert(".", QPointer<QObject>(&ob));
hjk's avatar
hjk committed
837
#endif
hjk's avatar
hjk committed
838 839
}

840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
namespace Names {
namespace Bar {

struct Ui {
    Ui() { w = 0; }
    QWidget *w;
};

class TestObject : public QObject
{
    Q_OBJECT

public:
    TestObject(QObject *parent = 0)
      : QObject(parent)
    {
        m_ui = new Ui;
857
        m_ui->w = new QWidget;
858
        Q_UNUSED(parent);
859 860
    }

861 862 863 864 865 866 867
    Q_PROPERTY(QString myProp1 READ myProp1 WRITE setMyProp1)
    QString myProp1() const { return m_myProp1; }
    Q_SLOT void setMyProp1(const QString &mt) { m_myProp1 = mt; }

    Q_PROPERTY(QString myProp2 READ myProp2 WRITE setMyProp2)
    QString myProp2() const { return m_myProp2; }
    Q_SLOT void setMyProp2(const QString &mt) { m_myProp2 = mt; }
868 869

public:
870
    Ui *m_ui;
871 872
    QString m_myProp1;
    QString m_myProp2;
873 874 875 876 877
};

} // namespace Bar
} // namespace Names

878
void testQObject(int &argc, char *argv[])
con's avatar
con committed
879 880
{
    QApplication app(argc, argv);
881
    //QString longString = QString(10000, QLatin1Char('A'));
882
#if 1
883
    Names::Bar::TestObject test;
884 885 886 887
    test.setMyProp1("HELLO");
    test.setMyProp2("WORLD");
    QString s = test.myProp1();
    s += test.myProp2();
888
    Q_UNUSED(s);
889
#endif
890

891
#if 0
con's avatar
con committed
892 893 894
    QAction act("xxx", &app);
    QString t = act.text();
    t += "y";
hjk's avatar
hjk committed
895 896 897 898
    t += "y";
    t += "y";
    t += "y";
    t += "y";
899
#endif
con's avatar
con committed
900

901
#if 1
902
    QWidget ob;
con's avatar
con committed
903
    ob.setObjectName("An Object");
904 905
    ob.setProperty("USER DEFINED 1", 44);
    ob.setProperty("USER DEFINED 2", QStringList() << "FOO" << "BAR");
con's avatar
con committed
906 907 908
    QObject ob1;
    ob1.setObjectName("Another Object");

909
    QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
con's avatar
con committed
910
    QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
911
    //QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater()));
912
#endif
con's avatar
con committed
913

914
#if 0
con's avatar
con committed
915 916 917 918 919 920
    QList<QObject *> obs;
    obs.append(&ob);
    obs.append(&ob1);
    obs.append(0);
    obs.append(&app);
    ob1.setObjectName("A Subobject");
921
#endif
922

923
#if 1
hjk's avatar
hjk committed
924 925
    QString str = QString::fromUtf8("XXXXXXXXXXXXXXyyXXX ö");
    QLabel l(str);
926
    l.setObjectName("Some Label");
con's avatar
con committed
927 928
    l.show();
    app.exec();
929
#endif
con's avatar
con committed
930 931
}

932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
class Sender : public QObject
{
    Q_OBJECT
public:
    Sender() { setObjectName("Sender"); }
    void doEmit() { emit aSignal(); }
signals:
    void aSignal();
};

class Receiver : public QObject
{
    Q_OBJECT
public:
    Receiver() { setObjectName("Receiver"); }
public slots:
    void aSlot() {
        QObject *s = sender();
        if (s) {
            qDebug() << "SENDER: " << s;
        } else {
            qDebug() << "NO SENDER";
        }
    }
};

void testSignalSlot(int &argc, char *argv[])
{
    QApplication app(argc, argv);
    Sender sender;
    Receiver receiver;
    QObject::connect(&sender, SIGNAL(aSignal()), &receiver, SLOT(aSlot()));
    sender.doEmit();
};


968
void testQPixmap()
con's avatar
con committed
969 970 971 972 973 974 975 976 977 978 979 980
{
    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);
    int i = 1;
    Q_UNUSED(i);
}

981 982
void testQRegion()
{
983
    // only works with Python dumper
984 985 986 987
    QRegion region;
    region += QRect(100, 100, 200, 200);
    region += QRect(300, 300, 400, 500);
    region += QRect(500, 500, 600, 600);
hjk's avatar
hjk committed
988 989 990
    region += QRect(500, 500, 600, 600);
    region += QRect(500, 500, 600, 600);
    region += QRect(500, 500, 600, 600);
991 992 993
}


con's avatar
con committed
994 995 996 997
void testPlugin()
{
    QString dir = QDir::currentPath();
#ifdef Q_OS_LINUX
Kai Koehne's avatar
Kai Koehne committed
998
    QLibrary lib(dir + "/libsimple_gdbtest_plugin.so");
con's avatar
con committed
999 1000 1001
#endif
#ifdef Q_OS_MAC
    dir = QFileInfo(dir + "/../..").canonicalPath();
Kai Koehne's avatar
Kai Koehne committed
1002
    QLibrary lib(dir + "/libsimple_gdbtest_plugin.dylib");
con's avatar
con committed
1003 1004
#endif
#ifdef Q_OS_WIN
Friedemann Kleint's avatar
Friedemann Kleint committed
1005
    QLibrary lib(dir + "/debug/simple_gdbtest_plugin.dll");
1006 1007
#endif
#ifdef Q_OS_SYMBIAN
Kai Koehne's avatar
Kai Koehne committed
1008
    QLibrary lib(dir + "/libsimple_gdbtest_plugin.dll");
con's avatar
con committed
1009 1010
#endif
    int (*foo)() = (int(*)()) lib.resolve("pluginTest");
Friedemann Kleint's avatar
Friedemann Kleint committed
1011
    qDebug() << "library resolve: " << foo << lib.fileName();
con's avatar
con committed
1012 1013 1014 1015 1016 1017 1018 1019
    if (foo) {
        int res = foo();
        res += 1;
    } else {
        qDebug() << lib.errorString();
    }
}

1020
void testQSet()
hjk's avatar
hjk committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
{
    QSet<int> hgg0;
    hgg0.insert(11);
    hgg0.insert(22);

    QSet<QString> hgg1;
    hgg1.insert("22.0");

    QObject ob;
    QSet<QPointer<QObject> > hash;
    QPointer<QObject> ptr(&ob);
1032
    Q_UNUSED(ptr);
hjk's avatar
hjk committed
1033 1034 1035 1036 1037
    //hash.insert(ptr);
    //hash.insert(ptr);
    //hash.insert(ptr);
}

1038
#if QT_VERSION >= 0x040500
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
class EmployeeData : public QSharedData
{
public:
    EmployeeData() : id(-1) { name.clear(); }
    EmployeeData(const EmployeeData &other)
        : QSharedData(other), id(other.id), name(other.name) { }
    ~EmployeeData() { }

    int id;
    QString name;
};

class Employee
{
public:
    Employee() { d = new EmployeeData; }
    Employee(int id, QString name) {
        d = new EmployeeData;
        setId(id);
        setName(name);
    }
    Employee(const Employee &other)
          : d (other.d)
    {
    }
    void setId(int id) { d->id = id; }
    void setName(QString name) { d->name = name; }

    int id() const { return d->id; }
    QString name() const { return d->name; }

   private:
     QSharedDataPointer<EmployeeData> d;
1072
};
1073

1074 1075 1076

void testQSharedPointer()
{
1077 1078
    //Employee e1(1, "Herbert");
    //Employee e2 = e1;
1079
#if 0
1080 1081 1082 1083 1084 1085 1086 1087
    QSharedPointer<int> iptr(new int(43));
    QSharedPointer<int> iptr2 = iptr;
    QSharedPointer<int> iptr3 = iptr;

    QSharedPointer<QString> ptr(new QString("hallo"));
    QSharedPointer<QString> ptr2 = ptr;
    QSharedPointer<QString> ptr3 = ptr;

hjk's avatar
hjk committed
1088 1089 1090 1091 1092 1093 1094
    QWeakPointer<int> wiptr(iptr);
    QWeakPointer<int> wiptr2 = wiptr;
    QWeakPointer<int> wiptr3 = wiptr;

    QWeakPointer<QString> wptr(ptr);
    QWeakPointer<QString> wptr2 = wptr;
    QWeakPointer<QString> wptr3 = wptr;
1095 1096 1097 1098 1099 1100
#endif

    QSharedPointer<Foo> fptr(new Foo(1));
    QWeakPointer<Foo> wfptr(fptr);
    QWeakPointer<Foo> wfptr2 = wfptr;
    QWeakPointer<Foo> wfptr3 = wfptr;
1101
}
1102
#endif
1103

con's avatar
con committed
1104 1105 1106 1107 1108
void stringRefTest(const QString &refstring)
{
    Q_UNUSED(refstring);
}

hjk's avatar
hjk committed
1109 1110
void testStdDeque()
{
1111
    // This is not supposed to work with the compiled dumpers.
hjk's avatar
hjk committed
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
    std::deque<int *> plist1;
    plist1.push_back(new int(1));
    plist1.push_back(0);
    plist1.push_back(new int(2));
    plist1.pop_back();
    plist1.pop_front();
    plist1.pop_front();

    std::deque<int> flist2;
    flist2.push_back(1);
    flist2.push_back(2);

    std::deque<Foo *> plist;
    plist.push_back(new Foo(1));
    plist.push_back(new Foo(2));

    std::deque<Foo> flist;
    flist.push_back(1);
    flist.push_front(2);
}

1133 1134
void testStdHashSet()
{
1135
    // This is not supposed to work with the compiled dumpers.
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
#if USE_GCC_EXT
    using namespace __gnu_cxx;
    hash_set<int> h;
    h.insert(1);
    h.insert(194);
    h.insert(2);
    h.insert(3);
    h.insert(4);
    h.insert(5);
#endif
}

1148
std::list<int> testStdList()
con's avatar
con committed
1149
{
1150
    // This is not supposed to work with the compiled dumpers.
1151 1152 1153 1154
    std::list<int> big;
    for (int i = 0; i < 10000; ++i)
        big.push_back(i);

1155 1156 1157 1158
    std::list<Foo> flist;
    for (int i = 0; i < 100; ++i)
        flist.push_back(i + 15);

1159
#if 1
hjk's avatar
hjk committed
1160
    std::list<int *> plist1;
con's avatar
con committed
1161 1162 1163 1164
    plist1.push_back(new int(1));
    plist1.push_back(0);
    plist1.push_back(new int(2));

hjk's avatar
hjk committed
1165
    std::list<int> flist2;
con's avatar
con committed
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
    flist2.push_back(1);
    flist2.push_back(2);
    flist2.push_back(3);
    flist2.push_back(4);

    flist2.push_back(1);
    flist2.push_back(2);
    flist2.push_back(3);
    flist2.push_back(4);

hjk's avatar
hjk committed
1176
    std::list<Foo *> plist;
con's avatar
con committed
1177 1178 1179 1180 1181
    plist.push_back(new Foo(1));
    plist.push_back(0);
    plist.push_back(new Foo(2));


1182 1183 1184
    foreach (Foo f, flist)
    {}

hjk's avatar
hjk committed
1185
    std::list<bool> vec;
con's avatar
con committed
1186 1187
    vec.push_back(true);
    vec.push_back(false);
1188
#endif
1189 1190
    std::list<int> result;
    return result;
con's avatar
con committed
1191 1192
}

1193 1194
void testStdMap()
{
1195
    // This is not supposed to work with the compiled dumpers.
1196
#if 0
hjk's avatar
hjk committed
1197 1198 1199 1200 1201
    std::map<QString, Foo> gg3;
    gg3["22.0"] = Foo(22);
    gg3["33.0"] = Foo(33);
    gg3["44.0"] = Foo(44);

1202 1203 1204 1205
    std::map<const char *, Foo> m1;
    m1["22.0"] = Foo(22);
    m1["33.0"] = Foo(33);
    m1["44.0"] = Foo(44);
1206

hjk's avatar
hjk committed
1207 1208 1209 1210 1211 1212 1213
    std::map<uint, uint> gg;
    gg[11] = 1;
    gg[22] = 2;
    gg[33] = 3;
    gg[44] = 4;
    gg[55] = 5;

1214 1215 1216 1217
    std::pair<uint, QStringList> p = std::make_pair(3, QStringList() << "11");
    std::vector< std::pair<uint, QStringList> > v;
    v.push_back(p);
    v.push_back(p);
1218

1219 1220 1221
    std::map<uint, QStringList> ggl;
    ggl[11] = QStringList() << "11";
    ggl[22] = QStringList() << "22";
hjk's avatar
hjk committed
1222 1223 1224
    ggl[33] = QStringList() << "33";
    ggl[44] = QStringList() << "44";
    ggl[55] = QStringList() << "55";
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240

    typedef std::map<uint, QStringList> T;
    T ggt;
    ggt[11] = QStringList() << "11";
    ggt[22] = QStringList() << "22";

    std::map<uint, float> gg0;
    gg0[11] = 11.0;
    gg0[22] = 22.0;


    std::map<QString, float> gg1;
    gg1["22.0"] = 22.0;

    std::map<int, QString> gg2;
    gg2[22] = "22.0";
1241
#endif
1242

1243
#if 1
1244 1245
    QObject ob;
    std::map<QString, QPointer<QObject> > map;
hjk's avatar
hjk committed
1246 1247 1248
    map["Hallo"] = QPointer<QObject>(&ob);
    map["Welt"] = QPointer<QObject>(&ob);
    map["."] = QPointer<QObject>(&ob);
1249 1250 1251
#endif
}

1252
std::set<int> testStdSet()
1253
{
1254
    // This is not supposed to work with the compiled dumpers.
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264