forked from qt-creator/qt-creator
Added more dumper auto tests.
Added test for QImage and fixed bug uncovered by that test. Also prepared test for QSharedPointer.
This commit is contained in:
@@ -1561,6 +1561,7 @@ static void qDumpQImage(QDumper &d)
|
|||||||
d.putItem("type", NS "QImageData");
|
d.putItem("type", NS "QImageData");
|
||||||
d.putItem("addr", d.data);
|
d.putItem("addr", d.data);
|
||||||
d.endHash();
|
d.endHash();
|
||||||
|
d.endChildren();
|
||||||
}
|
}
|
||||||
d.disarm();
|
d.disarm();
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,12 @@
|
|||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QProcess>
|
#include <QtCore/QProcess>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
|
#if QT_VERSION >= 0x040500
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
#endif
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QTextCodec>
|
#include <QtCore/QTextCodec>
|
||||||
|
#include <QtGui/QImage>
|
||||||
#include <QtGui/QStandardItemModel>
|
#include <QtGui/QStandardItemModel>
|
||||||
#include <QtGui/QStringListModel>
|
#include <QtGui/QStringListModel>
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
@@ -136,12 +140,17 @@ private slots:
|
|||||||
void dumpQFile();
|
void dumpQFile();
|
||||||
void dumpQFileInfo();
|
void dumpQFileInfo();
|
||||||
void dumpQHash();
|
void dumpQHash();
|
||||||
|
void dumpQImage();
|
||||||
|
void dumpQImageData();
|
||||||
void dumpQList_int();
|
void dumpQList_int();
|
||||||
void dumpQList_char();
|
void dumpQList_char();
|
||||||
void dumpQList_QString();
|
void dumpQList_QString();
|
||||||
void dumpQList_QString3();
|
void dumpQList_QString3();
|
||||||
void dumpQList_Int3();
|
void dumpQList_Int3();
|
||||||
void dumpQObject();
|
void dumpQObject();
|
||||||
|
#if QT_VERSION >= 0x040500
|
||||||
|
void dumpQSharedPointer();
|
||||||
|
#endif
|
||||||
void dumpQString();
|
void dumpQString();
|
||||||
void dumpQTextCodec();
|
void dumpQTextCodec();
|
||||||
void dumpQVariant_invalid();
|
void dumpQVariant_invalid();
|
||||||
@@ -165,6 +174,12 @@ private:
|
|||||||
void dumpQDateTimeHelper(QDateTime &d);
|
void dumpQDateTimeHelper(QDateTime &d);
|
||||||
void dumpQDirHelper(QDir &d);
|
void dumpQDirHelper(QDir &d);
|
||||||
void dumpQFileHelper(const QString &name, bool exists);
|
void dumpQFileHelper(const QString &name, bool exists);
|
||||||
|
void dumpQImageHelper(QImage &img);
|
||||||
|
void dumpQImageDataHelper(QImage &img);
|
||||||
|
#if QT_VERSION >= 0x040500
|
||||||
|
template <typename T>
|
||||||
|
void dumpQSharedPointerHelper(QSharedPointer<T> &ptr, bool isSimple);
|
||||||
|
#endif
|
||||||
void dumpQTextCodecHelper(QTextCodec *codec);
|
void dumpQTextCodecHelper(QTextCodec *codec);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -757,6 +772,56 @@ void tst_Debugger::dumpQHash()
|
|||||||
hash.insert("!", QList<int>() << 1 << 2);
|
hash.insert("!", QList<int>() << 1 << 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_Debugger::dumpQImageHelper(QImage &img)
|
||||||
|
{
|
||||||
|
QByteArray expected = QByteArray("value='(").
|
||||||
|
append(QString::number(img.width())).append("x").
|
||||||
|
append(QString::number(img.height())).append(")',type='"NS"QImage',").
|
||||||
|
append("numchild='1',children=[{name='data',type='"NS"QImageData',").
|
||||||
|
append("addr='").append(ptrToBa(&img)).append("'}]");
|
||||||
|
testDumper(expected, &img, NS"QImage", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_Debugger::dumpQImage()
|
||||||
|
{
|
||||||
|
// Case 1: Null image.
|
||||||
|
QImage img;
|
||||||
|
dumpQImageHelper(img);
|
||||||
|
|
||||||
|
// Case 2: Normal image.
|
||||||
|
img = QImage(3, 700, QImage::Format_RGB555);
|
||||||
|
dumpQImageHelper(img);
|
||||||
|
|
||||||
|
// Case 3: Invalid image.
|
||||||
|
img = QImage(100, 0, QImage::Format_Invalid);
|
||||||
|
dumpQImageHelper(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_Debugger::dumpQImageDataHelper(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(QString::number(ba.size())).append("',").
|
||||||
|
append("valuetooltip='").append(ba.toBase64()).append("'");
|
||||||
|
testDumper(expected, &img, NS"QImageData", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_Debugger::dumpQImageData()
|
||||||
|
{
|
||||||
|
// Case 1: Null image.
|
||||||
|
QImage img;
|
||||||
|
dumpQImageDataHelper(img);
|
||||||
|
|
||||||
|
// Case 2: Normal image.
|
||||||
|
img = QImage(3, 700, QImage::Format_RGB555);
|
||||||
|
dumpQImageDataHelper(img);
|
||||||
|
|
||||||
|
// Case 3: Invalid image.
|
||||||
|
img = QImage(100, 0, QImage::Format_Invalid);
|
||||||
|
dumpQImageDataHelper(img);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_Debugger::dumpQList_int()
|
void tst_Debugger::dumpQList_int()
|
||||||
{
|
{
|
||||||
QList<int> ilist;
|
QList<int> ilist;
|
||||||
@@ -891,6 +956,48 @@ void tst_Debugger::dumpQObject()
|
|||||||
&child, NS"QObject", false);
|
&child, NS"QObject", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= 0x040500
|
||||||
|
template<typename T>
|
||||||
|
void tst_Debugger::dumpQSharedPointerHelper(QSharedPointer<T> &ptr, bool isSimple)
|
||||||
|
{
|
||||||
|
// TODO: This works only for integer types at the moment.
|
||||||
|
QByteArray expected("value = '");
|
||||||
|
QString val;
|
||||||
|
if (isSimple) {
|
||||||
|
val = QString::number(*ptr.data());
|
||||||
|
expected.append(val);
|
||||||
|
}
|
||||||
|
QAtomicInt *weakAddr;
|
||||||
|
QAtomicInt *strongAddr;
|
||||||
|
int weakValue;
|
||||||
|
int strongValue;
|
||||||
|
if (!ptr.isNull()) {
|
||||||
|
weakAddr = &ptr.d->weakref;
|
||||||
|
strongAddr = &ptr.d->strongref;
|
||||||
|
weakValue = *weakAddr;
|
||||||
|
strongValue = *strongAddr;
|
||||||
|
} else {
|
||||||
|
weakAddr = strongAddr = 0;
|
||||||
|
weakValue = strongValue = 0;
|
||||||
|
}
|
||||||
|
expected.append("',valuedisabled='true',numchild='1',children=[").
|
||||||
|
append("{name='data',addr='").append(ptrToBa(ptr.data())).
|
||||||
|
append("',type='int',value='").append(val).append("'},").
|
||||||
|
append("{name='weakref',value='").append(QString::number(weakValue)).
|
||||||
|
append("',type='int',addr='").append(ptrToBa(weakAddr)).append("',numchild='0'},").
|
||||||
|
append("{name='data',value='").append(val).append("'},").
|
||||||
|
append("{name='strongref',value='").append(QString::number(strongValue)).
|
||||||
|
append("',type='int',addr='").append(ptrToBa(strongAddr)).append("',numchild='0'}]");
|
||||||
|
testDumper(expected, &ptr, NS"QSharedPointer", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_Debugger::dumpQSharedPointer()
|
||||||
|
{
|
||||||
|
QSharedPointer<int> ptr(new int(99));
|
||||||
|
// dumpQSharedPointerHelper(ptr, 1, 0, true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void tst_Debugger::dumpQString()
|
void tst_Debugger::dumpQString()
|
||||||
{
|
{
|
||||||
QString s;
|
QString s;
|
||||||
|
Reference in New Issue
Block a user