summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp39
-rw-r--r--tests/auto/corelib/itemmodels/CMakeLists.txt2
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp7
-rw-r--r--tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp61
-rw-r--r--tests/auto/corelib/text/qunicodetools/tst_qunicodetools.cpp12
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp2
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp4
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp1
-rw-r--r--tests/auto/other/qaccessibility/tst_qaccessibility.cpp5
-rw-r--r--tests/auto/other/qfocusevent/tst_qfocusevent.cpp2
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp1
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp9
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp95
13 files changed, 206 insertions, 34 deletions
diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp
index 458cdece514..dceb1e3bf66 100644
--- a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp
+++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp
@@ -55,6 +55,8 @@ class tst_QSaveFile : public QObject
public slots:
private slots:
+ void basics();
+ void stdfilesystem();
void transactionalWrite();
void retryTransactionalWrite();
void textStreamManualFlush();
@@ -91,6 +93,43 @@ static inline QByteArray msgCannotOpen(const QFileDevice &f)
return result.toLocal8Bit();
}
+void tst_QSaveFile::basics()
+{
+ QSaveFile f;
+ QCOMPARE(f.fileName(), QString());
+ f.setFileName("foobar");
+ QCOMPARE(f.fileName(), "foobar");
+ f.setFileName(QString());
+ QCOMPARE(f.fileName(), QString());
+
+ QString abspath = QDir::currentPath() + "/foobar";
+ QSaveFile f2(abspath);
+ QCOMPARE(f2.fileName(), abspath);
+ f2.setFileName(QString());
+ QCOMPARE(f2.fileName(), QString());
+}
+
+void tst_QSaveFile::stdfilesystem()
+{
+#if QT_CONFIG(cxx17_filesystem)
+ using namespace std::filesystem;
+ QSaveFile f;
+ f.setFileName(path("foobar"));
+ QCOMPARE(f.fileName(), "foobar");
+ QCOMPARE(f.filesystemFileName(), path("foobar"));
+ f.setFileName(path());
+ QCOMPARE(f.fileName(), QString());
+ QVERIFY(f.filesystemFileName().empty());
+
+ path abspath = QDir::current().filesystemAbsolutePath() / "foobar";
+ QSaveFile f2(abspath);
+ QCOMPARE(f2.filesystemFileName(), abspath);
+ f2.setFileName(path());
+ QCOMPARE(f2.fileName(), QString());
+ QVERIFY(f.filesystemFileName().empty());
+#endif
+}
+
void tst_QSaveFile::transactionalWrite()
{
QTemporaryDir dir;
diff --git a/tests/auto/corelib/itemmodels/CMakeLists.txt b/tests/auto/corelib/itemmodels/CMakeLists.txt
index 15c32b7a6f2..8304fa15bc6 100644
--- a/tests/auto/corelib/itemmodels/CMakeLists.txt
+++ b/tests/auto/corelib/itemmodels/CMakeLists.txt
@@ -2,8 +2,8 @@
# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qstringlistmodel)
-add_subdirectory(qrangemodel)
if(TARGET Qt::Gui)
+ add_subdirectory(qrangemodel)
add_subdirectory(qabstractitemmodel)
if(QT_FEATURE_proxymodel)
add_subdirectory(qabstractproxymodel)
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index e0173412339..a6662878786 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -2484,6 +2484,10 @@ void tst_QByteArray::fromPercentEncoding()
QFETCH(QByteArray, decodedString);
QCOMPARE(encodedString.percentDecoded(), decodedString);
+ QCOMPARE(QByteArray::fromPercentEncoding(encodedString), decodedString);
+ QCOMPARE(QByteArray{encodedString}.percentDecoded(), decodedString); // rvalue, shared
+ encodedString.detach();
+ QCOMPARE(std::move(encodedString).percentDecoded(), decodedString); // rvalue, detached
}
void tst_QByteArray::toPercentEncoding_data()
@@ -2545,6 +2549,9 @@ void tst_QByteArray::pecentEncodingRoundTrip()
QByteArray encodedData = original.toPercentEncoding(excludeInEncoding, includeInEncoding);
QCOMPARE(encodedData, encoded);
QCOMPARE(encodedData.percentDecoded(), original);
+ QCOMPARE(QByteArray{encodedData}.percentDecoded(), original); // rvalue, shared
+ encodedData.detach();
+ QCOMPARE(std::move(encodedData).percentDecoded(), original); // rvalue, detached
}
struct StringComparisonData
diff --git a/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp b/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp
index 22bff24eec0..c0a67840c75 100644
--- a/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp
+++ b/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp
@@ -11,6 +11,8 @@ class tst_QStringIterator : public QObject
private slots:
void sweep_data();
void sweep();
+ void nextOrRawCodeUnitEquivalenceWithOldCode_data() { sweep_data(); }
+ void nextOrRawCodeUnitEquivalenceWithOldCode();
void position();
};
@@ -253,6 +255,65 @@ void tst_QStringIterator::sweep()
}
}
+void tst_QStringIterator::nextOrRawCodeUnitEquivalenceWithOldCode()
+{
+ QFETCH(const QString, string);
+ // QFETCH(bool, valid);
+
+ const auto s = string.data_ptr().data(); // avoids QChar
+
+ // this is the old code, used before we had nextOrRawCodeUnit():
+ const auto oldResult = [&] {
+ QList<char32_t> result;
+ result.reserve(string.size());
+
+ const auto len = string.size();
+ for (qsizetype i = 0; i < len; ++i) {
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_CLANG("-Wcharacter-conversion")
+ char32_t ucs4;
+ const char16_t c = s[i];
+ if (QChar::isHighSurrogate(c) && i + 1 < len && QChar::isLowSurrogate(s[i + 1]))
+ ucs4 = QChar::surrogateToUcs4(c, s[++i]);
+ else
+ ucs4 = c;
+ QT_WARNING_POP
+ result.push_back(ucs4);
+ }
+ return result;
+ }();
+
+ // now the same with nextOrRawCodeUnit():
+ const auto newResult = [&] {
+ QList<char32_t> result;
+ result.reserve(string.size());
+
+ QStringIterator it(string);
+ while (it.hasNext())
+ result.push_back(it.nextOrRawCodeUnit());
+
+ return result;
+ }();
+
+ // they should yield the equivalent series of code points:
+ QCOMPARE_EQ(newResult, oldResult);
+
+ // also check next/previousOrRawCodeUnit() consistency:
+ const auto fromBack = [&] {
+ QList<char32_t> result;
+ result.reserve(string.size());
+
+ QStringIterator it(string, string.size());
+ while (it.hasPrevious())
+ result.push_back(it.previousOrRawCodeUnit());
+
+ std::reverse(result.begin(), result.end());
+ return result;
+ }();
+
+ QCOMPARE_EQ(fromBack, newResult);
+}
+
void tst_QStringIterator::position()
{
static const QChar stringData[] =
diff --git a/tests/auto/corelib/text/qunicodetools/tst_qunicodetools.cpp b/tests/auto/corelib/text/qunicodetools/tst_qunicodetools.cpp
index abb7497928a..a6a0ef2f26d 100644
--- a/tests/auto/corelib/text/qunicodetools/tst_qunicodetools.cpp
+++ b/tests/auto/corelib/text/qunicodetools/tst_qunicodetools.cpp
@@ -12,6 +12,7 @@ class tst_QUnicodeTools : public QObject
{
Q_OBJECT
private slots:
+ void allSurrogatesHaveLineBreakClassSG();
void lineBreakClass();
void graphemeBreakClass_data();
void graphemeBreakClass();
@@ -21,6 +22,17 @@ private slots:
void sentenceBreakClass();
};
+void tst_QUnicodeTools::allSurrogatesHaveLineBreakClassSG()
+{
+ char32_t c;
+ auto printOnFail = qScopeGuard([&] { qDebug() << c; });
+ for (c = 0; c <= QChar::LastValidCodePoint; ++c) {
+ if (QChar::isSurrogate(c))
+ QCOMPARE_EQ(QUnicodeTables::lineBreakClass(c), QUnicodeTables::LineBreak_SG);
+ }
+ printOnFail.dismiss();
+}
+
void tst_QUnicodeTools::lineBreakClass()
{
QVERIFY(QUnicodeTables::lineBreakClass(0x0029) == QUnicodeTables::LineBreak_CP);
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index 6a72b5ddf38..66fbac97977 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -1947,7 +1947,7 @@ void tst_QTimeZone::roundtripDisplayNames()
if (!match)
match = QTimeZonePrivate::findLongNamePrefix(extended, locale);
if (!match)
- match = QTimeZonePrivate::findNarrowOffsetPrefix(extended, locale, QLocale::NarrowFormat);
+ match = QTimeZonePrivate::findNarrowOffsetPrefix(extended, locale);
if (!match)
match = QTimeZonePrivate::findLongUtcPrefix(extended);
auto report = qScopeGuard([=]() {
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index 463f600e36d..cbe04ae39f7 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -650,14 +650,14 @@ QT_WARNING_POP
{
QList<int *> list;
QVERIFY(list.value(0) == 0);
- int i;
+ int i = 42;
list.append(&i);
QVERIFY(list.value(0) == &i);
}
{
QList<const int *> list;
QVERIFY(list.value(0) == 0);
- int i;
+ int i = 42;
list.append(&i);
QVERIFY(list.value(0) == &i);
}
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index f7c5af53310..9129fb2e7ed 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -3244,7 +3244,6 @@ void tst_QWindow::enterLeaveOnWindowShowHide()
QSKIP("We can't move the cursor");
window.show();
- window.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&window));
++expectedEnter;
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
index bf3efca35b2..a067ac541b0 100644
--- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
@@ -1357,6 +1357,11 @@ void tst_QAccessibility::scrollBarTest()
scrollBar->setMinimum(11);
scrollBar->setMaximum(111);
+ QAccessibleAttributesInterface *attributesIface = scrollBarInterface->attributesInterface();
+ QVERIFY(attributesIface);
+ QVERIFY(attributesIface->attributeKeys().contains(QAccessible::Attribute::Orientation));
+ QCOMPARE(attributesIface->attributeValue(QAccessible::Attribute::Orientation), Qt::Horizontal);
+
QAccessibleValueInterface *valueIface = scrollBarInterface->valueInterface();
QVERIFY(valueIface != 0);
QCOMPARE(valueIface->minimumValue().toInt(), scrollBar->minimum());
diff --git a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp
index c1b72d4d623..b4cfb0f4f79 100644
--- a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp
+++ b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp
@@ -364,7 +364,6 @@ void tst_QFocusEvent::checkReason_ActiveWindow()
Window window;
window.show();
- window.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&window));
if (windowActivationReasonFail)
@@ -374,7 +373,6 @@ void tst_QFocusEvent::checkReason_ActiveWindow()
Window window2;
window2.show();
- window2.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&window2));
if (windowActivationReasonFail)
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index a79d3454724..e8a3e8c046d 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -47,6 +47,7 @@ Q_GUI_EXPORT void qt_test_resetFetchedRoot();
QT_END_NAMESPACE
#endif
+[[maybe_unused]]
static QByteArray msgDoesNotExist(const QString &name)
{
return (QLatin1Char('"') + QDir::toNativeSeparators(name)
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index b651668cabd..526081b2f19 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -2842,15 +2842,6 @@ const bool block_some_signals = true; // The test should also work with this set
const int rowcount = 500;
const int colcount = 10;
-static inline QString istr(int n, bool comma = true)
-{
- QString s;
- s.setNum(n);
- if (comma)
- s += ", ";
- return s;
-}
-
void tst_QHeaderView::setupTestData()
{
QTest::addColumn<bool>("updates_enabled");
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 8e46876934d..e3d172c60c0 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -187,6 +187,7 @@ private slots:
void mapFromAndTo();
void focusChainOnHide();
void focusChainOnReparent();
+ void focusChainOnReparentNoChange();
void focusAbstraction();
void defaultTabOrder();
void reverseTabOrder();
@@ -1983,6 +1984,82 @@ void tst_QWidget::focusChainOnReparent()
}
}
+//#define DEBUG_FOCUS_CHAIN
+static void dumpFocusChain(QWidget *start, bool bForward, const char *desc = nullptr)
+{
+#ifdef DEBUG_FOCUS_CHAIN
+ qDebug() << "Dump focus chain, start:" << start << "isForward:" << bForward << desc;
+ QWidget *cur = start;
+ do {
+ qDebug() << "-" << cur << cur->objectName();
+ auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur));
+ cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev;
+ } while (cur != start);
+#else
+ Q_UNUSED(start);
+ Q_UNUSED(bForward);
+ Q_UNUSED(desc);
+#endif
+}
+
+void tst_QWidget::focusChainOnReparentNoChange()
+{
+ QWidget window;
+
+ auto new_QWidget = [](QWidget *parent, const char *name) {
+ QWidget *w = new QWidget(parent);
+ w->setObjectName(name);
+ return w;
+ };
+ QWidget *child1 = new_QWidget(&window, "child1");
+ QWidget *child2 = new_QWidget(&window, "child2");
+ QWidget *child3 = new_QWidget(&window, "child3");
+ QWidget *child21 = new_QWidget(child2, "child21");
+ QWidget *child22 = new_QWidget(child2, "child22");
+ QWidget *child4 = new_QWidget(&window, "child4");
+
+ dumpFocusChain(&window, true);
+
+ QWidget *expectedOriginalChain[8] = {&window, child1, child2, child3, child21, child22, child4, &window};
+ QWidget *w = &window;
+ for (auto expectedOriginal : expectedOriginalChain) {
+ QCOMPARE(w, expectedOriginal);
+ w = w->nextInFocusChain();
+ }
+ for (int i = 7; i >= 0; --i) {
+ w = w->previousInFocusChain();
+ QCOMPARE(w, expectedOriginalChain[i]);
+ }
+
+ child2->setParent(child4);
+ child22->setParent(&window);
+ dumpFocusChain(&window, true);
+
+ /*
+ * child2 and child22 was reparented *within* the &window hierarchy
+ * Hierarchy is now:
+ *
+ * - window
+ * - child1
+ * - child3
+ * - child4
+ * - child2
+ * - child21
+ * - child22
+ *
+ * but focus chain remains the same (it depends on the order of widget construction)
+ */
+ QWidget *expectedNewChain[8] = {&window, child1, child2, child3, child21, child22, child4, &window};
+ w = &window;
+ for (auto expectedNew : expectedNewChain) {
+ QCOMPARE(w, expectedNew);
+ w = w->nextInFocusChain();
+ }
+ for (int i = 7; i >= 0; --i) {
+ w = w->previousInFocusChain();
+ QCOMPARE(w, expectedNewChain[i]);
+ }
+}
void tst_QWidget::focusChainOnHide()
{
@@ -2536,24 +2613,6 @@ void tst_QWidget::tabOrderWithProxyDisabled()
qPrintable(focusWidgetName()));
}
-//#define DEBUG_FOCUS_CHAIN
-static void dumpFocusChain(QWidget *start, bool bForward, const char *desc = nullptr)
-{
-#ifdef DEBUG_FOCUS_CHAIN
- qDebug() << "Dump focus chain, start:" << start << "isForward:" << bForward << desc;
- QWidget *cur = start;
- do {
- qDebug() << "-" << cur;
- auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur));
- cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev;
- } while (cur != start);
-#else
- Q_UNUSED(start);
- Q_UNUSED(bForward);
- Q_UNUSED(desc);
-#endif
-}
-
void tst_QWidget::tabOrderWithCompoundWidgets()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))