5#include <QFontDatabase>
6#include <QtCore/qatomicscopedvaluerollback.h>
8#include <initializer_list>
10using namespace Qt::StringLiterals;
32 void defaultTryTimeout();
38 using namespace std::chrono_literals;
41 QTest::defaultTryTimeout.store(1s, std::memory_order_relaxed);
62QVERIFY2(QFileInfo(
"file.txt").exists(),
"file.txt does not exist.");
66QCOMPARE(QString(
"hello").toUpper(), QString(
"HELLO"));
73 QTest::addColumn<QString>(
"aString");
74 QTest::addColumn<
int>(
"expected");
76 QTest::newRow(
"positive+value") <<
"42" << 42;
77 QTest::newRow(
"negative-value") <<
"-42" << -42;
78 QTest::newRow(
"zero") <<
"0" << 0;
85 QFETCH(QString, aString);
86 QFETCH(
int, expected);
88 QCOMPARE(aString.toInt(), expected);
98 QFAIL(
"This test has not been ported to this platform yet.");
102QFETCH(QString, myString);
103QCOMPARE(QString(
"hello").toUpper(), myString);
107QTEST(QString(
"hello").toUpper(),
"myString");
111if (!QSqlDatabase::drivers().contains(
"SQLITE"))
112 QSKIP(
"This test requires the SQLITE database driver");
116QEXPECT_FAIL(
"",
"Will fix in the next release", Continue);
122QEXPECT_FAIL(
"data27",
"Oh my, this is soooo broken", Abort);
128QTEST_MAIN(TestQString)
133 class MyTestObject :
public QObject
146QTest::ignoreMessage(QtWarningMsg,
"QDir::mkdir: Empty or null file name(s)");
154 QTest::addColumn<QString>(
"aString");
155 QTest::newRow(
"just.hello") << QString(
"hello");
156 QTest::newRow(
"a.null.string") << QString();
163 QTest::addColumn<
int>(
"input");
164 QTest::addColumn<QString>(
"output");
165 QTest::addRow(
"%d", 0) << 0 << QString(
"0");
166 QTest::addRow(
"%d", 1) << 1 << QString(
"1");
173 QTest::addColumn<
int>(
"intval");
174 QTest::addColumn<QString>(
"str");
175 QTest::addColumn<
double>(
"dbl");
176 QTest::newRow(
"row1") << 1 <<
"hello" << 1.5;
183 if (qstrcmp(QTest::currentTestFunction(),
"myDatabaseTest") == 0) {
193using namespace std::chrono_literals;
201 QString str1 = u"This is a test string"_s;
202 QString str2 = u"This is a test string"_s;
203 QCOMPARE(str1.localeAwareCompare(str2), 0);
205 str1.localeAwareCompare(str2);
214bool opened = file.open(QIODevice::WriteOnly);
218QVERIFY2(file.open(QIODevice::WriteOnly),
219 qPrintable(QString(
"open %1: %2")
220 .arg(file.fileName()).arg(file.errorString())));
227 const int expected[] = {8, 10, 12, 16, 20, 24};
228 QCOMPARE(QFontDatabase::standardSizes(), expected);
235 #define ARG(...) __VA_ARGS__
236 QCOMPARE(QFontDatabase::standardSizes(),
ARG({8, 10, 12, 16, 20, 24}));
244const auto restoreDefaultLocale = qScopeGuard([prior = QLocale()]() {
245 QLocale::setDefault(prior);
248QLocale::setDefault(QLocale::c());
254 const QStringList actual = locale.uiLanguages();
255 auto report = qScopeGuard([&actual]() {
256 qDebug(
"\n\t%ls", qUtf16Printable(actual.join(
"\n\t"_L1)));
258 QCOMPARE(actual, expected);
265 using namespace std::chrono_literals;
268 const auto timeoutRollback = QAtomicScopedValueRollback(
269 QTest::defaultTryTimeout, 1s, std::memory_order_relaxed);
274 QCOMPARE(QTest::defaultTryTimeout.load(std::memory_order_relaxed), 1s);
void scopeGuardReport(const QLocale &locale, const QStringList &expected) const
void addSingleStringRows()
[20]
void addMultStringRows()
[20]
void wrapInFunction()
[16]
void compareListToInitializerList()
void quarterSecondSleep()
[22]
void compareListToArray()
void withRestoredDefaultLocale()