/tests/auto/debugger/tst_gdb.cpp
C++ | 3719 lines | 2936 code | 372 blank | 411 comment | 137 complexity | 4e3b2455dc03faaf2beea2fa3d6b9a5c MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /**************************************************************************
- **
- ** This file is part of Qt Creator
- **
- ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
- **
- ** Contact: Nokia Corporation (qt-info@nokia.com)
- **
- **
- ** GNU Lesser General Public License Usage
- **
- ** This file may be used under the terms of the GNU Lesser General Public
- ** License version 2.1 as published by the Free Software Foundation and
- ** appearing in the file LICENSE.LGPL included in the packaging of this file.
- ** Please review the following information to ensure the GNU Lesser General
- ** Public License version 2.1 requirements will be met:
- ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
- **
- ** In addition, as a special exception, Nokia gives you certain additional
- ** rights. These rights are described in the Nokia Qt LGPL Exception
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ** Other Usage
- **
- ** Alternatively, this file may be used in accordance with the terms and
- ** conditions contained in a signed written agreement between you and Nokia.
- **
- ** If you have questions regarding the use of this file, please contact
- ** Nokia at qt-info@nokia.com.
- **
- **************************************************************************/
- // Note: Keep the strange formating of closing braces in the void dump*()
- // functions as this reduces the risk of gdb reporting 'wrong' line numbers
- // when stopping and therefore the risk of the autotest to fail.
- //bool checkUninitialized = true;
- bool checkUninitialized = false;
- #define DO_DEBUG 1
- //TESTED_COMPONENT=src/plugins/debugger/gdb
- #include "gdb/gdbmi.h"
- #ifdef QT_GUI_LIB
- #include <QBitmap>
- #include <QBrush>
- #include <QColor>
- #include <QCursor>
- #include <QFont>
- #include <QIcon>
- #include <QKeySequence>
- #include <QMatrix4x4>
- #include <QPen>
- #include <QQuaternion>
- #include <QStandardItemModel>
- #include <QStringListModel>
- #include <QTextFormat>
- #include <QTextLength>
- #include <QVector2D>
- #include <QWidget>
- #endif
- #include <QtTest>
- #include <deque>
- #include <map>
- #include <set>
- #include <vector>
- #ifdef Q_OS_WIN
- #include <windows.h>
- #endif
- #undef NS
- #ifdef QT_NAMESPACE
- # define STRINGIFY0(s) #s
- # define STRINGIFY1(s) STRINGIFY0(s)
- # define NS STRINGIFY1(QT_NAMESPACE) "::"
- # define NSX "'" STRINGIFY1(QT_NAMESPACE) "::"
- # define NSY "'"
- #else
- # define NS ""
- # define NSX ""
- # define NSY ""
- #endif
- #undef DEBUG
- #if DO_DEBUG
- # define DEBUG(s) qDebug() << s
- #else
- # define DEBUG(s)
- #endif
- #define DEBUGX(s) qDebug() << s
- #define gettid() QString("0x%1").arg((qulonglong)(void *)currentGdbWrapper(), 0, 16)
- #ifdef Q_OS_WIN
- QString gdbBinary = "c:\\MinGw\\bin\\gdb.exe";
- #else
- QString gdbBinary = "gdb";
- #endif
- void nothing() {}
- template <typename T> QByteArray N(T v) { return QByteArray::number(v); }
- class Foo
- {
- public:
- Foo(int i = 0)
- : a(i), b(2)
- {}
- ~Foo()
- {
- }
- void doit()
- {
- static QObject ob;
- m["1"] = "2";
- h[&ob] = m.begin();
- a += 1;
- --b;
- //s += 'x';
- }
- struct Bar {
- Bar() : ob(0) {}
- QObject *ob;
- };
- public:
- int a, b;
- char x[6];
- private:
- //QString s;
- typedef QMap<QString, QString> Map;
- Map m;
- QHash<QObject *, Map::iterator> h;
- };
- /////////////////////////////////////////////////////////////////////////
- //
- // Helper stuff
- //
- /////////////////////////////////////////////////////////////////////////
- typedef QList<QByteArray> QByteArrayList;
- struct Int3
- {
- Int3(int base = 0) { i1 = 42 + base; i2 = 43 + base; i3 = 44 + base; }
- int i1, i2, i3;
- };
- uint qHash(const Int3 &i)
- {
- return (i.i1 ^ i.i2) ^ i.i3;
- }
- bool operator==(const Int3 &a, const Int3 &b)
- {
- return a.i1 == b.i1 && a.i2 == b.i2 && a.i3 == b.i3;
- }
- bool operator<(const Int3 &a, const Int3 &b)
- {
- return a.i1 < b.i1;
- }
- struct QString3
- {
- QString3() { s1 = "a"; s2 = "b"; s3 = "c"; }
- QString s1, s2, s3;
- };
- class tst_Gdb;
- class GdbWrapper : public QObject
- {
- Q_OBJECT
- public:
- GdbWrapper(tst_Gdb *test);
- ~GdbWrapper();
- void startup(QProcess *proc);
- void run();
- QString errorString() const { return m_errorString; }
- public slots:
- void readStandardOutput();
- bool parseOutput(const QByteArray &ba);
- void readStandardError();
- void handleGdbStarted();
- void handleGdbError(QProcess::ProcessError);
- void handleGdbFinished(int, QProcess::ExitStatus);
- QByteArray writeToGdbRequested(const QByteArray &ba)
- {
- DEBUG("GDB IN: " << ba);
- m_proc.write(ba);
- m_proc.write("\n");
- while (true) {
- m_proc.waitForReadyRead();
- QByteArray output = m_proc.readAllStandardOutput();
- if (parseOutput(output))
- break;
- }
- return m_buffer;
- }
- public:
- QByteArray m_lastStopped; // last seen "*stopped" message
- int m_line; // line extracted from last "*stopped" message
- QProcess m_proc;
- tst_Gdb *m_test; // not owned
- QString m_errorString;
- QByteArray m_buffer;
- };
- class tst_Gdb : public QObject
- {
- Q_OBJECT
- public:
- tst_Gdb();
- void prepare(const QByteArray &function);
- void check(const QByteArray &label, const QByteArray &expected,
- const QByteArray &expanded = QByteArray(), bool fancy = true);
- void next(int n = 1);
- QByteArray writeToGdb(const QByteArray &ba)
- {
- return m_gdb->writeToGdbRequested(ba);
- }
- private slots:
- void initTestCase();
- void cleanupTestCase();
- void dump_array();
- void dump_misc();
- void dump_typedef();
- void dump_std_deque();
- void dump_std_list();
- void dump_std_map_int_int();
- void dump_std_map_string_string();
- void dump_std_set_Int3();
- void dump_std_set_int();
- void dump_std_string();
- void dump_std_vector();
- void dump_std_wstring();
- void dump_Foo();
- //void dump_QImageData();
- void dump_QAbstractItemAndModelIndex();
- void dump_QAbstractItemModel();
- void dump_QByteArray();
- void dump_QChar();
- void dump_QDateTime();
- void dump_QDir();
- void dump_QFile();
- void dump_QFileInfo();
- void dump_QHash_QString_QString();
- void dump_QHash_int_int();
- void dump_QImage();
- void dump_QLinkedList_int();
- void dump_QList_Int3();
- void dump_QList_QString();
- void dump_QList_QString3();
- void dump_QList_char();
- void dump_QList_char_star();
- void dump_QList_int();
- void dump_QList_int_star();
- void dump_QLocale();
- void dump_QMap_QString_QString();
- void dump_QMap_int_int();
- void dump_QObject();
- void dump_QPixmap();
- void dump_QPoint();
- void dump_QRect();
- void dump_QSet_Int3();
- void dump_QSet_int();
- void dump_QSharedPointer();
- void dump_QSize();
- void dump_QStack();
- void dump_QString();
- void dump_QStringList();
- void dump_QTextCodec();
- void dump_QVariant();
- void dump_QVector();
- void dump_QWeakPointer_11();
- void dump_QWeakPointer_12();
- void dump_QWeakPointer_13();
- void dump_QWeakPointer_2();
- void dump_QWidget();
- public slots:
- void dumperCompatibility();
- private:
- #if 0
- void dump_QAbstractItemModelHelper(QAbstractItemModel &m);
- void dump_QObjectChildListHelper(QObject &o);
- void dump_QObjectSignalHelper(QObject &o, int sigNum);
- #endif
- QHash<QByteArray, int> m_lineForLabel;
- QByteArray m_function;
- GdbWrapper *m_gdb;
- };
- //
- // Dumpers
- //
- QByteArray str(const void *p)
- {
- char buf[100];
- sprintf(buf, "%p", p);
- return buf;
- }
- void tst_Gdb::dumperCompatibility()
- {
- // Ensure that no arbitrary padding is introduced by QVectorTypedData.
- const size_t qVectorDataSize = 16;
- QCOMPARE(sizeof(QVectorData), qVectorDataSize);
- QVectorTypedData<int> *v = 0;
- QCOMPARE(size_t(&v->array), qVectorDataSize);
- }
- static const QByteArray utfToHex(const QString &string)
- {
- return QByteArray(reinterpret_cast<const char *>(string.utf16()),
- 2 * string.size()).toHex();
- }
- static const QByteArray specQString(const QString &str)
- {
- return "valueencoded='7',value='" + utfToHex(str) + "'";
- }
- static const QByteArray specQChar(QChar ch)
- {
- return QByteArray("value=''") + char(ch.unicode()) + "' ("
- + QByteArray::number(ch.unicode()) + ")'";
- //return "valueencoded='7',value='" +
- // utfToHex(QString(QLatin1String("'%1' (%2)")).
- // arg(ch).arg(ch.unicode())) + "'";
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // GdbWrapper
- //
- /////////////////////////////////////////////////////////////////////////
- GdbWrapper::GdbWrapper(tst_Gdb *test) : m_test(test)
- {
- qWarning() << "SETUP START\n\n";
- #ifndef Q_CC_GNU
- QSKIP("gdb test not applicable for compiler", SkipAll);
- #endif
- //qDebug() << "\nRUN" << getpid() << gettid();
- QStringList args;
- args << QLatin1String("-i")
- << QLatin1String("mi") << QLatin1String("--args")
- << qApp->applicationFilePath();
- qWarning() << "Starting" << gdbBinary << args;
- m_proc.start(gdbBinary, args);
- if (!m_proc.waitForStarted()) {
- const QString msg = QString::fromLatin1("Unable to run %1: %2")
- .arg(gdbBinary, m_proc.errorString());
- QSKIP(msg.toLatin1().constData(), SkipAll);
- }
- connect(&m_proc, SIGNAL(error(QProcess::ProcessError)),
- this, SLOT(handleGdbError(QProcess::ProcessError)));
- connect(&m_proc, SIGNAL(finished(int,QProcess::ExitStatus)),
- this, SLOT(handleGdbFinished(int,QProcess::ExitStatus)));
- connect(&m_proc, SIGNAL(started()),
- this, SLOT(handleGdbStarted()));
- connect(&m_proc, SIGNAL(readyReadStandardOutput()),
- this, SLOT(readStandardOutput()));
- connect(&m_proc, SIGNAL(readyReadStandardError()),
- this, SLOT(readStandardError()));
- m_proc.write("python execfile('../../../share/qtcreator/dumper/bridge.py')\n");
- m_proc.write("python execfile('../../../share/qtcreator/dumper/dumper.py')\n");
- m_proc.write("python execfile('../../../share/qtcreator/dumper/qttypes.py')\n");
- m_proc.write("bbsetup\n");
- m_proc.write("break breaker\n");
- m_proc.write("handle SIGSTOP stop pass\n");
- m_proc.write("run\n");
- }
- GdbWrapper::~GdbWrapper()
- {
- }
- void GdbWrapper::handleGdbError(QProcess::ProcessError error)
- {
- qDebug() << "GDB ERROR: " << error;
- }
- void GdbWrapper::handleGdbFinished(int code, QProcess::ExitStatus st)
- {
- qDebug() << "GDB FINISHED: " << code << st;
- }
- void GdbWrapper::readStandardOutput()
- {
- //parseOutput(m_proc.readAllStandardOutput());
- }
- bool GdbWrapper::parseOutput(const QByteArray &ba0)
- {
- if (ba0.isEmpty())
- return false;
- QByteArray ba = ba0;
- DEBUG("GDB OUT: " << ba);
- // =library-loaded...
- if (ba.startsWith("=")) {
- DEBUG("LIBRARY LOADED");
- return false;
- }
- if (ba.startsWith("*stopped")) {
- m_lastStopped = ba;
- DEBUG("GDB OUT 2: " << ba);
- if (!ba.contains("func=\"breaker\"")) {
- int pos1 = ba.indexOf(",line=\"") + 7;
- int pos2 = ba.indexOf("\"", pos1);
- m_line = ba.mid(pos1, pos2 - pos1).toInt();
- DEBUG(" LINE 1: " << m_line);
- }
- }
- // The "call" is always aborted with a message like:
- // "~"2321\t /* A */ QString s;\n" "
- // "&"The program being debugged stopped while in a function called ..."
- // "^error,msg="The program being debugged stopped ..."
- // Extract the "2321" from this
- static QByteArray lastText;
- if (ba.startsWith("~")) {
- lastText = ba;
- if (ba.size() > 8
- && (ba.at(2) < 'a' || ba.at(2) > 'z')
- && (ba.at(2) < '0' || ba.at(2) > '9')
- && !ba.startsWith("~\"Breakpoint ")
- && !ba.startsWith("~\" at ")
- && !ba.startsWith("~\" locals=")
- && !ba.startsWith("~\"XXX:")) {
- QByteArray ba1 = ba.mid(2, ba.size() - 6);
- if (ba1.startsWith(" File "))
- ba1 = ba1.replace(2, ba1.indexOf(','), "");
- //qWarning() << "OUT: " << ba1;
- }
- }
- if (ba.startsWith("&\"The program being debugged")) {
- int pos1 = 2;
- int pos2 = lastText.indexOf("\\", pos1);
- m_line = lastText.mid(pos1, pos2 - pos1).toInt();
- DEBUG(" LINE 2: " << m_line);
- }
- if (ba.startsWith("^error,msg=")) {
- if (!ba.startsWith("^error,msg=\"The program being debugged stopped"))
- qWarning() << "ERROR: " << ba.mid(1, ba.size() - 3);
- }
- if (ba.startsWith("~\"XXX: ")) {
- QByteArray ba1 = ba.mid(7, ba.size() - 11);
- qWarning() << "MESSAGE: " << ba.mid(7, ba.size() - 12);
- }
- ba = ba.replace("\\\"", "\"");
- // No interesting output before 'locals=...'
- int pos = ba.indexOf("locals={iname=");
- if (pos == -1 && ba.isEmpty())
- return true;
- QByteArray output;
- if (output.isEmpty())
- output = ba.mid(pos);
- else
- output += ba;
- // Up to ^done\n(gdb)
- pos = output.indexOf("(gdb)");
- if (pos == -1)
- return true;
- output = output.left(pos);
- pos = output.indexOf("^done");
- if (pos >= 4)
- output = output.left(pos - 4);
- if (output.isEmpty())
- return true;
- m_buffer += output;
- return true;
- }
- void GdbWrapper::readStandardError()
- {
- QByteArray ba = m_proc.readAllStandardError();
- qDebug() << "GDB ERR: " << ba;
- }
- void GdbWrapper::handleGdbStarted()
- {
- //qDebug() << "\n\nGDB STARTED" << getpid() << gettid() << "\n\n";
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Test Class Framework Implementation
- //
- /////////////////////////////////////////////////////////////////////////
- tst_Gdb::tst_Gdb()
- : m_gdb(0)
- {
- }
- void tst_Gdb::initTestCase()
- {
- const QString fileName = "tst_gdb.cpp";
- QFile file(fileName);
- if (!file.open(QIODevice::ReadOnly)) {
- const QString msg = QString::fromLatin1("Unable to open %1: %2")
- .arg(fileName, file.errorString());
- QSKIP(msg.toLatin1().constData(), SkipAll);
- }
- QByteArray funcName;
- const QByteArrayList bal = file.readAll().split('\n');
- Q_ASSERT(bal.size() > 100);
- for (int i = 0; i != bal.size(); ++i) {
- const QByteArray &ba = bal.at(i);
- if (ba.startsWith("void dump")) {
- int pos = ba.indexOf('(');
- funcName = ba.mid(5, pos - 5) + '@';
- } else if (ba.startsWith(" /*")) {
- int pos = ba.indexOf('*', 7);
- m_lineForLabel[QByteArray(funcName + ba.mid(7, pos - 8)).trimmed()] = i + 1;
- }
- }
- Q_ASSERT(!m_gdb);
- m_gdb = new GdbWrapper(this);
- }
- void tst_Gdb::prepare(const QByteArray &function)
- {
- Q_ASSERT(m_gdb);
- m_function = function;
- writeToGdb("b " + function);
- writeToGdb("call " + function + "()");
- }
- static bool isJoker(const QByteArray &ba)
- {
- return ba.endsWith("'-'") || ba.contains("'-'}");
- }
- void tst_Gdb::check(const QByteArray &label, const QByteArray &expected0,
- const QByteArray &expanded, bool fancy)
- {
- //qDebug() << "\nABOUT TO RUN TEST: " << expanded;
- qWarning() << label << "...";
- QByteArray options = "pe";
- if (fancy)
- options += ",fancy";
- options += ",autoderef";
- QByteArray ba = writeToGdb("bb options:" + options
- + " vars: expanded:" + expanded
- + " typeformats: formats: watchers:\n");
- //bb options:fancy,autoderef vars: expanded: typeformats:63686172202a=1
- //formats: watchers:
- //locals.fromString("{" + ba + "}");
- QByteArray received = ba.replace("\"", "'");
- QByteArray actual = received.trimmed();
- int pos = actual.indexOf("^done");
- if (pos != -1)
- actual = actual.left(pos);
- if (actual.endsWith("\n"))
- actual.chop(1);
- if (actual.endsWith("\\n"))
- actual.chop(2);
- QByteArray expected = "locals={iname='local',name='Locals',value=' ',type=' ',"
- "children=[" + expected0 + "]}";
- int line = m_gdb->m_line;
- QByteArrayList l1_0 = actual.split(',');
- QByteArrayList l1;
- for (int i = 0; i != l1_0.size(); ++i) {
- const QByteArray &ba = l1_0.at(i);
- if (ba.startsWith("watchers={iname"))
- break;
- if (!ba.startsWith("addr"))
- l1.append(ba);
- }
- QByteArrayList l2 = expected.split(',');
- bool ok = l1.size() == l2.size();
- if (ok) {
- for (int i = 0 ; i < l1.size(); ++i) {
- // Use "-" as joker.
- if (l1.at(i) != l2.at(i) && !isJoker(l2.at(i)))
- ok = false;
- }
- } else {
- qWarning() << "!= size: " << l1.size() << l2.size();
- }
- if (!ok) {
- int i = 0;
- for ( ; i < l1.size() && i < l2.size(); ++i) {
- if (l1.at(i) == l2.at(i) || isJoker(l2.at(i))) {
- qWarning() << "== " << l1.at(i);
- } else {
- //qWarning() << "!= " << l1.at(i).right(30) << l2.at(i).right(30);
- qWarning() << "!= " << l1.at(i) << l2.at(i);
- ok = false;
- }
- }
- for ( ; i < l2.size(); ++i)
- qWarning() << "!= " << "-----" << l2.at(i);
- for ( ; i < l1.size(); ++i)
- qWarning() << "!= " << l1.at(i) << "-----";
- if (l1.size() != l2.size()) {
- ok = false;
- qWarning() << "!= size: " << l1.size() << l2.size();
- }
- qWarning() << "RECEIVED: " << received;
- qWarning() << "ACTUAL : " << actual;
- }
- QCOMPARE(ok, true);
- //qWarning() << "LINE: " << line << "ACT/EXP" << m_function + '@' + label;
- //QCOMPARE(actual, expected);
- int expline = m_lineForLabel.value(m_function + '@' + label);
- int actline = line;
- if (actline != expline) {
- qWarning() << "LAST STOPPED: " << m_gdb->m_lastStopped;
- }
- QCOMPARE(actline, expline);
- }
- void tst_Gdb::next(int n)
- {
- for (int i = 0; i != n; ++i)
- writeToGdb("next");
- }
- void tst_Gdb::cleanupTestCase()
- {
- Q_ASSERT(m_gdb);
- writeToGdb("kill");
- writeToGdb("quit");
- //m_gdb.m_proc.waitForFinished();
- //m_gdb.wait();
- delete m_gdb;
- m_gdb = 0;
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Dumper Tests
- //
- /////////////////////////////////////////////////////////////////////////
- ///////////////////////////// Foo structure /////////////////////////////////
- /*
- Foo:
- int a, b;
- char x[6];
- typedef QMap<QString, QString> Map;
- Map m;
- QHash<QObject *, Map::iterator> h;
- */
- void dump_Foo()
- {
- /* A */ Foo f;
- /* B */ f.doit();
- /* D */ (void) 0;
- }
- void tst_Gdb::dump_Foo()
- {
- prepare("dump_Foo");
- next();
- check("B","{iname='local.f',name='f',type='Foo',"
- "value='-',numchild='5'}", "", 0);
- check("B","{iname='local.f',name='f',type='Foo',"
- "value='-',numchild='5',children=["
- "{name='a',type='int',value='0',numchild='0'},"
- "{name='b',type='int',value='2',numchild='0'},"
- "{name='x',type='char [6]',"
- "value='{...}',numchild='1'},"
- "{name='m',type='" NS "QMap<" NS "QString, " NS "QString>',"
- "value='{...}',numchild='1'},"
- "{name='h',type='" NS "QHash<" NS "QObject*, "
- "" NS "QMap<" NS "QString, " NS "QString>::iterator>',"
- "value='{...}',numchild='1'}]}",
- "local.f", 0);
- }
- ///////////////////////////// Array ///////////////////////////////////////
- void dump_array_char()
- {
- /* A */ const char s[] = "XYZ";
- /* B */ (void) &s; }
- void dump_array_int()
- {
- /* A */ int s[] = {1, 2, 3};
- /* B */ (void) s; }
- void tst_Gdb::dump_array()
- {
- prepare("dump_array_char");
- next();
- // FIXME: numchild should be '4', not '1'
- check("B","{iname='local.s',name='s',type='char [4]',"
- "value='-',numchild='1'}", "");
- check("B","{iname='local.s',name='s',type='char [4]',"
- "value='-',numchild='1',childtype='char',childnumchild='0',"
- "children=[{value='88 'X''},{value='89 'Y''},{value='90 'Z''},"
- "{value='0 '\\\\000''}]}",
- "local.s");
- prepare("dump_array_int");
- next();
- // FIXME: numchild should be '3', not '1'
- check("B","{iname='local.s',name='s',type='int [3]',"
- "value='-',numchild='1'}", "");
- check("B","{iname='local.s',name='s',type='int [3]',"
- "value='-',numchild='1',childtype='int',childnumchild='0',"
- "children=[{value='1'},{value='2'},{value='3'}]}",
- "local.s");
- }
- ///////////////////////////// Misc stuff /////////////////////////////////
- void dump_misc()
- {
- #if 1
- /* A */ int *s = new int(1);
- /* B */ *s += 1;
- /* D */ (void) 0;
- #else
- QVariant v1(QLatin1String("hallo"));
- QVariant v2(QStringList(QLatin1String("hallo")));
- QVector<QString> vec;
- vec.push_back("Hallo");
- vec.push_back("Hallo2");
- std::set<std::string> stdSet;
- stdSet.insert("s1");
- # ifdef QT_GUI_LIB
- QWidget *ww = 0; //this;
- QWidget &wwr = *ww;
- Q_UNUSED(wwr);
- # endif
- QSharedPointer<QString> sps(new QString("hallo"));
- QList<QSharedPointer<QString> > spsl;
- spsl.push_back(sps);
- QMap<QString,QString> stringmap;
- QMap<int,int> intmap;
- std::map<std::string, std::string> stdstringmap;
- stdstringmap[std::string("A")] = std::string("B");
- int xxx = 45;
- if (1 == 1) {
- int xxx = 7;
- qDebug() << xxx;
- }
- QLinkedList<QString> lls;
- lls << "link1" << "link2";
- # ifdef QT_GUI_LIB
- QStandardItemModel *model = new QStandardItemModel;
- model->appendRow(new QStandardItem("i1"));
- # endif
- QList <QList<int> > nestedIntList;
- nestedIntList << QList<int>();
- nestedIntList.front() << 1 << 2;
- QVariantList vList;
- vList.push_back(QVariant(42));
- vList.push_back(QVariant("HALLO"));
- stringmap.insert("A", "B");
- intmap.insert(3,4);
- QSet<QString> stringSet;
- stringSet.insert("S1");
- stringSet.insert("S2");
- qDebug() << *(spsl.front()) << xxx;
- #endif
- }
- void tst_Gdb::dump_misc()
- {
- prepare("dump_misc");
- next();
- check("B","{iname='local.s',name='s',type='int *',"
- "value='-',numchild='1'}", "", 0);
- //check("B","{iname='local.s',name='s',type='int *',"
- // "value='1',numchild='0'}", "local.s,local.model", 0);
- check("B","{iname='local.s',name='s',type='int *',"
- "value='-',numchild='1',children=["
- "{name='*',type='int',value='1',numchild='0'}]}",
- "local.s,local.model", 0);
- }
- ///////////////////////////// typedef ////////////////////////////////////
- void dump_typedef()
- {
- /* A */ typedef QMap<uint, double> T;
- /* B */ T t;
- /* C */ t[11] = 13.0;
- /* D */ (void) 0;
- }
- void tst_Gdb::dump_typedef()
- {
- prepare("dump_typedef");
- next(2);
- check("D","{iname='local.t',name='t',type='T',"
- //"basetype='" NS "QMap<unsigned int, double>',"
- "value='-',numchild='1',"
- "childtype='double',childnumchild='0',"
- "children=[{name='11',value='13'}]}", "local.t");
- }
- #if 0
- void tst_Gdb::dump_QAbstractItemHelper(QModelIndex &index)
- {
- const QAbstractItemModel *model = index.model();
- const QString &rowStr = N(index.row());
- const QString &colStr = N(index.column());
- const QByteArray &internalPtrStrSymbolic = ptrToBa(index.internalPointer());
- const QByteArray &internalPtrStrValue = ptrToBa(index.internalPointer(), false);
- const QByteArray &modelPtrStr = ptrToBa(model);
- QByteArray indexSpecSymbolic = QByteArray().append(rowStr + "," + colStr + ",").
- append(internalPtrStrSymbolic + "," + modelPtrStr);
- QByteArray indexSpecValue = QByteArray().append(rowStr + "," + colStr + ",").
- append(internalPtrStrValue + "," + modelPtrStr);
- QByteArray expected = QByteArray("tiname='iname',addr='").append(ptrToBa(&index)).
- append("',type='" NS "QAbstractItem',addr='$").append(indexSpecSymbolic).
- append("',value='").append(valToString(model->data(index).toString())).
- append("',numchild='1',children=[");
- int rowCount = model->rowCount(index);
- int columnCount = model->columnCount(index);
- for (int row = 0; row < rowCount; ++row) {
- for (int col = 0; col < columnCount; ++col) {
- const QModelIndex &childIndex = model->index(row, col, index);
- expected.append("{name='[").append(valToString(row)).append(",").
- append(N(col)).append("]',numchild='1',addr='$").
- append(N(childIndex.row())).append(",").
- append(N(childIndex.column())).append(",").
- append(ptrToBa(childIndex.internalPointer())).append(",").
- append(modelPtrStr).append("',type='" NS "QAbstractItem',value='").
- append(valToString(model->data(childIndex).toString())).append("'}");
- if (col < columnCount - 1 || row < rowCount - 1)
- expected.append(",");
- }
- }
- expected.append("]");
- testDumper(expected, &index, NS"QAbstractItem", true, indexSpecValue);
- }
- #endif
- class PseudoTreeItemModel : public QAbstractItemModel
- {
- public:
- PseudoTreeItemModel() : QAbstractItemModel(), parent1(0),
- parent1Child(1), parent2(10), parent2Child1(11), parent2Child2(12)
- {}
- int columnCount(const QModelIndex &parent = QModelIndex()) const
- {
- Q_UNUSED(parent);
- return 1;
- }
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
- {
- return !index.isValid() || role != Qt::DisplayRole ?
- QVariant() : *static_cast<int *>(index.internalPointer());
- }
- QModelIndex index(int row, int column,
- const QModelIndex & parent = QModelIndex()) const
- {
- QModelIndex index;
- if (column == 0) {
- if (!parent.isValid()) {
- if (row == 0)
- index = createIndex(row, column, &parent1);
- else if (row == 1)
- index = createIndex(row, column, &parent2);
- } else if (parent.internalPointer() == &parent1 && row == 0) {
- index = createIndex(row, column, &parent1Child);
- } else if (parent.internalPointer() == &parent2) {
- index = createIndex(row, column,
- row == 0 ? &parent2Child1 : &parent2Child2);
- }
- }
- return index;
- }
- QModelIndex parent(const QModelIndex & index) const
- {
- QModelIndex parent;
- if (index.isValid()) {
- if (index.internalPointer() == &parent1Child)
- parent = createIndex(0, 0, &parent1);
- else if (index.internalPointer() == &parent2Child1 ||
- index.internalPointer() == &parent2Child2)
- parent = createIndex(1, 0, &parent2);
- }
- return parent;
- }
- int rowCount(const QModelIndex &parent = QModelIndex()) const
- {
- int rowCount;
- if (!parent.isValid() || parent.internalPointer() == &parent2)
- rowCount = 2;
- else if (parent.internalPointer() == &parent1)
- rowCount = 1;
- else
- rowCount = 0;
- return rowCount;
- }
- private:
- mutable int parent1;
- mutable int parent1Child;
- mutable int parent2;
- mutable int parent2Child1;
- mutable int parent2Child2;
- };
- ///////////////////////////// QAbstractItemAndModelIndex //////////////////////////
- // /* A */ QStringListModel m(QStringList() << "item1" << "item2" << "item3");
- // /* B */ index = m.index(2, 0);
- void dump_QAbstractItemAndModelIndex()
- {
- /* A */ PseudoTreeItemModel m2; QModelIndex index;
- /* C */ index = m2.index(0, 0);
- /* D */ index = m2.index(1, 0);
- /* E */ index = m2.index(0, 0, index);
- /* F */ (void) index.row();
- }
- void tst_Gdb::dump_QAbstractItemAndModelIndex()
- {
- prepare("dump_QAbstractItemAndModelIndex");
- if (checkUninitialized)
- check("A", "");
- next();
- check("C", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
- "value='{...}',numchild='6'},"
- "{iname='local.index',name='index',type='" NS "QModelIndex',"
- "value='(invalid)',numchild='0'}",
- "local.index");
- next();
- check("D", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
- "value='{...}',numchild='6'},"
- "{iname='local.index',name='index',type='" NS "QModelIndex',"
- "value='(0, 0)',numchild='5',children=["
- "{name='row',value='0',type='int',numchild='0'},"
- "{name='column',value='0',type='int',numchild='0'},"
- "{name='parent',type='" NS "QModelIndex',value='(invalid)',numchild='0'},"
- "{name='model',value='-',type='" NS "QAbstractItemModel*',numchild='1'}]}",
- "local.index");
- next();
- check("E", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
- "value='{...}',numchild='6'},"
- "{iname='local.index',name='index',type='" NS "QModelIndex',"
- "value='(1, 0)',numchild='5',children=["
- "{name='row',value='1',type='int',numchild='0'},"
- "{name='column',value='0',type='int',numchild='0'},"
- "{name='parent',type='" NS "QModelIndex',value='(invalid)',numchild='0'},"
- "{name='model',value='-',type='" NS "QAbstractItemModel*',numchild='1'}]}",
- "local.index");
- next();
- check("F", "{iname='local.m2',name='m2',type='PseudoTreeItemModel',"
- "value='{...}',numchild='6'},"
- "{iname='local.index',name='index',type='" NS "QModelIndex',"
- "value='(0, 0)',numchild='5',children=["
- "{name='row',value='0',type='int',numchild='0'},"
- "{name='column',value='0',type='int',numchild='0'},"
- "{name='parent',type='" NS "QModelIndex',value='(1, 0)',numchild='5'},"
- "{name='model',value='-',type='" NS "QAbstractItemModel*',numchild='1'}]}",
- "local.index");
- }
- /*
- QByteArray dump_QAbstractItemModelHelper(QAbstractItemModel &m)
- {
- QByteArray address = ptrToBa(&m);
- QByteArray expected = QByteArray("tiname='iname',"
- "type='" NS "QAbstractItemModel',value='(%,%)',numchild='1',children=["
- "{numchild='1',name='" NS "QObject',value='%',"
- "valueencoded='2',type='" NS "QObject',displayedtype='%'}")
- << address
- << N(m.rowCount())
- << N(m.columnCount())
- << address
- << utfToHex(m.objectName())
- << m.metaObject()->className();
- for (int row = 0; row < m.rowCount(); ++row) {
- for (int column = 0; column < m.columnCount(); ++column) {
- QModelIndex mi = m.index(row, column);
- expected.append(QByteArray(",{name='[%,%]',value='%',"
- "valueencoded='2',numchild='1',%,%,%',"
- "type='" NS "QAbstractItem'}")
- << N(row)
- << N(column)
- << utfToHex(m.data(mi).toString())
- << N(mi.row())
- << N(mi.column())
- << ptrToBa(mi.internalPointer())
- << ptrToBa(mi.model()));
- }
- }
- expected.append("]");
- return expected;
- }
- */
- void dump_QAbstractItemModel()
- {
- # ifdef QT_GUI_LIB
- /* A */ QStringList strList;
- strList << "String 1";
- QStringListModel model1(strList);
- QStandardItemModel model2(0, 2);
- /* B */ model1.setStringList(strList);
- /* C */ strList << "String 2";
- /* D */ model1.setStringList(strList);
- /* E */ model2.appendRow(QList<QStandardItem *>() << (new QStandardItem("Item (0,0)")) << (new QStandardItem("Item (0,1)")));
- /* F */ model2.appendRow(QList<QStandardItem *>() << (new QStandardItem("Item (1,0)")) << (new QStandardItem("Item (1,1)")));
- /* G */ (void) (model1.rowCount() + model2.rowCount() + strList.size());
- # endif
- }
- void tst_Gdb::dump_QAbstractItemModel()
- {
- # ifdef QT_GUI_LIB
- /* A */ QStringList strList;
- QString template_ =
- "{iname='local.strList',name='strList',type='" NS "QStringList',"
- "value='<%1 items>',numchild='%1'},"
- "{iname='local.model1',name='model1',type='" NS "QStringListModel',"
- "value='{...}',numchild='3'},"
- "{iname='local.model2',name='model2',type='" NS "QStandardItemModel',"
- "value='{...}',numchild='2'}";
- prepare("dump_QAbstractItemModel");
- if (checkUninitialized)
- check("A", template_.arg("1").toAscii());
- next(4);
- check("B", template_.arg("1").toAscii());
- # endif
- }
- ///////////////////////////// QByteArray /////////////////////////////////
- void dump_QByteArray()
- {
- /* A */ QByteArray ba; // Empty object.
- /* B */ ba.append('a'); // One element.
- /* C */ ba.append('b'); // Two elements.
- /* D */ ba = QByteArray(101, 'a'); // > 100 elements.
- /* E */ ba = QByteArray("abc\a\n\r\033\'\"?"); // Mixed.
- /* F */ (void) 0;
- }
- void tst_Gdb::dump_QByteArray()
- {
- prepare("dump_QByteArray");
- if (checkUninitialized)
- check("A","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "value='<invalid>',numchild='0'}");
- next();
- check("B","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "valueencoded='6',value='',numchild='0'}");
- next();
- check("C","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "valueencoded='6',value='61',numchild='1'}");
- next();
- check("D","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "valueencoded='6',value='6162',numchild='2'}");
- next();
- check("E","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "valueencoded='6',value='616161616161616161616161616161616161"
- "616161616161616161616161616161616161616161616161616161616161"
- "616161616161616161616161616161616161616161616161616161616161"
- "6161616161616161616161616161616161616161616161',numchild='101'}");
- next();
- check("F","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "valueencoded='6',value='616263070a0d1b27223f',numchild='10'}");
- check("F","{iname='local.ba',name='ba',type='" NS "QByteArray',"
- "valueencoded='6',value='616263070a0d1b27223f',numchild='10',"
- "childtype='char',childnumchild='0',"
- "children=[{value='97 'a''},{value='98 'b''},"
- "{value='99 'c''},{value='7 '\\\\a''},"
- "{value='10 '\\\\n''},{value='13 '\\\\r''},"
- "{value='27 '\\\\033''},{value='39 '\\\\'''},"
- "{value='34 ''''},{value='63 '?''}]}",
- "local.ba");
- }
- ///////////////////////////// QChar /////////////////////////////////
- void dump_QChar()
- {
- /* A */ QChar c('X'); // Printable ASCII character.
- /* B */ c = QChar(0x600); // Printable non-ASCII character.
- /* C */ c = QChar::fromAscii('\a'); // Non-printable ASCII character.
- /* D */ c = QChar(0x9f); // Non-printable non-ASCII character.
- /* E */ c = QChar::fromAscii('?'); // The replacement character.
- /* F */ (void) 0; }
- void tst_Gdb::dump_QChar()
- {
- prepare("dump_QChar");
- next();
- // Case 1: Printable ASCII character.
- check("B","{iname='local.c',name='c',type='" NS "QChar',"
- "value=''X' (88)',numchild='0'}");
- next();
- // Case 2: Printable non-ASCII character.
- check("C","{iname='local.c',name='c',type='" NS "QChar',"
- "value=''?' (1536)',numchild='0'}");
- next();
- // Case 3: Non-printable ASCII character.
- check("D","{iname='local.c',name='c',type='" NS "QChar',"
- "value=''?' (7)',numchild='0'}");
- next();
- // Case 4: Non-printable non-ASCII character.
- check("E","{iname='local.c',name='c',type='" NS "QChar',"
- "value=''?' (159)',numchild='0'}");
- next();
- // Case 5: Printable ASCII Character that looks like the replacement character.
- check("F","{iname='local.c',name='c',type='" NS "QChar',"
- "value=''?' (63)',numchild='0'}");
- }
- ///////////////////////////// QDateTime /////////////////////////////////
- void dump_QDateTime()
- {
- # ifndef QT_NO_DATESTRING
- /* A */ QDateTime d;
- /* B */ d = QDateTime::fromString("M5d21y7110:31:02", "'M'M'd'd'y'yyhh:mm:ss");
- /* C */ (void) d.isNull();
- # endif
- }
- void tst_Gdb::dump_QDateTime()
- {
- # ifndef QT_NO_DATESTRING
- prepare("dump_QDateTime");
- if (checkUninitialized)
- check("A","{iname='local.d',name='d',"
- "type='" NS "QDateTime',value='<invalid>',"
- "numchild='0'}");
- next();
- check("B", "{iname='local.d',name='d',type='" NS "QDateTime',"
- "valueencoded='7',value='-',numchild='3',children=["
- "{name='isNull',type='bool',value='true',numchild='0'},"
- "{name='toTime_t',type='unsigned int',value='4294967295',numchild='0'},"
- "{name='toString',type='myns::QString',valueencoded='7',"
- "value='',numchild='0'},"
- "{name='(ISO)',type='myns::QString',valueencoded='7',"
- "value='',numchild='0'},"
- "{name='(SystemLocale)',type='myns::QString',valueencoded='7',"
- "value='',numchild='0'},"
- "{name='(Locale)',type='myns::QString',valueencoded='7',"
- "value='',numchild='0'},"
- "{name='toUTC',type='myns::QDateTime',valueencoded='7',"
- "value='',numchild='3'},"
- "{name='toLocalTime',type='myns::QDateTime',valueencoded='7',"
- "value='',numchild='3'}"
- "]}",
- "local.d");
- next();
- check("C", "{iname='local.d',name='d',type='" NS "QDateTime',"
- "valueencoded='7',value='-',"
- "numchild='3',children=["
- "{name='isNull',type='bool',value='false',numchild='0'},"
- "{name='toTime_t',type='unsigned int',value='43666262',numchild='0'},"
- "{name='toString',type='myns::QString',valueencoded='7',"
- "value='-',numchild='0'},"
- "{name='(ISO)',type='myns::QString',valueencoded='7',"
- "value='-',numchild='0'},"
- "{name='(SystemLocale)',type='myns::QString',valueencoded='7',"
- "value='-',numchild='0'},"
- "{name='(Locale)',type='myns::QString',valueencoded='7',"
- "value='-',numchild='0'},"
- "{name='toUTC',type='myns::QDateTime',valueencoded='7',"
- "value='-',numchild='3'},"
- "{name='toLocalTime',type='myns::QDateTime',valueencoded='7',"
- "value='-',numchild='3'}"
- "]}",
- "local.d");
- # endif
- }
- ///////////////////////////// QDir /////////////////////////////////
- void dump_QDir()
- {
- /* A */ QDir dir = QDir::current(); // Case 1: Current working directory.
- /* B */ dir = QDir::root(); // Case 2: Root directory.
- /* C */ (void) dir.absolutePath(); }
- void tst_Gdb::dump_QDir()
- {
- prepare("dump_QDir");
- if (checkUninitialized)
- check("A","{iname='local.dir',name='dir',"
- "type='" NS "QDir',value='<invalid>',"
- "numchild='0'}");
- next();
- check("B", "{iname='local.dir',name='dir',type='" NS "QDir',"
- "valueencoded='7',value='-',numchild='2',children=["
- "{name='absolutePath',type='" NS "QString',"
- "valueencoded='7',value='-',numchild='0'},"
- "{name='canonicalPath',type='" NS "QString',"
- "valueencoded='7',value='-',numchild='0'}]}",
- "local.dir");
- next();
- check("C", "{iname='local.dir',name='dir',type='" NS "QDir',"
- "valueencoded='7',value='-',numchild='2',children=["
- "{name='absolutePath',type='" NS "QString',"
- "valueencoded='7',value='-',numchild='0'},"
- "{name='canonicalPath',type='" NS "QString',"
- "valueencoded='7',value='-',numchild='0'}]}",
- "local.dir");
- }
- ///////////////////////////// QFile /////////////////////////////////
- void dump_QFile()
- {
- /* A */ QFile file1(""); // Case 1: Empty file name => Does not exist.
- /* B */ QTemporaryFile file2; // Case 2: File that is known to exist.
- file2.open();
- /* C */ QFile file3("jfjfdskjdflsdfjfdls");
- /* D */ (void) (file1.fileName() + file2.fileName() + file3.fileName()); }
- void tst_Gdb::dump_QFile()
- {
- prepare("dump_QFile");
- next(4);
- check("D", "{iname='local.file1',name='file1',type='" NS "QFile',"
- "valueencoded='7',value='',numchild='2',children=["
- "{name='fileName',type='" NS "QString',"
- "valueencoded='7',value='',numchild='0'},"
- "{name='exists',type='bool',value='false',numchild='0'}"
- "]},"
- "{iname='local.file2',name='file2',type='" NS "QTemporaryFile',"
- "valueencoded='7',value='-',numchild='2',children=["
- "{name='fileName',type='" NS "QString',"
- "valueencoded='7',value='-',numchild='0'},"
- "{name='exists',type='bool',value='true',numchild='0'}"
- "]},"
- "{iname='local.file3',name='file3',type='" NS "QFile',"
- "valueencoded='7',value='-',numchild='2',children=["
- "{name='fileName',type='" NS "QString',"
- "valueencoded='7',value='-',numchild='0'},"
- "{name='exists',type='bool',value='false',numchild='0'}"
- "]}",
- "local.file1,local.file2,local.file3");
- }
- ///////////////////////////// QFileInfo /////////////////////////////////
- void dump_QFileInfo()
- {
- /* A */ QFileInfo fi(".");
- /* B */ (void) fi.baseName().size();
- }
- void tst_Gdb::dump_QFileInfo()
- {
- QFileInfo fi(".");
- prepare("dump_QFileInfo");
- next();
- check("B", "{iname='local.fi',name='fi',type='" NS "QFileInfo',"
- "valueencoded='7',value='" + utfToHex(fi.filePath()) + "',numchild='3',"
- "childtype='" NS "QString',childnumchild='0',children=["
- "{name='absolutePath'," + specQString(fi.absolutePath()) + "},"
- "{name='absoluteFilePath'," + specQString(fi.absoluteFilePath()) + "},"
- "{name='canonicalPath'," + specQString(fi.canonicalPath()) + "},"
- "{name='canonicalFilePath'," + specQString(fi.canonicalFilePath()) + "},"
- "{name='completeBaseName'," + specQString(fi.completeBaseName()) + "},"
- "{name='completeSuffix'," + specQString(fi.completeSuffix()) + "},"
- "{name='baseName'," + specQString(fi.baseName()) + "},"
- #if 0
- "{name='isBundle'," + specBool(fi.isBundle()) + "},"
- "{name='bundleName'," + specQString(fi.bundleName()) + "},"
- #endif
- "{name='fileName'," + specQString(fi.fileName()) + "},"
- "{name='filePath'," + specQString(fi.filePath()) + "},"
- //"{name='group'," + specQString(fi.group()) + "},"
- //"{name='owner'," + specQString(fi.owner()) + "},"
- "{name='path'," + specQString(fi.path()) + "},"
- "{name='groupid',type='unsigned int',value='" + N(fi.groupId()) + "'},"
- "{name='ownerid',type='unsigned int',value='" + N(fi.ownerId()) + "'},"
- "{name='permissions',value=' ',type='" NS "QFile::Permissions',numchild='10'},"
- "{name='caching',type='bool',value='true'},"
- "{name='exists',type='bool',value='true'},"
- "{name='isAbsolute',type='bool',value='false'},"
- "{name='isDir',type='bool',value='true'},"
- "{name='isExecutable',type='bool',value='true'},"
- "{name='isFile',type='bool',value='false'},"
- "{name='isHidden',type='bool',value='false'},"
- "{name='isReadable',type='bool',value='true'},"
- "{name='isRelative',type='bool',value='true'},"
- "{name='isRoot',type='bool',value='false'},"
- "{name='isSymLink',type='bool',value='false'},"
- "{name='isWritable',type='bool',value='true'},"
- "{name='created',type='" NS "QDateTime',"
- + specQString(fi.created().toString()) + ",numchild='3'},"
- "{name='lastModified',type='" NS "QDateTime',"
- + specQString(fi.lastModified().toString()) + ",numchild='3'},"
- "{name='lastRead',type='" NS "QDateTime',"
- + specQString(fi.lastRead().toString()) + ",numchild='3'}]}",
- "local.fi");
- }
- #if 0
- void tst_Gdb::dump_QImageDataHelper(QImage &img)
- {
- const QByteArray ba(QByteArray::fromRawData((const char*) img.bits(), img.numBytes()));
- QByteArray expected = QByteArray("tiname='$I',addr='$A',type='" NS "QImageData',").
- append("numchild='0',value='<hover here>',valuetooltipencoded='1',").
- append("valuetooltipsize='").append(N(ba.size())).append("',").
- append("valuetooltip='").append(ba.toBase64()).append("'");
- testDumper(expected, &img, NS"QImageData", false);
- }
- #endif // 0
- ///////////////////////////// QImage /////////////////////////////////
- void dump_QImage()
- {
- # ifdef QT_GUI_LIB
- /* A */ QImage image; // Null image.
- /* B */ image = QImage(30, 700, QImage::Format_RGB555); // Normal image.
- /* C */ image = QImage(100, 0, QImage::Format_Invalid); // Invalid image.
- /* D */ (void) image.size();
- /* E */ (void) image.size();
- # endif
- }
- void tst_Gdb::dump_QImage()
- {
- # ifdef QT_GUI_LIB
- prepare("dump_QImage");
- next();
- check("B", "{iname='local.image',name='image',type='" NS "QImage',"
- "value='(null)',numchild='0'}");
- next();
- check("C", "{iname='local.image',name='image',type='" NS "QImage',"
- "value='(30x700)',numchild='0'}");
- next(2);
- // FIXME:
- //check("E", "{iname='local.image',name='image',type='" NS "QImage',"
- // "value='(100x0)',numchild='0'}");
- # endif
- }
- #if 0
- void tst_Gdb::dump_QImageData()
- {
- // Case 1: Null image.
- QImage img;
- dump_QImageDataHelper(img);
- // Case 2: Normal image.
- img = QImage(3, 700, QImage::Format_RGB555);
- dump_QImageDataHelper(img);
- // Case 3: Invalid image.
- img = QImage(100, 0, QImage::Format_Invalid);
- dump_QImageDataHelper(img);
- }
- #endif
- void dump_QLocale()
- {
- /* A */ QLocale german(QLocale::German);
- QLocale chinese(QLocale::Chinese);
- QLocale swahili(QLocale::Swahili);
- /* C */ (void) (german.name() + chinese.name() + swahili.name());
- }
- QByteArray dump_QLocaleHelper(const QLocale &loc)
- {
- return "type='" NS "QLocale',valueencoded='7',value='" + utfToHex(loc.name()) +
- "',numchild='8',childtype='" NS "QChar',childnumchild='0',children=["
- "{name='country',type='" NS "QLocale::Country',value='-'},"
- "{name='language',type='" NS "QLocale::Language',value='-'},"
- "{name='measurementSystem',type='" NS "QLocale::MeasurementSystem',"
- "value='-'},"
- "{name='numberOptions',type='" NS "QFlags<myns::QLocale::NumberOption>',"
- "value='-'},"
- "{name='timeFormat_(short)',type='" NS "QString',"
- + specQString(loc.timeFormat(QLocale::ShortFormat)) + "},"
- "{name='timeFormat_(long)',type='" NS "QString',"
- + specQString(loc.timeFormat()) + "},"
- "{name='decimalPoint'," + specQChar(loc.decimalPoint()) + "},"
- "{name='exponential'," + specQChar(loc.exponential()) + "},"
- "{name='percent'," + specQChar(loc.percent()) + "},"
- "{name='zeroDigit'," + specQChar(loc.zeroDigit()) + "},"
- "{name='groupSeparator'," + specQChar(loc.groupSeparator()) + "},"
- "{name='negativeSign'," + specQChar(loc.negativeSign()) + "}]";
- }
- void tst_Gdb::dump_QLocale()
- {
- QLocale german(QLocale::German);
- QLocale chinese(QLocale::Chinese);
- QLocale swahili(QLocale::Swahili);
- prepare("dump_QLocale");
- if (checkUninitialized)
- check("A","{iname='local.english',name='english',"
- "type='" NS "QLocale',value='<invalid>',"
- "numchild='0'}");
- next(3);
- check("C", "{iname='local.german',name='german',"
- + dump_QLocaleHelper(german) + "},"
- "{iname='local.chinese',name='chinese',"
- + dump_QLocaleHelper(chinese) + "},"
- "{iname='local.swahili',name='swahili',"
- + dump_QLocaleHelper(swahili) + "}",
- "local.german,local.chinese,local.swahili");
- }
- ///////////////////////////// QHash<int, int> //////////////////////////////
- void dump_QHash_int_int()
- {
- /* A */ QHash<int, int> h;
- /* B */ h[43] = 44;
- /* C */ h[45] = 46;
- /* D */ (void) 0;
- }
- void tst_Gdb::dump_QHash_int_int()
- {
- // Need to check the following combinations:
- // int-key optimization, small value
- //struct NodeOS { void *next; uint k; uint v; } nodeOS
- // int-key optimiatzion, large value
- //struct NodeOL { void *next; uint k; void *v; } nodeOL
- // no optimization, small value
- //struct NodeNS + { void *next; uint h; uint k; uint v; } nodeNS
- // no optimization, large value
- //struct NodeNL { void *next; uint h; uint k; void *v; } nodeNL
- // complex key
- //struct NodeL { void *next; uint h; void *k; void *v; } nodeL
- prepare("dump_QHash_int_int");
- if (checkUninitialized)
- check("A","{iname='local.h',name='h',"
- "type='" NS "QHash<int, int>',value='<invalid>',"
- "numchild='0'}");
- next(3);
- check("D","{iname='local.h',name='h',"
- "type='" NS "QHash<int, int>',value='<2 items>',numchild='2',"
- "childtype='int',childnumchild='0',children=["
- "{name='43',value='44'},"
- "{name='45',value='46'}]}",
- "local.h");
- }
- ///////////////////////////// QHash<QString, QString> //////////////////////////////
- void dump_QHash_QString_QString()
- {
- /* A */ QHash<QString, QString> h;
- /* B */ h["hello"] = "world";
- /* C */ h["foo"] = "bar…
Large files files are truncated, but you can click here to view the full file