1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
36 //template <typename T> class B; B foo() {}
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>
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>
73 #include <QtScript/QScriptEngine>
74 #include <QtScript/QScriptValue>
76 #include <QtNetwork/QHostAddress>
91 #include <boost/optional.hpp>
92 #include <boost/shared_ptr.hpp>
96 #include <QtCore/private/qobject_p.h>
99 #if defined(__GNUC__) && !defined(__llvm__) && !defined(Q_OS_MAC)
100 # define USE_GCC_EXT 1
102 # include <ext/hash_set>
112 #include <xmmintrin.h>
115 Q_DECLARE_METATYPE(QHostAddress)
116 Q_DECLARE_METATYPE(QList<int>)
117 Q_DECLARE_METATYPE(QStringList)
119 typedef QMap<uint, QStringList> MyType;
121 Q_DECLARE_METATYPE(QMap<uint COMMA QStringList>)
123 template <typename T> class Vector
126 explicit Vector(int size) : m_size(size), m_data(new T[size]) {}
127 ~Vector() { delete [] m_data; }
143 class DerivedObjectPrivate : public QObjectPrivate
146 DerivedObjectPrivate()
149 m_extraY.append("xxx");
154 QStringList m_extraY;
160 class DerivedObject : public QObject
166 : QObject(*new DerivedObjectPrivate, 0)
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)
175 QStringList y() const;
176 void setY(QStringList y);
181 Q_DECLARE_PRIVATE(DerivedObject)
184 int DerivedObject::x() const
186 Q_D(const DerivedObject);
190 void DerivedObject::setX(int x)
194 d->m_extraA = !d->m_extraA;
195 d->m_extraB = !d->m_extraB;
198 QStringList DerivedObject::y() const
200 Q_D(const DerivedObject);
204 void DerivedObject::setY(QStringList y)
210 uint DerivedObject::z() const
212 Q_D(const DerivedObject);
216 void DerivedObject::setZ(uint z)
250 namespace nsXY = nsX::nsY;
257 uint qHash(const QMap<int, int> &)
262 uint qHash(const double & f)
322 typedef QMap<QString, QString> Map;
324 QHash<QObject *, Map::iterator> h;
334 class XX : virtual public Foo
341 class Y : virtual public Foo
348 class D : public X, public Y
365 for (int i = 0; i != 3; ++i)
366 for (int j = 0; j != 3; ++j)
400 //for (int i = 0; i != sizeof(foo)/sizeof(foo[0]); ++i) {
401 for (int i = 0; i < 5; ++i) {
412 struct { int i; int b; };
419 void testPeekAndPoke3()
425 struct { int i; int b; };
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.
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].
451 QImage im(QSize(200, 200), QImage::Format_RGB32);
452 im.fill(QColor(200, 10, 30).rgba());
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.
473 Something() { a = b = 1; }
503 typedef void (*func_t)();
504 func_t testFunctionPointer()
506 func_t f1 = testAnonymous;
507 func_t f2 = testPeekAndPoke3;
508 func_t f3 = testPeekAndPoke3;
515 void testQByteArray()
517 QByteArray ba = "Hello";
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 );
533 int testQByteArray2()
536 for (int i = 256; --i >= 0; )
541 static void throwit1()
546 static void throwit()
553 // Set a breakpoint on "throw" in the BreakWindow context menu
554 // before stepping further.
567 date = QDate::currentDate();
568 date = date.addDays(5);
569 date = date.addDays(5);
570 date = date.addDays(5);
571 date = date.addDays(5);
577 time = QTime::currentTime();
578 time = time.addSecs(5);
579 time = time.addSecs(5);
580 time = time.addSecs(5);
581 time = time.addSecs(5);
587 date = QDateTime::currentDateTime();
588 date = date.addSecs(5);
589 date = date.addSecs(5);
590 date = date.addSecs(5);
591 date = date.addSecs(5);
594 QFileInfo testQFileInfo()
596 QFileInfo fi("/tmp/t");
597 QString s = fi.absoluteFilePath();
602 QFileInfo result("/tmp/t");
609 QFixed f = QFixed::fromReal(4.2);
618 QHash<int, float> testQHash()
621 QHash<int, float> hgg0;
634 QHash<QString, int> hgg1;
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;
645 QHash<QByteArray, float> hgx1;
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;
657 QHash<int, QString> hgg2;
660 QHash<QString, Foo> hgg3;
661 hgg3["22.0"] = Foo(22);
662 hgg3["33.0"] = Foo(33);
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));
670 QHash<int, float> result;
676 // only works with Python dumper
677 QImage im(QSize(200, 200), QImage::Format_RGB32);
678 im.fill(QColor(200, 100, 130).rgba());
681 pain.drawLine(2, 2, 130, 130);
682 pain.drawLine(4, 2, 130, 140);
683 pain.drawRect(30, 30, 80, 80);
689 Function(QByteArray var, QByteArray f, double min, double max)
690 : var(var), f(f), min(min), max(max) {}
699 // In order to use this, switch on the 'qDump__Function' in gdbmacros.py
700 Function func("x", "sin(x)", 0, 1);
712 qDebug() << "qDebug() 1";
713 qDebug() << "qDebug() 2";
714 qDebug() << "qDebug() 3";
715 qDebug() << "qDebug <foo & bar>";
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";
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";
731 // This works only when "Run in terminal" is selected
732 // in the Run Configuration.
740 void testQLinkedList()
744 QLinkedList<uint> lu;
746 for (int i = 0; i != 3; ++i)
755 QLinkedList<Foo *> lpi;
756 lpi.append(new Foo(1));
758 lpi.append(new Foo(3));
760 QLinkedList<qulonglong> l;
770 QLinkedList<std::string> v;
779 QLocale loc = QLocale::system();
780 //QString s = loc.name();
782 QLocale::MeasurementSystem m = loc.measurementSystem();
789 for (int i = 0; i < 10000; ++i)
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);
802 for (int i = 0; i != 30; ++i) {
821 lpi.append(new int(1));
822 lpi.append(new int(2));
823 lpi.append(new int(3));
826 for (int i = 0; i != 3; ++i) {
847 lc.append(QChar('a'));
848 lc.append(QChar('b'));
849 lc.append(QChar('c'));
850 lc.append(QChar('d'));
862 QList<std::string> v;
875 SomeType(int a) : a(a) {}
885 QMap<uint, QStringList> ggl;
886 ggl[11] = QStringList() << "11";
887 ggl[22] = QStringList() << "22";
889 typedef QMap<uint, QStringList> T;
891 ggt[11] = QStringList() << "11";
892 ggt[22] = QStringList() << "22";
896 QMap<uint, float> gg0;
901 QMap<QString, float> gg1;
904 QMap<int, QString> gg2;
907 QMap<QString, Foo> gg3;
908 gg3["22.0"] = Foo(22);
909 gg3["33.0"] = Foo(33);
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));
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;
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);
941 QMultiMap<QString, float> gg1;
942 gg1.insert("22.0", 22.0);
944 QMultiMap<int, QString> gg2;
945 gg2.insert(22, "22.0");
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));
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));
969 class TestObject : public QObject
974 TestObject(QObject *parent = 0)
978 m_ui->w = new QWidget;
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; }
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; }
999 void testQObject(int &argc, char *argv[])
1001 QApplication app(argc, argv);
1002 //QString longString = QString(10000, QLatin1Char('A'));
1004 Names::Bar::TestObject test;
1005 test.setMyProp1("HELLO");
1006 test.setMyProp2("WORLD");
1007 QString s = test.myProp1();
1008 s += test.myProp2();
1013 QAction act("xxx", &app);
1014 QString t = act.text();
1024 ob.setObjectName("An Object");
1025 ob.setProperty("USER DEFINED 1", 44);
1026 ob.setProperty("USER DEFINED 2", QStringList() << "FOO" << "BAR");
1028 ob1.setObjectName("Another Object");
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()));
1036 QList<QObject *> obs;
1041 ob1.setObjectName("A Subobject");
1045 QString str = QString::fromUtf8("XXXXXXXXXXXXXXyyXXX ö");
1047 l.setObjectName("Some Label");
1053 class Sender : public QObject
1057 Sender() { setObjectName("Sender"); }
1058 void doEmit() { emit aSignal(); }
1063 class Receiver : public QObject
1067 Receiver() { setObjectName("Receiver"); }
1070 QObject *s = sender();
1072 qDebug() << "SENDER: " << s;
1074 qDebug() << "NO SENDER";
1079 void testSignalSlot(int &argc, char *argv[])
1081 QApplication app(argc, argv);
1084 QObject::connect(&sender, SIGNAL(aSignal()), &receiver, SLOT(aSlot()));
1091 QImage im(QSize(200, 200), QImage::Format_RGB32);
1092 im.fill(QColor(200, 100, 130).rgba());
1095 pain.drawLine(2, 2, 130, 130);
1097 QPixmap pm = QPixmap::fromImage(im);
1104 // only works with Python dumper
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);
1117 QString dir = QDir::currentPath();
1119 QLibrary lib(dir + "/libsimple_gdbtest_plugin.so");
1122 dir = QFileInfo(dir + "/../..").canonicalPath();
1123 QLibrary lib(dir + "/libsimple_gdbtest_plugin.dylib");
1126 QLibrary lib(dir + "/debug/simple_gdbtest_plugin.dll");
1129 QLibrary lib(dir + "/libsimple_gdbtest_plugin.dll");
1131 int (*foo)() = (int(*)()) lib.resolve("pluginTest");
1132 qDebug() << "library resolve: " << foo << lib.fileName();
1137 qDebug() << lib.errorString();
1148 hgg1.insert("22.0");
1151 QSet<QPointer<QObject> > hash;
1152 QPointer<QObject> ptr(&ob);
1159 #if QT_VERSION >= 0x040500
1160 class EmployeeData : public QSharedData
1163 EmployeeData() : id(-1) { name.clear(); }
1164 EmployeeData(const EmployeeData &other)
1165 : QSharedData(other), id(other.id), name(other.name) { }
1175 Employee() { d = new EmployeeData; }
1176 Employee(int id, QString name) {
1177 d = new EmployeeData;
1181 Employee(const Employee &other)
1185 void setId(int id) { d->id = id; }
1186 void setName(QString name) { d->name = name; }
1188 int id() const { return d->id; }
1189 QString name() const { return d->name; }
1192 QSharedDataPointer<EmployeeData> d;
1196 void testQSharedPointer()
1198 //Employee e1(1, "Herbert");
1201 QSharedPointer<int> iptr(new int(43));
1202 QSharedPointer<int> iptr2 = iptr;
1203 QSharedPointer<int> iptr3 = iptr;
1205 QSharedPointer<QString> ptr(new QString("hallo"));
1206 QSharedPointer<QString> ptr2 = ptr;
1207 QSharedPointer<QString> ptr3 = ptr;
1209 QWeakPointer<int> wiptr(iptr);
1210 QWeakPointer<int> wiptr2 = wiptr;
1211 QWeakPointer<int> wiptr3 = wiptr;
1213 QWeakPointer<QString> wptr(ptr);
1214 QWeakPointer<QString> wptr2 = wptr;
1215 QWeakPointer<QString> wptr3 = wptr;
1218 QSharedPointer<Foo> fptr(new Foo(1));
1219 QWeakPointer<Foo> wfptr(fptr);
1220 QWeakPointer<Foo> wfptr2 = wfptr;
1221 QWeakPointer<Foo> wfptr3 = wfptr;
1225 void stringRefTest(const QString &refstring)
1227 Q_UNUSED(refstring);
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));
1241 std::deque<int> flist2;
1242 flist2.push_back(1);
1243 flist2.push_back(2);
1245 std::deque<Foo *> plist;
1246 plist.push_back(new Foo(1));
1247 plist.push_back(new Foo(2));
1249 std::deque<Foo> flist;
1251 flist.push_front(2);
1254 void testStdHashSet()
1256 // This is not supposed to work with the compiled dumpers.
1258 using namespace __gnu_cxx;
1269 std::list<int> testStdList()
1271 // This is not supposed to work with the compiled dumpers.
1273 for (int i = 0; i < 10000; ++i)
1276 std::list<Foo> flist;
1277 for (int i = 0; i < 100; ++i)
1278 flist.push_back(i + 15);
1281 std::list<int *> plist1;
1282 plist1.push_back(new int(1));
1283 plist1.push_back(0);
1284 plist1.push_back(new int(2));
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);
1292 flist2.push_back(1);
1293 flist2.push_back(2);
1294 flist2.push_back(3);
1295 flist2.push_back(4);
1297 std::list<Foo *> plist;
1298 plist.push_back(new Foo(1));
1300 plist.push_back(new Foo(2));
1303 foreach (Foo f, flist)
1306 std::list<bool> vec;
1307 vec.push_back(true);
1308 vec.push_back(false);
1310 std::list<int> result;
1316 // This is not supposed to work with the compiled dumpers.
1318 std::map<QString, Foo> gg3;
1319 gg3["22.0"] = Foo(22);
1320 gg3["33.0"] = Foo(33);
1321 gg3["44.0"] = Foo(44);
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);
1328 std::map<uint, uint> gg;
1335 std::pair<uint, QStringList> p = std::make_pair(3, QStringList() << "11");
1336 std::vector< std::pair<uint, QStringList> > v;
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";
1347 typedef std::map<uint, QStringList> T;
1349 ggt[11] = QStringList() << "11";
1350 ggt[22] = QStringList() << "22";
1352 std::map<uint, float> gg0;
1357 std::map<QString, float> gg1;
1360 std::map<int, QString> gg2;
1366 std::map<QString, QPointer<QObject> > map;
1367 map["Hallo"] = QPointer<QObject>(&ob);
1368 map["Welt"] = QPointer<QObject>(&ob);
1369 map["."] = QPointer<QObject>(&ob);
1373 std::set<int> testStdSet()
1375 // This is not supposed to work with the compiled dumpers.
1381 std::set<QString> hgg1;
1382 hgg1.insert("22.0");
1385 std::set<QPointer<QObject> > hash;
1386 QPointer<QObject> ptr(&ob);
1388 std::set<int> result;
1392 std::stack<int> testStdStack()
1394 // This is not supposed to work with the compiled dumpers.
1395 std::stack<int *> plist1;
1396 plist1.push(new int(1));
1398 plist1.push(new int(2));
1403 std::stack<int> flist2;
1407 std::stack<Foo *> plist;
1408 plist.push(new Foo(1));
1409 plist.push(new Foo(2));
1411 std::stack<Foo> flist;
1415 std::stack<int> result;
1419 std::string testStdString()
1425 std::vector<std::string> v;
1429 wstr += wchar_t('e');
1433 wstr += wchar_t('e');
1440 wstr += wchar_t('e');
1441 wstr += wchar_t('e');
1444 QList<std::string> l;
1456 std::string result = "hi";
1460 void testStdVector()
1462 std::vector<int *> plist1;
1463 plist1.push_back(new int(1));
1464 plist1.push_back(0);
1465 plist1.push_back(new int(2));
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);
1473 flist2.push_back(1);
1474 flist2.push_back(2);
1475 flist2.push_back(3);
1476 flist2.push_back(4);
1478 std::vector<Foo *> plist;
1479 plist.push_back(new Foo(1));
1481 plist.push_back(new Foo(2));
1483 std::vector<Foo> flist;
1488 //flist.takeFirst();
1489 //flist.takeFirst();
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);
1499 void testQStandardItemModel()
1502 //QString *s = static_cast<QString *>(static_cast<void *>(&(v.data_ptr().data.c)));
1503 //QString *t = (QString *)&(v.data_ptr());
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")));
1519 QStack<int> testQStack()
1522 for (int i = 0; i < 10; ++i)
1525 for (int i = 0; i < 10; ++i)
1527 QStack<Foo *> plist;
1528 plist.append(new Foo(1));
1530 plist.append(new Foo(2));
1536 //flist.takeFirst();
1537 //flist.takeFirst();
1548 QUrl url(QString("http://www.nokia.com"));
1573 QString str = "Hello ";
1585 QString str = "Hello ";
1590 QString string("String Test");
1591 QString *pstring = new QString("Pointer String Test");
1592 stringRefTest(QString("Ref String Test"));
1599 QStringList testQStringList()
1622 void testTypeFormats()
1624 // These tests should result in properly displayed umlauts in the
1625 // Locals&Watchers view. It is only support on gdb with Python.
1627 // Select UTF-8 in "Change Format for Type" in L&W context menu.
1628 const char *s = "aöa";
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";
1634 if (sizeof(wchar_t) == 4)
1635 u = QString::fromUcs4((uint *)w);
1637 u = QString::fromUtf16((ushort *)w);
1639 // Make sure to undo "Change Format".
1647 class Thread : public QThread
1650 Thread(int id) : m_id(id) {}
1656 for (int i = 0; i != 100000; ++i) {
1670 void testQTextCursor()
1673 //char *argv[] = { "xxx", 0 };
1674 //QApplication app(argc, argv);
1676 doc.setPlainText("Hallo\nWorld");
1678 tc = doc.find("all");
1679 int pos = tc.position();
1680 int anc = tc.anchor();
1689 thread1.setObjectName("This is the first thread");
1690 thread2.setObjectName("This is another thread");
1697 void testQVariant1()
1703 v = QRect(100, 200, 300, 400);
1704 v = QRectF(100, 200, 300, 400);
1709 QVariant testQVariant2()
1712 QVariant::Type t = QVariant::String;
1713 value = QVariant(t, (void*)0);
1714 *(QString*)value.data() = QString("XXX");
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");
1735 QHostAddress ha("127.0.0.1");
1741 QHostAddress ha1 = var.value<QHostAddress>();
1742 typedef QMap<uint, QStringList> MyType;
1744 my[1] = (QStringList() << "Hello");
1745 my[3] = (QStringList() << "World");
1747 // FIXME: Known to break
1748 QString type = var.typeName();
1754 QVariant result("sss");
1758 QVariant testQVariant3()
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"));
1769 list << 1 << 2 << 3;
1770 QVariant variant = qVariantFromValue(list);
1772 list = qVariantValue<QList<int> >(variant);
1774 QVariant result("xxx");
1780 QVector<int> big(10000);
1792 QVector<Foo *> plist;
1793 plist.append(new Foo(1));
1795 plist.append(new Foo(2));
1802 //flist.takeFirst();
1803 //flist.takeFirst();
1810 void testQVectorOfQList()
1812 QVector<QList<int> > v;
1813 QVector<QList<int> > *pv = &v;
1814 v.append(QList<int>() << 1);
1815 v.append(QList<int>() << 2 << 3);
1824 Goo(const QString& str, const int n) :
1833 typedef QList<Goo> GooList;
1835 void testNoArgumentName(int i, int, int k)
1837 // This is not supposed to work with the compiled dumpers.
1839 list.append(Goo("Hello", 1));
1840 list.append(Goo("World", 2));
1843 list2.append(Goo("Hello", 1));
1844 list2.append(Goo("World", 2));
1852 void foo(QList<int>) {}
1853 void foo(QList<QVector<int> >) {}
1854 void foo(QList<QVector<int> *>) {}
1855 void foo(QList<QVector<int *> *>) {}
1858 void foo(QList<QVector<T> *>) {}
1861 namespace somespace {
1863 class MyBase : public QObject
1867 virtual void doit(int i)
1877 class MyFoo : public MyBase
1881 virtual void doit(int i)
1889 class MyBar : public MyFoo
1892 virtual void doit(int i)
1900 class MyAnon : public MyBar
1903 virtual void doit(int i)
1911 class MyBaz : public MyAnon
1914 virtual void doit(int i)
1925 } // namespace nested
1926 } // namespace somespace
1928 void testNamespace()
1930 using namespace somespace;
1931 using namespace nested;
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");
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);
1993 vector.push_back(new std::list<int>(list));
1994 vector.push_back(0);
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);
2016 class Z : public QObject
2030 void testMemoryView()
2033 for (int i = 0; i != 20; ++i)
2037 void testUninitialized()
2042 QMap<QString, QString> mss;
2043 QHash<int, int> hii;
2044 QHash<QString, QString> hss;
2050 std::map<int, int> smii;
2051 std::map<std::string, std::string> smss;
2053 std::list<std::string> ssl;
2054 std::vector<int> svi;
2055 std::stack<int> ssi;
2058 void testEndlessRecursion()
2060 testEndlessRecursion();
2063 int testEndlessLoop()
2067 // Breakpoint at "while" will stop only once
2068 // Hitting "Pause" button might show backtrace of different thread
2081 QString a = "hello";
2082 const QString &b = fooxx();
2083 const QString c = "world";
2084 return a.size() + b.size() + c.size();
2090 Color() { r = 1, g = 2, b = 3, a = 4; }
2104 typedef QVector<Foo> FooVector;
2106 FooVector fooVector()
2110 fprintf(stderr, "xxx\n");
2113 for (int i = 0; i < 1000; ++i)
2119 typedef unsigned long long vl;
2120 typedef vl verylong;
2125 typedef quint32 myType1;
2126 typedef unsigned int myType2;
2130 ns::verylong k = 1000;
2138 void testConditional(const QString &str)
2151 strcat(s,"\""); // add a quote
2152 strcat(s,"\""); // add a quote
2153 strcat(s,"\""); // add a quote
2154 strcat(s,"\""); // add a quote
2159 Tx() { data = new char[20](); data[0] = '1'; }
2161 char *GetStringPtr() const
2185 using namespace std;
2186 typedef map<string, list<string> > map_t;
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();
2199 pair<vector<int>, vector<int> > a(pair<vector<int>,vector<int> >(vec, vec));
2208 char *s = x.m_buffer.GetStringPtr();
2214 typedef unsigned char byte;
2217 testConditional("foo");
2218 testConditional(fooxx());
2219 testConditional("bar");
2220 testConditional("zzz");
2221 Foo *f1 = new Foo(1);
2228 //Foo *f5 = new D();
2229 qDebug() << f1 << f2 << f3 << f4;
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);
2248 // special char* support only with Python.
2249 typedef unsigned short wchar;
2250 wchar *str = new wchar[10];
2257 QString foo = "foo";
2258 wchar *f = (wchar*)foo.utf16();
2265 void testPassByReferenceHelper(Foo &f)
2270 void testPassByReference()
2273 testPassByReferenceHelper(f);
2278 using namespace std;
2279 wstring x = L"xxxxx";
2280 wstring::iterator i = x.begin();
2281 while (i != x.end()) {
2287 string::iterator j = y.begin();
2288 while (j != y.end()) {
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."
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;
2325 for (i = 0; i < 4; i++) {
2330 sseA = _mm_loadu_ps(a);
2331 sseB = _mm_loadu_ps(b);
2336 void testQSettings()
2338 // Note: Construct a QCoreApplication first.
2339 QSettings settings("/tmp/test.ini", QSettings::IniFormat);
2340 QVariant value = settings.value("item1","").toString();
2345 void testQScriptValue(int argc, char *argv[])
2347 QCoreApplication app(argc, argv);
2348 QScriptEngine engine;
2349 QDateTime date = QDateTime::currentDateTime();
2351 s = QScriptValue(33);
2352 int x = s.toInt32();
2354 s = QScriptValue(QString("34"));
2355 QString x1 = s.toString();
2357 s = engine.newVariant(QVariant(43));
2358 QVariant v = s.toVariant();
2360 s = engine.newVariant(QVariant(43.0));
2361 s = engine.newVariant(QVariant(QString("sss")));
2362 s = engine.newDate(date);
2364 bool xx = s.isDate();
2366 date = s.toDateTime();
2367 s.setProperty("a", QScriptValue());
2368 QScriptValue d = s.data();
2371 void testBoostOptional()
2374 boost::optional<int> i;
2376 boost::optional<QStringList> sl;
2377 sl = (QStringList() << "xxx" << "yyy");
2378 sl.get().append("zzz");
2385 void testBoostSharedPtr()
2388 QSharedPointer<int> qs;
2389 QSharedPointer<int> qi(new int(43));
2390 QSharedPointer<int> qj = qi;
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);
2404 proc.start("/bin/ls");
2405 proc.waitForFinished();
2406 QByteArray ba = proc.readAllStandardError();
2411 int main(int argc, char *argv[])
2426 testFunctionPointer();
2429 //testEndlessLoop();
2430 //testEndlessRecursion();
2432 testUninitialized();
2442 testSignalSlot(argc, argv);
2444 QString hallo = "hallo\nwelt";
2446 list << "aaa" << "bbb" << "cc";
2448 QList<const char *> list2;
2455 testQStandardItemModel();
2458 testNoArgumentName(1, 2, 3);
2478 testPassByReference();
2491 # if QT_VERSION >= 0x040500
2492 testQSharedPointer();
2495 testQScriptValue(argc, argv);
2502 testQVectorOfQList();
2504 testBoostOptional();
2505 testBoostSharedPtr();
2509 testQObject(argc, argv);
2511 //QColor color(255,128,10);
2519 #include "simple_gdbtest_app.moc"