summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp20
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp61
-rw-r--r--tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp10
-rw-r--r--tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp29
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp157
-rw-r--r--tests/auto/corelib/kernel/qobject/moc_oldnormalizeobject.cpp2
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp16
-rw-r--r--tests/auto/corelib/kernel/qvariant/stream/qt5.0/qregularexpression.binbin0 -> 53 bytes
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp46
-rw-r--r--tests/auto/corelib/tools/qarraydata/qarraydata.pro5
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h341
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp1464
-rw-r--r--tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp35
-rw-r--r--tests/auto/corelib/tools/qlist/tst_qlist.cpp172
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp220
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp94
-rw-r--r--tests/auto/corelib/tools/tools.pro1
-rw-r--r--tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp226
-rw-r--r--tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp38
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp2
-rw-r--r--tests/auto/tools/moc/slots-with-void-template.h2
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp28
-rw-r--r--tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro11
-rw-r--r--tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc5
-rw-r--r--tests/auto/tools/qdbuscpp2xml/test1.h128
-rw-r--r--tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp181
-rw-r--r--tests/auto/tools/tools.pro1
-rw-r--r--tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp2
-rw-r--r--tests/benchmarks/corelib/kernel/qmetaobject/main.cpp6
-rw-r--r--tests/benchmarks/corelib/tools/qvector/qrawvector.h58
-rw-r--r--tests/manual/cmake/CMakeLists.txt1
-rw-r--r--tests/manual/cmake/pass9/CMakeLists.txt32
-rw-r--r--tests/manual/cmake/pass9/mydbusobject.cpp56
-rw-r--r--tests/manual/cmake/pass9/mydbusobject.h58
34 files changed, 3355 insertions, 153 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index a74d817b8a..3bff330db2 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -262,9 +262,16 @@ void tst_QUrl::hashInPath()
QCOMPARE(withHashInPath.path(), QString::fromLatin1("hi#mum.txt"));
QCOMPARE(withHashInPath.toEncoded(), QByteArray("hi%23mum.txt"));
QCOMPARE(withHashInPath.toString(), QString("hi%23mum.txt"));
+ QCOMPARE(withHashInPath.toDisplayString(QUrl::PreferLocalFile), QString("hi%23mum.txt"));
QUrl fromHashInPath = QUrl::fromEncoded(withHashInPath.toEncoded());
QVERIFY(withHashInPath == fromHashInPath);
+
+ const QUrl localWithHash = QUrl::fromLocalFile("/hi#mum.txt");
+ QCOMPARE(localWithHash.path(), QString::fromLatin1("/hi#mum.txt"));
+ QCOMPARE(localWithHash.toEncoded(), QByteArray("file:///hi%23mum.txt"));
+ QCOMPARE(localWithHash.toString(), QString("file:///hi%23mum.txt"));
+ QCOMPARE(localWithHash.toDisplayString(QUrl::PreferLocalFile), QString("/hi#mum.txt"));
}
void tst_QUrl::unc()
@@ -352,6 +359,7 @@ void tst_QUrl::setUrl()
QCOMPARE(url.port(), -1);
QCOMPARE(url.toString(), QString::fromLatin1("file:///"));
QCOMPARE(url.toDisplayString(), QString::fromLatin1("file:///"));
+ QCOMPARE(url.toDisplayString(QUrl::PreferLocalFile), QString::fromLatin1("/"));
}
{
@@ -367,6 +375,7 @@ void tst_QUrl::setUrl()
QCOMPARE(url.port(), 80);
QCOMPARE(url.toString(), QString::fromLatin1("http://www.foo.bar:80"));
QCOMPARE(url.toDisplayString(), QString::fromLatin1("http://www.foo.bar:80"));
+ QCOMPARE(url.toDisplayString(QUrl::PreferLocalFile), QString::fromLatin1("http://www.foo.bar:80"));
QUrl url2("//www1.foo.bar");
QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("http://www1.foo.bar"));
@@ -451,15 +460,7 @@ void tst_QUrl::setUrl()
QUrl url = u1;
QVERIFY(url.isValid());
QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my#myref"));
- QCOMPARE(url.fragment(), QString::fromLatin1("myref"));
- }
-
- {
- QString u1 = "file:/home/dfaure/my#myref";
- QUrl url = u1;
- QVERIFY(url.isValid());
-
- QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my#myref"));
+ QCOMPARE(url.toString(QUrl::PreferLocalFile), QString::fromLatin1("file:///home/dfaure/my#myref"));
QCOMPARE(url.fragment(), QString::fromLatin1("myref"));
}
@@ -1001,6 +1002,7 @@ void tst_QUrl::toLocalFile()
QUrl url(theUrl);
QCOMPARE(url.toLocalFile(), theFile);
+ QCOMPARE(url.isLocalFile(), !theFile.isEmpty());
}
void tst_QUrl::fromLocalFile_data()
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
index 1651d00738..f44a671180 100644
--- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
+++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
@@ -223,7 +223,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject()")
<< QByteArray("MethodTestObject()")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>())
<< (QList<QByteArray>())
<< (QList<QByteArray>())
@@ -259,7 +259,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(int)")
<< QByteArray("MethodTestObject(int)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>() << int(QMetaType::Int))
<< (QList<QByteArray>() << QByteArray("int"))
<< (QList<QByteArray>() << QByteArray("constructorIntArg"))
@@ -295,7 +295,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(qreal)")
<< QByteArray("MethodTestObject(qreal)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>() << qMetaTypeId<qreal>())
<< (QList<QByteArray>() << QByteArray("qreal"))
<< (QList<QByteArray>() << QByteArray("constructorQRealArg"))
@@ -331,7 +331,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(QString)")
<< QByteArray("MethodTestObject(QString)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>() << int(QMetaType::QString))
<< (QList<QByteArray>() << QByteArray("QString"))
<< (QList<QByteArray>() << QByteArray("constructorQStringArg"))
@@ -367,7 +367,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(CustomType)")
<< QByteArray("MethodTestObject(CustomType)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>() << qMetaTypeId<CustomType>())
<< (QList<QByteArray>() << QByteArray("CustomType"))
<< (QList<QByteArray>() << QByteArray("constructorCustomTypeArg"))
@@ -403,7 +403,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(CustomUnregisteredType)")
<< QByteArray("MethodTestObject(CustomUnregisteredType)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>() << 0)
<< (QList<QByteArray>() << QByteArray("CustomUnregisteredType"))
<< (QList<QByteArray>() << QByteArray("constructorCustomUnregisteredTypeArg"))
@@ -536,7 +536,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
<< QByteArray("MethodTestObject(bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< parameterTypes << parameterTypeNames << parameterNames
<< QMetaMethod::Public
<< QMetaMethod::Constructor;
@@ -571,7 +571,7 @@ void tst_QMetaMethod::method_data()
QTest::newRow("MethodTestObject(bool,int)")
<< QByteArray("MethodTestObject(bool,int)")
- << int(QMetaType::Void) << QByteArray("")
+ << int(QMetaType::UnknownType) << QByteArray("")
<< (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int))
<< (QList<QByteArray>() << QByteArray("bool") << QByteArray("int"))
<< (QList<QByteArray>() << QByteArray("") << QByteArray(""))
@@ -603,15 +603,50 @@ void tst_QMetaMethod::method()
QCOMPARE(method.methodType(), methodType);
QCOMPARE(method.access(), access);
- QCOMPARE(method.signature(), signature.constData());
+ 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);
+ }
- QCOMPARE(method.tag(), "");
+ QByteArray computedName = signature.left(signature.indexOf('('));
+ QCOMPARE(method.name(), computedName);
- QCOMPARE(method.typeName(), returnTypeName.constData());
- QCOMPARE(QMetaType::type(method.typeName()), returnType);
+ QCOMPARE(method.tag(), "");
+ 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()
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
index 09fd0a7adb..b6b68338cd 100644
--- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
@@ -978,25 +978,25 @@ void tst_QMetaObject::propertyNotify()
QVERIFY(prop.isValid());
QVERIFY(prop.hasNotifySignal());
QMetaMethod signal = prop.notifySignal();
- QCOMPARE(signal.signature(), "value6Changed()");
+ QCOMPARE(signal.methodSignature(), QByteArray("value6Changed()"));
prop = mo->property(mo->indexOfProperty("value7"));
QVERIFY(prop.isValid());
QVERIFY(prop.hasNotifySignal());
signal = prop.notifySignal();
- QCOMPARE(signal.signature(), "value7Changed(QString)");
+ QCOMPARE(signal.methodSignature(), QByteArray("value7Changed(QString)"));
prop = mo->property(mo->indexOfProperty("value8"));
QVERIFY(prop.isValid());
QVERIFY(!prop.hasNotifySignal());
signal = prop.notifySignal();
- QCOMPARE(signal.signature(), (const char *)0);
+ QCOMPARE(signal.methodSignature(), QByteArray());
prop = mo->property(mo->indexOfProperty("value"));
QVERIFY(prop.isValid());
QVERIFY(!prop.hasNotifySignal());
signal = prop.notifySignal();
- QCOMPARE(signal.signature(), (const char *)0);
+ QCOMPARE(signal.methodSignature(), QByteArray());
}
void tst_QMetaObject::propertyConstant()
@@ -1114,7 +1114,7 @@ void tst_QMetaObject::indexOfMethod()
QFETCH(bool, isSignal);
int idx = object->metaObject()->indexOfMethod(name);
QVERIFY(idx >= 0);
- QCOMPARE(object->metaObject()->method(idx).signature(), name.constData());
+ QCOMPARE(object->metaObject()->method(idx).methodSignature(), name);
QCOMPARE(object->metaObject()->indexOfSlot(name), isSignal ? -1 : idx);
QCOMPARE(object->metaObject()->indexOfSignal(name), !isSignal ? -1 : idx);
}
diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
index 97b14a374e..f187425c84 100644
--- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
+++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
@@ -217,6 +217,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(nullMethod.signature(), QByteArray());
QVERIFY(nullMethod.methodType() == QMetaMethod::Method);
QVERIFY(nullMethod.returnType().isEmpty());
+ QVERIFY(nullMethod.parameterTypes().isEmpty());
QVERIFY(nullMethod.parameterNames().isEmpty());
QVERIFY(nullMethod.tag().isEmpty());
QVERIFY(nullMethod.access() == QMetaMethod::Public);
@@ -229,6 +230,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(method1.methodType() == QMetaMethod::Method);
QVERIFY(method1.returnType().isEmpty());
+ QCOMPARE(method1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QVERIFY(method1.parameterNames().isEmpty());
QVERIFY(method1.tag().isEmpty());
QVERIFY(method1.access() == QMetaMethod::Public);
@@ -242,6 +244,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QVERIFY(method2.methodType() == QMetaMethod::Method);
QCOMPARE(method2.returnType(), QByteArray("int"));
+ QCOMPARE(method2.parameterTypes(), QList<QByteArray>() << "QString");
QVERIFY(method2.parameterNames().isEmpty());
QVERIFY(method2.tag().isEmpty());
QVERIFY(method2.access() == QMetaMethod::Public);
@@ -267,6 +270,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(method1.methodType() == QMetaMethod::Method);
QCOMPARE(method1.returnType(), QByteArray("int"));
+ QCOMPARE(method1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QCOMPARE(method1.parameterNames(), QList<QByteArray>() << "a" << "b");
QCOMPARE(method1.tag(), QByteArray("tag"));
QVERIFY(method1.access() == QMetaMethod::Private);
@@ -276,6 +280,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QVERIFY(method2.methodType() == QMetaMethod::Method);
QCOMPARE(method2.returnType(), QByteArray("int"));
+ QCOMPARE(method2.parameterTypes(), QList<QByteArray>() << "QString");
QVERIFY(method2.parameterNames().isEmpty());
QVERIFY(method2.tag().isEmpty());
QVERIFY(method2.access() == QMetaMethod::Public);
@@ -296,6 +301,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(method1.methodType() == QMetaMethod::Method);
QCOMPARE(method1.returnType(), QByteArray("int"));
+ QCOMPARE(method1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QCOMPARE(method1.parameterNames(), QList<QByteArray>() << "a" << "b");
QCOMPARE(method1.tag(), QByteArray("tag"));
QVERIFY(method1.access() == QMetaMethod::Private);
@@ -305,6 +311,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QVERIFY(method2.methodType() == QMetaMethod::Method);
QCOMPARE(method2.returnType(), QByteArray("QString"));
+ QCOMPARE(method2.parameterTypes(), QList<QByteArray>() << "QString");
QCOMPARE(method2.parameterNames(), QList<QByteArray>() << "c");
QCOMPARE(method2.tag(), QByteArray("Q_FOO"));
QVERIFY(method2.access() == QMetaMethod::Protected);
@@ -320,6 +327,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QVERIFY(method2.methodType() == QMetaMethod::Method);
QCOMPARE(method2.returnType(), QByteArray("QString"));
+ QCOMPARE(method2.parameterTypes(), QList<QByteArray>() << "QString");
QCOMPARE(method2.parameterNames(), QList<QByteArray>() << "c");
QCOMPARE(method2.tag(), QByteArray("Q_FOO"));
QVERIFY(method2.access() == QMetaMethod::Protected);
@@ -347,6 +355,7 @@ void tst_QMetaObjectBuilder::slot()
QCOMPARE(method1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(method1.methodType() == QMetaMethod::Slot);
QVERIFY(method1.returnType().isEmpty());
+ QCOMPARE(method1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QVERIFY(method1.parameterNames().isEmpty());
QVERIFY(method1.tag().isEmpty());
QVERIFY(method1.access() == QMetaMethod::Public);
@@ -359,6 +368,7 @@ void tst_QMetaObjectBuilder::slot()
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QVERIFY(method2.methodType() == QMetaMethod::Slot);
QVERIFY(method2.returnType().isEmpty());
+ QCOMPARE(method2.parameterTypes(), QList<QByteArray>() << "QString");
QVERIFY(method2.parameterNames().isEmpty());
QVERIFY(method2.tag().isEmpty());
QVERIFY(method2.access() == QMetaMethod::Public);
@@ -384,6 +394,7 @@ void tst_QMetaObjectBuilder::signal()
QCOMPARE(method1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(method1.methodType() == QMetaMethod::Signal);
QVERIFY(method1.returnType().isEmpty());
+ QCOMPARE(method1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QVERIFY(method1.parameterNames().isEmpty());
QVERIFY(method1.tag().isEmpty());
QVERIFY(method1.access() == QMetaMethod::Protected);
@@ -396,6 +407,7 @@ void tst_QMetaObjectBuilder::signal()
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QVERIFY(method2.methodType() == QMetaMethod::Signal);
QVERIFY(method2.returnType().isEmpty());
+ QCOMPARE(method2.parameterTypes(), QList<QByteArray>() << "QString");
QVERIFY(method2.parameterNames().isEmpty());
QVERIFY(method2.tag().isEmpty());
QVERIFY(method2.access() == QMetaMethod::Protected);
@@ -421,6 +433,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(ctor1.methodType() == QMetaMethod::Constructor);
QVERIFY(ctor1.returnType().isEmpty());
+ QCOMPARE(ctor1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QVERIFY(ctor1.parameterNames().isEmpty());
QVERIFY(ctor1.tag().isEmpty());
QVERIFY(ctor1.access() == QMetaMethod::Public);
@@ -433,6 +446,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor2.signature(), QByteArray("bar(QString)"));
QVERIFY(ctor2.methodType() == QMetaMethod::Constructor);
QVERIFY(ctor2.returnType().isEmpty());
+ QCOMPARE(ctor2.parameterTypes(), QList<QByteArray>() << "QString");
QVERIFY(ctor2.parameterNames().isEmpty());
QVERIFY(ctor2.tag().isEmpty());
QVERIFY(ctor2.access() == QMetaMethod::Public);
@@ -458,6 +472,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(ctor1.methodType() == QMetaMethod::Constructor);
QCOMPARE(ctor1.returnType(), QByteArray("int"));
+ QCOMPARE(ctor1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QCOMPARE(ctor1.parameterNames(), QList<QByteArray>() << "a" << "b");
QCOMPARE(ctor1.tag(), QByteArray("tag"));
QVERIFY(ctor1.access() == QMetaMethod::Private);
@@ -466,6 +481,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor2.signature(), QByteArray("bar(QString)"));
QVERIFY(ctor2.methodType() == QMetaMethod::Constructor);
QVERIFY(ctor2.returnType().isEmpty());
+ QCOMPARE(ctor2.parameterTypes(), QList<QByteArray>() << "QString");
QVERIFY(ctor2.parameterNames().isEmpty());
QVERIFY(ctor2.tag().isEmpty());
QVERIFY(ctor2.access() == QMetaMethod::Public);
@@ -484,6 +500,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor1.signature(), QByteArray("foo(QString,int)"));
QVERIFY(ctor1.methodType() == QMetaMethod::Constructor);
QCOMPARE(ctor1.returnType(), QByteArray("int"));
+ QCOMPARE(ctor1.parameterTypes(), QList<QByteArray>() << "QString" << "int");
QCOMPARE(ctor1.parameterNames(), QList<QByteArray>() << "a" << "b");
QCOMPARE(ctor1.tag(), QByteArray("tag"));
QVERIFY(ctor1.access() == QMetaMethod::Private);
@@ -492,6 +509,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor2.signature(), QByteArray("bar(QString)"));
QVERIFY(ctor2.methodType() == QMetaMethod::Constructor);
QCOMPARE(ctor2.returnType(), QByteArray("QString"));
+ QCOMPARE(ctor2.parameterTypes(), QList<QByteArray>() << "QString");
QCOMPARE(ctor2.parameterNames(), QList<QByteArray>() << "c");
QCOMPARE(ctor2.tag(), QByteArray("Q_FOO"));
QVERIFY(ctor2.access() == QMetaMethod::Protected);
@@ -506,6 +524,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(ctor2.signature(), QByteArray("bar(QString)"));
QVERIFY(ctor2.methodType() == QMetaMethod::Constructor);
QCOMPARE(ctor2.returnType(), QByteArray("QString"));
+ QCOMPARE(ctor2.parameterTypes(), QList<QByteArray>() << "QString");
QCOMPARE(ctor2.parameterNames(), QList<QByteArray>() << "c");
QCOMPARE(ctor2.tag(), QByteArray("Q_FOO"));
QVERIFY(ctor2.access() == QMetaMethod::Protected);
@@ -525,6 +544,7 @@ void tst_QMetaObjectBuilder::constructor()
QCOMPARE(prototypeConstructor.signature(), QByteArray("SomethingOfEverything()"));
QVERIFY(prototypeConstructor.methodType() == QMetaMethod::Constructor);
QCOMPARE(prototypeConstructor.returnType(), QByteArray());
+ QVERIFY(prototypeConstructor.parameterTypes().isEmpty());
QVERIFY(prototypeConstructor.access() == QMetaMethod::Public);
QCOMPARE(prototypeConstructor.index(), 1);
@@ -1161,12 +1181,15 @@ bool tst_QMetaObjectBuilder::checkForSideEffects
static bool sameMethod(const QMetaMethod& method1, const QMetaMethod& method2)
{
- if (QByteArray(method1.signature()) != QByteArray(method2.signature()))
+ if (method1.methodSignature() != method2.methodSignature())
return false;
if (QByteArray(method1.typeName()) != QByteArray(method2.typeName()))
return false;
+ if (method1.parameterTypes() != method2.parameterTypes())
+ return false;
+
if (method1.parameterNames() != method2.parameterNames())
return false;
@@ -1466,7 +1489,7 @@ void TestObject::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break;
default: {
QMetaMethod ctor = _o->metaObject()->constructor(_id);
- qFatal("You forgot to add a case for CreateInstance %s", ctor.signature());
+ qFatal("You forgot to add a case for CreateInstance %s", ctor.methodSignature().constData());
}
}
} else if (_c == QMetaObject::InvokeMetaMethod) {
@@ -1478,7 +1501,7 @@ void TestObject::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
case 2: *reinterpret_cast<QVariantList(*)>(_a[0]) = _t->listInvokableQRealQString(*reinterpret_cast<qreal(*)>(_a[1]), *reinterpret_cast<QString(*)>(_a[2])); break;
default: {
QMetaMethod method = _o->metaObject()->method(_o->metaObject()->methodOffset() + _id);
- qFatal("You forgot to add a case for InvokeMetaMethod %s", method.signature());
+ qFatal("You forgot to add a case for InvokeMetaMethod %s", method.methodSignature().constData());
}
}
} else if (_c == QMetaObject::IndexOfMethod) {
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index d93e00eed8..b22a3d526a 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -97,16 +97,36 @@ private slots:
void isEnum();
void registerStreamBuiltin();
void automaticTemplateRegistration();
+ void saveAndLoadBuiltin_data();
+ void saveAndLoadBuiltin();
+ void saveAndLoadCustom();
};
struct Foo { int i; };
+
+class CustomQObject : public QObject
+{
+ Q_OBJECT
+public:
+ CustomQObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+ }
+};
+
+class CustomNonQObject {};
+
void tst_QMetaType::defined()
{
QCOMPARE(int(QMetaTypeId2<QString>::Defined), 1);
QCOMPARE(int(QMetaTypeId2<Foo>::Defined), 0);
QCOMPARE(int(QMetaTypeId2<void*>::Defined), 1);
QCOMPARE(int(QMetaTypeId2<int*>::Defined), 0);
+ QVERIFY(QMetaTypeId2<CustomQObject*>::Defined);
+ QVERIFY(!QMetaTypeId2<CustomQObject>::Defined);
+ QVERIFY(!QMetaTypeId2<CustomNonQObject>::Defined);
+ QVERIFY(!QMetaTypeId2<CustomNonQObject*>::Defined);
}
struct Bar
@@ -312,6 +332,7 @@ void tst_QMetaType::typeName_data()
QTest::addColumn<QString>("aTypeName");
QT_FOR_EACH_STATIC_TYPE(TYPENAME_DATA)
+ QTest::newRow("QMetaType::UnknownType") << QMetaType::UnknownType << static_cast<const char*>(0);
QTest::newRow("Whity<double>") << static_cast<QMetaType::Type>(::qMetaTypeId<Whity<double> >()) << QString::fromLatin1("Whity<double>");
QTest::newRow("Whity<int>") << static_cast<QMetaType::Type>(::qMetaTypeId<Whity<int> >()) << QString::fromLatin1("Whity<int>");
@@ -510,6 +531,16 @@ template<> struct TestValueFactory<QMetaType::QRegExp> {
#endif
}
};
+template<> struct TestValueFactory<QMetaType::QRegularExpression> {
+ static QRegularExpression *create()
+ {
+#ifndef QT_NO_REGEXP
+ return new QRegularExpression("abc.*def");
+#else
+ return 0;
+#endif
+ }
+};
template<> struct TestValueFactory<QMetaType::QVariant> {
static QVariant *create() { return new QVariant(QStringList(QStringList() << "Q" << "t")); }
};
@@ -630,6 +661,8 @@ void tst_QMetaType::sizeOf_data()
{
QTest::addColumn<QMetaType::Type>("type");
QTest::addColumn<size_t>("size");
+
+ QTest::newRow("QMetaType::UnknownType") << QMetaType::UnknownType << size_t(0);
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
QTest::newRow(#RealType) << QMetaType::MetaTypeName << size_t(QTypeInfo<RealType>::sizeOf);
FOR_EACH_CORE_METATYPE(ADD_METATYPE_TEST_ROW)
@@ -1052,6 +1085,7 @@ void tst_QMetaType::isRegistered_data()
QTest::newRow("-1") << -1 << false;
QTest::newRow("-42") << -42 << false;
QTest::newRow("IsRegisteredDummyType + 1") << (dummyTypeId + 1) << false;
+ QTest::newRow("QMetaType::UnknownType") << int(QMetaType::UnknownType) << false;
}
void tst_QMetaType::isRegistered()
@@ -1291,6 +1325,129 @@ void tst_QMetaType::automaticTemplateRegistration()
}
}
+template <typename T>
+struct StreamingTraits
+{
+ enum { isStreamable = 1 }; // Streamable by default
+};
+
+// Non-streamable types
+
+#define DECLARE_NONSTREAMABLE(Type) \
+ template<> struct StreamingTraits<Type> { enum { isStreamable = 0 }; };
+
+DECLARE_NONSTREAMABLE(void)
+DECLARE_NONSTREAMABLE(void*)
+DECLARE_NONSTREAMABLE(QModelIndex)
+DECLARE_NONSTREAMABLE(QObject*)
+DECLARE_NONSTREAMABLE(QWidget*)
+
+#define DECLARE_GUI_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \
+ DECLARE_NONSTREAMABLE(RealType)
+QT_FOR_EACH_STATIC_GUI_CLASS(DECLARE_GUI_CLASS_NONSTREAMABLE)
+#undef DECLARE_GUI_CLASS_NONSTREAMABLE
+
+#define DECLARE_WIDGETS_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \
+ DECLARE_NONSTREAMABLE(RealType)
+QT_FOR_EACH_STATIC_WIDGETS_CLASS(DECLARE_WIDGETS_CLASS_NONSTREAMABLE)
+#undef DECLARE_WIDGETS_CLASS_NONSTREAMABLE
+
+#undef DECLARE_NONSTREAMABLE
+
+void tst_QMetaType::saveAndLoadBuiltin_data()
+{
+ QTest::addColumn<int>("type");
+ QTest::addColumn<bool>("isStreamable");
+
+#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
+ QTest::newRow(#RealType) << MetaTypeId << bool(StreamingTraits<RealType>::isStreamable);
+ QT_FOR_EACH_STATIC_TYPE(ADD_METATYPE_TEST_ROW)
+#undef ADD_METATYPE_TEST_ROW
+}
+
+void tst_QMetaType::saveAndLoadBuiltin()
+{
+ QFETCH(int, type);
+ QFETCH(bool, isStreamable);
+
+ void *value = QMetaType::create(type);
+
+ QByteArray ba;
+ QDataStream stream(&ba, QIODevice::ReadWrite);
+ QCOMPARE(QMetaType::save(stream, type, value), isStreamable);
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ if (isStreamable) {
+ QVERIFY(QMetaType::load(stream, type, value)); // Hmmm, shouldn't it return false?
+ QCOMPARE(stream.status(), QDataStream::ReadPastEnd);
+ }
+
+ stream.device()->seek(0);
+ stream.resetStatus();
+ QCOMPARE(QMetaType::load(stream, type, value), isStreamable);
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ if (isStreamable) {
+ QVERIFY(QMetaType::load(stream, type, value)); // Hmmm, shouldn't it return false?
+ QCOMPARE(stream.status(), QDataStream::ReadPastEnd);
+ }
+
+ QMetaType::destroy(type, value);
+}
+
+struct CustomStreamableType
+{
+ int a;
+};
+Q_DECLARE_METATYPE(CustomStreamableType)
+
+QDataStream &operator<<(QDataStream &out, const CustomStreamableType &t)
+{
+ out << t.a; return out;
+}
+
+QDataStream &operator>>(QDataStream &in, CustomStreamableType &t)
+{
+ int a;
+ in >> a;
+ if (in.status() == QDataStream::Ok)
+ t.a = a;
+ return in;
+}
+
+void tst_QMetaType::saveAndLoadCustom()
+{
+ CustomStreamableType t;
+ t.a = 123;
+
+ int id = ::qMetaTypeId<CustomStreamableType>();
+ QByteArray ba;
+ QDataStream stream(&ba, QIODevice::ReadWrite);
+ QVERIFY(!QMetaType::save(stream, id, &t));
+ QCOMPARE(stream.status(), QDataStream::Ok);
+ QVERIFY(!QMetaType::load(stream, id, &t));
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ qRegisterMetaTypeStreamOperators<CustomStreamableType>("CustomStreamableType");
+ QVERIFY(QMetaType::save(stream, id, &t));
+ QCOMPARE(stream.status(), QDataStream::Ok);
+
+ CustomStreamableType t2;
+ t2.a = -1;
+ QVERIFY(QMetaType::load(stream, id, &t2)); // Hmmm, shouldn't it return false?
+ QCOMPARE(stream.status(), QDataStream::ReadPastEnd);
+ QCOMPARE(t2.a, -1);
+
+ stream.device()->seek(0);
+ stream.resetStatus();
+ QVERIFY(QMetaType::load(stream, id, &t2));
+ QCOMPARE(stream.status(), QDataStream::Ok);
+ QCOMPARE(t2.a, t.a);
+
+ QVERIFY(QMetaType::load(stream, id, &t2)); // Hmmm, shouldn't it return false?
+ QCOMPARE(stream.status(), QDataStream::ReadPastEnd);
+}
+
// Compile-time test, it should be possible to register function pointer types
class Undefined;
diff --git a/tests/auto/corelib/kernel/qobject/moc_oldnormalizeobject.cpp b/tests/auto/corelib/kernel/qobject/moc_oldnormalizeobject.cpp
index 2d180b88ea..021079a8e7 100644
--- a/tests/auto/corelib/kernel/qobject/moc_oldnormalizeobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/moc_oldnormalizeobject.cpp
@@ -90,7 +90,7 @@ static const char qt_meta_stringdata_OldNormalizeObject[] = {
};
const QMetaObject OldNormalizeObject::staticMetaObject = {
- { &QObject::staticMetaObject, qt_meta_stringdata_OldNormalizeObject,
+ { &QObject::staticMetaObject, reinterpret_cast<const QByteArrayData *>(qt_meta_stringdata_OldNormalizeObject),
qt_meta_data_OldNormalizeObject, 0 }
};
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index a6ad1d53bc..c6667ff2a8 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -1793,56 +1793,56 @@ void tst_QObject::metamethod()
QMetaMethod m;
m = mobj->method(mobj->indexOfMethod("invoke1()"));
- QVERIFY(QByteArray(m.signature()) == "invoke1()");
+ QVERIFY(m.methodSignature() == "invoke1()");
QVERIFY(m.methodType() == QMetaMethod::Method);
QVERIFY(m.access() == QMetaMethod::Public);
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable));
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("sinvoke1()"));
- QVERIFY(QByteArray(m.signature()) == "sinvoke1()");
+ QVERIFY(m.methodSignature() == "sinvoke1()");
QVERIFY(m.methodType() == QMetaMethod::Method);
QVERIFY(m.access() == QMetaMethod::Public);
QVERIFY((m.attributes() & QMetaMethod::Scriptable));
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("invoke2()"));
- QVERIFY(QByteArray(m.signature()) == "invoke2()");
+ QVERIFY(m.methodSignature() == "invoke2()");
QVERIFY(m.methodType() == QMetaMethod::Method);
QVERIFY(m.access() == QMetaMethod::Protected);
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable));
QVERIFY((m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("sinvoke2()"));
- QVERIFY(QByteArray(m.signature()) == "sinvoke2()");
+ QVERIFY(m.methodSignature() == "sinvoke2()");
QVERIFY(m.methodType() == QMetaMethod::Method);
QVERIFY(m.access() == QMetaMethod::Protected);
QVERIFY((m.attributes() & QMetaMethod::Scriptable));
QVERIFY((m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("invoke3()"));
- QVERIFY(QByteArray(m.signature()) == "invoke3()");
+ QVERIFY(m.methodSignature() == "invoke3()");
QVERIFY(m.methodType() == QMetaMethod::Method);
QVERIFY(m.access() == QMetaMethod::Private);
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable));
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("sinvoke3()"));
- QVERIFY(QByteArray(m.signature()) == "sinvoke3()");
+ QVERIFY(m.methodSignature() == "sinvoke3()");
QVERIFY(m.methodType() == QMetaMethod::Method);
QVERIFY(m.access() == QMetaMethod::Private);
QVERIFY((m.attributes() & QMetaMethod::Scriptable));
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("signal5()"));
- QVERIFY(QByteArray(m.signature()) == "signal5()");
+ QVERIFY(m.methodSignature() == "signal5()");
QVERIFY(m.methodType() == QMetaMethod::Signal);
QVERIFY(m.access() == QMetaMethod::Protected);
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable));
QVERIFY((m.attributes() & QMetaMethod::Compatibility));
m = mobj->method(mobj->indexOfMethod("aPublicSlot()"));
- QVERIFY(QByteArray(m.signature()) == "aPublicSlot()");
+ QVERIFY(m.methodSignature() == "aPublicSlot()");
QVERIFY(m.methodType() == QMetaMethod::Slot);
QVERIFY(m.access() == QMetaMethod::Public);
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable));
diff --git a/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qregularexpression.bin b/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qregularexpression.bin
new file mode 100644
index 0000000000..eaa50f7310
--- /dev/null
+++ b/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qregularexpression.bin
Binary files differ
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 655c714322..05655b4df6 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -192,6 +192,7 @@ private slots:
void toLocale();
void toRegExp();
+ void toRegularExpression();
void matrix();
@@ -1319,6 +1320,21 @@ void tst_QVariant::toRegExp()
rx = variant.toRegExp();
}
+void tst_QVariant::toRegularExpression()
+{
+ QVariant variant;
+ QRegularExpression re = variant.toRegularExpression();
+ QCOMPARE(re, QRegularExpression());
+
+ variant = QRegularExpression("abc.*def");
+ re = variant.toRegularExpression();
+ QCOMPARE(re, QRegularExpression("abc.*def"));
+
+ variant = QVariant::fromValue(QRegularExpression("[ab]\\w+"));
+ re = variant.value<QRegularExpression>();
+ QCOMPARE(re, QRegularExpression("[ab]\\w+"));
+}
+
void tst_QVariant::matrix()
{
QVariant variant;
@@ -1519,6 +1535,8 @@ void tst_QVariant::writeToReadFromDataStream_data()
QTest::newRow( "qchar_null" ) << QVariant(QChar(0)) << true;
QTest::newRow( "regexp" ) << QVariant(QRegExp("foo", Qt::CaseInsensitive)) << false;
QTest::newRow( "regexp_empty" ) << QVariant(QRegExp()) << false;
+ QTest::newRow( "regularexpression" ) << QVariant(QRegularExpression("abc.*def")) << false;
+ QTest::newRow( "regularexpression_empty" ) << QVariant(QRegularExpression()) << false;
// types known to QMetaType, but not part of QVariant::Type
QTest::newRow("QMetaType::Long invalid") << QVariant(QMetaType::Long, (void *) 0) << false;
@@ -1944,6 +1962,7 @@ void tst_QVariant::typeName_data()
QTest::newRow("48") << int(QVariant::Vector3D) << QByteArray("QVector3D");
QTest::newRow("49") << int(QVariant::Vector4D) << QByteArray("QVector4D");
QTest::newRow("50") << int(QVariant::Quaternion) << QByteArray("QQuaternion");
+ QTest::newRow("51") << int(QVariant::RegularExpression) << QByteArray("QRegularExpression");
}
void tst_QVariant::typeName()
@@ -2547,9 +2566,24 @@ public:
};
Q_DECLARE_METATYPE(CustomQObjectDerived*)
+class CustomQObjectDerivedNoMetaType : public CustomQObject {
+ Q_OBJECT
+public:
+ CustomQObjectDerivedNoMetaType(QObject *parent = 0) : CustomQObject(parent) {}
+};
+
void tst_QVariant::qvariant_cast_QObject_derived()
{
{
+ CustomQObjectDerivedNoMetaType *object = new CustomQObjectDerivedNoMetaType(this);
+ QVariant data = QVariant::fromValue(object);
+ QVERIFY(data.userType() == qMetaTypeId<CustomQObjectDerivedNoMetaType*>());
+ QCOMPARE(data.value<QObject *>(), object);
+ QCOMPARE(data.value<CustomQObjectDerivedNoMetaType *>(), object);
+ QCOMPARE(data.value<CustomQObject *>(), object);
+ QVERIFY(data.value<CustomQWidget*>() == 0);
+ }
+ {
CustomQObjectDerived *object = new CustomQObjectDerived(this);
QVariant data = QVariant::fromValue(object);
@@ -3548,6 +3582,10 @@ void tst_QVariant::loadQVariantFromDataStream(QDataStream::Version version)
stream >> typeName >> loadedVariant;
const int id = QMetaType::type(typeName.toLatin1());
+ if (id == QMetaType::Void) {
+ // Void type is not supported by QVariant
+ return;
+ }
QVariant constructedVariant(static_cast<QVariant::Type>(id));
QCOMPARE(constructedVariant.userType(), id);
@@ -3567,6 +3605,10 @@ void tst_QVariant::saveQVariantFromDataStream(QDataStream::Version version)
dataFileStream >> typeName;
QByteArray data = file.readAll();
const int id = QMetaType::type(typeName.toLatin1());
+ if (id == QMetaType::Void) {
+ // Void type is not supported by QVariant
+ return;
+ }
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
@@ -3627,7 +3669,9 @@ void tst_QVariant::debugStream_data()
const char *tagName = QMetaType::typeName(id);
if (!tagName)
continue;
- QTest::newRow(tagName) << QVariant(static_cast<QVariant::Type>(id)) << id;
+ if (id != QMetaType::Void) {
+ QTest::newRow(tagName) << QVariant(static_cast<QVariant::Type>(id)) << id;
+ }
}
QTest::newRow("QBitArray(111)") << QVariant(QBitArray(3, true)) << qMetaTypeId<QBitArray>();
QTest::newRow("CustomStreamableClass") << QVariant(qMetaTypeId<CustomStreamableClass>(), 0) << qMetaTypeId<CustomStreamableClass>();
diff --git a/tests/auto/corelib/tools/qarraydata/qarraydata.pro b/tests/auto/corelib/tools/qarraydata/qarraydata.pro
new file mode 100644
index 0000000000..8e368117fa
--- /dev/null
+++ b/tests/auto/corelib/tools/qarraydata/qarraydata.pro
@@ -0,0 +1,5 @@
+TARGET = tst_qarraydata
+SOURCES += tst_qarraydata.cpp
+HEADERS += simplevector.h
+QT = core testlib
+CONFIG += testcase parallel_test
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
new file mode 100644
index 0000000000..fe8108bff2
--- /dev/null
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -0,0 +1,341 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef QARRAY_TEST_SIMPLE_VECTOR_H
+#define QARRAY_TEST_SIMPLE_VECTOR_H
+
+#include <QtCore/qarraydata.h>
+#include <QtCore/qarraydatapointer.h>
+
+#include <algorithm>
+
+template <class T>
+struct SimpleVector
+{
+private:
+ typedef QTypedArrayData<T> Data;
+
+public:
+ typedef T value_type;
+ typedef typename Data::iterator iterator;
+ typedef typename Data::const_iterator const_iterator;
+
+ SimpleVector()
+ {
+ }
+
+ SimpleVector(size_t n, const T &t)
+ : d(Data::allocate(n))
+ {
+ if (n)
+ d->copyAppend(n, t);
+ }
+
+ SimpleVector(const T *begin, const T *end)
+ : d(Data::allocate(end - begin))
+ {
+ if (end - begin)
+ d->copyAppend(begin, end);
+ }
+
+ SimpleVector(QArrayDataPointerRef<T> ptr)
+ : d(ptr)
+ {
+ }
+
+ explicit SimpleVector(Data *ptr)
+ : d(ptr)
+ {
+ }
+
+ bool empty() const { return d->size == 0; }
+ bool isNull() const { return d.isNull(); }
+ bool isEmpty() const { return this->empty(); }
+
+ bool isStatic() const { return d->ref.isStatic(); }
+ bool isShared() const { return d->ref.isShared(); }
+ bool isSharedWith(const SimpleVector &other) const { return d == other.d; }
+ bool isSharable() const { return d->ref.isSharable(); }
+
+ void setSharable(bool sharable) { d.setSharable(sharable); }
+
+ size_t size() const { return d->size; }
+ size_t capacity() const { return d->alloc; }
+
+ iterator begin() { detach(); return d->begin(); }
+ iterator end() { detach(); return d->end(); }
+
+ const_iterator begin() const { return d->begin(); }
+ const_iterator end() const { return d->end(); }
+
+ const_iterator constBegin() const { return begin(); }
+ const_iterator constEnd() const { return end(); }
+
+ T &operator[](size_t i) { Q_ASSERT(i < size_t(d->size)); detach(); return begin()[i]; }
+ T &at(size_t i) { Q_ASSERT(i < size_t(d->size)); detach(); return begin()[i]; }
+
+ const T &operator[](size_t i) const { Q_ASSERT(i < size_t(d->size)); return begin()[i]; }
+ const T &at(size_t i) const { Q_ASSERT(i < size_t(d->size)); return begin()[i]; }
+
+ T &front()
+ {
+ Q_ASSERT(!isEmpty());
+ detach();
+ return *begin();
+ }
+
+ T &back()
+ {
+ Q_ASSERT(!isEmpty());
+ detach();
+ return *(end() - 1);
+ }
+
+ const T &front() const
+ {
+ Q_ASSERT(!isEmpty());
+ return *begin();
+ }
+
+ const T &back() const
+ {
+ Q_ASSERT(!isEmpty());
+ return *(end() - 1);
+ }
+
+ void reserve(size_t n)
+ {
+ if (n == 0)
+ return;
+
+ if (n <= capacity()) {
+ if (d->capacityReserved)
+ return;
+ if (!d->ref.isShared()) {
+ d->capacityReserved = 1;
+ return;
+ }
+ }
+
+ SimpleVector detached(Data::allocate(qMax(n, size()),
+ d->detachFlags() | Data::CapacityReserved));
+ if (size())
+ detached.d->copyAppend(constBegin(), constEnd());
+ detached.swap(*this);
+ }
+
+ void prepend(const_iterator first, const_iterator last)
+ {
+ if (!d->size) {
+ append(first, last);
+ return;
+ }
+
+ if (first == last)
+ return;
+
+ T *const begin = d->begin();
+ if (d->ref.isShared()
+ || capacity() - size() < size_t(last - first)) {
+ SimpleVector detached(Data::allocate(
+ qMax(capacity(), size() + (last - first)),
+ d->detachFlags() | Data::Grow));
+
+ detached.d->copyAppend(first, last);
+ detached.d->copyAppend(begin, begin + d->size);
+ detached.swap(*this);
+
+ return;
+ }
+
+ d->insert(begin, first, last);
+ }
+
+ void append(const_iterator first, const_iterator last)
+ {
+ if (first == last)
+ return;
+
+ if (d->ref.isShared()
+ || capacity() - size() < size_t(last - first)) {
+ SimpleVector detached(Data::allocate(
+ qMax(capacity(), size() + (last - first)),
+ d->detachFlags() | Data::Grow));
+
+ if (d->size) {
+ const T *const begin = constBegin();
+ detached.d->copyAppend(begin, begin + d->size);
+ }
+ detached.d->copyAppend(first, last);
+ detached.swap(*this);
+
+ return;
+ }
+
+ d->copyAppend(first, last);
+ }
+
+ void insert(int position, const_iterator first, const_iterator last)
+ {
+ if (position < 0)
+ position += d->size + 1;
+
+ if (position <= 0) {
+ prepend(first, last);
+ return;
+ }
+
+ if (size_t(position) >= size()) {
+ append(first, last);
+ return;
+ }
+
+ if (first == last)
+ return;
+
+ T *const begin = d->begin();
+ T *const where = begin + position;
+ const T *const end = begin + d->size;
+ if (d->ref.isShared()
+ || capacity() - size() < size_t(last - first)) {
+ SimpleVector detached(Data::allocate(
+ qMax(capacity(), size() + (last - first)),
+ d->detachFlags() | Data::Grow));
+
+ if (position)
+ detached.d->copyAppend(begin, where);
+ detached.d->copyAppend(first, last);
+ detached.d->copyAppend(where, end);
+ detached.swap(*this);
+
+ return;
+ }
+
+ if ((first >= where && first < end)
+ || (last > where && last <= end)) {
+ // Copy overlapping data first and only then shuffle it into place
+ T *start = d->begin() + position;
+ T *middle = d->end();
+
+ d->copyAppend(first, last);
+ std::rotate(start, middle, d->end());
+
+ return;
+ }
+
+ d->insert(where, first, last);
+ }
+
+ void swap(SimpleVector &other)
+ {
+ qSwap(d, other.d);
+ }
+
+ void clear()
+ {
+ d.clear();
+ }
+
+ void detach()
+ {
+ d.detach();
+ }
+
+ static SimpleVector fromRawData(const T *data, size_t size,
+ QArrayData::AllocationOptions options = Data::Default)
+ {
+ return SimpleVector(Data::fromRawData(data, size, options));
+ }
+
+private:
+ QArrayDataPointer<T> d;
+};
+
+template <class T>
+bool operator==(const SimpleVector<T> &lhs, const SimpleVector<T> &rhs)
+{
+ if (lhs.isSharedWith(rhs))
+ return true;
+ if (lhs.size() != rhs.size())
+ return false;
+ return std::equal(lhs.begin(), lhs.end(), rhs.begin());
+}
+
+template <class T>
+bool operator!=(const SimpleVector<T> &lhs, const SimpleVector<T> &rhs)
+{
+ return !(lhs == rhs);
+}
+
+template <class T>
+bool operator<(const SimpleVector<T> &lhs, const SimpleVector<T> &rhs)
+{
+ return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
+template <class T>
+bool operator>(const SimpleVector<T> &lhs, const SimpleVector<T> &rhs)
+{
+ return rhs < lhs;
+}
+
+template <class T>
+bool operator<=(const SimpleVector<T> &lhs, const SimpleVector<T> &rhs)
+{
+ return !(rhs < lhs);
+}
+
+template <class T>
+bool operator>=(const SimpleVector<T> &lhs, const SimpleVector<T> &rhs)
+{
+ return !(lhs < rhs);
+}
+
+namespace std {
+ template <class T>
+ void swap(SimpleVector<T> &v1, SimpleVector<T> &v2)
+ {
+ v1.swap(v2);
+ }
+}
+
+#endif // include guard
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
new file mode 100644
index 0000000000..9bfbac0017
--- /dev/null
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -0,0 +1,1464 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <QtCore/QString>
+#include <QtCore/qarraydata.h>
+
+#include "simplevector.h"
+
+struct SharedNullVerifier
+{
+ SharedNullVerifier()
+ {
+ Q_ASSERT(QArrayData::shared_null.ref.isStatic());
+ Q_ASSERT(QArrayData::shared_null.ref.isShared());
+ Q_ASSERT(QArrayData::shared_null.ref.isSharable());
+ }
+};
+
+// This is meant to verify/ensure that shared_null is not being dynamically
+// initialized and stays away from the order-of-static-initialization fiasco.
+//
+// Of course, if this was to fail, qmake and the build should have crashed and
+// burned before we ever got to this point :-)
+SharedNullVerifier globalInit;
+
+class tst_QArrayData : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void referenceCounting();
+ void sharedNullEmpty();
+ void staticData();
+ void simpleVector();
+ void simpleVectorReserve_data();
+ void simpleVectorReserve();
+ void allocate_data();
+ void allocate();
+ void alignment_data();
+ void alignment();
+ void typedData();
+ void gccBug43247();
+ void arrayOps();
+ void setSharable_data();
+ void setSharable();
+ void fromRawData();
+ void literals();
+ void variadicLiterals();
+ void rValueReferences();
+ void grow();
+};
+
+template <class T> const T &const_(const T &t) { return t; }
+
+void tst_QArrayData::referenceCounting()
+{
+ {
+ // Reference counting initialized to 1 (owned)
+ QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(1) }, 0, 0, 0, 0 };
+
+ QCOMPARE(array.ref.atomic.load(), 1);
+
+ QVERIFY(!array.ref.isStatic());
+ QVERIFY(array.ref.isSharable());
+
+ QVERIFY(array.ref.ref());
+ QCOMPARE(array.ref.atomic.load(), 2);
+
+ QVERIFY(array.ref.deref());
+ QCOMPARE(array.ref.atomic.load(), 1);
+
+ QVERIFY(array.ref.ref());
+ QCOMPARE(array.ref.atomic.load(), 2);
+
+ QVERIFY(array.ref.deref());
+ QCOMPARE(array.ref.atomic.load(), 1);
+
+ QVERIFY(!array.ref.deref());
+ QCOMPARE(array.ref.atomic.load(), 0);
+
+ // Now would be a good time to free/release allocated data
+ }
+
+ {
+ // Reference counting initialized to 0 (non-sharable)
+ QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
+
+ QCOMPARE(array.ref.atomic.load(), 0);
+
+ QVERIFY(!array.ref.isStatic());
+ QVERIFY(!array.ref.isSharable());
+
+ QVERIFY(!array.ref.ref());
+ // Reference counting fails, data should be copied
+ QCOMPARE(array.ref.atomic.load(), 0);
+
+ QVERIFY(!array.ref.deref());
+ QCOMPARE(array.ref.atomic.load(), 0);
+
+ // Free/release data
+ }
+
+ {
+ // Reference counting initialized to -1 (static read-only data)
+ QArrayData array = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
+
+ QCOMPARE(array.ref.atomic.load(), -1);
+
+ QVERIFY(array.ref.isStatic());
+ QVERIFY(array.ref.isSharable());
+
+ QVERIFY(array.ref.ref());
+ QCOMPARE(array.ref.atomic.load(), -1);
+
+ QVERIFY(array.ref.deref());
+ QCOMPARE(array.ref.atomic.load(), -1);
+ }
+}
+
+void tst_QArrayData::sharedNullEmpty()
+{
+ QArrayData *null = const_cast<QArrayData *>(&QArrayData::shared_null);
+ QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0);
+
+ QVERIFY(null->ref.isStatic());
+ QVERIFY(null->ref.isSharable());
+ QVERIFY(null->ref.isShared());
+
+ QVERIFY(empty->ref.isStatic());
+ QVERIFY(empty->ref.isSharable());
+ QVERIFY(empty->ref.isShared());
+
+ QCOMPARE(null->ref.atomic.load(), -1);
+ QCOMPARE(empty->ref.atomic.load(), -1);
+
+ QVERIFY(null->ref.ref());
+ QVERIFY(empty->ref.ref());
+
+ QCOMPARE(null->ref.atomic.load(), -1);
+ QCOMPARE(empty->ref.atomic.load(), -1);
+
+ QVERIFY(null->ref.deref());
+ QVERIFY(empty->ref.deref());
+
+ QCOMPARE(null->ref.atomic.load(), -1);
+ QCOMPARE(empty->ref.atomic.load(), -1);
+
+ QVERIFY(null != empty);
+
+ QCOMPARE(null->size, 0);
+ QCOMPARE(null->alloc, 0u);
+ QCOMPARE(null->capacityReserved, 0u);
+
+ QCOMPARE(empty->size, 0);
+ QCOMPARE(empty->alloc, 0u);
+ QCOMPARE(empty->capacityReserved, 0u);
+}
+
+void tst_QArrayData::staticData()
+{
+ QStaticArrayData<char, 10> charArray = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(char, 10),
+ { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }
+ };
+ QStaticArrayData<int, 10> intArray = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 10),
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
+ };
+ QStaticArrayData<double, 10> doubleArray = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(double, 10),
+ { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f }
+ };
+
+ QCOMPARE(charArray.header.size, 10);
+ QCOMPARE(intArray.header.size, 10);
+ QCOMPARE(doubleArray.header.size, 10);
+
+ QCOMPARE(charArray.header.data(), reinterpret_cast<void *>(&charArray.data));
+ QCOMPARE(intArray.header.data(), reinterpret_cast<void *>(&intArray.data));
+ QCOMPARE(doubleArray.header.data(), reinterpret_cast<void *>(&doubleArray.data));
+}
+
+void tst_QArrayData::simpleVector()
+{
+ QArrayData data0 = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
+ QStaticArrayData<int, 7> data1 = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 7),
+ { 0, 1, 2, 3, 4, 5, 6 }
+ };
+
+ int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ SimpleVector<int> v1;
+ SimpleVector<int> v2(v1);
+ SimpleVector<int> v3(static_cast<QTypedArrayData<int> *>(&data0));
+ SimpleVector<int> v4(static_cast<QTypedArrayData<int> *>(&data1.header));
+ SimpleVector<int> v5(static_cast<QTypedArrayData<int> *>(&data0));
+ SimpleVector<int> v6(static_cast<QTypedArrayData<int> *>(&data1.header));
+ SimpleVector<int> v7(10, 5);
+ SimpleVector<int> v8(array, array + sizeof(array)/sizeof(*array));
+
+ v3 = v1;
+ v1.swap(v3);
+ v4.clear();
+
+ QVERIFY(v1.isNull());
+ QVERIFY(v2.isNull());
+ QVERIFY(v3.isNull());
+ QVERIFY(v4.isNull());
+ QVERIFY(!v5.isNull());
+ QVERIFY(!v6.isNull());
+ QVERIFY(!v7.isNull());
+ QVERIFY(!v8.isNull());
+
+ QVERIFY(v1.isEmpty());
+ QVERIFY(v2.isEmpty());
+ QVERIFY(v3.isEmpty());
+ QVERIFY(v4.isEmpty());
+ QVERIFY(v5.isEmpty());
+ QVERIFY(!v6.isEmpty());
+ QVERIFY(!v7.isEmpty());
+ QVERIFY(!v8.isEmpty());
+
+ QCOMPARE(v1.size(), size_t(0));
+ QCOMPARE(v2.size(), size_t(0));
+ QCOMPARE(v3.size(), size_t(0));
+ QCOMPARE(v4.size(), size_t(0));
+ QCOMPARE(v5.size(), size_t(0));
+ QCOMPARE(v6.size(), size_t(7));
+ QCOMPARE(v7.size(), size_t(10));
+ QCOMPARE(v8.size(), size_t(10));
+
+ QCOMPARE(v1.capacity(), size_t(0));
+ QCOMPARE(v2.capacity(), size_t(0));
+ QCOMPARE(v3.capacity(), size_t(0));
+ QCOMPARE(v4.capacity(), size_t(0));
+ QCOMPARE(v5.capacity(), size_t(0));
+ // v6.capacity() is unspecified, for now
+ QVERIFY(v7.capacity() >= size_t(10));
+ QVERIFY(v8.capacity() >= size_t(10));
+
+ QVERIFY(v1.isStatic());
+ QVERIFY(v2.isStatic());
+ QVERIFY(v3.isStatic());
+ QVERIFY(v4.isStatic());
+ QVERIFY(v5.isStatic());
+ QVERIFY(v6.isStatic());
+ QVERIFY(!v7.isStatic());
+ QVERIFY(!v8.isStatic());
+
+ QVERIFY(v1.isShared());
+ QVERIFY(v2.isShared());
+ QVERIFY(v3.isShared());
+ QVERIFY(v4.isShared());
+ QVERIFY(v5.isShared());
+ QVERIFY(v6.isShared());
+ QVERIFY(!v7.isShared());
+ QVERIFY((SimpleVector<int>(v7), v7.isShared()));
+ QVERIFY(!v7.isShared());
+ QVERIFY(!v8.isShared());
+
+ QVERIFY(v1.isSharable());
+ QVERIFY(v2.isSharable());
+ QVERIFY(v3.isSharable());
+ QVERIFY(v4.isSharable());
+ QVERIFY(v5.isSharable());
+ QVERIFY(v6.isSharable());
+ QVERIFY(v7.isSharable());
+ QVERIFY(v8.isSharable());
+
+ QVERIFY(v1.isSharedWith(v2));
+ QVERIFY(v1.isSharedWith(v3));
+ QVERIFY(v1.isSharedWith(v4));
+ QVERIFY(!v1.isSharedWith(v5));
+ QVERIFY(!v1.isSharedWith(v6));
+
+ QCOMPARE((void *)v1.constBegin(), (void *)v1.constEnd());
+ QCOMPARE((void *)v4.constBegin(), (void *)v4.constEnd());
+ QCOMPARE((void *)(v6.constBegin() + v6.size()), (void *)v6.constEnd());
+ QCOMPARE((void *)(v7.constBegin() + v7.size()), (void *)v7.constEnd());
+ QCOMPARE((void *)(v8.constBegin() + v8.size()), (void *)v8.constEnd());
+
+ QVERIFY(v1 == v2);
+ QVERIFY(v1 == v3);
+ QVERIFY(v1 == v4);
+ QVERIFY(v1 == v5);
+ QVERIFY(!(v1 == v6));
+
+ QVERIFY(v1 != v6);
+ QVERIFY(v4 != v6);
+ QVERIFY(v5 != v6);
+ QVERIFY(!(v1 != v5));
+
+ QVERIFY(v1 < v6);
+ QVERIFY(!(v6 < v1));
+ QVERIFY(v6 > v1);
+ QVERIFY(!(v1 > v6));
+ QVERIFY(v1 <= v6);
+ QVERIFY(!(v6 <= v1));
+ QVERIFY(v6 >= v1);
+ QVERIFY(!(v1 >= v6));
+
+ {
+ SimpleVector<int> temp(v6);
+
+ QCOMPARE(const_(v6).front(), 0);
+ QCOMPARE(const_(v6).back(), 6);
+
+ QVERIFY(temp.isShared());
+ QVERIFY(temp.isSharedWith(v6));
+
+ QCOMPARE(temp.front(), 0);
+ QCOMPARE(temp.back(), 6);
+
+ // Detached
+ QVERIFY(!temp.isShared());
+ const int *const tempBegin = temp.begin();
+
+ for (size_t i = 0; i < v6.size(); ++i) {
+ QCOMPARE(const_(v6)[i], int(i));
+ QCOMPARE(const_(v6).at(i), int(i));
+ QCOMPARE(&const_(v6)[i], &const_(v6).at(i));
+
+ QCOMPARE(const_(v8)[i], const_(v6)[i]);
+
+ QCOMPARE(temp[i], int(i));
+ QCOMPARE(temp.at(i), int(i));
+ QCOMPARE(&temp[i], &temp.at(i));
+ }
+
+ // A single detach should do
+ QCOMPARE(temp.begin(), tempBegin);
+ }
+
+ {
+ int count = 0;
+ Q_FOREACH (int value, v7) {
+ QCOMPARE(value, 5);
+ ++count;
+ }
+
+ QCOMPARE(count, 10);
+ }
+
+ {
+ int count = 0;
+ Q_FOREACH (int value, v8) {
+ QCOMPARE(value, count);
+ ++count;
+ }
+
+ QCOMPARE(count, 10);
+ }
+
+ v5 = v6;
+ QVERIFY(v5.isSharedWith(v6));
+ QVERIFY(!v1.isSharedWith(v5));
+
+ v1.swap(v6);
+ QVERIFY(v6.isNull());
+ QVERIFY(v1.isSharedWith(v5));
+
+ {
+ using std::swap;
+ swap(v1, v6);
+ QVERIFY(v5.isSharedWith(v6));
+ QVERIFY(!v1.isSharedWith(v5));
+ }
+
+ v1.prepend(array, array + sizeof(array)/sizeof(array[0]));
+ QCOMPARE(v1.size(), size_t(10));
+ QVERIFY(v1 == v8);
+
+ v6 = v1;
+ QVERIFY(v1.isSharedWith(v6));
+
+ v1.prepend(array, array + sizeof(array)/sizeof(array[0]));
+ QVERIFY(!v1.isSharedWith(v6));
+ QCOMPARE(v1.size(), size_t(20));
+ QCOMPARE(v6.size(), size_t(10));
+
+ for (int i = 0; i < 20; ++i)
+ QCOMPARE(v1[i], v6[i % 10]);
+
+ v1.clear();
+
+ v1.append(array, array + sizeof(array)/sizeof(array[0]));
+ QCOMPARE(v1.size(), size_t(10));
+ QVERIFY(v1 == v8);
+
+ v6 = v1;
+ QVERIFY(v1.isSharedWith(v6));
+
+ v1.append(array, array + sizeof(array)/sizeof(array[0]));
+ QVERIFY(!v1.isSharedWith(v6));
+ QCOMPARE(v1.size(), size_t(20));
+ QCOMPARE(v6.size(), size_t(10));
+
+ for (int i = 0; i < 20; ++i)
+ QCOMPARE(v1[i], v6[i % 10]);
+
+ v1.insert(0, v6.constBegin(), v6.constEnd());
+ QCOMPARE(v1.size(), size_t(30));
+
+ v6 = v1;
+ QVERIFY(v1.isSharedWith(v6));
+
+ v1.insert(10, v6.constBegin(), v6.constEnd());
+ QVERIFY(!v1.isSharedWith(v6));
+ QCOMPARE(v1.size(), size_t(60));
+ QCOMPARE(v6.size(), size_t(30));
+
+ for (int i = 0; i < 30; ++i)
+ QCOMPARE(v6[i], v8[i % 10]);
+
+ v1.insert(v1.size(), v6.constBegin(), v6.constEnd());
+ QCOMPARE(v1.size(), size_t(90));
+
+ v1.insert(-1, v8.constBegin(), v8.constEnd());
+ QCOMPARE(v1.size(), size_t(100));
+
+ v1.insert(-11, v8.constBegin(), v8.constEnd());
+ QCOMPARE(v1.size(), size_t(110));
+
+ v1.insert(-200, v8.constBegin(), v8.constEnd());
+ QCOMPARE(v1.size(), size_t(120));
+
+ for (int i = 0; i < 120; ++i)
+ QCOMPARE(v1[i], v8[i % 10]);
+
+ {
+ v7.setSharable(true);
+ QVERIFY(v7.isSharable());
+
+ SimpleVector<int> copy1(v7);
+ QVERIFY(copy1.isSharedWith(v7));
+
+ v7.setSharable(false);
+ QVERIFY(!v7.isSharable());
+
+ QVERIFY(!copy1.isSharedWith(v7));
+ QCOMPARE(v7.size(), copy1.size());
+ for (size_t i = 0; i < copy1.size(); ++i)
+ QCOMPARE(v7[i], copy1[i]);
+
+ SimpleVector<int> clone(v7);
+ QVERIFY(!clone.isSharedWith(v7));
+ QCOMPARE(clone.size(), copy1.size());
+ for (size_t i = 0; i < copy1.size(); ++i)
+ QCOMPARE(clone[i], copy1[i]);
+
+ v7.setSharable(true);
+ QVERIFY(v7.isSharable());
+
+ SimpleVector<int> copy2(v7);
+ QVERIFY(copy2.isSharedWith(v7));
+ }
+
+ {
+ SimpleVector<int> null;
+ SimpleVector<int> empty(0, 5);
+
+ QVERIFY(null.isSharable());
+ QVERIFY(empty.isSharable());
+
+ null.setSharable(true);
+ empty.setSharable(true);
+
+ QVERIFY(null.isSharable());
+ QVERIFY(empty.isSharable());
+
+ QVERIFY(null.isEmpty());
+ QVERIFY(empty.isEmpty());
+
+ null.setSharable(false);
+ empty.setSharable(false);
+
+ QVERIFY(!null.isSharable());
+ QVERIFY(!empty.isSharable());
+
+ QVERIFY(null.isEmpty());
+ QVERIFY(empty.isEmpty());
+
+ null.setSharable(true);
+ empty.setSharable(true);
+
+ QVERIFY(null.isSharable());
+ QVERIFY(empty.isSharable());
+
+ QVERIFY(null.isEmpty());
+ QVERIFY(empty.isEmpty());
+ }
+}
+
+Q_DECLARE_METATYPE(SimpleVector<int>)
+
+void tst_QArrayData::simpleVectorReserve_data()
+{
+ QTest::addColumn<SimpleVector<int> >("vector");
+ QTest::addColumn<size_t>("capacity");
+ QTest::addColumn<size_t>("size");
+
+ QTest::newRow("null") << SimpleVector<int>() << size_t(0) << size_t(0);
+ QTest::newRow("empty") << SimpleVector<int>(0, 42) << size_t(0) << size_t(0);
+ QTest::newRow("non-empty") << SimpleVector<int>(5, 42) << size_t(5) << size_t(5);
+
+ static const QStaticArrayData<int, 15> array = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 15),
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } };
+ QArrayDataPointerRef<int> p = {
+ static_cast<QTypedArrayData<int> *>(
+ const_cast<QArrayData *>(&array.header)) };
+
+ QTest::newRow("static") << SimpleVector<int>(p) << size_t(0) << size_t(15);
+ QTest::newRow("raw-data") << SimpleVector<int>::fromRawData(array.data, 15) << size_t(0) << size_t(15);
+}
+
+void tst_QArrayData::simpleVectorReserve()
+{
+ QFETCH(SimpleVector<int>, vector);
+ QFETCH(size_t, capacity);
+ QFETCH(size_t, size);
+
+ QVERIFY(!capacity || capacity >= size);
+
+ QCOMPARE(vector.capacity(), capacity);
+ QCOMPARE(vector.size(), size);
+
+ const SimpleVector<int> copy(vector);
+
+ vector.reserve(0);
+ QCOMPARE(vector.capacity(), capacity);
+ QCOMPARE(vector.size(), size);
+
+ vector.reserve(10);
+
+ // zero-capacity (immutable) resets with detach
+ if (!capacity)
+ capacity = size;
+
+ QCOMPARE(vector.capacity(), qMax(size_t(10), capacity));
+ QCOMPARE(vector.size(), size);
+
+ vector.reserve(20);
+ QCOMPARE(vector.capacity(), size_t(20));
+ QCOMPARE(vector.size(), size);
+
+ vector.reserve(30);
+ QCOMPARE(vector.capacity(), size_t(30));
+ QCOMPARE(vector.size(), size);
+
+ QVERIFY(vector == copy);
+}
+
+struct Deallocator
+{
+ Deallocator(size_t objectSize, size_t alignment)
+ : objectSize(objectSize)
+ , alignment(alignment)
+ {
+ }
+
+ ~Deallocator()
+ {
+ Q_FOREACH (QArrayData *data, headers)
+ QArrayData::deallocate(data, objectSize, alignment);
+ }
+
+ size_t objectSize;
+ size_t alignment;
+ QVector<QArrayData *> headers;
+};
+
+Q_DECLARE_METATYPE(const QArrayData *)
+Q_DECLARE_METATYPE(QArrayData::AllocationOptions)
+
+void tst_QArrayData::allocate_data()
+{
+ QTest::addColumn<size_t>("objectSize");
+ QTest::addColumn<size_t>("alignment");
+ QTest::addColumn<QArrayData::AllocationOptions>("allocateOptions");
+ QTest::addColumn<bool>("isCapacityReserved");
+ QTest::addColumn<bool>("isSharable");
+ QTest::addColumn<const QArrayData *>("commonEmpty");
+
+ struct {
+ char const *typeName;
+ size_t objectSize;
+ size_t alignment;
+ } types[] = {
+ { "char", sizeof(char), Q_ALIGNOF(char) },
+ { "short", sizeof(short), Q_ALIGNOF(short) },
+ { "void *", sizeof(void *), Q_ALIGNOF(void *) }
+ };
+
+ QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0);
+ QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
+
+ QVERIFY(shared_empty);
+ QVERIFY(unsharable_empty);
+
+ struct {
+ char const *description;
+ QArrayData::AllocationOptions allocateOptions;
+ bool isCapacityReserved;
+ bool isSharable;
+ const QArrayData *commonEmpty;
+ } options[] = {
+ { "Default", QArrayData::Default, false, true, shared_empty },
+ { "Reserved", QArrayData::CapacityReserved, true, true, shared_empty },
+ { "Reserved | Unsharable",
+ QArrayData::CapacityReserved | QArrayData::Unsharable, true, false,
+ unsharable_empty },
+ { "Unsharable", QArrayData::Unsharable, false, false, unsharable_empty },
+ { "Grow", QArrayData::Grow, false, true, shared_empty }
+ };
+
+ for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i)
+ for (size_t j = 0; j < sizeof(options)/sizeof(options[0]); ++j)
+ QTest::newRow(qPrintable(
+ QLatin1String(types[i].typeName)
+ + QLatin1String(": ")
+ + QLatin1String(options[j].description)))
+ << types[i].objectSize << types[i].alignment
+ << options[j].allocateOptions << options[j].isCapacityReserved
+ << options[j].isSharable << options[j].commonEmpty;
+}
+
+void tst_QArrayData::allocate()
+{
+ QFETCH(size_t, objectSize);
+ QFETCH(size_t, alignment);
+ QFETCH(QArrayData::AllocationOptions, allocateOptions);
+ QFETCH(bool, isCapacityReserved);
+ QFETCH(bool, isSharable);
+ QFETCH(const QArrayData *, commonEmpty);
+
+ // Minimum alignment that can be requested is that of QArrayData.
+ // Typically, this alignment is sizeof(void *) and ensured by malloc.
+ size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData));
+
+ // Shared Empty
+ QCOMPARE(QArrayData::allocate(objectSize, minAlignment, 0,
+ QArrayData::AllocationOptions(allocateOptions)), commonEmpty);
+
+ Deallocator keeper(objectSize, minAlignment);
+ keeper.headers.reserve(1024);
+
+ for (int capacity = 1; capacity <= 1024; capacity <<= 1) {
+ QArrayData *data = QArrayData::allocate(objectSize, minAlignment,
+ capacity, QArrayData::AllocationOptions(allocateOptions));
+ keeper.headers.append(data);
+
+ QCOMPARE(data->size, 0);
+ if (allocateOptions & QArrayData::Grow)
+ QVERIFY(data->alloc > uint(capacity));
+ else
+ QCOMPARE(data->alloc, uint(capacity));
+ QCOMPARE(data->capacityReserved, uint(isCapacityReserved));
+ QCOMPARE(data->ref.isSharable(), isSharable);
+
+ // Check that the allocated array can be used. Best tested with a
+ // memory checker, such as valgrind, running.
+ ::memset(data->data(), 'A', objectSize * capacity);
+ }
+}
+
+class Unaligned
+{
+ char dummy[8];
+};
+
+void tst_QArrayData::alignment_data()
+{
+ QTest::addColumn<size_t>("alignment");
+
+ for (int i = 1; i < 10; ++i) {
+ size_t alignment = 1u << i;
+ QTest::newRow(qPrintable(QString::number(alignment))) << alignment;
+ }
+}
+
+void tst_QArrayData::alignment()
+{
+ QFETCH(size_t, alignment);
+
+ // Minimum alignment that can be requested is that of QArrayData.
+ // Typically, this alignment is sizeof(void *) and ensured by malloc.
+ size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData));
+
+ Deallocator keeper(sizeof(Unaligned), minAlignment);
+ keeper.headers.reserve(100);
+
+ for (int i = 0; i < 100; ++i) {
+ QArrayData *data = QArrayData::allocate(sizeof(Unaligned),
+ minAlignment, 8, QArrayData::Default);
+ keeper.headers.append(data);
+
+ QVERIFY(data);
+ QCOMPARE(data->size, 0);
+ QVERIFY(data->alloc >= uint(8));
+
+ // These conditions should hold as long as header and array are
+ // allocated together
+ QVERIFY(data->offset >= qptrdiff(sizeof(QArrayData)));
+ QVERIFY(data->offset <= qptrdiff(sizeof(QArrayData)
+ + minAlignment - Q_ALIGNOF(QArrayData)));
+
+ // Data is aligned
+ QCOMPARE(quintptr(data->data()) % alignment, quintptr(0u));
+
+ // Check that the allocated array can be used. Best tested with a
+ // memory checker, such as valgrind, running.
+ ::memset(data->data(), 'A', sizeof(Unaligned) * 8);
+ }
+}
+
+void tst_QArrayData::typedData()
+{
+ QStaticArrayData<int, 10> data = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 10),
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
+ };
+ QCOMPARE(data.header.size, 10);
+
+ {
+ QTypedArrayData<int> *array =
+ static_cast<QTypedArrayData<int> *>(&data.header);
+ QCOMPARE(array->data(), data.data);
+
+ int j = 0;
+ for (QTypedArrayData<int>::iterator iter = array->begin();
+ iter != array->end(); ++iter, ++j)
+ QCOMPARE(iter, data.data + j);
+ QCOMPARE(j, 10);
+ }
+
+ {
+ const QTypedArrayData<int> *array =
+ static_cast<const QTypedArrayData<int> *>(&data.header);
+
+ QCOMPARE(array->data(), data.data);
+
+ int j = 0;
+ for (QTypedArrayData<int>::const_iterator iter = array->begin();
+ iter != array->end(); ++iter, ++j)
+ QCOMPARE(iter, data.data + j);
+ QCOMPARE(j, 10);
+ }
+
+ {
+ QTypedArrayData<int> *null = QTypedArrayData<int>::sharedNull();
+ QTypedArrayData<int> *empty = QTypedArrayData<int>::allocate(0);
+
+ QVERIFY(null != empty);
+
+ QCOMPARE(null->size, 0);
+ QCOMPARE(empty->size, 0);
+
+ QCOMPARE(null->begin(), null->end());
+ QCOMPARE(empty->begin(), empty->end());
+ }
+
+
+ {
+ Deallocator keeper(sizeof(char),
+ Q_ALIGNOF(QTypedArrayData<char>::AlignmentDummy));
+ QArrayData *array = QTypedArrayData<char>::allocate(10);
+ keeper.headers.append(array);
+
+ QVERIFY(array);
+ QCOMPARE(array->size, 0);
+ QCOMPARE(array->alloc, 10u);
+
+ // Check that the allocated array can be used. Best tested with a
+ // memory checker, such as valgrind, running.
+ ::memset(array->data(), 0, 10 * sizeof(char));
+
+ keeper.headers.clear();
+ QTypedArrayData<short>::deallocate(array);
+
+ QVERIFY(true);
+ }
+
+ {
+ Deallocator keeper(sizeof(short),
+ Q_ALIGNOF(QTypedArrayData<short>::AlignmentDummy));
+ QArrayData *array = QTypedArrayData<short>::allocate(10);
+ keeper.headers.append(array);
+
+ QVERIFY(array);
+ QCOMPARE(array->size, 0);
+ QCOMPARE(array->alloc, 10u);
+
+ // Check that the allocated array can be used. Best tested with a
+ // memory checker, such as valgrind, running.
+ ::memset(array->data(), 0, 10 * sizeof(short));
+
+ keeper.headers.clear();
+ QTypedArrayData<short>::deallocate(array);
+
+ QVERIFY(true);
+ }
+
+ {
+ Deallocator keeper(sizeof(double),
+ Q_ALIGNOF(QTypedArrayData<double>::AlignmentDummy));
+ QArrayData *array = QTypedArrayData<double>::allocate(10);
+ keeper.headers.append(array);
+
+ QVERIFY(array);
+ QCOMPARE(array->size, 0);
+ QCOMPARE(array->alloc, 10u);
+
+ // Check that the allocated array can be used. Best tested with a
+ // memory checker, such as valgrind, running.
+ ::memset(array->data(), 0, 10 * sizeof(double));
+
+ keeper.headers.clear();
+ QTypedArrayData<double>::deallocate(array);
+
+ QVERIFY(true);
+ }
+}
+
+void tst_QArrayData::gccBug43247()
+{
+ // This test tries to verify QArrayData is not affected by GCC optimizer
+ // bug #43247.
+ // Reported on GCC 4.4.3, Linux, affects QVector
+
+ QTest::ignoreMessage(QtDebugMsg, "GCC Optimization bug #43247 not triggered (3)");
+ QTest::ignoreMessage(QtDebugMsg, "GCC Optimization bug #43247 not triggered (4)");
+ QTest::ignoreMessage(QtDebugMsg, "GCC Optimization bug #43247 not triggered (5)");
+ QTest::ignoreMessage(QtDebugMsg, "GCC Optimization bug #43247 not triggered (6)");
+ QTest::ignoreMessage(QtDebugMsg, "GCC Optimization bug #43247 not triggered (7)");
+
+ SimpleVector<int> array(10, 0);
+ // QVector<int> vector(10, 0);
+
+ for (int i = 0; i < 10; ++i) {
+ if (i >= 3 && i < 8)
+ qDebug("GCC Optimization bug #43247 not triggered (%i)", i);
+
+ // When access to data is implemented through an array of size 1, this
+ // line lets the compiler assume i == 0, and the conditional above is
+ // skipped.
+ QVERIFY(array.at(i) == 0);
+ // QVERIFY(vector.at(i) == 0);
+ }
+}
+
+struct CountedObject
+{
+ CountedObject()
+ : id(liveCount++)
+ {
+ }
+
+ CountedObject(const CountedObject &other)
+ : id(other.id)
+ {
+ ++liveCount;
+ }
+
+ ~CountedObject()
+ {
+ --liveCount;
+ }
+
+ CountedObject &operator=(const CountedObject &other)
+ {
+ id = other.id;
+ return *this;
+ }
+
+ struct LeakChecker
+ {
+ LeakChecker()
+ : previousLiveCount(liveCount)
+ {
+ }
+
+ ~LeakChecker()
+ {
+ QCOMPARE(liveCount, previousLiveCount);
+ }
+
+ private:
+ const size_t previousLiveCount;
+ };
+
+ size_t id; // not unique
+ static size_t liveCount;
+};
+
+size_t CountedObject::liveCount = 0;
+
+void tst_QArrayData::arrayOps()
+{
+ CountedObject::LeakChecker leakChecker; Q_UNUSED(leakChecker)
+
+ const int intArray[5] = { 80, 101, 100, 114, 111 };
+ const QString stringArray[5] = {
+ QLatin1String("just"),
+ QLatin1String("for"),
+ QLatin1String("testing"),
+ QLatin1String("a"),
+ QLatin1String("vector")
+ };
+ const CountedObject objArray[5];
+
+ QVERIFY(!QTypeInfo<int>::isComplex && !QTypeInfo<int>::isStatic);
+ QVERIFY(QTypeInfo<QString>::isComplex && !QTypeInfo<QString>::isStatic);
+ QVERIFY(QTypeInfo<CountedObject>::isComplex && QTypeInfo<CountedObject>::isStatic);
+
+ QCOMPARE(CountedObject::liveCount, size_t(5));
+ for (size_t i = 0; i < 5; ++i)
+ QCOMPARE(objArray[i].id, i);
+
+ ////////////////////////////////////////////////////////////////////////////
+ // copyAppend (I)
+ SimpleVector<int> vi(intArray, intArray + 5);
+ SimpleVector<QString> vs(stringArray, stringArray + 5);
+ SimpleVector<CountedObject> vo(objArray, objArray + 5);
+
+ QCOMPARE(CountedObject::liveCount, size_t(10));
+ for (int i = 0; i < 5; ++i) {
+ QCOMPARE(vi[i], intArray[i]);
+ QVERIFY(vs[i].isSharedWith(stringArray[i]));
+ QCOMPARE(vo[i].id, objArray[i].id);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // destroyAll
+ vi.clear();
+ vs.clear();
+ vo.clear();
+
+ QCOMPARE(CountedObject::liveCount, size_t(5));
+
+ ////////////////////////////////////////////////////////////////////////////
+ // copyAppend (II)
+ int referenceInt = 7;
+ QString referenceString = QLatin1String("reference");
+ CountedObject referenceObject;
+
+ vi = SimpleVector<int>(5, referenceInt);
+ vs = SimpleVector<QString>(5, referenceString);
+ vo = SimpleVector<CountedObject>(5, referenceObject);
+
+ QCOMPARE(vi.size(), size_t(5));
+ QCOMPARE(vs.size(), size_t(5));
+ QCOMPARE(vo.size(), size_t(5));
+
+ QCOMPARE(CountedObject::liveCount, size_t(11));
+ for (int i = 0; i < 5; ++i) {
+ QCOMPARE(vi[i], referenceInt);
+ QVERIFY(vs[i].isSharedWith(referenceString));
+ QCOMPARE(vo[i].id, referenceObject.id);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // insert
+ vi.reserve(30);
+ vs.reserve(30);
+ vo.reserve(30);
+
+ QCOMPARE(vi.size(), size_t(5));
+ QCOMPARE(vs.size(), size_t(5));
+ QCOMPARE(vo.size(), size_t(5));
+
+ QVERIFY(vi.capacity() >= 30);
+ QVERIFY(vs.capacity() >= 30);
+ QVERIFY(vo.capacity() >= 30);
+
+ // Displace as many elements as array is extended by
+ vi.insert(0, intArray, intArray + 5);
+ vs.insert(0, stringArray, stringArray + 5);
+ vo.insert(0, objArray, objArray + 5);
+
+ QCOMPARE(vi.size(), size_t(10));
+ QCOMPARE(vs.size(), size_t(10));
+ QCOMPARE(vo.size(), size_t(10));
+
+ // Displace more elements than array is extended by
+ vi.insert(0, intArray, intArray + 5);
+ vs.insert(0, stringArray, stringArray + 5);
+ vo.insert(0, objArray, objArray + 5);
+
+ QCOMPARE(vi.size(), size_t(15));
+ QCOMPARE(vs.size(), size_t(15));
+ QCOMPARE(vo.size(), size_t(15));
+
+ // Displace less elements than array is extended by
+ vi.insert(5, vi.constBegin(), vi.constEnd());
+ vs.insert(5, vs.constBegin(), vs.constEnd());
+ vo.insert(5, vo.constBegin(), vo.constEnd());
+
+ QCOMPARE(vi.size(), size_t(30));
+ QCOMPARE(vs.size(), size_t(30));
+ QCOMPARE(vo.size(), size_t(30));
+
+ QCOMPARE(CountedObject::liveCount, size_t(36));
+ for (int i = 0; i < 15; ++i) {
+ QCOMPARE(vi[i], intArray[i % 5]);
+ QVERIFY(vs[i].isSharedWith(stringArray[i % 5]));
+ QCOMPARE(vo[i].id, objArray[i % 5].id);
+ }
+
+ for (int i = 15; i < 20; ++i) {
+ QCOMPARE(vi[i], referenceInt);
+ QVERIFY(vs[i].isSharedWith(referenceString));
+ QCOMPARE(vo[i].id, referenceObject.id);
+ }
+
+ for (int i = 20; i < 25; ++i) {
+ QCOMPARE(vi[i], intArray[i % 5]);
+ QVERIFY(vs[i].isSharedWith(stringArray[i % 5]));
+ QCOMPARE(vo[i].id, objArray[i % 5].id);
+ }
+
+ for (int i = 25; i < 30; ++i) {
+ QCOMPARE(vi[i], referenceInt);
+ QVERIFY(vs[i].isSharedWith(referenceString));
+ QCOMPARE(vo[i].id, referenceObject.id);
+ }
+}
+
+Q_DECLARE_METATYPE(QArrayDataPointer<int>)
+
+static inline bool arrayIsFilledWith(const QArrayDataPointer<int> &array,
+ int fillValue, size_t size)
+{
+ const int *iter = array->begin();
+ const int *const end = array->end();
+
+ for (size_t i = 0; i < size; ++i, ++iter)
+ if (*iter != fillValue)
+ return false;
+
+ if (iter != end)
+ return false;
+
+ return true;
+}
+
+void tst_QArrayData::setSharable_data()
+{
+ QTest::addColumn<QArrayDataPointer<int> >("array");
+ QTest::addColumn<size_t>("size");
+ QTest::addColumn<size_t>("capacity");
+ QTest::addColumn<bool>("isCapacityReserved");
+ QTest::addColumn<int>("fillValue");
+
+ QArrayDataPointer<int> null;
+ QArrayDataPointer<int> empty; empty.clear();
+
+ static QStaticArrayData<int, 10> staticArrayData = {
+ Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 10),
+ { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
+ };
+
+ QArrayDataPointer<int> emptyReserved(QTypedArrayData<int>::allocate(5,
+ QArrayData::CapacityReserved));
+ QArrayDataPointer<int> nonEmpty(QTypedArrayData<int>::allocate(10,
+ QArrayData::Default));
+ QArrayDataPointer<int> nonEmptyReserved(QTypedArrayData<int>::allocate(15,
+ QArrayData::CapacityReserved));
+ QArrayDataPointer<int> staticArray(
+ static_cast<QTypedArrayData<int> *>(&staticArrayData.header));
+ QArrayDataPointer<int> rawData(
+ QTypedArrayData<int>::fromRawData(staticArrayData.data, 10));
+
+ nonEmpty->copyAppend(5, 1);
+ nonEmptyReserved->copyAppend(7, 2);
+
+ QTest::newRow("shared-null") << null << size_t(0) << size_t(0) << false << 0;
+ QTest::newRow("shared-empty") << empty << size_t(0) << size_t(0) << false << 0;
+ // unsharable-empty implicitly tested in shared-empty
+ QTest::newRow("empty-reserved") << emptyReserved << size_t(0) << size_t(5) << true << 0;
+ QTest::newRow("non-empty") << nonEmpty << size_t(5) << size_t(10) << false << 1;
+ QTest::newRow("non-empty-reserved") << nonEmptyReserved << size_t(7) << size_t(15) << true << 2;
+ QTest::newRow("static-array") << staticArray << size_t(10) << size_t(0) << false << 3;
+ QTest::newRow("raw-data") << rawData << size_t(10) << size_t(0) << false << 3;
+}
+
+void tst_QArrayData::setSharable()
+{
+ QFETCH(QArrayDataPointer<int>, array);
+ QFETCH(size_t, size);
+ QFETCH(size_t, capacity);
+ QFETCH(bool, isCapacityReserved);
+ QFETCH(int, fillValue);
+
+ QVERIFY(array->ref.isShared()); // QTest has a copy
+ QVERIFY(array->ref.isSharable());
+
+ QCOMPARE(size_t(array->size), size);
+ QCOMPARE(size_t(array->alloc), capacity);
+ QCOMPARE(bool(array->capacityReserved), isCapacityReserved);
+ QVERIFY(arrayIsFilledWith(array, fillValue, size));
+
+ // shared-null becomes shared-empty, may otherwise detach
+ array.setSharable(true);
+
+ QVERIFY(array->ref.isSharable());
+ QVERIFY(arrayIsFilledWith(array, fillValue, size));
+
+ {
+ QArrayDataPointer<int> copy(array);
+ QVERIFY(array->ref.isShared());
+ QVERIFY(array->ref.isSharable());
+ QCOMPARE(copy.data(), array.data());
+ }
+
+ // Unshare, must detach
+ array.setSharable(false);
+
+ // Immutability (alloc == 0) is lost on detach
+ if (capacity == 0 && size != 0)
+ capacity = size;
+
+ QVERIFY(!array->ref.isShared());
+ QVERIFY(!array->ref.isSharable());
+
+ QCOMPARE(size_t(array->size), size);
+ QCOMPARE(size_t(array->alloc), capacity);
+ QCOMPARE(bool(array->capacityReserved), isCapacityReserved);
+ QVERIFY(arrayIsFilledWith(array, fillValue, size));
+
+ {
+ QArrayDataPointer<int> copy(array);
+ QVERIFY(!array->ref.isShared());
+ QVERIFY(!array->ref.isSharable());
+
+ // Null/empty is always shared
+ QCOMPARE(copy->ref.isShared(), !(size || isCapacityReserved));
+ QVERIFY(copy->ref.isSharable());
+
+ QCOMPARE(size_t(copy->size), size);
+ QCOMPARE(size_t(copy->alloc), capacity);
+ QCOMPARE(bool(copy->capacityReserved), isCapacityReserved);
+ QVERIFY(arrayIsFilledWith(copy, fillValue, size));
+ }
+
+ // Make sharable, again
+ array.setSharable(true);
+
+ QCOMPARE(array->ref.isShared(), !(size || isCapacityReserved));
+ QVERIFY(array->ref.isSharable());
+
+ QCOMPARE(size_t(array->size), size);
+ QCOMPARE(size_t(array->alloc), capacity);
+ QCOMPARE(bool(array->capacityReserved), isCapacityReserved);
+ QVERIFY(arrayIsFilledWith(array, fillValue, size));
+
+ {
+ QArrayDataPointer<int> copy(array);
+ QVERIFY(array->ref.isShared());
+ QCOMPARE(copy.data(), array.data());
+ }
+
+ QCOMPARE(array->ref.isShared(), !(size || isCapacityReserved));
+ QVERIFY(array->ref.isSharable());
+}
+
+void tst_QArrayData::fromRawData()
+{
+ static const int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+
+ {
+ // Default: Immutable, sharable
+ SimpleVector<int> raw = SimpleVector<int>::fromRawData(array,
+ sizeof(array)/sizeof(array[0]), QArrayData::Default);
+
+ QCOMPARE(raw.size(), size_t(11));
+ QCOMPARE(raw.constBegin(), array);
+ QCOMPARE((void *)raw.constEnd(), (void *)(array + sizeof(array)/sizeof(array[0])));
+
+ QVERIFY(!raw.isShared());
+ QVERIFY(SimpleVector<int>(raw).isSharedWith(raw));
+ QVERIFY(!raw.isShared());
+
+ // Detach
+ QCOMPARE(raw.back(), 11);
+ QVERIFY(raw.constBegin() != array);
+ }
+
+ {
+ // Immutable, unsharable
+ SimpleVector<int> raw = SimpleVector<int>::fromRawData(array,
+ sizeof(array)/sizeof(array[0]), QArrayData::Unsharable);
+
+ QCOMPARE(raw.size(), size_t(11));
+ QCOMPARE(raw.constBegin(), array);
+ QCOMPARE((void *)raw.constEnd(), (void *)(array + sizeof(array)/sizeof(array[0])));
+
+ SimpleVector<int> copy(raw);
+ QVERIFY(!copy.isSharedWith(raw));
+ QVERIFY(!raw.isShared());
+
+ QCOMPARE(copy.size(), size_t(11));
+
+ for (size_t i = 0; i < 11; ++i)
+ QCOMPARE(const_(copy)[i], const_(raw)[i]);
+
+ QCOMPARE(raw.size(), size_t(11));
+ QCOMPARE(raw.constBegin(), array);
+ QCOMPARE((void *)raw.constEnd(), (void *)(array + sizeof(array)/sizeof(array[0])));
+
+ // Detach
+ QCOMPARE(raw.back(), 11);
+ QVERIFY(raw.constBegin() != array);
+ }
+}
+
+void tst_QArrayData::literals()
+{
+ {
+ QArrayDataPointer<char> d = Q_ARRAY_LITERAL(char, "ABCDEFGHIJ");
+ QCOMPARE(d->size, 10 + 1);
+ for (int i = 0; i < 10; ++i)
+ QCOMPARE(d->data()[i], char('A' + i));
+ }
+
+ {
+ // wchar_t is not necessarily 2-bytes
+ QArrayDataPointer<wchar_t> d = Q_ARRAY_LITERAL(wchar_t, L"ABCDEFGHIJ");
+ QCOMPARE(d->size, 10 + 1);
+ for (int i = 0; i < 10; ++i)
+ QCOMPARE(d->data()[i], wchar_t('A' + i));
+ }
+
+ {
+ SimpleVector<char> v = Q_ARRAY_LITERAL(char, "ABCDEFGHIJ");
+
+ QVERIFY(!v.isNull());
+ QVERIFY(!v.isEmpty());
+ QCOMPARE(v.size(), size_t(11));
+ // v.capacity() is unspecified, for now
+
+#if defined(Q_COMPILER_VARIADIC_MACROS) \
+ && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+ QVERIFY(v.isStatic());
+#endif
+
+ QVERIFY(v.isSharable());
+ QCOMPARE((void *)(v.constBegin() + v.size()), (void *)v.constEnd());
+
+ for (int i = 0; i < 10; ++i)
+ QCOMPARE(const_(v)[i], char('A' + i));
+ QCOMPARE(const_(v)[10], char('\0'));
+ }
+}
+
+void tst_QArrayData::variadicLiterals()
+{
+#if defined(Q_COMPILER_VARIADIC_MACROS) \
+ && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+ {
+ QArrayDataPointer<int> d =
+ Q_ARRAY_LITERAL(int, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ QCOMPARE(d->size, 10);
+ for (int i = 0; i < 10; ++i)
+ QCOMPARE(d->data()[i], i);
+ }
+
+ {
+ QArrayDataPointer<char> d = Q_ARRAY_LITERAL(char,
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
+ QCOMPARE(d->size, 10);
+ for (int i = 0; i < 10; ++i)
+ QCOMPARE(d->data()[i], char('A' + i));
+ }
+
+ {
+ QArrayDataPointer<const char *> d = Q_ARRAY_LITERAL(const char *,
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
+ QCOMPARE(d->size, 10);
+ for (int i = 0; i < 10; ++i) {
+ QCOMPARE(d->data()[i][0], char('A' + i));
+ QCOMPARE(d->data()[i][1], '\0');
+ }
+ }
+
+ {
+ SimpleVector<int> v = Q_ARRAY_LITERAL(int, 0, 1, 2, 3, 4, 5, 6);
+
+ QVERIFY(!v.isNull());
+ QVERIFY(!v.isEmpty());
+ QCOMPARE(v.size(), size_t(7));
+ // v.capacity() is unspecified, for now
+
+ QVERIFY(v.isStatic());
+
+ QVERIFY(v.isSharable());
+ QCOMPARE((void *)(v.constBegin() + v.size()), (void *)v.constEnd());
+
+ for (int i = 0; i < 7; ++i)
+ QCOMPARE(const_(v)[i], i);
+ }
+#else
+ QSKIP("Variadic Q_ARRAY_LITERAL not available in current configuration.");
+#endif // defined(Q_COMPILER_VARIADIC_MACROS)
+}
+
+#ifdef Q_COMPILER_RVALUE_REFS
+// std::remove_reference is in C++11, but requires library support
+template <class T> struct RemoveReference { typedef T Type; };
+template <class T> struct RemoveReference<T &> { typedef T Type; };
+
+// single-argument std::move is in C++11, but requires library support
+template <class T>
+typename RemoveReference<T>::Type &&cxx11Move(T &&t)
+{
+ return static_cast<typename RemoveReference<T>::Type &&>(t);
+}
+
+struct CompilerHasCxx11ImplicitMoves
+{
+ static bool value()
+ {
+ DetectImplicitMove d(cxx11Move(DetectImplicitMove()));
+ return d.constructor == DetectConstructor::MoveConstructor;
+ }
+
+ struct DetectConstructor
+ {
+ Q_DECL_CONSTEXPR DetectConstructor()
+ : constructor(DefaultConstructor)
+ {
+ }
+
+ Q_DECL_CONSTEXPR DetectConstructor(const DetectConstructor &)
+ : constructor(CopyConstructor)
+ {
+ }
+
+ Q_DECL_CONSTEXPR DetectConstructor(DetectConstructor &&)
+ : constructor(MoveConstructor)
+ {
+ }
+
+ enum Constructor {
+ DefaultConstructor,
+ CopyConstructor,
+ MoveConstructor
+ };
+
+ Constructor constructor;
+ };
+
+ struct DetectImplicitMove
+ : DetectConstructor
+ {
+ };
+};
+#endif
+
+void tst_QArrayData::rValueReferences()
+{
+#ifdef Q_COMPILER_RVALUE_REFS
+ if (!CompilerHasCxx11ImplicitMoves::value())
+ QSKIP("Implicit move ctor not supported in current configuration");
+
+ SimpleVector<int> v1(1, 42);
+ SimpleVector<int> v2;
+
+ const SimpleVector<int>::const_iterator begin = v1.constBegin();
+
+ QVERIFY(!v1.isNull());
+ QVERIFY(v2.isNull());
+
+ // move-assign
+ v2 = cxx11Move(v1);
+
+ QVERIFY(v1.isNull());
+ QVERIFY(!v2.isNull());
+ QCOMPARE(v2.constBegin(), begin);
+
+ SimpleVector<int> v3(cxx11Move(v2));
+
+ QVERIFY(v1.isNull());
+ QVERIFY(v2.isNull());
+ QVERIFY(!v3.isNull());
+ QCOMPARE(v3.constBegin(), begin);
+
+ QCOMPARE(v3.size(), size_t(1));
+ QCOMPARE(v3.front(), 42);
+#else
+ QSKIP("RValue references are not supported in current configuration");
+#endif
+}
+
+void tst_QArrayData::grow()
+{
+ SimpleVector<int> vector;
+
+ QCOMPARE(vector.size(), size_t(0));
+
+ size_t previousCapacity = vector.capacity();
+ size_t allocations = 0;
+ for (size_t i = 1; i <= (1 << 20); ++i) {
+ int source[1] = { int(i) };
+ vector.append(source, source + 1);
+ QCOMPARE(vector.size(), i);
+ if (vector.capacity() != previousCapacity) {
+ previousCapacity = vector.capacity();
+ ++allocations;
+ }
+ }
+ QCOMPARE(vector.size(), size_t(1 << 20));
+
+ // QArrayData::Grow prevents excessive allocations on a growing container
+ QVERIFY(allocations > 20 / 2);
+ QVERIFY(allocations < 20 * 2);
+
+ for (size_t i = 0; i < (1 << 20); ++i)
+ QCOMPARE(const_(vector).at(i), int(i + 1));
+}
+
+QTEST_APPLESS_MAIN(tst_QArrayData)
+#include "tst_qarraydata.moc"
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index 5e53683abd..13a6b3d471 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -1078,18 +1078,25 @@ void tst_QByteArray::toULongLong()
// global function defined in qbytearray.cpp
void tst_QByteArray::qAllocMore()
{
- static const int t[] = {
- INT_MIN, INT_MIN + 1, -1234567, -66000, -1025,
- -3, -1, 0, +1, +3, +1025, +66000, +1234567, INT_MAX - 1, INT_MAX,
- INT_MAX/3
- };
- static const int N = sizeof(t)/sizeof(t[0]);
-
- // make sure qAllocMore() doesn't loop infinitely on any input
- for (int i = 0; i < N; ++i) {
- for (int j = 0; j < N; ++j) {
- ::qAllocMore(t[i], t[j]);
- }
+ using QT_PREPEND_NAMESPACE(qAllocMore);
+
+ // Not very important, but please behave :-)
+ QVERIFY(qAllocMore(0, 0) >= 0);
+
+ for (int i = 1; i < 1 << 8; i <<= 1)
+ QVERIFY(qAllocMore(i, 0) >= i);
+
+ for (int i = 1 << 8; i < 1 << 30; i <<= 1) {
+ const int alloc = qAllocMore(i, 0);
+
+ QVERIFY(alloc >= i);
+ QCOMPARE(qAllocMore(i - 8, 8), alloc - 8);
+ QCOMPARE(qAllocMore(i - 16, 16), alloc - 16);
+ QCOMPARE(qAllocMore(i - 24, 24), alloc - 24);
+ QCOMPARE(qAllocMore(i - 32, 32), alloc - 32);
+
+ QVERIFY(qAllocMore(i - 1, 0) >= i - 1);
+ QVERIFY(qAllocMore(i + 1, 0) >= i + 1);
}
}
@@ -1587,8 +1594,8 @@ void tst_QByteArray::literals()
QVERIFY(str.length() == 4);
QVERIFY(str == "abcd");
- QVERIFY(str.data_ptr()->ref == -1);
- QVERIFY(str.data_ptr()->offset == 0);
+ QVERIFY(str.data_ptr()->ref.isStatic());
+ QVERIFY(str.data_ptr()->offset == sizeof(QByteArrayData));
const char *s = str.constData();
QByteArray str2 = str;
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
index 934130d3ee..c883c1c5f6 100644
--- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp
+++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
@@ -48,6 +48,9 @@ class tst_QList : public QObject
Q_OBJECT
private slots:
+ void init();
+ void cleanup();
+
void length() const;
void lengthSignature() const;
void append() const;
@@ -84,8 +87,100 @@ private slots:
void initializeList() const;
void const_shared_null() const;
+ void setSharable1_data() const;
+ void setSharable1() const;
+ void setSharable2_data() const;
+ void setSharable2() const;
+
+private:
+ int dummyForGuard;
+};
+
+struct Complex
+{
+ Complex(int val)
+ : value(val)
+ , checkSum(this)
+ {
+ ++liveCount;
+ }
+
+ Complex(Complex const &other)
+ : value(other.value)
+ , checkSum(this)
+ {
+ ++liveCount;
+ }
+
+ Complex &operator=(Complex const &other)
+ {
+ check(); other.check();
+
+ value = other.value;
+ return *this;
+ }
+
+ ~Complex()
+ {
+ --liveCount;
+ check();
+ }
+
+ operator int() const { return value; }
+
+ bool operator==(Complex const &other) const
+ {
+ check(); other.check();
+ return value == other.value;
+ }
+
+ bool check() const
+ {
+ if (this != checkSum) {
+ ++errorCount;
+ return false;
+ }
+ return true;
+ }
+
+ struct Guard
+ {
+ Guard() : initialLiveCount(liveCount) {}
+ ~Guard() { if (liveCount != initialLiveCount) ++errorCount; }
+
+ private:
+ Q_DISABLE_COPY(Guard);
+ int initialLiveCount;
+ };
+
+ static void resetErrors() { errorCount = 0; }
+ static int errors() { return errorCount; }
+
+private:
+ static int errorCount;
+ static int liveCount;
+
+ int value;
+ void *checkSum;
};
+int Complex::errorCount = 0;
+int Complex::liveCount = 0;
+
+void tst_QList::init()
+{
+ Complex::resetErrors();
+ new (&dummyForGuard) Complex::Guard();
+}
+
+void tst_QList::cleanup()
+{
+ QCOMPARE(Complex::errors(), 0);
+
+ reinterpret_cast<Complex::Guard *>(&dummyForGuard)->~Guard();
+ QCOMPARE(Complex::errors(), 0);
+}
+
void tst_QList::length() const
{
/* Empty list. */
@@ -690,5 +785,82 @@ void tst_QList::const_shared_null() const
QVERIFY(!list2.isDetached());
}
+Q_DECLARE_METATYPE(QList<int>);
+Q_DECLARE_METATYPE(QList<Complex>);
+
+template <class T>
+void generateSetSharableData()
+{
+ QTest::addColumn<QList<T> >("list");
+ QTest::addColumn<int>("size");
+
+ QTest::newRow("null") << QList<T>() << 0;
+ QTest::newRow("non-empty") << (QList<T>() << T(0) << T(1) << T(2) << T(3) << T(4)) << 5;
+}
+
+template <class T>
+void runSetSharableTest()
+{
+ QFETCH(QList<T>, list);
+ QFETCH(int, size);
+
+ QVERIFY(!list.isDetached()); // Shared with QTest
+
+ list.setSharable(true);
+
+ QCOMPARE(list.size(), size);
+
+ {
+ QList<T> copy(list);
+ QVERIFY(!copy.isDetached());
+ QVERIFY(copy.isSharedWith(list));
+ }
+
+ list.setSharable(false);
+ QVERIFY(list.isDetached() || list.isSharedWith(QList<T>()));
+
+ {
+ QList<T> copy(list);
+
+ QVERIFY(copy.isDetached() || copy.isSharedWith(QList<T>()));
+ QCOMPARE(copy.size(), size);
+ QCOMPARE(copy, list);
+ }
+
+ list.setSharable(true);
+
+ {
+ QList<T> copy(list);
+
+ QVERIFY(!copy.isDetached());
+ QVERIFY(copy.isSharedWith(list));
+ }
+
+ for (int i = 0; i < list.size(); ++i)
+ QCOMPARE(int(list[i]), i);
+
+ QCOMPARE(list.size(), size);
+}
+
+void tst_QList::setSharable1_data() const
+{
+ generateSetSharableData<int>();
+}
+
+void tst_QList::setSharable2_data() const
+{
+ generateSetSharableData<Complex>();
+}
+
+void tst_QList::setSharable1() const
+{
+ runSetSharableTest<int>();
+}
+
+void tst_QList::setSharable2() const
+{
+ runSetSharableTest<Complex>();
+}
+
QTEST_APPLESS_MAIN(tst_QList)
#include "tst_qlist.moc"
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index f007d44262..7d4a9b5aba 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -41,6 +41,7 @@
#include <QtTest/QtTest>
#include <qregexp.h>
+#include <qregularexpression.h>
#include <qtextcodec.h>
#include <qtextstream.h>
#include <qstringlist.h>
@@ -194,6 +195,7 @@ private slots:
void localeAwareCompare();
void split_data();
void split();
+ void split_regexp_data();
void split_regexp();
void fromUtf16_data();
void fromUtf16();
@@ -1080,6 +1082,17 @@ void tst_QString::indexOf()
QCOMPARE( rx2.matchedLength(), -1 );
}
+ {
+ QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
+ if (!bcs)
+ options |= QRegularExpression::CaseInsensitiveOption;
+
+ QRegularExpression re(QRegularExpression::escape(needle), options);
+ QEXPECT_FAIL("data58", "QRegularExpression does not support case folding", Continue);
+ QEXPECT_FAIL("data59", "QRegularExpression does not support case folding", Continue);
+ QCOMPARE( haystack.indexOf(re, startpos), resultpos );
+ }
+
if (cs == Qt::CaseSensitive) {
QCOMPARE( haystack.indexOf(needle, startpos), resultpos );
QCOMPARE( haystack.indexOf(ref, startpos), resultpos );
@@ -1267,6 +1280,15 @@ void tst_QString::lastIndexOf()
QCOMPARE(rx1.matchedLength(), -1);
QCOMPARE(rx2.matchedLength(), -1);
}
+
+ {
+ QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
+ if (!caseSensitive)
+ options |= QRegularExpression::CaseInsensitiveOption;
+
+ QRegularExpression re(QRegularExpression::escape(needle), options);
+ QCOMPARE(haystack.lastIndexOf(re, from), expected);
+ }
}
if (cs == Qt::CaseSensitive) {
@@ -1302,6 +1324,9 @@ void tst_QString::count()
QCOMPARE(a.count( "", Qt::CaseInsensitive), 16);
QCOMPARE(a.count(QRegExp("[FG][HI]")),1);
QCOMPARE(a.count(QRegExp("[G][HE]")),2);
+ QCOMPARE(a.count(QRegularExpression("[FG][HI]")), 1);
+ QCOMPARE(a.count(QRegularExpression("[G][HE]")), 2);
+
CREATE_REF(QLatin1String("FG"));
QCOMPARE(a.count(ref),2);
@@ -1327,6 +1352,8 @@ void tst_QString::contains()
QVERIFY(a.contains( "", Qt::CaseInsensitive));
QVERIFY(a.contains(QRegExp("[FG][HI]")));
QVERIFY(a.contains(QRegExp("[G][HE]")));
+ QVERIFY(a.contains(QRegularExpression("[FG][HI]")));
+ QVERIFY(a.contains(QRegularExpression("[G][HE]")));
CREATE_REF(QLatin1String("FG"));
QVERIFY(a.contains(ref));
@@ -1421,16 +1448,69 @@ void tst_QString::mid()
QVERIFY(a.mid(9999).isNull());
QVERIFY(a.mid(9999,1).isNull());
+ QCOMPARE(a.mid(-1, 6), a.mid(0, 5));
+ QVERIFY(a.mid(-100, 6).isEmpty());
+ QVERIFY(a.mid(INT_MIN, 0).isEmpty());
+ QCOMPARE(a.mid(INT_MIN, -1), a);
+ QVERIFY(a.mid(INT_MIN, INT_MAX).isNull());
+ QVERIFY(a.mid(INT_MIN + 1, INT_MAX).isEmpty());
+ QCOMPARE(a.mid(INT_MIN + 2, INT_MAX), a.left(1));
+ QCOMPARE(a.mid(INT_MIN + a.size() + 1, INT_MAX), a);
+ QVERIFY(a.mid(INT_MAX).isNull());
+ QVERIFY(a.mid(INT_MAX, INT_MAX).isNull());
+ QCOMPARE(a.mid(-5, INT_MAX), a);
+ QCOMPARE(a.mid(-1, INT_MAX), a);
+ QCOMPARE(a.mid(0, INT_MAX), a);
+ QCOMPARE(a.mid(1, INT_MAX), QString("BCDEFGHIEfGEFG"));
+ QCOMPARE(a.mid(5, INT_MAX), QString("FGHIEfGEFG"));
+ QVERIFY(a.mid(20, INT_MAX).isNull());
+ QCOMPARE(a.mid(-1, -1), a);
+
QString n;
QVERIFY(n.mid(3,3).isNull());
QVERIFY(n.mid(0,0).isNull());
QVERIFY(n.mid(9999,0).isNull());
QVERIFY(n.mid(9999,1).isNull());
+ QVERIFY(n.mid(-1, 6).isNull());
+ QVERIFY(n.mid(-100, 6).isNull());
+ QVERIFY(n.mid(INT_MIN, 0).isNull());
+ QVERIFY(n.mid(INT_MIN, -1).isNull());
+ QVERIFY(n.mid(INT_MIN, INT_MAX).isNull());
+ QVERIFY(n.mid(INT_MIN + 1, INT_MAX).isNull());
+ QVERIFY(n.mid(INT_MIN + 2, INT_MAX).isNull());
+ QVERIFY(n.mid(INT_MIN + n.size() + 1, INT_MAX).isNull());
+ QVERIFY(n.mid(INT_MAX).isNull());
+ QVERIFY(n.mid(INT_MAX, INT_MAX).isNull());
+ QVERIFY(n.mid(-5, INT_MAX).isNull());
+ QVERIFY(n.mid(-1, INT_MAX).isNull());
+ QVERIFY(n.mid(0, INT_MAX).isNull());
+ QVERIFY(n.mid(1, INT_MAX).isNull());
+ QVERIFY(n.mid(5, INT_MAX).isNull());
+ QVERIFY(n.mid(20, INT_MAX).isNull());
+ QVERIFY(n.mid(-1, -1).isNull());
+
QString x = "Nine pineapples";
QCOMPARE(x.mid(5, 4), QString("pine"));
QCOMPARE(x.mid(5), QString("pineapples"));
+ QCOMPARE(x.mid(-1, 6), x.mid(0, 5));
+ QVERIFY(x.mid(-100, 6).isEmpty());
+ QVERIFY(x.mid(INT_MIN, 0).isEmpty());
+ QCOMPARE(x.mid(INT_MIN, -1), x);
+ QVERIFY(x.mid(INT_MIN, INT_MAX).isNull());
+ QVERIFY(x.mid(INT_MIN + 1, INT_MAX).isEmpty());
+ QCOMPARE(x.mid(INT_MIN + 2, INT_MAX), x.left(1));
+ QCOMPARE(x.mid(INT_MIN + x.size() + 1, INT_MAX), x);
+ QVERIFY(x.mid(INT_MAX).isNull());
+ QVERIFY(x.mid(INT_MAX, INT_MAX).isNull());
+ QCOMPARE(x.mid(-5, INT_MAX), x);
+ QCOMPARE(x.mid(-1, INT_MAX), x);
+ QCOMPARE(x.mid(0, INT_MAX), x);
+ QCOMPARE(x.mid(1, INT_MAX), QString("ine pineapples"));
+ QCOMPARE(x.mid(5, INT_MAX), QString("pineapples"));
+ QVERIFY(x.mid(20, INT_MAX).isNull());
+ QCOMPARE(x.mid(-1, -1), x);
}
void tst_QString::midRef()
@@ -1447,16 +1527,69 @@ void tst_QString::midRef()
QVERIFY(a.midRef(9999).toString().isEmpty());
QVERIFY(a.midRef(9999,1).toString().isEmpty());
+ QCOMPARE(a.midRef(-1, 6), a.midRef(0, 5));
+ QVERIFY(a.midRef(-100, 6).isEmpty());
+ QVERIFY(a.midRef(INT_MIN, 0).isEmpty());
+ QCOMPARE(a.midRef(INT_MIN, -1).toString(), a);
+ QVERIFY(a.midRef(INT_MIN, INT_MAX).isNull());
+ QVERIFY(a.midRef(INT_MIN + 1, INT_MAX).isEmpty());
+ QCOMPARE(a.midRef(INT_MIN + 2, INT_MAX), a.leftRef(1));
+ QCOMPARE(a.midRef(INT_MIN + a.size() + 1, INT_MAX).toString(), a);
+ QVERIFY(a.midRef(INT_MAX).isNull());
+ QVERIFY(a.midRef(INT_MAX, INT_MAX).isNull());
+ QCOMPARE(a.midRef(-5, INT_MAX).toString(), a);
+ QCOMPARE(a.midRef(-1, INT_MAX).toString(), a);
+ QCOMPARE(a.midRef(0, INT_MAX).toString(), a);
+ QCOMPARE(a.midRef(1, INT_MAX).toString(), QString("BCDEFGHIEfGEFG"));
+ QCOMPARE(a.midRef(5, INT_MAX).toString(), QString("FGHIEfGEFG"));
+ QVERIFY(a.midRef(20, INT_MAX).isNull());
+ QCOMPARE(a.midRef(-1, -1).toString(), a);
+
QString n;
QVERIFY(n.midRef(3,3).toString().isEmpty());
QVERIFY(n.midRef(0,0).toString().isEmpty());
QVERIFY(n.midRef(9999,0).toString().isEmpty());
QVERIFY(n.midRef(9999,1).toString().isEmpty());
+ QVERIFY(n.midRef(-1, 6).isNull());
+ QVERIFY(n.midRef(-100, 6).isNull());
+ QVERIFY(n.midRef(INT_MIN, 0).isNull());
+ QVERIFY(n.midRef(INT_MIN, -1).isNull());
+ QVERIFY(n.midRef(INT_MIN, INT_MAX).isNull());
+ QVERIFY(n.midRef(INT_MIN + 1, INT_MAX).isNull());
+ QVERIFY(n.midRef(INT_MIN + 2, INT_MAX).isNull());
+ QVERIFY(n.midRef(INT_MIN + n.size() + 1, INT_MAX).isNull());
+ QVERIFY(n.midRef(INT_MAX).isNull());
+ QVERIFY(n.midRef(INT_MAX, INT_MAX).isNull());
+ QVERIFY(n.midRef(-5, INT_MAX).isNull());
+ QVERIFY(n.midRef(-1, INT_MAX).isNull());
+ QVERIFY(n.midRef(0, INT_MAX).isNull());
+ QVERIFY(n.midRef(1, INT_MAX).isNull());
+ QVERIFY(n.midRef(5, INT_MAX).isNull());
+ QVERIFY(n.midRef(20, INT_MAX).isNull());
+ QVERIFY(n.midRef(-1, -1).isNull());
+
QString x = "Nine pineapples";
QCOMPARE(x.midRef(5, 4).toString(), QString("pine"));
QCOMPARE(x.midRef(5).toString(), QString("pineapples"));
+ QCOMPARE(x.midRef(-1, 6), x.midRef(0, 5));
+ QVERIFY(x.midRef(-100, 6).isEmpty());
+ QVERIFY(x.midRef(INT_MIN, 0).isEmpty());
+ QCOMPARE(x.midRef(INT_MIN, -1).toString(), x);
+ QVERIFY(x.midRef(INT_MIN, INT_MAX).isNull());
+ QVERIFY(x.midRef(INT_MIN + 1, INT_MAX).isEmpty());
+ QCOMPARE(x.midRef(INT_MIN + 2, INT_MAX), x.leftRef(1));
+ QCOMPARE(x.midRef(INT_MIN + x.size() + 1, INT_MAX).toString(), x);
+ QVERIFY(x.midRef(INT_MAX).isNull());
+ QVERIFY(x.midRef(INT_MAX, INT_MAX).isNull());
+ QCOMPARE(x.midRef(-5, INT_MAX).toString(), x);
+ QCOMPARE(x.midRef(-1, INT_MAX).toString(), x);
+ QCOMPARE(x.midRef(0, INT_MAX).toString(), x);
+ QCOMPARE(x.midRef(1, INT_MAX).toString(), QString("ine pineapples"));
+ QCOMPARE(x.midRef(5, INT_MAX).toString(), QString("pineapples"));
+ QVERIFY(x.midRef(20, INT_MAX).isNull());
+ QCOMPARE(x.midRef(-1, -1).toString(), x);
}
void tst_QString::stringRef()
@@ -2066,6 +2199,9 @@ void tst_QString::replace_regexp()
QString s2 = string;
s2.replace( QRegExp(regexp), after );
QTEST( s2, "result" );
+ s2 = string;
+ s2.replace( QRegularExpression(regexp), after );
+ QTEST( s2, "result" );
}
void tst_QString::remove_uint_uint()
@@ -2130,8 +2266,13 @@ void tst_QString::remove_regexp()
QFETCH( QString, after );
if ( after.length() == 0 ) {
- string.remove( QRegExp(regexp) );
- QTEST( string, "result" );
+ QString s2 = string;
+ s2.remove( QRegExp(regexp) );
+ QTEST( s2, "result" );
+
+ s2 = string;
+ s2.remove( QRegularExpression(regexp) );
+ QTEST( s2, "result" );
} else {
QCOMPARE( 0, 0 ); // shut QtTest
}
@@ -3872,8 +4013,12 @@ void tst_QString::section()
QFETCH( bool, regexp );
if (regexp) {
QCOMPARE( wholeString.section( QRegExp(sep), start, end, QString::SectionFlag(flags) ), sectionString );
+ QCOMPARE( wholeString.section( QRegularExpression(sep), start, end, QString::SectionFlag(flags) ), sectionString );
} else {
QCOMPARE( wholeString.section( sep, start, end, QString::SectionFlag(flags) ), sectionString );
+ QCOMPARE( wholeString.section( QRegExp(QRegExp::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString );
+ QCOMPARE( wholeString.section( QRegularExpression(QRegularExpression::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString );
+
}
}
@@ -4394,6 +4539,7 @@ void tst_QString::split()
QFETCH(QStringList, result);
QRegExp rx = QRegExp(QRegExp::escape(sep));
+ QRegularExpression re(QRegularExpression::escape(sep));
QStringList list;
@@ -4401,6 +4547,8 @@ void tst_QString::split()
QVERIFY(list == result);
list = str.split(rx);
QVERIFY(list == result);
+ list = str.split(re);
+ QVERIFY(list == result);
if (sep.size() == 1) {
list = str.split(sep.at(0));
QVERIFY(list == result);
@@ -4410,6 +4558,8 @@ void tst_QString::split()
QVERIFY(list == result);
list = str.split(rx, QString::KeepEmptyParts);
QVERIFY(list == result);
+ list = str.split(re, QString::KeepEmptyParts);
+ QVERIFY(list == result);
if (sep.size() == 1) {
list = str.split(sep.at(0), QString::KeepEmptyParts);
QVERIFY(list == result);
@@ -4420,39 +4570,51 @@ void tst_QString::split()
QVERIFY(list == result);
list = str.split(rx, QString::SkipEmptyParts);
QVERIFY(list == result);
+ list = str.split(re, QString::SkipEmptyParts);
+ QVERIFY(list == result);
if (sep.size() == 1) {
list = str.split(sep.at(0), QString::SkipEmptyParts);
QVERIFY(list == result);
}
}
+void tst_QString::split_regexp_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<QStringList>("result");
+
+ QTest::newRow("data01") << "Some text\n\twith strange whitespace."
+ << "\\s+"
+ << (QStringList() << "Some" << "text" << "with" << "strange" << "whitespace." );
+
+ QTest::newRow("data02") << "This time, a normal English sentence."
+ << "\\W+"
+ << (QStringList() << "This" << "time" << "a" << "normal" << "English" << "sentence" << "");
+
+ QTest::newRow("data03") << "Now: this sentence fragment."
+ << "\\b"
+ << (QStringList() << "" << "Now" << ": " << "this" << " " << "sentence" << " " << "fragment" << ".");
+}
+
void tst_QString::split_regexp()
{
- QString str1 = "Some text\n\twith strange whitespace.";
- QStringList list1 = str1.split(QRegExp("\\s+"));
- QStringList result1;
- result1 << "Some" << "text" << "with" << "strange" << "whitespace.";
- QVERIFY(list1 == result1);
- list1 = str1.split(QRegExp("\\s"), QString::SkipEmptyParts);
- QVERIFY(list1 == result1);
-
- QString str2 = "This time, a normal English sentence.";
- QStringList list2 = str2.split(QRegExp("\\W+"));
- QStringList result2;
- result2 << "This" << "time" << "a" << "normal" << "English" << "sentence" << "";
- QVERIFY(list2 == result2);
- list2 = str2.split(QRegExp("\\W"), QString::SkipEmptyParts);
- result2.removeAll(QString());
- QVERIFY(list2 == result2);
-
- QString str3 = "Now: this sentence fragment.";
- QStringList list3 = str3.split(QRegExp("\\b"));
- QStringList result3;
- result3 << "" << "Now" << ": " << "this" << " " << "sentence" << " " << "fragment" << ".";
- QVERIFY(list3 == result3);
- list3 = str3.split(QRegExp("\\b"), QString::SkipEmptyParts);
- result3.removeAll(QString());
- QVERIFY(list3 == result3);
+ QFETCH(QString, string);
+ QFETCH(QString, pattern);
+ QFETCH(QStringList, result);
+
+ QStringList list;
+ list = string.split(QRegExp(pattern));
+ QCOMPARE(list, result);
+ list = string.split(QRegularExpression(pattern));
+ QCOMPARE(list, result);
+
+ result.removeAll(QString());
+
+ list = string.split(QRegExp(pattern), QString::SkipEmptyParts);
+ QCOMPARE(list, result);
+ list = string.split(QRegularExpression(pattern), QString::SkipEmptyParts);
+ QCOMPARE(list, result);
}
void tst_QString::fromUtf16_data()
@@ -5056,8 +5218,8 @@ void tst_QString::literals()
QVERIFY(str.length() == 4);
QVERIFY(str == QLatin1String("abcd"));
- QVERIFY(str.data_ptr()->ref == -1);
- QVERIFY(str.data_ptr()->offset == 0);
+ QVERIFY(str.data_ptr()->ref.isStatic());
+ QVERIFY(str.data_ptr()->offset == sizeof(QStringData));
const QChar *s = str.constData();
QString str2 = str;
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index c79aee4187..67ca547736 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -85,6 +85,8 @@ private slots:
void initializeList();
void const_shared_null();
+ void setSharable_data();
+ void setSharable();
};
void tst_QVector::constructors() const
@@ -946,5 +948,97 @@ void tst_QVector::const_shared_null()
QVERIFY(!v2.isDetached());
}
+Q_DECLARE_METATYPE(QVector<int>);
+
+void tst_QVector::setSharable_data()
+{
+ QTest::addColumn<QVector<int> >("vector");
+ QTest::addColumn<int>("size");
+ QTest::addColumn<int>("capacity");
+ QTest::addColumn<bool>("isCapacityReserved");
+
+ QVector<int> null;
+ QVector<int> empty(0, 5);
+ QVector<int> emptyReserved;
+ QVector<int> nonEmpty;
+ QVector<int> nonEmptyReserved;
+
+ emptyReserved.reserve(10);
+ nonEmptyReserved.reserve(15);
+
+ nonEmpty << 0 << 1 << 2 << 3 << 4;
+ nonEmptyReserved << 0 << 1 << 2 << 3 << 4 << 5 << 6;
+
+ QVERIFY(emptyReserved.capacity() >= 10);
+ QVERIFY(nonEmptyReserved.capacity() >= 15);
+
+ QTest::newRow("null") << null << 0 << 0 << false;
+ QTest::newRow("empty") << empty << 0 << 0 << false;
+ QTest::newRow("empty, Reserved") << emptyReserved << 0 << 10 << true;
+ QTest::newRow("non-empty") << nonEmpty << 5 << 0 << false;
+ QTest::newRow("non-empty, Reserved") << nonEmptyReserved << 7 << 15 << true;
+}
+
+void tst_QVector::setSharable()
+{
+ QFETCH(QVector<int>, vector);
+ QFETCH(int, size);
+ QFETCH(int, capacity);
+ QFETCH(bool, isCapacityReserved);
+
+ QVERIFY(!vector.isDetached()); // Shared with QTest
+
+ vector.setSharable(true);
+
+ QCOMPARE(vector.size(), size);
+ if (isCapacityReserved)
+ QVERIFY2(vector.capacity() >= capacity,
+ qPrintable(QString("Capacity is %1, expected at least %2.")
+ .arg(vector.capacity())
+ .arg(capacity)));
+
+ {
+ QVector<int> copy(vector);
+
+ QVERIFY(!copy.isDetached());
+ QVERIFY(copy.isSharedWith(vector));
+ }
+
+ vector.setSharable(false);
+ QVERIFY(vector.isDetached() || vector.isSharedWith(QVector<int>()));
+
+ {
+ QVector<int> copy(vector);
+
+ QVERIFY(copy.isDetached() || copy.isSharedWith(QVector<int>()));
+ QCOMPARE(copy.size(), size);
+ if (isCapacityReserved)
+ QVERIFY2(copy.capacity() >= capacity,
+ qPrintable(QString("Capacity is %1, expected at least %2.")
+ .arg(vector.capacity())
+ .arg(capacity)));
+ QCOMPARE(copy, vector);
+ }
+
+ vector.setSharable(true);
+
+ {
+ QVector<int> copy(vector);
+
+ QVERIFY(!copy.isDetached());
+ QVERIFY(copy.isSharedWith(vector));
+ }
+
+ for (int i = 0; i < vector.size(); ++i)
+ QCOMPARE(vector[i], i);
+
+ QCOMPARE(vector.size(), size);
+ if (isCapacityReserved)
+ QVERIFY2(vector.capacity() >= capacity,
+ qPrintable(QString("Capacity is %1, expected at least %2.")
+ .arg(vector.capacity())
+ .arg(capacity)));
+}
+
QTEST_APPLESS_MAIN(tst_QVector)
#include "tst_qvector.moc"
diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro
index d8961559e5..38225e12f7 100644
--- a/tests/auto/corelib/tools/tools.pro
+++ b/tests/auto/corelib/tools/tools.pro
@@ -1,6 +1,7 @@
TEMPLATE=subdirs
SUBDIRS=\
qalgorithms \
+ qarraydata \
qbitarray \
qbytearray \
qbytearraymatcher \
diff --git a/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp b/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp
index ed4ed4c6a2..a523a66bdd 100644
--- a/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp
+++ b/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp
@@ -397,16 +397,21 @@ void tst_QDBusMetaObject::types()
for (int i = metaobject->methodOffset(); i < metaobject->methodCount(); ++i) {
QMetaMethod expected = metaobject->method(i);
- int methodIdx = result->indexOfMethod(expected.signature());
+ int methodIdx = result->indexOfMethod(expected.methodSignature().constData());
QVERIFY(methodIdx != -1);
QMetaMethod constructed = result->method(methodIdx);
QCOMPARE(int(constructed.access()), int(expected.access()));
QCOMPARE(int(constructed.methodType()), int(expected.methodType()));
+ QCOMPARE(constructed.name(), expected.name());
+ QCOMPARE(constructed.parameterCount(), expected.parameterCount());
QCOMPARE(constructed.parameterNames(), expected.parameterNames());
QCOMPARE(constructed.parameterTypes(), expected.parameterTypes());
+ for (int j = 0; j < constructed.parameterCount(); ++j)
+ QCOMPARE(constructed.parameterType(j), expected.parameterType(j));
QCOMPARE(constructed.tag(), expected.tag());
QCOMPARE(constructed.typeName(), expected.typeName());
+ QCOMPARE(constructed.returnType(), expected.returnType());
}
for (int i = metaobject->propertyOffset(); i < metaobject->propertyCount(); ++i) {
@@ -427,6 +432,8 @@ void tst_QDBusMetaObject::types()
QCOMPARE(constructed.isUser(), expected.isUser());
QCOMPARE(constructed.isWritable(), expected.isWritable());
QCOMPARE(constructed.typeName(), expected.typeName());
+ QCOMPARE(constructed.type(), expected.type());
+ QCOMPARE(constructed.userType(), expected.userType());
}
}
@@ -667,6 +674,204 @@ const char PropertyTest4_xml[] =
"<annotation name=\"com.trolltech.QtDBus.QtTypeName\" value=\"Struct1\"/>"
"</property>";
+class PropertyTest_b: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool property READ property WRITE setProperty)
+public:
+ bool property() { return false; }
+ void setProperty(bool) { }
+};
+const char PropertyTest_b_xml[] =
+ "<property name=\"property\" type=\"b\" access=\"readwrite\"/>";
+
+class PropertyTest_y: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(uchar property READ property WRITE setProperty)
+public:
+ uchar property() { return 0; }
+ void setProperty(uchar) { }
+};
+const char PropertyTest_y_xml[] =
+ "<property name=\"property\" type=\"y\" access=\"readwrite\"/>";
+
+class PropertyTest_n: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(short property READ property WRITE setProperty)
+public:
+ short property() { return 0; }
+ void setProperty(short) { }
+};
+const char PropertyTest_n_xml[] =
+ "<property name=\"property\" type=\"n\" access=\"readwrite\"/>";
+
+class PropertyTest_q: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(ushort property READ property WRITE setProperty)
+public:
+ ushort property() { return 0; }
+ void setProperty(ushort) { }
+};
+const char PropertyTest_q_xml[] =
+ "<property name=\"property\" type=\"q\" access=\"readwrite\"/>";
+
+class PropertyTest_u: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(uint property READ property WRITE setProperty)
+public:
+ uint property() { return 0; }
+ void setProperty(uint) { }
+};
+const char PropertyTest_u_xml[] =
+ "<property name=\"property\" type=\"u\" access=\"readwrite\"/>";
+
+class PropertyTest_x: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qlonglong property READ property WRITE setProperty)
+public:
+ qlonglong property() { return 0; }
+ void setProperty(qlonglong) { }
+};
+const char PropertyTest_x_xml[] =
+ "<property name=\"property\" type=\"x\" access=\"readwrite\"/>";
+
+class PropertyTest_t: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qulonglong property READ property WRITE setProperty)
+public:
+ qulonglong property() { return 0; }
+ void setProperty(qulonglong) { }
+};
+const char PropertyTest_t_xml[] =
+ "<property name=\"property\" type=\"t\" access=\"readwrite\"/>";
+
+class PropertyTest_d: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(double property READ property WRITE setProperty)
+public:
+ double property() { return 0; }
+ void setProperty(double) { }
+};
+const char PropertyTest_d_xml[] =
+ "<property name=\"property\" type=\"d\" access=\"readwrite\"/>";
+
+class PropertyTest_s: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString property READ property WRITE setProperty)
+public:
+ QString property() { return QString(); }
+ void setProperty(QString) { }
+};
+const char PropertyTest_s_xml[] =
+ "<property name=\"property\" type=\"s\" access=\"readwrite\"/>";
+
+class PropertyTest_v: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDBusVariant property READ property WRITE setProperty)
+public:
+ QDBusVariant property() { return QDBusVariant(); }
+ void setProperty(QDBusVariant) { }
+};
+const char PropertyTest_v_xml[] =
+ "<property name=\"property\" type=\"v\" access=\"readwrite\"/>";
+
+class PropertyTest_o: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDBusObjectPath property READ property WRITE setProperty)
+public:
+ QDBusObjectPath property() { return QDBusObjectPath(); }
+ void setProperty(QDBusObjectPath) { }
+};
+const char PropertyTest_o_xml[] =
+ "<property name=\"property\" type=\"o\" access=\"readwrite\"/>";
+
+class PropertyTest_g: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDBusSignature property READ property WRITE setProperty)
+public:
+ QDBusSignature property() { return QDBusSignature(); }
+ void setProperty(QDBusSignature) { }
+};
+const char PropertyTest_g_xml[] =
+ "<property name=\"property\" type=\"g\" access=\"readwrite\"/>";
+
+class PropertyTest_h: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDBusUnixFileDescriptor property READ property WRITE setProperty)
+public:
+ QDBusUnixFileDescriptor property() { return QDBusUnixFileDescriptor(); }
+ void setProperty(QDBusUnixFileDescriptor) { }
+};
+const char PropertyTest_h_xml[] =
+ "<property name=\"property\" type=\"h\" access=\"readwrite\"/>";
+
+class PropertyTest_ay: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QByteArray property READ property WRITE setProperty)
+public:
+ QByteArray property() { return QByteArray(); }
+ void setProperty(QByteArray) { }
+};
+const char PropertyTest_ay_xml[] =
+ "<property name=\"property\" type=\"ay\" access=\"readwrite\"/>";
+
+class PropertyTest_as: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QStringList property READ property WRITE setProperty)
+public:
+ QStringList property() { return QStringList(); }
+ void setProperty(QStringList) { }
+};
+const char PropertyTest_as_xml[] =
+ "<property name=\"property\" type=\"as\" access=\"readwrite\"/>";
+
+class PropertyTest_av: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QVariantList property READ property WRITE setProperty)
+public:
+ QVariantList property() { return QVariantList(); }
+ void setProperty(QVariantList) { }
+};
+const char PropertyTest_av_xml[] =
+ "<property name=\"property\" type=\"av\" access=\"readwrite\"/>";
+
+class PropertyTest_ao: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QList<QDBusObjectPath> property READ property WRITE setProperty)
+public:
+ QList<QDBusObjectPath> property() { return QList<QDBusObjectPath>(); }
+ void setProperty(QList<QDBusObjectPath>) { }
+};
+const char PropertyTest_ao_xml[] =
+ "<property name=\"property\" type=\"ao\" access=\"readwrite\"/>";
+
+class PropertyTest_ag: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QList<QDBusSignature> property READ property WRITE setProperty)
+public:
+ QList<QDBusSignature> property() { return QList<QDBusSignature>(); }
+ void setProperty(QList<QDBusSignature>) { }
+};
+const char PropertyTest_ag_xml[] =
+ "<property name=\"property\" type=\"ag\" access=\"readwrite\"/>";
+
void tst_QDBusMetaObject::properties_data()
{
QTest::addColumn<const QMetaObject *>("metaobject");
@@ -676,6 +881,25 @@ void tst_QDBusMetaObject::properties_data()
QTest::newRow("readwrite") << &PropertyTest2::staticMetaObject << QString(PropertyTest2_xml);
QTest::newRow("write") << &PropertyTest3::staticMetaObject << QString(PropertyTest3_xml);
QTest::newRow("customtype") << &PropertyTest4::staticMetaObject << QString(PropertyTest4_xml);
+
+ QTest::newRow("bool") << &PropertyTest_b::staticMetaObject << QString(PropertyTest_b_xml);
+ QTest::newRow("byte") << &PropertyTest_y::staticMetaObject << QString(PropertyTest_y_xml);
+ QTest::newRow("short") << &PropertyTest_n::staticMetaObject << QString(PropertyTest_n_xml);
+ QTest::newRow("ushort") << &PropertyTest_q::staticMetaObject << QString(PropertyTest_q_xml);
+ QTest::newRow("uint") << &PropertyTest_u::staticMetaObject << QString(PropertyTest_u_xml);
+ QTest::newRow("qlonglong") << &PropertyTest_x::staticMetaObject << QString(PropertyTest_x_xml);
+ QTest::newRow("qulonglong") << &PropertyTest_t::staticMetaObject << QString(PropertyTest_t_xml);
+ QTest::newRow("double") << &PropertyTest_d::staticMetaObject << QString(PropertyTest_d_xml);
+ QTest::newRow("QString") << &PropertyTest_s::staticMetaObject << QString(PropertyTest_s_xml);
+ QTest::newRow("QDBusVariant") << &PropertyTest_v::staticMetaObject << QString(PropertyTest_v_xml);
+ QTest::newRow("QDBusObjectPath") << &PropertyTest_o::staticMetaObject << QString(PropertyTest_o_xml);
+ QTest::newRow("QDBusSignature") << &PropertyTest_g::staticMetaObject << QString(PropertyTest_g_xml);
+ QTest::newRow("QDBusUnixFileDescriptor") << &PropertyTest_h::staticMetaObject << QString(PropertyTest_h_xml);
+ QTest::newRow("QByteArray") << &PropertyTest_ay::staticMetaObject << QString(PropertyTest_ay_xml);
+ QTest::newRow("QStringList") << &PropertyTest_as::staticMetaObject << QString(PropertyTest_as_xml);
+ QTest::newRow("QVariantList") << &PropertyTest_av::staticMetaObject << QString(PropertyTest_av_xml);
+ QTest::newRow("QList<QDBusObjectPath>") << &PropertyTest_ao::staticMetaObject << QString(PropertyTest_ao_xml);
+ QTest::newRow("QList<QDBusSignature>") << &PropertyTest_ag::staticMetaObject << QString(PropertyTest_ag_xml);
}
void tst_QDBusMetaObject::properties()
diff --git a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp
index 5836945484..865c9a86ff 100644
--- a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp
+++ b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp
@@ -474,77 +474,77 @@ void tst_QDBusPendingReply::multipleTypes()
void tst_QDBusPendingReply::synchronousSimpleTypes()
{
- QDBusPendingReply<bool> rbool = iface->call("retrieveBool");
+ QDBusPendingReply<bool> rbool(iface->call("retrieveBool"));
rbool.waitForFinished();
QVERIFY(rbool.isFinished());
QCOMPARE(rbool.argumentAt<0>(), adaptor->retrieveBool());
- QDBusPendingReply<uchar> ruchar = iface->call("retrieveUChar");
+ QDBusPendingReply<uchar> ruchar(iface->call("retrieveUChar"));
ruchar.waitForFinished();
QVERIFY(ruchar.isFinished());
QCOMPARE(ruchar.argumentAt<0>(), adaptor->retrieveUChar());
- QDBusPendingReply<short> rshort = iface->call("retrieveShort");
+ QDBusPendingReply<short> rshort(iface->call("retrieveShort"));
rshort.waitForFinished();
QVERIFY(rshort.isFinished());
QCOMPARE(rshort.argumentAt<0>(), adaptor->retrieveShort());
- QDBusPendingReply<ushort> rushort = iface->call("retrieveUShort");
+ QDBusPendingReply<ushort> rushort(iface->call("retrieveUShort"));
rushort.waitForFinished();
QVERIFY(rushort.isFinished());
QCOMPARE(rushort.argumentAt<0>(), adaptor->retrieveUShort());
- QDBusPendingReply<int> rint = iface->call("retrieveInt");
+ QDBusPendingReply<int> rint(iface->call("retrieveInt"));
rint.waitForFinished();
QVERIFY(rint.isFinished());
QCOMPARE(rint.argumentAt<0>(), adaptor->retrieveInt());
- QDBusPendingReply<uint> ruint = iface->call("retrieveUInt");
+ QDBusPendingReply<uint> ruint(iface->call("retrieveUInt"));
ruint.waitForFinished();
QVERIFY(ruint.isFinished());
QCOMPARE(ruint.argumentAt<0>(), adaptor->retrieveUInt());
- QDBusPendingReply<qlonglong> rqlonglong = iface->call("retrieveLongLong");
+ QDBusPendingReply<qlonglong> rqlonglong(iface->call("retrieveLongLong"));
rqlonglong.waitForFinished();
QVERIFY(rqlonglong.isFinished());
QCOMPARE(rqlonglong.argumentAt<0>(), adaptor->retrieveLongLong());
- QDBusPendingReply<qulonglong> rqulonglong = iface->call("retrieveULongLong");
+ QDBusPendingReply<qulonglong> rqulonglong(iface->call("retrieveULongLong"));
rqulonglong.waitForFinished();
QVERIFY(rqulonglong.isFinished());
QCOMPARE(rqulonglong.argumentAt<0>(), adaptor->retrieveULongLong());
- QDBusPendingReply<double> rdouble = iface->call("retrieveDouble");
+ QDBusPendingReply<double> rdouble(iface->call("retrieveDouble"));
rdouble.waitForFinished();
QVERIFY(rdouble.isFinished());
QCOMPARE(rdouble.argumentAt<0>(), adaptor->retrieveDouble());
- QDBusPendingReply<QString> rstring = iface->call("retrieveString");
+ QDBusPendingReply<QString> rstring(iface->call("retrieveString"));
rstring.waitForFinished();
QVERIFY(rstring.isFinished());
QCOMPARE(rstring.argumentAt<0>(), adaptor->retrieveString());
- QDBusPendingReply<QDBusObjectPath> robjectpath = iface->call("retrieveObjectPath");
+ QDBusPendingReply<QDBusObjectPath> robjectpath(iface->call("retrieveObjectPath"));
robjectpath.waitForFinished();
QVERIFY(robjectpath.isFinished());
QCOMPARE(robjectpath.argumentAt<0>().path(), adaptor->retrieveObjectPath().path());
- QDBusPendingReply<QDBusSignature> rsignature = iface->call("retrieveSignature");
+ QDBusPendingReply<QDBusSignature> rsignature(iface->call("retrieveSignature"));
rsignature.waitForFinished();
QVERIFY(rsignature.isFinished());
QCOMPARE(rsignature.argumentAt<0>().signature(), adaptor->retrieveSignature().signature());
- QDBusPendingReply<QDBusVariant> rdbusvariant = iface->call("retrieveVariant");
+ QDBusPendingReply<QDBusVariant> rdbusvariant(iface->call("retrieveVariant"));
rdbusvariant.waitForFinished();
QVERIFY(rdbusvariant.isFinished());
QCOMPARE(rdbusvariant.argumentAt<0>().variant(), adaptor->retrieveVariant().variant());
- QDBusPendingReply<QByteArray> rbytearray = iface->call("retrieveByteArray");
+ QDBusPendingReply<QByteArray> rbytearray(iface->call("retrieveByteArray"));
rbytearray.waitForFinished();
QVERIFY(rbytearray.isFinished());
QCOMPARE(rbytearray.argumentAt<0>(), adaptor->retrieveByteArray());
- QDBusPendingReply<QStringList> rstringlist = iface->call("retrieveStringList");
+ QDBusPendingReply<QStringList> rstringlist(iface->call("retrieveStringList"));
rstringlist.waitForFinished();
QVERIFY(rstringlist.isFinished());
QCOMPARE(rstringlist.argumentAt<0>(), adaptor->retrieveStringList());
@@ -559,28 +559,28 @@ void tst_QDBusPendingReply::errors()
{
QDBusError error;
- QDBusPendingReply<> rvoid = iface->asyncCall("sendError");
+ QDBusPendingReply<> rvoid(iface->asyncCall("sendError"));
rvoid.waitForFinished();
QVERIFY(rvoid.isFinished());
QVERIFY(rvoid.isError());
error = rvoid.error();
VERIFY_ERROR(error);
- QDBusPendingReply<int> rint = iface->asyncCall("sendError");
+ QDBusPendingReply<int> rint(iface->asyncCall("sendError"));
rint.waitForFinished();
QVERIFY(rint.isFinished());
QVERIFY(rint.isError());
error = rint.error();
VERIFY_ERROR(error);
- QDBusPendingReply<int,int> rintint = iface->asyncCall("sendError");
+ QDBusPendingReply<int,int> rintint(iface->asyncCall("sendError"));
rintint.waitForFinished();
QVERIFY(rintint.isFinished());
QVERIFY(rintint.isError());
error = rintint.error();
VERIFY_ERROR(error);
- QDBusPendingReply<QString> rstring = iface->asyncCall("sendError");
+ QDBusPendingReply<QString> rstring(iface->asyncCall("sendError"));
rstring.waitForFinished();
QVERIFY(rstring.isFinished());
QVERIFY(rstring.isError());
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index 391600dd57..997e15ed55 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -595,7 +595,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
rawTouchPoint.setState(Qt::TouchPointPressed);
rawTouchPoint.setScreenPos(screenPos);
rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry));
- QList<QPointF> rawPosList;
+ QVector<QPointF> rawPosList;
rawPosList << QPointF(12, 34) << QPointF(56, 78);
rawTouchPoint.setRawScreenPositions(rawPosList);
const ulong timestamp = 1234;
diff --git a/tests/auto/tools/moc/slots-with-void-template.h b/tests/auto/tools/moc/slots-with-void-template.h
index 081b03eb4a..73f07d1dc7 100644
--- a/tests/auto/tools/moc/slots-with-void-template.h
+++ b/tests/auto/tools/moc/slots-with-void-template.h
@@ -51,9 +51,11 @@ class SlotsWithVoidTemplateTest : public QObject
Q_OBJECT
public slots:
inline void dummySlot() {}
+ inline void dummySlot2(void) {}
inline void anotherSlot(const TestTemplate<void> &) {}
inline TestTemplate<void> mySlot() { return TestTemplate<void>(); }
signals:
void mySignal(const TestTemplate<void> &);
void myVoidSignal();
+ void myVoidSignal2(void);
};
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 49095048bf..f7ce54959e 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -748,7 +748,7 @@ void tst_Moc::classinfoWithEscapes()
QCOMPARE(mobj->methodCount() - mobj->methodOffset(), 1);
QMetaMethod mm = mobj->method(mobj->methodOffset());
- QCOMPARE(mm.signature(), "slotWithAReallyLongName(int)");
+ QCOMPARE(mm.methodSignature(), QByteArray("slotWithAReallyLongName(int)"));
}
void tst_Moc::trNoopInClassInfo()
@@ -874,6 +874,8 @@ void tst_Moc::slotsWithVoidTemplate()
&test, SLOT(dummySlot(void))));
QVERIFY(QObject::connect(&test, SIGNAL(mySignal(const TestTemplate<void> &)),
&test, SLOT(anotherSlot(const TestTemplate<void> &))));
+ QVERIFY(QObject::connect(&test, SIGNAL(myVoidSignal2()),
+ &test, SLOT(dummySlot2())));
}
void tst_Moc::structQObject()
@@ -1093,14 +1095,14 @@ void tst_Moc::invokable()
{
const QMetaObject &mobj = InvokableBeforeReturnType::staticMetaObject;
QCOMPARE(mobj.methodCount(), 6);
- QVERIFY(mobj.method(5).signature() == QByteArray("foo()"));
+ QVERIFY(mobj.method(5).methodSignature() == QByteArray("foo()"));
}
{
const QMetaObject &mobj = InvokableBeforeInline::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
- QVERIFY(mobj.method(5).signature() == QByteArray("foo()"));
- QVERIFY(mobj.method(6).signature() == QByteArray("bar()"));
+ QVERIFY(mobj.method(5).methodSignature() == QByteArray("foo()"));
+ QVERIFY(mobj.method(6).methodSignature() == QByteArray("bar()"));
}
}
@@ -1109,22 +1111,22 @@ void tst_Moc::singleFunctionKeywordSignalAndSlot()
{
const QMetaObject &mobj = SingleFunctionKeywordBeforeReturnType::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
- QVERIFY(mobj.method(5).signature() == QByteArray("mySignal()"));
- QVERIFY(mobj.method(6).signature() == QByteArray("mySlot()"));
+ QVERIFY(mobj.method(5).methodSignature() == QByteArray("mySignal()"));
+ QVERIFY(mobj.method(6).methodSignature() == QByteArray("mySlot()"));
}
{
const QMetaObject &mobj = SingleFunctionKeywordBeforeInline::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
- QVERIFY(mobj.method(5).signature() == QByteArray("mySignal()"));
- QVERIFY(mobj.method(6).signature() == QByteArray("mySlot()"));
+ QVERIFY(mobj.method(5).methodSignature() == QByteArray("mySignal()"));
+ QVERIFY(mobj.method(6).methodSignature() == QByteArray("mySlot()"));
}
{
const QMetaObject &mobj = SingleFunctionKeywordAfterInline::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
- QVERIFY(mobj.method(5).signature() == QByteArray("mySignal()"));
- QVERIFY(mobj.method(6).signature() == QByteArray("mySlot()"));
+ QVERIFY(mobj.method(5).methodSignature() == QByteArray("mySignal()"));
+ QVERIFY(mobj.method(6).methodSignature() == QByteArray("mySlot()"));
}
}
@@ -1231,7 +1233,7 @@ void tst_Moc::constructors()
QMetaMethod mm = mo->constructor(0);
QCOMPARE(mm.access(), QMetaMethod::Public);
QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
- QCOMPARE(mm.signature(), "CtorTestClass(QObject*)");
+ QCOMPARE(mm.methodSignature(), QByteArray("CtorTestClass(QObject*)"));
QCOMPARE(mm.typeName(), "");
QList<QByteArray> paramNames = mm.parameterNames();
QCOMPARE(paramNames.size(), 1);
@@ -1244,7 +1246,7 @@ void tst_Moc::constructors()
QMetaMethod mm = mo->constructor(1);
QCOMPARE(mm.access(), QMetaMethod::Public);
QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
- QCOMPARE(mm.signature(), "CtorTestClass()");
+ QCOMPARE(mm.methodSignature(), QByteArray("CtorTestClass()"));
QCOMPARE(mm.typeName(), "");
QCOMPARE(mm.parameterNames().size(), 0);
QCOMPARE(mm.parameterTypes().size(), 0);
@@ -1253,7 +1255,7 @@ void tst_Moc::constructors()
QMetaMethod mm = mo->constructor(2);
QCOMPARE(mm.access(), QMetaMethod::Public);
QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
- QCOMPARE(mm.signature(), "CtorTestClass(QString)");
+ QCOMPARE(mm.methodSignature(), QByteArray("CtorTestClass(QString)"));
QCOMPARE(mm.typeName(), "");
QList<QByteArray> paramNames = mm.parameterNames();
QCOMPARE(paramNames.size(), 1);
diff --git a/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro
new file mode 100644
index 0000000000..4217d5e73c
--- /dev/null
+++ b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro
@@ -0,0 +1,11 @@
+CONFIG += testcase
+QT = core testlib dbus
+TARGET = tst_qdbuscpp2xml
+
+QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
+
+SOURCES += tst_qdbuscpp2xml.cpp \
+
+RESOURCES += qdbuscpp2xml.qrc
+
+HEADERS += test1.h \ No newline at end of file
diff --git a/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc
new file mode 100644
index 0000000000..b4cffb842e
--- /dev/null
+++ b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/tst_qdbuscpp2xml/">
+ <file>test1.h</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/tools/qdbuscpp2xml/test1.h b/tests/auto/tools/qdbuscpp2xml/test1.h
new file mode 100644
index 0000000000..35dee2cc38
--- /dev/null
+++ b/tests/auto/tools/qdbuscpp2xml/test1.h
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDBUSCPP2XML_TEST1_H
+#define QDBUSCPP2XML_TEST1_H
+
+#include <QObject>
+
+class QDBusObjectPath;
+class QDBusUnixFileDescriptor;
+class QDBusSignature;
+
+class Test1 : public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.qtProject.qdbuscpp2xmlTests.Test1")
+ Q_PROPERTY(int numProperty1 READ numProperty1 CONSTANT)
+ Q_PROPERTY(int numProperty2 READ numProperty2 WRITE setNumProperty2)
+public:
+ Test1(QObject *parent = 0) : QObject(parent) {}
+
+ int numProperty1() { return 42; }
+
+ int numProperty2() { return 42; }
+ void setNumProperty2(int) {}
+
+signals:
+ void signalVoidType();
+ int signalIntType();
+ void signal_primitive_args(int a1, bool a2, short a3, ushort a4, uint a5, qlonglong a6, double a7, qlonglong a8 = 0);
+ void signal_string_args(const QByteArray &ba, const QString &a2);
+ void signal_Qt_args1(const QDate &a1, const QTime &a2, const QDateTime &a3,
+ const QRect &a4, const QRectF &a5, const QSize &a6, const QSizeF &a7);
+ void signal_Qt_args2(const QPoint &a1, const QPointF &a2, const QLine &a3, const QLineF &a4,
+ const QVariantList &a5, const QVariantMap &a6, const QVariantHash &a7);
+
+ void signal_QDBus_args(const QDBusObjectPath &a1, const QDBusSignature &a2, const QDBusUnixFileDescriptor &a3);
+
+ void signal_container_args1(const QList<bool> &a1, const QList<short> &a2, const QList<ushort> &a3, const QList<int> &a4, const QList<uint> &a5);
+ void signal_container_args2(const QList<qlonglong> &a1, const QList<qulonglong> &a2, const QList<double> &a3, const QList<QDBusObjectPath> &a4, const QList<QDBusSignature> &a5, const QList<QDBusUnixFileDescriptor> &a6);
+
+ Q_SCRIPTABLE void signalVoidType_scriptable();
+ Q_SCRIPTABLE int signalIntType_scriptable();
+ Q_SCRIPTABLE void signal_primitive_args_scriptable(int a1, bool a2, short a3, ushort a4, uint a5, qlonglong a6, double a7, qlonglong a8 = 0);
+ Q_SCRIPTABLE void signal_string_args_scriptable(const QByteArray &ba, const QString &a2);
+ Q_SCRIPTABLE void signal_Qt_args1_scriptable(const QDate &a1, const QTime &a2, const QDateTime &a3,
+ const QRect &a4, const QRectF &a5, const QSize &a6, const QSizeF &a7);
+ Q_SCRIPTABLE void signal_Qt_args2_scriptable(const QPoint &a1, const QPointF &a2, const QLine &a3, const QLineF &a4,
+ const QVariantList &a5, const QVariantMap &a6, const QVariantHash &a7);
+
+ Q_SCRIPTABLE void signal_QDBus_args_scriptable(const QDBusObjectPath &a1, const QDBusSignature &a2, const QDBusUnixFileDescriptor &a3);
+
+ Q_SCRIPTABLE void signal_container_args1_scriptable(const QList<bool> &a1, const QList<short> &a2, const QList<ushort> &a3, const QList<int> &a4, const QList<uint> &a5);
+ Q_SCRIPTABLE void signal_container_args2_scriptable(const QList<qlonglong> &a1, const QList<qulonglong> &a2, const QList<double> &a3, const QList<QDBusObjectPath> &a4, const QList<QDBusSignature> &a5, const QList<QDBusUnixFileDescriptor> &a6);
+
+public slots:
+ void slotVoidType() {}
+ int slotIntType() { return 42; }
+
+ Q_SCRIPTABLE void slotVoidType_scriptable() {}
+ Q_SCRIPTABLE int slotIntType_scriptable() { return 42; }
+
+protected slots:
+ void neverExported1() {}
+ int neverExported2() { return 42; }
+
+ Q_SCRIPTABLE void neverExported3() {}
+ Q_SCRIPTABLE int neverExported4() { return 42; }
+
+private slots:
+ void neverExported5() {}
+ int neverExported6() { return 42; }
+
+ Q_SCRIPTABLE void neverExported7() {}
+ Q_SCRIPTABLE int neverExported8() { return 42; }
+
+public:
+ Q_SCRIPTABLE void methodVoidType() {}
+ Q_SCRIPTABLE int methodIntType() { return 42; }
+
+protected:
+ Q_SCRIPTABLE void neverExported9() {}
+ Q_SCRIPTABLE int neverExported10() { return 42; }
+
+private:
+ Q_SCRIPTABLE void neverExported11() {}
+ Q_SCRIPTABLE int neverExported12() { return 42; }
+};
+
+#endif
diff --git a/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp
new file mode 100644
index 0000000000..5510c656e1
--- /dev/null
+++ b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include "test1.h"
+
+#include <QtDBus/QDBusConnection>
+
+// in qdbusxmlgenerator.cpp
+QT_BEGIN_NAMESPACE
+extern Q_DBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface,
+ const QMetaObject *mo,
+ const QMetaObject *base,
+ int flags);
+QT_END_NAMESPACE
+
+static QString addXmlHeader(const QString &input)
+{
+ return
+ "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n<node>"
+ + (input.isEmpty() ? QString() : QString("\n " + input.trimmed()))
+ + "\n</node>\n";
+}
+
+class tst_qdbuscpp2xml : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void qdbuscpp2xml_data();
+ void qdbuscpp2xml();
+
+ void initTestCase();
+ void cleanupTestCase();
+
+private:
+ QHash<QString, QObject*> m_tests;
+};
+
+void tst_qdbuscpp2xml::initTestCase()
+{
+ m_tests.insert("test1", new Test1);
+}
+
+void tst_qdbuscpp2xml::cleanupTestCase()
+{
+ qDeleteAll(m_tests);
+}
+
+void tst_qdbuscpp2xml::qdbuscpp2xml_data()
+{
+ QTest::addColumn<QString>("inputfile");
+ QTest::addColumn<int>("flags");
+
+ QBitArray doneFlags(QDBusConnection::ExportAllContents + 1);
+ for (int flag = 0x10; flag < QDBusConnection::ExportScriptableContents; flag += 0x10) {
+ QTest::newRow("xmlgenerator-" + QByteArray::number(flag)) << "test1" << flag;
+ doneFlags.setBit(flag);
+ for (int mask = QDBusConnection::ExportAllSlots; mask <= QDBusConnection::ExportAllContents; mask += 0x110) {
+ int flags = flag | mask;
+ if (doneFlags.testBit(flags))
+ continue;
+ QTest::newRow("xmlgenerator-" + QByteArray::number(flags)) << "test1" << flags;
+ doneFlags.setBit(flags);
+ }
+ }
+}
+
+void tst_qdbuscpp2xml::qdbuscpp2xml()
+{
+ QFETCH(QString, inputfile);
+ QFETCH(int, flags);
+
+ // qdbuscpp2xml considers these equivalent
+ if (flags & QDBusConnection::ExportScriptableSlots)
+ flags |= QDBusConnection::ExportScriptableInvokables;
+ if (flags & QDBusConnection::ExportNonScriptableSlots)
+ flags |= QDBusConnection::ExportNonScriptableInvokables;
+
+ if (flags & QDBusConnection::ExportScriptableInvokables)
+ flags |= QDBusConnection::ExportScriptableSlots;
+ if (flags & QDBusConnection::ExportNonScriptableInvokables)
+ flags |= QDBusConnection::ExportNonScriptableSlots;
+
+ QStringList options;
+ if (flags & QDBusConnection::ExportScriptableProperties) {
+ if (flags & QDBusConnection::ExportNonScriptableProperties)
+ options << "-P";
+ else
+ options << "-p";
+ }
+ if (flags & QDBusConnection::ExportScriptableSignals) {
+ if (flags & QDBusConnection::ExportNonScriptableSignals)
+ options << "-S";
+ else
+ options << "-s";
+ }
+ if (flags & QDBusConnection::ExportScriptableSlots) {
+ if (flags & QDBusConnection::ExportNonScriptableSlots)
+ options << "-M";
+ else
+ options << "-m";
+ }
+
+ // Launch
+ const QString command = QLatin1String("qdbuscpp2xml");
+ QProcess process;
+ process.start(command, QStringList() << options << (QFINDTESTDATA(inputfile + QStringLiteral(".h"))));
+ if (!process.waitForFinished()) {
+ const QString path = QString::fromLocal8Bit(qgetenv("PATH"));
+ QString message = QString::fromLatin1("'%1' could not be found when run from '%2'. Path: '%3' ").
+ arg(command, QDir::currentPath(), path);
+ QFAIL(qPrintable(message));
+ }
+ const QChar cr = QLatin1Char('\r');
+ const QString err = QString::fromLocal8Bit(process.readAllStandardError()).remove(cr);
+ const QString out = QString::fromAscii(process.readAllStandardOutput()).remove(cr);
+
+ if (!err.isEmpty()) {
+ qDebug() << "UNEXPECTED STDERR CONTENTS: " << err;
+ QFAIL("UNEXPECTED STDERR CONTENTS");
+ }
+
+ const QChar nl = QLatin1Char('\n');
+ const QStringList actualLines = out.split(nl);
+
+ QObject *testObject = m_tests.value(inputfile);
+
+ if (flags == 0)
+ flags = QDBusConnection::ExportScriptableContents
+ | QDBusConnection::ExportNonScriptableContents;
+
+ QString expected = qDBusGenerateMetaObjectXml(QString(), testObject->metaObject(), &QObject::staticMetaObject, flags);
+
+ expected = addXmlHeader(expected);
+
+ QCOMPARE(out, expected);
+}
+
+QTEST_APPLESS_MAIN(tst_qdbuscpp2xml)
+
+#include "tst_qdbuscpp2xml.moc"
diff --git a/tests/auto/tools/tools.pro b/tests/auto/tools/tools.pro
index 6bf6ddf64f..0a2821773f 100644
--- a/tests/auto/tools/tools.pro
+++ b/tests/auto/tools/tools.pro
@@ -5,3 +5,4 @@ SUBDIRS=\
moc \
rcc \
+contains(QT_CONFIG, dbus):SUBDIRS += qdbuscpp2xml
diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
index 82632a018c..e97b044dbc 100644
--- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
+++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
@@ -1275,7 +1275,7 @@ static int numberOfConnectedSignals(MySubWindow *subWindow)
QMetaMethod method = subWindow->metaObject()->method(i);
if (method.methodType() == QMetaMethod::Signal) {
QString signature(QLatin1String("2"));
- signature += QLatin1String(method.signature());
+ signature += QLatin1String(method.methodSignature().constData());
numConnectedSignals += subWindow->receivers(signature.toLatin1());
}
}
diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp
index ab26158f9a..6d7c5c3853 100644
--- a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp
+++ b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp
@@ -174,7 +174,7 @@ void tst_qmetaobject::indexOfMethod_data()
const QMetaObject *mo = &QTreeView::staticMetaObject;
for (int i = 0; i < mo->methodCount(); ++i) {
QMetaMethod method = mo->method(i);
- QByteArray sig = method.signature();
+ QByteArray sig = method.methodSignature();
QTest::newRow(sig) << sig;
}
}
@@ -197,7 +197,7 @@ void tst_qmetaobject::indexOfSignal_data()
QMetaMethod method = mo->method(i);
if (method.methodType() != QMetaMethod::Signal)
continue;
- QByteArray sig = method.signature();
+ QByteArray sig = method.methodSignature();
QTest::newRow(sig) << sig;
}
}
@@ -220,7 +220,7 @@ void tst_qmetaobject::indexOfSlot_data()
QMetaMethod method = mo->method(i);
if (method.methodType() != QMetaMethod::Slot)
continue;
- QByteArray sig = method.signature();
+ QByteArray sig = method.methodSignature();
QTest::newRow(sig) << sig;
}
}
diff --git a/tests/benchmarks/corelib/tools/qvector/qrawvector.h b/tests/benchmarks/corelib/tools/qvector/qrawvector.h
index 7e570d93ff..0fdfa86f1d 100644
--- a/tests/benchmarks/corelib/tools/qvector/qrawvector.h
+++ b/tests/benchmarks/corelib/tools/qvector/qrawvector.h
@@ -66,24 +66,18 @@ QT_BEGIN_NAMESPACE
template <typename T>
class QRawVector
{
- struct Data : QVectorData { T array[1]; };
+ typedef QVectorTypedData<T> Data;
T *m_begin;
int m_size;
int m_alloc;
public:
- //static Data dummy;
- //int headerOffset() { return (char*)&dummy.array - (char*)&dummy; }
- inline int headerOffset() const {
- // gcc complains about: return offsetof(Data, array); and also
- // does not like '0' in the expression below.
- return (char *)&(((Data *)(1))->array) - (char *)1;
- }
- inline Data *toBase(T *begin) const
- { return (Data*)((char*)begin - headerOffset()); }
- inline T *fromBase(void *d) const
- { return (T*)((char*)d + headerOffset()); }
+ static Data *toBase(T *begin)
+ { return (Data*)((char*)begin - offsetOfTypedData()); }
+ static T *fromBase(void *d)
+ { return (T*)((char*)d + offsetOfTypedData()); }
+
inline QRawVector()
{ m_begin = fromBase(0); m_alloc = m_size = 0; realloc(m_size, m_alloc, true); }
explicit QRawVector(int size);
@@ -270,17 +264,20 @@ private:
T *allocate(int alloc);
void realloc(int size, int alloc, bool ref);
void free(T *begin, int size);
- int sizeOfTypedData() {
- // this is more or less the same as sizeof(Data), except that it doesn't
- // count the padding at the end
- return reinterpret_cast<const char *>(&(reinterpret_cast<const Data *>(this))->array[1]) - reinterpret_cast<const char *>(this);
+
+ class AlignmentDummy { QVectorData header; T array[1]; };
+
+ static Q_DECL_CONSTEXPR int offsetOfTypedData()
+ {
+ // (non-POD)-safe offsetof(AlignmentDummy, array)
+ return (sizeof(QVectorData) + (alignOfTypedData() - 1)) & ~(alignOfTypedData() - 1);
}
- static inline int alignOfTypedData()
+ static Q_DECL_CONSTEXPR int alignOfTypedData()
{
#ifdef Q_ALIGNOF
- return qMax<int>(sizeof(void*), Q_ALIGNOF(Data));
+ return Q_ALIGNOF(AlignmentDummy);
#else
- return 0;
+ return sizeof(void *);
#endif
}
@@ -288,11 +285,11 @@ public:
QVector<T> mutateToVector()
{
Data *d = toBase(m_begin);
- d->ref = 1;
+ d->ref.initializeOwned();
d->alloc = m_alloc;
d->size = m_size;
- d->sharable = 0;
- d->capacity = 0;
+ d->capacityReserved = 0;
+ d->offset = offsetOfTypedData();
QVector<T> v;
*reinterpret_cast<QVectorData **>(&v) = d;
@@ -309,7 +306,7 @@ void QRawVector<T>::reserve(int asize)
template <typename T>
void QRawVector<T>::resize(int asize)
{ realloc(asize, (asize > m_alloc || (asize < m_size && asize < (m_alloc >> 1)))
- ? QVectorData::grow(sizeOfTypedData(), asize, sizeof(T), QTypeInfo<T>::isStatic)
+ ? QVectorData::grow(offsetOfTypedData(), asize, sizeof(T))
: m_alloc, false); }
template <typename T>
inline void QRawVector<T>::clear()
@@ -370,7 +367,7 @@ QRawVector<T> &QRawVector<T>::operator=(const QRawVector<T> &v)
template <typename T>
inline T *QRawVector<T>::allocate(int aalloc)
{
- QVectorData *d = QVectorData::allocate(sizeOfTypedData() + (aalloc - 1) * sizeof(T), alignOfTypedData());
+ QVectorData *d = QVectorData::allocate(offsetOfTypedData() + aalloc * sizeof(T), alignOfTypedData());
Q_CHECK_PTR(d);
return fromBase(d);
}
@@ -446,10 +443,9 @@ void QRawVector<T>::realloc(int asize, int aalloc, bool ref)
changed = true;
} else {
QT_TRY {
- QVectorData *mem = QVectorData::reallocate(
- toBase(m_begin), sizeOfTypedData() + (aalloc - 1) * sizeof(T),
- sizeOfTypedData()
-+ (xalloc - 1) * sizeof(T), alignOfTypedData());
+ QVectorData *mem = QVectorData::reallocate(toBase(m_begin),
+ offsetOfTypedData() + aalloc * sizeof(T),
+ offsetOfTypedData() + xalloc * sizeof(T), alignOfTypedData());
Q_CHECK_PTR(mem);
xbegin = fromBase(mem);
xsize = m_size;
@@ -511,8 +507,7 @@ void QRawVector<T>::append(const T &t)
{
if (m_size + 1 > m_alloc) {
const T copy(t);
- realloc(m_size, QVectorData::grow(sizeOfTypedData(), m_size + 1, sizeof(T),
- QTypeInfo<T>::isStatic), false);
+ realloc(m_size, QVectorData::grow(offsetOfTypedData(), m_size + 1, sizeof(T)), false);
if (QTypeInfo<T>::isComplex)
new (m_begin + m_size) T(copy);
else
@@ -533,8 +528,7 @@ typename QRawVector<T>::iterator QRawVector<T>::insert(iterator before, size_typ
if (n != 0) {
const T copy(t);
if (m_size + n > m_alloc)
- realloc(m_size, QVectorData::grow(sizeOfTypedData(), m_size + n, sizeof(T),
- QTypeInfo<T>::isStatic), false);
+ realloc(m_size, QVectorData::grow(offsetOfTypedData(), m_size + n, sizeof(T)), false);
if (QTypeInfo<T>::isStatic) {
T *b = m_begin + m_size;
T *i = m_begin + m_size + n;
diff --git a/tests/manual/cmake/CMakeLists.txt b/tests/manual/cmake/CMakeLists.txt
index 2d0164a47b..241454e763 100644
--- a/tests/manual/cmake/CMakeLists.txt
+++ b/tests/manual/cmake/CMakeLists.txt
@@ -89,3 +89,4 @@ expect_fail(fail5)
expect_pass("pass(needsquoting)6")
expect_pass(pass7)
expect_pass(pass8)
+expect_pass(pass9)
diff --git a/tests/manual/cmake/pass9/CMakeLists.txt b/tests/manual/cmake/pass9/CMakeLists.txt
new file mode 100644
index 0000000000..6aefd37696
--- /dev/null
+++ b/tests/manual/cmake/pass9/CMakeLists.txt
@@ -0,0 +1,32 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(pass9)
+
+find_package(Qt5DBus REQUIRED)
+
+include_directories(
+ ${Qt5DBus_INCLUDE_DIRS}
+)
+
+add_definitions(${Qt5DBus_DEFINITIONS})
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(my_srcs mydbusobject.cpp)
+
+qt5_wrap_cpp(moc_files mydbusobject.h)
+
+qt5_generate_dbus_interface(
+ mydbusobject.h
+ ${CMAKE_BINARY_DIR}/org.qtProject.Tests.MyDBusObject.xml
+)
+
+qt5_add_dbus_adaptor(my_srcs
+ ${CMAKE_BINARY_DIR}/org.qtProject.Tests.MyDBusObject.xml
+ mydbusobject.h
+ MyDBusObject
+)
+
+add_executable(myobject ${my_srcs} ${moc_files})
+target_link_libraries(myobject ${Qt5DBus_LIBRARIES})
diff --git a/tests/manual/cmake/pass9/mydbusobject.cpp b/tests/manual/cmake/pass9/mydbusobject.cpp
new file mode 100644
index 0000000000..ee211bbe9b
--- /dev/null
+++ b/tests/manual/cmake/pass9/mydbusobject.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mydbusobject.h"
+#include "mydbusobjectadaptor.h"
+
+MyDBusObject::MyDBusObject(QObject *parent)
+ : QObject(parent)
+{
+ new MyDBusObjectAdaptor(this);
+ emit someSignal();
+}
+
+int main(int argc, char **argv)
+{
+ MyDBusObject myDBusObject;
+ return 0;
+}
diff --git a/tests/manual/cmake/pass9/mydbusobject.h b/tests/manual/cmake/pass9/mydbusobject.h
new file mode 100644
index 0000000000..dd9a023ffe
--- /dev/null
+++ b/tests/manual/cmake/pass9/mydbusobject.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYDBUSOBJECT_H
+#define MYDBUSOBJECT_H
+
+#include <QObject>
+
+class MyDBusObject : public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.qtProject.Tests.MyDBusObject")
+public:
+ MyDBusObject(QObject *parent = 0);
+
+signals:
+ void someSignal();
+};
+
+#endif