forked from qt-creator/qt-creator
Fix building tests with Qt6
Task-number: QTCREATORBUG-24098 Change-Id: I192245125f04f8350597bbe481d80d3f8ba0cae0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -46,6 +46,12 @@ using QHashValueType = uint;
|
||||
using QHashValueType = size_t;
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
using QtSizeType = int;
|
||||
#else
|
||||
using QtSizeType = qsizetype;
|
||||
#endif
|
||||
|
||||
// StringView - either QStringRef or QStringView
|
||||
// Can be used where it is not possible to completely switch to QStringView
|
||||
// For example where QString::splitRef / QStringView::split is essential.
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
// initializer_list related code on the templates inside algorithm.h
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <utils/porting.h>
|
||||
|
||||
class tst_Algorithm : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -112,8 +114,8 @@ void tst_Algorithm::transform()
|
||||
QCOMPARE(i1, QList<int>({1, 3, 132}));
|
||||
const QList<int> i2 = Utils::transform(strings, stringToInt);
|
||||
QCOMPARE(i2, QList<int>({1, 3, 132}));
|
||||
const QList<int> i3 = Utils::transform(strings, &QString::size);
|
||||
QCOMPARE(i3, QList<int>({1, 1, 3}));
|
||||
const QList<Utils::QtSizeType> i3 = Utils::transform(strings, &QString::size);
|
||||
QCOMPARE(i3, QList<Utils::QtSizeType>({1, 1, 3}));
|
||||
}
|
||||
{
|
||||
// QStringList
|
||||
@@ -122,8 +124,8 @@ void tst_Algorithm::transform()
|
||||
QCOMPARE(i1, QList<int>({1, 3, 132}));
|
||||
const QList<int> i2 = Utils::transform(strings, stringToInt);
|
||||
QCOMPARE(i2, QList<int>({1, 3, 132}));
|
||||
const QList<int> i3 = Utils::transform(strings, &QString::size);
|
||||
QCOMPARE(i3, QList<int>({1, 1, 3}));
|
||||
const QList<Utils::QtSizeType> i3 = Utils::transform(strings, &QString::size);
|
||||
QCOMPARE(i3, QList<Utils::QtSizeType>({1, 1, 3}));
|
||||
}
|
||||
{
|
||||
// QSet internally needs special inserter
|
||||
@@ -132,8 +134,8 @@ void tst_Algorithm::transform()
|
||||
QCOMPARE(i1, QSet<int>({1, 3, 132}));
|
||||
const QSet<int> i2 = Utils::transform(strings, stringToInt);
|
||||
QCOMPARE(i2, QSet<int>({1, 3, 132}));
|
||||
const QSet<int> i3 = Utils::transform(strings, &QString::size);
|
||||
QCOMPARE(i3, QSet<int>({1, 3}));
|
||||
const QSet<Utils::QtSizeType> i3 = Utils::transform(strings, &QString::size);
|
||||
QCOMPARE(i3, QSet<Utils::QtSizeType>({1, 3}));
|
||||
}
|
||||
|
||||
// different container types
|
||||
@@ -144,8 +146,8 @@ void tst_Algorithm::transform()
|
||||
QCOMPARE(i1, QSet<int>({1, 3, 132}));
|
||||
const QSet<int> i2 = Utils::transform<QSet>(strings, stringToInt);
|
||||
QCOMPARE(i2, QSet<int>({1, 3, 132}));
|
||||
const QSet<int> i3 = Utils::transform<QSet>(strings, &QString::size);
|
||||
QCOMPARE(i3, QSet<int>({1, 3}));
|
||||
const QSet<Utils::QtSizeType> i3 = Utils::transform<QSet>(strings, &QString::size);
|
||||
QCOMPARE(i3, QSet<Utils::QtSizeType>({1, 3}));
|
||||
}
|
||||
{
|
||||
// QStringList to QSet
|
||||
@@ -154,8 +156,8 @@ void tst_Algorithm::transform()
|
||||
QCOMPARE(i1, QSet<int>({1, 3, 132}));
|
||||
const QSet<int> i2 = Utils::transform<QSet>(strings, stringToInt);
|
||||
QCOMPARE(i2, QSet<int>({1, 3, 132}));
|
||||
const QSet<int> i3 = Utils::transform<QSet>(strings, &QString::size);
|
||||
QCOMPARE(i3, QSet<int>({1, 3}));
|
||||
const QSet<Utils::QtSizeType> i3 = Utils::transform<QSet>(strings, &QString::size);
|
||||
QCOMPARE(i3, QSet<Utils::QtSizeType>({1, 3}));
|
||||
}
|
||||
{
|
||||
// QSet to QList
|
||||
@@ -166,9 +168,9 @@ void tst_Algorithm::transform()
|
||||
QList<int> i2 = Utils::transform<QList>(strings, stringToInt);
|
||||
Utils::sort(i2);
|
||||
QCOMPARE(i2, QList<int>({1, 3, 132}));
|
||||
QList<int> i3 = Utils::transform<QList>(strings, &QString::size);
|
||||
QList<Utils::QtSizeType> i3 = Utils::transform<QList>(strings, &QString::size);
|
||||
Utils::sort(i3);
|
||||
QCOMPARE(i3, QList<int>({1, 1, 3}));
|
||||
QCOMPARE(i3, QList<Utils::QtSizeType>({1, 1, 3}));
|
||||
}
|
||||
{
|
||||
const QList<Struct> list({4, 3, 2, 1, 2});
|
||||
|
||||
@@ -139,14 +139,10 @@ private Q_SLOTS:
|
||||
void tst_FindUsages::dump(const QList<Usage> &usages) const
|
||||
{
|
||||
QTextStream err(stderr, QIODevice::WriteOnly);
|
||||
err << "DEBUG : " << usages.size() << " usages:" << endl;
|
||||
err << "DEBUG : " << usages.size() << " usages:" << Qt::endl;
|
||||
foreach (const Usage &usage, usages) {
|
||||
err << "DEBUG : "
|
||||
<< usage.path << ":"
|
||||
<< usage.line << ":"
|
||||
<< usage.col << ":"
|
||||
<< usage.len << ":"
|
||||
<< usage.lineText << endl;
|
||||
err << "DEBUG : " << usage.path << ":" << usage.line << ":" << usage.col << ":"
|
||||
<< usage.len << ":" << usage.lineText << Qt::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,13 @@
|
||||
//TESTED_COMPONENT=src/libs/cplusplus
|
||||
using namespace CPlusPlus;
|
||||
|
||||
template <template <typename, typename> class _Map, typename _T1, typename _T2>
|
||||
_Map<_T2, _T1> invert(const _Map<_T1, _T2> &m)
|
||||
template<typename _T1, typename _T2>
|
||||
QMultiMap<_T2, _T1> invert(const QMap<_T1, _T2> &m)
|
||||
{
|
||||
_Map<_T2, _T1> i;
|
||||
typename _Map<_T1, _T2>::const_iterator it = m.constBegin();
|
||||
QMultiMap<_T2, _T1> i;
|
||||
typename QMap<_T1, _T2>::const_iterator it = m.constBegin();
|
||||
for (; it != m.constEnd(); ++it) {
|
||||
i.insertMulti(it.value(), it.key());
|
||||
i.insert(it.value(), it.key());
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -149,11 +149,10 @@ void tst_Lookup::base_class_defined_1()
|
||||
|
||||
QCOMPARE(classSymbols.size(), 2);
|
||||
|
||||
const QMap<Class *, ClassSpecifierAST *> classToAST =
|
||||
invert(classSymbols.asMap());
|
||||
const QMultiMap<Class *, ClassSpecifierAST *> classToAST = invert(classSymbols.asMap());
|
||||
|
||||
QVERIFY(classToAST.value(baseClass) != 0);
|
||||
QVERIFY(classToAST.value(derivedClass) != 0);
|
||||
QVERIFY(!classToAST.values(baseClass).isEmpty());
|
||||
QVERIFY(!classToAST.values(derivedClass).isEmpty());
|
||||
}
|
||||
|
||||
void tst_Lookup::document_functionAt_data()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <utils/filesearch.h>
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QtTest>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <utils/mimetypes/mimetype.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QtTest>
|
||||
|
||||
using namespace LanguageServerProtocol;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/mapreduce.h>
|
||||
#include <utils/porting.h>
|
||||
|
||||
#include <QThreadPool>
|
||||
#include <QtTest>
|
||||
@@ -272,20 +273,23 @@ void tst_MapReduce::map()
|
||||
|
||||
// blocking map = mapped
|
||||
{
|
||||
const QSet<int> sizes = Utils::mapped<QSet>(QStringList({QLatin1String("foo"),
|
||||
QLatin1String("bar"), QLatin1String("blah")}),
|
||||
[](const QString &s) { return s.size(); });
|
||||
QList<int> vals = sizes.values();
|
||||
const QSet<Utils::QtSizeType> sizes = Utils::mapped<QSet>(
|
||||
QStringList({QLatin1String("foo"), QLatin1String("bar"), QLatin1String("blah")}),
|
||||
[](const QString &s) { return s.size(); });
|
||||
QList<Utils::QtSizeType> vals = sizes.values();
|
||||
Utils::sort(vals);
|
||||
QCOMPARE(vals, QList<int>({3, 4}));
|
||||
QCOMPARE(vals, QList<Utils::QtSizeType>({3, 4}));
|
||||
}
|
||||
{
|
||||
const QStringList list({QLatin1String("foo"), QLatin1String("bar"), QLatin1String("blah")});
|
||||
const QSet<int> sizes = Utils::mapped<QSet>(list.cbegin(), list.cend(),
|
||||
[](const QString &s) { return s.size(); });
|
||||
QList<int> vals = sizes.values();
|
||||
const QSet<Utils::QtSizeType> sizes = Utils::mapped<QSet>(list.cbegin(),
|
||||
list.cend(),
|
||||
[](const QString &s) {
|
||||
return s.size();
|
||||
});
|
||||
QList<Utils::QtSizeType> vals = sizes.values();
|
||||
Utils::sort(vals);
|
||||
QCOMPARE(vals, QList<int>({3, 4}));
|
||||
QCOMPARE(vals, QList<Utils::QtSizeType>({3, 4}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -476,7 +476,10 @@ void tst_ProFileWriter::adds()
|
||||
|
||||
QMakeVfs vfs;
|
||||
QMakeParser parser(0, &vfs, &parseHandler);
|
||||
ProFile *proFile = parser.parsedProBlock(QStringRef(&input), 0, QLatin1String(BASE_DIR "/test.pro"), 1);
|
||||
ProFile *proFile = parser.parsedProBlock(Utils::make_stringview(input),
|
||||
0,
|
||||
QLatin1String(BASE_DIR "/test.pro"),
|
||||
1);
|
||||
QVERIFY(proFile);
|
||||
PW::putVarValues(proFile, &lines, values, var, PW::PutFlags(flags), scope, "\t");
|
||||
proFile->deref();
|
||||
@@ -647,7 +650,10 @@ void tst_ProFileWriter::removes()
|
||||
|
||||
QMakeVfs vfs;
|
||||
QMakeParser parser(0, &vfs, &parseHandler);
|
||||
ProFile *proFile = parser.parsedProBlock(QStringRef(&input), 0, QLatin1String(BASE_DIR "/test.pro"), 1);
|
||||
ProFile *proFile = parser.parsedProBlock(Utils::make_stringview(input),
|
||||
0,
|
||||
QLatin1String(BASE_DIR "/test.pro"),
|
||||
1);
|
||||
QVERIFY(proFile);
|
||||
QmakeProjectManager::Internal::ProWriter::removeVarValues(proFile, &lines, values, vars);
|
||||
proFile->deref();
|
||||
@@ -676,7 +682,10 @@ void tst_ProFileWriter::multiVar()
|
||||
|
||||
QMakeVfs vfs;
|
||||
QMakeParser parser(0, &vfs, &parseHandler);
|
||||
ProFile *proFile = parser.parsedProBlock(QStringRef(&input), 0, QLatin1String(BASE_DIR "/test.pro"), 1);
|
||||
ProFile *proFile = parser.parsedProBlock(Utils::make_stringview(input),
|
||||
0,
|
||||
QLatin1String(BASE_DIR "/test.pro"),
|
||||
1);
|
||||
QVERIFY(proFile);
|
||||
QmakeProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, baseDir, files, vars);
|
||||
proFile->deref();
|
||||
@@ -696,7 +705,10 @@ void tst_ProFileWriter::addFiles()
|
||||
|
||||
QMakeVfs vfs;
|
||||
QMakeParser parser(0, &vfs, &parseHandler);
|
||||
ProFile *proFile = parser.parsedProBlock(QStringRef(&input), 0, BASE_DIR "/test.pro", 1);
|
||||
ProFile *proFile = parser.parsedProBlock(Utils::make_stringview(input),
|
||||
0,
|
||||
BASE_DIR "/test.pro",
|
||||
1);
|
||||
QVERIFY(proFile);
|
||||
QmakeProjectManager::Internal::ProWriter::addFiles(proFile, &lines,
|
||||
QStringList(BASE_DIR "/sub/bar.cpp"),
|
||||
@@ -719,7 +731,10 @@ void tst_ProFileWriter::removeFiles()
|
||||
|
||||
QMakeVfs vfs;
|
||||
QMakeParser parser(0, &vfs, &parseHandler);
|
||||
ProFile *proFile = parser.parsedProBlock(QStringRef(&input), 0, QLatin1String(BASE_DIR "/test.pro"), 1);
|
||||
ProFile *proFile = parser.parsedProBlock(Utils::make_stringview(input),
|
||||
0,
|
||||
QLatin1String(BASE_DIR "/test.pro"),
|
||||
1);
|
||||
QVERIFY(proFile);
|
||||
QmakeProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, QDir(BASE_DIR),
|
||||
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest>
|
||||
#include <QObject>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QStringList)
|
||||
#include <QStringList>
|
||||
#include <QtTest>
|
||||
|
||||
class tst_TestTrie : public QObject
|
||||
{
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QEventLoop>
|
||||
#include <QRandomGenerator>
|
||||
#include <QStringList>
|
||||
#include <QTemporaryDir>
|
||||
#include <QTimer>
|
||||
@@ -386,7 +387,7 @@ void tst_Ssh::sftp()
|
||||
QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(file.errorString()));
|
||||
int content[1024 / sizeof(int)];
|
||||
for (size_t j = 0; j < sizeof content / sizeof content[0]; ++j)
|
||||
content[j] = qrand();
|
||||
content[j] = QRandomGenerator::global()->generate();
|
||||
file.write(reinterpret_cast<char *>(content), sizeof content);
|
||||
file.close();
|
||||
QVERIFY2(file.error() == QFile::NoError, qPrintable(file.errorString()));
|
||||
@@ -401,7 +402,7 @@ void tst_Ssh::sftp()
|
||||
for (int block = 0; block < blockCount; ++block) {
|
||||
int content[blockSize / sizeof(int)];
|
||||
for (size_t j = 0; j < sizeof content / sizeof content[0]; ++j)
|
||||
content[j] = qrand();
|
||||
content[j] = QRandomGenerator::global()->generate();
|
||||
bigFile.write(reinterpret_cast<char *>(content), sizeof content);
|
||||
}
|
||||
bigFile.close();
|
||||
|
||||
@@ -19,6 +19,7 @@ add_qtc_test(unittest GTEST
|
||||
DEPENDS
|
||||
Qt5::Core Qt5::Network Qt5::Widgets
|
||||
Qt5::Xml Qt5::Concurrent Qt5::Qml Qt5::Gui
|
||||
Qt6Core5Compat
|
||||
Googletest
|
||||
DEFINES
|
||||
QT_NO_CAST_TO_ASCII
|
||||
|
||||
Reference in New Issue
Block a user