diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-02-20 21:27:11 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-22 16:19:16 +0100 |
commit | e1c0047c6b50dd28f61fb94bed50810a8ce7b48d (patch) | |
tree | 27390a5a9276ab7c1767c1d964eb2c51d79e1590 | |
parent | 093031257da7d72572bcee3ead931d83fcdd69d2 (diff) | |
download | qtscript-e1c0047c6b50dd28f61fb94bed50810a8ce7b48d.tar.gz |
Port QtScript autotests to QMetaObjectBuilder
The tests were using a custom meta-object builder that generated
meta-objects of an old revision. Kill the custom builder and use
QMOB instead.
Change-Id: I4eeb6f08474f780dead13fc1a9e3605b93973672
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
4 files changed, 49 insertions, 113 deletions
diff --git a/tests/auto/qscriptjstestsuite/qscriptjstestsuite.pro b/tests/auto/qscriptjstestsuite/qscriptjstestsuite.pro index 86a928b..90bf4b2 100644 --- a/tests/auto/qscriptjstestsuite/qscriptjstestsuite.pro +++ b/tests/auto/qscriptjstestsuite/qscriptjstestsuite.pro @@ -1,6 +1,6 @@ TARGET = tst_qscriptjstestsuite CONFIG += testcase -QT = core script testlib +QT = core-private script testlib SOURCES += tst_qscriptjstestsuite.cpp RESOURCES += qscriptjstestsuite.qrc include(../qscriptv8testsuite/abstracttestsuite.pri) diff --git a/tests/auto/qscriptv8testsuite/abstracttestsuite.cpp b/tests/auto/qscriptv8testsuite/abstracttestsuite.cpp index 7d16554..d6eec1d 100644 --- a/tests/auto/qscriptv8testsuite/abstracttestsuite.cpp +++ b/tests/auto/qscriptv8testsuite/abstracttestsuite.cpp @@ -43,6 +43,7 @@ #include <QtTest/QtTest> #include <QtCore/qset.h> #include <QtCore/qtextstream.h> +#include <private/qmetaobjectbuilder_p.h> /*! AbstractTestSuite provides a way of building QtTest test objects @@ -104,97 +105,6 @@ skip entry if appropriate. */ -// Helper class for constructing the test class's QMetaObject contents -// at runtime. -class TestMetaObjectBuilder -{ -public: - TestMetaObjectBuilder(const QByteArray &className, - const QMetaObject *superClass); - - void appendPrivateVoidSlot(const char *signature); - void appendPrivateVoidSlot(const QString &signature) - { appendPrivateVoidSlot(signature.toLatin1().constData()); } - - void assignContents(QMetaObject &); - -private: - void appendString(const char *); - void finalize(); - - const QByteArray m_className; - const QMetaObject *m_superClass; - QVector<uint> m_data; - QVector<char> m_stringdata; - int m_emptyStringOffset; - bool m_finalized; -}; - -TestMetaObjectBuilder::TestMetaObjectBuilder( - const QByteArray &className, - const QMetaObject *superClass) - : m_className(className), m_superClass(superClass), - m_finalized(false) -{ - // header - m_data << 1 // revision - << 0 // classname - << 0 << 0 // classinfo - << 0 << 10 // methods (backpatched later) - << 0 << 0 // properties - << 0 << 0 // enums/sets - ; - - appendString(className.constData()); - m_emptyStringOffset = m_stringdata.size(); - appendString(""); -} - -void TestMetaObjectBuilder::appendString(const char *s) -{ - char c; - do { - c = *(s++); - m_stringdata << c; - } while (c != '\0'); -} - -void TestMetaObjectBuilder::appendPrivateVoidSlot(const char *signature) -{ - static const int methodCountOffset = 4; - // signature, parameters, type, tag, flags - m_data << m_stringdata.size() - << m_emptyStringOffset - << m_emptyStringOffset - << m_emptyStringOffset - << 0x08; - appendString(signature); - ++m_data[methodCountOffset]; -} - -void TestMetaObjectBuilder::finalize() -{ - if (m_finalized) - return; - m_data << 0; // eod - m_finalized = true; -} - -/** - Assigns this builder's contents to the meta-object \a mo. It's up - to the caller to ensure that this builder (and hence, its data) - stays alive as long as needed. -*/ -void TestMetaObjectBuilder::assignContents(QMetaObject &mo) -{ - finalize(); - mo.d.superdata = m_superClass; - mo.d.stringdata = m_stringdata.constData(); - mo.d.data = m_data.constData(); - mo.d.extradata = 0; -} - - class TestConfigClientInterface; // For parsing information about skipped tests and expected failures. class TestConfigParser @@ -323,49 +233,70 @@ bool TestConfigParser::isDefined(const QString &symbol) } -QMetaObject AbstractTestSuite::staticMetaObject; - const QMetaObject *AbstractTestSuite::metaObject() const { - return &staticMetaObject; + return dynamicMetaObject; } void *AbstractTestSuite::qt_metacast(const char *_clname) { if (!_clname) return 0; - if (!strcmp(_clname, staticMetaObject.d.stringdata)) + if (!strcmp(_clname, dynamicMetaObject->className())) return static_cast<void*>(const_cast<AbstractTestSuite*>(this)); return QObject::qt_metacast(_clname); } -int AbstractTestSuite::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +void AbstractTestSuite::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) { - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; + Q_UNUSED(_a); if (_c == QMetaObject::InvokeMetaMethod) { + AbstractTestSuite *_t = static_cast<AbstractTestSuite *>(_o); switch (_id) { case 0: - initTestCase(); + _t->initTestCase(); break; case 1: - cleanupTestCase(); + _t->cleanupTestCase(); break; default: // If another method is added above, this offset must be adjusted. - runTestFunction(_id - 2); + _t->runTestFunction(_id - 2); } - _id -= staticMetaObject.methodCount() - staticMetaObject.methodOffset(); + } +} + +int AbstractTestSuite::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QObject::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + Q_ASSERT(dynamicMetaObject->cast(this)); + int ownMethodCount = dynamicMetaObject->methodCount() - dynamicMetaObject->methodOffset(); + if (_id < ownMethodCount) + qt_static_metacall(this, _c, _id, _a); + _id -= ownMethodCount; } return _id; } +void AbstractTestSuite::addPrivateSlot(const QByteArray &signature) +{ + QMetaMethodBuilder slot = metaBuilder->addSlot(signature); + slot.setAccess(QMetaMethod::Private); +} + AbstractTestSuite::AbstractTestSuite(const QByteArray &className, const QString &defaultTestsPath, const QString &defaultConfigPath) : shouldGenerateExpectedFailures(false), - metaBuilder(new TestMetaObjectBuilder(className, &QObject::staticMetaObject)) + dynamicMetaObject(0), + metaBuilder(new QMetaObjectBuilder) { + metaBuilder->setSuperClass(&QObject::staticMetaObject); + metaBuilder->setClassName(className); + metaBuilder->setStaticMetacallFunction(qt_static_metacall); + QString testConfigPath = qgetenv("QTSCRIPT_TEST_CONFIG_DIR"); if (testConfigPath.isEmpty()) testConfigPath = defaultConfigPath; @@ -389,7 +320,7 @@ AbstractTestSuite::AbstractTestSuite(const QByteArray &className, AbstractTestSuite::~AbstractTestSuite() { - delete metaBuilder; + qFree(dynamicMetaObject); } void AbstractTestSuite::addTestFunction(const QString &name, @@ -397,15 +328,15 @@ void AbstractTestSuite::addTestFunction(const QString &name, { if (dfc == CreateDataFunction) { QString dataSignature = QString::fromLatin1("%0_data()").arg(name); - metaBuilder->appendPrivateVoidSlot(dataSignature); + addPrivateSlot(dataSignature.toLatin1()); } QString signature = QString::fromLatin1("%0()").arg(name); - metaBuilder->appendPrivateVoidSlot(signature); + addPrivateSlot(signature.toLatin1()); } void AbstractTestSuite::finalizeMetaObject() { - metaBuilder->assignContents(staticMetaObject); + dynamicMetaObject = metaBuilder->toMetaObject(); } void AbstractTestSuite::initTestCase() diff --git a/tests/auto/qscriptv8testsuite/abstracttestsuite.h b/tests/auto/qscriptv8testsuite/abstracttestsuite.h index f51270b..a083de6 100644 --- a/tests/auto/qscriptv8testsuite/abstracttestsuite.h +++ b/tests/auto/qscriptv8testsuite/abstracttestsuite.h @@ -46,12 +46,13 @@ #include <QtCore/qbytearray.h> #include <QtCore/qdir.h> +#include <QtCore/qscopedpointer.h> #include <QtCore/qstring.h> #include <QtCore/qstringlist.h> #include <QtCore/qvector.h> #include <QtCore/qtextstream.h> -class TestMetaObjectBuilder; +QT_FORWARD_DECLARE_CLASS(QMetaObjectBuilder) namespace TestConfig { enum Mode { @@ -82,7 +83,6 @@ public: const QString &defaultConfigPath); virtual ~AbstractTestSuite(); - static QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **argv); @@ -114,7 +114,12 @@ protected: bool shouldGenerateExpectedFailures; private: - TestMetaObjectBuilder *metaBuilder; + static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); + + void addPrivateSlot(const QByteArray &signature); + + QMetaObject *dynamicMetaObject; + QScopedPointer<QMetaObjectBuilder> metaBuilder; QString skipConfigPath, expectFailConfigPath; private: diff --git a/tests/auto/qscriptv8testsuite/qscriptv8testsuite.pro b/tests/auto/qscriptv8testsuite/qscriptv8testsuite.pro index 2d0b5b1..a1c0852 100644 --- a/tests/auto/qscriptv8testsuite/qscriptv8testsuite.pro +++ b/tests/auto/qscriptv8testsuite/qscriptv8testsuite.pro @@ -1,6 +1,6 @@ TARGET = tst_qscriptv8testsuite CONFIG += testcase -QT = core script testlib +QT = core-private script testlib SOURCES += tst_qscriptv8testsuite.cpp RESOURCES += qscriptv8testsuite.qrc include(abstracttestsuite.pri) |