diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-02-19 00:15:00 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-29 12:50:14 +0100 |
commit | f95181c7bb340744a0ce172e8c5a8fcdc2543297 (patch) | |
tree | 98f564183796f3b271c3ebe5de437bef18675aed /tests/auto/corelib/kernel/qmetamethod | |
parent | 96f2365cf4cebc074c3171878dcd25ce19ee7486 (diff) |
Long live Qt5 meta-object method/property descriptors
This commit introduces two significant changes to the meta-object
data format:
1) Meta-type information (QMetaType type/name) information is
stored directly in the meta-data for both properties and methods;
2) The original signature (string) of a method is no longer stored
in the meta-data, since it can be reconstructed from the method
name and parameter type info.
The motivation for this change is to enable direct access to method
names and type information (avoiding string-based lookup for types
if possible), since that's typically the information language
bindings (e.g. QML) need. (moc already had all the desired
information about methods, but it threw it away!)
This change keeps support for the older (6 and below) meta-object
revisions, but the support will be removed after a short grace
period.
The following public QMetaMethod functions have been added:
name() : QByteArray
returnType() : int
parameterCount() : int
parameterType(int index) : int
The following internal QMetaMethod function has been added:
getParameterTypes(int *types) : void
This commit extends the meta-method data to include explicit
type/name data for methods. The new data follows the existing
(5-word) method descriptors in the meta-data. The method descriptor
format was modified to enable this. First, the descriptor now
contains the meta-data index where the method's type/name information
can be found. Second, the descriptor contains the number of
parameters. Third, the descriptor has a reference to the name of the
method, not the full signature.
Each entry of a method's type/name array contains either the type id
(if it could be determined at meta-object definition time), or a
reference to the name of the type (so that the type id can be
resolved at runtime).
Lastly, instead of storing the method parameter names as a
comma-separated list that needs to be parsed at runtime (which was
how it was done prior to this commit), the names are now stored as
separate entries in the meta-object string table, and their indexes
are stored immediately after the method type info array. Hence,
parameter names can be queried through the public API without
parsing/allocating/copying, too.
Task-number: QTBUG-24154
Change-Id: Idb7ab81f12d4bfd658b74e18a0fce594f580cba3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qmetamethod')
-rw-r--r-- | tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp index f653e66bfd..60c8fdb2f2 100644 --- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -603,15 +603,51 @@ void tst_QMetaMethod::method() QCOMPARE(method.methodType(), methodType); QCOMPARE(method.access(), access); - QCOMPARE(method.methodSignature(), signature); + QVERIFY(!method.methodSignature().isEmpty()); + if (method.methodSignature() != signature) { + // QMetaMethod should always produce a semantically equivalent signature + int signatureIndex = (methodType == QMetaMethod::Constructor) + ? mo->indexOfConstructor(method.methodSignature()) + : mo->indexOfMethod(method.methodSignature()); + QCOMPARE(signatureIndex, index); + } + + QByteArray computedName = signature.left(signature.indexOf('(')); + QCOMPARE(method.name(), computedName); QCOMPARE(method.tag(), ""); - QCOMPARE(method.typeName(), returnTypeName.constData()); - QCOMPARE(QMetaType::type(method.typeName()), returnType); + QCOMPARE(method.returnType(), returnType); + if (QByteArray(method.typeName()) != returnTypeName) { + // QMetaMethod should always produce a semantically equivalent typename + QCOMPARE(QMetaType::type(method.typeName()), QMetaType::type(returnTypeName)); + } - QCOMPARE(method.parameterTypes(), parameterTypeNames); + if (method.parameterTypes() != parameterTypeNames) { + // QMetaMethod should always produce semantically equivalent typenames + QList<QByteArray> actualTypeNames = method.parameterTypes(); + QCOMPARE(actualTypeNames.size(), parameterTypeNames.size()); + for (int i = 0; i < parameterTypeNames.size(); ++i) { + QCOMPARE(QMetaType::type(actualTypeNames.at(i)), + QMetaType::type(parameterTypeNames.at(i))); + } + } QCOMPARE(method.parameterNames(), parameterNames); + + QCOMPARE(method.parameterCount(), parameterTypes.size()); + for (int i = 0; i < parameterTypes.size(); ++i) + QCOMPARE(method.parameterType(i), parameterTypes.at(i)); + + { + QVector<int> actualParameterTypes(parameterTypes.size()); + method.getParameterTypes(actualParameterTypes.data()); + for (int i = 0; i < parameterTypes.size(); ++i) + QCOMPARE(actualParameterTypes.at(i), parameterTypes.at(i)); + } + + // Bogus indexes + QCOMPARE(method.parameterType(-1), 0); + QCOMPARE(method.parameterType(parameterTypes.size()), 0); } void tst_QMetaMethod::invalidMethod() |