diff options
Diffstat (limited to 'tests/auto/tools/moc/tst_moc.cpp')
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 126 |
1 files changed, 118 insertions, 8 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index edb6488eaa..d67b3e011a 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -572,6 +572,8 @@ private slots: void relatedMetaObjectsInGadget(); void relatedMetaObjectsNameConflict_data(); void relatedMetaObjectsNameConflict(); + void strignLiteralsInMacroExtension(); + void veryLongStringData(); signals: void sigWithUnsignedArg(unsigned foo); @@ -1299,13 +1301,13 @@ public: PrivatePropertyTest(QObject *parent = 0) : QObject(parent), mFoo(0), d (new MyDPointer) {} int foo() { return mFoo ; } void setFoo(int value) { mFoo = value; } - MyDPointer *d_func() {return d;} + MyDPointer *d_func() {return d.data();} signals: void blub4Changed(); void blub5Changed(const QString &newBlub); private: int mFoo; - MyDPointer *d; + QScopedPointer<MyDPointer> d; }; @@ -1409,19 +1411,19 @@ void tst_Moc::constructors() QCOMPARE(mo->indexOfConstructor("CtorTestClass2(QObject*)"), -1); QCOMPARE(mo->indexOfConstructor("CtorTestClass(float,float)"), -1); - QObject *o1 = mo->newInstance(); + QScopedPointer<QObject> o1(mo->newInstance()); QVERIFY(o1 != 0); QCOMPARE(o1->parent(), (QObject*)0); - QVERIFY(qobject_cast<CtorTestClass*>(o1) != 0); + QVERIFY(qobject_cast<CtorTestClass*>(o1.data()) != 0); - QObject *o2 = mo->newInstance(Q_ARG(QObject*, o1)); + QObject *o2 = mo->newInstance(Q_ARG(QObject*, o1.data())); QVERIFY(o2 != 0); - QCOMPARE(o2->parent(), o1); + QCOMPARE(o2->parent(), o1.data()); QString str = QString::fromLatin1("hello"); - QObject *o3 = mo->newInstance(Q_ARG(QString, str)); + QScopedPointer<QObject> o3(mo->newInstance(Q_ARG(QString, str))); QVERIFY(o3 != 0); - QCOMPARE(qobject_cast<CtorTestClass*>(o3)->m_str, str); + QCOMPARE(qobject_cast<CtorTestClass*>(o3.data())->m_str, str); { //explicit constructor @@ -3269,6 +3271,114 @@ void tst_Moc::relatedMetaObjectsNameConflict() QCOMPARE(dependency.size(), relatedMetaObjects.size()); } +class StringLiteralsInMacroExtension: public QObject +{ + Q_OBJECT +#define Macro(F) F " " F + Q_CLASSINFO(Macro("String"), Macro("Literal")) +#undef Macro + +#define Macro(F) F + Q_CLASSINFO("String" Macro("!"), "Literal" Macro("!")) + Q_CLASSINFO(Macro("!") "String", Macro("!") "Literal") +#undef Macro + +#define Macro "foo" + Q_CLASSINFO("String" Macro, "Literal" Macro) + Q_CLASSINFO(Macro "String", Macro "Literal") +#undef Macro +}; + +void tst_Moc::strignLiteralsInMacroExtension() +{ + const QMetaObject *mobj = &StringLiteralsInMacroExtension::staticMetaObject; + QCOMPARE(mobj->classInfoCount(), 5); + + QCOMPARE(mobj->classInfo(0).name(), "String String"); + QCOMPARE(mobj->classInfo(0).value(), "Literal Literal"); + + QCOMPARE(mobj->classInfo(1).name(), "String!"); + QCOMPARE(mobj->classInfo(1).value(), "Literal!"); + + QCOMPARE(mobj->classInfo(2).name(), "!String"); + QCOMPARE(mobj->classInfo(2).value(), "!Literal"); + + QCOMPARE(mobj->classInfo(3).name(), "Stringfoo"); + QCOMPARE(mobj->classInfo(3).value(), "Literalfoo"); + + QCOMPARE(mobj->classInfo(4).name(), "fooString"); + QCOMPARE(mobj->classInfo(4).value(), "fooLiteral"); +} + +class VeryLongStringData : public QObject +{ + Q_OBJECT + + #define repeat2(V) V V + #define repeat4(V) repeat2(V) repeat2(V) + #define repeat8(V) repeat4(V) repeat4(V) + #define repeat16(V) repeat8(V) repeat8(V) + #define repeat32(V) repeat16(V) repeat16(V) + #define repeat64(V) repeat32(V) repeat32(V) + #define repeat128(V) repeat64(V) repeat64(V) + #define repeat256(V) repeat128(V) repeat128(V) + #define repeat512(V) repeat256(V) repeat256(V) + #define repeat1024(V) repeat512(V) repeat512(V) + #define repeat2048(V) repeat1024(V) repeat1024(V) + #define repeat4096(V) repeat2048(V) repeat2048(V) + #define repeat8192(V) repeat4096(V) repeat4096(V) + #define repeat16384(V) repeat8192(V) repeat8192(V) + #define repeat32768(V) repeat16384(V) repeat16384(V) + #define repeat65534(V) repeat32768(V) repeat16384(V) repeat8192(V) repeat4096(V) repeat2048(V) repeat1024(V) repeat512(V) repeat256(V) repeat128(V) repeat64(V) repeat32(V) repeat16(V) repeat8(V) repeat4(V) repeat2(V) + + Q_CLASSINFO(repeat65534("n"), repeat65534("i")) + Q_CLASSINFO(repeat65534("e"), repeat65534("r")) + Q_CLASSINFO(repeat32768("o"), repeat32768("b")) + Q_CLASSINFO(":", ")") + + #undef repeat2 + #undef repeat4 + #undef repeat8 + #undef repeat16 + #undef repeat32 + #undef repeat64 + #undef repeat128 + #undef repeat256 + #undef repeat512 + #undef repeat1024 + #undef repeat2048 + #undef repeat4096 + #undef repeat8192 + #undef repeat16384 + #undef repeat32768 + #undef repeat65534 +}; + +void tst_Moc::veryLongStringData() +{ + const QMetaObject *mobj = &VeryLongStringData::staticMetaObject; + QCOMPARE(mobj->classInfoCount(), 4); + + strlen(0); + QCOMPARE(mobj->classInfo(0).name()[0], 'n'); + QCOMPARE(mobj->classInfo(0).value()[0], 'i'); + QCOMPARE(mobj->classInfo(1).name()[0], 'e'); + QCOMPARE(mobj->classInfo(1).value()[0], 'r'); + QCOMPARE(mobj->classInfo(2).name()[0], 'o'); + QCOMPARE(mobj->classInfo(2).value()[0], 'b'); + QCOMPARE(mobj->classInfo(3).name()[0], ':'); + QCOMPARE(mobj->classInfo(3).value()[0], ')'); + + QCOMPARE(strlen(mobj->classInfo(0).name()), static_cast<size_t>(65534)); + QCOMPARE(strlen(mobj->classInfo(0).value()), static_cast<size_t>(65534)); + QCOMPARE(strlen(mobj->classInfo(1).name()), static_cast<size_t>(65534)); + QCOMPARE(strlen(mobj->classInfo(1).value()), static_cast<size_t>(65534)); + QCOMPARE(strlen(mobj->classInfo(2).name()), static_cast<size_t>(32768)); + QCOMPARE(strlen(mobj->classInfo(2).value()), static_cast<size_t>(32768)); + QCOMPARE(strlen(mobj->classInfo(3).name()), static_cast<size_t>(1)); + QCOMPARE(strlen(mobj->classInfo(3).value()), static_cast<size_t>(1)); +} + QTEST_MAIN(tst_Moc) // the generated code must compile with QT_NO_KEYWORDS |