Commit e2cfc095 authored by hjk's avatar hjk

debugger: mark 'Null' QStrings() in pretty-printers

parent 40518ac1
......@@ -77,6 +77,7 @@
#if USE_QT_GUI
# include <QtGui/QApplication>
# include <QtGui/QImage>
# include <QtGui/QRegion>
# include <QtGui/QPixmap>
# include <QtGui/QWidget>
# include <QtGui/QFont>
......@@ -478,6 +479,7 @@ struct QDumper
void putHash(const char *name, QChar value);
void putHash(const char *name, float value);
void putHash(const char *name, double value);
void putStringValue(const QString &value);
void beginHash(); // start of data hash output
void endHash(); // start of data hash output
......@@ -710,6 +712,16 @@ void QDumper::putBase64Encoded(const char *buf, int n)
}
}
void QDumper::putStringValue(const QString &str)
{
if (str.isNull()) {
putItem("value", "\"\" (null)");
} else {
putItem("value", str);
putItem("valueencoded", "2");
}
}
void QDumper::disarm()
{
success = true;
......@@ -784,10 +796,9 @@ void QDumper::putHash(const char *name, const QString &value)
{
beginHash();
putItem("name", name);
putItem("value", value);
putStringValue(value);
putItem("type", NS"QString");
putItem("numchild", "0");
putItem("valueencoded", "2");
endHash();
}
......@@ -859,9 +870,8 @@ void QDumper::putHash(const char *name, QChar value)
{
beginHash();
putItem("name", name);
putItem("value", QString(QLatin1String("'%1' (%2, 0x%3)"))
putStringValue(QString(QLatin1String("'%1' (%2, 0x%3)"))
.arg(value).arg(value.unicode()).arg(value.unicode(), 0, 16));
putItem("valueencoded", "2");
putItem("type", NS"QChar");
putItem("numchild", "0");
endHash();
......@@ -2850,8 +2860,7 @@ static void qDumpQString(QDumper &d)
return;
}
d.putItem("value", str);
d.putItem("valueencoded", "2");
d.putStringValue(str);
d.putItem("type", NS"QString");
//d.putItem("editvalue", str); // handled generically below
d.putItem("numchild", "0");
......@@ -2880,8 +2889,7 @@ static void qDumpQStringList(QDumper &d)
d.beginChildren(n ? NS"QString" : 0);
for (int i = 0; i != n; ++i) {
d.beginHash();
d.putItem("value", list[i]);
d.putItem("valueencoded", "2");
d.putStringValue(list.at(i));
d.endHash();
}
if (n < list.size())
......
......@@ -175,8 +175,7 @@ private slots:
private:
void dumpQAbstractItemHelper(QModelIndex &index);
void dumpQAbstractItemModelHelper(QAbstractItemModel &m);
void dumpQDateTimeHelper(const QDateTime &d);
void dumpQFileHelper(const QString &name, bool exists);
void dumpQDateTimeHelper(const QDateTime &d, bool isNull);
template <typename K, typename V> void dumpQHashNodeHelper(QHash<K, V> &hash);
void dumpQImageHelper(const QImage &img);
void dumpQImageDataHelper(QImage &img);
......@@ -458,10 +457,13 @@ static const QByteArray ptrToBa(const void *p, bool symbolicNull = true)
QByteArray("0x") + QByteArray::number((quintptr) p, 16));
}
static const QByteArray generateQStringSpec(const QString &str)
static const QByteArray generateQStringSpec(const QString &str, bool isNull = false)
{
return QByteArray("value='%',type='"NS"QString',numchild='0',valueencoded='2'")
<< utfToBase64(str);
if (isNull)
return QByteArray("value=''' (null)',type='"NS"QString',numchild='0'");
return
QByteArray("value='%',valueencoded='2',type='"NS"QString',numchild='0'")
<< utfToBase64(str);
}
static const QByteArray generateQCharSpec(const QChar& ch)
......@@ -925,7 +927,7 @@ void tst_Debugger::dumpQChar()
&c, NS"QChar", false);
}
void tst_Debugger::dumpQDateTimeHelper(const QDateTime &d)
void tst_Debugger::dumpQDateTimeHelper(const QDateTime &d, bool isNull)
{
QByteArray value;
if (d.isNull())
......@@ -944,10 +946,10 @@ void tst_Debugger::dumpQDateTimeHelper(const QDateTime &d)
<< value
<< generateBoolSpec(d.isNull())
<< generateLongSpec((d.toTime_t()))
<< generateQStringSpec(d.toString())
<< generateQStringSpec(d.toString(Qt::ISODate))
<< generateQStringSpec(d.toString(Qt::SystemLocaleDate))
<< generateQStringSpec(d.toString(Qt::LocaleDate));
<< generateQStringSpec(d.toString(), isNull)
<< generateQStringSpec(d.toString(Qt::ISODate), isNull)
<< generateQStringSpec(d.toString(Qt::SystemLocaleDate), isNull)
<< generateQStringSpec(d.toString(Qt::LocaleDate), isNull);
testDumper(expected, &d, NS"QDateTime", true);
}
......@@ -955,11 +957,11 @@ void tst_Debugger::dumpQDateTime()
{
// Case 1: Null object.
QDateTime d;
dumpQDateTimeHelper(d);
dumpQDateTimeHelper(d, true);
// Case 2: Non-null object.
d = QDateTime::currentDateTime();
dumpQDateTimeHelper(d);
dumpQDateTimeHelper(d, false);
}
void tst_Debugger::dumpQDir()
......@@ -983,30 +985,35 @@ void tst_Debugger::dumpQDir()
&dir, NS"QDir", true);
}
void tst_Debugger::dumpQFileHelper(const QString &name, bool exists)
{
QFile file(name);
QByteArray filenameAsBase64 = utfToBase64(name);
testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2',"
"children=[{name='fileName',value='%',type='"NS"QString',"
"numchild='0',valueencoded='2'},"
"{name='exists',value=%,type='bool',numchild='0'}]")
<< filenameAsBase64 << filenameAsBase64 << boolToVal(exists),
&file, NS"QFile", true);
}
void tst_Debugger::dumpQFile()
{
// Case 1: Empty file name => Does not exist.
dumpQFileHelper("", false);
QFile file1("");
testDumper(QByteArray("value='',valueencoded='2',type='$T',numchild='2',"
"children=[{name='fileName',value='',valueencoded='2',type='"NS"QString',"
"numchild='0'},"
"{name='exists',value='false',type='bool',numchild='0'}]"),
&file1, NS"QFile", true);
// Case 2: File that is known to exist.
QTemporaryFile file;
file.open();
dumpQFileHelper(file.fileName(), true);
QTemporaryFile file2;
file2.open();
testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2',"
"children=[{name='fileName',value='%',valueencoded='2',type='"NS"QString',"
"numchild='0'},"
"{name='exists',value='true',type='bool',numchild='0'}]")
<< utfToBase64(file2.fileName()) << utfToBase64(file2.fileName()),
&file2, NS"QFile", true);
// Case 3: File with a name that most likely does not exist.
dumpQFileHelper("jfjfdskjdflsdfjfdls", false);
QFile file3("jfjfdskjdflsdfjfdls");
testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2',"
"children=[{name='fileName',value='%',valueencoded='2',type='"NS"QString',"
"numchild='0'},"
"{name='exists',value='false',type='bool',numchild='0'}]")
<< utfToBase64(file3.fileName()) << utfToBase64(file3.fileName()),
&file3, NS"QFile", true);
}
void tst_Debugger::dumpQFileInfo()
......@@ -1062,7 +1069,7 @@ void tst_Debugger::dumpQFileInfo()
expected <<= generateQStringSpec(fi.canonicalPath());
expected <<= generateQStringSpec(fi.canonicalFilePath());
expected <<= generateQStringSpec(fi.completeBaseName());
expected <<= generateQStringSpec(fi.completeSuffix());
expected <<= generateQStringSpec(fi.completeSuffix(), true);
expected <<= generateQStringSpec(fi.baseName());
#ifdef Q_OS_MACX
expected <<= generateBoolSpec(fi.isBundle());
......@@ -2254,7 +2261,7 @@ void tst_Debugger::dumpQSharedPointer()
void tst_Debugger::dumpQString()
{
QString s;
testDumper("value='',valueencoded='2',type='$T',numchild='0'",
testDumper("value=''' (null)',type='$T',numchild='0'",
&s, NS"QString", false);
s = "abc";
testDumper("value='YQBiAGMA',valueencoded='2',type='$T',numchild='0'",
......
......@@ -1526,7 +1526,7 @@ void dump_QObject()
/* B */ QObject ob;
/* D */ ob.setObjectName("An Object");
/* E */ QObject::connect(&ob, SIGNAL(destroyed()), qApp, SLOT(quit()));
/* F */ QObject::disconnect(&ob, SIGNAL(destroyed()), qApp, SLOT(quit()));
// /* F */ QObject::disconnect(&ob, SIGNAL(destroyed()), qApp, SLOT(quit()));
/* G */ ob.setObjectName("A renamed Object");
/* H */ (void) 0; }
......@@ -1546,7 +1546,7 @@ void tst_Gdb::dump_QObject()
run("A","{iname='local.ob',name='ob',"
"type='"NS"QObject',value='<not in scope>',"
"numchild='0'}");
next(3);
next(4);
run("F","{iname='local.ob',name='ob',type='"NS"QObject',valueencoded='7',"
"value='41006e0020004f0062006a00650063007400',numchild='4',children=["
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment