Commit feecfcbc authored by hjk's avatar hjk

Debugger: Avoid #define private public in auto tests

Change-Id: Ie8d9c7745a45fef1de2c446a78faf9096b1c7bb0
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 6c7d80e7
......@@ -37,38 +37,78 @@
#endif
#endif
// Don't do this at home. This is test code, not production.
#define protected public
#define private public
#include <private/qdatetime_p.h>
#include <private/qfile_p.h>
#include <private/qfileinfo_p.h>
#include <private/qobject_p.h>
#ifdef HAS_BOOST
namespace {
// Based on http://bloglitb.blogspot.com/2011/12/access-to-private-members-safer.html
template<typename Tag, typename Tag::type M>
struct Rob {
friend typename Tag::type get(Tag) {
return M;
}
template<typename Class, typename Type, Type Value, typename Tag>
class Access
{
friend int offset(Tag) {
Class *c = 0;
return (char*)&(c->*Value) - (char*)c; // UB. Don't try at home.
}
};
typedef boost::unordered_set<int> uset;
typedef boost::unordered::detail::set<uset::allocator_type, uset::key_type,
uset::hasher, uset::key_equal> uset_types;
#define OFFSET_ACCESS0(Name, Tag, Type, Class, Member) \
struct Tag {}; \
int offset(Tag); \
template class Access<Class, Type Class::*, &Class::Member, Tag>; \
const int Name = offset(Tag())
struct Table {
typedef uset_types::table uset::*type;
friend type get(Table);
};
#define OFFSET_ACCESS(Type, Class, Member) \
OFFSET_ACCESS0(Class ## _## Member, tag_ ## Class ## _ ## Member, Type, Class, Member)
#define STRINGIFY_INTERNAL(x) #x
#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
#define OFFSET_TEST(Class, Member) \
QTest::newRow(STRINGIFY(Class) STRINGIFY(Member)) << Class ## _ ## Member
OFFSET_ACCESS(QString, QFilePrivate, fileName);
OFFSET_ACCESS(QString, QFileSystemEntry, m_filePath);
OFFSET_ACCESS(QFileSystemEntry, QFileInfoPrivate, fileEntry);
OFFSET_ACCESS(QObjectPrivate::ExtraData*, QObjectPrivate, extraData);
#if QT_VERSION < 0x50000
OFFSET_ACCESS(QString, QObjectPrivate, objectName);
#endif
#if QT_VERSION < 0x50200
OFFSET_ACCESS(QDate, QDateTimePrivate, date);
OFFSET_ACCESS(QTime, QDateTimePrivate, time);
OFFSET_ACCESS(Qt::TimeSpec,, QDateTimePrivate, spec);
OFFSET_ACCESS(int, QDateTimePrivate, utcOffset);
#else
OFFSET_ACCESS(qint64, QDateTimePrivate, m_msecs);
OFFSET_ACCESS(Qt::TimeSpec, QDateTimePrivate, m_spec);
OFFSET_ACCESS(int, QDateTimePrivate, m_offsetFromUtc);
OFFSET_ACCESS(QTimeZone, QDateTimePrivate, m_timeZone);
OFFSET_ACCESS(QDateTimePrivate::StatusFlags, QDateTimePrivate, m_status);
#endif
template struct Rob<Table, &uset::table_>;
} // anon namespace
#ifdef HAS_BOOST
typedef boost::unordered::unordered_set<int>::key_type T_;
typedef boost::unordered::unordered_set<int>::hasher H_;
typedef boost::unordered::unordered_set<int>::key_equal P_;
typedef boost::unordered::unordered_set<int>::allocator_type A_;
typedef boost::unordered::detail::set<A_, T_, H_, P_> Uset_types;
typedef boost::unordered::detail::table_impl<Uset_types>::table UsetTable;
typedef boost::unordered_set<int> Uset;
OFFSET_ACCESS(Uset::table, Uset, table_);
OFFSET_ACCESS(std::size_t, UsetTable, size_);
OFFSET_ACCESS(std::size_t, UsetTable, bucket_count_);
OFFSET_ACCESS(UsetTable::bucket_pointer, UsetTable, buckets_);
#endif
class tst_offsets : public QObject
{
Q_OBJECT
......@@ -104,162 +144,108 @@ void tst_offsets::offsets_data()
const int qtVersion = QT_VERSION;
{
QFilePrivate *p = 0;
QTestData &data = QTest::newRow("QFilePrivate::fileName")
<< int((char *)&p->fileName - (char *)p);
if (qtVersion >= 0x50600)
if (qtVersion >= 0x50600)
#ifdef Q_OS_WIN
# ifdef Q_CC_MSVC
data << 176 << 248;
OFFSET_TEST(QFilePrivate, fileName) << 176 << 248;
# else // MinGW
data << 164 << 248;
OFFSET_TEST(QFilePrivate, fileName) << 164 << 248;
# endif
#else
data << 168 << 248;
OFFSET_TEST(QFilePrivate, fileName) << 168 << 248;
#endif
else if (qtVersion >= 0x50500)
else if (qtVersion >= 0x50500)
#ifdef Q_OS_WIN
# ifdef Q_CC_MSVC
data << 176 << 248;
OFFSET_TEST(QFilePrivate, fileName) << 176 << 248;
# else // MinGW
data << 164 << 248;
OFFSET_TEST(QFilePrivate, fileName) << 164 << 248;
# endif
#else
data << 164 << 248;
OFFSET_TEST(QFilePrivate, fileName) << 164 << 248;
#endif
else if (qtVersion >= 0x50400)
else if (qtVersion >= 0x50400)
#ifdef Q_OS_WIN
# ifdef Q_CC_MSVC
data << 196 << 272;
OFFSET_TEST(QFilePrivate, fileName) << 196 << 272;
# else // MinGW
data << 188 << 272;
OFFSET_TEST(QFilePrivate, fileName) << 188 << 272;
# endif
#else
data << 180 << 272;
OFFSET_TEST(QFilePrivate, fileName) << 180 << 272;
#endif
else if (qtVersion > 0x50200)
else if (qtVersion > 0x50200)
#ifdef Q_OS_WIN
# ifdef Q_CC_MSVC
data << 184 << 272;
OFFSET_TEST(QFilePrivate, fileName) << 184 << 272;
# else // MinGW
data << 180 << 272;
OFFSET_TEST(QFilePrivate, fileName) << 180 << 272;
# endif
#else
data << 176 << 272;
OFFSET_TEST(QFilePrivate, fileName) << 176 << 272;
#endif
else if (qtVersion >= 0x50000)
data << 176 << 280;
else
else if (qtVersion >= 0x50000)
OFFSET_TEST(QFilePrivate, fileName) << 176 << 280;
else
#ifdef Q_OS_WIN
data << 144 << 232;
OFFSET_TEST(QFilePrivate, fileName) << 144 << 232;
#else
data << 140 << 232;
OFFSET_TEST(QFilePrivate, fileName) << 140 << 232;
#endif
}
{
QFileInfoPrivate *p = 0;
QTestData &data = QTest::newRow("QFileInfoPrivate::filePath")
<< int((char *)&p->fileEntry.m_filePath - (char *)p);
data << 4 << 8;
}
OFFSET_TEST(QFileSystemEntry, m_filePath) << 0 << 0;
OFFSET_TEST(QFileInfoPrivate, fileEntry) << 4 << 8;
{
QTestData &data = QTest::newRow("sizeof(QObjectData)")
<< int(sizeof(QObjectData));
data << 28 << 48; // vptr + 3 ptr + 2 int + ptr
}
QTest::newRow("sizeof(QObjectData)") << int(sizeof(QObjectData))
<< 28 << 48; // vptr + 3 ptr + 2 int + ptr
{
QObjectPrivate *p = 0;
QTestData &data = QTest::newRow("QObjectPrivate::extraData")
<< int((char *)&p->extraData - (char *)p);
if (qtVersion >= 0x50000)
data << 28 << 48; // sizeof(QObjectData)
else
data << 32 << 56; // sizeof(QObjectData) + 1 ptr
}
if (qtVersion >= 0x50000)
OFFSET_TEST(QObjectPrivate, extraData) << 28 << 48; // sizeof(QObjectData)
else
OFFSET_TEST(QObjectPrivate, extraData) << 32 << 56; // sizeof(QObjectData) + 1 ptr
#if QT_VERSION < 0x50000
{
QObjectPrivate *p = 0;
QTestData &data = QTest::newRow("QObjectPrivate::objectName")
<< int((char *)&p->objectName - (char *)p);
data << 28 << 48; // sizeof(QObjectData)
}
OFFSET_TEST(QObjectPrivate, objectName) << 28 << 48; // sizeof(QObjectData)
#endif
{
QDateTimePrivate *p = 0;
#if QT_VERSION < 0x50000
QTest::newRow("QDateTimePrivate::date")
<< int((char *)&p->date - (char *)p) << 4 << 4;
QTest::newRow("QDateTimePrivate::time")
<< int((char *)&p->time - (char *)p) << 8 << 8;
QTest::newRow("QDateTimePrivate::spec")
<< int((char *)&p->spec - (char *)p) << 12 << 12;
QTest::newRow("QDateTimePrivate::utcOffset")
<< int((char *)&p->utcOffset - (char *)p) << 16 << 16;
OFFSET_TEST(QDateTimePrivate, date) << 4 << 4;
OFFSET_TEST(QDateTimePrivate, time) << 8 << 8;
OFFSET_TEST(QDateTimePrivate, spec) << 12 << 12;
OFFSET_TEST(QDateTimePrivate, utcOffset) << 16 << 16;
#elif QT_VERSION < 0x50200
# ifdef Q_OS_WIN
QTest::newRow("QDateTimePrivate::date")
<< int((char *)&p->date - (char *)p) << 8 << 8;
QTest::newRow("QDateTimePrivate::time")
<< int((char *)&p->time - (char *)p) << 16 << 16;
QTest::newRow("QDateTimePrivate::spec")
<< int((char *)&p->spec - (char *)p) << 20 << 20;
QTest::newRow("QDateTimePrivate::utcOffset")
<< int((char *)&p->utcOffset - (char *)p) << 24 << 24;
OFFSET_TEST(QDateTimePrivate, date) << 8 << 8;
OFFSET_TEST(QDateTimePrivate, time) << 16 << 16;
OFFSET_TEST(QDateTimePrivate, spec) << 20 << 20;
OFFSET_TEST(QDateTimePrivate, utcOffset) << 24 << 24;
# else
QTest::newRow("QDateTimePrivate::date")
<< int((char *)&p->date - (char *)p) << 4 << 8;
QTest::newRow("QDateTimePrivate::time")
<< int((char *)&p->time - (char *)p) << 12 << 16;
QTest::newRow("QDateTimePrivate::spec")
<< int((char *)&p->spec - (char *)p) << 16 << 20;
QTest::newRow("QDateTimePrivate::utcOffset")
<< int((char *)&p->utcOffset - (char *)p) << 20 << 24;
OFFSET_TEST(QDateTimePrivate, date) << 4 << 8;
OFFSET_TEST(QDateTimePrivate, time) << 12 << 16;
OFFSET_TEST(QDateTimePrivate, spec) << 16 << 20;
OFFSET_TEST(QDateTimePrivate, utcOffset) << 20 << 24;
# endif
#else
# ifdef Q_OS_WIN
QTest::newRow("QDateTimePrivate::m_msecs")
<< int((char *)&p->m_msecs - (char *)p) << 8 << 8;
QTest::newRow("QDateTimePrivate::m_spec")
<< int((char *)&p->m_spec - (char *)p) << 16 << 16;
QTest::newRow("QDateTimePrivate::m_offsetFromUtc")
<< int((char *)&p->m_offsetFromUtc - (char *)p) << 20 << 20;
QTest::newRow("QDateTimePrivate::m_timeZone")
<< int((char *)&p->m_timeZone - (char *)p) << 24 << 24;
QTest::newRow("QDateTimePrivate::m_status")
<< int((char *)&p->m_status - (char *)p) << 28 << 32;
OFFSET_TEST(QDateTimePrivate, m_msecs) << 8 << 8;
OFFSET_TEST(QDateTimePrivate, m_spec) << 16 << 16;
OFFSET_TEST(QDateTimePrivate, m_offsetFromUtc) << 20 << 20;
OFFSET_TEST(QDateTimePrivate, m_timeZone) << 24 << 24;
OFFSET_TEST(QDateTimePrivate, m_status) << 28 << 32;
# else
QTest::newRow("QDateTimePrivate::m_msecs")
<< int((char *)&p->m_msecs - (char *)p) << 4 << 8;
QTest::newRow("QDateTimePrivate::m_spec")
<< int((char *)&p->m_spec - (char *)p) << 12 << 16;
QTest::newRow("QDateTimePrivate::m_offsetFromUtc")
<< int((char *)&p->m_offsetFromUtc - (char *)p) << 16 << 20;
QTest::newRow("QDateTimePrivate::m_timeZone")
<< int((char *)&p->m_timeZone - (char *)p) << 20 << 24;
QTest::newRow("QDateTimePrivate::m_status")
<< int((char *)&p->m_status - (char *)p) << 24 << 32;
OFFSET_TEST(QDateTimePrivate, m_msecs) << 4 << 8;
OFFSET_TEST(QDateTimePrivate, m_spec) << 12 << 16;
OFFSET_TEST(QDateTimePrivate, m_offsetFromUtc) << 16 << 20;
OFFSET_TEST(QDateTimePrivate, m_timeZone) << 20 << 24;
OFFSET_TEST(QDateTimePrivate, m_status) << 24 << 32;
# endif
#endif
}
#ifdef HAS_BOOST
{
boost::unordered::unordered_set<int> *p = 0;
auto &table = p->*get(Table());
QTest::newRow("boost::unordered::unordered_set::size")
<< int((char *)&table.size_ - (char *)p) << 8 << 16;
QTest::newRow("boost::unordered::unordered_set::bucket_count")
<< int((char *)&table.bucket_count_ - (char *)p) << 4 << 8;
QTest::newRow("boost::unordered::unordered_set::buckets_")
<< int((char *)&table.buckets_ - (char *)p) << 20 << 40;
}
OFFSET_TEST(Uset, table_) << 0 << 0;
OFFSET_TEST(UsetTable, size_) << 8 << 16;
OFFSET_TEST(UsetTable, bucket_count_) << 4 << 8;
OFFSET_TEST(UsetTable, buckets_) << 20 << 40;
#endif
}
......
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