OSDN Git Service

f65ab71a35bfcba3f1c654cf808bd04c445dac60
[qt-creator-jp/qt-creator-jp.git] / tests / manual / gdbdebugger / simple / simple_gdbtest_app.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 //#include <complex>
35
36 //template <typename T> class B;  B foo() {}
37
38 #include <QtCore/QDebug>
39 #include <QtCore/QDateTime>
40 #include <QtCore/QDir>
41 #include <QtCore/QHash>
42 #include <QtCore/QLibrary>
43 #include <QtCore/QLinkedList>
44 #include <QtCore/QList>
45 #include <QtCore/QMap>
46 #include <QtCore/QPointer>
47 #include <QtCore/QProcess>
48 #include <QtCore/QString>
49 #include <QtCore/QStringList>
50 #include <QtCore/QSettings>
51 #include <QtCore/QStack>
52 #include <QtCore/QThread>
53 #include <QtCore/QVariant>
54 #include <QtCore/QVector>
55 #include <QtCore/QUrl>
56 #if QT_VERSION >= 0x040500
57 #include <QtCore/QSharedPointer>
58 #endif
59
60 #include <QtGui/QApplication>
61 #include <QtGui/QAction>
62 #include <QtGui/QColor>
63 #include <QtGui/QFont>
64 #include <QtGui/QLabel>
65 //#include <QtGui/private/qfixed_p.h>
66 #include <QtGui/QPainter>
67 #include <QtGui/QPainterPath>
68 #include <QtGui/QRegion>
69 #include <QtGui/QStandardItemModel>
70 #include <QtGui/QTextCursor>
71 #include <QtGui/QTextDocument>
72
73 #include <QtScript/QScriptEngine>
74 #include <QtScript/QScriptValue>
75
76 #include <QtNetwork/QHostAddress>
77
78 #include <deque>
79 #include <iostream>
80 #include <map>
81 #include <list>
82 #include <set>
83 #include <stack>
84 #include <string>
85 #include <vector>
86
87 #define USE_PRIVATE 1
88 //#define USE_BOOST 1
89
90 #if USE_BOOST
91 #include <boost/optional.hpp>
92 #include <boost/shared_ptr.hpp>
93 #endif
94
95 #if USE_PRIVATE
96 #include <QtCore/private/qobject_p.h>
97 #endif
98
99 #if defined(__GNUC__) && !defined(__llvm__) && !defined(Q_OS_MAC)
100 #    define USE_GCC_EXT 1
101 #    undef __DEPRECATED
102 #    include <ext/hash_set>
103 #endif
104
105 #ifdef Q_OS_WIN
106 #include <windows.h>
107 #undef min
108 #undef max
109 #endif
110
111 #ifdef __SSE__
112 #include <xmmintrin.h>
113 #include <stddef.h>
114 #endif
115 Q_DECLARE_METATYPE(QHostAddress)
116 Q_DECLARE_METATYPE(QList<int>)
117 Q_DECLARE_METATYPE(QStringList)
118
119 typedef QMap<uint, QStringList> MyType;
120 #define COMMA ,
121 Q_DECLARE_METATYPE(QMap<uint COMMA QStringList>)
122
123 template <typename T> class Vector
124 {
125 public:
126     explicit Vector(int size) : m_size(size), m_data(new T[size]) {}
127     ~Vector() { delete [] m_data; }
128     //...
129 private:
130     int m_size;
131     T *m_data;
132 };
133
134
135 namespace nsX {
136 namespace nsY {
137 int z;
138 }
139 }
140
141 #if USE_PRIVATE
142
143 class DerivedObjectPrivate : public QObjectPrivate
144 {
145 public:
146     DerivedObjectPrivate()
147     {
148         m_extraX = 43;
149         m_extraY.append("xxx");
150         m_extraZ = 1;
151     }
152
153     int m_extraX;
154     QStringList m_extraY;
155     uint m_extraZ : 1;
156     bool m_extraA : 1;
157     bool m_extraB;
158 };
159
160 class DerivedObject : public QObject
161 {
162     Q_OBJECT
163
164 public:
165     DerivedObject()
166        : QObject(*new DerivedObjectPrivate, 0)
167     {}
168
169     Q_PROPERTY(int x READ x WRITE setX)
170     Q_PROPERTY(QStringList y READ y WRITE setY)
171     Q_PROPERTY(uint z READ z WRITE setZ)
172
173     int x() const;
174     void setX(int x);
175     QStringList y() const;
176     void setY(QStringList y);
177     uint z() const;
178     void setZ(uint z);
179
180 private:
181     Q_DECLARE_PRIVATE(DerivedObject)
182 };
183
184 int DerivedObject::x() const
185 {
186     Q_D(const DerivedObject);
187     return d->m_extraX;
188 }
189
190 void DerivedObject::setX(int x)
191 {
192     Q_D(DerivedObject);
193     d->m_extraX = x;
194     d->m_extraA = !d->m_extraA;
195     d->m_extraB = !d->m_extraB;
196 }
197
198 QStringList DerivedObject::y() const
199 {
200     Q_D(const DerivedObject);
201     return d->m_extraY;
202 }
203
204 void DerivedObject::setY(QStringList y)
205 {
206     Q_D(DerivedObject);
207     d->m_extraY = y;
208 }
209
210 uint DerivedObject::z() const
211 {
212     Q_D(const DerivedObject);
213     return d->m_extraZ;
214 }
215
216 void DerivedObject::setZ(uint z)
217 {
218     Q_D(DerivedObject);
219     d->m_extraZ = z;
220 }
221
222 #endif
223
224 struct S
225 {
226     uint x : 1;
227     uint y : 1;
228     bool c : 1;
229     bool b;
230     float f;
231     double d;
232     qreal q;
233     int i;
234 };
235
236 void testPrivate()
237 {
238     S s;
239     s.x = 1;
240 #if USE_PRIVATE
241     DerivedObject ob;
242     ob.setX(23);
243     ob.setX(25);
244     ob.setX(26);
245     ob.setX(63);
246     ob.setX(32);
247 #endif
248 }
249
250 namespace nsXY = nsX::nsY;
251
252 int qwert()
253 {
254     return nsXY::z;
255 }
256
257 uint qHash(const QMap<int, int> &)
258 {
259     return 0;
260 }
261
262 uint qHash(const double & f)
263 {
264     return int(f);
265 }
266
267
268 class Foo
269 {
270 public:
271     Foo(int i = 0)
272         : a(i), b(2)
273     {
274         int s = 1;
275         int t = 2;
276         b = 2 + s + t;
277         a += 1;
278         a += 1;
279         a += 1;
280         a += 1;
281         a += 1;
282         a += 1;
283         a += 1;
284         a += 1;
285         a += 1;
286         a += 1;
287         a += 1;
288         a += 1;
289         a += 1;
290         a += 1;
291         a += 1;
292     }
293
294     virtual ~Foo()
295     {
296         a = 5;
297     }
298
299     void doit()
300     {
301         static QObject ob;
302         m["1"] = "2";
303         h[&ob] = m.begin();
304
305         a += 1;
306         --b;
307         //s += 'x';
308     }
309
310
311     struct Bar {
312         Bar() : ob(0) {}
313         QObject *ob;
314     };
315
316 public:
317     int a, b;
318     char x[6];
319
320 private:
321     //QString s;
322     typedef QMap<QString, QString> Map;
323     Map m;
324     QHash<QObject *, Map::iterator> h;
325 };
326
327 class X : public Foo
328 {
329 public:
330     X() {
331     }
332 };
333
334 class XX : virtual public Foo
335 {
336 public:
337     XX() {
338     }
339 };
340
341 class Y : virtual public Foo
342 {
343 public:
344     Y() {
345     }
346 };
347
348 class D : public X, public Y
349 {
350     int diamond;
351 };
352
353 void testArray()
354 {
355 #if 1
356     X x;
357     XX xx;
358     D diamond;
359     Q_UNUSED(diamond);
360     Foo *f = &xx;
361     Q_UNUSED(f);
362     Foo ff;
363     Q_UNUSED(ff);
364     double d[3][3];
365     for (int i = 0; i != 3; ++i)
366         for (int j = 0; j != 3; ++j)
367             d[i][j] = i + j;
368     Q_UNUSED(d);
369 #endif
370
371 #if 1
372     char c[20];
373     c[0] = 'a';
374     c[1] = 'b';
375     c[2] = 'c';
376     c[3] = 'd';
377     Q_UNUSED(c);
378 #endif
379
380 #if 1
381     QString s[20];
382     s[0] = "a";
383     s[1] = "b";
384     s[2] = "c";
385     s[3] = "d";
386     Q_UNUSED(s);
387 #endif
388
389 #if 1
390     QByteArray b[20];
391     b[0] = "a";
392     b[1] = "b";
393     b[2] = "c";
394     b[3] = "d";
395     Q_UNUSED(b);
396 #endif
397
398 #if 1
399     Foo foo[10];
400     //for (int i = 0; i != sizeof(foo)/sizeof(foo[0]); ++i) {
401     for (int i = 0; i < 5; ++i) {
402         foo[i].a = i;
403         foo[i].doit();
404     }
405 #endif
406 }
407
408 #ifndef Q_CC_RVCT
409 struct TestAnonymous
410 {
411     union {
412         struct { int i; int b; };
413         struct { float f; };
414         double d;
415     };
416 };
417 #endif
418
419 void testPeekAndPoke3()
420 {
421     // Anonymous structs
422     {
423 #ifndef Q_CC_RVCT
424         union {
425             struct { int i; int b; };
426             struct { float f; };
427             double d;
428         } a = { { 42, 43 } };
429         a.i = 1; // Break here. Expand a. Step.
430         a.i = 2; // Change a.i in Locals view to 0. This changes f, d but expectedly not b. Step.
431         a.i = 3; // Continue.
432         Q_UNUSED(a);
433 #endif
434     }
435
436     // Complex watchers
437     {
438         struct S { int a; double b; } s[10];
439         for (int i = 0; i != 10; ++i) {
440             s[i].a = i;  // Break here. Expand s and s[0]. Step.
441             // Watcher Context: "Add New Watcher".
442             // Type    ['s[%d].a' % i for i in range(5)]
443             // Expand it, continue stepping. This should result in a list
444             // of five items containing the .a fields of s[0]..s[4].
445         }
446         Q_UNUSED(s);
447     }
448
449     // QImage display
450     {
451         QImage im(QSize(200, 200), QImage::Format_RGB32);
452         im.fill(QColor(200, 10, 30).rgba());
453         QPainter pain;
454         pain.begin(&im);
455         pain.setPen(QPen(Qt::black, 5.0, Qt::SolidLine, Qt::RoundCap));
456         pain.drawEllipse(20, 20, 160, 160); // Break here. Step.
457         // Toggle between "Normal" and "Displayed" in L&W Context Menu, entry "Display of Type QImage". Step.
458         pain.drawArc(70, 115, 60, 30, 200 * 16, 140 * 16);
459         pain.setBrush(Qt::black);
460         pain.drawEllipse(65, 70, 15, 15); // Step.
461         pain.drawEllipse(120, 70, 15, 15); // Step.
462         pain.end();
463     }
464
465 }
466
467
468 #ifndef Q_CC_RVCT
469 namespace { // anon
470
471 struct Something
472 {
473     Something() { a = b = 1; }
474
475     void foo()
476     {
477         a = 42;
478         b = 43;
479     }
480
481     int a, b;
482 };
483
484 } // anon
485 #endif
486
487
488 void testAnonymous()
489 {
490 #ifndef Q_CC_RVCT
491     TestAnonymous a;
492     a.i = 1;
493     a.i = 2;
494     a.i = 3;
495     Q_UNUSED(a);
496
497     Something s;
498     s.foo();
499     Q_UNUSED(s);
500 #endif
501 }
502
503 typedef void (*func_t)();
504 func_t testFunctionPointer()
505 {
506     func_t f1 = testAnonymous;
507     func_t f2 = testPeekAndPoke3;
508     func_t f3 = testPeekAndPoke3;
509     Q_UNUSED(f1);
510     Q_UNUSED(f2);
511     Q_UNUSED(f3);
512     return f1;
513 }
514
515 void testQByteArray()
516 {
517     QByteArray ba = "Hello";
518     ba += '"';
519     ba += "World";
520
521     const char *str1 = "\356";
522     const char *str2 = "\xee";
523     const char *str3 = "\\ee";
524     QByteArray buf1( str1 );
525     QByteArray buf2( str2 );
526     QByteArray buf3( str3 );
527
528     ba += char(0);
529     ba += 1;
530     ba += 2;
531 }
532
533 int testQByteArray2()
534 {
535     QByteArray ba;
536     for (int i = 256; --i >= 0; )
537         ba.append(char(i));
538     return ba.size();
539 }
540
541 static void throwit1()
542 {
543     throw 14;
544 }
545
546 static void throwit()
547 {
548     throwit1();
549 }
550
551 int testCatchThrow()
552 {
553     // Set a breakpoint on "throw" in the BreakWindow context menu
554     // before stepping further.
555     int gotit = 0;
556     try {
557         throwit();
558     } catch (int what) {
559         gotit = what;
560     }
561     return gotit;
562 }
563
564 void testQDate()
565 {
566     QDate date;
567     date = QDate::currentDate();
568     date = date.addDays(5);
569     date = date.addDays(5);
570     date = date.addDays(5);
571     date = date.addDays(5);
572 }
573
574 void testQTime()
575 {
576     QTime time;
577     time = QTime::currentTime();
578     time = time.addSecs(5);
579     time = time.addSecs(5);
580     time = time.addSecs(5);
581     time = time.addSecs(5);
582 }
583
584 void testQDateTime()
585 {
586     QDateTime date;
587     date = QDateTime::currentDateTime();
588     date = date.addSecs(5);
589     date = date.addSecs(5);
590     date = date.addSecs(5);
591     date = date.addSecs(5);
592 }
593
594 QFileInfo testQFileInfo()
595 {
596     QFileInfo fi("/tmp/t");
597     QString s = fi.absoluteFilePath();
598     s = fi.bundleName();
599     s = fi.bundleName();
600     s = fi.bundleName();
601
602     QFileInfo result("/tmp/t");
603     return result;
604 }
605
606 void testQFixed()
607 {
608 /*
609     QFixed f = QFixed::fromReal(4.2);
610     f += 1;
611     f += 1;
612     f *= -1;
613     f += 1;
614     f += 1;
615 */
616 }
617
618 QHash<int, float> testQHash()
619 {
620 #if 1
621     QHash<int, float> hgg0;
622     hgg0[11] = 11.0;
623     hgg0[22] = 22.0;
624     hgg0[22] = 22.0;
625     hgg0[22] = 22.0;
626     hgg0[22] = 22.0;
627     hgg0[22] = 22.0;
628     hgg0[22] = 22.0;
629
630 #endif
631
632 #if 1
633
634     QHash<QString, int> hgg1;
635     hgg1["22.0"] = 22.0;
636     hgg1["123.0"] = 22.0;
637     hgg1["111111ss111128.0"] = 28.0;
638     hgg1["11124.0"] = 22.0;
639     hgg1["1111125.0"] = 22.0;
640     hgg1["11111126.0"] = 22.0;
641     hgg1["111111127.0"] = 27.0;
642     hgg1["111111111128.0"] = 28.0;
643     hgg1["111111111111111111129.0"] = 29.0;
644
645     QHash<QByteArray, float> hgx1;
646     hgx1["22.0"] = 22.0;
647     hgx1["123.0"] = 22.0;
648     hgx1["111111ss111128.0"] = 28.0;
649     hgx1["11124.0"] = 22.0;
650     hgx1["1111125.0"] = 22.0;
651     hgx1["11111126.0"] = 22.0;
652     hgx1["111111127.0"] = 27.0;
653     hgx1["111111111128.0"] = 28.0;
654     hgx1["111111111111111111129.0"] = 29.0;
655 #endif
656 #if 1
657     QHash<int, QString> hgg2;
658     hgg2[22] = "22.0";
659
660     QHash<QString, Foo> hgg3;
661     hgg3["22.0"] = Foo(22);
662     hgg3["33.0"] = Foo(33);
663
664     QObject ob;
665     QHash<QString, QPointer<QObject> > hash;
666     hash.insert("Hallo", QPointer<QObject>(&ob));
667     hash.insert("Welt", QPointer<QObject>(&ob));
668     hash.insert(".", QPointer<QObject>(&ob));
669 #endif
670     QHash<int, float> result;
671     return result;
672 }
673
674 void testQImage()
675 {
676     // only works with Python dumper
677     QImage im(QSize(200, 200), QImage::Format_RGB32);
678     im.fill(QColor(200, 100, 130).rgba());
679     QPainter pain;
680     pain.begin(&im);
681     pain.drawLine(2, 2, 130, 130);
682     pain.drawLine(4, 2, 130, 140);
683     pain.drawRect(30, 30, 80, 80);
684     pain.end();
685 }
686
687 struct Function
688 {
689     Function(QByteArray var, QByteArray f, double min, double max)
690       : var(var), f(f), min(min), max(max) {}
691     QByteArray var;
692     QByteArray f;
693     double min;
694     double max;
695 };
696
697 void testFunction()
698 {
699     // In order to use this, switch on the 'qDump__Function' in gdbmacros.py
700     Function func("x", "sin(x)", 0, 1);
701     func.max = 10;
702     func.f = "cos(x)";
703     func.max = 4;
704     func.max = 5;
705     func.max = 6;
706     func.max = 7;
707     func.max = 8;
708 }
709
710 void testOutput()
711 {
712     qDebug() << "qDebug() 1";
713     qDebug() << "qDebug() 2";
714     qDebug() << "qDebug() 3";
715     qDebug() << "qDebug <foo & bar>";
716
717     std::cout << "std::cout @@ 1" << std::endl;
718     std::cout << "std::cout @@ 2\n";
719     std::cout << "std::cout @@ 3" << std::endl;
720     std::cout << "std::cout <foo & bar>\n";
721
722     std::cerr << "std::cerr 1\n";
723     std::cerr << "std::cerr 2\n";
724     std::cerr << "std::cerr 3\n";
725     std::cerr << "std::cerr <foo & bar>\n";
726 }
727
728 void testInput()
729 {
730 #if 0
731     // This works only when "Run in terminal" is selected
732     // in the Run Configuration.
733     int i;
734     std::cin >> i;
735     int j;
736     std::cin >> j;
737 #endif
738 }
739
740 void testQLinkedList()
741 {
742 #if 1
743     QLinkedList<int> li;
744     QLinkedList<uint> lu;
745
746     for (int i = 0; i != 3; ++i)
747         li.append(i);
748     li.append(102);
749
750
751     lu.append(102);
752     lu.append(102);
753     lu.append(102);
754
755     QLinkedList<Foo *> lpi;
756     lpi.append(new Foo(1));
757     lpi.append(0);
758     lpi.append(new Foo(3));
759
760     QLinkedList<qulonglong> l;
761     l.append(42);
762     l.append(43);
763     l.append(44);
764     l.append(45);
765
766     QLinkedList<Foo> f;
767     f.append(Foo(1));
768     f.append(Foo(2));
769 #endif
770     QLinkedList<std::string> v;
771     v.push_back("aa");
772     v.push_back("bb");
773     v.push_back("cc");
774     v.push_back("dd");
775  }
776
777 void testQLocale()
778 {
779     QLocale loc = QLocale::system();
780     //QString s = loc.name();
781     //QVariant v = loc;
782     QLocale::MeasurementSystem m = loc.measurementSystem();
783     Q_UNUSED(m);
784 }
785
786 void testQList()
787 {
788     QList<int> big;
789     for (int i = 0; i < 10000; ++i)
790         big.push_back(i);
791
792     QList<Foo> flist;
793     for (int i = 0; i < 100; ++i)
794         flist.push_back(i + 15);
795     flist.push_back(1000);
796     flist.push_back(1001);
797     flist.push_back(1002);
798 #if 1
799     QList<int> li;
800     QList<uint> lu;
801
802     for (int i = 0; i != 30; ++i) {
803         li.append(i);
804     }
805     li.append(101);
806     li.append(102);
807     li.append(102);
808     li.append(102);
809     li.append(102);
810     li.append(102);
811     li.append(102);
812     li.append(102);
813     li.append(102);
814     li.append(102);
815     li.append(102);
816     li.append(102);
817     li.append(102);
818     li.append(102);
819
820     QList<int *> lpi;
821     lpi.append(new int(1));
822     lpi.append(new int(2));
823     lpi.append(new int(3));
824
825
826     for (int i = 0; i != 3; ++i) {
827         lu.append(i);
828     }
829     lu.append(101);
830     lu.append(102);
831     lu.append(102);
832     lu.append(102);
833
834     QList<uint> i;
835     i.append(42);
836     i.append(43);
837     i.append(44);
838     i.append(45);
839
840     QList<ushort> ls;
841     ls.append(42);
842     ls.append(43);
843     ls.append(44);
844     ls.append(45);
845
846     QList<QChar> lc;
847     lc.append(QChar('a'));
848     lc.append(QChar('b'));
849     lc.append(QChar('c'));
850     lc.append(QChar('d'));
851
852     QList<qulonglong> l;
853     l.append(42);
854     l.append(43);
855     l.append(44);
856     l.append(45);
857
858     QList<Foo> f;
859     f.append(Foo(1));
860     f.append(Foo(2));
861
862     QList<std::string> v;
863     v.push_back("aa");
864     v.push_back("bb");
865     v.push_back("cc");
866     v.push_back("dd");
867 #endif
868  }
869
870 namespace A {
871 namespace B {
872
873 struct SomeType
874 {
875     SomeType(int a) : a(a) {}
876     int a;
877 };
878
879 } // namespace B
880 } // namespace A
881
882 void testQMap()
883 {
884 #if 0
885     QMap<uint, QStringList> ggl;
886     ggl[11] = QStringList() << "11";
887     ggl[22] = QStringList() << "22";
888
889     typedef QMap<uint, QStringList> T;
890     T ggt;
891     ggt[11] = QStringList() << "11";
892     ggt[22] = QStringList() << "22";
893 #endif
894
895 #if 0
896     QMap<uint, float> gg0;
897     gg0[11] = 11.0;
898     gg0[22] = 22.0;
899
900
901     QMap<QString, float> gg1;
902     gg1["22.0"] = 22.0;
903
904     QMap<int, QString> gg2;
905     gg2[22] = "22.0";
906
907     QMap<QString, Foo> gg3;
908     gg3["22.0"] = Foo(22);
909     gg3["33.0"] = Foo(33);
910
911     QObject ob;
912     QMap<QString, QPointer<QObject> > map;
913     map.insert("Hallo", QPointer<QObject>(&ob));
914     map.insert("Welt", QPointer<QObject>(&ob));
915     map.insert(".", QPointer<QObject>(&ob));
916 #endif
917
918 #if 1
919     QList<A::B::SomeType *> x;
920     x.append(new A::B::SomeType(1));
921     x.append(new A::B::SomeType(2));
922     x.append(new A::B::SomeType(3));
923     QMap<QString, QList<A::B::SomeType *> > mlt;
924     mlt["foo"] = x;
925     mlt["bar"] = x;
926     mlt["1"] = x;
927     mlt["2"] = x;
928 #endif
929 }
930
931 void testQMultiMap()
932 {
933     QMultiMap<uint, float> gg0;
934     gg0.insert(11, 11.0);
935     gg0.insert(22, 22.0);
936     gg0.insert(22, 33.0);
937     gg0.insert(22, 34.0);
938     gg0.insert(22, 35.0);
939     gg0.insert(22, 36.0);
940 #if 1
941     QMultiMap<QString, float> gg1;
942     gg1.insert("22.0", 22.0);
943
944     QMultiMap<int, QString> gg2;
945     gg2.insert(22, "22.0");
946
947     QMultiMap<QString, Foo> gg3;
948     gg3.insert("22.0", Foo(22));
949     gg3.insert("33.0", Foo(33));
950     gg3.insert("22.0", Foo(22));
951
952     QObject ob;
953     QMultiMap<QString, QPointer<QObject> > map;
954     map.insert("Hallo", QPointer<QObject>(&ob));
955     map.insert("Welt", QPointer<QObject>(&ob));
956     map.insert(".", QPointer<QObject>(&ob));
957     map.insert(".", QPointer<QObject>(&ob));
958 #endif
959 }
960
961 namespace Names {
962 namespace Bar {
963
964 struct Ui {
965     Ui() { w = 0; }
966     QWidget *w;
967 };
968
969 class TestObject : public QObject
970 {
971     Q_OBJECT
972
973 public:
974     TestObject(QObject *parent = 0)
975       : QObject(parent)
976     {
977         m_ui = new Ui;
978         m_ui->w = new QWidget;
979         Q_UNUSED(parent);
980     }
981
982     Q_PROPERTY(QString myProp1 READ myProp1 WRITE setMyProp1)
983     QString myProp1() const { return m_myProp1; }
984     Q_SLOT void setMyProp1(const QString &mt) { m_myProp1 = mt; }
985
986     Q_PROPERTY(QString myProp2 READ myProp2 WRITE setMyProp2)
987     QString myProp2() const { return m_myProp2; }
988     Q_SLOT void setMyProp2(const QString &mt) { m_myProp2 = mt; }
989
990 public:
991     Ui *m_ui;
992     QString m_myProp1;
993     QString m_myProp2;
994 };
995
996 } // namespace Bar
997 } // namespace Names
998
999 void testQObject(int &argc, char *argv[])
1000 {
1001     QApplication app(argc, argv);
1002     //QString longString = QString(10000, QLatin1Char('A'));
1003 #if 1
1004     Names::Bar::TestObject test;
1005     test.setMyProp1("HELLO");
1006     test.setMyProp2("WORLD");
1007     QString s = test.myProp1();
1008     s += test.myProp2();
1009     Q_UNUSED(s);
1010 #endif
1011
1012 #if 0
1013     QAction act("xxx", &app);
1014     QString t = act.text();
1015     t += "y";
1016     t += "y";
1017     t += "y";
1018     t += "y";
1019     t += "y";
1020 #endif
1021
1022 #if 1
1023     QWidget ob;
1024     ob.setObjectName("An Object");
1025     ob.setProperty("USER DEFINED 1", 44);
1026     ob.setProperty("USER DEFINED 2", QStringList() << "FOO" << "BAR");
1027     QObject ob1;
1028     ob1.setObjectName("Another Object");
1029
1030     QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
1031     QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
1032     //QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater()));
1033 #endif
1034
1035 #if 0
1036     QList<QObject *> obs;
1037     obs.append(&ob);
1038     obs.append(&ob1);
1039     obs.append(0);
1040     obs.append(&app);
1041     ob1.setObjectName("A Subobject");
1042 #endif
1043
1044 #if 1
1045     QString str = QString::fromUtf8("XXXXXXXXXXXXXXyyXXX ö");
1046     QLabel l(str);
1047     l.setObjectName("Some Label");
1048     l.show();
1049     app.exec();
1050 #endif
1051 }
1052
1053 class Sender : public QObject
1054 {
1055     Q_OBJECT
1056 public:
1057     Sender() { setObjectName("Sender"); }
1058     void doEmit() { emit aSignal(); }
1059 signals:
1060     void aSignal();
1061 };
1062
1063 class Receiver : public QObject
1064 {
1065     Q_OBJECT
1066 public:
1067     Receiver() { setObjectName("Receiver"); }
1068 public slots:
1069     void aSlot() {
1070         QObject *s = sender();
1071         if (s) {
1072             qDebug() << "SENDER: " << s;
1073         } else {
1074             qDebug() << "NO SENDER";
1075         }
1076     }
1077 };
1078
1079 void testSignalSlot(int &argc, char *argv[])
1080 {
1081     QApplication app(argc, argv);
1082     Sender sender;
1083     Receiver receiver;
1084     QObject::connect(&sender, SIGNAL(aSignal()), &receiver, SLOT(aSlot()));
1085     sender.doEmit();
1086 };
1087
1088
1089 void testQPixmap()
1090 {
1091     QImage im(QSize(200, 200), QImage::Format_RGB32);
1092     im.fill(QColor(200, 100, 130).rgba());
1093     QPainter pain;
1094     pain.begin(&im);
1095     pain.drawLine(2, 2, 130, 130);
1096     pain.end();
1097     QPixmap pm = QPixmap::fromImage(im);
1098     int i = 1;
1099     Q_UNUSED(i);
1100 }
1101
1102 void testQRegion()
1103 {
1104     // only works with Python dumper
1105     QRegion region;
1106     region += QRect(100, 100, 200, 200);
1107     region += QRect(300, 300, 400, 500);
1108     region += QRect(500, 500, 600, 600);
1109     region += QRect(500, 500, 600, 600);
1110     region += QRect(500, 500, 600, 600);
1111     region += QRect(500, 500, 600, 600);
1112 }
1113
1114
1115 void testPlugin()
1116 {
1117     QString dir = QDir::currentPath();
1118 #ifdef Q_OS_LINUX
1119     QLibrary lib(dir + "/libsimple_gdbtest_plugin.so");
1120 #endif
1121 #ifdef Q_OS_MAC
1122     dir = QFileInfo(dir + "/../..").canonicalPath();
1123     QLibrary lib(dir + "/libsimple_gdbtest_plugin.dylib");
1124 #endif
1125 #ifdef Q_OS_WIN
1126     QLibrary lib(dir + "/debug/simple_gdbtest_plugin.dll");
1127 #endif
1128 #ifdef Q_OS_SYMBIAN
1129     QLibrary lib(dir + "/libsimple_gdbtest_plugin.dll");
1130 #endif
1131     int (*foo)() = (int(*)()) lib.resolve("pluginTest");
1132     qDebug() << "library resolve: " << foo << lib.fileName();
1133     if (foo) {
1134         int res = foo();
1135         res += 1;
1136     } else {
1137         qDebug() << lib.errorString();
1138     }
1139 }
1140
1141 void testQSet()
1142 {
1143     QSet<int> hgg0;
1144     hgg0.insert(11);
1145     hgg0.insert(22);
1146
1147     QSet<QString> hgg1;
1148     hgg1.insert("22.0");
1149
1150     QObject ob;
1151     QSet<QPointer<QObject> > hash;
1152     QPointer<QObject> ptr(&ob);
1153     Q_UNUSED(ptr);
1154     //hash.insert(ptr);
1155     //hash.insert(ptr);
1156     //hash.insert(ptr);
1157 }
1158
1159 #if QT_VERSION >= 0x040500
1160 class EmployeeData : public QSharedData
1161 {
1162 public:
1163     EmployeeData() : id(-1) { name.clear(); }
1164     EmployeeData(const EmployeeData &other)
1165         : QSharedData(other), id(other.id), name(other.name) { }
1166     ~EmployeeData() { }
1167
1168     int id;
1169     QString name;
1170 };
1171
1172 class Employee
1173 {
1174 public:
1175     Employee() { d = new EmployeeData; }
1176     Employee(int id, QString name) {
1177         d = new EmployeeData;
1178         setId(id);
1179         setName(name);
1180     }
1181     Employee(const Employee &other)
1182           : d (other.d)
1183     {
1184     }
1185     void setId(int id) { d->id = id; }
1186     void setName(QString name) { d->name = name; }
1187
1188     int id() const { return d->id; }
1189     QString name() const { return d->name; }
1190
1191    private:
1192      QSharedDataPointer<EmployeeData> d;
1193 };
1194
1195
1196 void testQSharedPointer()
1197 {
1198     //Employee e1(1, "Herbert");
1199     //Employee e2 = e1;
1200 #if 0
1201     QSharedPointer<int> iptr(new int(43));
1202     QSharedPointer<int> iptr2 = iptr;
1203     QSharedPointer<int> iptr3 = iptr;
1204
1205     QSharedPointer<QString> ptr(new QString("hallo"));
1206     QSharedPointer<QString> ptr2 = ptr;
1207     QSharedPointer<QString> ptr3 = ptr;
1208
1209     QWeakPointer<int> wiptr(iptr);
1210     QWeakPointer<int> wiptr2 = wiptr;
1211     QWeakPointer<int> wiptr3 = wiptr;
1212
1213     QWeakPointer<QString> wptr(ptr);
1214     QWeakPointer<QString> wptr2 = wptr;
1215     QWeakPointer<QString> wptr3 = wptr;
1216 #endif
1217
1218     QSharedPointer<Foo> fptr(new Foo(1));
1219     QWeakPointer<Foo> wfptr(fptr);
1220     QWeakPointer<Foo> wfptr2 = wfptr;
1221     QWeakPointer<Foo> wfptr3 = wfptr;
1222 }
1223 #endif
1224
1225 void stringRefTest(const QString &refstring)
1226 {
1227     Q_UNUSED(refstring);
1228 }
1229
1230 void testStdDeque()
1231 {
1232     // This is not supposed to work with the compiled dumpers.
1233     std::deque<int *> plist1;
1234     plist1.push_back(new int(1));
1235     plist1.push_back(0);
1236     plist1.push_back(new int(2));
1237     plist1.pop_back();
1238     plist1.pop_front();
1239     plist1.pop_front();
1240
1241     std::deque<int> flist2;
1242     flist2.push_back(1);
1243     flist2.push_back(2);
1244
1245     std::deque<Foo *> plist;
1246     plist.push_back(new Foo(1));
1247     plist.push_back(new Foo(2));
1248
1249     std::deque<Foo> flist;
1250     flist.push_back(1);
1251     flist.push_front(2);
1252 }
1253
1254 void testStdHashSet()
1255 {
1256     // This is not supposed to work with the compiled dumpers.
1257 #if USE_GCC_EXT
1258     using namespace __gnu_cxx;
1259     hash_set<int> h;
1260     h.insert(1);
1261     h.insert(194);
1262     h.insert(2);
1263     h.insert(3);
1264     h.insert(4);
1265     h.insert(5);
1266 #endif
1267 }
1268
1269 std::list<int> testStdList()
1270 {
1271     // This is not supposed to work with the compiled dumpers.
1272     std::list<int> big;
1273     for (int i = 0; i < 10000; ++i)
1274         big.push_back(i);
1275
1276     std::list<Foo> flist;
1277     for (int i = 0; i < 100; ++i)
1278         flist.push_back(i + 15);
1279
1280 #if 1
1281     std::list<int *> plist1;
1282     plist1.push_back(new int(1));
1283     plist1.push_back(0);
1284     plist1.push_back(new int(2));
1285
1286     std::list<int> flist2;
1287     flist2.push_back(1);
1288     flist2.push_back(2);
1289     flist2.push_back(3);
1290     flist2.push_back(4);
1291
1292     flist2.push_back(1);
1293     flist2.push_back(2);
1294     flist2.push_back(3);
1295     flist2.push_back(4);
1296
1297     std::list<Foo *> plist;
1298     plist.push_back(new Foo(1));
1299     plist.push_back(0);
1300     plist.push_back(new Foo(2));
1301
1302
1303     foreach (Foo f, flist)
1304     {}
1305
1306     std::list<bool> vec;
1307     vec.push_back(true);
1308     vec.push_back(false);
1309 #endif
1310     std::list<int> result;
1311     return result;
1312 }
1313
1314 void testStdMap()
1315 {
1316     // This is not supposed to work with the compiled dumpers.
1317 #if 0
1318     std::map<QString, Foo> gg3;
1319     gg3["22.0"] = Foo(22);
1320     gg3["33.0"] = Foo(33);
1321     gg3["44.0"] = Foo(44);
1322
1323     std::map<const char *, Foo> m1;
1324     m1["22.0"] = Foo(22);
1325     m1["33.0"] = Foo(33);
1326     m1["44.0"] = Foo(44);
1327
1328     std::map<uint, uint> gg;
1329     gg[11] = 1;
1330     gg[22] = 2;
1331     gg[33] = 3;
1332     gg[44] = 4;
1333     gg[55] = 5;
1334
1335     std::pair<uint, QStringList> p = std::make_pair(3, QStringList() << "11");
1336     std::vector< std::pair<uint, QStringList> > v;
1337     v.push_back(p);
1338     v.push_back(p);
1339
1340     std::map<uint, QStringList> ggl;
1341     ggl[11] = QStringList() << "11";
1342     ggl[22] = QStringList() << "22";
1343     ggl[33] = QStringList() << "33";
1344     ggl[44] = QStringList() << "44";
1345     ggl[55] = QStringList() << "55";
1346
1347     typedef std::map<uint, QStringList> T;
1348     T ggt;
1349     ggt[11] = QStringList() << "11";
1350     ggt[22] = QStringList() << "22";
1351
1352     std::map<uint, float> gg0;
1353     gg0[11] = 11.0;
1354     gg0[22] = 22.0;
1355
1356
1357     std::map<QString, float> gg1;
1358     gg1["22.0"] = 22.0;
1359
1360     std::map<int, QString> gg2;
1361     gg2[22] = "22.0";
1362 #endif
1363
1364 #if 1
1365     QObject ob;
1366     std::map<QString, QPointer<QObject> > map;
1367     map["Hallo"] = QPointer<QObject>(&ob);
1368     map["Welt"] = QPointer<QObject>(&ob);
1369     map["."] = QPointer<QObject>(&ob);
1370 #endif
1371 }
1372
1373 std::set<int> testStdSet()
1374 {
1375     // This is not supposed to work with the compiled dumpers.
1376     std::set<int> hgg0;
1377     hgg0.insert(11);
1378     hgg0.insert(22);
1379     hgg0.insert(33);
1380 #if 1
1381     std::set<QString> hgg1;
1382     hgg1.insert("22.0");
1383
1384     QObject ob;
1385     std::set<QPointer<QObject> > hash;
1386     QPointer<QObject> ptr(&ob);
1387 #endif
1388     std::set<int> result;
1389     return result;
1390 }
1391
1392 std::stack<int> testStdStack()
1393 {
1394     // This is not supposed to work with the compiled dumpers.
1395     std::stack<int *> plist1;
1396     plist1.push(new int(1));
1397     plist1.push(0);
1398     plist1.push(new int(2));
1399     plist1.pop();
1400     plist1.pop();
1401     plist1.pop();
1402
1403     std::stack<int> flist2;
1404     flist2.push(1);
1405     flist2.push(2);
1406
1407     std::stack<Foo *> plist;
1408     plist.push(new Foo(1));
1409     plist.push(new Foo(2));
1410
1411     std::stack<Foo> flist;
1412     flist.push(1);
1413     flist.push(2);
1414
1415     std::stack<int> result;
1416     return result;
1417 }
1418
1419 std::string testStdString()
1420 {
1421     QString foo;
1422     std::string str;
1423     std::wstring wstr;
1424
1425     std::vector<std::string> v;
1426
1427     foo += "a";
1428     str += "b";
1429     wstr += wchar_t('e');
1430     foo += "c";
1431     str += "d";
1432     foo += "e";
1433     wstr += wchar_t('e');
1434     str += "e";
1435     foo += "a";
1436     str += "b";
1437     foo += "c";
1438     str += "d";
1439     str += "e";
1440     wstr += wchar_t('e');
1441     wstr += wchar_t('e');
1442     str += "e";
1443
1444     QList<std::string> l;
1445
1446     l.push_back(str);
1447     l.push_back(str);
1448     l.push_back(str);
1449     l.push_back(str);
1450
1451     v.push_back(str);
1452     v.push_back(str);
1453     v.push_back(str);
1454     v.push_back(str);
1455
1456     std::string result = "hi";
1457     return result;
1458 }
1459
1460 void testStdVector()
1461 {
1462     std::vector<int *> plist1;
1463     plist1.push_back(new int(1));
1464     plist1.push_back(0);
1465     plist1.push_back(new int(2));
1466
1467     std::vector<int> flist2;
1468     flist2.push_back(1);
1469     flist2.push_back(2);
1470     flist2.push_back(3);
1471     flist2.push_back(4);
1472
1473     flist2.push_back(1);
1474     flist2.push_back(2);
1475     flist2.push_back(3);
1476     flist2.push_back(4);
1477
1478     std::vector<Foo *> plist;
1479     plist.push_back(new Foo(1));
1480     plist.push_back(0);
1481     plist.push_back(new Foo(2));
1482
1483     std::vector<Foo> flist;
1484     flist.push_back(1);
1485     flist.push_back(2);
1486     flist.push_back(3);
1487     flist.push_back(4);
1488     //flist.takeFirst();
1489     //flist.takeFirst();
1490
1491     std::vector<bool> vec;
1492     vec.push_back(true);
1493     vec.push_back(false);
1494     vec.push_back(false);
1495     vec.push_back(true);
1496     vec.push_back(false);
1497 }
1498
1499 void testQStandardItemModel()
1500 {
1501     //char buf[100];
1502     //QString *s = static_cast<QString *>(static_cast<void *>(&(v.data_ptr().data.c)));
1503     //QString *t = (QString *)&(v.data_ptr());
1504
1505     QStandardItemModel m;
1506     QStandardItem *i1, *i2, *i11;
1507     m.appendRow(QList<QStandardItem *>()
1508          << (i1 = new QStandardItem("1")) << (new QStandardItem("a")) << (new QStandardItem("a2")));
1509     QModelIndex mi = i1->index();
1510     m.appendRow(QList<QStandardItem *>()
1511          << (i2 = new QStandardItem("2")) << (new QStandardItem("b")));
1512     i1->appendRow(QList<QStandardItem *>()
1513          << (i11 = new QStandardItem("11")) << (new QStandardItem("aa")));
1514     int i = 1;
1515     ++i;
1516     ++i;
1517 }
1518
1519 QStack<int> testQStack()
1520 {
1521     QVector<int> bigv;
1522     for (int i = 0; i < 10; ++i)
1523         bigv.append(i);
1524     QStack<int> big;
1525     for (int i = 0; i < 10; ++i)
1526         big.append(i);
1527     QStack<Foo *> plist;
1528     plist.append(new Foo(1));
1529     plist.append(0);
1530     plist.append(new Foo(2));
1531     QStack<Foo> flist;
1532     flist.append(1);
1533     flist.append(2);
1534     flist.append(3);
1535     flist.append(4);
1536     //flist.takeFirst();
1537     //flist.takeFirst();
1538     QStack<bool> vec;
1539     vec.append(true);
1540     vec.append(false);
1541     QStack<int> result;
1542     return result;
1543 }
1544
1545
1546 void testQUrl()
1547 {
1548     QUrl url(QString("http://www.nokia.com"));
1549     (void) url;
1550 }
1551
1552
1553 #ifdef FOP
1554
1555 int xxxx()
1556 {
1557 }
1558
1559 #else
1560
1561 void xxxx()
1562 {
1563 }
1564
1565
1566 #endif
1567
1568
1569 void testQString()
1570 {
1571     QImage im;
1572
1573     QString str = "Hello ";
1574     str += " big, ";
1575     str += " fat ";
1576     str += " World ";
1577     str += " World ";
1578     str += " World ";
1579     str += " World ";
1580     str += " World ";
1581 }
1582
1583 void testQString3()
1584 {
1585     QString str = "Hello ";
1586     str += " big, ";
1587     str += " fat ";
1588     str += " World ";
1589
1590     QString string("String Test");
1591     QString *pstring = new QString("Pointer String Test");
1592     stringRefTest(QString("Ref String Test"));
1593     string = "Hi";
1594     string += "Du";
1595     qDebug() << string;
1596     delete pstring;
1597 }
1598
1599 QStringList testQStringList()
1600 {
1601     QStringList l;
1602     l << "Hello ";
1603     l << " big, ";
1604     l << " fat ";
1605     l.takeFirst();
1606     l << " World ";
1607     QStringList result;
1608     return result;
1609 }
1610
1611 Foo testStruct()
1612 {
1613     Foo f(2);
1614     f.doit();
1615     f.doit();
1616     f.doit();
1617     Foo f1 = f;
1618     f1.doit();
1619     return f1;
1620 }
1621
1622 void testTypeFormats()
1623 {
1624     // These tests should result in properly displayed umlauts in the
1625     // Locals&Watchers view. It is only support on gdb with Python.
1626
1627     // Select UTF-8 in "Change Format for Type" in L&W context menu.
1628     const char *s = "aöa";
1629
1630     // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu.
1631     // Other: Select UCS-6 in "Change Format for Type" in L&W context menu.
1632     const wchar_t *w = L"aöa";
1633     QString u;
1634     if (sizeof(wchar_t) == 4)
1635         u = QString::fromUcs4((uint *)w);
1636     else
1637         u = QString::fromUtf16((ushort *)w);
1638
1639     // Make sure to undo "Change Format".
1640     int dummy = 1;
1641     Q_UNUSED(s);
1642     Q_UNUSED(w);
1643     Q_UNUSED(dummy);
1644 }
1645
1646
1647 class Thread : public QThread
1648 {
1649 public:
1650     Thread(int id) : m_id(id) {}
1651
1652     void run()
1653     {
1654         int j = 2;
1655         ++j;
1656         for (int i = 0; i != 100000; ++i) {
1657             //sleep(1);
1658             std::cerr << m_id;
1659         }
1660         if (m_id == 2) {
1661             ++j;
1662         }
1663         std::cerr << j;
1664     }
1665
1666 private:
1667     int m_id;
1668 };
1669
1670 void testQTextCursor()
1671 {
1672     //int argc = 0;
1673     //char *argv[] = { "xxx", 0 };
1674     //QApplication app(argc, argv);
1675     QTextDocument doc;
1676     doc.setPlainText("Hallo\nWorld");
1677     QTextCursor tc;
1678     tc = doc.find("all");
1679     int pos = tc.position();
1680     int anc = tc.anchor();
1681     Q_UNUSED(pos);
1682     Q_UNUSED(anc);
1683 }
1684
1685 void testQThread()
1686 {
1687     Thread thread1(1);
1688     Thread thread2(2);
1689     thread1.setObjectName("This is the first thread");
1690     thread2.setObjectName("This is another thread");
1691     thread1.start();
1692     thread2.start();
1693     thread1.wait();
1694     thread2.wait();
1695 }
1696
1697 void testQVariant1()
1698 {
1699     QVariant v;
1700     v = 1;
1701     v = 1.0;
1702     v = "string";
1703     v = QRect(100, 200, 300, 400);
1704     v = QRectF(100, 200, 300, 400);
1705     v = 1;
1706     //return v;
1707 }
1708
1709 QVariant testQVariant2()
1710 {
1711     QVariant value;
1712     QVariant::Type t = QVariant::String;
1713     value = QVariant(t, (void*)0);
1714     *(QString*)value.data() = QString("XXX");
1715
1716     int i = 1;
1717     ++i;
1718     ++i;
1719     ++i;
1720 #if 1
1721     QVariant var;
1722     var.setValue(1);
1723     var.setValue(2);
1724     var.setValue(3);
1725     var.setValue(QString("Hello"));
1726     var.setValue(QString("World"));
1727     var.setValue(QString("Hello"));
1728     var.setValue(QStringList() << "World");
1729     var.setValue(QStringList() << "World" << "Hello");
1730     var.setValue(QStringList() << "Hello" << "Hello");
1731     var.setValue(QStringList() << "World" << "Hello" << "Hello");
1732 #endif
1733 #if 1
1734     QVariant var3;
1735     QHostAddress ha("127.0.0.1");
1736     var.setValue(ha);
1737     var3 = var;
1738     var3 = var;
1739     var3 = var;
1740     var3 = var;
1741     QHostAddress ha1 = var.value<QHostAddress>();
1742     typedef QMap<uint, QStringList> MyType;
1743     MyType my;
1744     my[1] = (QStringList() << "Hello");
1745     my[3] = (QStringList() << "World");
1746     var.setValue(my);
1747     // FIXME: Known to break
1748     QString type = var.typeName();
1749     var.setValue(my);
1750     var.setValue(my);
1751     var.setValue(my);
1752     var.setValue(my);
1753 #endif
1754     QVariant result("sss");
1755     return result;
1756 }
1757
1758 QVariant testQVariant3()
1759 {
1760     QVariantList vl;
1761     vl.append(QVariant(1));
1762     vl.append(QVariant(2));
1763     vl.append(QVariant("Some String"));
1764     vl.append(QVariant(21));
1765     vl.append(QVariant(22));
1766     vl.append(QVariant("2Some String"));
1767
1768     QList<int> list;
1769     list << 1 << 2 << 3;
1770     QVariant variant = qVariantFromValue(list);
1771     list.clear();
1772     list = qVariantValue<QList<int> >(variant);
1773
1774     QVariant result("xxx");
1775     return result;
1776 }
1777
1778 void testQVector()
1779 {
1780     QVector<int> big(10000);
1781     big[1] = 1;
1782     big[2] = 2;
1783     big[3] = 3;
1784     big[4] = 4;
1785     big[5] = 5;
1786     big[9] = 9;
1787     big.append(1);
1788     big.append(1);
1789     big.append(1);
1790     big.append(1);
1791
1792     QVector<Foo *> plist;
1793     plist.append(new Foo(1));
1794     plist.append(0);
1795     plist.append(new Foo(2));
1796
1797     QVector<Foo> flist;
1798     flist.append(1);
1799     flist.append(2);
1800     flist.append(3);
1801     flist.append(4);
1802     //flist.takeFirst();
1803     //flist.takeFirst();
1804
1805     QVector<bool> vec;
1806     vec.append(true);
1807     vec.append(false);
1808 }
1809
1810 void testQVectorOfQList()
1811 {
1812     QVector<QList<int> > v;
1813     QVector<QList<int> > *pv = &v;
1814     v.append(QList<int>() << 1);
1815     v.append(QList<int>() << 2 << 3);
1816     Q_UNUSED(pv);
1817     //return v;
1818 }
1819
1820
1821 class Goo
1822 {
1823 public:
1824    Goo(const QString& str, const int n) :
1825            str_(str), n_(n)
1826    {
1827    }
1828 private:
1829    QString str_;
1830    int n_;
1831 };
1832
1833 typedef QList<Goo> GooList;
1834
1835 void testNoArgumentName(int i, int, int k)
1836 {
1837     // This is not supposed to work with the compiled dumpers.
1838     GooList list;
1839     list.append(Goo("Hello", 1));
1840     list.append(Goo("World", 2));
1841
1842     QList<Goo> list2;
1843     list2.append(Goo("Hello", 1));
1844     list2.append(Goo("World", 2));
1845
1846     ++i;
1847     ++k;
1848 }
1849
1850 void foo() {}
1851 void foo(int) {}
1852 void foo(QList<int>) {}
1853 void foo(QList<QVector<int> >) {}
1854 void foo(QList<QVector<int> *>) {}
1855 void foo(QList<QVector<int *> *>) {}
1856
1857 template <class T>
1858 void foo(QList<QVector<T> *>) {}
1859
1860
1861 namespace somespace {
1862
1863 class MyBase : public QObject
1864 {
1865 public:
1866     MyBase() {}
1867     virtual void doit(int i)
1868     {
1869        n = i;
1870     }
1871 protected:
1872     int n;
1873 };
1874
1875 namespace nested {
1876
1877 class MyFoo : public MyBase
1878 {
1879 public:
1880     MyFoo() {}
1881     virtual void doit(int i)
1882     {
1883        n = i;
1884     }
1885 protected:
1886     int n;
1887 };
1888
1889 class MyBar : public MyFoo
1890 {
1891 public:
1892     virtual void doit(int i)
1893     {
1894        n = i + 1;
1895     }
1896 };
1897
1898 namespace {
1899
1900 class MyAnon : public MyBar
1901 {
1902 public:
1903     virtual void doit(int i)
1904     {
1905        n = i + 3;
1906     }
1907 };
1908
1909 namespace baz {
1910
1911 class MyBaz : public MyAnon
1912 {
1913 public:
1914     virtual void doit(int i)
1915     {
1916        n = i + 5;
1917     }
1918 };
1919
1920 } // namespace baz
1921
1922 } // namespace anon
1923
1924
1925 } // namespace nested
1926 } // namespace somespace
1927
1928 void testNamespace()
1929 {
1930     using namespace somespace;
1931     using namespace nested;
1932     MyFoo foo;
1933     MyBar bar;
1934     MyAnon anon;
1935     baz::MyBaz baz;
1936     baz.doit(1);
1937     anon.doit(1);
1938     foo.doit(1);
1939     bar.doit(1);
1940     bar.doit(1);
1941     bar.doit(1);
1942     bar.doit(1);
1943     bar.doit(1);
1944     bar.doit(1);
1945     bar.doit(1);
1946 }
1947
1948 void testHidden()
1949 {
1950     int  n = 1;
1951     n = 2;
1952     n = 3;
1953     n = 4;
1954     n = 4;
1955     n = 5;
1956     n = 6;
1957     n = 7;
1958     n = 8;
1959     {
1960         QString n = "2";
1961         n = "3";
1962         n = "4";
1963         {
1964             double n = 3.5;
1965             ++n;
1966             ++n;
1967         }
1968         n = "3";
1969         n = "4";
1970     }
1971     ++n;
1972     ++n;
1973 }
1974
1975 void testObject1()
1976 {
1977     QObject parent;
1978     parent.setObjectName("A Parent");
1979     QObject child(&parent);
1980     child.setObjectName("A Child");
1981     QObject::connect(&child, SIGNAL(destroyed()), qApp, SLOT(quit()));
1982     QObject::disconnect(&child, SIGNAL(destroyed()), qApp, SLOT(quit()));
1983     child.setObjectName("A renamed Child");
1984 }
1985
1986 void testVector1()
1987 {
1988     std::vector<std::list<int> *> vector;
1989     std::list<int> list;
1990     vector.push_back(new std::list<int>(list));
1991     vector.push_back(0);
1992     list.push_back(45);
1993     vector.push_back(new std::list<int>(list));
1994     vector.push_back(0);
1995 }
1996
1997 void testQHash1()
1998 {
1999     QHash<QString, QList<int> > hash;
2000     hash.insert("Hallo", QList<int>());
2001     hash.insert("Welt", QList<int>() << 1);
2002     hash.insert("!", QList<int>() << 1 << 2);
2003     hash.insert("!", QList<int>() << 1 << 2);
2004 }
2005
2006 void testPointer()
2007 {
2008     Foo *f = new Foo();
2009     Q_UNUSED(f);
2010     int i = 0;
2011     ++i;
2012     ++i;
2013     ++i;
2014 }
2015
2016 class Z : public QObject
2017 {
2018 public:
2019     Z() {
2020         f = new Foo();
2021         i = 0;
2022         i = 1;
2023         i = 2;
2024         i = 3;
2025     }
2026     int i;
2027     Foo *f;
2028 };
2029
2030 void testMemoryView()
2031 {
2032     int a[20];
2033     for (int i = 0; i != 20; ++i)
2034         a[i] = i;
2035 }
2036
2037 void testUninitialized()
2038 {
2039     QString s;
2040     QStringList sl;
2041     QMap<int, int> mii;
2042     QMap<QString, QString> mss;
2043     QHash<int, int> hii;
2044     QHash<QString, QString> hss;
2045     QList<int> li;
2046     QVector<int> vi;
2047     QStack<int> si;
2048
2049     std::string ss;
2050     std::map<int, int> smii;
2051     std::map<std::string, std::string> smss;
2052     std::list<int> sli;
2053     std::list<std::string> ssl;
2054     std::vector<int> svi;
2055     std::stack<int> ssi;
2056 }
2057
2058 void testEndlessRecursion()
2059 {
2060     testEndlessRecursion();
2061 }
2062
2063 int testEndlessLoop()
2064 {
2065     qlonglong a = 1;
2066     // gdb:
2067     // Breakpoint at "while" will stop only once
2068     // Hitting "Pause" button might show backtrace of different thread
2069     while (a > 0)
2070         ++a;
2071     return a;
2072 }
2073
2074 QString fooxx()
2075 {
2076     return "bababa";
2077 }
2078
2079 int testReference()
2080 {
2081     QString a = "hello";
2082     const QString &b = fooxx();
2083     const QString c = "world";
2084     return a.size() + b.size() + c.size();
2085 }
2086
2087 struct Color
2088 {
2089     int r,g,b,a;
2090     Color() { r = 1, g = 2, b = 3, a = 4; }
2091 };
2092
2093 void testColor()
2094 {
2095     Color c;
2096     c.r = 5;
2097 }
2098
2099 int fooii()
2100 {
2101     return 3;
2102 }
2103
2104 typedef QVector<Foo> FooVector;
2105
2106 FooVector fooVector()
2107 {
2108     FooVector f;
2109     f.append(Foo(2));
2110     fprintf(stderr, "xxx\n");
2111     f.append(Foo(3));
2112     f.append(Foo(4));
2113     for (int i = 0; i < 1000; ++i)
2114         f.append(Foo(i));
2115     return f;
2116 }
2117
2118 namespace ns {
2119     typedef unsigned long long vl;
2120     typedef vl verylong;
2121 }
2122
2123 void testTypedef()
2124 {
2125     typedef quint32 myType1;
2126     typedef unsigned int myType2;
2127     myType1 t1 = 0;
2128     myType2 t2 = 0;
2129     ns::vl j = 1000;
2130     ns::verylong k = 1000;
2131
2132     ++j;
2133     ++k;
2134     ++t1;
2135     ++t2;
2136 }
2137
2138 void testConditional(const QString &str)
2139 {
2140     //
2141     QString res = str;
2142     res += "x";
2143     res += "x";
2144     res += "x";
2145 }
2146
2147 void testChar()
2148 {
2149     char s[5];
2150     s[0] = 0;
2151     strcat(s,"\""); // add a quote
2152     strcat(s,"\""); // add a quote
2153     strcat(s,"\""); // add a quote
2154     strcat(s,"\""); // add a quote
2155 }
2156
2157 struct Tx
2158 {
2159     Tx() { data = new char[20](); data[0] = '1'; }
2160
2161     char *GetStringPtr() const
2162     {
2163         return data;
2164     }
2165
2166     char *data;
2167 };
2168
2169 struct Ty
2170 {
2171     void doit()
2172     {
2173         int i = 1;
2174         i = 2;
2175         i = 2;
2176         i = 2;
2177         i = 2;
2178     }
2179
2180     Tx m_buffer;
2181 };
2182
2183 void testStuff()
2184 {
2185     using namespace std;
2186     typedef map<string, list<string> > map_t;
2187     map_t m;
2188     m["one"].push_back("a");
2189     m["one"].push_back("b");
2190     m["one"].push_back("c");
2191     m["two"].push_back("1");
2192     m["two"].push_back("2");
2193     m["two"].push_back("3");
2194     map_t::const_iterator i = m.begin();
2195
2196     vector<int> vec;
2197     vec.push_back(1);
2198     vec.push_back(2);
2199     pair<vector<int>, vector<int> > a(pair<vector<int>,vector<int> >(vec, vec));
2200
2201     i++;
2202 }
2203
2204 void testStuff4()
2205 {
2206     Ty x;
2207     x.doit();
2208     char *s = x.m_buffer.GetStringPtr();
2209     Q_UNUSED(s);
2210 }
2211
2212 void testStuff3()
2213 {
2214     typedef unsigned char byte;
2215     byte f = '2';
2216     Q_UNUSED(f);
2217     testConditional("foo");
2218     testConditional(fooxx());
2219     testConditional("bar");
2220     testConditional("zzz");
2221     Foo *f1 = new Foo(1);
2222     X *x = new X();
2223     Foo *f2 = x;
2224     XX *xx = new XX();
2225     Foo *f3 = xx;
2226     Y *y = new Y();
2227     Foo *f4 = y;
2228     //Foo *f5 = new D();
2229     qDebug() << f1 << f2 << f3 << f4;
2230 }
2231
2232 void testStuff2()
2233 {
2234     QList<QList<int> > list1;
2235     QList<QList<int> > list2;
2236     list1.append(QList<int>() << 1);
2237     list2.append(QList<int>() << 2);
2238     for (int i = 0; i < list1.size(); ++i) {
2239         for (int j = 0; j < list1.at(i).size(); ++j) {
2240             for (int k = i; k < list1.size(); ++k) {
2241                 for (int l = j; l < list1.at(k).size(); ++l) {
2242                     qDebug() << list1.at(i).at(j)+list2.at(k).at(l);
2243                 }
2244             }
2245         }
2246     }
2247
2248     // special char* support only with Python.
2249     typedef unsigned short wchar;
2250     wchar *str = new wchar[10];
2251     str[2] = 0;
2252     str[1] = 'B';
2253     str[0] = 'A';
2254     str[0] = 'A';
2255     str[0] = 'A';
2256     str[0] = 'A';
2257     QString foo = "foo";
2258     wchar *f = (wchar*)foo.utf16();
2259     Q_UNUSED(f);
2260     str[0] = 'A';
2261     str[0] = 'A';
2262     str[0] = 'A';
2263 }
2264
2265 void testPassByReferenceHelper(Foo &f)
2266 {
2267     ++f.a;
2268 }
2269
2270 void testPassByReference()
2271 {
2272     Foo f(12);
2273     testPassByReferenceHelper(f);
2274 }
2275
2276 void testWCout()
2277 {
2278     using namespace std;
2279     wstring x = L"xxxxx";
2280     wstring::iterator i = x.begin();
2281     while (i != x.end()) {
2282         wcout << *i;
2283         i++;
2284     }
2285     wcout.flush();
2286     string y = "yyyyy";
2287     string::iterator j = y.begin();
2288     while (j != y.end()) {
2289         cout << *j;
2290         j++;
2291     }
2292     cout.flush();
2293 };
2294
2295 void testWCout0()
2296 {
2297     // Mixing cout and wcout does not work with gcc.
2298     // See http://gcc.gnu.org/ml/gcc-bugs/2006-05/msg01193.html
2299     // which also says "you can obtain something close to your
2300     // expectations by calling std::ios::sync_with_stdio(false);
2301     // at the beginning of your program."
2302
2303     using namespace std;
2304     //std::ios::sync_with_stdio(false);
2305     wcout << L"WWWWWW" << endl;
2306     wcerr << L"YYYYYY" << endl;
2307     cout << "CCCCCC" << endl;
2308     cerr << "EEEEEE" << endl;
2309     wcout << L"WWWWWW" << endl;
2310     wcerr << L"YYYYYY" << endl;
2311     cout << "CCCCCC" << endl;
2312     cerr << "EEEEEE" << endl;
2313     wcout << L"WWWWWW" << endl;
2314     wcerr << L"YYYYYY" << endl;
2315     cout << "CCCCCC" << endl;
2316     cerr << "EEEEEE" << endl;
2317 }
2318
2319 void testSSE()
2320 {
2321 #ifdef __SSE__
2322     float a[4];
2323     float b[4];
2324     int i;
2325     for (i = 0; i < 4; i++) {
2326         a[i] = 2 * i;
2327         b[i] = 2 * i;
2328     }
2329     __m128 sseA, sseB;
2330     sseA = _mm_loadu_ps(a);
2331     sseB = _mm_loadu_ps(b);
2332     ++i;
2333 #endif
2334 }
2335
2336 void testQSettings()
2337 {
2338     // Note: Construct a QCoreApplication first.
2339     QSettings settings("/tmp/test.ini", QSettings::IniFormat);
2340     QVariant value = settings.value("item1","").toString();
2341     int x = 1;
2342     Q_UNUSED(x);
2343 }
2344
2345 void testQScriptValue(int argc, char *argv[])
2346 {
2347     QCoreApplication app(argc, argv);
2348     QScriptEngine engine;
2349     QDateTime date = QDateTime::currentDateTime();
2350     QScriptValue s;
2351     s = QScriptValue(33);
2352     int x = s.toInt32();
2353
2354     s = QScriptValue(QString("34"));
2355     QString x1 = s.toString();
2356
2357     s = engine.newVariant(QVariant(43));
2358     QVariant v = s.toVariant();
2359
2360     s = engine.newVariant(QVariant(43.0));
2361     s = engine.newVariant(QVariant(QString("sss")));
2362     s = engine.newDate(date);
2363     x = s.toInt32();
2364     bool xx = s.isDate();
2365     Q_UNUSED(xx);
2366     date = s.toDateTime();
2367     s.setProperty("a", QScriptValue());
2368     QScriptValue d = s.data();
2369 }
2370
2371 void testBoostOptional()
2372 {
2373 #if USE_BOOST
2374     boost::optional<int> i;
2375     i = 1;
2376     boost::optional<QStringList> sl;
2377     sl = (QStringList() << "xxx" << "yyy");
2378     sl.get().append("zzz");
2379     i = 3;
2380     i = 4;
2381     i = 5;
2382 #endif
2383 }
2384
2385 void testBoostSharedPtr()
2386 {
2387 #if USE_BOOST
2388     QSharedPointer<int> qs;
2389     QSharedPointer<int> qi(new int(43));
2390     QSharedPointer<int> qj = qi;
2391
2392     boost::shared_ptr<int> s;
2393     boost::shared_ptr<int> i(new int(43));
2394     boost::shared_ptr<int> j = i;
2395     boost::shared_ptr<QStringList> sl(new QStringList);
2396     int k = 2;
2397     ++k;
2398 #endif
2399 }
2400
2401 void testFork()
2402 {
2403     QProcess proc;
2404     proc.start("/bin/ls");
2405     proc.waitForFinished();
2406     QByteArray ba = proc.readAllStandardError();
2407     ba.append('x');
2408     ba.append('x');
2409 }
2410
2411 int main(int argc, char *argv[])
2412 {
2413     testPrivate();
2414     testMemoryView();
2415     //testQSettings();
2416     //testWCout0();
2417     //testWCout();
2418     testSSE();
2419     testQLocale();
2420     testColor();
2421     testQRegion();
2422     testTypedef();
2423     testChar();
2424     testStuff();
2425     testPeekAndPoke3();
2426     testFunctionPointer();
2427     testAnonymous();
2428     testReference();
2429     //testEndlessLoop();
2430     //testEndlessRecursion();
2431     testQStack();
2432     testUninitialized();
2433     testPointer();
2434     testQDate();
2435     testQDateTime();
2436     testQTime();
2437     testQFileInfo();
2438     testQFixed();
2439     testObject1();
2440     testVector1();
2441     testQHash1();
2442     testSignalSlot(argc, argv);
2443
2444     QString hallo = "hallo\nwelt";
2445     QStringList list;
2446     list << "aaa" << "bbb" << "cc";
2447
2448     QList<const char *> list2;
2449     list2 << "foo";
2450     list2 << "bar";
2451     list2 << 0;
2452     list2 << "baz";
2453     list2 << 0;
2454
2455     testQStandardItemModel();
2456     testFunction();
2457     testQImage();
2458     testNoArgumentName(1, 2, 3);
2459     testQTextCursor();
2460     testInput();
2461     testOutput();
2462     testHidden();
2463     testArray();
2464     testCatchThrow();
2465     testQByteArray();
2466     testQByteArray2();
2467
2468     testStdDeque();
2469     testStdList();
2470     testStdHashSet();
2471     testStdMap();
2472     testStdSet();
2473     testStdStack();
2474     testStdString();
2475     testStdVector();
2476     testTypeFormats();
2477
2478     testPassByReference();
2479     testPlugin();
2480     testQList();
2481     testQLinkedList();
2482     testNamespace();
2483     //return 0;
2484     testQHash();
2485     testQImage();
2486     testQMap();
2487     testQMultiMap();
2488     testQString();
2489     testQUrl();
2490     testQSet();
2491 #    if QT_VERSION >= 0x040500
2492     testQSharedPointer();
2493 #    endif
2494     testQStringList();
2495     testQScriptValue(argc, argv);
2496     testStruct();
2497     //testQThread();
2498     testQVariant1();
2499     testQVariant2();
2500     testQVariant3();
2501     testQVector();
2502     testQVectorOfQList();
2503
2504     testBoostOptional();
2505     testBoostSharedPtr();
2506
2507     testFork();
2508
2509     testQObject(argc, argv);
2510
2511     //QColor color(255,128,10);
2512     //QFont font;
2513     return 0;
2514 }
2515
2516 QT_BEGIN_NAMESPACE
2517 QT_END_NAMESPACE
2518
2519 #include "simple_gdbtest_app.moc"