summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/global/qflags/qflags.pro1
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp14
-rw-r--r--tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp68
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp32
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp42
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp49
-rw-r--r--tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp80
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp106
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp443
-rw-r--r--tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp10
-rw-r--r--tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp29
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp29
-rw-r--r--tests/auto/corelib/tools/qdatetime/qdatetime.pro5
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp12
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm82
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp20
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp280
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp76
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp12
19 files changed, 1214 insertions, 176 deletions
diff --git a/tests/auto/corelib/global/qflags/qflags.pro b/tests/auto/corelib/global/qflags/qflags.pro
index 9e80d5634b..3f78bc045b 100644
--- a/tests/auto/corelib/global/qflags/qflags.pro
+++ b/tests/auto/corelib/global/qflags/qflags.pro
@@ -3,3 +3,4 @@ TARGET = tst_qflags
QT = core testlib
SOURCES = tst_qflags.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+contains(QT_CONFIG, c++11): CONFIG += c++11 c++14
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp
index 4c74ac166b..15fe93298d 100644
--- a/tests/auto/corelib/global/qflags/tst_qflags.cpp
+++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp
@@ -94,6 +94,16 @@ void tst_QFlags::testFlagMultiBits() const
template <unsigned int N, typename T> bool verifyConstExpr(T n) { return n == N; }
+Q_DECL_RELAXED_CONSTEXPR Qt::MouseButtons testRelaxedConstExpr()
+{
+ Qt::MouseButtons value;
+ value = Qt::LeftButton | Qt::RightButton;
+ value |= Qt::MiddleButton;
+ value &= ~Qt::LeftButton;
+ value ^= Qt::RightButton;
+ return value;
+}
+
void tst_QFlags::constExpr()
{
#ifdef Q_COMPILER_CONSTEXPR
@@ -115,6 +125,10 @@ void tst_QFlags::constExpr()
QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::RightButton) | 0xff>(0xff));
QVERIFY(!verifyConstExpr<Qt::RightButton>(!Qt::MouseButtons(Qt::LeftButton)));
+
+#if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304
+ QVERIFY(verifyConstExpr<testRelaxedConstExpr()>(Qt::MiddleButton));
+#endif
#endif
}
diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
index c0b4ff654a..3304a09061 100644
--- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
+++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
@@ -41,14 +41,22 @@ class tst_QGetPutEnv : public QObject
Q_OBJECT
private slots:
void getSetCheck();
+ void intValue_data();
+ void intValue();
};
void tst_QGetPutEnv::getSetCheck()
{
const char varName[] = "should_not_exist";
+ bool ok;
+
QVERIFY(!qEnvironmentVariableIsSet(varName));
QVERIFY(qEnvironmentVariableIsEmpty(varName));
+ ok = true;
+ QCOMPARE(qEnvironmentVariableIntValue(varName), 0);
+ QCOMPARE(qEnvironmentVariableIntValue(varName, &ok), 0);
+ QVERIFY(!ok);
QByteArray result = qgetenv(varName);
QCOMPARE(result, QByteArray());
@@ -57,12 +65,20 @@ void tst_QGetPutEnv::getSetCheck()
QVERIFY(qEnvironmentVariableIsSet(varName));
QVERIFY(qEnvironmentVariableIsEmpty(varName));
+ ok = true;
+ QCOMPARE(qEnvironmentVariableIntValue(varName), 0);
+ QCOMPARE(qEnvironmentVariableIntValue(varName, &ok), 0);
+ QVERIFY(!ok);
#endif
QVERIFY(qputenv(varName, QByteArray("supervalue")));
QVERIFY(qEnvironmentVariableIsSet(varName));
QVERIFY(!qEnvironmentVariableIsEmpty(varName));
+ ok = true;
+ QCOMPARE(qEnvironmentVariableIntValue(varName), 0);
+ QCOMPARE(qEnvironmentVariableIntValue(varName, &ok), 0);
+ QVERIFY(!ok);
result = qgetenv(varName);
QVERIFY(result == "supervalue");
@@ -72,9 +88,61 @@ void tst_QGetPutEnv::getSetCheck()
QVERIFY(qunsetenv(varName));
QVERIFY(!qEnvironmentVariableIsSet(varName));
QVERIFY(qEnvironmentVariableIsEmpty(varName));
+ ok = true;
+ QCOMPARE(qEnvironmentVariableIntValue(varName), 0);
+ QCOMPARE(qEnvironmentVariableIntValue(varName, &ok), 0);
+ QVERIFY(!ok);
result = qgetenv(varName);
QCOMPARE(result, QByteArray());
}
+void tst_QGetPutEnv::intValue_data()
+{
+ QTest::addColumn<QByteArray>("value");
+ QTest::addColumn<int>("expected");
+ QTest::addColumn<bool>("ok");
+
+ // most non-success cases already tested in getSetCheck()
+
+#define ROW(x, i, b) \
+ QTest::newRow(#x) << QByteArray(#x) << (i) << (b)
+ ROW(auto, 0, false);
+ ROW(0, 0, true);
+ ROW(1, 1, true);
+ ROW(010, 8, true);
+ ROW(0x10, 16, true);
+ ROW(-1, -1, true);
+ ROW(-010, -8, true);
+ // ROW(0xffffffff, -1, true); // could be expected, but not how QByteArray::toInt() works
+ ROW(0xffffffff, 0, false);
+ const int bases[] = {10, 8, 16};
+ for (size_t i = 0; i < sizeof bases / sizeof *bases; ++i) {
+ QTest::newRow(qPrintable(QString().sprintf("INT_MAX, base %d", bases[i])))
+ << QByteArray::number(INT_MAX) << INT_MAX << true;
+ QTest::newRow(qPrintable(QString().sprintf("INT_MAX+1, base %d", bases[i])))
+ << QByteArray::number(qlonglong(INT_MAX) + 1) << 0 << false;
+ QTest::newRow(qPrintable(QString().sprintf("INT_MIN, base %d", bases[i])))
+ << QByteArray::number(INT_MIN) << INT_MIN << true;
+ QTest::newRow(qPrintable(QString().sprintf("INT_MIN-1, base %d", bases[i])))
+ << QByteArray::number(qlonglong(INT_MIN) - 1) << 0 << false;
+ };
+}
+
+void tst_QGetPutEnv::intValue()
+{
+ const char varName[] = "should_not_exist";
+
+ QFETCH(QByteArray, value);
+ QFETCH(int, expected);
+ QFETCH(bool, ok);
+
+ bool actualOk = !ok;
+
+ QVERIFY(qputenv(varName, value));
+ QCOMPARE(qEnvironmentVariableIntValue(varName), expected);
+ QCOMPARE(qEnvironmentVariableIntValue(varName, &actualOk), expected);
+ QCOMPARE(actualOk, ok);
+}
+
QTEST_MAIN(tst_QGetPutEnv)
#include "tst_qgetputenv.moc"
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 53ed1bc9a0..122427a021 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -96,6 +96,7 @@ private slots:
void changeSourceData_data();
void changeSourceData();
void changeSourceDataKeepsStableSorting_qtbug1548();
+ void changeSourceDataForwardsRoles_qtbug35440();
void sortFilterRole();
void selectionFilteredOut();
void match_data();
@@ -2084,6 +2085,37 @@ void tst_QSortFilterProxyModel::changeSourceDataKeepsStableSorting_qtbug1548()
checkSortedTableModel(&model, rows);
}
+void tst_QSortFilterProxyModel::changeSourceDataForwardsRoles_qtbug35440()
+{
+ QStringList strings;
+ for (int i = 0; i < 100; ++i)
+ strings << QString::number(i);
+
+ QStringListModel model(strings);
+
+ QSortFilterProxyModel proxy;
+ proxy.setSourceModel(&model);
+ proxy.sort(0, Qt::AscendingOrder);
+
+ QSignalSpy spy(&proxy, &QAbstractItemModel::dataChanged);
+ QVERIFY(spy.isValid());
+ QCOMPARE(spy.length(), 0);
+
+ QModelIndex index;
+
+ index = model.index(0, 0);
+ QVERIFY(index.isValid());
+ model.setData(index, QStringLiteral("teststring"), Qt::DisplayRole);
+ QCOMPARE(spy.length(), 1);
+ QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), QVector<int>() << Qt::DisplayRole);
+
+ index = model.index(1, 0);
+ QVERIFY(index.isValid());
+ model.setData(index, QStringLiteral("teststring2"), Qt::EditRole);
+ QCOMPARE(spy.length(), 2);
+ QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), QVector<int>() << Qt::EditRole);
+}
+
void tst_QSortFilterProxyModel::sortFilterRole()
{
QStandardItemModel model;
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index 56a5a28c50..997ceaf7b9 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -90,7 +90,9 @@ private Q_SLOTS:
void fromVariant();
void fromVariantMap();
+ void fromVariantHash();
void toVariantMap();
+ void toVariantHash();
void toVariantList();
void toJson();
@@ -1165,6 +1167,17 @@ void tst_QtJson::fromVariantMap()
QCOMPARE(array.at(3).toString(), QLatin1String("foo"));
}
+void tst_QtJson::fromVariantHash()
+{
+ QVariantHash map;
+ map.insert(QLatin1String("key1"), QLatin1String("value1"));
+ map.insert(QLatin1String("key2"), QLatin1String("value2"));
+ QJsonObject object = QJsonObject::fromVariantHash(map);
+ QCOMPARE(object.size(), 2);
+ QCOMPARE(object.value(QLatin1String("key1")), QJsonValue(QLatin1String("value1")));
+ QCOMPARE(object.value(QLatin1String("key2")), QJsonValue(QLatin1String("value2")));
+}
+
void tst_QtJson::toVariantMap()
{
QCOMPARE(QMetaType::Type(QJsonValue(QJsonObject()).toVariant().type()), QMetaType::QVariantMap); // QTBUG-32524
@@ -1196,6 +1209,35 @@ void tst_QtJson::toVariantMap()
QCOMPARE(list.at(3), QVariant());
}
+void tst_QtJson::toVariantHash()
+{
+ QJsonObject object;
+ QVariantHash hash = object.toVariantHash();
+ QVERIFY(hash.isEmpty());
+
+ object.insert("Key", QString("Value"));
+ object.insert("null", QJsonValue());
+ QJsonArray array;
+ array.append(true);
+ array.append(999.);
+ array.append(QLatin1String("string"));
+ array.append(QJsonValue());
+ object.insert("Array", array);
+
+ hash = object.toVariantHash();
+
+ QCOMPARE(hash.size(), 3);
+ QCOMPARE(hash.value("Key"), QVariant(QString("Value")));
+ QCOMPARE(hash.value("null"), QVariant());
+ QCOMPARE(hash.value("Array").type(), QVariant::List);
+ QVariantList list = hash.value("Array").toList();
+ QCOMPARE(list.size(), 4);
+ QCOMPARE(list.at(0), QVariant(true));
+ QCOMPARE(list.at(1), QVariant(999.));
+ QCOMPARE(list.at(2), QVariant(QLatin1String("string")));
+ QCOMPARE(list.at(3), QVariant());
+}
+
void tst_QtJson::toVariantList()
{
QCOMPARE(QMetaType::Type(QJsonValue(QJsonArray()).toVariant().type()), QMetaType::QVariantList); // QTBUG-32524
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
index 1d39280afb..18de761e2a 100644
--- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
+++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -50,6 +51,8 @@ private slots:
void comparisonOperators();
void fromSignal();
+
+ void gadget();
};
struct CustomType { };
@@ -727,5 +730,51 @@ void tst_QMetaMethod::fromSignal()
#undef FROMSIGNAL_HELPER
}
+class MyGadget {
+ Q_GADGET
+public:
+ QString m_value;
+ Q_INVOKABLE void setValue(const QString &value) { m_value = value; }
+ Q_INVOKABLE QString getValue() { return m_value; }
+};
+
+void tst_QMetaMethod::gadget()
+{
+ int idx;
+
+ idx = MyGadget::staticMetaObject.indexOfMethod("setValue(QString)");
+ QVERIFY(idx >= 0);
+ QMetaMethod setValueMethod = MyGadget::staticMetaObject.method(idx);
+ QVERIFY(setValueMethod.isValid());
+
+ idx = MyGadget::staticMetaObject.indexOfMethod("getValue()");
+ QVERIFY(idx >= 0);
+ QMetaMethod getValueMethod = MyGadget::staticMetaObject.method(idx);
+ QVERIFY(getValueMethod.isValid());
+
+ {
+ MyGadget gadget;
+ QString string;
+
+ QVERIFY(getValueMethod.invokeOnGadget(&gadget, Q_RETURN_ARG(QString, string)));
+ QCOMPARE(string, gadget.m_value);
+
+ QVERIFY(setValueMethod.invokeOnGadget(&gadget, Q_ARG(QString, QLatin1String("hello"))));
+ QCOMPARE(gadget.m_value, QLatin1String("hello"));
+
+ QVERIFY(getValueMethod.invokeOnGadget(&gadget, Q_RETURN_ARG(QString, string)));
+ QCOMPARE(string, gadget.m_value);
+ }
+
+ {
+ // Call with null should not crash
+ MyGadget *gadget = Q_NULLPTR;
+ QString string;
+ QVERIFY(!setValueMethod.invokeOnGadget(gadget, Q_ARG(QString, QLatin1String("hi"))));
+ QVERIFY(!getValueMethod.invokeOnGadget(gadget, Q_RETURN_ARG(QString, string)));
+ }
+}
+
+
QTEST_MAIN(tst_QMetaMethod)
#include "tst_qmetamethod.moc"
diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp
index 5cac80191c..df76dfc47f 100644
--- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp
+++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -50,6 +51,8 @@ private slots:
void hasStdCppSet();
void isConstant();
void isFinal();
+ void gadget();
+ void readAndWriteWithLazyRegistration();
public:
enum EnumType { EnumType1 };
@@ -103,5 +106,82 @@ void tst_QMetaProperty::isFinal()
QVERIFY(!prop.isFinal());
}
+class MyGadget {
+ Q_GADGET
+ Q_PROPERTY(QString value READ getValue WRITE setValue RESET resetValue)
+public:
+ QString m_value;
+ void setValue(const QString &value) { m_value = value; }
+ QString getValue() { return m_value; }
+ void resetValue() { m_value = QLatin1Literal("reset"); }
+};
+
+void tst_QMetaProperty::gadget()
+{
+ const QMetaObject *mo = &MyGadget::staticMetaObject;
+ QMetaProperty valueProp = mo->property(mo->indexOfProperty("value"));
+ QVERIFY(valueProp.isValid());
+ {
+ MyGadget g;
+ QString hello = QLatin1Literal("hello");
+ QVERIFY(valueProp.writeOnGadget(&g, hello));
+ QCOMPARE(g.m_value, QLatin1String("hello"));
+ QCOMPARE(valueProp.readOnGadget(&g), QVariant(hello));
+ QVERIFY(valueProp.resetOnGadget(&g));
+ QCOMPARE(valueProp.readOnGadget(&g), QVariant(QLatin1String("reset")));
+ }
+}
+
+struct CustomReadObject : QObject
+{
+ Q_OBJECT
+};
+
+struct CustomWriteObject : QObject
+{
+ Q_OBJECT
+};
+
+struct CustomWriteObjectChild : CustomWriteObject
+{
+ Q_OBJECT
+};
+
+struct TypeLazyRegistration : QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(CustomReadObject *read MEMBER _read)
+ Q_PROPERTY(CustomWriteObject *write MEMBER _write)
+
+ CustomReadObject *_read;
+ CustomWriteObject *_write;
+
+public:
+ TypeLazyRegistration()
+ : _read()
+ , _write()
+ {}
+};
+
+void tst_QMetaProperty::readAndWriteWithLazyRegistration()
+{
+ QCOMPARE(QMetaType::type("CustomReadObject*"), int(QMetaType::UnknownType));
+ QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType));
+
+ TypeLazyRegistration o;
+ QVERIFY(o.property("read").isValid());
+ QVERIFY(QMetaType::type("CustomReadObject*") != QMetaType::UnknownType);
+ QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType));
+
+ CustomWriteObjectChild data;
+ QVariant value = QVariant::fromValue(&data); // this register CustomWriteObjectChild
+ // check if base classes are not registered automatically, otherwise this test would be meaningless
+ QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType));
+ QVERIFY(o.setProperty("write", value));
+ QVERIFY(QMetaType::type("CustomWriteObject*") != QMetaType::UnknownType);
+ QCOMPARE(o.property("write").value<CustomWriteObjectChild*>(), &data);
+}
+
+
QTEST_MAIN(tst_QMetaProperty)
#include "tst_qmetaproperty.moc"
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index a35896283a..e3ef2b6714 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -79,6 +79,10 @@ private slots:
void normalizedTypes();
void typeName_data();
void typeName();
+ void type_data();
+ void type();
+ void type_fromSubString_data();
+ void type_fromSubString();
void create_data();
void create();
void createCopy_data();
@@ -109,6 +113,7 @@ private slots:
void saveAndLoadBuiltin_data();
void saveAndLoadBuiltin();
void saveAndLoadCustom();
+ void metaObject_data();
void metaObject();
void constexprMetaTypeIds();
void constRefs();
@@ -385,6 +390,61 @@ void tst_QMetaType::typeName()
QCOMPARE(name.toLatin1(), QMetaObject::normalizedType(name.toLatin1().constData()));
}
+void tst_QMetaType::type_data()
+{
+ QTest::addColumn<QMetaType::Type>("aType");
+ QTest::addColumn<QByteArray>("aTypeName");
+
+#define TST_QMETATYPE_TYPE_DATA(MetaTypeName, MetaTypeId, RealType)\
+ QTest::newRow(#RealType) << QMetaType::MetaTypeName << QByteArray( #RealType );
+#define TST_QMETATYPE_TYPE_DATA_ALIAS(MetaTypeName, MetaTypeId, AliasType, RealTypeString)\
+ QTest::newRow(RealTypeString) << QMetaType::MetaTypeName << QByteArray( #AliasType );
+
+ QTest::newRow("empty") << QMetaType::UnknownType << QByteArray();
+
+ QT_FOR_EACH_STATIC_TYPE(TST_QMETATYPE_TYPE_DATA)
+ QT_FOR_EACH_STATIC_ALIAS_TYPE(TST_QMETATYPE_TYPE_DATA_ALIAS)
+
+#undef TST_QMETATYPE_TYPE_DATA
+#undef TST_METATYPE_TYPE_DATA_ALIAS
+}
+
+void tst_QMetaType::type()
+{
+ QFETCH(QMetaType::Type, aType);
+ QFETCH(QByteArray, aTypeName);
+
+ // QMetaType::type(QByteArray)
+ QCOMPARE(QMetaType::type(aTypeName), int(aType));
+ // QMetaType::type(const char *)
+ QCOMPARE(QMetaType::type(aTypeName.constData()), int(aType));
+}
+
+void tst_QMetaType::type_fromSubString_data()
+{
+ QTest::addColumn<int>("offset");
+ QTest::addColumn<int>("size");
+ QTest::addColumn<int>("expectedType");
+
+ // The test string is defined in the test function below
+ QTest::newRow("int") << 0 << 3 << int(QMetaType::Int);
+ QTest::newRow("boo") << 3 << 3 << 0;
+ QTest::newRow("bool") << 3 << 4 << int(QMetaType::Bool);
+ QTest::newRow("intbool") << 0 << 7 << 0;
+ QTest::newRow("QMetaType::Type") << 7 << 15 << ::qMetaTypeId<QMetaType::Type>();
+ QTest::newRow("double") << 22 << 6 << int(QMetaType::Double);
+}
+
+void tst_QMetaType::type_fromSubString()
+{
+ static const char *types = "intboolQMetaType::Typedoublexxx";
+ QFETCH(int, offset);
+ QFETCH(int, size);
+ QFETCH(int, expectedType);
+ QByteArray ba = QByteArray::fromRawData(types + offset, size);
+ QCOMPARE(QMetaType::type(ba), expectedType);
+}
+
#define FOR_EACH_PRIMITIVE_METATYPE(F) \
QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \
QT_FOR_EACH_STATIC_CORE_POINTER(F) \
@@ -968,7 +1028,9 @@ void tst_QMetaType::flagsBinaryCompatibility5_0()
QFETCH(quint32, id);
QFETCH(quint32, flags);
- QCOMPARE(quint32(QMetaType::typeFlags(id)), flags);
+ quint32 mask_5_0 = 0x1ff; // Only compare the values that were already defined in 5.0
+
+ QCOMPARE(quint32(QMetaType::typeFlags(id)) & mask_5_0, flags);
}
void tst_QMetaType::construct_data()
@@ -1772,17 +1834,41 @@ void tst_QMetaType::saveAndLoadCustom()
QCOMPARE(stream.status(), QDataStream::ReadPastEnd);
}
-void tst_QMetaType::metaObject()
+struct MyGadget {
+ Q_GADGET;
+};
+
+Q_DECLARE_METATYPE(MyGadget);
+Q_DECLARE_METATYPE(const QMetaObject *);
+
+void tst_QMetaType::metaObject_data()
{
- QCOMPARE(QMetaType::metaObjectForType(QMetaType::QObjectStar), &QObject::staticMetaObject);
- QCOMPARE(QMetaType::metaObjectForType(::qMetaTypeId<QFile*>()), &QFile::staticMetaObject);
- QCOMPARE(QMetaType::metaObjectForType(::qMetaTypeId<MyObject*>()), &MyObject::staticMetaObject);
- QCOMPARE(QMetaType::metaObjectForType(QMetaType::Int), static_cast<const QMetaObject *>(0));
+ QTest::addColumn<int>("type");
+ QTest::addColumn<const QMetaObject*>("result");
+ QTest::addColumn<bool>("isGadget");
+ QTest::addColumn<bool>("isQObjectPtr");
+
+ QTest::newRow("QObject") << int(QMetaType::QObjectStar) << &QObject::staticMetaObject << false << true;
+ QTest::newRow("QFile*") << ::qMetaTypeId<QFile*>() << &QFile::staticMetaObject << false << true;
+ QTest::newRow("MyObject*") << ::qMetaTypeId<MyObject*>() << &MyObject::staticMetaObject << false << true;
+ QTest::newRow("int") << int(QMetaType::Int) << static_cast<const QMetaObject *>(0) << false << false;
+ QTest::newRow("QEasingCurve") << ::qMetaTypeId<QEasingCurve>() << &QEasingCurve::staticMetaObject << true << false;
+ QTest::newRow("MyGadget") << ::qMetaTypeId<MyGadget>() << &MyGadget::staticMetaObject << true << false;
+}
- QCOMPARE(QMetaType(QMetaType::QObjectStar).metaObject(), &QObject::staticMetaObject);
- QCOMPARE(QMetaType(::qMetaTypeId<QFile*>()).metaObject(), &QFile::staticMetaObject);
- QCOMPARE(QMetaType(::qMetaTypeId<MyObject*>()).metaObject(), &MyObject::staticMetaObject);
- QCOMPARE(QMetaType(QMetaType::Int).metaObject(), static_cast<const QMetaObject *>(0));
+
+void tst_QMetaType::metaObject()
+{
+ QFETCH(int, type);
+ QFETCH(const QMetaObject *, result);
+ QFETCH(bool, isGadget);
+ QFETCH(bool, isQObjectPtr);
+
+ QCOMPARE(QMetaType::metaObjectForType(type), result);
+ QMetaType mt(type);
+ QCOMPARE(mt.metaObject(), result);
+ QCOMPARE(!!(mt.flags() & QMetaType::IsGadget), isGadget);
+ QCOMPARE(!!(mt.flags() & QMetaType::PointerToQObject), isQObjectPtr);
}
#define METATYPE_ID_FUNCTION(Type, MetaTypeId, Name) \
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 41a6de214a..757576c6da 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -43,9 +43,10 @@
#include <qlocale.h>
#include <qdebug.h>
#include <qjsondocument.h>
-
+#include <quuid.h>
#include <limits.h>
+#include <float.h>
#include <QLinkedList>
#include <QRegularExpression>
@@ -169,8 +170,9 @@ private slots:
void operator_eq_eq_data();
void operator_eq_eq();
-
void operator_eq_eq_rhs();
+ void compareNumbers_data() const;
+ void compareNumbers() const;
void typeName_data();
void typeName();
@@ -213,7 +215,10 @@ private slots:
void toIntFromQString() const;
void toIntFromDouble() const;
void setValue();
+ void fpStringRoundtrip_data() const;
+ void fpStringRoundtrip() const;
+ void numericalConvert_data();
void numericalConvert();
void moreCustomTypes();
void movabilityTest();
@@ -985,7 +990,7 @@ void tst_QVariant::toByteArray_data()
QTest::newRow( "int" ) << QVariant( -123 ) << QByteArray( "-123" );
QTest::newRow( "uint" ) << QVariant( (uint)123 ) << QByteArray( "123" );
QTest::newRow( "double" ) << QVariant( 123.456 ) << QByteArray( "123.456" );
- QTest::newRow( "float" ) << QVariant( 123.456f ) << QByteArray( "123.456" );
+ QTest::newRow( "float" ) << QVariant( 123.456f ) << QByteArray( "123.456001" );
QTest::newRow( "longlong" ) << QVariant( (qlonglong)34 ) << QByteArray( "34" );
QTest::newRow( "ulonglong" ) << QVariant( (qulonglong)34 ) << QByteArray( "34" );
}
@@ -1011,7 +1016,7 @@ void tst_QVariant::toString_data()
QTest::newRow( "int" ) << QVariant( -123 ) << QString( "-123" );
QTest::newRow( "uint" ) << QVariant( (uint)123 ) << QString( "123" );
QTest::newRow( "double" ) << QVariant( 123.456 ) << QString( "123.456" );
- QTest::newRow( "float" ) << QVariant( 123.456f ) << QString( "123.456" );
+ QTest::newRow( "float" ) << QVariant( 123.456f ) << QString( "123.456001" );
QTest::newRow( "bool" ) << QVariant( true ) << QString( "true" );
QTest::newRow( "qdate" ) << QVariant( QDate( 2002, 1, 1 ) ) << QString( "2002-01-01" );
QTest::newRow( "qtime" ) << QVariant( QTime( 12, 34, 56 ) ) << QString( "12:34:56" );
@@ -1367,12 +1372,12 @@ void tst_QVariant::operator_eq_eq_data()
QVariant mUIntQString(QString("42"));
QVariant mDouble(42.11);
- QVariant mDoubleString(QByteArray("42.11"));
- QVariant mDoubleQString(QString("42.11"));
+ QVariant mDoubleString(QByteArray("42.109999999999999"));
+ QVariant mDoubleQString(QString("42.109999999999999"));
QVariant mFloat(42.11f);
- QVariant mFloatString(QByteArray("42.11"));
- QVariant mFloatQString(QString("42.11"));
+ QVariant mFloatString(QByteArray("42.1100006"));
+ QVariant mFloatQString(QString("42.1100006"));
QVariant mLongLong((qlonglong)-42);
QVariant mLongLongString(QByteArray("-42"));
@@ -1433,6 +1438,13 @@ void tst_QVariant::operator_eq_eq_data()
// ### many other combinations missing
{
+ // QUuid can convert to QString, but not the opposite
+ QUuid uuid(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ QTest::newRow("uuidstring") << QVariant(uuid) << QVariant(uuid.toString()) << true;
+ QTest::newRow("stringuuid") << QVariant(uuid.toString()) << QVariant(uuid) << true;
+ }
+
+ {
QMap<QString, QVariant> map1;
map1.insert( "X", 1 );
@@ -1580,6 +1592,326 @@ void tst_QVariant::operator_eq_eq_rhs()
#endif
}
+void tst_QVariant::compareNumbers_data() const
+{
+ typedef signed char schar;
+ QTest::addColumn<QVariant>("v1");
+ QTest::addColumn<QVariant>("v2");
+ QTest::addColumn<int>("expected");
+
+ // sanity checking: same types
+ QTest::newRow("bool1") << QVariant(false) << QVariant(false) << 0;
+ QTest::newRow("bool2") << QVariant(true) << QVariant(true) << 0;
+ QTest::newRow("bool3") << QVariant(false) << QVariant(true) << -1;
+ QTest::newRow("bool4") << QVariant(true) << QVariant(false) << +1;
+
+ QTest::newRow("char1") << qVariantFromValue(char(0)) << qVariantFromValue(char(0)) << 0;
+ QTest::newRow("char2") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(CHAR_MAX) << 0;
+ QTest::newRow("char3") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(CHAR_MIN) << 0;
+ QTest::newRow("char4") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(CHAR_MAX) << -1;
+ QTest::newRow("char5") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(CHAR_MIN) << +1;
+
+ QTest::newRow("schar1") << qVariantFromValue(schar(0)) << qVariantFromValue(schar(0)) << 0;
+ QTest::newRow("schar2") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(SCHAR_MAX) << 0;
+ QTest::newRow("schar3") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(SCHAR_MIN) << 0;
+ QTest::newRow("schar4") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(SCHAR_MAX) << -1;
+ QTest::newRow("schar5") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(SCHAR_MIN) << +1;
+
+ QTest::newRow("uchar1") << qVariantFromValue(uchar(0)) << qVariantFromValue(uchar(0)) << 0;
+ QTest::newRow("uchar2") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(UCHAR_MAX) << 0;
+ QTest::newRow("uchar3") << qVariantFromValue(uchar(0)) << qVariantFromValue(UCHAR_MAX) << -1;
+ QTest::newRow("uchar4") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(uchar(0)) << +1;
+
+ QTest::newRow("short1") << qVariantFromValue(short(0)) << qVariantFromValue(short(0)) << 0;
+ QTest::newRow("short2") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(SHRT_MAX) << 0;
+ QTest::newRow("short3") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(SHRT_MIN) << 0;
+ QTest::newRow("short4") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(SHRT_MAX) << -1;
+ QTest::newRow("short5") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(SHRT_MIN) << +1;
+
+ QTest::newRow("ushort1") << qVariantFromValue(ushort(0)) << qVariantFromValue(ushort(0)) << 0;
+ QTest::newRow("ushort2") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(USHRT_MAX) << 0;
+ QTest::newRow("ushort3") << qVariantFromValue(ushort(0)) << qVariantFromValue(USHRT_MAX) << -1;
+ QTest::newRow("ushort4") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(ushort(0)) << +1;
+
+ QTest::newRow("int1") << qVariantFromValue(int(0)) << qVariantFromValue(int(0)) << 0;
+ QTest::newRow("int2") << qVariantFromValue(INT_MAX) << qVariantFromValue(INT_MAX) << 0;
+ QTest::newRow("int3") << qVariantFromValue(INT_MIN) << qVariantFromValue(INT_MIN) << 0;
+ QTest::newRow("int4") << qVariantFromValue(INT_MIN) << qVariantFromValue(INT_MAX) << -1;
+ QTest::newRow("int5") << qVariantFromValue(INT_MAX) << qVariantFromValue(INT_MIN) << +1;
+
+ QTest::newRow("uint1") << qVariantFromValue(uint(0)) << qVariantFromValue(uint(0)) << 0;
+ QTest::newRow("uint2") << qVariantFromValue(UINT_MAX) << qVariantFromValue(UINT_MAX) << 0;
+ QTest::newRow("uint3") << qVariantFromValue(uint(0)) << qVariantFromValue(UINT_MAX) << -1;
+ QTest::newRow("uint4") << qVariantFromValue(UINT_MAX) << qVariantFromValue(uint(0)) << +1;
+
+ QTest::newRow("long1") << qVariantFromValue(long(0)) << qVariantFromValue(long(0)) << 0;
+ QTest::newRow("long2") << qVariantFromValue(LONG_MAX) << qVariantFromValue(LONG_MAX) << 0;
+ QTest::newRow("long3") << qVariantFromValue(LONG_MIN) << qVariantFromValue(LONG_MIN) << 0;
+ QTest::newRow("long4") << qVariantFromValue(LONG_MIN) << qVariantFromValue(LONG_MAX) << -1;
+ QTest::newRow("long5") << qVariantFromValue(LONG_MAX) << qVariantFromValue(LONG_MIN) << +1;
+
+ QTest::newRow("ulong1") << qVariantFromValue(ulong(0)) << qVariantFromValue(ulong(0)) << 0;
+ QTest::newRow("ulong2") << qVariantFromValue(ULONG_MAX) << qVariantFromValue(ULONG_MAX) << 0;
+ QTest::newRow("ulong3") << qVariantFromValue(ulong(0)) << qVariantFromValue(ULONG_MAX) << -1;
+ QTest::newRow("ulong4") << qVariantFromValue(ULONG_MAX) << qVariantFromValue(ulong(0)) << +1;
+
+ QTest::newRow("llong1") << qVariantFromValue(qlonglong(0)) << qVariantFromValue(qlonglong(0)) << 0;
+ QTest::newRow("llong2") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(LLONG_MAX) << 0;
+ QTest::newRow("llong3") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(LLONG_MIN) << 0;
+ QTest::newRow("llong4") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(LLONG_MAX) << -1;
+ QTest::newRow("llong5") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(LLONG_MIN) << +1;
+
+ QTest::newRow("ullong1") << qVariantFromValue(qulonglong(0)) << qVariantFromValue(qulonglong(0)) << 0;
+ QTest::newRow("ullong2") << qVariantFromValue(ULLONG_MAX) << qVariantFromValue(ULLONG_MAX) << 0;
+ QTest::newRow("ullong3") << qVariantFromValue(qulonglong(0)) << qVariantFromValue(ULLONG_MAX) << -1;
+ QTest::newRow("ullong4") << qVariantFromValue(ULLONG_MAX) << qVariantFromValue(qulonglong(0)) << +1;
+
+ QTest::newRow("float1") << qVariantFromValue(0.f) << qVariantFromValue(0.f) << 0;
+ QTest::newRow("float2") << qVariantFromValue(-1.f) << qVariantFromValue(0.f) << -1;
+ QTest::newRow("float3") << qVariantFromValue(0.f) << qVariantFromValue(-1.f) << +1;
+ QTest::newRow("float4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.f) << -1;
+ QTest::newRow("float5") << qVariantFromValue(0.f) << qVariantFromValue(-float(qInf())) << +1;
+
+ QTest::newRow("double1") << qVariantFromValue(0.) << qVariantFromValue(0.) << 0;
+ QTest::newRow("double2") << qVariantFromValue(-1.) << qVariantFromValue(0.) << -1;
+ QTest::newRow("double3") << qVariantFromValue(0.) << qVariantFromValue(-1.) << +1;
+ QTest::newRow("double4") << qVariantFromValue(-qInf()) << qVariantFromValue(0.) << -1;
+ QTest::newRow("double5") << qVariantFromValue(0.) << qVariantFromValue(-qInf()) << +1;
+
+ // mixed comparisons
+ // fp + fp
+ QTest::newRow("float+double1") << qVariantFromValue(0.f) << qVariantFromValue(0.) << 0;
+ QTest::newRow("float+double2") << qVariantFromValue(-1.f) << qVariantFromValue(0.) << -1;
+ QTest::newRow("float+double3") << qVariantFromValue(0.f) << qVariantFromValue(-1.) << +1;
+ QTest::newRow("float+double4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.) << -1;
+ QTest::newRow("float+double5") << qVariantFromValue(0.f) << qVariantFromValue(-qInf()) << +1;
+
+ // fp + int
+ QTest::newRow("float+int1") << qVariantFromValue(0.f) << qVariantFromValue(0) << 0;
+ QTest::newRow("double+int1") << qVariantFromValue(0.) << qVariantFromValue(0) << 0;
+ QTest::newRow("float+int2") << qVariantFromValue(-1.f) << qVariantFromValue(0) << -1;
+ QTest::newRow("double+int2") << qVariantFromValue(-1.) << qVariantFromValue(0) << -1;
+ QTest::newRow("float+int3") << qVariantFromValue(0.f) << qVariantFromValue(-1) << +1;
+ QTest::newRow("double+int3") << qVariantFromValue(0.) << qVariantFromValue(-1) << +1;
+ QTest::newRow("float+int4") << qVariantFromValue(1.5f) << qVariantFromValue(1) << +1;
+ QTest::newRow("double+int4") << qVariantFromValue(1.5) << qVariantFromValue(1) << +1;
+
+ // fp + uint
+ QTest::newRow("float+uint1") << qVariantFromValue(0.f) << qVariantFromValue(0U) << 0;
+ QTest::newRow("double+uint1") << qVariantFromValue(0.) << qVariantFromValue(0U) << 0;
+ QTest::newRow("float+uint2") << qVariantFromValue(-1.f) << qVariantFromValue(0U) << -1;
+ QTest::newRow("double+uint2") << qVariantFromValue(-1.) << qVariantFromValue(0U) << -1;
+ QTest::newRow("float+uint3") << qVariantFromValue(0.f) << qVariantFromValue(1U) << -1;
+ QTest::newRow("double+uint3") << qVariantFromValue(0.) << qVariantFromValue(1U) << -1;
+ QTest::newRow("float+uint4") << qVariantFromValue(1.5f) << qVariantFromValue(1U) << +1;
+ QTest::newRow("double+uint4") << qVariantFromValue(1.5) << qVariantFromValue(1U) << +1;
+
+ // lower ranked + int
+ QTest::newRow("bool+int1") << qVariantFromValue(false) << qVariantFromValue(0) << 0;
+ QTest::newRow("bool+int2") << qVariantFromValue(false) << qVariantFromValue(1) << -1;
+ QTest::newRow("bool+int3") << qVariantFromValue(true) << qVariantFromValue(0) << +1;
+ QTest::newRow("bool+int4") << qVariantFromValue(true) << qVariantFromValue(1) << 0;
+ QTest::newRow("bool+int5") << qVariantFromValue(true) << qVariantFromValue(2) << -1;
+
+ QTest::newRow("char+int1") << qVariantFromValue(char(0)) << qVariantFromValue(0) << 0;
+ QTest::newRow("char+int2") << qVariantFromValue(char(0)) << qVariantFromValue(1) << -1;
+ QTest::newRow("char+int3") << qVariantFromValue(char(1)) << qVariantFromValue(0) << +1;
+ QTest::newRow("char+int4") << qVariantFromValue(char(1)) << qVariantFromValue(1) << 0;
+ if (std::numeric_limits<char>::is_signed) {
+ QTest::newRow("char+int5") << qVariantFromValue(char(-1)) << qVariantFromValue(0) << -1;
+ QTest::newRow("char+int6") << qVariantFromValue(char(-1)) << qVariantFromValue(-1) << 0;
+ }
+
+ QTest::newRow("schar+int1") << qVariantFromValue(schar(0)) << qVariantFromValue(0) << 0;
+ QTest::newRow("schar+int2") << qVariantFromValue(schar(0)) << qVariantFromValue(1) << -1;
+ QTest::newRow("schar+int3") << qVariantFromValue(schar(1)) << qVariantFromValue(0) << +1;
+ QTest::newRow("schar+int4") << qVariantFromValue(schar(1)) << qVariantFromValue(1) << 0;
+ QTest::newRow("schar+int5") << qVariantFromValue(schar(-1)) << qVariantFromValue(0) << -1;
+ QTest::newRow("schar+int6") << qVariantFromValue(schar(-1)) << qVariantFromValue(-1) << 0;
+
+ QTest::newRow("uchar+int1") << qVariantFromValue(uchar(0)) << qVariantFromValue(0) << 0;
+ QTest::newRow("uchar+int2") << qVariantFromValue(uchar(0)) << qVariantFromValue(1) << -1;
+ QTest::newRow("uchar+int3") << qVariantFromValue(uchar(1)) << qVariantFromValue(0) << +1;
+ QTest::newRow("uchar+int4") << qVariantFromValue(uchar(1)) << qVariantFromValue(1) << 0;
+
+ QTest::newRow("short+int1") << qVariantFromValue(short(0)) << qVariantFromValue(0) << 0;
+ QTest::newRow("short+int2") << qVariantFromValue(short(0)) << qVariantFromValue(1) << -1;
+ QTest::newRow("short+int3") << qVariantFromValue(short(1)) << qVariantFromValue(0) << +1;
+ QTest::newRow("short+int4") << qVariantFromValue(short(1)) << qVariantFromValue(1) << 0;
+ QTest::newRow("short+int5") << qVariantFromValue(short(-1)) << qVariantFromValue(0) << -1;
+ QTest::newRow("short+int6") << qVariantFromValue(short(-1)) << qVariantFromValue(-1) << 0;
+
+ QTest::newRow("ushort+int1") << qVariantFromValue(ushort(0)) << qVariantFromValue(0) << 0;
+ QTest::newRow("ushort+int2") << qVariantFromValue(ushort(0)) << qVariantFromValue(1) << -1;
+ QTest::newRow("ushort+int3") << qVariantFromValue(ushort(1)) << qVariantFromValue(0) << +1;
+ QTest::newRow("ushort+int4") << qVariantFromValue(ushort(1)) << qVariantFromValue(1) << 0;
+
+ // lower ranked + uint (without sign change)
+ QTest::newRow("bool+uint1") << qVariantFromValue(false) << qVariantFromValue(0U) << 0;
+ QTest::newRow("bool+uint2") << qVariantFromValue(false) << qVariantFromValue(1U) << -1;
+ QTest::newRow("bool+uint3") << qVariantFromValue(true) << qVariantFromValue(0U) << +1;
+ QTest::newRow("bool+uint4") << qVariantFromValue(true) << qVariantFromValue(1U) << 0;
+ QTest::newRow("bool+uint5") << qVariantFromValue(true) << qVariantFromValue(2U) << -1;
+
+ QTest::newRow("char+uint1") << qVariantFromValue(char(0)) << qVariantFromValue(0U) << 0;
+ QTest::newRow("char+uint2") << qVariantFromValue(char(0)) << qVariantFromValue(1U) << -1;
+ QTest::newRow("char+uint3") << qVariantFromValue(char(1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("char+uint4") << qVariantFromValue(char(1)) << qVariantFromValue(1U) << 0;
+
+ QTest::newRow("schar+uint1") << qVariantFromValue(schar(0)) << qVariantFromValue(0U) << 0;
+ QTest::newRow("schar+uint2") << qVariantFromValue(schar(0)) << qVariantFromValue(1U) << -1;
+ QTest::newRow("schar+uint3") << qVariantFromValue(schar(1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("schar+uint4") << qVariantFromValue(schar(1)) << qVariantFromValue(1U) << 0;
+
+ QTest::newRow("uchar+uint1") << qVariantFromValue(uchar(0)) << qVariantFromValue(0U) << 0;
+ QTest::newRow("uchar+uint2") << qVariantFromValue(uchar(0)) << qVariantFromValue(1U) << -1;
+ QTest::newRow("uchar+uint3") << qVariantFromValue(uchar(1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("uchar+uint4") << qVariantFromValue(uchar(1)) << qVariantFromValue(1U) << 0;
+
+ QTest::newRow("short+uint1") << qVariantFromValue(short(0)) << qVariantFromValue(0U) << 0;
+ QTest::newRow("short+uint2") << qVariantFromValue(short(0)) << qVariantFromValue(1U) << -1;
+ QTest::newRow("short+uint3") << qVariantFromValue(short(1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("short+uint4") << qVariantFromValue(short(1)) << qVariantFromValue(1U) << 0;
+
+ QTest::newRow("ushort+uint1") << qVariantFromValue(ushort(0)) << qVariantFromValue(0U) << 0;
+ QTest::newRow("ushort+uint2") << qVariantFromValue(ushort(0)) << qVariantFromValue(1U) << -1;
+ QTest::newRow("ushort+uint3") << qVariantFromValue(ushort(1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("ushort+uint4") << qVariantFromValue(ushort(1)) << qVariantFromValue(1U) << 0;
+
+ // int + qlonglong
+ QTest::newRow("int+qlonglong1") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(0)) << 0;
+ QTest::newRow("int+qlonglong2") << qVariantFromValue(1) << qVariantFromValue(Q_INT64_C(0)) << +1;
+ QTest::newRow("int+qlonglong3") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(1)) << -1;
+ QTest::newRow("int+qlonglong4") << qVariantFromValue(1) << qVariantFromValue(Q_INT64_C(1)) << 0;
+ QTest::newRow("int+qlonglong5") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(-1)) << +1;
+ QTest::newRow("int+qlonglong6") << qVariantFromValue(-1) << qVariantFromValue(Q_INT64_C(0)) << -1;
+ QTest::newRow("int+qlonglong7") << qVariantFromValue(-1) << qVariantFromValue(Q_INT64_C(-1)) << 0;
+
+ // uint + qulonglong
+ QTest::newRow("uint+qulonglong1") << qVariantFromValue(0U) << qVariantFromValue(Q_UINT64_C(0)) << 0;
+ QTest::newRow("uint+qulonglong2") << qVariantFromValue(1U) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("uint+qulonglong3") << qVariantFromValue(0U) << qVariantFromValue(Q_UINT64_C(1)) << -1;
+ QTest::newRow("uint+qulonglong4") << qVariantFromValue(1U) << qVariantFromValue(Q_UINT64_C(1)) << 0;
+
+ // int + uint (without sign change)
+ QTest::newRow("int+uint1") << qVariantFromValue(0) << qVariantFromValue(0U) << 0;
+ QTest::newRow("int+uint2") << qVariantFromValue(1) << qVariantFromValue(0U) << +1;
+ QTest::newRow("int+uint3") << qVariantFromValue(0) << qVariantFromValue(1U) << -1;
+ QTest::newRow("int+uint4") << qVariantFromValue(1) << qVariantFromValue(1U) << 0;
+
+ // uint + qlonglong
+ QTest::newRow("uint+qlonglong1") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(0)) << 0;
+ QTest::newRow("uint+qlonglong2") << qVariantFromValue(1U) << qVariantFromValue(Q_INT64_C(0)) << +1;
+ QTest::newRow("uint+qlonglong3") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(1)) << -1;
+ QTest::newRow("uint+qlonglong4") << qVariantFromValue(1U) << qVariantFromValue(Q_INT64_C(1)) << 0;
+ QTest::newRow("uint+qlonglong5") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(-1)) << +1;
+
+ // boundary conditions
+ QTest::newRow("charmax+intmax") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(INT_MAX) << -1;
+ QTest::newRow("charmax+uintmax") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(UINT_MAX) << -1;
+ QTest::newRow("scharmax+intmax") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(INT_MAX) << -1;
+ QTest::newRow("scharmax+uintmax") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(UINT_MAX) << -1;
+ QTest::newRow("ucharmax+intmax") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(INT_MAX) << -1;
+ QTest::newRow("ucharmax+uintmax") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(UINT_MAX) << -1;
+ QTest::newRow("shortmax+intmax") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(INT_MAX) << -1;
+ QTest::newRow("shortmax+uintmax") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(UINT_MAX) << -1;
+ QTest::newRow("ushortmax+intmax") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(INT_MAX) << -1;
+ QTest::newRow("ushortmax+uintmax") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(UINT_MAX) << -1;
+
+ QTest::newRow("intmin+qlonglongmin") << qVariantFromValue(INT_MIN) << qVariantFromValue(LLONG_MIN) << +1;
+ QTest::newRow("intmax+uintmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(UINT_MAX) << -1;
+ QTest::newRow("intmax+qlonglongmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(LLONG_MAX) << -1;
+ QTest::newRow("uintmax+qlonglongmax") << qVariantFromValue(UINT_MAX) << qVariantFromValue(LLONG_MAX) << -1;
+ QTest::newRow("intmax+qulonglongmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(ULLONG_MAX) << -1;
+ QTest::newRow("qlonglongmax+qulonglongmax") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(ULLONG_MAX) << -1;
+ QTest::newRow("uintmax+qlonglongmin") << qVariantFromValue(UINT_MAX) << qVariantFromValue(LLONG_MIN) << +1;
+
+ // check for no sign-extension issues
+ QTest::newRow("ushortmax+intzero") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(0) << +1;
+ QTest::newRow("ushortmax+qlonglongzero") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(Q_INT64_C(0)) << +1;
+ QTest::newRow("uintmax+qlonglongzero") << qVariantFromValue(UINT_MAX) << qVariantFromValue(Q_INT64_C(0)) << +1;
+
+ // sign changes
+ // the tests below check that a signed negative number sign-changes to a non-zero unsigned number and that
+ // signed -1 sign-changes to unsigned maximum (all bits set, ~0). This works on two's complement machines
+ // (all that Qt supports), and would also work on one's complement.
+ if (std::numeric_limits<char>::is_signed) {
+ QTest::newRow("signchange-char+uint") << qVariantFromValue(char(-1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-char+uintmax") << qVariantFromValue(char(-1)) << qVariantFromValue(UINT_MAX) << 0;
+ QTest::newRow("signchange-charmin+uint") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-char+qulonglong") << qVariantFromValue(char(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-char+qulonglongmax") << qVariantFromValue(char(-1)) << qVariantFromValue(ULLONG_MAX) << 0;
+ QTest::newRow("signchange-charmin+qulonglong") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ }
+ QTest::newRow("signchange-schar+uint") << qVariantFromValue(schar(-1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-schar+uintmax") << qVariantFromValue(schar(-1)) << qVariantFromValue(UINT_MAX) << 0;
+ QTest::newRow("signchange-scharmin+uint") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-schar+qulonglong") << qVariantFromValue(schar(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-schar+qulonglongmax") << qVariantFromValue(schar(-1)) << qVariantFromValue(ULLONG_MAX) << 0;
+ QTest::newRow("signchange-scharmin+qulonglong") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-short+uint") << qVariantFromValue(short(-1)) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-short+uintmax") << qVariantFromValue(short(-1)) << qVariantFromValue(UINT_MAX) << 0;
+ QTest::newRow("signchange-shortmin+uint") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-short+qulonglong") << qVariantFromValue(short(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-short+qulonglongmax") << qVariantFromValue(short(-1)) << qVariantFromValue(ULLONG_MAX) << 0;
+ QTest::newRow("signchange-shortmin+qulonglong") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-int+uint") << qVariantFromValue(-1) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-int+uintmax") << qVariantFromValue(-1) << qVariantFromValue(UINT_MAX) << 0;
+ QTest::newRow("signchange-intmin+uint") << qVariantFromValue(INT_MIN) << qVariantFromValue(0U) << +1;
+ QTest::newRow("signchange-int+qulonglong") << qVariantFromValue(-1) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-int+qulonglongmax") << qVariantFromValue(-1) << qVariantFromValue(ULLONG_MAX) << 0;
+ QTest::newRow("signchange-intmin+qulonglong") << qVariantFromValue(INT_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ // no qlonglong+uint, since that should promote to qlonglong and then the comparison is signed (tested above)
+ QTest::newRow("signchange-qlonglong+qulonglong") << qVariantFromValue(Q_INT64_C(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+ QTest::newRow("signchange-qlonglong+qulonglongmax") << qVariantFromValue(Q_INT64_C(-1)) << qVariantFromValue(ULLONG_MAX) << 0;
+ QTest::newRow("signchange-qlonglongmin+qulonglong") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1;
+}
+
+void tst_QVariant::compareNumbers() const
+{
+ QFETCH(QVariant, v1);
+ QFETCH(QVariant, v2);
+ QFETCH(int, expected);
+
+ if (expected == -1) {
+ QVERIFY(v1 < v2);
+ QVERIFY(v1 <= v2);
+ QVERIFY(!(v1 == v2));
+ QVERIFY(!(v1 > v2));
+ QVERIFY(!(v1 >= v2));
+
+ QVERIFY(!(v2 < v1));
+ QVERIFY(!(v2 <= v1));
+ QVERIFY(!(v2 == v1));
+ QVERIFY(v2 >= v1);
+ QVERIFY(v2 > v1);
+ } else if (expected == 0) {
+ QVERIFY(!(v1 < v2));
+ QVERIFY(v1 <= v2);
+ QCOMPARE(v1, v2);
+ QVERIFY(!(v1 > v2));
+ QVERIFY(v1 >= v2);
+
+ QVERIFY(!(v2 < v1));
+ QVERIFY(v2 <= v1);
+ QCOMPARE(v2, v1);
+ QVERIFY(v2 >= v1);
+ QVERIFY(!(v2 > v1));
+ } else {
+ QVERIFY(!(v1 < v2));
+ QVERIFY(!(v1 <= v2));
+ QVERIFY(!(v1 == v2));
+ QVERIFY(v1 > v2);
+ QVERIFY(v1 >= v2);
+
+ QVERIFY(v2 < v1);
+ QVERIFY(v2 <= v1);
+ QVERIFY(!(v2 == v1));
+ QVERIFY(!(v2 >= v1));
+ QVERIFY(!(v2 > v1));
+ }
+}
+
void tst_QVariant::typeName_data()
{
QTest::addColumn<int>("type");
@@ -2945,41 +3277,72 @@ void tst_QVariant::setValue()
QVERIFY( v2.isDetached() );
}
+void tst_QVariant::fpStringRoundtrip_data() const
+{
+ QTest::addColumn<QVariant>("number");
+
+ QTest::newRow("float") << QVariant(1 + FLT_EPSILON);
+ QTest::newRow("double") << QVariant(1 + DBL_EPSILON);
+}
+
+void tst_QVariant::fpStringRoundtrip() const
+{
+ QFETCH(QVariant, number);
+
+ QVariant converted = number;
+ QVERIFY(converted.convert(QVariant::String));
+ QVERIFY(converted.convert(number.type()));
+ QCOMPARE(converted, number);
+
+ converted = number;
+ QVERIFY(converted.convert(QVariant::ByteArray));
+ QVERIFY(converted.convert(number.type()));
+ QCOMPARE(converted, number);
+}
+
+void tst_QVariant::numericalConvert_data()
+{
+ QTest::addColumn<QVariant>("v");
+ QTest::addColumn<bool>("isInteger");
+ QTest::newRow("float") << QVariant(float(5.3)) << false;
+ QTest::newRow("double") << QVariant(double(5.3)) << false;
+ QTest::newRow("qreal") << QVariant(qreal(5.3)) << false;
+ QTest::newRow("int") << QVariant(int(5)) << true;
+ QTest::newRow("uint") << QVariant(uint(5)) << true;
+ QTest::newRow("short") << QVariant(short(5)) << true;
+ QTest::newRow("longlong") << QVariant(quint64(5)) << true;
+ QTest::newRow("long") << QVariant::fromValue(long(5)) << true;
+ QTest::newRow("stringint") << QVariant(QString::fromLatin1("5")) << true;
+ QTest::newRow("string") << QVariant(QString::fromLatin1("5.30000019")) << false;
+}
+
void tst_QVariant::numericalConvert()
{
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
QSKIP("Known to fail due to a GCC bug on at least Ubuntu 10.04 32-bit - check QTBUG-8959");
#endif
- QVariant vfloat(float(5.3));
- QVariant vdouble(double(5.3));
- QVariant vreal(qreal(5.3));
- QVariant vint(int(5));
- QVariant vuint(uint(5));
- QVariant vshort(short(5));
- QVariant vlonglong(quint64(5));
- QVariant vlong = QVariant::fromValue(long(5));
- QVariant vstringint(QString::fromLatin1("5"));
- QVariant vstring(QString::fromLatin1("5.3"));
-
- QVector<QVariant *> vect;
- vect << &vfloat << &vdouble << &vreal << &vint << &vuint << &vshort<< &vlonglong << &vlong << &vstringint << &vstring;
-
- for(int i = 0; i < vect.size(); i++) {
- double num = 5.3;
- if (i >= 3 && i <= 8)
- num = 5;
- QVariant *v = vect.at(i);
- QCOMPARE(v->toFloat() , float(num));
- QCOMPARE(float(v->toReal()) , float(num));
- QCOMPARE(float(v->toDouble()) , float(num));
- if (i != 9) {
- QCOMPARE(v->toInt() , int(num));
- QCOMPARE(v->toUInt() , uint(num));
- QCOMPARE(v->toULongLong() , quint64(num));
- QCOMPARE(v->value<ulong>() , ulong(num));
- QCOMPARE(v->value<ushort>() , ushort(num));
- }
- QCOMPARE(v->toString() , QString::number(num));
+ QFETCH(QVariant, v);
+ QFETCH(bool, isInteger);
+ double num = isInteger ? 5 : 5.3;
+
+ QCOMPARE(v.toFloat() , float(num));
+ QCOMPARE(float(v.toReal()) , float(num));
+ QCOMPARE(float(v.toDouble()) , float(num));
+ if (isInteger) {
+ QCOMPARE(v.toInt() , int(num));
+ QCOMPARE(v.toUInt() , uint(num));
+ QCOMPARE(v.toULongLong() , quint64(num));
+ QCOMPARE(v.value<ulong>() , ulong(num));
+ QCOMPARE(v.value<ushort>() , ushort(num));
+ }
+ switch (v.userType())
+ {
+ case QVariant::Double:
+ QCOMPARE(v.toString() , QString::number(num, 'g', DBL_MANT_DIG * log10(2.) + 2));
+ break;
+ case QMetaType::Float:
+ QCOMPARE(v.toString() , QString::number(float(num), 'g', FLT_MANT_DIG * log10(2.) + 2));
+ break;
}
}
@@ -3214,8 +3577,8 @@ void tst_QVariant::moreCustomTypes()
QCOMPARE(MyNotMovable::count, 0);
{
- PLAY_WITH_VARIANT(12.12, false, "12.12", 12.12, true);
- PLAY_WITH_VARIANT(12.12f, false, "12.12", 12.12f, true);
+ PLAY_WITH_VARIANT(12.12, false, "12.119999999999999", 12.12, true);
+ PLAY_WITH_VARIANT(12.12f, false, "12.1199999", 12.12f, true);
PLAY_WITH_VARIANT('a', false, "a", 'a', true);
PLAY_WITH_VARIANT((unsigned char)('a'), false, "a", 'a', true);
PLAY_WITH_VARIANT( quint8(12), false, "\xc", 12, true);
diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
index 425a07b3a7..605a1525e3 100644
--- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
+++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
@@ -94,13 +94,9 @@
# define QATOMIC_TEST_NOT_SUPPORTED
#endif
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic ignored "-Wtype-limits"
-# pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
-# pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
-#endif
+QT_WARNING_DISABLE_GCC("-Wtype-limits")
+QT_WARNING_DISABLE_GCC("-Wsign-compare")
+QT_WARNING_DISABLE_CLANG("-Wtautological-constant-out-of-range-compare")
typedef signed char schar;
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index 18739cb4e1..d010ff807d 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -2000,6 +2000,9 @@ void tst_QByteArray::toUpperLower_data()
QTest::addColumn<QByteArray>("lower");
QTest::newRow("empty") << QByteArray() << QByteArray() << QByteArray();
+ QTest::newRow("literal") << QByteArrayLiteral("Hello World")
+ << QByteArrayLiteral("HELLO WORLD")
+ << QByteArrayLiteral("hello world");
QTest::newRow("ascii") << QByteArray("Hello World, this is a STRING")
<< QByteArray("HELLO WORLD, THIS IS A STRING")
<< QByteArray("hello world, this is a string");
@@ -2014,8 +2017,34 @@ void tst_QByteArray::toUpperLower()
QFETCH(QByteArray, input);
QFETCH(QByteArray, upper);
QFETCH(QByteArray, lower);
+ QCOMPARE(lower.toLower(), lower);
+ QCOMPARE(upper.toUpper(), upper);
QCOMPARE(input.toUpper(), upper);
QCOMPARE(input.toLower(), lower);
+
+ QByteArray copy = input;
+ QCOMPARE(qMove(copy).toUpper(), upper);
+ copy = input;
+ copy.detach();
+ QCOMPARE(qMove(copy).toUpper(), upper);
+
+ copy = input;
+ QCOMPARE(qMove(copy).toLower(), lower);
+ copy = input;
+ copy.detach();
+ QCOMPARE(qMove(copy).toLower(), lower);
+
+ copy = lower;
+ QCOMPARE(qMove(copy).toLower(), lower);
+ copy = lower;
+ copy.detach();
+ QCOMPARE(qMove(copy).toLower(), lower);
+
+ copy = upper;
+ QCOMPARE(qMove(copy).toUpper(), upper);
+ copy = upper;
+ copy.detach();
+ QCOMPARE(qMove(copy).toUpper(), upper);
}
void tst_QByteArray::macTypes()
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index a4350ea2fe..55c911a5fc 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -47,6 +47,8 @@ public slots:
void init();
void cleanup();
private slots:
+ void operators_data();
+ void operators();
void toUpper();
void toLower();
void toTitle();
@@ -99,6 +101,33 @@ void tst_QChar::cleanup()
#endif
}
+void tst_QChar::operators_data()
+{
+ QTest::addColumn<QChar>("lhs");
+ QTest::addColumn<QChar>("rhs");
+
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j)
+ QTest::newRow(qPrintable(QString().sprintf("'\\%d' (op) '\\%d'", i, j)))
+ << QChar(ushort(i)) << QChar(ushort(j));
+ }
+}
+
+void tst_QChar::operators()
+{
+ QFETCH(QChar, lhs);
+ QFETCH(QChar, rhs);
+
+#define CHECK(op) QCOMPARE((lhs op rhs), (lhs.unicode() op rhs.unicode()))
+ CHECK(==);
+ CHECK(!=);
+ CHECK(< );
+ CHECK(> );
+ CHECK(<=);
+ CHECK(>=);
+#undef CHECK
+}
+
void tst_QChar::toUpper()
{
QVERIFY(QChar('a').toUpper() == 'A');
diff --git a/tests/auto/corelib/tools/qdatetime/qdatetime.pro b/tests/auto/corelib/tools/qdatetime/qdatetime.pro
index 0a89fe7645..25d11443e4 100644
--- a/tests/auto/corelib/tools/qdatetime/qdatetime.pro
+++ b/tests/auto/corelib/tools/qdatetime/qdatetime.pro
@@ -11,3 +11,8 @@ win32-msvc|win32-msvc9x {
QMAKE_CXXFLAGS_RELEASE -= -O1
}
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
+mac {
+ OBJECTIVE_SOURCES += tst_qdatetime_mac.mm
+ LIBS += -framework Foundation
+}
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 51c3a19d63..8876bb3d34 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -145,6 +145,8 @@ private slots:
void invalid() const;
+ void macTypes();
+
private:
enum { LocalTimeIsUtc = 0, LocalTimeAheadOfUtc = 1, LocalTimeBehindUtc = -1} localTimeType;
bool europeanTimeZone;
@@ -2981,5 +2983,15 @@ void tst_QDateTime::invalid() const
QCOMPARE(tzDate.timeSpec(), Qt::TimeZone);
}
+void tst_QDateTime::macTypes()
+{
+#ifndef Q_OS_MAC
+ QSKIP("This is a Apple-only test");
+#else
+ extern void tst_QDateTime_macTypes(); // in qdatetime_mac.mm
+ tst_QDateTime_macTypes();
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QDateTime)
#include "tst_qdatetime.moc"
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
new file mode 100644
index 0000000000..d03ae3faeb
--- /dev/null
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Petroules Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QDateTime>
+#include <QtTest/QtTest>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <Foundation/Foundation.h>
+
+void tst_QDateTime_macTypes()
+{
+ // QDateTime <-> CFDate
+ {
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const CFDateRef cfDate = qtDateTime.toCFDate();
+ QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTime);
+ CFRelease(cfDate);
+ }
+ {
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const CFDateRef cfDate = qtDateTime.toCFDate();
+ QDateTime qtDateTimeCopy(qtDateTime);
+ qtDateTime.setTime_t(10000); // modify
+ QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTimeCopy);
+ }
+ // QDateTime <-> NSDate
+ {
+ NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const NSDate *nsDate = qtDateTime.toNSDate();
+ QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTime);
+ [autoreleasepool release];
+ }
+ {
+ NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const NSDate *nsDate = qtDateTime.toNSDate();
+ QDateTime qtDateTimeCopy(qtDateTime);
+ qtDateTime.setTime_t(10000); // modify
+ QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTimeCopy);
+ [autoreleasepool release];
+ }
+}
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index d1152419c0..c1d6184072 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -51,6 +51,7 @@ private slots:
void operators();
void properties();
void metaTypes();
+ void propertyOrderIsNotImportant();
void bezierSpline_data();
void bezierSpline();
void tcbSpline_data();
@@ -552,6 +553,25 @@ void tst_QEasingCurve::metaTypes()
QVERIFY(qMetaTypeId<QEasingCurve>() == QMetaType::QEasingCurve);
}
+/*
+ Test to ensure that regardless of what order properties are set, they should produce the same
+ behavior.
+ */
+void tst_QEasingCurve::propertyOrderIsNotImportant()
+{
+
+ QEasingCurve c1;
+ c1.setPeriod(1);
+ c1.setType(QEasingCurve::OutSine);
+ QVERIFY(c1.valueForProgress(0.75) > 0.9);
+
+ QEasingCurve c2;
+ c2.setType(QEasingCurve::OutSine);
+ c2.setPeriod(1);
+
+ QCOMPARE(c1.valueForProgress(0.75), c2.valueForProgress(0.75));
+}
+
void tst_QEasingCurve::bezierSpline_data()
{
QTest::addColumn<QString>("definition");
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index db22f99cb8..1b6fe2aefe 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -237,6 +237,95 @@ void consistencyCheck(const QRegularExpressionMatchIterator &iterator)
}
+template<typename Result>
+static void prepareResultForNoMatchType(Result *r, const Result &orig)
+{
+ Q_UNUSED(r);
+ Q_UNUSED(orig);
+}
+
+static void prepareResultForNoMatchType(Match *m, const Match &orig)
+{
+ m->isValid = orig.isValid;
+}
+
+template<typename QREMatch, typename QREMatchFunc, typename Subject, typename Result>
+static void testMatchImpl(const QRegularExpression &regexp,
+ QREMatchFunc matchingMethod,
+ const Subject &subject,
+ int offset,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const Result &result)
+{
+ {
+ const QREMatch m = (regexp.*matchingMethod)(subject, offset, matchType, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == result);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), matchType);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Result realMatch;
+ prepareResultForNoMatchType(&realMatch, result);
+
+ const QREMatch m = (regexp.*matchingMethod)(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+}
+
+template<typename QREMatch, typename QREMatchFuncForString, typename QREMatchFuncForStringRef, typename Result>
+static void testMatch(const QRegularExpression &regexp,
+ QREMatchFuncForString matchingMethodForString,
+ QREMatchFuncForStringRef matchingMethodForStringRef,
+ const QString &subject,
+ int offset,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const Result &result)
+{
+ if (forceOptimize)
+ regexp.optimize();
+
+ // test with QString as subject type
+ testMatchImpl<QREMatch>(regexp, matchingMethodForString, subject, offset, matchType, matchOptions, result);
+
+ // test with QStringRef as subject type
+ testMatchImpl<QREMatch>(regexp,
+ matchingMethodForStringRef,
+ QStringRef(&subject, 0, subject.length()),
+ offset,
+ matchType,
+ matchOptions,
+ result);
+
+ // offset <= 0 tested above; now also test stringrefs not spanning over
+ // the entire subject. Note that the offset can be negative, hence the above
+ // tests can't be merged into this one
+ for (int i = 1; i <= offset; ++i) {
+ testMatchImpl<QREMatch>(regexp,
+ matchingMethodForStringRef,
+ QStringRef(&subject, i, subject.length() - i),
+ offset - i,
+ matchType,
+ matchOptions,
+ result);
+ }
+}
+
+typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringRefPMF)(const QStringRef &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringRefPMF)(const QStringRef &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+
void tst_QRegularExpression::provideRegularExpressions()
{
QTest::addColumn<QString>("pattern");
@@ -526,6 +615,7 @@ void tst_QRegularExpression::normalMatch_data()
QTest::addColumn<Match>("match");
Match m;
+ int offset = 0;
m.clear();
m.isValid = true; m.hasMatch = true;
@@ -577,20 +667,28 @@ void tst_QRegularExpression::normalMatch_data()
m.clear();
m.isValid = true; m.hasMatch = true;
m.captured << "c123def" << "c12" << "3" << "def";
- QTest::newRow("match06") << QRegularExpression("(\\w*)(\\d+)(\\w*)")
- << "abc123def"
- << 2
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 2;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("match06-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("(\\w*)(\\d+)(\\w*)")
+ << QStringLiteral("abc123def").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true; m.hasMatch = true;
m.captured << QString("");
- QTest::newRow("match07") << QRegularExpression("\\w*")
- << "abc123def"
- << 9
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 9;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("match07-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("\\w*")
+ << QStringLiteral("abc123def").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true; m.hasMatch = true;
@@ -648,19 +746,27 @@ void tst_QRegularExpression::normalMatch_data()
m.clear();
m.isValid = true;
- QTest::newRow("nomatch02") << QRegularExpression("(\\w+) (\\w+)")
- << "a string"
- << 1
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 1;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("nomatch02-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("(\\w+) (\\w+)")
+ << QStringLiteral("a string").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true;
- QTest::newRow("nomatch03") << QRegularExpression("\\w+")
- << "abc123def"
- << 9
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 9;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("nomatch03-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("\\w+")
+ << QStringLiteral("abc123def").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
// ***
@@ -728,32 +834,14 @@ void tst_QRegularExpression::normalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- if (forceOptimize)
- regexp.optimize();
-
- {
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
- {
- // ignore the expected results provided by the match object --
- // we'll never get any result when testing the NoMatch type.
- // Just check the validity of the match here.
- Match realMatch;
- realMatch.clear();
- realMatch.isValid = match.isValid;
-
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == realMatch);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
+ testMatch<QRegularExpressionMatch>(regexp,
+ static_cast<QREMatchStringPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringRefPMF>(&QRegularExpression::match),
+ subject,
+ offset,
+ QRegularExpression::NormalMatch,
+ matchOptions,
+ match);
}
void tst_QRegularExpression::partialMatch_data()
@@ -766,6 +854,7 @@ void tst_QRegularExpression::partialMatch_data()
QTest::addColumn<Match>("match");
Match m;
+ int offset = 0;
m.clear();
m.isValid = true; m.hasPartialMatch = true;
@@ -840,12 +929,16 @@ void tst_QRegularExpression::partialMatch_data()
m.clear();
m.isValid = true; m.hasPartialMatch = true;
m.captured << "def";
- QTest::newRow("softmatch08") << QRegularExpression("abc\\w+X|defY")
- << "abcdef"
- << 1
- << QRegularExpression::PartialPreferCompleteMatch
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 1;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("softmatch08-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("abc\\w+X|defY")
+ << QStringLiteral("abcdef").mid(offset - i)
+ << i
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
// ***
@@ -922,12 +1015,16 @@ void tst_QRegularExpression::partialMatch_data()
m.clear();
m.isValid = true; m.hasPartialMatch = true;
m.captured << "def";
- QTest::newRow("hardmatch08") << QRegularExpression("abc\\w+X|defY")
- << "abcdef"
- << 1
- << QRegularExpression::PartialPreferFirstMatch
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 1;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("hardmatch08-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("abc\\w+X|defY")
+ << QStringLiteral("abcdef").mid(offset - i)
+ << i
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true; m.hasPartialMatch = true;
@@ -1009,32 +1106,14 @@ void tst_QRegularExpression::partialMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- if (forceOptimize)
- regexp.optimize();
-
- {
- QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), matchType);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
- {
- // ignore the expected results provided by the match object --
- // we'll never get any result when testing the NoMatch type.
- // Just check the validity of the match here.
- Match realMatch;
- realMatch.clear();
- realMatch.isValid = match.isValid;
-
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == realMatch);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
+ testMatch<QRegularExpressionMatch>(regexp,
+ static_cast<QREMatchStringPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringRefPMF>(&QRegularExpression::match),
+ subject,
+ offset,
+ matchType,
+ matchOptions,
+ match);
}
void tst_QRegularExpression::globalMatch_data()
@@ -1304,31 +1383,14 @@ void tst_QRegularExpression::globalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(QList<Match>, matchList);
- if (forceOptimize)
- regexp.optimize();
-
- {
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == matchList);
- QCOMPARE(iterator.regularExpression(), regexp);
- QCOMPARE(iterator.matchType(), matchType);
- QCOMPARE(iterator.matchOptions(), matchOptions);
- }
- {
- // ignore the expected results provided by the match object --
- // we'll never get any result when testing the NoMatch type.
- // Just check the validity of the match here.
- QList<Match> realMatchList;
-
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == realMatchList);
- QCOMPARE(iterator.regularExpression(), regexp);
- QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
- QCOMPARE(iterator.matchOptions(), matchOptions);
- }
-
+ testMatch<QRegularExpressionMatchIterator>(regexp,
+ static_cast<QREGlobalMatchStringPMF>(&QRegularExpression::globalMatch),
+ static_cast<QREGlobalMatchStringRefPMF>(&QRegularExpression::globalMatch),
+ subject,
+ offset,
+ matchType,
+ matchOptions,
+ matchList);
}
void tst_QRegularExpression::serialize_data()
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index ea40c64c89..ed72b58d6e 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -155,6 +155,7 @@ private slots:
void lastIndexOfInvalidRegex();
void indexOf_data();
void indexOf();
+ void indexOfInvalidRegex();
void indexOf2_data();
void indexOf2();
void indexOf3_data();
@@ -812,10 +813,8 @@ void tst_QString::acc_01()
}
}
-#ifdef Q_CC_GNU
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wformat-security"
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wformat-security")
void tst_QString::isNull()
{
@@ -827,9 +826,7 @@ void tst_QString::isNull()
QVERIFY(!a.isNull());
}
-#ifdef Q_CC_GNU
-# pragma GCC diagnostic pop
-#endif
+QT_WARNING_POP
void tst_QString::isEmpty()
{
@@ -1182,6 +1179,18 @@ void tst_QString::indexOf()
QRegularExpression re(QRegularExpression::escape(needle), options);
QCOMPARE( haystack.indexOf(re, startpos), resultpos );
+ QCOMPARE(haystack.indexOf(re, startpos, Q_NULLPTR), resultpos);
+
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QCOMPARE(haystack.indexOf(re, startpos, &match), resultpos);
+ QCOMPARE(match.hasMatch(), resultpos != -1);
+ if (resultpos > -1 && needleIsLatin) {
+ if (bcs)
+ QVERIFY(match.captured() == needle);
+ else
+ QVERIFY(match.captured().toLower() == needle.toLower());
+ }
}
if (cs == Qt::CaseSensitive) {
@@ -1290,6 +1299,20 @@ void tst_QString::indexOf2()
}
}
+void tst_QString::indexOfInvalidRegex()
+{
+ QTest::ignoreMessage(QtWarningMsg, "QString::indexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").indexOf(QRegularExpression("invalid regex\\")), -1);
+ QTest::ignoreMessage(QtWarningMsg, "QString::indexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").indexOf(QRegularExpression("invalid regex\\"), -1, Q_NULLPTR), -1);
+
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QTest::ignoreMessage(QtWarningMsg, "QString::indexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").indexOf(QRegularExpression("invalid regex\\"), -1, &match), -1);
+ QVERIFY(!match.hasMatch());
+}
+
void tst_QString::lastIndexOf_data()
{
QTest::addColumn<QString>("haystack" );
@@ -1379,6 +1402,17 @@ void tst_QString::lastIndexOf()
QRegularExpression re(QRegularExpression::escape(needle), options);
QCOMPARE(haystack.lastIndexOf(re, from), expected);
+ QCOMPARE(haystack.lastIndexOf(re, from, Q_NULLPTR), expected);
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QCOMPARE(haystack.lastIndexOf(re, from, &match), expected);
+ QCOMPARE(match.hasMatch(), expected > -1);
+ if (expected > -1) {
+ if (caseSensitive)
+ QCOMPARE(match.captured(), needle);
+ else
+ QCOMPARE(match.captured().toLower(), needle.toLower());
+ }
}
}
@@ -1403,7 +1437,15 @@ void tst_QString::lastIndexOf()
void tst_QString::lastIndexOfInvalidRegex()
{
QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object");
- QCOMPARE(QString("").lastIndexOf(QRegularExpression("invalid regex\\"), 0), -1);
+ QCOMPARE(QString("invalid regex\\").lastIndexOf(QRegularExpression("invalid regex\\"), 0), -1);
+ QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").lastIndexOf(QRegularExpression("invalid regex\\"), -1, Q_NULLPTR), -1);
+
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").lastIndexOf(QRegularExpression("invalid regex\\"), -1, &match), -1);
+ QVERIFY(!match.hasMatch());
}
void tst_QString::count()
@@ -1838,6 +1880,7 @@ void tst_QString::toUpper()
{
QCOMPARE( QString().toUpper(), QString() );
QCOMPARE( QString("").toUpper(), QString("") );
+ QCOMPARE( QStringLiteral("text").toUpper(), QString("TEXT") );
QCOMPARE( QString("text").toUpper(), QString("TEXT") );
QCOMPARE( QString("Text").toUpper(), QString("TEXT") );
QCOMPARE( QString("tExt").toUpper(), QString("TEXT") );
@@ -1898,6 +1941,7 @@ void tst_QString::toLower()
QCOMPARE( QString().toLower(), QString() );
QCOMPARE( QString("").toLower(), QString("") );
QCOMPARE( QString("text").toLower(), QString("text") );
+ QCOMPARE( QStringLiteral("Text").toLower(), QString("text") );
QCOMPARE( QString("Text").toLower(), QString("text") );
QCOMPARE( QString("tExt").toLower(), QString("text") );
QCOMPARE( QString("teXt").toLower(), QString("text") );
@@ -2019,6 +2063,13 @@ void tst_QString::trimmed()
QCOMPARE(a,(QString)" ");
a=" a ";
QCOMPARE(a.trimmed(),(QString)"a");
+
+ a="Text";
+ QCOMPARE(qMove(a).trimmed(),(QString)"Text");
+ a=" ";
+ QCOMPARE(qMove(a).trimmed(),(QString)"");
+ a=" a ";
+ QCOMPARE(qMove(a).trimmed(),(QString)"a");
}
void tst_QString::simplified_data()
@@ -2063,9 +2114,12 @@ void tst_QString::simplified()
QVERIFY2(result.isEmpty() && !result.isNull(), qPrintable("'" + full + "' did not yield empty: " + result));
} else {
QCOMPARE(result, simple);
- if (full == simple)
- QVERIFY(result.isSharedWith(full));
}
+
+ // force a detach
+ if (!full.isEmpty())
+ full[0] = full[0];
+ QCOMPARE(qMove(full).simplified(), simple);
}
void tst_QString::insert()
@@ -4454,6 +4508,8 @@ void tst_QString::section()
QCOMPARE( wholeString.section( QRegExp(sep), start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegularExpression(sep), start, end, QString::SectionFlag(flags) ), sectionString );
} else {
+ if (sep.size() == 1)
+ QCOMPARE( wholeString.section( sep[0], start, end, QString::SectionFlag(flags) ), sectionString );
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 );
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index 9a79d48472..c9e8a5f657 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -575,6 +575,18 @@ void tst_QVector::append() const
QCOMPARE(v.last(), SimpleValue<T>::at(0));
}
#endif
+ {
+ QVector<int> v;
+ v << 1 << 2 << 3;
+ QVector<int> x;
+ x << 4 << 5 << 6;
+ v.append(x);
+
+ QVector<int> combined;
+ combined << 1 << 2 << 3 << 4 << 5 << 6;
+
+ QCOMPARE(v, combined);
+ }
}
void tst_QVector::appendInt() const