main.cpp 22.7 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
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
17
18
19
20
21
22
23
24
**
** GNU Lesser General Public License Usage
**
** 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.
**
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.
31
32
33
34
**
**************************************************************************/

#include <QtCore/QStringList>
35
#include <QtCore/QLinkedList>
36
#include <QtCore/QVector>
37
#include <QtCore/QSharedPointer>
38
#include <QtCore/QTimer>
39
#include <QtCore/QMap>
Friedemann Kleint's avatar
Friedemann Kleint committed
40
#include <QtCore/QSet>
41
#include <QtCore/QVariant>
Friedemann Kleint's avatar
Friedemann Kleint committed
42
43
#include <QtCore/QFileInfo>
#include <QtCore/QCoreApplication>
44
#include <QtGui/QAction>
45
46
47

#include <string>
#include <list>
48
#include <vector>
49
#include <set>
50
#include <map>
51
52
53
54

#include <stdio.h>
#include <string.h>

55
56
// Test uninitialized variables allocing memory
bool optTestUninitialized = false;
57
58
59
bool optTestAll = false;
bool optEmptyContainers = false;
unsigned optVerbose = 0;
Friedemann Kleint's avatar
Friedemann Kleint committed
60
const char *appPath = 0;
61

62
// Provide address of type of be tested.
63
// When testing uninitialized memory, allocate at random.
64
65
66
template <class T>
        inline T* testAddress(T* in)
{
67
68
69
    unsigned char *mem = 0;
    if (optTestUninitialized) {
        mem = new unsigned char[sizeof(T)];
70
        for (unsigned int i = 0; i < sizeof(T); i++) {
71
72
73
74
75
76
            mem[i] = char(rand() % 255u);
        }
    } else {
        mem = reinterpret_cast<unsigned char*>(in);
    }
    if (optVerbose) {
77
        for (unsigned int i = 0; i < sizeof(T); i++) {
78
79
80
81
82
83
            unsigned int b = mem[i];
            printf("%2d %2x %3d\n", i, b, b);
        }
        fflush(stdout);
    }
    return reinterpret_cast<T*>(mem);
84
}
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Test program for Dumper development/porting.
 * Takes the type as first argument. */

// --------------- Dumper symbols
extern char qDumpInBuffer[10000];
extern char qDumpOutBuffer[100000];

extern "C" void *qDumpObjectData440(
    int protocolVersion,
    int token,
    void *data,
#ifdef Q_CC_MSVC // CDB cannot handle boolean parameters
    int dumpChildren,
#else
    bool dumpChildren,
#endif
    int extraInt0, int extraInt1, int extraInt2, int extraInt3);

static void prepareInBuffer(const char *outerType,
                            const char *iname,
                            const char *expr,
                            const char *innerType)
{
    // Leave trailing '\0'
    char *ptr = qDumpInBuffer;
    strcpy(ptr, outerType);
    ptr += strlen(outerType);
    ptr++;
    strcpy(ptr, iname);
    ptr += strlen(iname);
    ptr++;
    strcpy(ptr, expr);
    ptr += strlen(expr);
    ptr++;
    strcpy(ptr, innerType);
    ptr += strlen(innerType);
    ptr++;
    strcpy(ptr, iname);
}

// ---------------  Qt types
static int dumpQString()
{
    QString test = QLatin1String("hallo");
    prepareInBuffer("QString", "local.qstring", "local.qstring", "");
131
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0, 0, 0);
132
133
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
134
    QString uninitialized;
135
136
137
    return 0;
}

138
139
140
141
142
143
144
145
146
147
148
static int dumpQSharedPointerQString()
{
    QSharedPointer<QString> test(new QString(QLatin1String("hallo")));
    prepareInBuffer("QSharedPointer", "local.sharedpointerqstring", "local.local.sharedpointerqstring", "QString");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    QString uninitialized;
    return 0;
}

149
150
151
152
static int dumpQStringList()
{
    QStringList test = QStringList() << QLatin1String("item1") << QLatin1String("item2");
    prepareInBuffer("QList", "local.qstringlist", "local.qstringlist", "QString");
153
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), 0, 0, 0);
154
155
156
157
158
159
160
161
162
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

static int dumpQIntList()
{
    QList<int> test = QList<int>() << 1 << 2;
    prepareInBuffer("QList", "local.qintlist", "local.qintlist", "int");
163
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
164
165
166
167
168
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

169
170
171
172
173
174
175
176
177
178
static int dumpQIntLinkedList()
{
    QLinkedList<int> test = QLinkedList<int>() << 1 << 2;
    prepareInBuffer("QLinkedList", "local.qintlinkedlist", "local.qlinkedintlist", "int");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

179
180
static int dumpQIntVector()
{
181
    QVector<int> test = QVector<int>() << 42 << 43;
182
    prepareInBuffer("QVector", "local.qintvector", "local.qintvector", "int");
183
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
184
185
186
187
188
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

Friedemann Kleint's avatar
Friedemann Kleint committed
189
190
191
192
193
194
195
196
197
198
static int dumpQQStringVector()
{
    QVector<QString> test = QVector<QString>() << "42s" << "43s";
    prepareInBuffer("QVector", "local.qstringvector", "local.qstringvector", "QString");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

199
200
201
202
203
static int dumpQMapIntInt()
{
    QMap<int,int> test;
    QMapNode<int,int> mapNode;
    const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
204
205
206
207
    if (!optEmptyContainers) {
        test.insert(42, 43);
        test.insert(43, 44);
    }
208
209
210
211
212
213
214
215
216
217
218
219
    prepareInBuffer("QMap", "local.qmapintint", "local.qmapintint", "int@int");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(int), sizeof(mapNode), valueOffset);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

static int dumpQMapIntString()
{
    QMap<int,QString> test;
    QMapNode<int,QString> mapNode;
    const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
220
221
222
223
    if (!optEmptyContainers) {
        test.insert(42, QLatin1String("fortytwo"));
        test.insert(43, QLatin1String("fortytree"));
    }
224
225
226
227
228
229
230
    prepareInBuffer("QMap", "local.qmapintqstring", "local.qmapintqstring", "int@QString");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(QString), sizeof(mapNode), valueOffset);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

Friedemann Kleint's avatar
Friedemann Kleint committed
231
232
233
static int dumpQSetInt()
{
    QSet<int> test;
234
235
236
237
    if (!optEmptyContainers) {
        test.insert(42);
        test.insert(43);
    }
Friedemann Kleint's avatar
Friedemann Kleint committed
238
239
240
241
242
243
244
245
    prepareInBuffer("QSet", "local.qsetint", "local.qsetint", "int");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}


246
247
248
249
250
static int dumpQMapQStringString()
{
    QMap<QString,QString> test;
    QMapNode<QString,QString> mapNode;
    const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
251
252
253
254
    if (!optEmptyContainers) {
        test.insert(QLatin1String("42s"), QLatin1String("fortytwo"));
        test.insert(QLatin1String("423"), QLatin1String("fortytree"));
    }
255
    prepareInBuffer("QMap", "local.qmapqstringqstring", "local.qmapqstringqstring", "QString@QString");
256
257
258
259
260
261
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(QString), sizeof(mapNode), valueOffset);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

262
263
static int dumpQVariant()
{
Friedemann Kleint's avatar
Friedemann Kleint committed
264
265
266
267
268
269
270
271
272
273
274
    QVariant test = QLatin1String("item");
    prepareInBuffer("QVariant", "local.qvariant", "local.qvariant", "");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
    fputs("\n\n", stdout);
    test = QVariant(int(42));
    prepareInBuffer("QVariant", "local.qvariant", "local.qvariant", "");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
    fputs("\n\n", stdout);
    test = QVariant(double(3.141));
275
276
277
278
279
280
281
282
    prepareInBuffer("QVariant", "local.qvariant", "local.qvariant", "");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
    fputs("\n\n", stdout);
    test = QVariant(QStringList(QLatin1String("item1")));
    prepareInBuffer("QVariant", "local.qvariant", "local.qvariant", "");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
283
284
285
286
    test = QVariant(QRect(1,2, 3, 4));
    prepareInBuffer("QVariant", "local.qvariant", "local.qvariant", "");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
287
288
289
    return 0;
}

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
static int dumpQVariantList()
{
    QVariantList test;
    if (!optEmptyContainers) {
        test.push_back(QVariant(QLatin1String("hallo")));
        test.push_back(QVariant(42));
        test.push_back(QVariant(3.141));
    }
    // As a list
    prepareInBuffer("QList", "local.qvariantlist", "local.qvariantlist", "QVariant");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QVariant), 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
    // As typedef
    fputs("\n\n", stdout);
    prepareInBuffer("QVariantList", "local.qvariantlist", "local.qvariantlist", "");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0,0 ,0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

311
312
313
314
315
316
// ---------------  std types

static int dumpStdString()
{
    std::string test = "hallo";
    prepareInBuffer("std::string", "local.string", "local.string", "");
317
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0, 0, 0);
318
319
320
321
322
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

323
324
325
326
static int dumpStdWString()
{
    std::wstring test = L"hallo";
    prepareInBuffer("std::wstring", "local.wstring", "local.wstring", "");
327
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0, 0, 0);
328
329
330
331
332
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

333
334
335
static int dumpStdStringList()
{
    std::list<std::string> test;
336
337
338
339
    if (!optEmptyContainers) {
        test.push_back("item1");
        test.push_back("item2");
    }
340
    prepareInBuffer("std::list", "local.stringlist", "local.stringlist", "std::string");
341
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<std::string>::allocator_type), 0, 0);
342
343
344
345
346
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

347
348
349
static int dumpStdStringQList()
{
    QList<std::string> test;
350
351
352
353
    if (!optEmptyContainers) {
        test.push_back("item1");
        test.push_back("item2");
    }
354
    prepareInBuffer("QList", "local.stringqlist", "local.stringqlist", "std::string");
355
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), 0, 0, 0);
356
357
358
359
360
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

361
362
363
static int dumpStdIntList()
{
    std::list<int> test;
364
365
366
367
    if (!optEmptyContainers) {
        test.push_back(1);
        test.push_back(2);
    }
368
    prepareInBuffer("std::list", "local.intlist", "local.intlist", "int");
369
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0);
370
371
372
373
374
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

375
376
377
static int dumpStdIntVector()
{
    std::vector<int> test;
378
379
380
381
    if (!optEmptyContainers) {
        test.push_back(1);
        test.push_back(2);
    }
382
    prepareInBuffer("std::vector", "local.intvector", "local.intvector", "int");
383
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0);
384
385
386
387
388
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

389
390
391
static int dumpStdStringVector()
{
    std::vector<std::string> test;
392
393
394
395
    if (!optEmptyContainers) {
        test.push_back("item1");
        test.push_back("item2");
    }
396
    prepareInBuffer("std::vector", "local.stringvector", "local.stringvector", "std::string");
397
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<int>::allocator_type), 0, 0);
398
399
400
401
402
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

403
404
405
static int dumpStdWStringVector()
{
    std::vector<std::wstring> test;
406
407
408
409
    if (!optEmptyContainers) {
        test.push_back(L"item1");
        test.push_back(L"item2");
    }
410
411
412
413
414
415
416
    prepareInBuffer("std::vector", "local.wstringvector", "local.wstringvector", "std::wstring");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::wstring), sizeof(std::list<int>::allocator_type), 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

417
418
419
static int dumpStdIntSet()
{
    std::set<int> test;
420
421
422
423
    if (!optEmptyContainers) {
        test.insert(1);
        test.insert(2);
    }
424
    prepareInBuffer("std::set", "local.intset", "local.intset", "int");
425
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0);
426
427
428
429
430
431
432
433
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

static int dumpStdStringSet()
{
    std::set<std::string> test;
434
435
436
437
    if (!optEmptyContainers) {
        test.insert("item1");
        test.insert("item2");
    }
438
    prepareInBuffer("std::set", "local.stringset", "local.stringset", "std::string");
439
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<int>::allocator_type), 0, 0);
440
441
442
443
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}
444

445
446
447
static int dumpStdQStringSet()
{
    std::set<QString> test;
448
449
450
451
    if (!optEmptyContainers) {
        test.insert(QLatin1String("item1"));
        test.insert(QLatin1String("item2"));
    }
452
453
454
455
456
457
458
    prepareInBuffer("std::set", "local.stringset", "local.stringset", "QString");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(std::list<int>::allocator_type), 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

459
460
static int dumpStdMapIntString()
{
461
    std::map<int,std::string> test;
462
    std::map<int,std::string>::value_type entry(42, std::string("fortytwo"));
463
464
465
    if (!optEmptyContainers) {
        test.insert(entry);
    }
466
467
468
469
470
471
472
473
474
    const int valueOffset = (char*)&(entry.second) - (char*)&entry;
    prepareInBuffer("std::map", "local.stdmapintstring", "local.stdmapintstring",
                    "int@std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::less<int>@std::allocator<std::pair<const int,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::string), valueOffset, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

475
476
477
478
479
static int dumpStdMapStringString()
{
    typedef std::map<std::string,std::string> TestType;
    TestType test;
    const TestType::value_type entry("K", "V");
480
481
482
    if (!optEmptyContainers) {
        test.insert(entry);
    }
483
484
485
486
487
488
489
490
491
    const int valueOffset = (char*)&(entry.second) - (char*)&entry;
    prepareInBuffer("std::map", "local.stdmapstringstring", "local.stdmapstringstring",
                    "std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::less<int>@std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >");
    qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::string), valueOffset, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

492
493
static int dumpQObject()
{
494
    // Requires the childOffset to be know, but that is not critical
495
496
497
498
499
500
    QAction action(0);
    QObject x;
    QAction *a2= new QAction(&action);
    a2->setObjectName(QLatin1String("a2"));
    action.setObjectName(QLatin1String("action"));
    QObject::connect(&action, SIGNAL(triggered()), &x, SLOT(deleteLater()));
501
    prepareInBuffer("QObject", "local.qobject", "local.qobject", "");
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
    qDumpObjectData440(2, 42, testAddress(&action), 1, 0, 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputs("\n\n", stdout);
    // Property list
    prepareInBuffer("QObjectPropertyList", "local.qobjectpropertylist", "local.qobjectpropertylist", "");
    qDumpObjectData440(2, 42, testAddress(&action), 1, 0, 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputs("\n\n", stdout);
    // Signal list
    prepareInBuffer("QObjectSignalList", "local.qobjectsignallist", "local.qobjectsignallist", "");
    qDumpObjectData440(2, 42, testAddress(&action), 1, 0, 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    // Slot list
    prepareInBuffer("QObjectSlotList", "local.qobjectslotlist", "local.qobjectslotlist", "");
    qDumpObjectData440(2, 42, testAddress(&action), 1, 0, 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputs("\n\n", stdout);
    // Signal list
    prepareInBuffer("QObjectChildList", "local.qobjectchildlist", "local.qobjectchildlist", "");
    qDumpObjectData440(2, 42, testAddress(&action), 1, 0, 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    return 0;
}

Friedemann Kleint's avatar
Friedemann Kleint committed
526
527
528
529
530
531
532
533
534
535
static int dumpQFileInfo()
{
    QFileInfo test(QString::fromLatin1(appPath));
    prepareInBuffer("QFileInfo", "local.qfileinfo", "local.qfileinfo","");
    qDumpObjectData440(2, 42, testAddress(&test), 1, 0, 0, 0, 0);
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    return 0;
}

536
537
538
539
540
541
542
543
544
545
546
547
548
static int dumpQObjectList()
{
    // Requires the childOffset to be know, but that is not critical
    QObject *root = new QObject;
    root ->setObjectName("root");
    QTimer *t1 = new QTimer;
    t1 ->setObjectName("t1");
    QTimer *t2 = new QTimer;
    t2 ->setObjectName("t2");
    QObjectList test;
    test << root << t1 << t2;
    prepareInBuffer("QList", "local.qobjectlist", "local.qobjectlist", "QObject *");
    qDumpObjectData440(2, 42, testAddress(&test), sizeof(QObject*), 0, 0, 0, 0);
549
550
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
551
    delete root;
552
553
554
    return 0;
}

555
556
557
558
typedef int (*DumpFunction)();
typedef QMap<QString, DumpFunction> TypeDumpFunctionMap;

static TypeDumpFunctionMap registerTypes()
559
{
560
561
562
563
564
    TypeDumpFunctionMap rc;
    rc.insert("QString", dumpQString);
    rc.insert("QSharedPointer<QString>", dumpQSharedPointerQString);
    rc.insert("QStringList", dumpQStringList);
    rc.insert("QList<int>", dumpQIntList);
565
    rc.insert("QLinkedList<int>", dumpQIntLinkedList);
566
567
    rc.insert("QList<std::string>", dumpStdStringQList);
    rc.insert("QVector<int>", dumpQIntVector);
Friedemann Kleint's avatar
Friedemann Kleint committed
568
    rc.insert("QVector<QString>", dumpQQStringVector);
569
    rc.insert("QMap<int,QString>", dumpQMapIntString);
570
    rc.insert("QMap<QString,QString>", dumpQMapQStringString);
571
    rc.insert("QMap<int,int>", dumpQMapIntInt);
Friedemann Kleint's avatar
Friedemann Kleint committed
572
    rc.insert("QSet<int>", dumpQSetInt);
573
574
575
576
577
578
579
580
581
    rc.insert("string", dumpStdString);
    rc.insert("wstring", dumpStdWString);
    rc.insert("list<int>", dumpStdIntList);
    rc.insert("list<string>", dumpStdStringList);
    rc.insert("vector<int>", dumpStdIntVector);
    rc.insert("vector<string>", dumpStdStringVector);
    rc.insert("vector<wstring>", dumpStdWStringVector);
    rc.insert("set<int>", dumpStdIntSet);
    rc.insert("set<string>", dumpStdStringSet);
582
    rc.insert("set<QString>", dumpStdQStringSet);
583
    rc.insert("map<int,string>", dumpStdMapIntString);
584
    rc.insert("map<string,string>", dumpStdMapStringString);
Friedemann Kleint's avatar
Friedemann Kleint committed
585
    rc.insert("QFileInfo", dumpQFileInfo);
586
587
588
    rc.insert("QObject", dumpQObject);
    rc.insert("QObjectList", dumpQObjectList);
    rc.insert("QVariant", dumpQVariant);
589
    rc.insert("QVariantList", dumpQVariantList);
590
    return rc;
591
592
}

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
static void usage(const char *b, const TypeDumpFunctionMap &tdm)
{
    printf("Usage: %s [-v][-u][-e] <type1> <type2..>\n", b);
    printf("Usage: %s [-v][-u][-e] -a excluded_type1 <excluded_type2...>\n", b);
    printf("Options:  -u  Test uninitialized memory\n");
    printf("          -e  Empty containers\n");
    printf("          -v  Verbose\n");
    printf("          -a  Test all available types\n");
    printf("Supported types: ");
    const TypeDumpFunctionMap::const_iterator cend = tdm.constEnd();
    for (TypeDumpFunctionMap::const_iterator it = tdm.constBegin(); it != cend; ++it) {
        fputs(qPrintable(it.key()), stdout);
        fputc(' ', stdout);
    }
    fputc('\n', stdout);
}

610
611
int main(int argc, char *argv[])
{
Friedemann Kleint's avatar
Friedemann Kleint committed
612
    appPath = argv[0];
613
    printf("\nQt Creator Debugging Helper testing tool\n\n");
614
    printf("Running query protocol\n");
615
    qDumpObjectData440(1, 42, 0, 1, 0, 0, 0, 0);
616
617
618
    fputs(qDumpOutBuffer, stdout);
    fputc('\n', stdout);
    fputc('\n', stdout);
619
620
621
622
623

    const TypeDumpFunctionMap tdm = registerTypes();
    const TypeDumpFunctionMap::const_iterator cend = tdm.constEnd();

    if (argc < 2) {
624
        usage(argv[0], tdm);
625
        return 0;
626
    }
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
    // Parse args
    QStringList tests;
    for (int a = 1; a < argc; a++) {
        const char *arg = argv[a];
        if (arg[0] == '-') {
            switch (arg[1]) {
            case 'a':
                optTestAll = true;
                break;
            case 'u':
                optTestUninitialized = true;
                break;
            case 'v':
                optVerbose++;
                break;
            case 'e':
                optEmptyContainers = true;
                break;
            default:
                fprintf(stderr, "Invalid option %s\n", arg);
                usage(argv[0], tdm);
                return -1;
            }
        } else {
            tests.push_back(QLatin1String(arg));
        }
    }
    // Go
655
    int rc = 0;
656
    if (optTestAll) {
657
        for (TypeDumpFunctionMap::const_iterator it = tdm.constBegin(); it != cend; ++it) {
658
659
660
661
662
663
664
665
666
            const QString test = it.key();
            if (tests.contains(test)) {
                printf("\nSkipping: %s\n", qPrintable(test));
            } else {
                printf("\nTesting: %s\n", qPrintable(test));
                rc += (*it.value())();
                if (optTestUninitialized)
                    printf("Survived: %s\n", qPrintable(test));
            }
667
668
        }
    } else {
669
670
671
        foreach(const QString &test, tests) {
            printf("\nTesting: %s\n", qPrintable(test));
            const TypeDumpFunctionMap::const_iterator it = tdm.constFind(test);
672
673
            if (it == cend) {
                rc = -1;
674
                fprintf(stderr, "\nUnhandled type: %s\n", qPrintable(test));
675
676
677
            } else {
                rc = (*it.value())();
            }
678
        }
679
    }
680
    return rc;
681
}