PageRenderTime 70ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/auto/debugger/tst_gdb.cpp

https://bitbucket.org/kpozn/qt-creator-py-reborn
C++ | 3719 lines | 2936 code | 372 blank | 411 comment | 137 complexity | 4e3b2455dc03faaf2beea2fa3d6b9a5c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**************************************************************************
  2. **
  3. ** This file is part of Qt Creator
  4. **
  5. ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
  6. **
  7. ** Contact: Nokia Corporation (qt-info@nokia.com)
  8. **
  9. **
  10. ** GNU Lesser General Public License Usage
  11. **
  12. ** This file may be used under the terms of the GNU Lesser General Public
  13. ** License version 2.1 as published by the Free Software Foundation and
  14. ** appearing in the file LICENSE.LGPL included in the packaging of this file.
  15. ** Please review the following information to ensure the GNU Lesser General
  16. ** Public License version 2.1 requirements will be met:
  17. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  18. **
  19. ** In addition, as a special exception, Nokia gives you certain additional
  20. ** rights. These rights are described in the Nokia Qt LGPL Exception
  21. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  22. **
  23. ** Other Usage
  24. **
  25. ** Alternatively, this file may be used in accordance with the terms and
  26. ** conditions contained in a signed written agreement between you and Nokia.
  27. **
  28. ** If you have questions regarding the use of this file, please contact
  29. ** Nokia at qt-info@nokia.com.
  30. **
  31. **************************************************************************/
  32. // Note: Keep the strange formating of closing braces in the void dump*()
  33. // functions as this reduces the risk of gdb reporting 'wrong' line numbers
  34. // when stopping and therefore the risk of the autotest to fail.
  35. //bool checkUninitialized = true;
  36. bool checkUninitialized = false;
  37. #define DO_DEBUG 1
  38. //TESTED_COMPONENT=src/plugins/debugger/gdb
  39. #include "gdb/gdbmi.h"
  40. #ifdef QT_GUI_LIB
  41. #include <QBitmap>
  42. #include <QBrush>
  43. #include <QColor>
  44. #include <QCursor>
  45. #include <QFont>
  46. #include <QIcon>
  47. #include <QKeySequence>
  48. #include <QMatrix4x4>
  49. #include <QPen>
  50. #include <QQuaternion>
  51. #include <QStandardItemModel>
  52. #include <QStringListModel>
  53. #include <QTextFormat>
  54. #include <QTextLength>
  55. #include <QVector2D>
  56. #include <QWidget>
  57. #endif
  58. #include <QtTest>
  59. #include <deque>
  60. #include <map>
  61. #include <set>
  62. #include <vector>
  63. #ifdef Q_OS_WIN
  64. #include <windows.h>
  65. #endif
  66. #undef NS
  67. #ifdef QT_NAMESPACE
  68. # define STRINGIFY0(s) #s
  69. # define STRINGIFY1(s) STRINGIFY0(s)
  70. # define NS STRINGIFY1(QT_NAMESPACE) "::"
  71. # define NSX "'" STRINGIFY1(QT_NAMESPACE) "::"
  72. # define NSY "'"
  73. #else
  74. # define NS ""
  75. # define NSX ""
  76. # define NSY ""
  77. #endif
  78. #undef DEBUG
  79. #if DO_DEBUG
  80. # define DEBUG(s) qDebug() << s
  81. #else
  82. # define DEBUG(s)
  83. #endif
  84. #define DEBUGX(s) qDebug() << s
  85. #define gettid() QString("0x%1").arg((qulonglong)(void *)currentGdbWrapper(), 0, 16)
  86. #ifdef Q_OS_WIN
  87. QString gdbBinary = "c:\\MinGw\\bin\\gdb.exe";
  88. #else
  89. QString gdbBinary = "gdb";
  90. #endif
  91. void nothing() {}
  92. template <typename T> QByteArray N(T v) { return QByteArray::number(v); }
  93. class Foo
  94. {
  95. public:
  96. Foo(int i = 0)
  97. : a(i), b(2)
  98. {}
  99. ~Foo()
  100. {
  101. }
  102. void doit()
  103. {
  104. static QObject ob;
  105. m["1"] = "2";
  106. h[&ob] = m.begin();
  107. a += 1;
  108. --b;
  109. //s += 'x';
  110. }
  111. struct Bar {
  112. Bar() : ob(0) {}
  113. QObject *ob;
  114. };
  115. public:
  116. int a, b;
  117. char x[6];
  118. private:
  119. //QString s;
  120. typedef QMap<QString, QString> Map;
  121. Map m;
  122. QHash<QObject *, Map::iterator> h;
  123. };
  124. /////////////////////////////////////////////////////////////////////////
  125. //
  126. // Helper stuff
  127. //
  128. /////////////////////////////////////////////////////////////////////////
  129. typedef QList<QByteArray> QByteArrayList;
  130. struct Int3
  131. {
  132. Int3(int base = 0) { i1 = 42 + base; i2 = 43 + base; i3 = 44 + base; }
  133. int i1, i2, i3;
  134. };
  135. uint qHash(const Int3 &i)
  136. {
  137. return (i.i1 ^ i.i2) ^ i.i3;
  138. }
  139. bool operator==(const Int3 &a, const Int3 &b)
  140. {
  141. return a.i1 == b.i1 && a.i2 == b.i2 && a.i3 == b.i3;
  142. }
  143. bool operator<(const Int3 &a, const Int3 &b)
  144. {
  145. return a.i1 < b.i1;
  146. }
  147. struct QString3
  148. {
  149. QString3() { s1 = "a"; s2 = "b"; s3 = "c"; }
  150. QString s1, s2, s3;
  151. };
  152. class tst_Gdb;
  153. class GdbWrapper : public QObject
  154. {
  155. Q_OBJECT
  156. public:
  157. GdbWrapper(tst_Gdb *test);
  158. ~GdbWrapper();
  159. void startup(QProcess *proc);
  160. void run();
  161. QString errorString() const { return m_errorString; }
  162. public slots:
  163. void readStandardOutput();
  164. bool parseOutput(const QByteArray &ba);
  165. void readStandardError();
  166. void handleGdbStarted();
  167. void handleGdbError(QProcess::ProcessError);
  168. void handleGdbFinished(int, QProcess::ExitStatus);
  169. QByteArray writeToGdbRequested(const QByteArray &ba)
  170. {
  171. DEBUG("GDB IN: " << ba);
  172. m_proc.write(ba);
  173. m_proc.write("\n");
  174. while (true) {
  175. m_proc.waitForReadyRead();
  176. QByteArray output = m_proc.readAllStandardOutput();
  177. if (parseOutput(output))
  178. break;
  179. }
  180. return m_buffer;
  181. }
  182. public:
  183. QByteArray m_lastStopped; // last seen "*stopped" message
  184. int m_line; // line extracted from last "*stopped" message
  185. QProcess m_proc;
  186. tst_Gdb *m_test; // not owned
  187. QString m_errorString;
  188. QByteArray m_buffer;
  189. };
  190. class tst_Gdb : public QObject
  191. {
  192. Q_OBJECT
  193. public:
  194. tst_Gdb();
  195. void prepare(const QByteArray &function);
  196. void check(const QByteArray &label, const QByteArray &expected,
  197. const QByteArray &expanded = QByteArray(), bool fancy = true);
  198. void next(int n = 1);
  199. QByteArray writeToGdb(const QByteArray &ba)
  200. {
  201. return m_gdb->writeToGdbRequested(ba);
  202. }
  203. private slots:
  204. void initTestCase();
  205. void cleanupTestCase();
  206. void dump_array();
  207. void dump_misc();
  208. void dump_typedef();
  209. void dump_std_deque();
  210. void dump_std_list();
  211. void dump_std_map_int_int();
  212. void dump_std_map_string_string();
  213. void dump_std_set_Int3();
  214. void dump_std_set_int();
  215. void dump_std_string();
  216. void dump_std_vector();
  217. void dump_std_wstring();
  218. void dump_Foo();
  219. //void dump_QImageData();
  220. void dump_QAbstractItemAndModelIndex();
  221. void dump_QAbstractItemModel();
  222. void dump_QByteArray();
  223. void dump_QChar();
  224. void dump_QDateTime();
  225. void dump_QDir();
  226. void dump_QFile();
  227. void dump_QFileInfo();
  228. void dump_QHash_QString_QString();
  229. void dump_QHash_int_int();
  230. void dump_QImage();
  231. void dump_QLinkedList_int();
  232. void dump_QList_Int3();
  233. void dump_QList_QString();
  234. void dump_QList_QString3();
  235. void dump_QList_char();
  236. void dump_QList_char_star();
  237. void dump_QList_int();
  238. void dump_QList_int_star();
  239. void dump_QLocale();
  240. void dump_QMap_QString_QString();
  241. void dump_QMap_int_int();
  242. void dump_QObject();
  243. void dump_QPixmap();
  244. void dump_QPoint();
  245. void dump_QRect();
  246. void dump_QSet_Int3();
  247. void dump_QSet_int();
  248. void dump_QSharedPointer();
  249. void dump_QSize();
  250. void dump_QStack();
  251. void dump_QString();
  252. void dump_QStringList();
  253. void dump_QTextCodec();
  254. void dump_QVariant();
  255. void dump_QVector();
  256. void dump_QWeakPointer_11();
  257. void dump_QWeakPointer_12();
  258. void dump_QWeakPointer_13();
  259. void dump_QWeakPointer_2();
  260. void dump_QWidget();
  261. public slots:
  262. void dumperCompatibility();
  263. private:
  264. #if 0
  265. void dump_QAbstractItemModelHelper(QAbstractItemModel &m);
  266. void dump_QObjectChildListHelper(QObject &o);
  267. void dump_QObjectSignalHelper(QObject &o, int sigNum);
  268. #endif
  269. QHash<QByteArray, int> m_lineForLabel;
  270. QByteArray m_function;
  271. GdbWrapper *m_gdb;
  272. };
  273. //
  274. // Dumpers
  275. //
  276. QByteArray str(const void *p)
  277. {
  278. char buf[100];
  279. sprintf(buf, "%p", p);
  280. return buf;
  281. }
  282. void tst_Gdb::dumperCompatibility()
  283. {
  284. // Ensure that no arbitrary padding is introduced by QVectorTypedData.
  285. const size_t qVectorDataSize = 16;
  286. QCOMPARE(sizeof(QVectorData), qVectorDataSize);
  287. QVectorTypedData<int> *v = 0;
  288. QCOMPARE(size_t(&v->array), qVectorDataSize);
  289. }
  290. static const QByteArray utfToHex(const QString &string)
  291. {
  292. return QByteArray(reinterpret_cast<const char *>(string.utf16()),
  293. 2 * string.size()).toHex();
  294. }
  295. static const QByteArray specQString(const QString &str)
  296. {
  297. return "valueencoded='7',value='" + utfToHex(str) + "'";
  298. }
  299. static const QByteArray specQChar(QChar ch)
  300. {
  301. return QByteArray("value=''") + char(ch.unicode()) + "' ("
  302. + QByteArray::number(ch.unicode()) + ")'";
  303. //return "valueencoded='7',value='" +
  304. // utfToHex(QString(QLatin1String("'%1' (%2)")).
  305. // arg(ch).arg(ch.unicode())) + "'";
  306. }
  307. /////////////////////////////////////////////////////////////////////////
  308. //
  309. // GdbWrapper
  310. //
  311. /////////////////////////////////////////////////////////////////////////
  312. GdbWrapper::GdbWrapper(tst_Gdb *test) : m_test(test)
  313. {
  314. qWarning() << "SETUP START\n\n";
  315. #ifndef Q_CC_GNU
  316. QSKIP("gdb test not applicable for compiler", SkipAll);
  317. #endif
  318. //qDebug() << "\nRUN" << getpid() << gettid();
  319. QStringList args;
  320. args << QLatin1String("-i")
  321. << QLatin1String("mi") << QLatin1String("--args")
  322. << qApp->applicationFilePath();
  323. qWarning() << "Starting" << gdbBinary << args;
  324. m_proc.start(gdbBinary, args);
  325. if (!m_proc.waitForStarted()) {
  326. const QString msg = QString::fromLatin1("Unable to run %1: %2")
  327. .arg(gdbBinary, m_proc.errorString());
  328. QSKIP(msg.toLatin1().constData(), SkipAll);
  329. }
  330. connect(&m_proc, SIGNAL(error(QProcess::ProcessError)),
  331. this, SLOT(handleGdbError(QProcess::ProcessError)));
  332. connect(&m_proc, SIGNAL(finished(int,QProcess::ExitStatus)),
  333. this, SLOT(handleGdbFinished(int,QProcess::ExitStatus)));
  334. connect(&m_proc, SIGNAL(started()),
  335. this, SLOT(handleGdbStarted()));
  336. connect(&m_proc, SIGNAL(readyReadStandardOutput()),
  337. this, SLOT(readStandardOutput()));
  338. connect(&m_proc, SIGNAL(readyReadStandardError()),
  339. this, SLOT(readStandardError()));
  340. m_proc.write("python execfile('../../../share/qtcreator/dumper/bridge.py')\n");
  341. m_proc.write("python execfile('../../../share/qtcreator/dumper/dumper.py')\n");
  342. m_proc.write("python execfile('../../../share/qtcreator/dumper/qttypes.py')\n");
  343. m_proc.write("bbsetup\n");
  344. m_proc.write("break breaker\n");
  345. m_proc.write("handle SIGSTOP stop pass\n");
  346. m_proc.write("run\n");
  347. }
  348. GdbWrapper::~GdbWrapper()
  349. {
  350. }
  351. void GdbWrapper::handleGdbError(QProcess::ProcessError error)
  352. {
  353. qDebug() << "GDB ERROR: " << error;
  354. }
  355. void GdbWrapper::handleGdbFinished(int code, QProcess::ExitStatus st)
  356. {
  357. qDebug() << "GDB FINISHED: " << code << st;
  358. }
  359. void GdbWrapper::readStandardOutput()
  360. {
  361. //parseOutput(m_proc.readAllStandardOutput());
  362. }
  363. bool GdbWrapper::parseOutput(const QByteArray &ba0)
  364. {
  365. if (ba0.isEmpty())
  366. return false;
  367. QByteArray ba = ba0;
  368. DEBUG("GDB OUT: " << ba);
  369. // =library-loaded...
  370. if (ba.startsWith("=")) {
  371. DEBUG("LIBRARY LOADED");
  372. return false;
  373. }
  374. if (ba.startsWith("*stopped")) {
  375. m_lastStopped = ba;
  376. DEBUG("GDB OUT 2: " << ba);
  377. if (!ba.contains("func=\"breaker\"")) {
  378. int pos1 = ba.indexOf(",line=\"") + 7;
  379. int pos2 = ba.indexOf("\"", pos1);
  380. m_line = ba.mid(pos1, pos2 - pos1).toInt();
  381. DEBUG(" LINE 1: " << m_line);
  382. }
  383. }
  384. // The "call" is always aborted with a message like:
  385. // "~"2321\t /* A */ QString s;\n" "
  386. // "&"The program being debugged stopped while in a function called ..."
  387. // "^error,msg="The program being debugged stopped ..."
  388. // Extract the "2321" from this
  389. static QByteArray lastText;
  390. if (ba.startsWith("~")) {
  391. lastText = ba;
  392. if (ba.size() > 8
  393. && (ba.at(2) < 'a' || ba.at(2) > 'z')
  394. && (ba.at(2) < '0' || ba.at(2) > '9')
  395. && !ba.startsWith("~\"Breakpoint ")
  396. && !ba.startsWith("~\" at ")
  397. && !ba.startsWith("~\" locals=")
  398. && !ba.startsWith("~\"XXX:")) {
  399. QByteArray ba1 = ba.mid(2, ba.size() - 6);
  400. if (ba1.startsWith(" File "))
  401. ba1 = ba1.replace(2, ba1.indexOf(','), "");
  402. //qWarning() << "OUT: " << ba1;
  403. }
  404. }
  405. if (ba.startsWith("&\"The program being debugged")) {
  406. int pos1 = 2;
  407. int pos2 = lastText.indexOf("\\", pos1);
  408. m_line = lastText.mid(pos1, pos2 - pos1).toInt();
  409. DEBUG(" LINE 2: " << m_line);
  410. }
  411. if (ba.startsWith("^error,msg=")) {
  412. if (!ba.startsWith("^error,msg=\"The program being debugged stopped"))
  413. qWarning() << "ERROR: " << ba.mid(1, ba.size() - 3);
  414. }
  415. if (ba.startsWith("~\"XXX: ")) {
  416. QByteArray ba1 = ba.mid(7, ba.size() - 11);
  417. qWarning() << "MESSAGE: " << ba.mid(7, ba.size() - 12);
  418. }
  419. ba = ba.replace("\\\"", "\"");
  420. // No interesting output before 'locals=...'
  421. int pos = ba.indexOf("locals={iname=");
  422. if (pos == -1 && ba.isEmpty())
  423. return true;
  424. QByteArray output;
  425. if (output.isEmpty())
  426. output = ba.mid(pos);
  427. else
  428. output += ba;
  429. // Up to ^done\n(gdb)
  430. pos = output.indexOf("(gdb)");
  431. if (pos == -1)
  432. return true;
  433. output = output.left(pos);
  434. pos = output.indexOf("^done");
  435. if (pos >= 4)
  436. output = output.left(pos - 4);
  437. if (output.isEmpty())
  438. return true;
  439. m_buffer += output;
  440. return true;
  441. }
  442. void GdbWrapper::readStandardError()
  443. {
  444. QByteArray ba = m_proc.readAllStandardError();
  445. qDebug() << "GDB ERR: " << ba;
  446. }
  447. void GdbWrapper::handleGdbStarted()
  448. {
  449. //qDebug() << "\n\nGDB STARTED" << getpid() << gettid() << "\n\n";
  450. }
  451. /////////////////////////////////////////////////////////////////////////
  452. //
  453. // Test Class Framework Implementation
  454. //
  455. /////////////////////////////////////////////////////////////////////////
  456. tst_Gdb::tst_Gdb()
  457. : m_gdb(0)
  458. {
  459. }
  460. void tst_Gdb::initTestCase()
  461. {
  462. const QString fileName = "tst_gdb.cpp";
  463. QFile file(fileName);
  464. if (!file.open(QIODevice::ReadOnly)) {
  465. const QString msg = QString::fromLatin1("Unable to open %1: %2")
  466. .arg(fileName, file.errorString());
  467. QSKIP(msg.toLatin1().constData(), SkipAll);
  468. }
  469. QByteArray funcName;
  470. const QByteArrayList bal = file.readAll().split('\n');
  471. Q_ASSERT(bal.size() > 100);
  472. for (int i = 0; i != bal.size(); ++i) {
  473. const QByteArray &ba = bal.at(i);
  474. if (ba.startsWith("void dump")) {
  475. int pos = ba.indexOf('(');
  476. funcName = ba.mid(5, pos - 5) + '@';
  477. } else if (ba.startsWith(" /*")) {
  478. int pos = ba.indexOf('*', 7);
  479. m_lineForLabel[QByteArray(funcName + ba.mid(7, pos - 8)).trimmed()] = i + 1;
  480. }
  481. }
  482. Q_ASSERT(!m_gdb);
  483. m_gdb = new GdbWrapper(this);
  484. }
  485. void tst_Gdb::prepare(const QByteArray &function)
  486. {
  487. Q_ASSERT(m_gdb);
  488. m_function = function;
  489. writeToGdb("b " + function);
  490. writeToGdb("call " + function + "()");
  491. }
  492. static bool isJoker(const QByteArray &ba)
  493. {
  494. return ba.endsWith("'-'") || ba.contains("'-'}");
  495. }
  496. void tst_Gdb::check(const QByteArray &label, const QByteArray &expected0,
  497. const QByteArray &expanded, bool fancy)
  498. {
  499. //qDebug() << "\nABOUT TO RUN TEST: " << expanded;
  500. qWarning() << label << "...";
  501. QByteArray options = "pe";
  502. if (fancy)
  503. options += ",fancy";
  504. options += ",autoderef";
  505. QByteArray ba = writeToGdb("bb options:" + options
  506. + " vars: expanded:" + expanded
  507. + " typeformats: formats: watchers:\n");
  508. //bb options:fancy,autoderef vars: expanded: typeformats:63686172202a=1
  509. //formats: watchers:
  510. //locals.fromString("{" + ba + "}");
  511. QByteArray received = ba.replace("\"", "'");
  512. QByteArray actual = received.trimmed();
  513. int pos = actual.indexOf("^done");
  514. if (pos != -1)
  515. actual = actual.left(pos);
  516. if (actual.endsWith("\n"))
  517. actual.chop(1);
  518. if (actual.endsWith("\\n"))
  519. actual.chop(2);
  520. QByteArray expected = "locals={iname='local',name='Locals',value=' ',type=' ',"
  521. "children=[" + expected0 + "]}";
  522. int line = m_gdb->m_line;
  523. QByteArrayList l1_0 = actual.split(',');
  524. QByteArrayList l1;
  525. for (int i = 0; i != l1_0.size(); ++i) {
  526. const QByteArray &ba = l1_0.at(i);
  527. if (ba.startsWith("watchers={iname"))
  528. break;
  529. if (!ba.startsWith("addr"))
  530. l1.append(ba);
  531. }
  532. QByteArrayList l2 = expected.split(',');
  533. bool ok = l1.size() == l2.size();
  534. if (ok) {
  535. for (int i = 0 ; i < l1.size(); ++i) {
  536. // Use "-" as joker.
  537. if (l1.at(i) != l2.at(i) && !isJoker(l2.at(i)))
  538. ok = false;
  539. }
  540. } else {
  541. qWarning() << "!= size: " << l1.size() << l2.size();
  542. }
  543. if (!ok) {
  544. int i = 0;
  545. for ( ; i < l1.size() && i < l2.size(); ++i) {
  546. if (l1.at(i) == l2.at(i) || isJoker(l2.at(i))) {
  547. qWarning() << "== " << l1.at(i);
  548. } else {
  549. //qWarning() << "!= " << l1.at(i).right(30) << l2.at(i).right(30);
  550. qWarning() << "!= " << l1.at(i) << l2.at(i);
  551. ok = false;
  552. }
  553. }
  554. for ( ; i < l2.size(); ++i)
  555. qWarning() << "!= " << "-----" << l2.at(i);
  556. for ( ; i < l1.size(); ++i)
  557. qWarning() << "!= " << l1.at(i) << "-----";
  558. if (l1.size() != l2.size()) {
  559. ok = false;
  560. qWarning() << "!= size: " << l1.size() << l2.size();
  561. }
  562. qWarning() << "RECEIVED: " << received;
  563. qWarning() << "ACTUAL : " << actual;
  564. }
  565. QCOMPARE(ok, true);
  566. //qWarning() << "LINE: " << line << "ACT/EXP" << m_function + '@' + label;
  567. //QCOMPARE(actual, expected);
  568. int expline = m_lineForLabel.value(m_function + '@' + label);
  569. int actline = line;
  570. if (actline != expline) {
  571. qWarning() << "LAST STOPPED: " << m_gdb->m_lastStopped;
  572. }
  573. QCOMPARE(actline, expline);
  574. }
  575. void tst_Gdb::next(int n)
  576. {
  577. for (int i = 0; i != n; ++i)
  578. writeToGdb("next");
  579. }
  580. void tst_Gdb::cleanupTestCase()
  581. {
  582. Q_ASSERT(m_gdb);
  583. writeToGdb("kill");
  584. writeToGdb("quit");
  585. //m_gdb.m_proc.waitForFinished();
  586. //m_gdb.wait();
  587. delete m_gdb;
  588. m_gdb = 0;
  589. }
  590. /////////////////////////////////////////////////////////////////////////
  591. //
  592. // Dumper Tests
  593. //
  594. /////////////////////////////////////////////////////////////////////////
  595. ///////////////////////////// Foo structure /////////////////////////////////
  596. /*
  597. Foo:
  598. int a, b;
  599. char x[6];
  600. typedef QMap<QString, QString> Map;
  601. Map m;
  602. QHash<QObject *, Map::iterator> h;
  603. */
  604. void dump_Foo()
  605. {
  606. /* A */ Foo f;
  607. /* B */ f.doit();
  608. /* D */ (void) 0;
  609. }
  610. void tst_Gdb::dump_Foo()
  611. {
  612. prepare("dump_Foo");
  613. next();
  614. check("B","{iname='local.f',name='f',type='Foo',"
  615. "value='-',numchild='5'}", "", 0);
  616. check("B","{iname='local.f',name='f',type='Foo',"
  617. "value='-',numchild='5',children=["
  618. "{name='a',type='int',value='0',numchild='0'},"
  619. "{name='b',type='int',value='2',numchild='0'},"
  620. "{name='x',type='char [6]',"
  621. "value='{...}',numchild='1'},"
  622. "{name='m',type='" NS "QMap<" NS "QString, " NS "QString>',"
  623. "value='{...}',numchild='1'},"
  624. "{name='h',type='" NS "QHash<" NS "QObject*, "
  625. "" NS "QMap<" NS "QString, " NS "QString>::iterator>',"
  626. "value='{...}',numchild='1'}]}",
  627. "local.f", 0);
  628. }
  629. ///////////////////////////// Array ///////////////////////////////////////
  630. void dump_array_char()
  631. {
  632. /* A */ const char s[] = "XYZ";
  633. /* B */ (void) &s; }
  634. void dump_array_int()
  635. {
  636. /* A */ int s[] = {1, 2, 3};
  637. /* B */ (void) s; }
  638. void tst_Gdb::dump_array()
  639. {
  640. prepare("dump_array_char");
  641. next();
  642. // FIXME: numchild should be '4', not '1'
  643. check("B","{iname='local.s',name='s',type='char [4]',"
  644. "value='-',numchild='1'}", "");
  645. check("B","{iname='local.s',name='s',type='char [4]',"
  646. "value='-',numchild='1',childtype='char',childnumchild='0',"
  647. "children=[{value='88 'X''},{value='89 'Y''},{value='90 'Z''},"
  648. "{value='0 '\\\\000''}]}",
  649. "local.s");
  650. prepare("dump_array_int");
  651. next();
  652. // FIXME: numchild should be '3', not '1'
  653. check("B","{iname='local.s',name='s',type='int [3]',"
  654. "value='-',numchild='1'}", "");
  655. check("B","{iname='local.s',name='s',type='int [3]',"
  656. "value='-',numchild='1',childtype='int',childnumchild='0',"
  657. "children=[{value='1'},{value='2'},{value='3'}]}",
  658. "local.s");
  659. }
  660. ///////////////////////////// Misc stuff /////////////////////////////////
  661. void dump_misc()
  662. {
  663. #if 1
  664. /* A */ int *s = new int(1);
  665. /* B */ *s += 1;
  666. /* D */ (void) 0;
  667. #else
  668. QVariant v1(QLatin1String("hallo"));
  669. QVariant v2(QStringList(QLatin1String("hallo")));
  670. QVector<QString> vec;
  671. vec.push_back("Hallo");
  672. vec.push_back("Hallo2");
  673. std::set<std::string> stdSet;
  674. stdSet.insert("s1");
  675. # ifdef QT_GUI_LIB
  676. QWidget *ww = 0; //this;
  677. QWidget &wwr = *ww;
  678. Q_UNUSED(wwr);
  679. # endif
  680. QSharedPointer<QString> sps(new QString("hallo"));
  681. QList<QSharedPointer<QString> > spsl;
  682. spsl.push_back(sps);
  683. QMap<QString,QString> stringmap;
  684. QMap<int,int> intmap;
  685. std::map<std::string, std::string> stdstringmap;
  686. stdstringmap[std::string("A")] = std::string("B");
  687. int xxx = 45;
  688. if (1 == 1) {
  689. int xxx = 7;
  690. qDebug() << xxx;
  691. }
  692. QLinkedList<QString> lls;
  693. lls << "link1" << "link2";
  694. # ifdef QT_GUI_LIB
  695. QStandardItemModel *model = new QStandardItemModel;
  696. model->appendRow(new QStandardItem("i1"));
  697. # endif
  698. QList <QList<int> > nestedIntList;
  699. nestedIntList << QList<int>();
  700. nestedIntList.front() << 1 << 2;
  701. QVariantList vList;
  702. vList.push_back(QVariant(42));
  703. vList.push_back(QVariant("HALLO"));
  704. stringmap.insert("A", "B");
  705. intmap.insert(3,4);
  706. QSet<QString> stringSet;
  707. stringSet.insert("S1");
  708. stringSet.insert("S2");
  709. qDebug() << *(spsl.front()) << xxx;
  710. #endif
  711. }
  712. void tst_Gdb::dump_misc()
  713. {
  714. prepare("dump_misc");
  715. next();
  716. check("B","{iname='local.s',name='s',type='int *',"
  717. "value='-',numchild='1'}", "", 0);
  718. //check("B","{iname='local.s',name='s',type='int *',"
  719. // "value='1',numchild='0'}", "local.s,local.model", 0);
  720. check("B","{iname='local.s',name='s',type='int *',"
  721. "value='-',numchild='1',children=["
  722. "{name='*',type='int',value='1',numchild='0'}]}",
  723. "local.s,local.model", 0);
  724. }
  725. ///////////////////////////// typedef ////////////////////////////////////
  726. void dump_typedef()
  727. {
  728. /* A */ typedef QMap<uint, double> T;
  729. /* B */ T t;
  730. /* C */ t[11] = 13.0;
  731. /* D */ (void) 0;
  732. }
  733. void tst_Gdb::dump_typedef()
  734. {
  735. prepare("dump_typedef");
  736. next(2);
  737. check("D","{iname='local.t',name='t',type='T',"
  738. //"basetype='" NS "QMap<unsigned int, double>',"
  739. "value='-',numchild='1',"
  740. "childtype='double',childnumchild='0',"
  741. "children=[{name='11',value='13'}]}", "local.t");
  742. }
  743. #if 0
  744. void tst_Gdb::dump_QAbstractItemHelper(QModelIndex &index)
  745. {
  746. const QAbstractItemModel *model = index.model();
  747. const QString &rowStr = N(index.row());
  748. const QString &colStr = N(index.column());
  749. const QByteArray &internalPtrStrSymbolic = ptrToBa(index.internalPointer());
  750. const QByteArray &internalPtrStrValue = ptrToBa(index.internalPointer(), false);
  751. const QByteArray &modelPtrStr = ptrToBa(model);
  752. QByteArray indexSpecSymbolic = QByteArray().append(rowStr + "," + colStr + ",").
  753. append(internalPtrStrSymbolic + "," + modelPtrStr);
  754. QByteArray indexSpecValue = QByteArray().append(rowStr + "," + colStr + ",").
  755. append(internalPtrStrValue + "," + modelPtrStr);
  756. QByteArray expected = QByteArray("tiname='iname',addr='").append(ptrToBa(&index)).
  757. append("',type='" NS "QAbstractItem',addr='$").append(indexSpecSymbolic).
  758. append("',value='").append(valToString(model->data(index).toString())).
  759. append("',numchild='1',children=[");
  760. int rowCount = model->rowCount(index);
  761. int columnCount = model->columnCount(index);
  762. for (int row = 0; row < rowCount; ++row) {
  763. for (int col = 0; col < columnCount; ++col) {
  764. const QModelIndex &childIndex = model->index(row, col, index);
  765. expected.append("{name='[").append(valToString(row)).append(",").
  766. append(N(col)).append("]',numchild='1',addr='$").
  767. append(N(childIndex.row())).append(",").
  768. append(N(childIndex.column())).append(",").
  769. append(ptrToBa(childIndex.internalPointer())).append(",").
  770. append(modelPtrStr).append("',type='" NS "QAbstractItem',value='").
  771. append(valToString(model->data(childIndex).toString())).append("'}");
  772. if (col < columnCount - 1 || row < rowCount - 1)
  773. expected.append(",");
  774. }
  775. }
  776. expected.append("]");
  777. testDumper(expected, &index, NS"QAbstractItem", true, indexSpecValue);
  778. }
  779. #endif
  780. class PseudoTreeItemModel : public QAbstractItemModel
  781. {
  782. public:
  783. PseudoTreeItemModel() : QAbstractItemModel(), parent1(0),
  784. parent1Child(1), parent2(10), parent2Child1(11), parent2Child2(12)
  785. {}
  786. int columnCount(const QModelIndex &parent = QModelIndex()) const
  787. {
  788. Q_UNUSED(parent);
  789. return 1;
  790. }
  791. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
  792. {
  793. return !index.isValid() || role != Qt::DisplayRole ?
  794. QVariant() : *static_cast<int *>(index.internalPointer());
  795. }
  796. QModelIndex index(int row, int column,
  797. const QModelIndex & parent = QModelIndex()) const
  798. {
  799. QModelIndex index;
  800. if (column == 0) {
  801. if (!parent.isValid()) {
  802. if (row == 0)
  803. index = createIndex(row, column, &parent1);
  804. else if (row == 1)
  805. index = createIndex(row, column, &parent2);
  806. } else if (parent.internalPointer() == &parent1 && row == 0) {
  807. index = createIndex(row, column, &parent1Child);
  808. } else if (parent.internalPointer() == &parent2) {
  809. index = createIndex(row, column,
  810. row == 0 ? &parent2Child1 : &parent2Child2);
  811. }
  812. }
  813. return index;
  814. }
  815. QModelIndex parent(const QModelIndex & index) const
  816. {
  817. QModelIndex parent;
  818. if (index.isValid()) {
  819. if (index.internalPointer() == &parent1Child)
  820. parent = createIndex(0, 0, &parent1);
  821. else if (index.internalPointer() == &parent2Child1 ||
  822. index.internalPointer() == &parent2Child2)
  823. parent = createIndex(1, 0, &parent2);
  824. }
  825. return parent;
  826. }
  827. int rowCount(const QModelIndex &parent = QModelIndex()) const
  828. {
  829. int rowCount;
  830. if (!parent.isValid() || parent.internalPointer() == &parent2)
  831. rowCount = 2;
  832. else if (parent.internalPointer() == &parent1)
  833. rowCount = 1;
  834. else
  835. rowCount = 0;
  836. return rowCount;
  837. }
  838. private:
  839. mutable int parent1;
  840. mutable int parent1Child;
  841. mutable int parent2;
  842. mutable int parent2Child1;
  843. mutable int parent2Child2;
  844. };
  845. ///////////////////////////// QAbstractItemAndModelIndex //////////////////////////
  846. // /* A */ QStringListModel m(QStringList() << "item1" << "item2" << "item3");
  847. // /* B */ index = m.index(2, 0);
  848. void dump_QAbstractItemAndModelIndex()
  849. {
  850. /* A */ PseudoTreeItemModel m2; QModelIndex index;
  851. /* C */ index = m2.index(0, 0);
  852. /* D */ index = m2.index(1, 0);
  853. /* E */ index = m2.index(0, 0, index);
  854. /* F */ (void) index.row();
  855. }
  856. void tst_Gdb::dump_QAbstractItemAndModelIndex()
  857. {
  858. prepare("dump_QAbstractItemAndModelIndex");
  859. if (checkUninitialized)
  860. check("A", "");
  861. next();
  862. check("C", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
  863. "value='{...}',numchild='6'},"
  864. "{iname='local.index',name='index',type='" NS "QModelIndex',"
  865. "value='(invalid)',numchild='0'}",
  866. "local.index");
  867. next();
  868. check("D", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
  869. "value='{...}',numchild='6'},"
  870. "{iname='local.index',name='index',type='" NS "QModelIndex',"
  871. "value='(0, 0)',numchild='5',children=["
  872. "{name='row',value='0',type='int',numchild='0'},"
  873. "{name='column',value='0',type='int',numchild='0'},"
  874. "{name='parent',type='" NS "QModelIndex',value='(invalid)',numchild='0'},"
  875. "{name='model',value='-',type='" NS "QAbstractItemModel*',numchild='1'}]}",
  876. "local.index");
  877. next();
  878. check("E", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
  879. "value='{...}',numchild='6'},"
  880. "{iname='local.index',name='index',type='" NS "QModelIndex',"
  881. "value='(1, 0)',numchild='5',children=["
  882. "{name='row',value='1',type='int',numchild='0'},"
  883. "{name='column',value='0',type='int',numchild='0'},"
  884. "{name='parent',type='" NS "QModelIndex',value='(invalid)',numchild='0'},"
  885. "{name='model',value='-',type='" NS "QAbstractItemModel*',numchild='1'}]}",
  886. "local.index");
  887. next();
  888. check("F", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
  889. "value='{...}',numchild='6'},"
  890. "{iname='local.index',name='index',type='" NS "QModelIndex',"
  891. "value='(0, 0)',numchild='5',children=["
  892. "{name='row',value='0',type='int',numchild='0'},"
  893. "{name='column',value='0',type='int',numchild='0'},"
  894. "{name='parent',type='" NS "QModelIndex',value='(1, 0)',numchild='5'},"
  895. "{name='model',value='-',type='" NS "QAbstractItemModel*',numchild='1'}]}",
  896. "local.index");
  897. }
  898. /*
  899. QByteArray dump_QAbstractItemModelHelper(QAbstractItemModel &m)
  900. {
  901. QByteArray address = ptrToBa(&m);
  902. QByteArray expected = QByteArray("tiname='iname',"
  903. "type='" NS "QAbstractItemModel',value='(%,%)',numchild='1',children=["
  904. "{numchild='1',name='" NS "QObject',value='%',"
  905. "valueencoded='2',type='" NS "QObject',displayedtype='%'}")
  906. << address
  907. << N(m.rowCount())
  908. << N(m.columnCount())
  909. << address
  910. << utfToHex(m.objectName())
  911. << m.metaObject()->className();
  912. for (int row = 0; row < m.rowCount(); ++row) {
  913. for (int column = 0; column < m.columnCount(); ++column) {
  914. QModelIndex mi = m.index(row, column);
  915. expected.append(QByteArray(",{name='[%,%]',value='%',"
  916. "valueencoded='2',numchild='1',%,%,%',"
  917. "type='" NS "QAbstractItem'}")
  918. << N(row)
  919. << N(column)
  920. << utfToHex(m.data(mi).toString())
  921. << N(mi.row())
  922. << N(mi.column())
  923. << ptrToBa(mi.internalPointer())
  924. << ptrToBa(mi.model()));
  925. }
  926. }
  927. expected.append("]");
  928. return expected;
  929. }
  930. */
  931. void dump_QAbstractItemModel()
  932. {
  933. # ifdef QT_GUI_LIB
  934. /* A */ QStringList strList;
  935. strList << "String 1";
  936. QStringListModel model1(strList);
  937. QStandardItemModel model2(0, 2);
  938. /* B */ model1.setStringList(strList);
  939. /* C */ strList << "String 2";
  940. /* D */ model1.setStringList(strList);
  941. /* E */ model2.appendRow(QList<QStandardItem *>() << (new QStandardItem("Item (0,0)")) << (new QStandardItem("Item (0,1)")));
  942. /* F */ model2.appendRow(QList<QStandardItem *>() << (new QStandardItem("Item (1,0)")) << (new QStandardItem("Item (1,1)")));
  943. /* G */ (void) (model1.rowCount() + model2.rowCount() + strList.size());
  944. # endif
  945. }
  946. void tst_Gdb::dump_QAbstractItemModel()
  947. {
  948. # ifdef QT_GUI_LIB
  949. /* A */ QStringList strList;
  950. QString template_ =
  951. "{iname='local.strList',name='strList',type='" NS "QStringList',"
  952. "value='<%1 items>',numchild='%1'},"
  953. "{iname='local.model1',name='model1',type='" NS "QStringListModel',"
  954. "value='{...}',numchild='3'},"
  955. "{iname='local.model2',name='model2',type='" NS "QStandardItemModel',"
  956. "value='{...}',numchild='2'}";
  957. prepare("dump_QAbstractItemModel");
  958. if (checkUninitialized)
  959. check("A", template_.arg("1").toAscii());
  960. next(4);
  961. check("B", template_.arg("1").toAscii());
  962. # endif
  963. }
  964. ///////////////////////////// QByteArray /////////////////////////////////
  965. void dump_QByteArray()
  966. {
  967. /* A */ QByteArray ba; // Empty object.
  968. /* B */ ba.append('a'); // One element.
  969. /* C */ ba.append('b'); // Two elements.
  970. /* D */ ba = QByteArray(101, 'a'); // > 100 elements.
  971. /* E */ ba = QByteArray("abc\a\n\r\033\'\"?"); // Mixed.
  972. /* F */ (void) 0;
  973. }
  974. void tst_Gdb::dump_QByteArray()
  975. {
  976. prepare("dump_QByteArray");
  977. if (checkUninitialized)
  978. check("A","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  979. "value='<invalid>',numchild='0'}");
  980. next();
  981. check("B","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  982. "valueencoded='6',value='',numchild='0'}");
  983. next();
  984. check("C","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  985. "valueencoded='6',value='61',numchild='1'}");
  986. next();
  987. check("D","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  988. "valueencoded='6',value='6162',numchild='2'}");
  989. next();
  990. check("E","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  991. "valueencoded='6',value='616161616161616161616161616161616161"
  992. "616161616161616161616161616161616161616161616161616161616161"
  993. "616161616161616161616161616161616161616161616161616161616161"
  994. "6161616161616161616161616161616161616161616161',numchild='101'}");
  995. next();
  996. check("F","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  997. "valueencoded='6',value='616263070a0d1b27223f',numchild='10'}");
  998. check("F","{iname='local.ba',name='ba',type='" NS "QByteArray',"
  999. "valueencoded='6',value='616263070a0d1b27223f',numchild='10',"
  1000. "childtype='char',childnumchild='0',"
  1001. "children=[{value='97 'a''},{value='98 'b''},"
  1002. "{value='99 'c''},{value='7 '\\\\a''},"
  1003. "{value='10 '\\\\n''},{value='13 '\\\\r''},"
  1004. "{value='27 '\\\\033''},{value='39 '\\\\'''},"
  1005. "{value='34 ''''},{value='63 '?''}]}",
  1006. "local.ba");
  1007. }
  1008. ///////////////////////////// QChar /////////////////////////////////
  1009. void dump_QChar()
  1010. {
  1011. /* A */ QChar c('X'); // Printable ASCII character.
  1012. /* B */ c = QChar(0x600); // Printable non-ASCII character.
  1013. /* C */ c = QChar::fromAscii('\a'); // Non-printable ASCII character.
  1014. /* D */ c = QChar(0x9f); // Non-printable non-ASCII character.
  1015. /* E */ c = QChar::fromAscii('?'); // The replacement character.
  1016. /* F */ (void) 0; }
  1017. void tst_Gdb::dump_QChar()
  1018. {
  1019. prepare("dump_QChar");
  1020. next();
  1021. // Case 1: Printable ASCII character.
  1022. check("B","{iname='local.c',name='c',type='" NS "QChar',"
  1023. "value=''X' (88)',numchild='0'}");
  1024. next();
  1025. // Case 2: Printable non-ASCII character.
  1026. check("C","{iname='local.c',name='c',type='" NS "QChar',"
  1027. "value=''?' (1536)',numchild='0'}");
  1028. next();
  1029. // Case 3: Non-printable ASCII character.
  1030. check("D","{iname='local.c',name='c',type='" NS "QChar',"
  1031. "value=''?' (7)',numchild='0'}");
  1032. next();
  1033. // Case 4: Non-printable non-ASCII character.
  1034. check("E","{iname='local.c',name='c',type='" NS "QChar',"
  1035. "value=''?' (159)',numchild='0'}");
  1036. next();
  1037. // Case 5: Printable ASCII Character that looks like the replacement character.
  1038. check("F","{iname='local.c',name='c',type='" NS "QChar',"
  1039. "value=''?' (63)',numchild='0'}");
  1040. }
  1041. ///////////////////////////// QDateTime /////////////////////////////////
  1042. void dump_QDateTime()
  1043. {
  1044. # ifndef QT_NO_DATESTRING
  1045. /* A */ QDateTime d;
  1046. /* B */ d = QDateTime::fromString("M5d21y7110:31:02", "'M'M'd'd'y'yyhh:mm:ss");
  1047. /* C */ (void) d.isNull();
  1048. # endif
  1049. }
  1050. void tst_Gdb::dump_QDateTime()
  1051. {
  1052. # ifndef QT_NO_DATESTRING
  1053. prepare("dump_QDateTime");
  1054. if (checkUninitialized)
  1055. check("A","{iname='local.d',name='d',"
  1056. "type='" NS "QDateTime',value='<invalid>',"
  1057. "numchild='0'}");
  1058. next();
  1059. check("B", "{iname='local.d',name='d',type='" NS "QDateTime',"
  1060. "valueencoded='7',value='-',numchild='3',children=["
  1061. "{name='isNull',type='bool',value='true',numchild='0'},"
  1062. "{name='toTime_t',type='unsigned int',value='4294967295',numchild='0'},"
  1063. "{name='toString',type='myns::QString',valueencoded='7',"
  1064. "value='',numchild='0'},"
  1065. "{name='(ISO)',type='myns::QString',valueencoded='7',"
  1066. "value='',numchild='0'},"
  1067. "{name='(SystemLocale)',type='myns::QString',valueencoded='7',"
  1068. "value='',numchild='0'},"
  1069. "{name='(Locale)',type='myns::QString',valueencoded='7',"
  1070. "value='',numchild='0'},"
  1071. "{name='toUTC',type='myns::QDateTime',valueencoded='7',"
  1072. "value='',numchild='3'},"
  1073. "{name='toLocalTime',type='myns::QDateTime',valueencoded='7',"
  1074. "value='',numchild='3'}"
  1075. "]}",
  1076. "local.d");
  1077. next();
  1078. check("C", "{iname='local.d',name='d',type='" NS "QDateTime',"
  1079. "valueencoded='7',value='-',"
  1080. "numchild='3',children=["
  1081. "{name='isNull',type='bool',value='false',numchild='0'},"
  1082. "{name='toTime_t',type='unsigned int',value='43666262',numchild='0'},"
  1083. "{name='toString',type='myns::QString',valueencoded='7',"
  1084. "value='-',numchild='0'},"
  1085. "{name='(ISO)',type='myns::QString',valueencoded='7',"
  1086. "value='-',numchild='0'},"
  1087. "{name='(SystemLocale)',type='myns::QString',valueencoded='7',"
  1088. "value='-',numchild='0'},"
  1089. "{name='(Locale)',type='myns::QString',valueencoded='7',"
  1090. "value='-',numchild='0'},"
  1091. "{name='toUTC',type='myns::QDateTime',valueencoded='7',"
  1092. "value='-',numchild='3'},"
  1093. "{name='toLocalTime',type='myns::QDateTime',valueencoded='7',"
  1094. "value='-',numchild='3'}"
  1095. "]}",
  1096. "local.d");
  1097. # endif
  1098. }
  1099. ///////////////////////////// QDir /////////////////////////////////
  1100. void dump_QDir()
  1101. {
  1102. /* A */ QDir dir = QDir::current(); // Case 1: Current working directory.
  1103. /* B */ dir = QDir::root(); // Case 2: Root directory.
  1104. /* C */ (void) dir.absolutePath(); }
  1105. void tst_Gdb::dump_QDir()
  1106. {
  1107. prepare("dump_QDir");
  1108. if (checkUninitialized)
  1109. check("A","{iname='local.dir',name='dir',"
  1110. "type='" NS "QDir',value='<invalid>',"
  1111. "numchild='0'}");
  1112. next();
  1113. check("B", "{iname='local.dir',name='dir',type='" NS "QDir',"
  1114. "valueencoded='7',value='-',numchild='2',children=["
  1115. "{name='absolutePath',type='" NS "QString',"
  1116. "valueencoded='7',value='-',numchild='0'},"
  1117. "{name='canonicalPath',type='" NS "QString',"
  1118. "valueencoded='7',value='-',numchild='0'}]}",
  1119. "local.dir");
  1120. next();
  1121. check("C", "{iname='local.dir',name='dir',type='" NS "QDir',"
  1122. "valueencoded='7',value='-',numchild='2',children=["
  1123. "{name='absolutePath',type='" NS "QString',"
  1124. "valueencoded='7',value='-',numchild='0'},"
  1125. "{name='canonicalPath',type='" NS "QString',"
  1126. "valueencoded='7',value='-',numchild='0'}]}",
  1127. "local.dir");
  1128. }
  1129. ///////////////////////////// QFile /////////////////////////////////
  1130. void dump_QFile()
  1131. {
  1132. /* A */ QFile file1(""); // Case 1: Empty file name => Does not exist.
  1133. /* B */ QTemporaryFile file2; // Case 2: File that is known to exist.
  1134. file2.open();
  1135. /* C */ QFile file3("jfjfdskjdflsdfjfdls");
  1136. /* D */ (void) (file1.fileName() + file2.fileName() + file3.fileName()); }
  1137. void tst_Gdb::dump_QFile()
  1138. {
  1139. prepare("dump_QFile");
  1140. next(4);
  1141. check("D", "{iname='local.file1',name='file1',type='" NS "QFile',"
  1142. "valueencoded='7',value='',numchild='2',children=["
  1143. "{name='fileName',type='" NS "QString',"
  1144. "valueencoded='7',value='',numchild='0'},"
  1145. "{name='exists',type='bool',value='false',numchild='0'}"
  1146. "]},"
  1147. "{iname='local.file2',name='file2',type='" NS "QTemporaryFile',"
  1148. "valueencoded='7',value='-',numchild='2',children=["
  1149. "{name='fileName',type='" NS "QString',"
  1150. "valueencoded='7',value='-',numchild='0'},"
  1151. "{name='exists',type='bool',value='true',numchild='0'}"
  1152. "]},"
  1153. "{iname='local.file3',name='file3',type='" NS "QFile',"
  1154. "valueencoded='7',value='-',numchild='2',children=["
  1155. "{name='fileName',type='" NS "QString',"
  1156. "valueencoded='7',value='-',numchild='0'},"
  1157. "{name='exists',type='bool',value='false',numchild='0'}"
  1158. "]}",
  1159. "local.file1,local.file2,local.file3");
  1160. }
  1161. ///////////////////////////// QFileInfo /////////////////////////////////
  1162. void dump_QFileInfo()
  1163. {
  1164. /* A */ QFileInfo fi(".");
  1165. /* B */ (void) fi.baseName().size();
  1166. }
  1167. void tst_Gdb::dump_QFileInfo()
  1168. {
  1169. QFileInfo fi(".");
  1170. prepare("dump_QFileInfo");
  1171. next();
  1172. check("B", "{iname='local.fi',name='fi',type='" NS "QFileInfo',"
  1173. "valueencoded='7',value='" + utfToHex(fi.filePath()) + "',numchild='3',"
  1174. "childtype='" NS "QString',childnumchild='0',children=["
  1175. "{name='absolutePath'," + specQString(fi.absolutePath()) + "},"
  1176. "{name='absoluteFilePath'," + specQString(fi.absoluteFilePath()) + "},"
  1177. "{name='canonicalPath'," + specQString(fi.canonicalPath()) + "},"
  1178. "{name='canonicalFilePath'," + specQString(fi.canonicalFilePath()) + "},"
  1179. "{name='completeBaseName'," + specQString(fi.completeBaseName()) + "},"
  1180. "{name='completeSuffix'," + specQString(fi.completeSuffix()) + "},"
  1181. "{name='baseName'," + specQString(fi.baseName()) + "},"
  1182. #if 0
  1183. "{name='isBundle'," + specBool(fi.isBundle()) + "},"
  1184. "{name='bundleName'," + specQString(fi.bundleName()) + "},"
  1185. #endif
  1186. "{name='fileName'," + specQString(fi.fileName()) + "},"
  1187. "{name='filePath'," + specQString(fi.filePath()) + "},"
  1188. //"{name='group'," + specQString(fi.group()) + "},"
  1189. //"{name='owner'," + specQString(fi.owner()) + "},"
  1190. "{name='path'," + specQString(fi.path()) + "},"
  1191. "{name='groupid',type='unsigned int',value='" + N(fi.groupId()) + "'},"
  1192. "{name='ownerid',type='unsigned int',value='" + N(fi.ownerId()) + "'},"
  1193. "{name='permissions',value=' ',type='" NS "QFile::Permissions',numchild='10'},"
  1194. "{name='caching',type='bool',value='true'},"
  1195. "{name='exists',type='bool',value='true'},"
  1196. "{name='isAbsolute',type='bool',value='false'},"
  1197. "{name='isDir',type='bool',value='true'},"
  1198. "{name='isExecutable',type='bool',value='true'},"
  1199. "{name='isFile',type='bool',value='false'},"
  1200. "{name='isHidden',type='bool',value='false'},"
  1201. "{name='isReadable',type='bool',value='true'},"
  1202. "{name='isRelative',type='bool',value='true'},"
  1203. "{name='isRoot',type='bool',value='false'},"
  1204. "{name='isSymLink',type='bool',value='false'},"
  1205. "{name='isWritable',type='bool',value='true'},"
  1206. "{name='created',type='" NS "QDateTime',"
  1207. + specQString(fi.created().toString()) + ",numchild='3'},"
  1208. "{name='lastModified',type='" NS "QDateTime',"
  1209. + specQString(fi.lastModified().toString()) + ",numchild='3'},"
  1210. "{name='lastRead',type='" NS "QDateTime',"
  1211. + specQString(fi.lastRead().toString()) + ",numchild='3'}]}",
  1212. "local.fi");
  1213. }
  1214. #if 0
  1215. void tst_Gdb::dump_QImageDataHelper(QImage &img)
  1216. {
  1217. const QByteArray ba(QByteArray::fromRawData((const char*) img.bits(), img.numBytes()));
  1218. QByteArray expected = QByteArray("tiname='$I',addr='$A',type='" NS "QImageData',").
  1219. append("numchild='0',value='<hover here>',valuetooltipencoded='1',").
  1220. append("valuetooltipsize='").append(N(ba.size())).append("',").
  1221. append("valuetooltip='").append(ba.toBase64()).append("'");
  1222. testDumper(expected, &img, NS"QImageData", false);
  1223. }
  1224. #endif // 0
  1225. ///////////////////////////// QImage /////////////////////////////////
  1226. void dump_QImage()
  1227. {
  1228. # ifdef QT_GUI_LIB
  1229. /* A */ QImage image; // Null image.
  1230. /* B */ image = QImage(30, 700, QImage::Format_RGB555); // Normal image.
  1231. /* C */ image = QImage(100, 0, QImage::Format_Invalid); // Invalid image.
  1232. /* D */ (void) image.size();
  1233. /* E */ (void) image.size();
  1234. # endif
  1235. }
  1236. void tst_Gdb::dump_QImage()
  1237. {
  1238. # ifdef QT_GUI_LIB
  1239. prepare("dump_QImage");
  1240. next();
  1241. check("B", "{iname='local.image',name='image',type='" NS "QImage',"
  1242. "value='(null)',numchild='0'}");
  1243. next();
  1244. check("C", "{iname='local.image',name='image',type='" NS "QImage',"
  1245. "value='(30x700)',numchild='0'}");
  1246. next(2);
  1247. // FIXME:
  1248. //check("E", "{iname='local.image',name='image',type='" NS "QImage',"
  1249. // "value='(100x0)',numchild='0'}");
  1250. # endif
  1251. }
  1252. #if 0
  1253. void tst_Gdb::dump_QImageData()
  1254. {
  1255. // Case 1: Null image.
  1256. QImage img;
  1257. dump_QImageDataHelper(img);
  1258. // Case 2: Normal image.
  1259. img = QImage(3, 700, QImage::Format_RGB555);
  1260. dump_QImageDataHelper(img);
  1261. // Case 3: Invalid image.
  1262. img = QImage(100, 0, QImage::Format_Invalid);
  1263. dump_QImageDataHelper(img);
  1264. }
  1265. #endif
  1266. void dump_QLocale()
  1267. {
  1268. /* A */ QLocale german(QLocale::German);
  1269. QLocale chinese(QLocale::Chinese);
  1270. QLocale swahili(QLocale::Swahili);
  1271. /* C */ (void) (german.name() + chinese.name() + swahili.name());
  1272. }
  1273. QByteArray dump_QLocaleHelper(const QLocale &loc)
  1274. {
  1275. return "type='" NS "QLocale',valueencoded='7',value='" + utfToHex(loc.name()) +
  1276. "',numchild='8',childtype='" NS "QChar',childnumchild='0',children=["
  1277. "{name='country',type='" NS "QLocale::Country',value='-'},"
  1278. "{name='language',type='" NS "QLocale::Language',value='-'},"
  1279. "{name='measurementSystem',type='" NS "QLocale::MeasurementSystem',"
  1280. "value='-'},"
  1281. "{name='numberOptions',type='" NS "QFlags<myns::QLocale::NumberOption>',"
  1282. "value='-'},"
  1283. "{name='timeFormat_(short)',type='" NS "QString',"
  1284. + specQString(loc.timeFormat(QLocale::ShortFormat)) + "},"
  1285. "{name='timeFormat_(long)',type='" NS "QString',"
  1286. + specQString(loc.timeFormat()) + "},"
  1287. "{name='decimalPoint'," + specQChar(loc.decimalPoint()) + "},"
  1288. "{name='exponential'," + specQChar(loc.exponential()) + "},"
  1289. "{name='percent'," + specQChar(loc.percent()) + "},"
  1290. "{name='zeroDigit'," + specQChar(loc.zeroDigit()) + "},"
  1291. "{name='groupSeparator'," + specQChar(loc.groupSeparator()) + "},"
  1292. "{name='negativeSign'," + specQChar(loc.negativeSign()) + "}]";
  1293. }
  1294. void tst_Gdb::dump_QLocale()
  1295. {
  1296. QLocale german(QLocale::German);
  1297. QLocale chinese(QLocale::Chinese);
  1298. QLocale swahili(QLocale::Swahili);
  1299. prepare("dump_QLocale");
  1300. if (checkUninitialized)
  1301. check("A","{iname='local.english',name='english',"
  1302. "type='" NS "QLocale',value='<invalid>',"
  1303. "numchild='0'}");
  1304. next(3);
  1305. check("C", "{iname='local.german',name='german',"
  1306. + dump_QLocaleHelper(german) + "},"
  1307. "{iname='local.chinese',name='chinese',"
  1308. + dump_QLocaleHelper(chinese) + "},"
  1309. "{iname='local.swahili',name='swahili',"
  1310. + dump_QLocaleHelper(swahili) + "}",
  1311. "local.german,local.chinese,local.swahili");
  1312. }
  1313. ///////////////////////////// QHash<int, int> //////////////////////////////
  1314. void dump_QHash_int_int()
  1315. {
  1316. /* A */ QHash<int, int> h;
  1317. /* B */ h[43] = 44;
  1318. /* C */ h[45] = 46;
  1319. /* D */ (void) 0;
  1320. }
  1321. void tst_Gdb::dump_QHash_int_int()
  1322. {
  1323. // Need to check the following combinations:
  1324. // int-key optimization, small value
  1325. //struct NodeOS { void *next; uint k; uint v; } nodeOS
  1326. // int-key optimiatzion, large value
  1327. //struct NodeOL { void *next; uint k; void *v; } nodeOL
  1328. // no optimization, small value
  1329. //struct NodeNS + { void *next; uint h; uint k; uint v; } nodeNS
  1330. // no optimization, large value
  1331. //struct NodeNL { void *next; uint h; uint k; void *v; } nodeNL
  1332. // complex key
  1333. //struct NodeL { void *next; uint h; void *k; void *v; } nodeL
  1334. prepare("dump_QHash_int_int");
  1335. if (checkUninitialized)
  1336. check("A","{iname='local.h',name='h',"
  1337. "type='" NS "QHash<int, int>',value='<invalid>',"
  1338. "numchild='0'}");
  1339. next(3);
  1340. check("D","{iname='local.h',name='h',"
  1341. "type='" NS "QHash<int, int>',value='<2 items>',numchild='2',"
  1342. "childtype='int',childnumchild='0',children=["
  1343. "{name='43',value='44'},"
  1344. "{name='45',value='46'}]}",
  1345. "local.h");
  1346. }
  1347. ///////////////////////////// QHash<QString, QString> //////////////////////////////
  1348. void dump_QHash_QString_QString()
  1349. {
  1350. /* A */ QHash<QString, QString> h;
  1351. /* B */ h["hello"] = "world";
  1352. /* C */ h["foo"] = "bar";
  1353. /* D */ (void) 0;
  1354. }
  1355. void tst_Gdb::dump_QHash_QString_QString()
  1356. {
  1357. prepare("dump_QHash_QString_QString");
  1358. if (checkUninitialized)
  1359. check("A","{iname='local.h',name='h',"
  1360. "type='" NS "QHash<" NS "QString, " NS "QString>',value='<invalid>',"
  1361. "numchild='0'}");
  1362. next();
  1363. check("B","{iname='local.h',name='h',"
  1364. "type='" NS "QHash<" NS "QString, " NS "QString>',value='<0 items>',"
  1365. "numchild='0'}");
  1366. next();
  1367. next();
  1368. check("D","{iname='local.h',name='h',"
  1369. "type='" NS "QHash<" NS "QString, " NS "QString>',value='<2 items>',"
  1370. "numchild='2'}");
  1371. check("D","{iname='local.h',name='h',"
  1372. "type='" NS "QHash<" NS "QString, " NS "QString>',value='<2 items>',"
  1373. "numchild='2',childtype='" NS "QHashNode<" NS "QString, " NS "QString>',"
  1374. "children=["
  1375. "{value=' ',numchild='2',children=[{name='key',type='" NS "QString',"
  1376. "valueencoded='7',value='66006f006f00',numchild='0'},"
  1377. "{name='value',type='" NS "QString',"
  1378. "valueencoded='7',value='620061007200',numchild='0'}]},"
  1379. "{value=' ',numchild='2',children=[{name='key',type='" NS "QString',"
  1380. "valueencoded='7',value='680065006c006c006f00',numchild='0'},"
  1381. "{name='value',type='" NS "QString',valueencoded='7',"
  1382. "value='77006f0072006c006400',numchild='0'}]}"
  1383. "]}",
  1384. "local.h,local.h.0,local.h.1");
  1385. }
  1386. ///////////////////////////// QLinkedList<int> ///////////////////////////////////
  1387. void dump_QLinkedList_int()
  1388. {
  1389. /* A */ QLinkedList<int> h;
  1390. /* B */ h.append(42);
  1391. /* C */ h.append(44);
  1392. /* D */ (void) 0; }
  1393. void tst_Gdb::dump_QLinkedList_int()
  1394. {
  1395. prepare("dump_QLinkedList_int");
  1396. if (checkUninitialized)
  1397. check("A","{iname='local.h',name='h',"
  1398. "type='" NS "QLinkedList<int>',value='<invalid>',"
  1399. "numchild='0'}");
  1400. next(3);
  1401. check("D","{iname='local.h',name='h',"
  1402. "type='" NS "QLinkedList<int>',value='<2 items>',numchild='2',"
  1403. "childtype='int',childnumchild='0',children=["
  1404. "{value='42'},{value='44'}]}", "local.h");
  1405. }
  1406. ///////////////////////////// QList<int> /////////////////////////////////
  1407. void dump_QList_int()
  1408. {
  1409. /* A */ QList<int> list;
  1410. /* B */ list.append(1);
  1411. /* C */ list.append(2);
  1412. /* D */ (void) 0;
  1413. }
  1414. void tst_Gdb::dump_QList_int()
  1415. {
  1416. prepare("dump_QList_int");
  1417. if (checkUninitialized)
  1418. check("A","{iname='local.list',name='list',"
  1419. "type='" NS "QList<int>',value='<invalid>',numchild='0'}");
  1420. next();
  1421. check("B","{iname='local.list',name='list',"
  1422. "type='" NS "QList<int>',value='<0 items>',numchild='0'}");
  1423. next();
  1424. check("C","{iname='local.list',name='list',"
  1425. "type='" NS "QList<int>',value='<1 items>',numchild='1'}");
  1426. check("C","{iname='local.list',name='list',"
  1427. "type='" NS "QList<int>',value='<1 items>',numchild='1',"
  1428. "childtype='int',childnumchild='0',children=["
  1429. "{value='1'}]}", "local.list");
  1430. next();
  1431. check("D","{iname='local.list',name='list',"
  1432. "type='" NS "QList<int>',value='<2 items>',numchild='2'}");
  1433. check("D","{iname='local.list',name='list',"
  1434. "type='" NS "QList<int>',value='<2 items>',numchild='2',"
  1435. "childtype='int',childnumchild='0',children=["
  1436. "{value='1'},{value='2'}]}", "local.list");
  1437. }
  1438. ///////////////////////////// QList<int *> /////////////////////////////////
  1439. void dump_QList_int_star()
  1440. {
  1441. /* A */ QList<int *> list;
  1442. /* B */ list.append(new int(1));
  1443. /* C */ list.append(0);
  1444. /* D */ list.append(new int(2));
  1445. /* E */ (void) 0;
  1446. }
  1447. void tst_Gdb::dump_QList_int_star()
  1448. {
  1449. prepare("dump_QList_int_star");
  1450. if (checkUninitialized)
  1451. check("A","{iname='local.list',name='list',"
  1452. "type='" NS "QList<int*>',value='<invalid>',numchild='0'}");
  1453. next();
  1454. next();
  1455. next();
  1456. next();
  1457. check("E","{iname='local.list',name='list',"
  1458. "type='" NS "QList<int*>',value='<3 items>',numchild='3',"
  1459. "childtype='int',childnumchild='0',children=["
  1460. "{value='1'},{value='0x0',type='int *'},{value='2'}]}", "local.list");
  1461. }
  1462. ///////////////////////////// QList<char> /////////////////////////////////
  1463. void dump_QList_char()
  1464. {
  1465. /* A */ QList<char> list;
  1466. /* B */ list.append('a');
  1467. /* C */ (void) 0;
  1468. }
  1469. void tst_Gdb::dump_QList_char()
  1470. {
  1471. prepare("dump_QList_char");
  1472. if (checkUninitialized)
  1473. check("A","{iname='local.list',name='list',"
  1474. "type='" NS "QList<char>',value='<invalid>',numchild='0'}");
  1475. next();
  1476. check("B","{iname='local.list',name='list',"
  1477. "type='" NS "QList<char>',value='<0 items>',numchild='0'}");
  1478. next();
  1479. check("C","{iname='local.list',name='list',"
  1480. "type='" NS "QList<char>',value='<1 items>',numchild='1'}");
  1481. check("C","{iname='local.list',name='list',"
  1482. "type='" NS "QList<char>',value='<1 items>',numchild='1',"
  1483. "childtype='char',childnumchild='0',children=["
  1484. "{value='97 'a''}]}", "local.list");
  1485. }
  1486. ///////////////////////////// QList<const char *> /////////////////////////////////
  1487. void dump_QList_char_star()
  1488. {
  1489. /* A */ QList<const char *> list;
  1490. /* B */ list.append("a");
  1491. /* C */ list.append(0);
  1492. /* D */ list.append("bc");
  1493. /* E */ (void) 0;
  1494. }
  1495. void tst_Gdb::dump_QList_char_star()
  1496. {
  1497. prepare("dump_QList_char_star");
  1498. if (checkUninitialized)
  1499. check("A","{iname='local.list',name='list',"
  1500. "type='" NS "QList<char const*>',value='<invalid>',numchild='0'}");
  1501. next();
  1502. check("B","{iname='local.list',name='list',"
  1503. "type='" NS "QList<char const*>',value='<0 items>',numchild='0'}");
  1504. next();
  1505. check("C","{iname='local.list',name='list',"
  1506. "type='" NS "QList<char const*>',value='<1 items>',numchild='1'}");
  1507. check("C","{iname='local.list',name='list',"
  1508. "type='" NS "QList<char const*>',value='<1 items>',numchild='1',"
  1509. "childtype='const char *',childnumchild='1',children=["
  1510. "{valueencoded='6',value='61',numchild='0'}]}", "local.list");
  1511. next();
  1512. next();
  1513. check("E","{iname='local.list',name='list',"
  1514. "type='" NS "QList<char const*>',value='<3 items>',numchild='3',"
  1515. "childtype='const char *',childnumchild='1',children=["
  1516. "{valueencoded='6',value='61',numchild='0'},"
  1517. "{value='0x0',numchild='0'},"
  1518. "{valueencoded='6',value='6263',numchild='0'}]}", "local.list");
  1519. }
  1520. ///////////////////////////// QList<QString> /////////////////////////////////////
  1521. void dump_QList_QString()
  1522. {
  1523. /* A */ QList<QString> list;
  1524. /* B */ list.append("Hallo");
  1525. /* C */ (void) 0;
  1526. }
  1527. void tst_Gdb::dump_QList_QString()
  1528. {
  1529. prepare("dump_QList_QString");
  1530. if (0 && checkUninitialized)
  1531. check("A","{iname='local.list',name='list',"
  1532. "type='" NS "QList<" NS "QString>',value='<invalid>',numchild='0'}");
  1533. next();
  1534. check("B","{iname='local.list',name='list',"
  1535. "type='" NS "QList<" NS "QString>',value='<0 items>',numchild='0'}");
  1536. next();
  1537. check("C","{iname='local.list',name='list',"
  1538. "type='" NS "QList<" NS "QString>',value='<1 items>',numchild='1'}");
  1539. check("C","{iname='local.list',name='list',"
  1540. "type='" NS "QList<" NS "QString>',value='<1 items>',numchild='1',"
  1541. "childtype='" NS "QString',childnumchild='0',children=["
  1542. "{valueencoded='7',value='480061006c006c006f00'}]}", "local.list");
  1543. }
  1544. ///////////////////////////// QList<QString3> ///////////////////////////////////
  1545. void dump_QList_QString3()
  1546. {
  1547. /* A */ QList<QString3> list;
  1548. /* B */ list.append(QString3());
  1549. /* C */ (void) 0;
  1550. }
  1551. void tst_Gdb::dump_QList_QString3()
  1552. {
  1553. prepare("dump_QList_QString3");
  1554. if (checkUninitialized)
  1555. check("A","{iname='local.list',name='list',"
  1556. "type='" NS "QList<QString3>',value='<invalid>',numchild='0'}");
  1557. next();
  1558. check("B","{iname='local.list',name='list',"
  1559. "type='" NS "QList<QString3>',value='<0 items>',numchild='0'}");
  1560. next();
  1561. check("C","{iname='local.list',name='list',"
  1562. "type='" NS "QList<QString3>',value='<1 items>',numchild='1'}");
  1563. check("C","{iname='local.list',name='list',"
  1564. "type='" NS "QList<QString3>',value='<1 items>',numchild='1',"
  1565. "childtype='QString3',children=["
  1566. "{value='{...}',numchild='3'}]}", "local.list");
  1567. check("C","{iname='local.list',name='list',"
  1568. "type='" NS "QList<QString3>',value='<1 items>',numchild='1',"
  1569. "childtype='QString3',children=[{value='{...}',numchild='3',children=["
  1570. "{name='s1',type='" NS "QString',"
  1571. "valueencoded='7',value='6100',numchild='0'},"
  1572. "{name='s2',type='" NS "QString',"
  1573. "valueencoded='7',value='6200',numchild='0'},"
  1574. "{name='s3',type='" NS "QString',"
  1575. "valueencoded='7',value='6300',numchild='0'}]}]}",
  1576. "local.list,local.list.0");
  1577. }
  1578. ///////////////////////////// QList<Int3> /////////////////////////////////////
  1579. void dump_QList_Int3()
  1580. {
  1581. /* A */ QList<Int3> list;
  1582. /* B */ list.append(Int3());
  1583. /* C */ (void) 0;
  1584. }
  1585. void tst_Gdb::dump_QList_Int3()
  1586. {
  1587. prepare("dump_QList_Int3");
  1588. if (checkUninitialized)
  1589. check("A","{iname='local.list',name='list',"
  1590. "type='" NS "QList<Int3>',value='<invalid>',numchild='0'}");
  1591. next();
  1592. check("B","{iname='local.list',name='list',"
  1593. "type='" NS "QList<Int3>',value='<0 items>',numchild='0'}");
  1594. next();
  1595. check("C","{iname='local.list',name='list',"
  1596. "type='" NS "QList<Int3>',value='<1 items>',numchild='1'}");
  1597. check("C","{iname='local.list',name='list',"
  1598. "type='" NS "QList<Int3>',value='<1 items>',numchild='1',"
  1599. "childtype='Int3',children=[{value='{...}',numchild='3'}]}",
  1600. "local.list");
  1601. check("C","{iname='local.list',name='list',"
  1602. "type='" NS "QList<Int3>',value='<1 items>',numchild='1',"
  1603. "childtype='Int3',children=[{value='{...}',numchild='3',children=["
  1604. "{name='i1',type='int',value='42',numchild='0'},"
  1605. "{name='i2',type='int',value='43',numchild='0'},"
  1606. "{name='i3',type='int',value='44',numchild='0'}]}]}",
  1607. "local.list,local.list.0");
  1608. }
  1609. ///////////////////////////// QMap<int, int> //////////////////////////////
  1610. void dump_QMap_int_int()
  1611. {
  1612. /* A */ QMap<int, int> h;
  1613. /* B */ h[12] = 34;
  1614. /* C */ h[14] = 54;
  1615. /* D */ (void) 0;
  1616. }
  1617. void tst_Gdb::dump_QMap_int_int()
  1618. {
  1619. prepare("dump_QMap_int_int");
  1620. if (checkUninitialized)
  1621. check("A","{iname='local.h',name='h',"
  1622. "type='" NS "QMap<int, int>',value='<invalid>',"
  1623. "numchild='0'}");
  1624. next();
  1625. check("B","{iname='local.h',name='h',"
  1626. "type='" NS "QMap<int, int>',value='<0 items>',"
  1627. "numchild='0'}");
  1628. next();
  1629. next();
  1630. check("D","{iname='local.h',name='h',"
  1631. "type='" NS "QMap<int, int>',value='<2 items>',"
  1632. "numchild='2'}");
  1633. check("D","{iname='local.h',name='h',"
  1634. "type='" NS "QMap<int, int>',value='<2 items>',"
  1635. "numchild='2',childtype='int',childnumchild='0',"
  1636. "children=[{name='12',value='34'},{name='14',value='54'}]}",
  1637. "local.h,local.h.0,local.h.1");
  1638. }
  1639. ///////////////////////////// QMap<QString, QString> //////////////////////////////
  1640. void dump_QMap_QString_QString()
  1641. {
  1642. /* A */ QMap<QString, QString> m;
  1643. /* B */ m["hello"] = "world";
  1644. /* C */ m["foo"] = "bar";
  1645. /* D */ (void) 0;
  1646. }
  1647. void tst_Gdb::dump_QMap_QString_QString()
  1648. {
  1649. prepare("dump_QMap_QString_QString");
  1650. if (checkUninitialized)
  1651. check("A","{iname='local.m',name='m',"
  1652. "type='" NS "QMap<" NS "QString, " NS "QString>',value='<invalid>',"
  1653. "numchild='0'}");
  1654. next();
  1655. check("B","{iname='local.m',name='m',"
  1656. "type='" NS "QMap<" NS "QString, " NS "QString>',value='<0 items>',"
  1657. "numchild='0'}");
  1658. next();
  1659. next();
  1660. check("D","{iname='local.m',name='m',"
  1661. "type='" NS "QMap<" NS "QString, " NS "QString>',value='<2 items>',"
  1662. "numchild='2'}");
  1663. check("D","{iname='local.m',name='m',"
  1664. "type='" NS "QMap<" NS "QString, " NS "QString>',value='<2 items>',"
  1665. "numchild='2',childtype='" NS "QMapNode<" NS "QString, " NS "QString>',"
  1666. "children=["
  1667. "{value=' ',numchild='2',children=[{name='key',type='" NS "QString',"
  1668. "valueencoded='7',value='66006f006f00',numchild='0'},"
  1669. "{name='value',type='" NS "QString',"
  1670. "valueencoded='7',value='620061007200',numchild='0'}]},"
  1671. "{value=' ',numchild='2',children=[{name='key',type='" NS "QString',"
  1672. "valueencoded='7',value='680065006c006c006f00',numchild='0'},"
  1673. "{name='value',type='" NS "QString',valueencoded='7',"
  1674. "value='77006f0072006c006400',numchild='0'}]}"
  1675. "]}",
  1676. "local.m,local.m.0,local.m.1");
  1677. }
  1678. ///////////////////////////// QObject /////////////////////////////////
  1679. void dump_QObject()
  1680. {
  1681. /* B */ QObject ob;
  1682. /* D */ ob.setObjectName("An Object");
  1683. /* E */ QObject::connect(&ob, SIGNAL(destroyed()), qApp, SLOT(quit()));
  1684. /* F */ QObject::disconnect(&ob, SIGNAL(destroyed()), qApp, SLOT(quit()));
  1685. /* G */ ob.setObjectName("A renamed Object");
  1686. /* H */ (void) 0; }
  1687. void dump_QObject1()
  1688. {
  1689. /* A */ QObject parent;
  1690. /* B */ QObject child(&parent);
  1691. /* C */ parent.setObjectName("A Parent");
  1692. /* D */ child.setObjectName("A Child");
  1693. /* H */ (void) 0; }
  1694. void tst_Gdb::dump_QObject()
  1695. {
  1696. prepare("dump_QObject");
  1697. if (checkUninitialized)
  1698. check("A","{iname='local.ob',name='ob',"
  1699. "type='" NS "QObject',value='<invalid>',"
  1700. "numchild='0'}");
  1701. next(4);
  1702. check("G","{iname='local.ob',name='ob',type='" NS "QObject',valueencoded='7',"
  1703. "value='41006e0020004f0062006a00650063007400',numchild='4',children=["
  1704. "{name='parent',value='0x0',type='" NS "QObject *',"
  1705. "numchild='0'},"
  1706. "{name='children',type='-'," // NS"QObject{Data,}::QObjectList',"
  1707. "value='<0 items>',numchild='0',children=[]},"
  1708. "{name='properties',value='<1 items>',type=' ',numchild='1',children=["
  1709. "{name='objectName',type='" NS "QString',valueencoded='7',"
  1710. "value='41006e0020004f0062006a00650063007400',numchild='0'}]},"
  1711. "{name='connections',value='<0 items>',type=' ',numchild='0',"
  1712. "children=[]},"
  1713. "{name='signals',value='<2 items>',type=' ',numchild='2',"
  1714. "childnumchild='0',children=["
  1715. "{name='signal 0',type=' ',value='destroyed(QObject*)'},"
  1716. "{name='signal 1',type=' ',value='destroyed()'}]},"
  1717. "{name='slots',value='<2 items>',type=' ',numchild='2',"
  1718. "childnumchild='0',children=["
  1719. "{name='slot 0',type=' ',value='deleteLater()'},"
  1720. "{name='slot 1',type=' ',value='_q_reregisterTimers(void*)'}]}]}",
  1721. "local.ob"
  1722. ",local.ob.children"
  1723. ",local.ob.properties"
  1724. ",local.ob.connections"
  1725. ",local.ob.signals"
  1726. ",local.ob.slots"
  1727. );
  1728. #if 0
  1729. testDumper("value='',valueencoded='2',type='$T',displayedtype='QObject',"
  1730. "numchild='4'",
  1731. &parent, NS"QObject", false);
  1732. testDumper("value='',valueencoded='2',type='$T',displayedtype='QObject',"
  1733. "numchild='4',children=["
  1734. "{name='properties',addr='$A',type='$TPropertyList',"
  1735. "value='<1 items>',numchild='1'},"
  1736. "{name='signals',addr='$A',type='$TSignalList',"
  1737. "value='<2 items>',numchild='2'},"
  1738. "{name='slots',addr='$A',type='$TSlotList',"
  1739. "value='<2 items>',numchild='2'},"
  1740. "{name='parent',value='0x0',type='$T *',numchild='0'},"
  1741. "{name='className',value='QObject',type='',numchild='0'}]",
  1742. &parent, NS"QObject", true);
  1743. #if 0
  1744. testDumper("numchild='2',value='<2 items>',type='QObjectSlotList',"
  1745. "children=[{name='2',value='deleteLater()',"
  1746. "numchild='0',addr='$A',type='QObjectSlot'},"
  1747. "{name='3',value='_q_reregisterTimers(void*)',"
  1748. "numchild='0',addr='$A',type='QObjectSlot'}]",
  1749. &parent, NS"QObjectSlotList", true);
  1750. #endif
  1751. parent.setObjectName("A Parent");
  1752. testDumper("value='QQAgAFAAYQByAGUAbgB0AA==',valueencoded='2',type='$T',"
  1753. "displayedtype='QObject',numchild='4'",
  1754. &parent, NS"QObject", false);
  1755. QObject child(&parent);
  1756. testDumper("value='',valueencoded='2',type='$T',"
  1757. "displayedtype='QObject',numchild='4'",
  1758. &child, NS"QObject", false);
  1759. child.setObjectName("A Child");
  1760. QByteArray ba ="value='QQAgAEMAaABpAGwAZAA=',valueencoded='2',type='$T',"
  1761. "displayedtype='QObject',numchild='4',children=["
  1762. "{name='properties',addr='$A',type='$TPropertyList',"
  1763. "value='<1 items>',numchild='1'},"
  1764. "{name='signals',addr='$A',type='$TSignalList',"
  1765. "value='<2 items>',numchild='2'},"
  1766. "{name='slots',addr='$A',type='$TSlotList',"
  1767. "value='<2 items>',numchild='2'},"
  1768. "{name='parent',addr='" + str(&parent) + "',"
  1769. "value='QQAgAFAAYQByAGUAbgB0AA==',valueencoded='2',type='$T',"
  1770. "displayedtype='QObject',numchild='1'},"
  1771. "{name='className',value='QObject',type='',numchild='0'}]";
  1772. testDumper(ba, &child, NS"QObject", true);
  1773. connect(&child, SIGNAL(destroyed()), qApp, SLOT(quit()));
  1774. testDumper(ba, &child, NS"QObject", true);
  1775. disconnect(&child, SIGNAL(destroyed()), qApp, SLOT(quit()));
  1776. testDumper(ba, &child, NS"QObject", true);
  1777. child.setObjectName("A renamed Child");
  1778. testDumper("value='QQAgAHIAZQBuAGEAbQBlAGQAIABDAGgAaQBsAGQA',valueencoded='2',"
  1779. "type='$T',displayedtype='QObject',numchild='4'",
  1780. &child, NS"QObject", false);
  1781. #endif
  1782. }
  1783. #if 0
  1784. void tst_Gdb::dump_QObjectChildListHelper(QObject &o)
  1785. {
  1786. const QObjectList children = o.children();
  1787. const int size = children.size();
  1788. const QString sizeStr = N(size);
  1789. QByteArray expected = QByteArray("numchild='").append(sizeStr).append("',value='<").
  1790. append(sizeStr).append(" items>',type='" NS "QObjectChildList',children=[");
  1791. for (int i = 0; i < size; ++i) {
  1792. const QObject *child = children.at(i);
  1793. expected.append("{addr='").append(ptrToBa(child)).append("',value='").
  1794. append(utfToHex(child->objectName())).
  1795. append("',valueencoded='2',type='" NS "QObject',displayedtype='").
  1796. append(child->metaObject()->className()).append("',numchild='1'}");
  1797. if (i < size - 1)
  1798. expected.append(",");
  1799. }
  1800. expected.append("]");
  1801. testDumper(expected, &o, NS"QObjectChildList", true);
  1802. }
  1803. void tst_Gdb::dump_QObjectChildList()
  1804. {
  1805. // Case 1: Object with no children.
  1806. QObject o;
  1807. dump_QObjectChildListHelper(o);
  1808. // Case 2: Object with one child.
  1809. QObject o2(&o);
  1810. dump_QObjectChildListHelper(o);
  1811. // Case 3: Object with two children.
  1812. QObject o3(&o);
  1813. dump_QObjectChildListHelper(o);
  1814. }
  1815. void tst_Gdb::dump_QObjectMethodList()
  1816. {
  1817. QStringListModel m;
  1818. testDumper("addr='<synthetic>',type='$T',numchild='20',"
  1819. "childtype='" NS "QMetaMethod::Method',childnumchild='0',children=["
  1820. "{name='0 0 destroyed(QObject*)',value='<Signal> (1)'},"
  1821. "{name='1 1 destroyed()',value='<Signal> (1)'},"
  1822. "{name='2 2 deleteLater()',value='<Slot> (2)'},"
  1823. "{name='3 3 _q_reregisterTimers(void*)',value='<Slot> (2)'},"
  1824. "{name='4 4 dataChanged(QModelIndex,QModelIndex)',value='<Signal> (1)'},"
  1825. "{name='5 5 headerDataChanged(Qt::Orientation,int,int)',value='<Signal> (1)'},"
  1826. "{name='6 6 layoutChanged()',value='<Signal> (1)'},"
  1827. "{name='7 7 layoutAboutToBeChanged()',value='<Signal> (1)'},"
  1828. "{name='8 8 rowsAboutToBeInserted(QModelIndex,int,int)',value='<Signal> (1)'},"
  1829. "{name='9 9 rowsInserted(QModelIndex,int,int)',value='<Signal> (1)'},"
  1830. "{name='10 10 rowsAboutToBeRemoved(QModelIndex,int,int)',value='<Signal> (1)'},"
  1831. "{name='11 11 rowsRemoved(QModelIndex,int,int)',value='<Signal> (1)'},"
  1832. "{name='12 12 columnsAboutToBeInserted(QModelIndex,int,int)',value='<Signal> (1)'},"
  1833. "{name='13 13 columnsInserted(QModelIndex,int,int)',value='<Signal> (1)'},"
  1834. "{name='14 14 columnsAboutToBeRemoved(QModelIndex,int,int)',value='<Signal> (1)'},"
  1835. "{name='15 15 columnsRemoved(QModelIndex,int,int)',value='<Signal> (1)'},"
  1836. "{name='16 16 modelAboutToBeReset()',value='<Signal> (1)'},"
  1837. "{name='17 17 modelReset()',value='<Signal> (1)'},"
  1838. "{name='18 18 submit()',value='<Slot> (2)'},"
  1839. "{name='19 19 revert()',value='<Slot> (2)'}]",
  1840. &m, NS"QObjectMethodList", true);
  1841. }
  1842. void tst_Gdb::dump_QObjectPropertyList()
  1843. {
  1844. // Case 1: Model without a parent.
  1845. QStringListModel m(QStringList() << "Test1" << "Test2");
  1846. testDumper("addr='<synthetic>',type='$T',numchild='1',value='<1 items>',"
  1847. "children=[{name='objectName',type='QString',value='',"
  1848. "valueencoded='2',numchild='0'}]",
  1849. &m, NS"QObjectPropertyList", true);
  1850. // Case 2: Model with a parent.
  1851. QStringListModel m2(&m);
  1852. testDumper("addr='<synthetic>',type='$T',numchild='1',value='<1 items>',"
  1853. "children=[{name='objectName',type='QString',value='',"
  1854. "valueencoded='2',numchild='0'}]",
  1855. &m2, NS"QObjectPropertyList", true);
  1856. }
  1857. static const char *connectionType(uint type)
  1858. {
  1859. Qt::ConnectionType connType = static_cast<Qt::ConnectionType>(type);
  1860. const char *output = "unknown";
  1861. switch (connType) {
  1862. case Qt::AutoConnection: output = "auto"; break;
  1863. case Qt::DirectConnection: output = "direct"; break;
  1864. case Qt::QueuedConnection: output = "queued"; break;
  1865. case Qt::BlockingQueuedConnection: output = "blockingqueued"; break;
  1866. case 3: output = "autocompat"; break;
  1867. #if QT_VERSION >= 0x040600
  1868. case Qt::UniqueConnection: break; // Can't happen.
  1869. #endif
  1870. default:
  1871. qWarning() << "Unknown connection type: " << type;
  1872. break;
  1873. };
  1874. return output;
  1875. };
  1876. class Cheater : public QObject
  1877. {
  1878. public:
  1879. static const QObjectPrivate *getPrivate(const QObject &o)
  1880. {
  1881. const Cheater &cheater = static_cast<const Cheater&>(o);
  1882. #if QT_VERSION >= 0x040600
  1883. return dynamic_cast<const QObjectPrivate *>(cheater.d_ptr.data());
  1884. #else
  1885. return dynamic_cast<const QObjectPrivate *>(cheater.d_ptr);
  1886. #endif
  1887. }
  1888. };
  1889. typedef QVector<QObjectPrivate::ConnectionList> ConnLists;
  1890. void tst_Gdb::dump_QObjectSignalHelper(QObject &o, int sigNum)
  1891. {
  1892. //qDebug() << o.objectName() << sigNum;
  1893. QByteArray expected("addr='<synthetic>',numchild='1',type='" NS "QObjectSignal'");
  1894. #if QT_VERSION >= 0x040400
  1895. expected.append(",children=[");
  1896. const QObjectPrivate *p = Cheater::getPrivate(o);
  1897. Q_ASSERT(p != 0);
  1898. const ConnLists *connLists = reinterpret_cast<const ConnLists *>(p->connectionLists);
  1899. QObjectPrivate::ConnectionList connList =
  1900. connLists != 0 && connLists->size() > sigNum ?
  1901. connLists->at(sigNum) : QObjectPrivate::ConnectionList();
  1902. int i = 0;
  1903. for (QObjectPrivate::Connection *conn = connList.first; conn != 0;
  1904. ++i, conn = conn->nextConnectionList) {
  1905. const QString iStr = N(i);
  1906. expected.append("{name='").append(iStr).append(" receiver',");
  1907. if (conn->receiver == &o)
  1908. expected.append("value='<this>',type='").
  1909. append(o.metaObject()->className()).
  1910. append("',numchild='0',addr='").append(ptrToBa(&o)).append("'");
  1911. else if (conn->receiver == 0)
  1912. expected.append("value='0x0',type='" NS "QObject *',numchild='0'");
  1913. else
  1914. expected.append("addr='").append(ptrToBa(conn->receiver)).append("',value='").
  1915. append(utfToHex(conn->receiver->objectName())).append("',valueencoded='2',").
  1916. append("type='" NS "QObject',displayedtype='").
  1917. append(conn->receiver->metaObject()->className()).append("',numchild='1'");
  1918. expected.append("},{name='").append(iStr).append(" slot',type='',value='");
  1919. if (conn->receiver != 0)
  1920. expected.append(conn->receiver->metaObject()->method(conn->method).signature());
  1921. else
  1922. expected.append("<invalid receiver>");
  1923. expected.append("',numchild='0'},{name='").append(iStr).append(" type',type='',value='<").
  1924. append(connectionType(conn->connectionType)).append(" connection>',").
  1925. append("numchild='0'}");
  1926. if (conn != connList.last)
  1927. expected.append(",");
  1928. }
  1929. expected.append("],numchild='").append(N(i)).append("'");
  1930. #endif
  1931. testDumper(expected, &o, NS"QObjectSignal", true, "", "", sigNum);
  1932. }
  1933. void tst_Gdb::dump_QObjectSignal()
  1934. {
  1935. // Case 1: Simple QObject.
  1936. QObject o;
  1937. o.setObjectName("Test");
  1938. testDumper("addr='<synthetic>',numchild='1',type='" NS "QObjectSignal',"
  1939. "children=[],numchild='0'",
  1940. &o, NS"QObjectSignal", true, "", "", 0);
  1941. // Case 2: QAbstractItemModel with no connections.
  1942. QStringListModel m(QStringList() << "Test1" << "Test2");
  1943. for (int signalIndex = 0; signalIndex < 17; ++signalIndex)
  1944. dump_QObjectSignalHelper(m, signalIndex);
  1945. // Case 3: QAbstractItemModel with connections to itself and to another
  1946. // object, using different connection types.
  1947. qRegisterMetaType<QModelIndex>("QModelIndex");
  1948. connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
  1949. &o, SLOT(deleteLater()), Qt::DirectConnection);
  1950. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  1951. &m, SLOT(revert()), Qt::QueuedConnection);
  1952. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  1953. &m, SLOT(submit()), Qt::QueuedConnection);
  1954. connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)),
  1955. &m, SLOT(submit()), Qt::BlockingQueuedConnection);
  1956. connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)),
  1957. &m, SLOT(deleteLater()), Qt::AutoConnection);
  1958. #if QT_VERSION >= 0x040600
  1959. connect(&m, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  1960. &m, SLOT(revert()), Qt::UniqueConnection);
  1961. #endif
  1962. for (int signalIndex = 0; signalIndex < 17; ++signalIndex)
  1963. dump_QObjectSignalHelper(m, signalIndex);
  1964. }
  1965. void tst_Gdb::dump_QObjectSignalList()
  1966. {
  1967. // Case 1: Simple QObject.
  1968. QObject o;
  1969. o.setObjectName("Test");
  1970. testDumper("type='" NS "QObjectSignalList',value='<2 items>',"
  1971. "addr='$A',numchild='2',children=["
  1972. "{name='0',value='destroyed(QObject*)',numchild='0',"
  1973. "addr='$A',type='" NS "QObjectSignal'},"
  1974. "{name='1',value='destroyed()',numchild='0',"
  1975. "addr='$A',type='" NS "QObjectSignal'}]",
  1976. &o, NS"QObjectSignalList", true);
  1977. // Case 2: QAbstractItemModel with no connections.
  1978. QStringListModel m(QStringList() << "Test1" << "Test2");
  1979. QByteArray expected = "type='" NS "QObjectSignalList',value='<16 items>',"
  1980. "addr='$A',numchild='16',children=["
  1981. "{name='0',value='destroyed(QObject*)',numchild='0',"
  1982. "addr='$A',type='" NS "QObjectSignal'},"
  1983. "{name='1',value='destroyed()',numchild='0',"
  1984. "addr='$A',type='" NS "QObjectSignal'},"
  1985. "{name='4',value='dataChanged(QModelIndex,QModelIndex)',numchild='0',"
  1986. "addr='$A',type='" NS "QObjectSignal'},"
  1987. "{name='5',value='headerDataChanged(Qt::Orientation,int,int)',"
  1988. "numchild='0',addr='$A',type='" NS "QObjectSignal'},"
  1989. "{name='6',value='layoutChanged()',numchild='0',"
  1990. "addr='$A',type='" NS "QObjectSignal'},"
  1991. "{name='7',value='layoutAboutToBeChanged()',numchild='0',"
  1992. "addr='$A',type='" NS "QObjectSignal'},"
  1993. "{name='8',value='rowsAboutToBeInserted(QModelIndex,int,int)',"
  1994. "numchild='0',addr='$A',type='" NS "QObjectSignal'},"
  1995. "{name='9',value='rowsInserted(QModelIndex,int,int)',"
  1996. "numchild='0',addr='$A',type='" NS "QObjectSignal'},"
  1997. "{name='10',value='rowsAboutToBeRemoved(QModelIndex,int,int)',"
  1998. "numchild='%',addr='$A',type='" NS "QObjectSignal'},"
  1999. "{name='11',value='rowsRemoved(QModelIndex,int,int)',"
  2000. "numchild='%',addr='$A',type='" NS "QObjectSignal'},"
  2001. "{name='12',value='columnsAboutToBeInserted(QModelIndex,int,int)',"
  2002. "numchild='%',addr='$A',type='" NS "QObjectSignal'},"
  2003. "{name='13',value='columnsInserted(QModelIndex,int,int)',"
  2004. "numchild='%',addr='$A',type='" NS "QObjectSignal'},"
  2005. "{name='14',value='columnsAboutToBeRemoved(QModelIndex,int,int)',"
  2006. "numchild='%',addr='$A',type='" NS "QObjectSignal'},"
  2007. "{name='15',value='columnsRemoved(QModelIndex,int,int)',"
  2008. "numchild='%',addr='$A',type='" NS "QObjectSignal'},"
  2009. "{name='16',value='modelAboutToBeReset()',"
  2010. "numchild='0',addr='$A',type='" NS "QObjectSignal'},"
  2011. "{name='17',value='modelReset()',"
  2012. "numchild='0',addr='$A',type='" NS "QObjectSignal'}]";
  2013. testDumper(expected << "0" << "0" << "0" << "0" << "0" << "0",
  2014. &m, NS"QObjectSignalList", true);
  2015. // Case 3: QAbstractItemModel with connections to itself and to another
  2016. // object, using different connection types.
  2017. qRegisterMetaType<QModelIndex>("QModelIndex");
  2018. connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
  2019. &o, SLOT(deleteLater()), Qt::DirectConnection);
  2020. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  2021. &m, SLOT(revert()), Qt::QueuedConnection);
  2022. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  2023. &m, SLOT(submit()), Qt::QueuedConnection);
  2024. connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)),
  2025. &m, SLOT(submit()), Qt::BlockingQueuedConnection);
  2026. connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)),
  2027. &m, SLOT(deleteLater()), Qt::AutoConnection);
  2028. testDumper(expected << "1" << "1" << "2" << "1" << "0" << "0",
  2029. &m, NS"QObjectSignalList", true);
  2030. }
  2031. QByteArray slotIndexList(const QObject *ob)
  2032. {
  2033. QByteArray slotIndices;
  2034. const QMetaObject *mo = ob->metaObject();
  2035. for (int i = 0; i < mo->methodCount(); ++i) {
  2036. const QMetaMethod &mm = mo->method(i);
  2037. if (mm.methodType() == QMetaMethod::Slot) {
  2038. int slotIndex = mo->indexOfSlot(mm.signature());
  2039. Q_ASSERT(slotIndex != -1);
  2040. slotIndices.append(N(slotIndex));
  2041. slotIndices.append(',');
  2042. }
  2043. }
  2044. slotIndices.chop(1);
  2045. return slotIndices;
  2046. }
  2047. void tst_Gdb::dump_QObjectSlot()
  2048. {
  2049. // Case 1: Simple QObject.
  2050. QObject o;
  2051. o.setObjectName("Test");
  2052. QByteArray slotIndices = slotIndexList(&o);
  2053. QCOMPARE(slotIndices, QByteArray("2,3"));
  2054. QCOMPARE(o.metaObject()->indexOfSlot("deleteLater()"), 2);
  2055. QByteArray expected = QByteArray("addr='$A',numchild='1',type='$T',"
  2056. //"children=[{name='1 sender'}],numchild='1'");
  2057. "children=[],numchild='0'");
  2058. qDebug() << "FIXME!";
  2059. testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2);
  2060. // Case 2: QAbstractItemModel with no connections.
  2061. QStringListModel m(QStringList() << "Test1" << "Test2");
  2062. slotIndices = slotIndexList(&o);
  2063. QCOMPARE(slotIndices, QByteArray("2,3"));
  2064. QCOMPARE(o.metaObject()->indexOfSlot("deleteLater()"), 2);
  2065. expected = QByteArray("addr='$A',numchild='1',type='$T',"
  2066. //"children=[{name='1 sender'}],numchild='1'");
  2067. "children=[],numchild='0'");
  2068. qDebug() << "FIXME!";
  2069. testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2);
  2070. // Case 3: QAbstractItemModel with connections to itself and to another
  2071. // o, using different connection types.
  2072. qRegisterMetaType<QModelIndex>("QModelIndex");
  2073. connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
  2074. &o, SLOT(deleteLater()), Qt::DirectConnection);
  2075. connect(&o, SIGNAL(destroyed(QObject*)),
  2076. &m, SLOT(revert()), Qt::QueuedConnection);
  2077. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  2078. &m, SLOT(submit()), Qt::QueuedConnection);
  2079. connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)),
  2080. &m, SLOT(submit()), Qt::BlockingQueuedConnection);
  2081. connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)),
  2082. &m, SLOT(deleteLater()), Qt::AutoConnection);
  2083. #if QT_VERSION >= 0x040600
  2084. connect(&m, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  2085. &m, SLOT(revert()), Qt::UniqueConnection);
  2086. #endif
  2087. expected = QByteArray("addr='$A',numchild='1',type='$T',"
  2088. //"children=[{name='1 sender'}],numchild='1'");
  2089. "children=[],numchild='0'");
  2090. qDebug() << "FIXME!";
  2091. testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2);
  2092. }
  2093. void tst_Gdb::dump_QObjectSlotList()
  2094. {
  2095. // Case 1: Simple QObject.
  2096. QObject o;
  2097. o.setObjectName("Test");
  2098. testDumper("numchild='2',value='<2 items>',type='$T',"
  2099. "children=[{name='2',value='deleteLater()',numchild='0',"
  2100. "addr='$A',type='" NS "QObjectSlot'},"
  2101. "{name='3',value='_q_reregisterTimers(void*)',numchild='0',"
  2102. "addr='$A',type='" NS "QObjectSlot'}]",
  2103. &o, NS"QObjectSlotList", true);
  2104. // Case 2: QAbstractItemModel with no connections.
  2105. QStringListModel m(QStringList() << "Test1" << "Test2");
  2106. testDumper("numchild='4',value='<4 items>',type='$T',"
  2107. "children=[{name='2',value='deleteLater()',numchild='0',"
  2108. "addr='$A',type='" NS "QObjectSlot'},"
  2109. "{name='3',value='_q_reregisterTimers(void*)',numchild='0',"
  2110. "addr='$A',type='" NS "QObjectSlot'},"
  2111. "{name='18',value='submit()',numchild='0',"
  2112. "addr='$A',type='" NS "QObjectSlot'},"
  2113. "{name='19',value='revert()',numchild='0',"
  2114. "addr='$A',type='" NS "QObjectSlot'}]",
  2115. &m, NS"QObjectSlotList", true);
  2116. // Case 3: QAbstractItemModel with connections to itself and to another
  2117. // object, using different connection types.
  2118. qRegisterMetaType<QModelIndex>("QModelIndex");
  2119. connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
  2120. &o, SLOT(deleteLater()), Qt::DirectConnection);
  2121. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  2122. &m, SLOT(revert()), Qt::QueuedConnection);
  2123. connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
  2124. &m, SLOT(submit()), Qt::QueuedConnection);
  2125. connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)),
  2126. &m, SLOT(submit()), Qt::BlockingQueuedConnection);
  2127. connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)),
  2128. &m, SLOT(deleteLater()), Qt::AutoConnection);
  2129. connect(&o, SIGNAL(destroyed(QObject*)), &m, SLOT(submit()));
  2130. testDumper("numchild='4',value='<4 items>',type='$T',"
  2131. "children=[{name='2',value='deleteLater()',numchild='0',"
  2132. "addr='$A',type='" NS "QObjectSlot'},"
  2133. "{name='3',value='_q_reregisterTimers(void*)',numchild='0',"
  2134. "addr='$A',type='" NS "QObjectSlot'},"
  2135. "{name='18',value='submit()',numchild='0',"
  2136. "addr='$A',type='" NS "QObjectSlot'},"
  2137. "{name='19',value='revert()',numchild='0',"
  2138. "addr='$A',type='" NS "QObjectSlot'}]",
  2139. &m, NS"QObjectSlotList", true);
  2140. }
  2141. #endif // #if 0
  2142. ///////////////////////////// QPixmap /////////////////////////////////
  2143. const char * const pixmap[] = {
  2144. "2 24 3 1", " c None", ". c #DBD3CB", "+ c #FCFBFA",
  2145. " ", " ", " ", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+",
  2146. ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", " ", " ", " "
  2147. };
  2148. void dump_QPixmap()
  2149. {
  2150. # ifdef QT_GUI_LIB
  2151. /* A */ QPixmap p; // Case 1: Null Pixmap.
  2152. /* B */ p = QPixmap(20, 100); // Case 2: Uninitialized non-null pixmap.
  2153. /* C */ p = QPixmap(pixmap); // Case 3: Initialized non-null pixmap.
  2154. /* D */ (void) p.size();
  2155. # endif
  2156. }
  2157. void tst_Gdb::dump_QPixmap()
  2158. {
  2159. # ifdef QT_GUI_LIB
  2160. prepare("dump_QPixmap");
  2161. next();
  2162. check("B", "{iname='local.p',name='p',type='" NS "QPixmap',"
  2163. "value='(null)',numchild='0'}");
  2164. next();
  2165. check("C", "{iname='local.p',name='p',type='" NS "QPixmap',"
  2166. "value='(20x100)',numchild='0'}");
  2167. next();
  2168. check("D", "{iname='local.p',name='p',type='" NS "QPixmap',"
  2169. "value='(2x24)',numchild='0'}");
  2170. # endif
  2171. }
  2172. ///////////////////////////// QPoint /////////////////////////////////
  2173. void dump_QPoint()
  2174. {
  2175. /* A */ QPoint p(43, 44);
  2176. /* B */ QPointF f(45, 46);
  2177. /* C */ (void) (p.x() + f.x()); }
  2178. void tst_Gdb::dump_QPoint()
  2179. {
  2180. prepare("dump_QPoint");
  2181. next();
  2182. next();
  2183. check("C","{iname='local.p',name='p',type='" NS "QPoint',"
  2184. "value='(43, 44)',numchild='2',childtype='int',childnumchild='0',"
  2185. "children=[{name='x',value='43'},{name='y',value='44'}]},"
  2186. "{iname='local.f',name='f',type='" NS "QPointF',"
  2187. "value='(45, 46)',numchild='2',childtype='double',childnumchild='0',"
  2188. "children=[{name='x',value='45'},{name='y',value='46'}]}",
  2189. "local.p,local.f");
  2190. }
  2191. ///////////////////////////// QRect /////////////////////////////////
  2192. void dump_QRect()
  2193. {
  2194. /* A */ QRect p(43, 44, 100, 200);
  2195. /* B */ QRectF f(45, 46, 100, 200);
  2196. /* C */ (void) (p.x() + f.x()); }
  2197. void tst_Gdb::dump_QRect()
  2198. {
  2199. prepare("dump_QRect");
  2200. next();
  2201. next();
  2202. check("C","{iname='local.p',name='p',type='" NS "QRect',"
  2203. "value='100x200+43+44',numchild='4',childtype='int',childnumchild='0',"
  2204. "children=[{name='x1',value='43'},{name='y1',value='44'},"
  2205. "{name='x2',value='142'},{name='y2',value='243'}]},"
  2206. "{iname='local.f',name='f',type='" NS "QRectF',"
  2207. "value='100x200+45+46',numchild='4',childtype='double',childnumchild='0',"
  2208. "children=[{name='x',value='45'},{name='y',value='46'},"
  2209. "{name='w',value='100'},{name='h',value='200'}]}",
  2210. "local.p,local.f");
  2211. }
  2212. ///////////////////////////// QSet<int> ///////////////////////////////////
  2213. void dump_QSet_int()
  2214. {
  2215. /* A */ QSet<int> h;
  2216. /* B */ h.insert(42);
  2217. /* C */ h.insert(44);
  2218. /* D */ (void) 0;
  2219. }
  2220. void tst_Gdb::dump_QSet_int()
  2221. {
  2222. prepare("dump_QSet_int");
  2223. if (checkUninitialized)
  2224. check("A","{iname='local.h',name='h',"
  2225. "type='" NS "QSet<int>',value='<invalid>',"
  2226. "numchild='0'}");
  2227. next(3);
  2228. check("D","{iname='local.h',name='h',"
  2229. "type='" NS "QSet<int>',value='<2 items>',numchild='2',"
  2230. "childtype='int',childnumchild='0',children=["
  2231. "{value='42'},{value='44'}]}", "local.h");
  2232. }
  2233. ///////////////////////////// QSet<Int3> ///////////////////////////////////
  2234. void dump_QSet_Int3()
  2235. {
  2236. /* A */ QSet<Int3> h;
  2237. /* B */ h.insert(Int3(42));
  2238. /* C */ h.insert(Int3(44));
  2239. /* D */ (void) 0;
  2240. }
  2241. void tst_Gdb::dump_QSet_Int3()
  2242. {
  2243. prepare("dump_QSet_Int3");
  2244. if (checkUninitialized)
  2245. check("A","{iname='local.h',name='h',"
  2246. "type='" NS "QSet<Int3>',value='<invalid>',"
  2247. "numchild='0'}");
  2248. next(3);
  2249. check("D","{iname='local.h',name='h',"
  2250. "type='" NS "QSet<Int3>',value='<2 items>',numchild='2',"
  2251. "childtype='Int3',children=["
  2252. "{value='{...}',numchild='3'},{value='{...}',numchild='3'}]}", "local.h");
  2253. }
  2254. ///////////////////////////// QSize /////////////////////////////////
  2255. #if QT_VERSION >= 0x040500
  2256. void dump_QSharedPointer()
  2257. {
  2258. /* A */ // Case 1: Simple type.
  2259. // Case 1.1: Null pointer.
  2260. QSharedPointer<int> simplePtr;
  2261. // Case 1.2: Non-null pointer,
  2262. QSharedPointer<int> simplePtr2(new int(99));
  2263. // Case 1.3: Shared pointer.
  2264. QSharedPointer<int> simplePtr3 = simplePtr2;
  2265. // Case 1.4: Weak pointer.
  2266. QWeakPointer<int> simplePtr4(simplePtr2);
  2267. // Case 2: Composite type.
  2268. // Case 2.1: Null pointer.
  2269. QSharedPointer<QString> compositePtr;
  2270. // Case 2.2: Non-null pointer,
  2271. QSharedPointer<QString> compositePtr2(new QString("Test"));
  2272. // Case 2.3: Shared pointer.
  2273. QSharedPointer<QString> compositePtr3 = compositePtr2;
  2274. // Case 2.4: Weak pointer.
  2275. QWeakPointer<QString> compositePtr4(compositePtr2);
  2276. /* C */ (void) simplePtr.data();
  2277. }
  2278. #endif
  2279. void tst_Gdb::dump_QSharedPointer()
  2280. {
  2281. #if QT_VERSION >= 0x040500
  2282. prepare("dump_QSharedPointer");
  2283. if (checkUninitialized)
  2284. check("A","{iname='local.simplePtr',name='simplePtr',"
  2285. "type='" NS "QSharedPointer<int>',value='<invalid>',numchild='0'},"
  2286. "{iname='local.simplePtr2',name='simplePtr2',"
  2287. "type='" NS "QSharedPointer<int>',value='<invalid>',numchild='0'},"
  2288. "{iname='local.simplePtr3',name='simplePtr3',"
  2289. "type='" NS "QSharedPointer<int>',value='<invalid>',numchild='0'},"
  2290. "{iname='local.simplePtr4',name='simplePtr4',"
  2291. "type='" NS "QWeakPointer<int>',value='<invalid>',numchild='0'},"
  2292. "{iname='local.compositePtr',name='compositePtr',"
  2293. "type='" NS "QSharedPointer<" NS "QString>',value='<invalid>',numchild='0'},"
  2294. "{iname='local.compositePtr2',name='compositePtr2',"
  2295. "type='" NS "QSharedPointer<" NS "QString>',value='<invalid>',numchild='0'},"
  2296. "{iname='local.compositePtr3',name='compositePtr3',"
  2297. "type='" NS "QSharedPointer<" NS "QString>',value='<invalid>',numchild='0'},"
  2298. "{iname='local.compositePtr4',name='compositePtr4',"
  2299. "type='" NS "QWeakPointer<" NS "QString>',value='<invalid>',numchild='0'}");
  2300. next(8);
  2301. check("C","{iname='local.simplePtr',name='simplePtr',"
  2302. "type='" NS "QSharedPointer<int>',value='(null)',numchild='0'},"
  2303. "{iname='local.simplePtr2',name='simplePtr2',"
  2304. "type='" NS "QSharedPointer<int>',value='',numchild='3'},"
  2305. "{iname='local.simplePtr3',name='simplePtr3',"
  2306. "type='" NS "QSharedPointer<int>',value='',numchild='3'},"
  2307. "{iname='local.simplePtr4',name='simplePtr4',"
  2308. "type='" NS "QWeakPointer<int>',value='',numchild='3'},"
  2309. "{iname='local.compositePtr',name='compositePtr',"
  2310. "type='" NS "QSharedPointer<" NS "QString>',value='(null)',numchild='0'},"
  2311. "{iname='local.compositePtr2',name='compositePtr2',"
  2312. "type='" NS "QSharedPointer<" NS "QString>',value='',numchild='3'},"
  2313. "{iname='local.compositePtr3',name='compositePtr3',"
  2314. "type='" NS "QSharedPointer<" NS "QString>',value='',numchild='3'},"
  2315. "{iname='local.compositePtr4',name='compositePtr4',"
  2316. "type='" NS "QWeakPointer<" NS "QString>',value='',numchild='3'}");
  2317. check("C","{iname='local.simplePtr',name='simplePtr',"
  2318. "type='" NS "QSharedPointer<int>',value='(null)',numchild='0'},"
  2319. "{iname='local.simplePtr2',name='simplePtr2',"
  2320. "type='" NS "QSharedPointer<int>',value='',numchild='3',children=["
  2321. "{name='data',type='int',value='99',numchild='0'},"
  2322. "{name='weakref',value='3',type='int',numchild='0'},"
  2323. "{name='strongref',value='2',type='int',numchild='0'}]},"
  2324. "{iname='local.simplePtr3',name='simplePtr3',"
  2325. "type='" NS "QSharedPointer<int>',value='',numchild='3',children=["
  2326. "{name='data',type='int',value='99',numchild='0'},"
  2327. "{name='weakref',value='3',type='int',numchild='0'},"
  2328. "{name='strongref',value='2',type='int',numchild='0'}]},"
  2329. "{iname='local.simplePtr4',name='simplePtr4',"
  2330. "type='" NS "QWeakPointer<int>',value='',numchild='3',children=["
  2331. "{name='data',type='int',value='99',numchild='0'},"
  2332. "{name='weakref',value='3',type='int',numchild='0'},"
  2333. "{name='strongref',value='2',type='int',numchild='0'}]},"
  2334. "{iname='local.compositePtr',name='compositePtr',"
  2335. "type='" NS "QSharedPointer<" NS "QString>',value='(null)',numchild='0'},"
  2336. "{iname='local.compositePtr2',name='compositePtr2',"
  2337. "type='" NS "QSharedPointer<" NS "QString>',value='',numchild='3'},"
  2338. "{iname='local.compositePtr3',name='compositePtr3',"
  2339. "type='" NS "QSharedPointer<" NS "QString>',value='',numchild='3'},"
  2340. "{iname='local.compositePtr4',name='compositePtr4',"
  2341. "type='" NS "QWeakPointer<" NS "QString>',value='',numchild='3'}",
  2342. "local.simplePtr,local.simplePtr2,local.simplePtr3,local.simplePtr4,"
  2343. "local.compositePtr,local.compositePtr,local.compositePtr,"
  2344. "local.compositePtr");
  2345. #endif
  2346. }
  2347. ///////////////////////////// QSize /////////////////////////////////
  2348. void dump_QSize()
  2349. {
  2350. /* A */ QSize p(43, 44);
  2351. // /* B */ QSizeF f(45, 46);
  2352. /* C */ (void) 0; }
  2353. void tst_Gdb::dump_QSize()
  2354. {
  2355. prepare("dump_QSize");
  2356. next(1);
  2357. // FIXME: Enable child type as soon as 'double' is not reported
  2358. // as 'myns::QVariant::Private::Data::qreal' anymore
  2359. check("C","{iname='local.p',name='p',type='" NS "QSize',"
  2360. "value='(43, 44)',numchild='2',childtype='int',childnumchild='0',"
  2361. "children=[{name='w',value='43'},{name='h',value='44'}]}"
  2362. // ",{iname='local.f',name='f',type='" NS "QSizeF',"
  2363. // "value='(45, 46)',numchild='2',childtype='double',childnumchild='0',"
  2364. // "children=[{name='w',value='45'},{name='h',value='46'}]}"
  2365. "",
  2366. "local.p,local.f");
  2367. }
  2368. ///////////////////////////// QStack /////////////////////////////////
  2369. void dump_QStack()
  2370. {
  2371. /* A */ QStack<int> v;
  2372. /* B */ v.append(3);
  2373. /* C */ v.append(2);
  2374. /* D */ (void) 0;
  2375. }
  2376. void tst_Gdb::dump_QStack()
  2377. {
  2378. prepare("dump_QStack");
  2379. if (checkUninitialized)
  2380. check("A","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2381. "value='<invalid>',numchild='0'}");
  2382. next();
  2383. check("B","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2384. "value='<0 items>',numchild='0'}");
  2385. check("B","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2386. "value='<0 items>',numchild='0',children=[]}", "local.v");
  2387. next();
  2388. check("C","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2389. "value='<1 items>',numchild='1'}");
  2390. check("C","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2391. "value='<1 items>',numchild='1',childtype='int',"
  2392. "childnumchild='0',children=[{value='3'}]}", // rounding...
  2393. "local.v");
  2394. next();
  2395. check("D","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2396. "value='<2 items>',numchild='2'}");
  2397. check("D","{iname='local.v',name='v',type='" NS "QStack<int>',"
  2398. "value='<2 items>',numchild='2',childtype='int',"
  2399. "childnumchild='0',children=[{value='3'},{value='2'}]}",
  2400. "local.v");
  2401. }
  2402. ///////////////////////////// QString /////////////////////////////////////
  2403. void dump_QString()
  2404. {
  2405. /* A */ QString s;
  2406. /* B */ s = "hallo";
  2407. /* C */ s += "x";
  2408. /* D */ (void) 0; }
  2409. void tst_Gdb::dump_QString()
  2410. {
  2411. prepare("dump_QString");
  2412. if (checkUninitialized)
  2413. check("A","{iname='local.s',name='s',type='" NS "QString',"
  2414. "value='<invalid>',numchild='0'}");
  2415. next();
  2416. check("B","{iname='local.s',name='s',type='" NS "QString',"
  2417. "valueencoded='7',value='',numchild='0'}", "local.s");
  2418. // Plain C style dumping:
  2419. check("B","{iname='local.s',name='s',type='" NS "QString',"
  2420. "value='{...}',numchild='5'}", "", 0);
  2421. check("B","{iname='local.s',name='s',type='" NS "QString',"
  2422. "value='{...}',numchild='5',children=["
  2423. "{name='d',type='" NS "QString::Data *',"
  2424. "value='-',numchild='1'}]}", "local.s", 0);
  2425. /*
  2426. // FIXME: changed after auto-deref commit
  2427. check("B","{iname='local.s',name='s',type='" NS "QString',"
  2428. "value='{...}',numchild='5',"
  2429. "children=[{name='d',"
  2430. "type='" NS "QString::Data *',value='-',numchild='1',"
  2431. "children=[{iname='local.s.d.*',name='*d',"
  2432. "type='" NS "QString::Data',value='{...}',numchild='11'}]}]}",
  2433. "local.s,local.s.d", 0);
  2434. */
  2435. next();
  2436. check("C","{iname='local.s',name='s',type='" NS "QString',"
  2437. "valueencoded='7',value='680061006c006c006f00',numchild='0'}");
  2438. next();
  2439. check("D","{iname='local.s',name='s',type='" NS "QString',"
  2440. "valueencoded='7',value='680061006c006c006f007800',numchild='0'}");
  2441. }
  2442. ///////////////////////////// QStringList /////////////////////////////////
  2443. void dump_QStringList()
  2444. {
  2445. /* A */ QStringList s;
  2446. /* B */ s.append("hello");
  2447. /* C */ s.append("world");
  2448. /* D */ (void) 0;
  2449. }
  2450. void tst_Gdb::dump_QStringList()
  2451. {
  2452. prepare("dump_QStringList");
  2453. if (checkUninitialized)
  2454. check("A","{iname='local.s',name='s',type='" NS "QStringList',"
  2455. "value='<invalid>',numchild='0'}");
  2456. next();
  2457. check("B","{iname='local.s',name='s',type='" NS "QStringList',"
  2458. "value='<0 items>',numchild='0'}");
  2459. check("B","{iname='local.s',name='s',type='" NS "QStringList',"
  2460. "value='<0 items>',numchild='0',children=[]}", "local.s");
  2461. next();
  2462. check("C","{iname='local.s',name='s',type='" NS "QStringList',"
  2463. "value='<1 items>',numchild='1'}");
  2464. check("C","{iname='local.s',name='s',type='" NS "QStringList',"
  2465. "value='<1 items>',numchild='1',childtype='" NS "QString',"
  2466. "childnumchild='0',children=[{valueencoded='7',"
  2467. "value='680065006c006c006f00'}]}",
  2468. "local.s");
  2469. next();
  2470. check("D","{iname='local.s',name='s',type='" NS "QStringList',"
  2471. "value='<2 items>',numchild='2'}");
  2472. check("D","{iname='local.s',name='s',type='" NS "QStringList',"
  2473. "value='<2 items>',numchild='2',childtype='" NS "QString',"
  2474. "childnumchild='0',children=["
  2475. "{valueencoded='7',value='680065006c006c006f00'},"
  2476. "{valueencoded='7',value='77006f0072006c006400'}]}",
  2477. "local.s");
  2478. }
  2479. ///////////////////////////// QTextCodec /////////////////////////////////
  2480. void dump_QTextCodec()
  2481. {
  2482. /* A */ QTextCodec *codec = QTextCodec::codecForName("UTF-16");
  2483. /* D */ (void) codec; }
  2484. void tst_Gdb::dump_QTextCodec()
  2485. {
  2486. // FIXME
  2487. prepare("dump_QTextCodec");
  2488. next();
  2489. check("D", "{iname='local.codec',name='codec',type='" NS "QTextCodec',"
  2490. "valueencoded='6',value='5554462d3136',numchild='2',children=["
  2491. "{name='name',type='" NS "QByteArray',valueencoded='6',"
  2492. "value='5554462d3136',numchild='6'},"
  2493. "{name='mibEnum',type='int',value='1015',numchild='0'}]}",
  2494. "local.codec,local.codec.*");
  2495. }
  2496. ///////////////////////////// QVector /////////////////////////////////
  2497. void dump_QVector()
  2498. {
  2499. /* A */ QVector<double> v;
  2500. /* B */ v.append(3.14);
  2501. /* C */ v.append(2.81);
  2502. /* D */ (void) 0;
  2503. }
  2504. void tst_Gdb::dump_QVector()
  2505. {
  2506. prepare("dump_QVector");
  2507. if (checkUninitialized)
  2508. check("A","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2509. "value='<invalid>',numchild='0'}");
  2510. next();
  2511. check("B","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2512. "value='<0 items>',numchild='0'}");
  2513. check("B","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2514. "value='<0 items>',numchild='0',children=[]}", "local.v");
  2515. next();
  2516. check("C","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2517. "value='<1 items>',numchild='1'}");
  2518. check("C","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2519. "value='<1 items>',numchild='1',childtype='double',"
  2520. "childnumchild='0',children=[{value='-'}]}", // rounding...
  2521. "local.v");
  2522. next();
  2523. check("D","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2524. "value='<2 items>',numchild='2'}");
  2525. check("D","{iname='local.v',name='v',type='" NS "QVector<double>',"
  2526. "value='<2 items>',numchild='2',childtype='double',"
  2527. "childnumchild='0',children=[{value='-'},{value='-'}]}",
  2528. "local.v");
  2529. }
  2530. ///////////////////////////// QVariant /////////////////////////////////
  2531. void dump_QVariant1()
  2532. {
  2533. QVariant v(QLatin1String("hallo"));
  2534. (void) v.toInt();
  2535. }
  2536. #ifdef QT_GUI_LIB
  2537. #define GUI(s) s
  2538. #else
  2539. #define GUI(s) 0
  2540. #endif
  2541. void dump_QVariant()
  2542. {
  2543. /*<invalid>*/ QVariant v;
  2544. /* <invalid> */ v = QBitArray();
  2545. /* QBitArray */ v = GUI(QBitmap());
  2546. /* QBitMap */ v = bool(true);
  2547. /* bool */ v = GUI(QBrush());
  2548. /* QBrush */ v = QByteArray("abc");
  2549. /* QByteArray */ v = QChar(QLatin1Char('x'));
  2550. /* QChar */ v = GUI(QColor());
  2551. /* QColor */ v = GUI(QCursor());
  2552. /* QCursor */ v = QDate();
  2553. /* QDate */ v = QDateTime();
  2554. /* QDateTime */ v = double(46);
  2555. /* double */ v = GUI(QFont());
  2556. /* QFont */ v = QVariantHash();
  2557. /* QVariantHash */ v = GUI(QIcon());
  2558. /* QIcon */ v = GUI(QImage(10, 10, QImage::Format_RGB32));
  2559. /* QImage */ v = int(42);
  2560. /* int */ v = GUI(QKeySequence());
  2561. /* QKeySequence */ v = QLine();
  2562. /* QLine */ v = QLineF();
  2563. /* QLineF */ v = QVariantList();
  2564. /* QVariantList */ v = QLocale();
  2565. /* QLocale */ v = qlonglong(44);
  2566. /* qlonglong */ v = QVariantMap();
  2567. /* QVariantMap */ v = GUI(QTransform());
  2568. /* QTransform */ v = GUI(QMatrix4x4());
  2569. /* QMatrix4x4 */ v = GUI(QPalette());
  2570. /* QPalette */ v = GUI(QPen());
  2571. /* QPen */ v = GUI(QPixmap());
  2572. /* QPixmap */ v = QPoint(45, 46);
  2573. /* QPoint */ v = QPointF(41, 42);
  2574. /* QPointF */ v = GUI(QPolygon());
  2575. /* QPolygon */ v = GUI(QQuaternion());
  2576. /* QQuaternion */ v = QRect(1, 2, 3, 4);
  2577. /* QRect */ v = QRectF(1, 2, 3, 4);
  2578. /* QRectF */ v = QRegExp("abc");
  2579. /* QRegExp */ v = GUI(QRegion());
  2580. /* QRegion */ v = QSize(0, 0);
  2581. /* QSize */ v = QSizeF(0, 0);
  2582. /* QSizeF */ v = GUI(QSizePolicy());
  2583. /* QSizePolicy */ v = QString("abc");
  2584. /* QString */ v = QStringList() << "abc";
  2585. /* QStringList */ v = GUI(QTextFormat());
  2586. /* QTextFormat */ v = GUI(QTextLength());
  2587. /* QTextLength */ v = QTime();
  2588. /* QTime */ v = uint(43);
  2589. /* uint */ v = qulonglong(45);
  2590. /* qulonglong */ v = QUrl("http://foo");
  2591. /* QUrl */ v = GUI(QVector2D());
  2592. /* QVector2D */ v = GUI(QVector3D());
  2593. /* QVector3D */ v = GUI(QVector4D());
  2594. /* QVector4D */ (void) 0;
  2595. }
  2596. void tst_Gdb::dump_QVariant()
  2597. {
  2598. # define PRE "iname='local.v',name='v',type='" NS "QVariant',"
  2599. prepare("dump_QVariant");
  2600. if (checkUninitialized) /*<invalid>*/
  2601. check("A","{" PRE "'value=<invalid>',numchild='0'}");
  2602. next();
  2603. check("<invalid>", "{" PRE "value='(invalid)',numchild='0'}");
  2604. next();
  2605. check("QBitArray", "{" PRE "value='(" NS "QBitArray)',numchild='1',children=["
  2606. "{name='data',type='" NS "QBitArray',value='{...}',numchild='1'}]}",
  2607. "local.v");
  2608. next();
  2609. (void)GUI(check("QBitMap", "{" PRE "value='(" NS "QBitmap)',numchild='1',children=["
  2610. "{name='data',type='" NS "QBitmap',value='{...}',numchild='1'}]}",
  2611. "local.v"));
  2612. next();
  2613. check("bool", "{" PRE "value='true',numchild='0'}", "local.v");
  2614. next();
  2615. (void)GUI(check("QBrush", "{" PRE "value='(" NS "QBrush)',numchild='1',children=["
  2616. "{name='data',type='" NS "QBrush',value='{...}',numchild='1'}]}",
  2617. "local.v"));
  2618. next();
  2619. check("QByteArray", "{" PRE "value='(" NS "QByteArray)',numchild='1',"
  2620. "children=[{name='data',type='" NS "QByteArray',valueencoded='6',"
  2621. "value='616263',numchild='3'}]}", "local.v");
  2622. next();
  2623. check("QChar", "{" PRE "value='(" NS "QChar)',numchild='1',"
  2624. "children=[{name='data',type='" NS "QChar',value=''x' (120)',numchild='0'}]}", "local.v");
  2625. next();
  2626. (void)GUI(check("QColor", "{" PRE "value='(" NS "QColor)',numchild='1',children=["
  2627. "{name='data',type='" NS "QColor',value='{...}',numchild='2'}]}",
  2628. "local.v"));
  2629. next();
  2630. (void)GUI(check("QCursor", "{" PRE "value='(" NS "QCursor)',numchild='1',children=["
  2631. "{name='data',type='" NS "QCursor',value='{...}',numchild='1'}]}",
  2632. "local.v"));
  2633. next();
  2634. check("QDate", "{" PRE "value='(" NS "QDate)',numchild='1',children=["
  2635. "{name='data',type='" NS "QDate',value='{...}',numchild='1'}]}", "local.v");
  2636. next();
  2637. check("QDateTime", "{" PRE "value='(" NS "QDateTime)',numchild='1',children=["
  2638. "{name='data',type='" NS "QDateTime',valueencoded='7',value='',numchild='3'}]}", "local.v");
  2639. next();
  2640. check("double", "{" PRE "value='46',numchild='0'}", "local.v");
  2641. next();
  2642. (void)GUI(check("QFont", "{" PRE "value='(" NS "QFont)',numchild='1',children=["
  2643. "{name='data',type='" NS "QFont',value='{...}',numchild='3'}]}",
  2644. "local.v"));
  2645. next();
  2646. check("QVariantHash", "{" PRE "value='(" NS "QVariantHash)',numchild='1',children=["
  2647. "{name='data',type='" NS "QHash<" NS "QString, " NS "QVariant>',"
  2648. "value='<0 items>',numchild='0'}]}", "local.v");
  2649. next();
  2650. (void)GUI(check("QIcon", "{" PRE "value='(" NS "QIcon)',numchild='1',children=["
  2651. "{name='data',type='" NS "QIcon',value='{...}',numchild='1'}]}",
  2652. "local.v"));
  2653. next();
  2654. // FIXME:
  2655. // (void)GUI(check("QImage", "{" PRE "value='(" NS "QImage)',numchild='1',children=["
  2656. // "{name='data',type='" NS "QImage',value='{...}',numchild='1'}]}",
  2657. // "local.v"));
  2658. next();
  2659. check("int", "{" PRE "value='42',numchild='0'}", "local.v");
  2660. next();
  2661. (void)GUI(check("QKeySequence","{" PRE "value='(" NS "QKeySequence)',numchild='1',children=["
  2662. "{name='data',type='" NS "QKeySequence',value='{...}',numchild='1'}]}",
  2663. "local.v"));
  2664. next();
  2665. check("QLine", "{" PRE "value='(" NS "QLine)',numchild='1',children=["
  2666. "{name='data',type='" NS "QLine',value='{...}',numchild='2'}]}", "local.v");
  2667. next();
  2668. check("QLineF", "{" PRE "value='(" NS "QLineF)',numchild='1',children=["
  2669. "{name='data',type='" NS "QLineF',value='{...}',numchild='2'}]}", "local.v");
  2670. next();
  2671. check("QVariantList", "{" PRE "value='(" NS "QVariantList)',numchild='1',children=["
  2672. "{name='data',type='" NS "QList<" NS "QVariant>',"
  2673. "value='<0 items>',numchild='0'}]}", "local.v");
  2674. next();
  2675. check("QLocale", "{" PRE "value='(" NS "QLocale)',numchild='1',children=["
  2676. "{name='data',type='" NS "QLocale',valueencoded='7',value='-',numchild='8'}]}", "local.v");
  2677. next();
  2678. check("qlonglong", "{" PRE "value='44',numchild='0'}", "local.v");
  2679. next();
  2680. check("QVariantMap", "{" PRE "value='(" NS "QVariantMap)',numchild='1',children=["
  2681. "{name='data',type='" NS "QMap<" NS "QString, " NS "QVariant>',"
  2682. "value='<0 items>',numchild='0'}]}", "local.v");
  2683. next();
  2684. (void)GUI(check("QTransform", "{" PRE "value='(" NS "QTransform)',numchild='1',children=["
  2685. "{name='data',type='" NS "QTransform',value='{...}',numchild='7'}]}",
  2686. "local.v"));
  2687. next();
  2688. (void)GUI(check("QMatrix4x4", "{" PRE "value='(" NS "QMatrix4x4)',numchild='1',children=["
  2689. "{name='data',type='" NS "QMatrix4x4',value='{...}',numchild='2'}]}",
  2690. "local.v"));
  2691. next();
  2692. (void)GUI(check("QPalette", "{" PRE "value='(" NS "QPalette)',numchild='1',children=["
  2693. "{name='data',type='" NS "QPalette',value='{...}',numchild='4'}]}",
  2694. "local.v"));
  2695. next();
  2696. (void)GUI(check("QPen", "{" PRE "value='(" NS "QPen)',numchild='1',children=["
  2697. "{name='data',type='" NS "QPen',value='{...}',numchild='1'}]}",
  2698. "local.v"));
  2699. next();
  2700. // FIXME:
  2701. // (void)GUI(check("QPixmap", "{" PRE "value='(" NS "QPixmap)',numchild='1',children=["
  2702. // "{name='data',type='" NS "QPixmap',value='{...}',numchild='1'}]}",
  2703. // "local.v"));
  2704. next();
  2705. check("QPoint", "{" PRE "value='(" NS "QPoint)',numchild='1',children=["
  2706. "{name='data',type='" NS "QPoint',value='(45, 46)',numchild='2'}]}",
  2707. "local.v");
  2708. next();
  2709. // FIXME
  2710. // check("QPointF", "{" PRE "value='(" NS "QPointF)',numchild='1',children=["
  2711. // "{name='data',type='" NS "QBrush',value='{...}',numchild='1'}]}",
  2712. // "local.v"));
  2713. next();
  2714. (void)GUI(check("QPolygon", "{" PRE "value='(" NS "QPolygon)',numchild='1',children=["
  2715. "{name='data',type='" NS "QPolygon',value='{...}',numchild='1'}]}",
  2716. "local.v"));
  2717. next();
  2718. // FIXME:
  2719. // (void)GUI(check("QQuaternion", "{" PRE "value='(" NS "QQuaternion)',numchild='1',children=["
  2720. // "{name='data',type='" NS "QQuadernion',value='{...}',numchild='1'}]}",
  2721. // "local.v"));
  2722. next();
  2723. // FIXME: Fix value
  2724. check("QRect", "{" PRE "value='(" NS "QRect)',numchild='1',children=["
  2725. "{name='data',type='" NS "QRect',value='-',numchild='4'}]}", "local.v");
  2726. next();
  2727. // FIXME: Fix value
  2728. check("QRectF", "{" PRE "value='(" NS "QRectF)',numchild='1',children=["
  2729. "{name='data',type='" NS "QRectF',value='-',numchild='4'}]}", "local.v");
  2730. next();
  2731. check("QRegExp", "{" PRE "value='(" NS "QRegExp)',numchild='1',children=["
  2732. "{name='data',type='" NS "QRegExp',value='{...}',numchild='1'}]}", "local.v");
  2733. next();
  2734. (void)GUI(check("QRegion", "{" PRE "value='(" NS "QRegion)',numchild='1',children=["
  2735. "{name='data',type='" NS "QRegion',value='{...}',numchild='2'}]}",
  2736. "local.v"));
  2737. next();
  2738. check("QSize", "{" PRE "value='(" NS "QSize)',numchild='1',children=["
  2739. "{name='data',type='" NS "QSize',value='(0, 0)',numchild='2'}]}", "local.v");
  2740. next();
  2741. // FIXME:
  2742. // check("QSizeF", "{" PRE "value='(" NS "QSizeF)',numchild='1',children=["
  2743. // "{name='data',type='" NS "QBrush',value='{...}',numchild='1'}]}",
  2744. // "local.v");
  2745. next();
  2746. (void)GUI(check("QSizePolicy", "{" PRE "value='(" NS "QSizePolicy)',numchild='1',children=["
  2747. "{name='data',type='" NS "QSizePolicy',value='{...}',numchild='2'}]}",
  2748. "local.v"));
  2749. next();
  2750. check("QString", "{" PRE "value='(" NS "QString)',numchild='1',children=["
  2751. "{name='data',type='" NS "QString',valueencoded='7',value='610062006300',numchild='0'}]}",
  2752. "local.v");
  2753. next();
  2754. check("QStringList", "{" PRE "value='(" NS "QStringList)',numchild='1',children=["
  2755. "{name='data',type='" NS "QStringList',value='<1 items>',numchild='1'}]}", "local.v");
  2756. next();
  2757. (void)GUI(check("QTextFormat", "{" PRE "value='(" NS "QTextFormat)',numchild='1',children=["
  2758. "{name='data',type='" NS "QTextFormat',value='{...}',numchild='3'}]}",
  2759. "local.v"));
  2760. next();
  2761. (void)GUI(check("QTextLength", "{" PRE "value='(" NS "QTextLength)',numchild='1',children=["
  2762. "{name='data',type='" NS "QTextLength',value='{...}',numchild='2'}]}",
  2763. "local.v"));
  2764. next();
  2765. check("QTime", "{" PRE "value='(" NS "QTime)',numchild='1',children=["
  2766. "{name='data',type='" NS "QTime',value='{...}',numchild='1'}]}", "local.v");
  2767. next();
  2768. check("uint", "{" PRE "value='43',numchild='0'}", "local.v");
  2769. next();
  2770. check("qulonglong", "{" PRE "value='45',numchild='0'}", "local.v");
  2771. next();
  2772. check("QUrl", "{" PRE "value='(" NS "QUrl)',numchild='1',children=["
  2773. "{name='data',type='" NS "QUrl',value='{...}',numchild='1'}]}", "local.v");
  2774. next();
  2775. (void)GUI(check("QVector2D", "{" PRE "value='(" NS "QVector2D)',numchild='1',children=["
  2776. "{name='data',type='" NS "QVector2D',value='{...}',numchild='2'}]}",
  2777. "local.v"));
  2778. next();
  2779. (void)GUI(check("QVector3D", "{" PRE "value='(" NS "QVector3D)',numchild='1',children=["
  2780. "{name='data',type='" NS "QVector3D',value='{...}',numchild='3'}]}",
  2781. "local.v"));
  2782. next();
  2783. (void)GUI(check("QVector4D", "{" PRE "value='(" NS "QVector4D)',numchild='1',children=["
  2784. "{name='data',type='" NS "QVector4D',value='{...}',numchild='4'}]}",
  2785. "local.v"));
  2786. }
  2787. ///////////////////////////// QWeakPointer /////////////////////////////////
  2788. #if QT_VERSION >= 0x040500
  2789. void dump_QWeakPointer_11()
  2790. {
  2791. /* A */ QSharedPointer<int> sp;
  2792. /* */ QWeakPointer<int> wp = sp.toWeakRef();
  2793. /* B */ (void) 0; }
  2794. void tst_Gdb::dump_QWeakPointer_11()
  2795. {
  2796. // Case 1.1: Null pointer.
  2797. prepare("dump_QWeakPointer_11");
  2798. if (checkUninitialized)
  2799. check("A","{iname='local.sp',name='sp',"
  2800. "type='" NS "QSharedPointer<int>',value='<invalid>',numchild='0'},"
  2801. "{iname='local.wp',name='wp',"
  2802. "type='" NS "QWeakPointer<int>',value='<invalid>',numchild='0'}");
  2803. next(2);
  2804. check("B","{iname='local.sp',name='sp',"
  2805. "type='" NS "QSharedPointer<int>',value='(null)',numchild='0'},"
  2806. "{iname='local.wp',name='wp',"
  2807. "type='" NS "QWeakPointer<int>',value='(null)',numchild='0'}");
  2808. }
  2809. void dump_QWeakPointer_12()
  2810. {
  2811. /* A */ QSharedPointer<int> sp(new int(99));
  2812. /* */ QWeakPointer<int> wp = sp.toWeakRef();
  2813. /* B */ (void) 0; }
  2814. void tst_Gdb::dump_QWeakPointer_12()
  2815. {
  2816. return;
  2817. // Case 1.2: Weak pointer is unique.
  2818. prepare("dump_QWeakPointer_12");
  2819. if (checkUninitialized)
  2820. check("A","{iname='local.sp',name='sp',"
  2821. "type='" NS "QSharedPointer<int>',value='<invalid>',numchild='0'},"
  2822. "{iname='local.wp',name='wp',"
  2823. "type='" NS "QWeakPointer<int>',value='<invalid>',numchild='0'}");
  2824. next();
  2825. next();
  2826. check("B","{iname='local.sp',name='sp',"
  2827. "type='" NS "QSharedPointer<int>',value='',numchild='3'},"
  2828. "{iname='local.wp',name='wp',"
  2829. "type='" NS "QWeakPointer<int>',value='',numchild='3'}");
  2830. check("B","{iname='local.sp',name='sp',"
  2831. "type='" NS "QSharedPointer<int>',value='',numchild='3',children=["
  2832. "{name='data',type='int',value='99',numchild='0'},"
  2833. "{name='weakref',value='2',type='int',numchild='0'},"
  2834. "{name='strongref',value='1',type='int',numchild='0'}]},"
  2835. "{iname='local.wp',name='wp',"
  2836. "type='" NS "QWeakPointer<int>',value='',numchild='3',children=["
  2837. "{name='data',type='int',value='99',numchild='0'},"
  2838. "{name='weakref',value='2',type='int',numchild='0'},"
  2839. "{name='strongref',value='1',type='int',numchild='0'}]}",
  2840. "local.sp,local.wp");
  2841. }
  2842. void dump_QWeakPointer_13()
  2843. {
  2844. /* A */ QSharedPointer<int> sp(new int(99));
  2845. /* */ QWeakPointer<int> wp = sp.toWeakRef();
  2846. /* */ QWeakPointer<int> wp2 = sp.toWeakRef();
  2847. /* B */ (void) 0; }
  2848. void tst_Gdb::dump_QWeakPointer_13()
  2849. {
  2850. // Case 1.3: There are other weak pointers.
  2851. prepare("dump_QWeakPointer_13");
  2852. if (checkUninitialized)
  2853. check("A","{iname='local.sp',name='sp',"
  2854. "type='" NS "QSharedPointer<int>',value='<invalid>',numchild='0'},"
  2855. "{iname='local.wp',name='wp',"
  2856. "type='" NS "QWeakPointer<int>',value='<invalid>',numchild='0'},"
  2857. "{iname='local.wp2',name='wp2',"
  2858. "type='" NS "QWeakPointer<int>',value='<invalid>',numchild='0'}");
  2859. next(3);
  2860. check("B","{iname='local.sp',name='sp',"
  2861. "type='" NS "QSharedPointer<int>',value='',numchild='3'},"
  2862. "{iname='local.wp',name='wp',"
  2863. "type='" NS "QWeakPointer<int>',value='',numchild='3'},"
  2864. "{iname='local.wp2',name='wp2',"
  2865. "type='" NS "QWeakPointer<int>',value='',numchild='3'}");
  2866. check("B","{iname='local.sp',name='sp',"
  2867. "type='" NS "QSharedPointer<int>',value='',numchild='3',children=["
  2868. "{name='data',type='int',value='99',numchild='0'},"
  2869. "{name='weakref',value='3',type='int',numchild='0'},"
  2870. "{name='strongref',value='1',type='int',numchild='0'}]},"
  2871. "{iname='local.wp',name='wp',"
  2872. "type='" NS "QWeakPointer<int>',value='',numchild='3',children=["
  2873. "{name='data',type='int',value='99',numchild='0'},"
  2874. "{name='weakref',value='3',type='int',numchild='0'},"
  2875. "{name='strongref',value='1',type='int',numchild='0'}]},"
  2876. "{iname='local.wp2',name='wp2',"
  2877. "type='" NS "QWeakPointer<int>',value='',numchild='3'}",
  2878. "local.sp,local.wp");
  2879. }
  2880. void dump_QWeakPointer_2()
  2881. {
  2882. /* A */ QSharedPointer<QString> sp(new QString("Test"));
  2883. /* */ QWeakPointer<QString> wp = sp.toWeakRef();
  2884. /* B */ (void *) wp.data(); }
  2885. void tst_Gdb::dump_QWeakPointer_2()
  2886. {
  2887. // Case 2: Composite type.
  2888. prepare("dump_QWeakPointer_2");
  2889. if (checkUninitialized)
  2890. check("A","{iname='local.sp',name='sp',"
  2891. "type='" NS "QSharedPointer<" NS "QString>',"
  2892. "value='<invalid>',numchild='0'},"
  2893. "{iname='local.wp',name='wp',"
  2894. "type='" NS "QWeakPointer<" NS "QString>',"
  2895. "value='<invalid>',numchild='0'}");
  2896. next(2);
  2897. check("B","{iname='local.sp',name='sp',"
  2898. "type='" NS "QSharedPointer<" NS "QString>',value='',numchild='3',children=["
  2899. "{name='data',type='" NS "QString',"
  2900. "valueencoded='7',value='5400650073007400',numchild='0'},"
  2901. "{name='weakref',value='2',type='int',numchild='0'},"
  2902. "{name='strongref',value='1',type='int',numchild='0'}]},"
  2903. "{iname='local.wp',name='wp',"
  2904. "type='" NS "QWeakPointer<" NS "QString>',value='',numchild='3',children=["
  2905. "{name='data',type='" NS "QString',"
  2906. "valueencoded='7',value='5400650073007400',numchild='0'},"
  2907. "{name='weakref',value='2',type='int',numchild='0'},"
  2908. "{name='strongref',value='1',type='int',numchild='0'}]}",
  2909. "local.sp,local.wp");
  2910. }
  2911. #else // before Qt 4.5
  2912. void tst_Gdb::dump_QWeakPointer_11() {}
  2913. void tst_Gdb::dump_QWeakPointer_12() {}
  2914. void tst_Gdb::dump_QWeakPointer_13() {}
  2915. void tst_Gdb::dump_QWeakPointer_2() {}
  2916. #endif
  2917. ///////////////////////////// QWidget //////////////////////////////
  2918. void dump_QWidget()
  2919. {
  2920. # ifdef QT_GUI_LIB
  2921. /* A */ QWidget w;
  2922. /* B */ (void) w.size();
  2923. # endif
  2924. }
  2925. void tst_Gdb::dump_QWidget()
  2926. {
  2927. # ifdef QT_GUI_LIB
  2928. prepare("dump_QWidget");
  2929. if (checkUninitialized)
  2930. check("A","{iname='local.w',name='w',"
  2931. "type='" NS "QWidget',value='<invalid>',numchild='0'}");
  2932. next();
  2933. check("B","{iname='local.w',name='w',type='" NS "QWidget',"
  2934. "value='{...}',numchild='4',children=["
  2935. "{name='" NS "QObject',type='" NS "QObject',"
  2936. "valueencoded='7',value='',numchild='4',children=["
  2937. "{name='parent',type='" NS "QObject *',value='0x0',numchild='0'},"
  2938. "{name='children',type='" NS "QObject::QObjectList',"
  2939. "value='<0 items>',numchild='0'},"
  2940. "{name='properties',value='<1 items>',type='',numchild='1'},"
  2941. "{name='connections',value='<0 items>',type='',numchild='0'},"
  2942. "{name='signals',value='<2 items>',type='',"
  2943. "numchild='2',childnumchild='0'},"
  2944. "{name='slots',value='<2 items>',type='',"
  2945. "numchild='2',childnumchild='0'}"
  2946. "]},"
  2947. "{name='" NS "QPaintDevice',type='" NS "QPaintDevice',"
  2948. "value='{...}',numchild='2'},"
  2949. "{name='data',type='" NS "QWidgetData *',"
  2950. "value='-',numchild='1'}]}",
  2951. "local.w,local.w." NS "QObject");
  2952. # endif
  2953. }
  2954. ///////////////////////////// std::deque<int> //////////////////////////////
  2955. void dump_std_deque()
  2956. {
  2957. /* A */ std::deque<int> deque;
  2958. /* B */ deque.push_back(45);
  2959. /* C */ deque.push_back(46);
  2960. /* D */ deque.push_back(47);
  2961. /* E */ (void) 0;
  2962. }
  2963. void tst_Gdb::dump_std_deque()
  2964. {
  2965. prepare("dump_std_deque");
  2966. if (checkUninitialized)
  2967. check("A","{iname='local.deque',name='deque',"
  2968. "type='std::deque<int, std::allocator<int> >',"
  2969. "value='<invalid>',numchild='0'}");
  2970. next();
  2971. check("B", "{iname='local.deque',name='deque',"
  2972. "type='std::deque<int, std::allocator<int> >',"
  2973. "value='<0 items>',numchild='0',children=[]}",
  2974. "local.deque");
  2975. next(3);
  2976. check("E", "{iname='local.deque',name='deque',"
  2977. "type='std::deque<int, std::allocator<int> >',"
  2978. "value='<3 items>',numchild='3',"
  2979. "childtype='int',childnumchild='0',children=["
  2980. "{value='45'},{value='46'},{value='47'}]}",
  2981. "local.deque");
  2982. // FIXME: Try large container
  2983. }
  2984. ///////////////////////////// std::list<int> //////////////////////////////
  2985. void dump_std_list()
  2986. {
  2987. /* A */ std::list<int> list;
  2988. /* B */ list.push_back(45);
  2989. /* C */ list.push_back(46);
  2990. /* D */ list.push_back(47);
  2991. /* E */ (void) 0;
  2992. }
  2993. void tst_Gdb::dump_std_list()
  2994. {
  2995. prepare("dump_std_list");
  2996. if (checkUninitialized)
  2997. check("A","{iname='local.list',name='list',"
  2998. "numchild='0'}");
  2999. next();
  3000. check("B", "{iname='local.list',name='list',"
  3001. "type='std::list<int, std::allocator<int> >',"
  3002. "value='<0 items>',numchild='0',children=[]}",
  3003. "local.list");
  3004. next();
  3005. check("C", "{iname='local.list',name='list',"
  3006. "type='std::list<int, std::allocator<int> >',"
  3007. "value='<1 items>',numchild='1',"
  3008. "childtype='int',childnumchild='0',children=[{value='45'}]}",
  3009. "local.list");
  3010. next();
  3011. check("D", "{iname='local.list',name='list',"
  3012. "type='std::list<int, std::allocator<int> >',"
  3013. "value='<2 items>',numchild='2',"
  3014. "childtype='int',childnumchild='0',children=["
  3015. "{value='45'},{value='46'}]}",
  3016. "local.list");
  3017. next();
  3018. check("E", "{iname='local.list',name='list',"
  3019. "type='std::list<int, std::allocator<int> >',"
  3020. "value='<3 items>',numchild='3',"
  3021. "childtype='int',childnumchild='0',children=["
  3022. "{value='45'},{value='46'},{value='47'}]}",
  3023. "local.list");
  3024. }
  3025. ///////////////////////////// std::map<int, int> //////////////////////////////
  3026. void dump_std_map_int_int()
  3027. {
  3028. /* A */ std::map<int, int> h;
  3029. /* B */ h[12] = 34;
  3030. /* C */ h[14] = 54;
  3031. /* D */ (void) 0;
  3032. }
  3033. void tst_Gdb::dump_std_map_int_int()
  3034. {
  3035. QByteArray type = "std::map<int, int, std::less<int>, "
  3036. "std::allocator<std::pair<int const, int> > >";
  3037. prepare("dump_std_map_int_int");
  3038. if (checkUninitialized)
  3039. check("A","{iname='local.h',name='h',"
  3040. "type='" + type + "',value='<invalid>',"
  3041. "numchild='0'}");
  3042. next();
  3043. check("B","{iname='local.h',name='h',"
  3044. "type='" + type + "',value='<0 items>',"
  3045. "numchild='0'}");
  3046. next(2);
  3047. check("D","{iname='local.h',name='h',"
  3048. "type='" + type + "',value='<2 items>',"
  3049. "numchild='2'}");
  3050. check("D","{iname='local.h',name='h',"
  3051. "type='" + type + "',value='<2 items>',"
  3052. "numchild='2',childtype='int',childnumchild='0',"
  3053. "children=[{name='12',value='34'},{name='14',value='54'}]}",
  3054. "local.h,local.h.0,local.h.1");
  3055. }
  3056. //////////////////////// std::map<std::string, std::string> ////////////////////////
  3057. void dump_std_map_string_string()
  3058. {
  3059. /* A */ std::map<std::string, std::string> m;
  3060. /* B */ m["hello"] = "world";
  3061. /* C */ m["foo"] = "bar";
  3062. /* D */ (void) 0; }
  3063. void tst_Gdb::dump_std_map_string_string()
  3064. {
  3065. QByteArray strType =
  3066. "std::basic_string<char, std::char_traits<char>, std::allocator<char> >";
  3067. QByteArray pairType =
  3068. + "std::pair<" + strType + " const, " + strType + " >";
  3069. QByteArray type = "std::map<" + strType + ", " + strType + ", "
  3070. + "std::less<" + strType + " >, "
  3071. + "std::allocator<" + pairType + " > >";
  3072. prepare("dump_std_map_string_string");
  3073. if (checkUninitialized)
  3074. check("A","{iname='local.m',name='m',"
  3075. "type='" + type + "',value='<invalid>',"
  3076. "numchild='0'}");
  3077. next();
  3078. check("B","{iname='local.m',name='m',"
  3079. "type='" + type + "',value='<0 items>',"
  3080. "numchild='0'}");
  3081. next();
  3082. next();
  3083. check("D","{iname='local.m',name='m',"
  3084. "type='" + type + "',value='<2 items>',"
  3085. "numchild='2'}");
  3086. check("D","{iname='local.m',name='m',type='" + type + "',"
  3087. "value='<2 items>',numchild='2',childtype='" + pairType + "',"
  3088. "childnumchild='2',children=["
  3089. "{value=' ',children=["
  3090. "{name='first',type='const " + strType + "',"
  3091. "type='std::string',"
  3092. "valueencoded='6',value='666f6f',numchild='0'},"
  3093. "{name='second',type='" + strType + "',"
  3094. "type='std::string',"
  3095. "valueencoded='6',value='626172',numchild='0'}]},"
  3096. "{value=' ',children=["
  3097. "{name='first',type='const " + strType + "',"
  3098. "type='std::string',"
  3099. "valueencoded='6',value='68656c6c6f',numchild='0'},"
  3100. "{name='second',type='" + strType + "',"
  3101. "type='std::string',"
  3102. "valueencoded='6',value='776f726c64',numchild='0'}]}"
  3103. "]}",
  3104. "local.m,local.m.0,local.m.1");
  3105. }
  3106. ///////////////////////////// std::set<int> ///////////////////////////////////
  3107. void dump_std_set_int()
  3108. {
  3109. /* A */ std::set<int> h;
  3110. /* B */ h.insert(42);
  3111. /* C */ h.insert(44);
  3112. /* D */ (void) 0;
  3113. }
  3114. void tst_Gdb::dump_std_set_int()
  3115. {
  3116. QByteArray setType = "std::set<int, std::less<int>, std::allocator<int> >";
  3117. prepare("dump_std_set_int");
  3118. if (checkUninitialized)
  3119. check("A","{iname='local.h',name='h',"
  3120. "type='" + setType + "',value='<invalid>',"
  3121. "numchild='0'}");
  3122. next(3);
  3123. check("D","{iname='local.h',name='h',"
  3124. "type='" + setType + "',value='<2 items>',numchild='2',"
  3125. "childtype='int',childnumchild='0',children=["
  3126. "{value='42'},{value='44'}]}", "local.h");
  3127. }
  3128. ///////////////////////////// QSet<Int3> ///////////////////////////////////
  3129. void dump_std_set_Int3()
  3130. {
  3131. /* A */ std::set<Int3> h;
  3132. /* B */ h.insert(Int3(42));
  3133. /* C */ h.insert(Int3(44));
  3134. /* D */ (void) 0; }
  3135. void tst_Gdb::dump_std_set_Int3()
  3136. {
  3137. QByteArray setType = "std::set<Int3, std::less<Int3>, std::allocator<Int3> >";
  3138. prepare("dump_std_set_Int3");
  3139. if (checkUninitialized)
  3140. check("A","{iname='local.h',name='h',"
  3141. "type='" + setType + "',value='<invalid>',"
  3142. "numchild='0'}");
  3143. next(3);
  3144. check("D","{iname='local.h',name='h',"
  3145. "type='" + setType + "',value='<2 items>',numchild='2',"
  3146. "childtype='Int3',children=["
  3147. "{value='{...}',numchild='3'},{value='{...}',numchild='3'}]}", "local.h");
  3148. }
  3149. ///////////////////////////// std::string //////////////////////////////////
  3150. void dump_std_string()
  3151. {
  3152. /* A */ std::string str;
  3153. /* B */ str = "Hallo";
  3154. /* C */ (void) 0; }
  3155. void tst_Gdb::dump_std_string()
  3156. {
  3157. prepare("dump_std_string");
  3158. if (checkUninitialized)
  3159. check("A","{iname='local.str',name='str',type='-',"
  3160. "value='<invalid>',numchild='0'}");
  3161. next();
  3162. check("B","{iname='local.str',name='str',type='std::string',"
  3163. "valueencoded='6',value='',numchild='0'}");
  3164. next();
  3165. check("C","{iname='local.str',name='str',type='std::string',"
  3166. "valueencoded='6',value='48616c6c6f',numchild='0'}");
  3167. }
  3168. ///////////////////////////// std::wstring //////////////////////////////////
  3169. void dump_std_wstring()
  3170. {
  3171. /* A */ std::wstring str;
  3172. /* B */ str = L"Hallo";
  3173. /* C */ (void) 0;
  3174. }
  3175. void tst_Gdb::dump_std_wstring()
  3176. {
  3177. prepare("dump_std_wstring");
  3178. if (checkUninitialized)
  3179. check("A","{iname='local.str',name='str',"
  3180. "numchild='0'}");
  3181. next();
  3182. check("B","{iname='local.str',name='str',type='std::string',valueencoded='6',"
  3183. "value='',numchild='0'}");
  3184. next();
  3185. if (sizeof(wchar_t) == 2)
  3186. check("C","{iname='local.str',name='str',type='std::string',valueencoded='6',"
  3187. "value='00480061006c006c006f',numchild='0'}");
  3188. else
  3189. check("C","{iname='local.str',name='str',type='std::string',valueencoded='6',"
  3190. "value='00000048000000610000006c0000006c0000006f',numchild='0'}");
  3191. }
  3192. ///////////////////////////// std::vector<int> //////////////////////////////
  3193. void dump_std_vector()
  3194. {
  3195. /* A */ std::vector<std::list<int> *> vector;
  3196. std::list<int> list;
  3197. /* B */ list.push_back(45);
  3198. /* C */ vector.push_back(new std::list<int>(list));
  3199. /* D */ vector.push_back(0);
  3200. /* E */ (void) list.size();
  3201. /* F */ (void) list.size(); }
  3202. void tst_Gdb::dump_std_vector()
  3203. {
  3204. QByteArray listType = "std::list<int, std::allocator<int> >";
  3205. QByteArray vectorType = "std::vector<" + listType + "*, "
  3206. "std::allocator<" + listType + "*> >";
  3207. prepare("dump_std_vector");
  3208. if (checkUninitialized)
  3209. check("A","{iname='local.vector',name='vector',type='" + vectorType + "',"
  3210. "value='<invalid>',numchild='0'},"
  3211. "{iname='local.list',name='list',type='" + listType + "',"
  3212. "value='<invalid>',numchild='0'}");
  3213. next(2);
  3214. check("B","{iname='local.vector',name='vector',type='" + vectorType + "',"
  3215. "value='<0 items>',numchild='0'},"
  3216. "{iname='local.list',name='list',type='" + listType + "',"
  3217. "value='<0 items>',numchild='0'}");
  3218. next(3);
  3219. check("E","{iname='local.vector',name='vector',type='" + vectorType + "',"
  3220. "value='<2 items>',numchild='2',childtype='" + listType + " *',"
  3221. "childnumchild='1',children=["
  3222. "{type='" + listType + "',value='<1 items>',"
  3223. "childtype='int',"
  3224. "childnumchild='0',children=[{value='45'}]},"
  3225. "{value='0x0',numchild='0'}]},"
  3226. "{iname='local.list',name='list',type='" + listType + "',"
  3227. "value='<1 items>',numchild='1'}",
  3228. "local.vector,local.vector.0");
  3229. }
  3230. /////////////////////////////////////////////////////////////////////////
  3231. //
  3232. // Main
  3233. //
  3234. /////////////////////////////////////////////////////////////////////////
  3235. void breaker() {}
  3236. int main(int argc, char *argv[])
  3237. {
  3238. # ifdef QT_GUI_LIB
  3239. QApplication app(argc, argv);
  3240. # else
  3241. QCoreApplication app(argc, argv);
  3242. # endif
  3243. breaker();
  3244. QStringList args = app.arguments();
  3245. if (args.size() == 2 && args.at(1) == "run") {
  3246. // We are the debugged process, recursively called and steered
  3247. // by our spawning alter ego.
  3248. return 0;
  3249. }
  3250. if (args.size() == 2 && args.at(1) == "debug") {
  3251. dump_array_char();
  3252. dump_array_int();
  3253. dump_std_deque();
  3254. dump_std_list();
  3255. dump_std_map_int_int();
  3256. dump_std_map_string_string();
  3257. dump_std_set_Int3();
  3258. dump_std_set_int();
  3259. dump_std_vector();
  3260. dump_std_string();
  3261. dump_std_wstring();
  3262. dump_Foo();
  3263. dump_misc();
  3264. dump_typedef();
  3265. dump_QAbstractItemModel();
  3266. dump_QAbstractItemAndModelIndex();
  3267. dump_QByteArray();
  3268. dump_QChar();
  3269. dump_QDir();
  3270. dump_QFile();
  3271. dump_QFileInfo();
  3272. dump_QHash_int_int();
  3273. dump_QHash_QString_QString();
  3274. dump_QImage();
  3275. dump_QLinkedList_int();
  3276. dump_QList_char();
  3277. dump_QList_char_star();
  3278. dump_QList_int();
  3279. dump_QList_int_star();
  3280. dump_QList_Int3();
  3281. dump_QList_QString();
  3282. dump_QList_QString3();
  3283. dump_QLocale();
  3284. dump_QMap_int_int();
  3285. dump_QMap_QString_QString();
  3286. dump_QPixmap();
  3287. dump_QObject();
  3288. dump_QPoint();
  3289. dump_QRect();
  3290. dump_QSet_int();
  3291. dump_QSet_Int3();
  3292. dump_QSharedPointer();
  3293. dump_QSize();
  3294. dump_QStack();
  3295. dump_QString();
  3296. dump_QStringList();
  3297. dump_QTextCodec();
  3298. dump_QVariant();
  3299. dump_QVector();
  3300. dump_QWeakPointer_11();
  3301. dump_QWeakPointer_12();
  3302. dump_QWeakPointer_13();
  3303. dump_QWeakPointer_2();
  3304. dump_QWidget();
  3305. }
  3306. try {
  3307. // Plain call. Start the testing.
  3308. tst_Gdb *test = new tst_Gdb;
  3309. return QTest::qExec(test, argc, argv);
  3310. } catch (...) {
  3311. qDebug() << "TEST ABORTED ";
  3312. }
  3313. }
  3314. #include "tst_gdb.moc"