tst_gdb.cpp 131 KB
Newer Older
1
2
3
4
5

// Note: Keep the strange formating of closing braces in the  void dump*()
// functions as this reduces the risk of gdb reporting 'wrong' line numbers
// when stopping and therefore the risk of the autotest to fail.

hjk's avatar
hjk committed
6
7
//bool checkUninitialized = true;
bool checkUninitialized = false;
hjk's avatar
hjk committed
8
9
//#define DO_DEBUG 1

10
11
#include "gdb/gdbmi.h"

hjk's avatar
hjk committed
12
13
#include <QtCore/QThread>
#include <QtCore/QMutex>
14
#include <QtCore/QSignalMapper>
hjk's avatar
hjk committed
15
16
#include <QtCore/QWaitCondition>

17
#ifdef QT_GUI_LIB
18
19
20
21
22
23
24
#include <QtGui/QBitmap>
#include <QtGui/QBrush>
#include <QtGui/QColor>
#include <QtGui/QCursor>
#include <QtGui/QFont>
#include <QtGui/QIcon>
#include <QtGui/QKeySequence>
hjk's avatar
hjk committed
25
26
#include <QtGui/QMatrix4x4>
#include <QtGui/QPen>
27
28
29
#include <QtGui/QQuaternion>
#include <QtGui/QStandardItemModel>
#include <QtGui/QStringListModel>
hjk's avatar
hjk committed
30
31
32
#include <QtGui/QTextFormat>
#include <QtGui/QTextLength>
#include <QtGui/QVector2D>
33
34
#include <QtGui/QWidget>
#endif
hjk's avatar
hjk committed
35
36
37

#include <QtTest/QtTest>

38
39
40
41
#include <deque>
#include <map>
#include <set>
#include <vector>
hjk's avatar
hjk committed
42

Daniel Molkentin's avatar
Daniel Molkentin committed
43
44
45
46
#ifdef Q_OS_WIN
#include <windows.h>
#endif

hjk's avatar
hjk committed
47
48
49
50
51
52
53
54
55
56
57
58
59
#undef NS
#ifdef QT_NAMESPACE
#   define STRINGIFY0(s) #s
#   define STRINGIFY1(s) STRINGIFY0(s)
#   define NS STRINGIFY1(QT_NAMESPACE) "::"
#   define NSX "'" STRINGIFY1(QT_NAMESPACE) "::"
#   define NSY "'"
#else
#   define NS ""
#   define NSX ""
#   define NSY ""
#endif

hjk's avatar
hjk committed
60
61
62
63
64
65
66
67
#undef DEBUG
#if DO_DEBUG
#   define DEBUG(s) qDebug() << s
#else
#   define DEBUG(s)
#endif
#define DEBUGX(s) qDebug() << s

hjk's avatar
hjk committed
68
69
#define gettid()  QString("0x%1").arg((qulonglong)(void *)currentThread(), 0, 16)

Friedemann Kleint's avatar
Friedemann Kleint committed
70
71
72
73
74
#ifdef Q_OS_WIN
QString gdbBinary = "c:\\MinGw\\bin\\gdb.exe";
#else
QString gdbBinary = "./gdb";
#endif
75

76
77
void nothing() {}

hjk's avatar
hjk committed
78
79
template <typename T> QByteArray N(T v) { return QByteArray::number(v); }

hjk's avatar
hjk committed
80
81
82
83
84
85
86
87
88
class Foo
{
public:
    Foo(int i = 0)
        : a(i), b(2)
    {}

    ~Foo()
    {
hjk's avatar
hjk committed
89
    }
90

hjk's avatar
hjk committed
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
    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;
};


120
121
122
123
124
125
/////////////////////////////////////////////////////////////////////////
//
// Helper stuff
//
/////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
126
127
typedef QList<QByteArray> QByteArrayList;

128
129
struct Int3
{
hjk's avatar
hjk committed
130
    Int3(int base = 0) { i1 = 42 + base; i2 = 43 + base; i3 = 44 + base; }
hjk's avatar
hjk committed
131
132
133
    int i1, i2, i3;
};

hjk's avatar
hjk committed
134
135
136
137
138
139
140
141
142
143
uint qHash(const Int3 &i)
{
    return (i.i1 ^ i.i2) ^ i.i3;
}

bool operator==(const Int3 &a, const Int3 &b)
{
    return a.i1 == b.i1 && a.i2 == b.i2 && a.i3 == b.i3;
}

144
145
146
147
148
149
150
bool operator<(const Int3 &a, const Int3 &b)
{
    return a.i1 < b.i1;
}

struct QString3
{
hjk's avatar
hjk committed
151
152
153
154
155
156
157
158
159
160
161
162
    QString3() { s1 = "a"; s2 = "b"; s3 = "c"; }
    QString s1, s2, s3;
};

class tst_Gdb;

class Thread : public QThread
{
    Q_OBJECT

public:
    Thread(tst_Gdb *test);
Friedemann Kleint's avatar
Friedemann Kleint committed
163
    void startup(QProcess *proc);
hjk's avatar
hjk committed
164
165
    void run();

Friedemann Kleint's avatar
Friedemann Kleint committed
166
167
    QString errorString() const { return  m_errorString; }

hjk's avatar
hjk committed
168
169
170
171
172
173
174
175
public slots:
    void readStandardOutput();
    void readStandardError();
    void handleGdbStarted();
    void handleGdbError(QProcess::ProcessError);
    void handleGdbFinished(int, QProcess::ExitStatus);
    void writeToGdbRequested(const QByteArray &ba)
    {
hjk's avatar
hjk committed
176
        DEBUG("THREAD GDB IN: " << ba);
hjk's avatar
hjk committed
177
178
179
180
181
182
183
        m_proc->write(ba);
        m_proc->write("\n");
    }


public:
    QByteArray m_output;
hjk's avatar
hjk committed
184
185
    QByteArray m_lastStopped; // last seen "*stopped" message
    int m_line; // line extracted from last "*stopped" message
hjk's avatar
hjk committed
186
187
    QProcess *m_proc; // owned
    tst_Gdb *m_test; // not owned
Friedemann Kleint's avatar
Friedemann Kleint committed
188
    QString m_errorString;
hjk's avatar
hjk committed
189
190
191
192
193
194
195
};

class tst_Gdb : public QObject
{
    Q_OBJECT

public:
hjk's avatar
hjk committed
196
197
198
    tst_Gdb();

    void prepare(const QByteArray &function);
199
    void check(const QByteArray &label, const QByteArray &expected,
hjk's avatar
hjk committed
200
        const QByteArray &expanded = QByteArray(), bool fancy = true);
hjk's avatar
hjk committed
201
202
203
204
205
206
    void next(int n = 1);

signals:
    void writeToGdb(const QByteArray &ba);

private slots:
Friedemann Kleint's avatar
Friedemann Kleint committed
207
    void initTestCase();
208
209
    void cleanupTestCase();

hjk's avatar
hjk committed
210
211
    void dump_array();
    void dump_misc();
212
    void dump_typedef();
213
    void dump_std_deque();
hjk's avatar
hjk committed
214
    void dump_std_list();
215
216
217
218
    void dump_std_map_int_int();
    void dump_std_map_string_string();
    void dump_std_set_Int3();
    void dump_std_set_int();
hjk's avatar
hjk committed
219
    void dump_std_string();
220
    void dump_std_vector();
hjk's avatar
hjk committed
221
    void dump_std_wstring();
hjk's avatar
hjk committed
222
    void dump_Foo();
223
    //void dump_QImageData();
224
    void dump_QAbstractItemAndModelIndex();
225
    void dump_QAbstractItemModel();
hjk's avatar
hjk committed
226
227
    void dump_QByteArray();
    void dump_QChar();
228
229
230
231
    void dump_QDateTime();
    void dump_QDir();
    void dump_QFile();
    void dump_QFileInfo();
232
    void dump_QHash_QString_QString();
233
    void dump_QHash_int_int();
234
    void dump_QImage();
235
    void dump_QLinkedList_int();
236
237
238
    void dump_QList_Int3();
    void dump_QList_QString();
    void dump_QList_QString3();
hjk's avatar
hjk committed
239
240
241
242
    void dump_QList_char();
    void dump_QList_char_star();
    void dump_QList_int();
    void dump_QList_int_star();
243
    void dump_QLocale();
hjk's avatar
hjk committed
244
    void dump_QMap_QString_QString();
245
    void dump_QMap_int_int();
246
    void dump_QObject();
247
    void dump_QPixmap();
248
249
    void dump_QPoint();
    void dump_QRect();
250
251
    void dump_QSet_Int3();
    void dump_QSet_int();
hjk's avatar
hjk committed
252
    void dump_QSharedPointer();
253
    void dump_QSize();
hjk's avatar
hjk committed
254
255
256
    void dump_QStack();
    void dump_QString();
    void dump_QStringList();
257
    void dump_QTextCodec();
258
259
    void dump_QVariant();
    void dump_QVector();
hjk's avatar
hjk committed
260
261
262
263
    void dump_QWeakPointer_11();
    void dump_QWeakPointer_12();
    void dump_QWeakPointer_13();
    void dump_QWeakPointer_2();
264
    void dump_QWidget();
hjk's avatar
hjk committed
265

hjk's avatar
hjk committed
266
267
268
269
public slots:
    void dumperCompatibility();

private:
hjk's avatar
hjk committed
270
#if 0
hjk's avatar
hjk committed
271
272
273
    void dump_QAbstractItemModelHelper(QAbstractItemModel &m);
    void dump_QObjectChildListHelper(QObject &o);
    void dump_QObjectSignalHelper(QObject &o, int sigNum);
hjk's avatar
hjk committed
274
#endif
hjk's avatar
hjk committed
275

hjk's avatar
hjk committed
276
277
    QHash<QByteArray, int> m_lineForLabel;
    QByteArray m_function;
hjk's avatar
hjk committed
278
279
280
    Thread m_thread;
};

281
282
283
284
285
286
//QMutex m_mutex;
//QWaitCondition m_waitCondition;

QByteArray buffer;
QSemaphore freeBytes(1);
QSemaphore usedBytes(0);
hjk's avatar
hjk committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

//
// Dumpers
//

QByteArray str(const void *p)
{
    char buf[100];
    sprintf(buf, "%p", p);
    return buf;
}

void tst_Gdb::dumperCompatibility()
{
    // Ensure that no arbitrary padding is introduced by QVectorTypedData.
    const size_t qVectorDataSize = 16;
    QCOMPARE(sizeof(QVectorData), qVectorDataSize);
    QVectorTypedData<int> *v = 0;
    QCOMPARE(size_t(&v->array), qVectorDataSize);
}

308
static const QByteArray utfToHex(const QString &string)
hjk's avatar
hjk committed
309
{
310
311
    return QByteArray(reinterpret_cast<const char *>(string.utf16()),
        2 * string.size()).toHex();
hjk's avatar
hjk committed
312
313
}

314
static const QByteArray specQString(const QString &str)
hjk's avatar
hjk committed
315
{
hjk's avatar
hjk committed
316
    return "valueencoded='7',value='" + utfToHex(str) + "'";
hjk's avatar
hjk committed
317
318
}

319
static const QByteArray specQChar(QChar ch)
hjk's avatar
hjk committed
320
{
hjk's avatar
hjk committed
321
322
323
324
325
    return QByteArray("value=''") + char(ch.unicode()) + "' ("
        + QByteArray::number(ch.unicode()) + ")'";
    //return "valueencoded='7',value='" +
    //    utfToHex(QString(QLatin1String("'%1' (%2)")).
    //              arg(ch).arg(ch.unicode())) + "'";
hjk's avatar
hjk committed
326
327
}

hjk's avatar
hjk committed
328
329
330
331
332
333
334
335


/////////////////////////////////////////////////////////////////////////
//
// Gdb Thread
//
/////////////////////////////////////////////////////////////////////////

336

Friedemann Kleint's avatar
Friedemann Kleint committed
337
Thread::Thread(tst_Gdb *test) : m_proc(0), m_test(test)
hjk's avatar
hjk committed
338
{
339
340
341
342
343
//#ifdef Q_OS_WIN
//    qDebug() << "\nTHREAD CREATED" << GetCurrentProcessId() << GetCurrentThreadId();
//#else
//    qDebug() << "\nTHREAD CREATED" << getpid() << gettid();
//#endif
hjk's avatar
hjk committed
344
    moveToThread(this);
hjk's avatar
hjk committed
345
    connect(m_test, SIGNAL(writeToGdb(QByteArray)),
Friedemann Kleint's avatar
Friedemann Kleint committed
346
347
348
349
350
351
352
            this, SLOT(writeToGdbRequested(QByteArray)), Qt::QueuedConnection);
}

void Thread::startup(QProcess *proc)
{
    m_proc = proc;
    m_proc->moveToThread(this);
hjk's avatar
hjk committed
353
354
355
356
357
358
359
360
361
362
363
    connect(m_proc, SIGNAL(error(QProcess::ProcessError)),
        this, SLOT(handleGdbError(QProcess::ProcessError)));
    connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)),
        this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
    connect(m_proc, SIGNAL(started()),
        this, SLOT(handleGdbStarted()));
    connect(m_proc, SIGNAL(readyReadStandardOutput()),
        this, SLOT(readStandardOutput()));
    connect(m_proc, SIGNAL(readyReadStandardError()),
        this, SLOT(readStandardError()));
    start();
hjk's avatar
hjk committed
364
365
}

hjk's avatar
hjk committed
366
void Thread::handleGdbError(QProcess::ProcessError error)
hjk's avatar
hjk committed
367
{
hjk's avatar
hjk committed
368
369
370
    qDebug() << "GDB ERROR: " << error;
    //this->exit();
}
hjk's avatar
hjk committed
371

hjk's avatar
hjk committed
372
373
374
375
376
void Thread::handleGdbFinished(int code, QProcess::ExitStatus st)
{
    qDebug() << "GDB FINISHED: " << code << st;
    //m_waitCondition.wakeAll();
    //this->exit();
hjk's avatar
hjk committed
377
    //throw 42;
hjk's avatar
hjk committed
378
}
hjk's avatar
hjk committed
379

hjk's avatar
hjk committed
380
381
382
void Thread::readStandardOutput()
{
    QByteArray ba = m_proc->readAllStandardOutput();
383
    //DEBUG("THREAD GDB OUT: " << ba);
hjk's avatar
hjk committed
384
    // =library-loaded...
385
    if (ba.startsWith("=")) {
386
        //DEBUG("LIBRARY LOADED");
hjk's avatar
hjk committed
387
        return;
388
    }
hjk's avatar
hjk committed
389
390
    if (ba.startsWith("*stopped")) {
        m_lastStopped = ba;
391
392
        DEBUG("THREAD GDB OUT 2: " << ba);
        if (!ba.contains("func=\"breaker\"")) {
hjk's avatar
hjk committed
393
394
395
396
            int pos1 = ba.indexOf(",line=\"") + 7;
            int pos2 = ba.indexOf("\"", pos1);
            m_line = ba.mid(pos1, pos2 - pos1).toInt();
            DEBUG(" LINE 1: " << m_line);
hjk's avatar
hjk committed
397
        }
hjk's avatar
hjk committed
398
    }
hjk's avatar
hjk committed
399

hjk's avatar
hjk committed
400
    // The "call" is always aborted with a message like:
hjk's avatar
hjk committed
401
    //  "~"2321\t    /* A */ QString s;\n" "
hjk's avatar
hjk committed
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
    //  "&"The program being debugged stopped while in a function called ..."
    //  "^error,msg="The program being debugged stopped ..."
    // Extract the "2321" from this
    static QByteArray lastText;
    if (ba.startsWith("~")) {
        lastText = ba;
        if (ba.size() > 8
                && (ba.at(2) < 'a' || ba.at(2) > 'z')
                && (ba.at(2) < '0' || ba.at(2) > '9')
                && !ba.startsWith("~\"Breakpoint ")
                && !ba.startsWith("~\"    at ")
                && !ba.startsWith("~\"    locals=")
                && !ba.startsWith("~\"XXX:")) {
            QByteArray ba1 = ba.mid(2, ba.size() - 6);
            if (ba1.startsWith("  File "))
                ba1 = ba1.replace(2, ba1.indexOf(','), "");
418
            //qWarning() << "OUT: " << ba1;
hjk's avatar
hjk committed
419
        }
hjk's avatar
hjk committed
420
421
422
423
424
425
426
427
428
429
430
    }
    if (ba.startsWith("&\"The program being debugged")) {
        int pos1 = 2;
        int pos2 = lastText.indexOf("\\", pos1);
        m_line = lastText.mid(pos1, pos2 - pos1).toInt();
        DEBUG(" LINE 2: " << m_line);
    }
    if (ba.startsWith("^error,msg=")) {
        if (!ba.startsWith("^error,msg=\"The program being debugged stopped"))
            qWarning() << "ERROR: " << ba.mid(1, ba.size() - 3);
    }
hjk's avatar
hjk committed
431

hjk's avatar
hjk committed
432
433
434
435
    if (ba.startsWith("~\"XXX: ")) {
        QByteArray ba1 = ba.mid(7, ba.size() - 11);
        qWarning() << "MESSAGE: " << ba.mid(7, ba.size() - 12);
    }
436

hjk's avatar
hjk committed
437
    ba = ba.replace("\\\"", "\"");
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

    // No interesting output before 'locals=...'
    int pos = ba.indexOf("locals={iname=");
    if (pos == -1 && m_output.isEmpty())
        return;

    if (m_output.isEmpty())
        m_output = ba.mid(pos);
    else
        m_output += ba;
    // Up to ^done\n(gdb)
    pos = m_output.indexOf("(gdb)");
    if (pos == -1)
        return;
    m_output = m_output.left(pos);
    pos = m_output.indexOf("^done");
    if (pos >= 4)
        m_output = m_output.left(pos - 4);

    if (m_output.isEmpty())
        return;

    //qWarning() << "WAKE UP: " << m_output;
    //qDebug() << "\n2 ABOUT TO AQUIRE FREE ";
    freeBytes.acquire();
    //qDebug() << "\n2 AQUIRED FREE ";
    buffer = m_output;
    m_output.clear();
    //m_waitCondition.wakeAll();
    //qDebug() << "\n2 ABOUT TO RELEASE USED";
    usedBytes.release();
    //qDebug() << "\n2 RELEASED USED";
hjk's avatar
hjk committed
470
}
hjk's avatar
hjk committed
471

hjk's avatar
hjk committed
472
473
void Thread::readStandardError()
{
474
    QByteArray ba = m_proc->readAllStandardError();
hjk's avatar
hjk committed
475
476
    qDebug() << "THREAD GDB ERR: " << ba;
}
hjk's avatar
hjk committed
477

hjk's avatar
hjk committed
478
479
480
481
void Thread::handleGdbStarted()
{
    //qDebug() << "\n\nGDB STARTED" << getpid() << gettid() << "\n\n";
}
hjk's avatar
hjk committed
482

hjk's avatar
hjk committed
483
484
void Thread::run()
{
hjk's avatar
hjk committed
485
486
    m_proc->write("source -p ../../../share/qtcreator/gdbmacros/dumper.py\n");
    m_proc->write("source -p ../../../share/qtcreator/gdbmacros/gdbmacros.py\n");
487
    m_proc->write("break breaker\n");
hjk's avatar
hjk committed
488
489
    m_proc->write("run\n");
    m_proc->write("handle SIGSTOP stop pass\n");
490
491
    qDebug() << "\n2 THREAD RUNNING, RELEASE FREE";
    freeBytes.release();
hjk's avatar
hjk committed
492
493
    exec();
}
hjk's avatar
hjk committed
494
495


hjk's avatar
hjk committed
496
497
498
499
500
/////////////////////////////////////////////////////////////////////////
//
// Test Class Framework Implementation
//
/////////////////////////////////////////////////////////////////////////
hjk's avatar
hjk committed
501

hjk's avatar
hjk committed
502
503
504
505
tst_Gdb::tst_Gdb()
    : m_thread(this)
{

Friedemann Kleint's avatar
Friedemann Kleint committed
506
507
508
509
}

void tst_Gdb::initTestCase()
{
510
    qWarning() << "SETUP START\n\n";
511
512
#ifndef Q_CC_GNU
    QSKIP("gdb test not applicable for compiler", SkipAll);
hjk's avatar
hjk committed
513
#endif
Friedemann Kleint's avatar
Friedemann Kleint committed
514
515
516
517
518
519
    //qDebug() << "\nTHREAD RUN" << getpid() << gettid();
    QProcess *gdbProc = new QProcess;
    QStringList args;
    args << QLatin1String("-i")
            << QLatin1String("mi") << QLatin1String("--args")
            << qApp->applicationFilePath();
520
    qWarning() << "Starting" << gdbBinary << args;
Friedemann Kleint's avatar
Friedemann Kleint committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
    gdbProc->start(gdbBinary, args);
    if (!gdbProc->waitForStarted()) {
        const QString msg = QString::fromLatin1("Unable to run %1: %2").arg(gdbBinary, gdbProc->errorString());
        delete gdbProc;
        QSKIP(msg.toLatin1().constData(), SkipAll);
    }

    const QString fileName = "tst_gdb.cpp";
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly)) {
        const QString msg = QString::fromLatin1("Unable to open %1: %2").arg(fileName, file.errorString());
        QSKIP(msg.toLatin1().constData(), SkipAll);
    }

hjk's avatar
hjk committed
535
536
537
538
539
540
541
542
543
544
    QByteArray funcName;
    const QByteArrayList bal = file.readAll().split('\n');
    Q_ASSERT(bal.size() > 100);
    for (int i = 0; i != bal.size(); ++i) {
        const QByteArray &ba = bal.at(i);
        if (ba.startsWith("void dump")) {
            int pos = ba.indexOf('(');
            funcName = ba.mid(5, pos - 5) + '@';
        } else if (ba.startsWith("    /*")) {
            int pos = ba.indexOf('*', 7);
545
            m_lineForLabel[(funcName + ba.mid(7, pos - 8)).trimmed()] = i + 1;
hjk's avatar
hjk committed
546
547
        }
    }
548
    //freeBytes.acquire();
Friedemann Kleint's avatar
Friedemann Kleint committed
549
    m_thread.startup(gdbProc);
550
    //usedBytes.release();
hjk's avatar
hjk committed
551
552
553
554
555
556
557
558
559
560
561
562
563
564
}

void tst_Gdb::prepare(const QByteArray &function)
{
    m_function = function;
    writeToGdb("b " + function);
    writeToGdb("call " + function + "()");
}

static bool isJoker(const QByteArray &ba)
{
    return ba.endsWith("'-'") || ba.contains("'-'}");
}

565
void tst_Gdb::check(const QByteArray &label, const QByteArray &expected0,
hjk's avatar
hjk committed
566
567
568
569
    const QByteArray &expanded, bool fancy)
{
    //qDebug() << "\nABOUT TO RUN TEST: " << expanded;
    qWarning() << label << "...";
570
    writeToGdb("bb " + N(int(fancy)) + " 1 " + expanded);
571
572
573
574
575
576

    //m_mutex.lock();
    //m_waitCondition.wait(&m_mutex);
    //QByteArray ba = m_thread.m_output;
    //m_thread.m_output.clear();
    //m_mutex.unlock();
hjk's avatar
hjk committed
577
    //GdbMi locals;
578
579
580
581
582
583
584
585
586
587

    //qDebug() << "\n1 ABOUT TO AQUIRE USED ";
    usedBytes.acquire();
    //qDebug() << "\n1 AQUIRED USED ";
    QByteArray ba = buffer;
    buffer.clear();
    //qDebug() << "\n1 ABOUT TO RELEASE FREE ";
    freeBytes.release();
    //qDebug() << "\n1 RELEASED FREE ";

hjk's avatar
hjk committed
588
589
590
591
592
593
    //locals.fromString("{" + ba + "}");
    QByteArray received = ba.replace("\"", "'");
    //qDebug() << "OUTPUT: " << ba << "\n\n";
    //qDebug() << "OUTPUT: " << locals.toString() << "\n\n";

    QByteArray actual = received.trimmed();
594
595
596
    int pos = actual.indexOf("^done");
    if (pos != -1)
        actual = actual.left(pos);
hjk's avatar
hjk committed
597
598
    if (actual.endsWith("\n"))
        actual.chop(1);
hjk's avatar
hjk committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
    if (actual.endsWith("\\n"))
        actual.chop(2);
    QByteArray expected = "locals={iname='local',name='Locals',value=' ',type=' ',"
        "children=[" + expected0 + "]}";
    int line = m_thread.m_line;

    QByteArrayList l1 = actual.split(',');
    QByteArrayList l2 = expected.split(',');

    bool ok = l1.size() == l2.size();
    if (ok) {
        for (int i = 0 ; i < l1.size(); ++i) {
            // Use "-" as joker.
            if (l1.at(i) != l2.at(i) && !isJoker(l2.at(i)))
                ok = false;
        }
    } else {
        qWarning() << "!= size: " << l1.size() << l2.size();
    }
hjk's avatar
hjk committed
618

hjk's avatar
hjk committed
619
620
621
622
623
624
625
626
627
628
629
    if (!ok) {
        int i = 0;
        for ( ; i < l1.size() && i < l2.size(); ++i) {
            if (l1.at(i) == l2.at(i) || isJoker(l2.at(i))) {
                qWarning() << "== " << l1.at(i);
            } else {
                //qWarning() << "!= " << l1.at(i).right(30) << l2.at(i).right(30);
                qWarning() << "!= " << l1.at(i) << l2.at(i);
                ok = false;
            }
        }
hjk's avatar
hjk committed
630
        for ( ; i < l2.size(); ++i)
hjk's avatar
hjk committed
631
            qWarning() << "!= " << "-----" << l2.at(i);
hjk's avatar
hjk committed
632
        for ( ; i < l1.size(); ++i)
hjk's avatar
hjk committed
633
634
635
636
637
638
            qWarning() << "!= " << l1.at(i) << "-----";
        if (l1.size() != l2.size()) {
            ok = false;
            qWarning() << "!= size: " << l1.size() << l2.size();
        }
        qWarning() << "RECEIVED: " << received;
639
        qWarning() << "ACTUAL  : " << actual;
hjk's avatar
hjk committed
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
    }
    QCOMPARE(ok, true);
    //qWarning() << "LINE: " << line << "ACT/EXP" << m_function + '@' + label;
    //QCOMPARE(actual, expected);


    int expline = m_lineForLabel.value(m_function + '@' + label);
    int actline = line;
    if (actline != expline) {
        qWarning() << "LAST STOPPED: " << m_thread.m_lastStopped;
    }
    QCOMPARE(actline, expline);
}

void tst_Gdb::next(int n)
{
    for (int i = 0; i != n; ++i)
        writeToGdb("next");
}

void tst_Gdb::cleanupTestCase()
{
    writeToGdb("kill");
    writeToGdb("quit");
    //m_thread.m_proc->waitForFinished();
665
    //m_thread.wait();
hjk's avatar
hjk committed
666
667
668
669
670
671
672
673
674
}


/////////////////////////////////////////////////////////////////////////
//
// Dumper Tests
//
/////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
675

hjk's avatar
hjk committed
676
677
///////////////////////////// Foo structure /////////////////////////////////

678
679
680
681
682
683
684
685
686
/*
    Foo:
        int a, b;
        char x[6];
        typedef QMap<QString, QString> Map;
        Map m;
        QHash<QObject *, Map::iterator> h;
*/

hjk's avatar
hjk committed
687
void dump_Foo()
hjk's avatar
hjk committed
688
689
690
691
692
693
{
    /* A */ Foo f;
    /* B */ f.doit();
    /* D */ (void) 0;
}

hjk's avatar
hjk committed
694
void tst_Gdb::dump_Foo()
hjk's avatar
hjk committed
695
{
hjk's avatar
hjk committed
696
    prepare("dump_Foo");
hjk's avatar
hjk committed
697
    next();
698
    check("B","{iname='local.f',name='f',type='Foo',"
hjk's avatar
hjk committed
699
            "value='-',numchild='5'}", "", 0);
700
    check("B","{iname='local.f',name='f',type='Foo',"
hjk's avatar
hjk committed
701
            "value='-',numchild='5',children=["
702
703
704
            "{name='a',type='int',value='0',numchild='0'},"
            "{name='b',type='int',value='2',numchild='0'},"
            "{name='x',type='char [6]',"
hjk's avatar
hjk committed
705
                "value='{...}',numchild='1'},"
706
            "{name='m',type='"NS"QMap<"NS"QString, "NS"QString>',"
hjk's avatar
hjk committed
707
                "value='{...}',numchild='1'},"
708
            "{name='h',type='"NS"QHash<"NS"QObject*, "
hjk's avatar
hjk committed
709
710
711
712
713
714
715
716
                ""NS"QMap<"NS"QString, "NS"QString>::iterator>',"
                "value='{...}',numchild='1'}]}",
            "local.f", 0);
}


///////////////////////////// Array ///////////////////////////////////////

hjk's avatar
hjk committed
717
void dump_array_char()
hjk's avatar
hjk committed
718
719
720
721
{
    /* A */ const char s[] = "XYZ";
    /* B */ (void) &s; }

hjk's avatar
hjk committed
722
void dump_array_int()
hjk's avatar
hjk committed
723
724
725
726
{
    /* A */ int s[] = {1, 2, 3};
    /* B */ (void) s; }

hjk's avatar
hjk committed
727
void tst_Gdb::dump_array()
hjk's avatar
hjk committed
728
{
hjk's avatar
hjk committed
729
    prepare("dump_array_char");
hjk's avatar
hjk committed
730
731
    next();
    // FIXME: numchild should be '4', not '1'
732
    check("B","{iname='local.s',name='s',type='char [4]',"
hjk's avatar
hjk committed
733
            "value='-',numchild='1'}", "");
734
    check("B","{iname='local.s',name='s',type='char [4]',"
hjk's avatar
hjk committed
735
736
737
738
739
            "value='-',numchild='1',childtype='char',childnumchild='0',"
            "children=[{value='88 'X''},{value='89 'Y''},{value='90 'Z''},"
            "{value='0 '\\\\000''}]}",
            "local.s");

hjk's avatar
hjk committed
740
    prepare("dump_array_int");
hjk's avatar
hjk committed
741
742
    next();
    // FIXME: numchild should be '3', not '1'
743
    check("B","{iname='local.s',name='s',type='int [3]',"
hjk's avatar
hjk committed
744
            "value='-',numchild='1'}", "");
745
    check("B","{iname='local.s',name='s',type='int [3]',"
hjk's avatar
hjk committed
746
747
748
749
750
751
752
753
            "value='-',numchild='1',childtype='int',childnumchild='0',"
            "children=[{value='1'},{value='2'},{value='3'}]}",
            "local.s");
}


///////////////////////////// Misc stuff /////////////////////////////////

hjk's avatar
hjk committed
754
void dump_misc()
hjk's avatar
hjk committed
755
{
756
#if 1
hjk's avatar
hjk committed
757
758
759
    /* A */ int *s = new int(1);
    /* B */ *s += 1;
    /* D */ (void) 0;
760
#else
hjk's avatar
hjk committed
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
    QVariant v1(QLatin1String("hallo"));
    QVariant v2(QStringList(QLatin1String("hallo")));
    QVector<QString> vec;
    vec.push_back("Hallo");
    vec.push_back("Hallo2");
    std::set<std::string> stdSet;
    stdSet.insert("s1");
    #ifdef QT_GUI_LIB
    QWidget *ww = 0; //this;
    QWidget &wwr = *ww;
    Q_UNUSED(wwr);
    #endif

    QSharedPointer<QString> sps(new QString("hallo"));
    QList<QSharedPointer<QString> > spsl;
    spsl.push_back(sps);
    QMap<QString,QString> stringmap;
    QMap<int,int> intmap;
    std::map<std::string, std::string> stdstringmap;
    stdstringmap[std::string("A")]  = std::string("B");
    int xxx = 45;

    if (1 == 1) {
        int xxx = 7;
        qDebug() << xxx;
    }

    QLinkedList<QString> lls;
    lls << "link1" << "link2";
    #ifdef QT_GUI_LIB
    QStandardItemModel *model = new QStandardItemModel;
    model->appendRow(new QStandardItem("i1"));
    #endif

    QList <QList<int> > nestedIntList;
    nestedIntList << QList<int>();
    nestedIntList.front() << 1 << 2;

    QVariantList vList;
    vList.push_back(QVariant(42));
    vList.push_back(QVariant("HALLO"));


    stringmap.insert("A", "B");
    intmap.insert(3,4);
    QSet<QString> stringSet;
    stringSet.insert("S1");
    stringSet.insert("S2");
    qDebug() << *(spsl.front()) << xxx;
810
#endif
hjk's avatar
hjk committed
811
812
}

hjk's avatar
hjk committed
813

hjk's avatar
hjk committed
814
void tst_Gdb::dump_misc()
hjk's avatar
hjk committed
815
{
hjk's avatar
hjk committed
816
    prepare("dump_misc");
hjk's avatar
hjk committed
817
    next();
818
    check("B","{iname='local.s',name='s',type='int *',"
hjk's avatar
hjk committed
819
            "value='-',numchild='1'}", "", 0);
820
    check("B","{iname='local.s',name='s',type='int *',"
hjk's avatar
hjk committed
821
822
823
824
825
            "value='1',numchild='0'}", "local.s,local.model", 0);
    //check("B","{iname='local.s',name='s',type='int *',"
    //        "value='-',numchild='1',children=[{iname='local.s.*',"
    //        "name='*s',type='int',value='1',numchild='0'}]}",
    //        "local.s,local.model", 0);
hjk's avatar
hjk committed
826
827
}

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842

///////////////////////////// typedef  ////////////////////////////////////

void dump_typedef()
{
    /* A */ typedef QMap<uint, double> T;
    /* B */ T t;
    /* C */ t[11] = 13.0;
    /* D */ (void) 0;
}

void tst_Gdb::dump_typedef()
{
    prepare("dump_typedef");
    next(2);
843
    check("D","{iname='local.t',name='t',type='T',"
844
            //"basetype='"NS"QMap<unsigned int, double>',"
845
            "value='-',numchild='1',"
846
847
            "childtype='double',childnumchild='0',"
            "children=[{name='11',value='13'}]}", "local.t");
848
849
}

hjk's avatar
hjk committed
850
#if 0
hjk's avatar
hjk committed
851
void tst_Gdb::dump_QAbstractItemHelper(QModelIndex &index)
hjk's avatar
hjk committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
{
    const QAbstractItemModel *model = index.model();
    const QString &rowStr = N(index.row());
    const QString &colStr = N(index.column());
    const QByteArray &internalPtrStrSymbolic = ptrToBa(index.internalPointer());
    const QByteArray &internalPtrStrValue = ptrToBa(index.internalPointer(), false);
    const QByteArray &modelPtrStr = ptrToBa(model);
    QByteArray indexSpecSymbolic = QByteArray().append(rowStr + "," + colStr + ",").
        append(internalPtrStrSymbolic + "," + modelPtrStr);
    QByteArray indexSpecValue = QByteArray().append(rowStr + "," + colStr + ",").
        append(internalPtrStrValue + "," + modelPtrStr);
    QByteArray expected = QByteArray("tiname='iname',addr='").append(ptrToBa(&index)).
        append("',type='"NS"QAbstractItem',addr='$").append(indexSpecSymbolic).
        append("',value='").append(valToString(model->data(index).toString())).
        append("',numchild='1',children=[");
    int rowCount = model->rowCount(index);
    int columnCount = model->columnCount(index);
    for (int row = 0; row < rowCount; ++row) {
        for (int col = 0; col < columnCount; ++col) {
            const QModelIndex &childIndex = model->index(row, col, index);
            expected.append("{name='[").append(valToString(row)).append(",").
                append(N(col)).append("]',numchild='1',addr='$").
                append(N(childIndex.row())).append(",").
                append(N(childIndex.column())).append(",").
                append(ptrToBa(childIndex.internalPointer())).append(",").
                append(modelPtrStr).append("',type='"NS"QAbstractItem',value='").
                append(valToString(model->data(childIndex).toString())).append("'}");
            if (col < columnCount - 1 || row < rowCount - 1)
                expected.append(",");
        }
    }
    expected.append("]");
    testDumper(expected, &index, NS"QAbstractItem", true, indexSpecValue);
}
886
#endif
hjk's avatar
hjk committed
887

888
class PseudoTreeItemModel : public QAbstractItemModel
hjk's avatar
hjk committed
889
{
890
891
892
893
894
895
public:
    PseudoTreeItemModel() : QAbstractItemModel(), parent1(0),
        parent1Child(1), parent2(10), parent2Child1(11), parent2Child2(12)
    {}

    int columnCount(const QModelIndex &parent = QModelIndex()) const
hjk's avatar
hjk committed
896
    {
897
898
899
        Q_UNUSED(parent);
        return 1;
    }
hjk's avatar
hjk committed
900

901
902
903
904
905
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
    {
        return !index.isValid() || role != Qt::DisplayRole ?
                QVariant() : *static_cast<int *>(index.internalPointer());
    }
hjk's avatar
hjk committed
906

907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
    QModelIndex index(int row, int column,
                      const QModelIndex & parent = QModelIndex()) const
    {
        QModelIndex index;
        if (column == 0) {
            if (!parent.isValid()) {
                if (row == 0)
                    index = createIndex(row, column, &parent1);
                else if (row == 1)
                    index = createIndex(row, column, &parent2);
            } else if (parent.internalPointer() == &parent1 && row == 0) {
                index = createIndex(row, column, &parent1Child);
            } else if (parent.internalPointer() == &parent2) {
                index = createIndex(row, column,
                            row == 0 ? &parent2Child1 : &parent2Child2);
hjk's avatar
hjk committed
922
923
            }
        }
924
925
        return index;
    }
hjk's avatar
hjk committed
926

927
928
929
930
931
932
933
934
935
    QModelIndex parent(const QModelIndex & index) const
    {
        QModelIndex parent;
        if (index.isValid()) {
            if (index.internalPointer() == &parent1Child)
                parent = createIndex(0, 0, &parent1);
            else if (index.internalPointer() == &parent2Child1 ||
                     index.internalPointer() == &parent2Child2)
                parent = createIndex(1, 0, &parent2);
hjk's avatar
hjk committed
936
        }
937
938
        return parent;
    }
hjk's avatar
hjk committed
939

940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
    int rowCount(const QModelIndex &parent = QModelIndex()) const
    {
        int rowCount;
        if (!parent.isValid() || parent.internalPointer() == &parent2)
            rowCount = 2;
        else if (parent.internalPointer() == &parent1)
            rowCount = 1;
        else
            rowCount = 0;
        return rowCount;
    }

private:
    mutable int parent1;
    mutable int parent1Child;
    mutable int parent2;
    mutable int parent2Child1;
    mutable int parent2Child2;
};
hjk's avatar
hjk committed
959
960


961
962
963

///////////////////////////// QAbstractItemAndModelIndex //////////////////////////

964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
//    /* A */ QStringListModel m(QStringList() << "item1" << "item2" << "item3");
//    /* B */ index = m.index(2, 0);
void dump_QAbstractItemAndModelIndex()
{
    /* A */ PseudoTreeItemModel m2; QModelIndex index;
    /* C */ index = m2.index(0, 0);
    /* D */ index = m2.index(1, 0);
    /* E */ index = m2.index(0, 0, index);
    /* F */ (void) index.row();
}

void tst_Gdb::dump_QAbstractItemAndModelIndex()
{
    prepare("dump_QAbstractItemAndModelIndex");
    if (checkUninitialized)
979
        check("A", "");
980
    next();
981
    check("C", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
982
983
984
985
986
            "value='{...}',numchild='6'},"
        "{iname='local.index',name='index',type='"NS"QModelIndex',"
            "value='(invalid)',numchild='0'}",
        "local.index");
    next();
987
    check("D", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
988
989
990
991
992
993
994
995
996
           "value='{...}',numchild='6'},"
        "{iname='local.index',name='index',type='"NS"QModelIndex',"
          "value='(0, 0)',numchild='5',children=["
            "{name='row',value='0',type='int',numchild='0'},"
            "{name='column',value='0',type='int',numchild='0'},"
            "{name='parent',type='"NS"QModelIndex',value='(invalid)',numchild='0'},"
            "{name='model',value='-',type='"NS"QAbstractItemModel*',numchild='1'}]}",
        "local.index");
    next();
997
    check("E", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
998
999
1000
1001
1002
1003
1004
1005
1006
           "value='{...}',numchild='6'},"
        "{iname='local.index',name='index',type='"NS"QModelIndex',"
          "value='(1, 0)',numchild='5',children=["
            "{name='row',value='1',type='int',numchild='0'},"
            "{name='column',value='0',type='int',numchild='0'},"
            "{name='parent',type='"NS"QModelIndex',value='(invalid)',numchild='0'},"
            "{name='model',value='-',type='"NS"QAbstractItemModel*',numchild='1'}]}",
        "local.index");
    next();
1007
    check("F", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
           "value='{...}',numchild='6'},"
        "{iname='local.index',name='index',type='"NS"QModelIndex',"
          "value='(0, 0)',numchild='5',children=["
            "{name='row',value='0',type='int',numchild='0'},"
            "{name='column',value='0',type='int',numchild='0'},"
            "{name='parent',type='"NS"QModelIndex',value='(1, 0)',numchild='5'},"
            "{name='model',value='-',type='"NS"QAbstractItemModel*',numchild='1'}]}",
        "local.index");
}

/*
QByteArray dump_QAbstractItemModelHelper(QAbstractItemModel &m)
hjk's avatar
hjk committed
1020
1021
{
    QByteArray address = ptrToBa(&m);
hjk's avatar
hjk committed
1022
    QByteArray expected = QByteArray("tiname='iname',"
hjk's avatar
hjk committed
1023
        "type='"NS"QAbstractItemModel',value='(%,%)',numchild='1',children=["
hjk's avatar
hjk committed
1024
        "{numchild='1',name='"NS"QObject',value='%',"
hjk's avatar
hjk committed
1025
1026
1027
1028
1029
        "valueencoded='2',type='"NS"QObject',displayedtype='%'}")
            << address
            << N(m.rowCount())
            << N(m.columnCount())
            << address
1030
            << utfToHex(m.objectName())
hjk's avatar
hjk committed
1031
1032
1033
1034
1035
1036
            << m.metaObject()->className();

    for (int row = 0; row < m.rowCount(); ++row) {
        for (int column = 0; column < m.columnCount(); ++column) {
            QModelIndex mi = m.index(row, column);
            expected.append(QByteArray(",{name='[%,%]',value='%',"
hjk's avatar
hjk committed
1037
                "valueencoded='2',numchild='1',%,%,%',"
hjk's avatar
hjk committed
1038
1039
1040
                "type='"NS"QAbstractItem'}")
                << N(row)
                << N(column)
1041
                << utfToHex(m.data(mi).toString())
hjk's avatar
hjk committed
1042
1043
1044
1045
1046
1047
1048
                << N(mi.row())
                << N(mi.column())
                << ptrToBa(mi.internalPointer())
                << ptrToBa(mi.model()));
        }
    }
    expected.append("]");
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
    return expected;
}
*/

void dump_QAbstractItemModel()
{
    #ifdef QT_GUI_LIB
    /* A */ QStringList strList;
            strList << "String 1";
            QStringListModel model1(strList);
hjk's avatar
hjk committed
1059
            QStandardItemModel model2(0, 2);
1060
1061
1062
    /* B */ model1.setStringList(strList);
    /* C */ strList << "String 2";
    /* D */ model1.setStringList(strList);
1063
1064
1065
    /* E */ model2.appendRow(QList<QStandardItem *>() << (new QStandardItem("Item (0,0)")) << (new QStandardItem("Item (0,1)")));
    /* F */ model2.appendRow(QList<QStandardItem *>() << (new QStandardItem("Item (1,0)")) << (new QStandardItem("Item (1,1)")));
    /* G */ (void) (model1.rowCount() + model2.rowCount() + strList.size());
1066
    #endif
hjk's avatar
hjk committed
1067
1068
}

hjk's avatar
hjk committed
1069
void tst_Gdb::dump_QAbstractItemModel()
hjk's avatar
hjk committed
1070
{
1071
1072
    #ifdef QT_GUI_LIB
    /* A */ QStringList strList;
hjk's avatar
hjk committed
1073
    QString template_ =
1074
1075
1076
1077
1078
1079
1080
1081
1082
        "{iname='local.strList',name='strList',type='"NS"QStringList',"
            "value='<%1 items>',numchild='%1'},"
        "{iname='local.model1',name='model1',type='"NS"QStringListModel',"
            "value='{...}',numchild='3'},"
        "{iname='local.model2',name='model2',type='"NS"QStandardItemModel',"
            "value='{...}',numchild='2'}";

    prepare("dump_QAbstractItemModel");
    if (checkUninitialized)
1083
        check("A", template_.arg("1").toAscii());
1084
    next(4);
1085
    check("B", template_.arg("1").toAscii());
1086
    #endif
hjk's avatar
hjk committed
1087
1088
}

1089
1090
1091

///////////////////////////// QByteArray /////////////////////////////////

hjk's avatar
hjk committed
1092
void dump_QByteArray()
hjk's avatar
hjk committed
1093
{
hjk's avatar
hjk committed
1094
1095
1096
1097
    /* A */ QByteArray ba;                       // Empty object.
    /* B */ ba.append('a');                      // One element.
    /* C */ ba.append('b');                      // Two elements.
    /* D */ ba = QByteArray(101, 'a');           // > 100 elements.
Friedemann Kleint's avatar
Friedemann Kleint committed
1098
    /* E */ ba = QByteArray("abc\a\n\r\033\'\"?"); // Mixed.
hjk's avatar
hjk committed
1099
    /* F */ (void) 0;
hjk's avatar
hjk committed
1100
1101
}

hjk's avatar
hjk committed
1102
void tst_Gdb::dump_QByteArray()
hjk's avatar
hjk committed
1103
{
hjk's avatar
hjk committed
1104
1105
    prepare("dump_QByteArray");
    if (checkUninitialized)
1106
        check("A","{iname='local.ba',name='ba',type='"NS"QByteArray',"
1107
            "value='<invalid>',numchild='0'}");
hjk's avatar
hjk committed
1108
    next();
1109
    check("B","{iname='local.ba',name='ba',type='"NS"QByteArray',"
hjk's avatar
hjk committed
1110
1111
            "valueencoded='6',value='',numchild='0'}");
    next();
1112
    check("C","{iname='local.ba',name='ba',type='"NS"QByteArray',"
hjk's avatar
hjk committed
1113
1114
            "valueencoded='6',value='61',numchild='1'}");
    next();
1115
    check("D","{iname='local.ba',name='ba',type='"NS"QByteArray',"
hjk's avatar
hjk committed
1116
1117
            "valueencoded='6',value='6162',numchild='2'}");
    next();
1118
    check("E","{iname='local.ba',name='ba',type='"NS"QByteArray',"
hjk's avatar
hjk committed
1119
1120
1121
1122
1123
            "valueencoded='6',value='616161616161616161616161616161616161"
            "616161616161616161616161616161616161616161616161616161616161"
            "616161616161616161616161616161616161616161616161616161616161"
            "6161616161616161616161616161616161616161616161',numchild='101'}");
    next();
1124
    check("F","{iname='local.ba',name='ba',type='"NS"QByteArray',"
hjk's avatar
hjk committed
1125
            "valueencoded='6',value='616263070a0d1b27223f',numchild='10'}");
1126
    check("F","{iname='local.ba',name='ba',type='"NS"QByteArray',"
hjk's avatar
hjk committed
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
            "valueencoded='6',value='616263070a0d1b27223f',numchild='10',"
            "childtype='char',childnumchild='0',"
            "children=[{value='97 'a''},{value='98 'b''},"
            "{value='99 'c''},{value='7 '\\\\a''},"
            "{value='10 '\\\\n''},{value='13 '\\\\r''},"
            "{value='27 '\\\\033''},{value='39 '\\\\'''},"
            "{value='34 ''''},{value='63 '?''}]}",
            "local.ba");
}

1137
1138
1139

///////////////////////////// QChar /////////////////////////////////

hjk's avatar
hjk committed
1140
void dump_QChar()
hjk's avatar
hjk committed
1141
1142
1143
1144
1145
1146
1147
1148
{
    /* A */ QChar c('X');               // Printable ASCII character.
    /* B */ c = QChar(0x600);           // Printable non-ASCII character.
    /* C */ c = QChar::fromAscii('\a'); // Non-printable ASCII character.
    /* D */ c = QChar(0x9f);            // Non-printable non-ASCII character.
    /* E */ c = QChar::fromAscii('?');  // The replacement character.
    /* F */ (void) 0; }

hjk's avatar
hjk committed
1149
void tst_Gdb::dump_QChar()
hjk's avatar
hjk committed
1150
{
hjk's avatar
hjk committed
1151
    prepare("dump_QChar");
hjk's avatar
hjk committed
1152
1153
    next();

hjk's avatar
hjk committed
1154
    // Case 1: Printable ASCII character.
1155
    check("B","{iname='local.c',name='c',type='"NS"QChar',"
hjk's avatar
hjk committed
1156
        "value=''X' (88)',numchild='0'}");
hjk's avatar
hjk committed
1157
    next();
hjk's avatar
hjk committed
1158
1159

    // Case 2: Printable non-ASCII character.
1160
    check("C","{iname='local.c',name='c',type='"NS"QChar',"
hjk's avatar
hjk committed
1161
        "value=''?' (1536)',numchild='0'}");
hjk's avatar
hjk committed
1162
    next();
hjk's avatar
hjk committed
1163
1164

    // Case 3: Non-printable ASCII character.
1165
    check("D","{iname='local.c',name='c',type='"NS"QChar',"
hjk's avatar
hjk committed
1166
        "value=''?' (7)',numchild='0'}");
hjk's avatar
hjk committed
1167
    next();
hjk's avatar
hjk committed
1168
1169

    // Case 4: Non-printable non-ASCII character.
1170
    check("E","{iname='local.c',name='c',type='"NS"QChar',"
hjk's avatar
hjk committed
1171
        "value=''?' (159)',numchild='0'}");
hjk's avatar
hjk committed
1172
    next();
hjk's avatar
hjk committed
1173
1174

    // Case 5: Printable ASCII Character that looks like the replacement character.
1175
    check("F","{iname='local.c',name='c',type='"NS"QChar',"
hjk's avatar
hjk committed
1176
        "value=''?' (63)',numchild='0'}");
hjk's avatar
hjk committed
1177
1178
}

1179
1180
1181
1182
1183
1184

///////////////////////////// QDateTime /////////////////////////////////

void dump_QDateTime()
{
    #ifndef QT_NO_DATESTRING
hjk's avatar
hjk committed
1185
    /* A */ QDateTime d;
1186
1187
1188
    /* B */ d = QDateTime::fromString("M5d21y7110:31:02", "'M'M'd'd'y'yyhh:mm:ss");
    /* C */ (void) d.isNull();
    #endif
hjk's avatar
hjk committed
1189
1190
}

hjk's avatar
hjk committed
1191
void tst_Gdb::dump_QDateTime()
hjk's avatar
hjk committed
1192
{
1193
1194
1195
    #ifndef QT_NO_DATESTRING
    prepare("dump_QDateTime");
    if (checkUninitialized)
1196
        check("A","{iname='local.d',name='d',"
1197
1198
1199
            "type='"NS"QDateTime',value='<invalid>',"
            "numchild='0'}");
    next();
1200
    check("B", "{iname='local.d',name='d',type='"NS"QDateTime',"
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
          "valueencoded='7',value='-',numchild='3',children=["
            "{name='isNull',type='bool',value='true',numchild='0'},"
            "{name='toTime_t',type='unsigned int',value='4294967295',numchild='0'},"
            "{name='toString',type='myns::QString',valueencoded='7',"
                "value='',numchild='0'},"
            "{name='(ISO)',type='myns::QString',valueencoded='7',"
                "value='',numchild='0'},"
            "{name='(SystemLocale)',type='myns::QString',valueencoded='7',"
                "value='',numchild='0'},"
            "{name='(Locale)',type='myns::QString',valueencoded='7',"
                "value='',numchild='0'},"
            "{name='toUTC',type='myns::QDateTime',valueencoded='7',"
                "value='',numchild='3'},"
            "{name='toLocalTime',type='myns::QDateTime',valueencoded='7',"
                "value='',numchild='3'}"
            "]}",
          "local.d");
    next();
1219
    check("C", "{iname='local.d',name='d',type='"NS"QDateTime',"
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
          "valueencoded='7',value='-',"
                "numchild='3',children=["
            "{name='isNull',type='bool',value='false',numchild='0'},"
            "{name='toTime_t',type='unsigned int',value='43666262',numchild='0'},"
            "{name='toString',type='myns::QString',valueencoded='7',"
                "value='-',numchild='0'},"
            "{name='(ISO)',type='myns::QString',valueencoded='7',"
                "value='-',numchild='0'},"
            "{name='(SystemLocale)',type='myns::QString',valueencoded='7',"
                "value='-',numchild='0'},"
            "{name='(Locale)',type='myns::QString',valueencoded='7',"
                "value='-',numchild='0'},"
            "{name='toUTC',type='myns::QDateTime',valueencoded='7',"
                "value='-',numchild='3'},"
            "{name='toLocalTime',type='myns::QDateTime',valueencoded='7',"
                "value='-',numchild='3'}"
            "]}",
          "local.d");
    #endif
hjk's avatar
hjk committed
1239
1240
}

1241
1242
1243
1244
1245
1246
1247
1248
1249

///////////////////////////// QDir /////////////////////////////////

void dump_QDir()
{
    /* A */ QDir dir = QDir::current(); // Case 1: Current working directory.
    /* B */ dir = QDir::root();         // Case 2: Root directory.
    /* C */ (void)