summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-06-27 15:48:30 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2019-07-05 11:25:46 +0200
commit9b3e8b32f2657948591f6bdffea9d48291b8a69b (patch)
treed6fbb8a21930dbf9ccf9d8271f18a8ca132fe88a /tests/auto/corelib/tools
parent6061e6820b97c45100d2e761a9bb302c71ce3e62 (diff)
Remove usages of deprecated APIs of corelib
- Replaced the usages of deprecated APIs of corelib by corresponding alternatives in the library code and documentation. - Modified the tests to make them build when deprecated APIs disabled: * Made the the parts of the tests testing the deprecated APIs to be compiled conditionally, only when the corresponding methods are enabled. * If the test-case tests only the deprecated API, but not the corresponding replacement, added tests for the replacement. Task-number: QTBUG-76491 Task-number: QTBUG-76539 Task-number: QTBUG-76541 Change-Id: I62ed4a5b530a965ec3f6502c6480808f938921aa Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp4
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp41
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp2
-rw-r--r--tests/auto/corelib/tools/qline/tst_qline.cpp4
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp108
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp10
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp24
7 files changed, 171 insertions, 22 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index e2ce5cb9f9..e79a4dba29 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -1994,13 +1994,17 @@ void tst_Collections::qstring()
QString nonNull = "";
QVERIFY(null.left(10).isNull());
QVERIFY(null.mid(0).isNull());
+ QVERIFY(null.isNull());
+ QVERIFY(!nonNull.isNull());
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(null == QString::null);
QVERIFY(QString::null == null);
QVERIFY(nonNull != QString::null);
QVERIFY(QString::null != nonNull);
QVERIFY(null == nonNull);
QVERIFY(QString::null == QString::null);
+#endif
QString fill = "123";
fill.fill('a');
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index d1bf63bf8a..18432e51a6 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -48,6 +48,11 @@ class tst_QAlgorithms : public QObject
{
Q_OBJECT
private slots:
+ void swap();
+ void swap2();
+ void convenienceAPI();
+
+#if QT_DEPRECATED_SINCE(5, 2)
void test_qLowerBound_data();
void test_qLowerBound();
void test_qUpperBound_data();
@@ -55,19 +60,23 @@ private slots:
void test_qBinaryFind_data();
void test_qBinaryFind();
void qBinaryFindOneEntry();
- void swap();
- void swap2();
void sortEmptyList();
void sortedList();
void sortAPItest();
void stableSortTest();
void stableSortCorrectnessTest_data();
void stableSortCorrectnessTest();
- void convenienceAPI();
+ void convenienceAPI_deprecated();
void qCountIterators() const;
void qCountContainer() const;
void binaryFindOnLargeContainer() const;
+#if Q_TEST_PERFORMANCE
+ void performance();
+#endif
+
+#endif // QT_DEPRECATED_SINCE(5, 2)
+
void popCount08_data() { popCount_data_impl(sizeof(quint8 )); }
void popCount16_data() { popCount_data_impl(sizeof(quint16)); }
void popCount32_data() { popCount_data_impl(sizeof(quint32)); }
@@ -96,9 +105,6 @@ private slots:
void countLeading64() { countLeading_impl<quint64>(); }
private:
-#if Q_TEST_PERFORMANCE
- void performance();
-#endif
void popCount_data_impl(size_t sizeof_T_Int);
template <typename T_Int>
void popCount_impl();
@@ -112,6 +118,8 @@ private:
void countLeading_impl();
};
+#if QT_DEPRECATED_SINCE(5, 2)
+
class TestInt
{
public:
@@ -257,6 +265,8 @@ void testAlgorithm(Algorithm algorithm, QStringList &dataSetTypes)
}
#endif
+#endif // QT_DEPRECATED_SINCE(5, 2)
+
void tst_QAlgorithms::swap()
{
{
@@ -391,6 +401,17 @@ void tst_QAlgorithms::swap2()
}
}
+void tst_QAlgorithms::convenienceAPI()
+{
+ // Compile-test for QAlgorithm convenience functions.
+
+ QList<int *> pointerList;
+ qDeleteAll(pointerList);
+ qDeleteAll(pointerList.begin(), pointerList.end());
+}
+
+#if QT_DEPRECATED_SINCE(5, 2)
+
void tst_QAlgorithms::sortEmptyList()
{
// Only test if it crashes
@@ -676,7 +697,7 @@ void tst_QAlgorithms::stableSortCorrectnessTest()
QVERIFY(isSorted(sorted));
}
-void tst_QAlgorithms::convenienceAPI()
+void tst_QAlgorithms::convenienceAPI_deprecated()
{
// Compile-test for QAlgorithm convenience functions.
QList<int> list, list2;
@@ -716,10 +737,6 @@ void tst_QAlgorithms::convenienceAPI()
qBinaryFind(list, 1);
qBinaryFind(list.begin(), list.end(), 1);
qBinaryFind(list.begin(), list.end(), 1, qLess<int>());
-
- QList<int *> pointerList;
- qDeleteAll(pointerList);
- qDeleteAll(pointerList.begin(), pointerList.end());
}
template <typename DataType>
@@ -1041,6 +1058,8 @@ void tst_QAlgorithms::binaryFindOnLargeContainer() const
QCOMPARE(foundIt.pos(), 1073987655);
}
+#endif // QT_DEPRECATED_SINCE(5, 2)
+
// alternative implementation of qPopulationCount for comparison:
static Q_DECL_CONSTEXPR const uint bitsSetInNibble[] = {
0, 1, 1, 2, 1, 2, 2, 3,
diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
index b9bcecd607..513c811788 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
@@ -74,10 +74,12 @@ int main(int argc, char *argv[])
hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR"));
hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(hiddenOption);
+#if QT_DEPRECATED_SINCE(5, 8)
QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2"));
hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS"));
hiddenOption2.setHidden(true);
parser.addOption(hiddenOption2);
+#endif
// This program supports different options depending on the "command" (first argument).
// Call parse() to find out the positional arguments.
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp
index 915a24a1f6..0418daf640 100644
--- a/tests/auto/corelib/tools/qline/tst_qline.cpp
+++ b/tests/auto/corelib/tools/qline/tst_qline.cpp
@@ -53,8 +53,10 @@ private slots:
void testNormalVector();
void testNormalVector_data();
+#if QT_DEPRECATED_SINCE(5, 14)
void testAngle();
void testAngle_data();
+#endif
void testAngle2();
void testAngle2_data();
@@ -378,6 +380,7 @@ void tst_QLine::testNormalVector()
QCOMPARE(n.dy(), qreal(nvy));
}
+#if QT_DEPRECATED_SINCE(5, 14)
void tst_QLine::testAngle_data()
{
QTest::addColumn<double>("xa1");
@@ -426,6 +429,7 @@ void tst_QLine::testAngle()
double resultAngle = a.angle(b);
QCOMPARE(qRound(resultAngle), qRound(angle));
}
+#endif
void tst_QLine::testAngle2_data()
{
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 187b73eeec..f3c647515a 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -75,8 +75,10 @@ private slots:
void functionCallDownCast();
void upCast();
void qobjectWeakManagement();
+#if QT_DEPRECATED_SINCE(5, 0)
void noSharedPointerFromWeakQObject();
void sharedPointerFromQObjectWithWeak();
+#endif
void weakQObjectFromSharedPointer();
void objectCast();
void objectCastStdSharedPtr();
@@ -882,6 +884,78 @@ void tst_QSharedPointer::qobjectWeakManagement()
QWeakPointer<QObject> weak;
weak = QWeakPointer<QObject>();
QVERIFY(weak.isNull());
+ QVERIFY(weak.toStrongRef().isNull());
+ }
+
+ {
+ QObject *obj = new QObject;
+ QSharedPointer<QObject> shared(obj);
+ QWeakPointer<QObject> weak(shared);
+ QVERIFY(!weak.isNull());
+ QVERIFY(weak.toStrongRef() == obj);
+
+ // now delete
+ shared.reset();
+ QVERIFY(weak.isNull());
+ }
+ safetyCheck();
+
+ {
+ // same, bit with operator=
+ QObject *obj = new QObject;
+ QSharedPointer<QObject> shared(obj);
+ QWeakPointer<QObject> weak;
+ weak = shared;
+ QVERIFY(!weak.isNull());
+ QVERIFY(weak.toStrongRef() == obj);
+
+ // now delete
+ shared.reset();
+ QVERIFY(weak.isNull());
+ }
+ safetyCheck();
+
+ {
+ // with two QWeakPointers
+ QObject *obj = new QObject;
+ QSharedPointer<QObject> shared(obj);
+ QWeakPointer<QObject> weak(shared);
+
+ {
+ QWeakPointer<QObject> weak2(shared);
+ QVERIFY(!weak2.isNull());
+ QVERIFY(weak == weak2);
+ }
+ QVERIFY(!weak.isNull());
+
+ shared.reset();
+ QVERIFY(weak.isNull());
+ }
+ safetyCheck();
+
+ {
+ // same, but delete the pointer while two QWeakPointers exist
+ QObject *obj = new QObject;
+ QSharedPointer<QObject> shared(obj);
+ QWeakPointer<QObject> weak(shared);
+
+ {
+ QWeakPointer<QObject> weak2(shared);
+ QVERIFY(!weak2.isNull());
+
+ shared.reset();
+ QVERIFY(weak.isNull());
+ QVERIFY(weak2.isNull());
+ }
+ QVERIFY(weak.isNull());
+ }
+ safetyCheck();
+
+#if QT_DEPRECATED_SINCE(5, 0)
+ {
+ QWeakPointer<QObject> weak;
+ weak = QWeakPointer<QObject>();
+ QVERIFY(weak.isNull());
QVERIFY(!weak.data());
}
@@ -972,8 +1046,10 @@ void tst_QSharedPointer::qobjectWeakManagement()
QVERIFY(weak.isNull());
}
safetyCheck();
+#endif
}
+#if QT_DEPRECATED_SINCE(5, 0)
void tst_QSharedPointer::noSharedPointerFromWeakQObject()
{
// you're not allowed to create a QSharedPointer from an unmanaged QObject
@@ -1007,18 +1083,32 @@ void tst_QSharedPointer::sharedPointerFromQObjectWithWeak()
}
QVERIFY(weak.isNull());
}
+#endif
void tst_QSharedPointer::weakQObjectFromSharedPointer()
{
- // this is the inverse of the above: you're allowed to create a QWeakPointer
- // from a managed QObject
- QSharedPointer<QObject> shared(new QObject);
- QWeakPointer<QObject> weak = shared.data();
- QVERIFY(!weak.isNull());
+#if QT_DEPRECATED_SINCE(5, 0)
+ {
+ // this is the inverse of the above: you're allowed to create a QWeakPointer
+ // from a managed QObject
+ QSharedPointer<QObject> shared(new QObject);
+ QWeakPointer<QObject> weak = shared.data();
+ QVERIFY(!weak.isNull());
- // delete:
- shared.clear();
- QVERIFY(weak.isNull());
+ // delete:
+ shared.clear();
+ QVERIFY(weak.isNull());
+ }
+#endif
+ {
+ QSharedPointer<QObject> shared(new QObject);
+ QWeakPointer<QObject> weak = shared;
+ QVERIFY(!weak.isNull());
+
+ // delete:
+ shared.clear();
+ QVERIFY(weak.isNull());
+ }
}
void tst_QSharedPointer::objectCast()
@@ -2376,6 +2466,7 @@ void tst_QSharedPointer::qvariantCast()
// Intentionally does not compile.
// QSharedPointer<int> sop = qSharedPointerFromVariant<int>(v);
+#if QT_DEPRECATED_SINCE(5, 0)
v = QVariant::fromValue(sp.toWeakRef());
{
@@ -2419,6 +2510,7 @@ void tst_QSharedPointer::qvariantCast()
QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v);
QVERIFY(!other);
}
+#endif
}
class SomeClass : public QEnableSharedFromThis<SomeClass>
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 79f5a8c46d..e4aa00f500 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -521,7 +521,9 @@ private slots:
void stringRef_local8Bit_data();
void stringRef_local8Bit();
void fromLatin1();
+#if QT_DEPRECATED_SINCE(5, 0)
void fromAscii();
+#endif
void fromUcs4();
void toUcs4();
void arg();
@@ -4284,9 +4286,9 @@ void tst_QString::fromLocal8Bit_data()
//QTest::newRow("null5") << QByteArray() << 5 << QString();
//QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << -1 << QString();
//QTest::newRow("empty0") << QByteArray() << 0 << QString();
- //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromAscii("\0abcd", 5);
- //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromAscii("ab");
- //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromAscii("ab\0cd", 5);
+ //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromLatin1("\0abcd", 5);
+ //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromLatin1("ab");
+ //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromLatin1("ab\0cd", 5);
}
void tst_QString::fromLocal8Bit()
@@ -4590,6 +4592,7 @@ void tst_QString::fromLatin1()
QVERIFY(a.size() == 5);
}
+#if QT_DEPRECATED_SINCE(5, 0)
void tst_QString::fromAscii()
{
QString a;
@@ -4610,6 +4613,7 @@ void tst_QString::fromAscii()
a = QString::fromAscii("\0abcd", 5);
QVERIFY(a.size() == 5);
}
+#endif
void tst_QString::fromUcs4()
{
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 581e9152e6..6f01947131 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -596,7 +596,10 @@ void tst_QStringRef::startsWith()
QVERIFY(!ref.startsWith("C"));
QVERIFY(!ref.startsWith("ABCDEF"));
QVERIFY(ref.startsWith(""));
+ QVERIFY(ref.startsWith(QString()));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null));
+#endif
QVERIFY(ref.startsWith('A'));
QVERIFY(ref.startsWith(QLatin1Char('A')));
QVERIFY(ref.startsWith(QChar('A')));
@@ -623,7 +626,10 @@ void tst_QStringRef::startsWith()
QVERIFY(!ref.startsWith("c", Qt::CaseInsensitive));
QVERIFY(!ref.startsWith("abcdef", Qt::CaseInsensitive));
QVERIFY(ref.startsWith("", Qt::CaseInsensitive));
+ QVERIFY(ref.startsWith(QString(), Qt::CaseInsensitive));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null, Qt::CaseInsensitive));
+#endif
QVERIFY(ref.startsWith('a', Qt::CaseInsensitive));
QVERIFY(ref.startsWith('A', Qt::CaseInsensitive));
QVERIFY(ref.startsWith(QLatin1Char('a'), Qt::CaseInsensitive));
@@ -656,7 +662,10 @@ void tst_QStringRef::startsWith()
const QString a = QString::fromLatin1("");
CREATE_REF(a);
QVERIFY(ref.startsWith(""));
+ QVERIFY(ref.startsWith(QString()));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null));
+#endif
QVERIFY(!ref.startsWith("ABC"));
QVERIFY(ref.startsWith(QLatin1String("")));
@@ -670,7 +679,10 @@ void tst_QStringRef::startsWith()
{
const QStringRef ref;
QVERIFY(!ref.startsWith(""));
+ QVERIFY(ref.startsWith(QString()));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null));
+#endif
QVERIFY(!ref.startsWith("ABC"));
QVERIFY(!ref.startsWith(QLatin1String("")));
@@ -693,7 +705,10 @@ void tst_QStringRef::endsWith()
QVERIFY(!ref.endsWith("C"));
QVERIFY(!ref.endsWith("ABCDEF"));
QVERIFY(ref.endsWith(""));
+ QVERIFY(ref.endsWith(QString()));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null));
+#endif
QVERIFY(ref.endsWith('B'));
QVERIFY(ref.endsWith(QLatin1Char('B')));
QVERIFY(ref.endsWith(QChar('B')));
@@ -720,7 +735,10 @@ void tst_QStringRef::endsWith()
QVERIFY(!ref.endsWith("c", Qt::CaseInsensitive));
QVERIFY(!ref.endsWith("abcdef", Qt::CaseInsensitive));
QVERIFY(ref.endsWith("", Qt::CaseInsensitive));
+ QVERIFY(ref.endsWith(QString(), Qt::CaseInsensitive));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null, Qt::CaseInsensitive));
+#endif
QVERIFY(ref.endsWith('b', Qt::CaseInsensitive));
QVERIFY(ref.endsWith('B', Qt::CaseInsensitive));
QVERIFY(ref.endsWith(QLatin1Char('b'), Qt::CaseInsensitive));
@@ -754,7 +772,10 @@ void tst_QStringRef::endsWith()
const QString a = QString::fromLatin1("");
CREATE_REF(a);
QVERIFY(ref.endsWith(""));
+ QVERIFY(ref.endsWith(QString()));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null));
+#endif
QVERIFY(!ref.endsWith("ABC"));
QVERIFY(!ref.endsWith(QLatin1Char(0)));
QVERIFY(!ref.endsWith(QLatin1Char('x')));
@@ -768,7 +789,10 @@ void tst_QStringRef::endsWith()
{
QStringRef ref;
QVERIFY(!ref.endsWith(""));
+ QVERIFY(ref.endsWith(QString()));
+#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null));
+#endif
QVERIFY(!ref.endsWith("ABC"));
QVERIFY(!ref.endsWith(QLatin1String("")));