qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qdesktopservices)
add_subdirectory(qdoublevalidator)
add_subdirectory(qintvalidator)
add_subdirectory(qregularexpressionvalidator)
add_subdirectory(qtexturefilereader)
add_subdirectory(qundogroup)
add_subdirectory(qundostack)

View File

@ -0,0 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qdesktopservices Test:
#####################################################################
qt_internal_add_test(tst_qdesktopservices
SOURCES
tst_qdesktopservices.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,84 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <qdesktopservices.h>
#include <qregularexpression.h>
using namespace Qt::StringLiterals;
class tst_qdesktopservices : public QObject
{
Q_OBJECT
private slots:
void openUrl();
void handlers();
};
void tst_qdesktopservices::openUrl()
{
// At the bare minimum check that they return false for invalid url's
QCOMPARE(QDesktopServices::openUrl(QUrl()), false);
#if defined(Q_OS_WIN)
// this test is only valid on windows on other systems it might mean open a new document in the application handling .file
const QRegularExpression messagePattern("ShellExecute 'file://invalid\\.file' failed \\(error \\d+\\)\\.");
QVERIFY(messagePattern.isValid());
QTest::ignoreMessage(QtWarningMsg, messagePattern);
QCOMPARE(QDesktopServices::openUrl(QUrl("file://invalid.file")), false);
#endif
}
class MyUrlHandler : public QObject
{
Q_OBJECT
public:
QUrl lastHandledUrl;
public slots:
inline void handle(const QUrl &url) {
lastHandledUrl = url;
}
};
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
# define CAN_IMPLICITLY_UNSET
#endif
void tst_qdesktopservices::handlers()
{
MyUrlHandler fooHandler;
MyUrlHandler barHandler;
QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle");
QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle");
#ifndef CAN_IMPLICITLY_UNSET
const auto unsetHandlers = qScopeGuard([] {
QDesktopServices::unsetUrlHandler(u"bar"_s);
QDesktopServices::unsetUrlHandler(u"foo"_s);
});
#endif
QUrl fooUrl("foo://blub/meh");
QUrl barUrl("bar://hmm/hmmmm");
QVERIFY(QDesktopServices::openUrl(fooUrl));
QVERIFY(QDesktopServices::openUrl(barUrl));
QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString());
QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString());
#ifdef CAN_IMPLICITLY_UNSET
for (int i = 0; i < 2; ++i)
QTest::ignoreMessage(QtWarningMsg,
"Please call QDesktopServices::unsetUrlHandler() before destroying a "
"registered URL handler object.\n"
"Support for destroying a registered URL handler object is deprecated, "
"and will be removed in Qt 6.6.");
#endif
}
QTEST_MAIN(tst_qdesktopservices)
#include "tst_qdesktopservices.moc"

View File

@ -0,0 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qdoublevalidator Test:
#####################################################################
qt_internal_add_test(tst_qdoublevalidator
SOURCES
tst_qdoublevalidator.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,747 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QSignalSpy>
#include <qvalidator.h>
class tst_QDoubleValidator : public QObject
{
Q_OBJECT
private slots:
void validate_data();
void validate();
void zeroPaddedExponent_data();
void zeroPaddedExponent();
void validateThouSep_data();
void validateThouSep();
void validateIntEquiv_data();
void validateIntEquiv();
void notifySignals();
void fixup();
void fixup_data();
void setRangeOverloads();
void setRangeOverloads_data();
};
Q_DECLARE_METATYPE(QValidator::State);
#define INV QValidator::Invalid
#define ITM QValidator::Intermediate
#define ACC QValidator::Acceptable
void tst_QDoubleValidator::validateThouSep_data()
{
QTest::addColumn<QString>("localeName");
QTest::addColumn<QString>("value");
QTest::addColumn<bool>("rejectGroupSeparator");
QTest::addColumn<QValidator::State>("result");
QTest::newRow("1,000C") << "C" << QString("1,000") << false << ACC;
QTest::newRow("1,000.1C") << "C" << QString("1,000.1") << false << ACC;
QTest::newRow("1,000.1C_reject") << "C" << QString("1,000.1") << true << INV;
QTest::newRow("1.000C") << "C" << QString("1.000") << false << ACC;
QTest::newRow("1,000de") << "de" << QString("1,000") << false << ACC;
QTest::newRow("1.000de") << "de" << QString("1.000") << false << ACC;
QTest::newRow(".C") << "C" << QString(".") << false << ITM;
QTest::newRow(".de") << "de" << QString(".") << false << INV;
QTest::newRow("1.000,1de") << "de" << QString("1.000,1") << false << ACC;
QTest::newRow("1.000,1de_reject") << "de" << QString("1.000,1") << true << INV;
QTest::newRow(",C") << "C" << QString(",") << false << INV;
QTest::newRow(",de") << "de" << QString(",") << false << ITM;
QTest::newRow("1,23") << "en_AU" << QString("1,00") << false << ITM;
}
void tst_QDoubleValidator::validateThouSep()
{
QFETCH(QString, localeName);
QFETCH(QString, value);
QFETCH(bool, rejectGroupSeparator);
QFETCH(QValidator::State, result);
int dummy = 0;
QDoubleValidator iv(-10000, 10000, 3, 0);
iv.setNotation(QDoubleValidator::ScientificNotation);
QLocale locale(localeName);
if (rejectGroupSeparator)
locale.setNumberOptions(QLocale::RejectGroupSeparator);
iv.setLocale(locale);
QCOMPARE(iv.validate(value, dummy), result);
}
void tst_QDoubleValidator::validate_data()
{
QTest::addColumn<QString>("localeName");
QTest::addColumn<double>("minimum");
QTest::addColumn<double>("maximum");
QTest::addColumn<int>("decimals");
QTest::addColumn<QString>("value");
QTest::addColumn<QValidator::State>("scientific_state");
QTest::addColumn<QValidator::State>("standard_state");
QTest::newRow("data0") << "C" << 0.0 << 100.0 << 1 << QString("50.0") << ACC << ACC;
QTest::newRow("data1") << "C" << 00.0 << 100.0 << 1 << QString("500.0") << ITM << ITM;
QTest::newRow("data1a") << "C" << 00.0 << 100.0 << 1 << QString("5001.0") << ITM << INV;
QTest::newRow("data2") << "C" << 00.0 << 100.0 << 1 << QString("-35.0") << INV << INV;
QTest::newRow("data3") << "C" << 00.0 << 100.0 << 1 << QString("a") << INV << INV;
QTest::newRow("data4") << "C" << 0.0 << 100.0 << 1 << QString("-") << INV << INV;
QTest::newRow("data5") << "C" << 0.0 << 100.0 << 1 << QString("100.0") << ACC << ACC;
QTest::newRow("data6") << "C" << -100.0 << 100.0 << 1 << QString("-") << ITM << ITM;
QTest::newRow("data7") << "C" << -100.0 << 100.0 << 1 << QString("-500.0") << ITM << ITM;
QTest::newRow("data8") << "C" << -100.0 << 100.0 << 1 << QString("-100") << ACC << ACC;
QTest::newRow("data9") << "C" << -100.0 << -10.0 << 1 << QString("10") << ITM << ITM;
QTest::newRow("data10") << "C" << 0.3 << 0.5 << 5 << QString("0.34567") << ACC << ACC;
QTest::newRow("data11") << "C" << -0.3 << -0.5 << 5 << QString("-0.345678") << INV << INV;
QTest::newRow("data12") << "C" << -0.32 << 0.32 << 1 << QString("0") << ACC << ACC;
QTest::newRow("data13") << "C" << 0.0 << 100.0 << 1 << QString("3456a") << INV << INV;
QTest::newRow("data14") << "C" << -100.0 << 100.0 << 1 << QString("-3456a") << INV << INV;
QTest::newRow("data15") << "C" << -100.0 << 100.0 << 1 << QString("a-3456") << INV << INV;
QTest::newRow("data16") << "C" << -100.0 << 100.0 << 1 << QString("a-3456a") << INV << INV;
QTest::newRow("data17") << "C" << 1229.0 << 1231.0 << 0 << QString("123e") << ITM << INV;
QTest::newRow("data18") << "C" << 1229.0 << 1231.0 << 0 << QString("123e+") << ITM << INV;
QTest::newRow("data19") << "C" << 1229.0 << 1231.0 << 0 << QString("123e+1") << ACC << INV;
QTest::newRow("data20") << "C" << 12290.0 << 12310.0 << 0 << QString("123e+2") << ACC << INV;
QTest::newRow("data21") << "C" << 12.290 << 12.310 << 2 << QString("123e-") << ITM << INV;
QTest::newRow("data22") << "C" << 12.290 << 12.310 << 2 << QString("123e-1") << ACC << INV;
QTest::newRow("data23") << "C" << 1.2290 << 1.2310 << 3 << QString("123e-2") << ACC << INV;
QTest::newRow("data24") << "C" << 1229.0 << 1231.0 << 0 << QString("123E") << ITM << INV;
QTest::newRow("data25") << "C" << 1229.0 << 1231.0 << 0 << QString("123E+") << ITM << INV;
QTest::newRow("data26") << "C" << 1229.0 << 1231.0 << 0 << QString("123E+1") << ACC << INV;
QTest::newRow("data27") << "C" << 12290.0 << 12310.0 << 0 << QString("123E+2") << ACC << INV;
QTest::newRow("data28") << "C" << 12.290 << 12.310 << 2 << QString("123E-") << ITM << INV;
QTest::newRow("data29") << "C" << 12.290 << 12.310 << 2 << QString("123E-1") << ACC << INV;
QTest::newRow("data30") << "C" << 1.2290 << 1.2310 << 3 << QString("123E-2") << ACC << INV;
QTest::newRow("data31") << "C" << 1.2290 << 1.2310 << 3 << QString("e") << ITM << INV;
QTest::newRow("data32") << "C" << 1.2290 << 1.2310 << 3 << QString("e+") << ITM << INV;
QTest::newRow("data33") << "C" << 1.2290 << 1.2310 << 3 << QString("e+1") << ITM << INV;
QTest::newRow("data34") << "C" << 1.2290 << 1.2310 << 3 << QString("e-") << ITM << INV;
QTest::newRow("data35") << "C" << 1.2290 << 1.2310 << 3 << QString("e-1") << ITM << INV;
QTest::newRow("data36") << "C" << 1.2290 << 1.2310 << 3 << QString("E") << ITM << INV;
QTest::newRow("data37") << "C" << 1.2290 << 1.2310 << 3 << QString("E+") << ITM << INV;
QTest::newRow("data38") << "C" << 1.2290 << 1.2310 << 3 << QString("E+1") << ITM << INV;
QTest::newRow("data39") << "C" << 1.2290 << 1.2310 << 3 << QString("E-") << ITM << INV;
QTest::newRow("data40") << "C" << 1.2290 << 1.2310 << 3 << QString("E-1") << ITM << INV;
QTest::newRow("data41") << "C" << -100.0 << 100.0 << 0 << QString("10e") << ITM << INV;
QTest::newRow("data42") << "C" << -100.0 << 100.0 << 0 << QString("10e+") << ITM << INV;
QTest::newRow("data43") << "C" << 0.01 << 0.09 << 2 << QString("0") << ITM << ITM;
QTest::newRow("data44") << "C" << 0.0 << 10.0 << 1 << QString("11") << ITM << ITM;
QTest::newRow("data45") << "C" << 0.0 << 10.0 << 2 << QString("11") << ITM << ITM;
QTest::newRow("data46") << "C" << 0.0 << 100.0 << 0 << QString("0.") << ACC << ACC;
QTest::newRow("data47") << "C" << 0.0 << 100.0 << 0 << QString("0.0") << INV << INV;
QTest::newRow("data48") << "C" << 0.0 << 100.0 << 1 << QString("0.0") << ACC << ACC;
QTest::newRow("data49") << "C" << 0.0 << 100.0 << 0 << QString(".") << ITM << ITM;
QTest::newRow("data50") << "C" << 0.0 << 100.0 << 1 << QString(".") << ITM << ITM;
QTest::newRow("data51") << "C" << 0.0 << 2.0 << 2 << QString("9.99") << ITM << ITM;
QTest::newRow("data52") << "C" << 100.0 << 200.0 << 4 << QString("999.9999") << ITM << ITM;
QTest::newRow("data53") << "C" << 0.0 << 2.0 << 2 << QString("9.9999") << INV << INV;
QTest::newRow("data54") << "C" << 100.0 << 200.0 << 4 << QString("9999.9999") << ITM << INV;
QTest::newRow("data55") << "C" << 1229.0 << 1231.0 << -1 << QString("123E") << ITM << INV;
QTest::newRow("data56") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+") << ITM << INV;
QTest::newRow("data57") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+1") << ACC << INV;
QTest::newRow("data58") << "C" << 0.0 << 100.0 << -1 << QString("0.0") << ACC << ACC;
QTest::newRow("overlong") << "C" << 0.0 << 99.9 << 2 << QString("1234.0") << ITM << INV;
QTest::newRow("data_de0") << "de" << 0.0 << 100.0 << 1 << QString("50,0") << ACC << ACC;
QTest::newRow("data_de1") << "de" << 00.0 << 100.0 << 1 << QString("500,0") << ITM << ITM;
QTest::newRow("data_de1a") << "de" << 00.0 << 100.0 << 1 << QString("5001,0") << ITM << INV;
QTest::newRow("data_de0C") << "de" << 0.0 << 100.0 << 1 << QString("50,0") << ACC << ACC;
QTest::newRow("data_de1C") << "de" << 00.0 << 100.0 << 1 << QString("500,0") << ITM << ITM;
QTest::newRow("data_de1aC") << "de" << 00.0 << 100.0 << 1 << QString("5001,0") << ITM << INV;
QTest::newRow("data_de2") << "de" << 00.0 << 100.0 << 1 << QString("-35,0") << INV << INV;
QTest::newRow("data_de3") << "de" << 00.0 << 100.0 << 1 << QString("a") << INV << INV;
QTest::newRow("data_de4") << "de" << 0.0 << 100.0 << 1 << QString("-") << INV << INV;
QTest::newRow("data_de5") << "de" << 0.0 << 100.0 << 1 << QString("100,0") << ACC << ACC;
QTest::newRow("data_de6") << "de" << -100.0 << 100.0 << 1 << QString("-") << ITM << ITM;
QTest::newRow("data_de7") << "de" << -100.0 << 100.0 << 1 << QString("-500,0") << ITM << ITM;
QTest::newRow("data_de8") << "de" << -100.0 << 100.0 << 1 << QString("-100") << ACC << ACC;
QTest::newRow("data_de9") << "de" << -100.0 << -10.0 << 1 << QString("10") << ITM << ITM;
QTest::newRow("data_de10") << "de" << 0.3 << 0.5 << 5 << QString("0,34567") << ACC << ACC;
QTest::newRow("data_de11") << "de" << -0.3 << -0.5 << 5 << QString("-0,345678") << INV << INV;
QTest::newRow("data_de12") << "de" << -0.32 << 0.32 << 1 << QString("0") << ACC << ACC;
QTest::newRow("data_de13") << "de" << 0.0 << 100.0 << 1 << QString("3456a") << INV << INV;
QTest::newRow("data_de14") << "de" << -100.0 << 100.0 << 1 << QString("-3456a") << INV << INV;
QTest::newRow("data_de15") << "de" << -100.0 << 100.0 << 1 << QString("a-3456") << INV << INV;
QTest::newRow("data_de16") << "de" << -100.0 << 100.0 << 1 << QString("a-3456a") << INV << INV;
QTest::newRow("data_de17") << "de" << 1229.0 << 1231.0 << 0 << QString("123e") << ITM << INV;
QTest::newRow("data_de18") << "de" << 1229.0 << 1231.0 << 0 << QString("123e+") << ITM << INV;
QTest::newRow("data_de19") << "de" << 1229.0 << 1231.0 << 0 << QString("123e+1") << ACC << INV;
QTest::newRow("data_de20") << "de" << 12290.0 << 12310.0 << 0 << QString("123e+2") << ACC << INV;
QTest::newRow("data_de21") << "de" << 12.290 << 12.310 << 2 << QString("123e-") << ITM << INV;
QTest::newRow("data_de22") << "de" << 12.290 << 12.310 << 2 << QString("123e-1") << ACC << INV;
QTest::newRow("data_de23") << "de" << 1.2290 << 1.2310 << 3 << QString("123e-2") << ACC << INV;
QTest::newRow("data_de24") << "de" << 1229.0 << 1231.0 << 0 << QString("123E") << ITM << INV;
QTest::newRow("data_de25") << "de" << 1229.0 << 1231.0 << 0 << QString("123E+") << ITM << INV;
QTest::newRow("data_de26") << "de" << 1229.0 << 1231.0 << 0 << QString("123E+1") << ACC << INV;
QTest::newRow("data_de27") << "de" << 12290.0 << 12310.0 << 0 << QString("123E+2") << ACC << INV;
QTest::newRow("data_de28") << "de" << 12.290 << 12.310 << 2 << QString("123E-") << ITM << INV;
QTest::newRow("data_de29") << "de" << 12.290 << 12.310 << 2 << QString("123E-1") << ACC << INV;
QTest::newRow("data_de30") << "de" << 1.2290 << 1.2310 << 3 << QString("123E-2") << ACC << INV;
QTest::newRow("data_de31") << "de" << 1.2290 << 1.2310 << 3 << QString("e") << ITM << INV;
QTest::newRow("data_de32") << "de" << 1.2290 << 1.2310 << 3 << QString("e+") << ITM << INV;
QTest::newRow("data_de33") << "de" << 1.2290 << 1.2310 << 3 << QString("e+1") << ITM << INV;
QTest::newRow("data_de34") << "de" << 1.2290 << 1.2310 << 3 << QString("e-") << ITM << INV;
QTest::newRow("data_de35") << "de" << 1.2290 << 1.2310 << 3 << QString("e-1") << ITM << INV;
QTest::newRow("data_de36") << "de" << 1.2290 << 1.2310 << 3 << QString("E") << ITM << INV;
QTest::newRow("data_de37") << "de" << 1.2290 << 1.2310 << 3 << QString("E+") << ITM << INV;
QTest::newRow("data_de38") << "de" << 1.2290 << 1.2310 << 3 << QString("E+1") << ITM << INV;
QTest::newRow("data_de39") << "de" << 1.2290 << 1.2310 << 3 << QString("E-") << ITM << INV;
QTest::newRow("data_de40") << "de" << 1.2290 << 1.2310 << 3 << QString("E-1") << ITM << INV;
QTest::newRow("data_de41") << "de" << -100.0 << 100.0 << 0 << QString("10e") << ITM << INV;
QTest::newRow("data_de42") << "de" << -100.0 << 100.0 << 0 << QString("10e+") << ITM << INV;
QTest::newRow("data_de43") << "de" << 0.01 << 0.09 << 2 << QString("0") << ITM << ITM;
QTest::newRow("data_de44") << "de" << 0.0 << 10.0 << 1 << QString("11") << ITM << ITM;
QTest::newRow("data_de45") << "de" << 0.0 << 10.0 << 2 << QString("11") << ITM << ITM;
QTest::newRow("data_de46") << "de" << 0.0 << 2.0 << 2 << QString("9,99") << ITM << ITM;
QTest::newRow("data_de47") << "de" << 100.0 << 200.0 << 4 << QString("999,9999") << ITM << ITM;
QTest::newRow("data_de48") << "de" << 0.0 << 2.0 << 2 << QString("9,9999") << INV << INV;
QTest::newRow("data_de49") << "de" << 100.0 << 200.0 << 4 << QString("9999,9999") << ITM << INV;
// using default QDoubleValidator parameters for initialization
QTest::newRow("inf") << "C" << -HUGE_VAL << HUGE_VAL << 1000 << QString("inf") << INV << INV;
QTest::newRow("+inf") << "C" << -HUGE_VAL << HUGE_VAL << 1000 << QString("+inf") << INV << INV;
QTest::newRow("-inf") << "C" << -HUGE_VAL << HUGE_VAL << 1000 << QString("-inf") << INV << INV;
QTest::newRow("nan") << "C" << -HUGE_VAL << HUGE_VAL << 1000 << QString("nan") << INV << INV;
QTest::newRow("+nan") << "C" << -HUGE_VAL << HUGE_VAL << 1000 << QString("+nan") << INV << INV;
QTest::newRow("-nan") << "C" << -HUGE_VAL << HUGE_VAL << 1000 << QString("-nan") << INV << INV;
QString arabicNum;
arabicNum += QChar(1633); // "18.4" in arabic
arabicNum += QChar(1640);
arabicNum += QChar(1643);
arabicNum += QChar(1636);
QTest::newRow("arabic") << "ar" << 0.0 << 20.0 << 2 << arabicNum << ACC << ACC;
// Confim no fallback to C locale
QTest::newRow("data_C1") << "de" << 0.0 << 1000.0 << 2 << QString("1.000,00") << ACC << ACC;
QTest::newRow("data_C2") << "de" << 0.0 << 1000.0 << 2 << QString("1,000.00") << INV << INV;
}
void tst_QDoubleValidator::validate()
{
QFETCH(QString, localeName);
QFETCH(double, minimum);
QFETCH(double, maximum);
QFETCH(int, decimals);
QFETCH(QString, value);
QFETCH(QValidator::State, scientific_state);
QFETCH(QValidator::State, standard_state);
QLocale::setDefault(QLocale(localeName));
QDoubleValidator dv(minimum, maximum, decimals, 0);
int dummy;
QCOMPARE(dv.validate(value, dummy), scientific_state);
dv.setNotation(QDoubleValidator::StandardNotation);
QCOMPARE(dv.validate(value, dummy), standard_state);
}
void tst_QDoubleValidator::zeroPaddedExponent_data()
{
QTest::addColumn<double>("minimum");
QTest::addColumn<double>("maximum");
QTest::addColumn<int>("decimals");
QTest::addColumn<QString>("value");
QTest::addColumn<bool>("rejectZeroPaddedExponent");
QTest::addColumn<QValidator::State>("state");
QTest::newRow("data01") << 1229.0 << 1231.0 << 0 << QString("123e+1") << false << ACC;
QTest::newRow("data02") << 12290.0 << 12310.0 << 0 << QString("123e2") << false << ACC;
QTest::newRow("data03") << 12.290 << 12.310 << 2 << QString("123e-") << false << ITM;
QTest::newRow("data04") << 12.290 << 12.310 << 2 << QString("123e-1") << false << ACC;
QTest::newRow("data05") << 1.2290 << 1.2310 << 3 << QString("123e-2") << false << ACC;
QTest::newRow("data11") << 1229.0 << 1231.0 << 0 << QString("123e+1") << true << ACC;
QTest::newRow("data12") << 12290.0 << 12310.0 << 0 << QString("123e2") << true << ACC;
QTest::newRow("data13") << 12.290 << 12.310 << 2 << QString("123e-") << true << ITM;
QTest::newRow("data14") << 12.290 << 12.310 << 2 << QString("123e-1") << true << ACC;
QTest::newRow("data15") << 1.2290 << 1.2310 << 3 << QString("123e-2") << true << ACC;
QTest::newRow("data21") << 1229.0 << 1231.0 << 0 << QString("123e+01") << false << ACC;
QTest::newRow("data22") << 12290.0 << 12310.0 << 0 << QString("123e02") << false << ACC;
QTest::newRow("data23") << 12.290 << 12.310 << 2 << QString("123e-0") << false << ITM;
QTest::newRow("data24") << 12.290 << 12.310 << 2 << QString("123e-01") << false << ACC;
QTest::newRow("data25") << 1.2290 << 1.2310 << 3 << QString("123e-02") << false << ACC;
QTest::newRow("data31") << 1229.0 << 1231.0 << 0 << QString("123e+01") << true << INV;
QTest::newRow("data32") << 12290.0 << 12310.0 << 0 << QString("123e02") << true << INV;
QTest::newRow("data33") << 12.290 << 12.310 << 2 << QString("123e-0") << true << INV;
QTest::newRow("data34") << 12.290 << 12.310 << 2 << QString("123e-01") << true << INV;
QTest::newRow("data35") << 1.2290 << 1.2310 << 3 << QString("123e-02") << true << INV;
}
void tst_QDoubleValidator::zeroPaddedExponent()
{
QFETCH(double, minimum);
QFETCH(double, maximum);
QFETCH(int, decimals);
QFETCH(QString, value);
QFETCH(bool, rejectZeroPaddedExponent);
QFETCH(QValidator::State, state);
QLocale locale(QLocale::C);
if (rejectZeroPaddedExponent)
locale.setNumberOptions(QLocale::RejectLeadingZeroInExponent);
QDoubleValidator dv(minimum, maximum, decimals, 0);
dv.setLocale(locale);
int dummy;
QCOMPARE(dv.validate(value, dummy), state);
}
void tst_QDoubleValidator::notifySignals()
{
QLocale::setDefault(QLocale("C"));
QDoubleValidator dv(0.1, 0.9, 10, 0);
QSignalSpy topSpy(&dv, SIGNAL(topChanged(double)));
QSignalSpy bottomSpy(&dv, SIGNAL(bottomChanged(double)));
QSignalSpy decSpy(&dv, SIGNAL(decimalsChanged(int)));
QSignalSpy changedSpy(&dv, SIGNAL(changed()));
qRegisterMetaType<QDoubleValidator::Notation>("QDoubleValidator::Notation");
QSignalSpy notSpy(&dv, SIGNAL(notationChanged(QDoubleValidator::Notation)));
QCOMPARE(dv.bottom(), 0.1);
QCOMPARE(dv.top(), 0.9);
QCOMPARE(dv.decimals(), 10);
dv.setTop(0.8);
QCOMPARE(topSpy.size(), 1);
QCOMPARE(changedSpy.size(), 1);
QCOMPARE(dv.top(), 0.8);
dv.setBottom(0.2);
QCOMPARE(bottomSpy.size(), 1);
QCOMPARE(changedSpy.size(), 2);
QCOMPARE(dv.bottom(), 0.2);
dv.setRange(0.2, 0.7);
QCOMPARE(topSpy.size(), 2);
QCOMPARE(bottomSpy.size(), 1);
QCOMPARE(decSpy.size(), 0);
QCOMPARE(changedSpy.size(), 3);
QCOMPARE(dv.bottom(), 0.2);
QCOMPARE(dv.top(), 0.7);
QCOMPARE(dv.decimals(), 10);
dv.setRange(0.3, 0.7);
QCOMPARE(topSpy.size(), 2);
QCOMPARE(bottomSpy.size(), 2);
QCOMPARE(changedSpy.size(), 4);
QCOMPARE(dv.bottom(), 0.3);
QCOMPARE(dv.top(), 0.7);
QCOMPARE(dv.decimals(), 10);
dv.setRange(0.4, 0.6);
QCOMPARE(topSpy.size(), 3);
QCOMPARE(bottomSpy.size(), 3);
QCOMPARE(changedSpy.size(), 5);
QCOMPARE(dv.bottom(), 0.4);
QCOMPARE(dv.top(), 0.6);
QCOMPARE(dv.decimals(), 10);
dv.setDecimals(5);
QCOMPARE(decSpy.size(), 1);
QCOMPARE(changedSpy.size(), 6);
QCOMPARE(dv.decimals(), 5);
dv.setRange(0.4, 0.6, 100);
QCOMPARE(topSpy.size(), 3);
QCOMPARE(bottomSpy.size(), 3);
QCOMPARE(decSpy.size(), 2);
QCOMPARE(changedSpy.size(), 7);
QCOMPARE(dv.bottom(), 0.4);
QCOMPARE(dv.top(), 0.6);
QCOMPARE(dv.decimals(), 100);
dv.setNotation(QDoubleValidator::StandardNotation);
QCOMPARE(notSpy.size(), 1);
QCOMPARE(changedSpy.size(), 8);
QCOMPARE(dv.notation(), QDoubleValidator::StandardNotation);
dv.setRange(dv.bottom(), dv.top(), dv.decimals());
QCOMPARE(topSpy.size(), 3);
QCOMPARE(bottomSpy.size(), 3);
QCOMPARE(decSpy.size(), 2);
QCOMPARE(changedSpy.size(), 8);
dv.setNotation(dv.notation());
QCOMPARE(notSpy.size(), 1);
QCOMPARE(changedSpy.size(), 8);
dv.setLocale(QLocale("C"));
QCOMPARE(changedSpy.size(), 8);
dv.setLocale(QLocale("en"));
QCOMPARE(changedSpy.size(), 9);
}
void tst_QDoubleValidator::fixup()
{
QFETCH(QString, localeName);
QFETCH(QDoubleValidator::Notation, notation);
QFETCH(int, decimals);
QFETCH(QString, input);
QFETCH(QString, output);
QDoubleValidator val;
val.setLocale(QLocale(localeName));
val.setNotation(notation);
val.setDecimals(decimals);
val.fixup(input);
QCOMPARE(input, output);
}
void tst_QDoubleValidator::fixup_data()
{
QTest::addColumn<QString>("localeName");
QTest::addColumn<QDoubleValidator::Notation>("notation");
QTest::addColumn<int>("decimals");
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
// C locale uses '.' as decimal point and ',' as grouping separator.
// C locale does not group digits by default.
QTest::newRow("C standard no digit grouping")
<< "C" << QDoubleValidator::StandardNotation << -1 << "12.345"
<< "12.345";
QTest::newRow("C standard with digit grouping")
<< "C" << QDoubleValidator::StandardNotation << -1 << "-12,345.678"
<< "-12345.678";
QTest::newRow("C standard with invalid digit grouping")
<< "C" << QDoubleValidator::StandardNotation << -1 << "1,234,5.678"
<< "12345.678";
QTest::newRow("C standard with invalid number of decimals")
<< "C" << QDoubleValidator::StandardNotation << 2 << "-12,34.678"
<< "-1234.68";
QTest::newRow("C standard truncate decimals")
<< "C" << QDoubleValidator::StandardNotation << -1
<< "1.23456789012345678901234567890"
<< "1.2345678901234567";
QTest::newRow("C standard skip trailing zeroes")
<< "C" << QDoubleValidator::StandardNotation << -1 << "1,234.5670000"
<< "1234.567";
QTest::newRow("C standard zero value")
<< "C" << QDoubleValidator::StandardNotation << -1 << "0.0"
<< "0";
QTest::newRow("C standard scientific value")
<< "C" << QDoubleValidator::StandardNotation << -1 << "1.23e-2"
<< "1.23e-2";
QTest::newRow("C standard no fractional part")
<< "C" << QDoubleValidator::StandardNotation << -1 << "-1,234"
<< "-1234";
QTest::newRow("C scientific no digit grouping")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "0.98765e2"
<< "9.8765e+01";
QTest::newRow("C scientific with digit grouping")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "-1,234.98765E-4"
<< "-1.23498765E-01";
QTest::newRow("C scientific with invalid digit grouping")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "12,34.98765e2"
<< "1.23498765e+05";
QTest::newRow("C scientific with invalid number of decimals")
<< "C" << QDoubleValidator::ScientificNotation << 2 << "-12,34.98765e2"
<< "-1.23e+05";
QTest::newRow("C scientific truncate decimals")
<< "C" << QDoubleValidator::ScientificNotation << -1
<< "1.23456789012345678901234567890E5"
<< "1.2345678901234567E+05";
QTest::newRow("C scientific skip trailing zeroes")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "1,234.5670000e3"
<< "1.234567e+06";
QTest::newRow("C scientific zero value")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "0.0"
<< "0e+00";
QTest::newRow("C scientific standard value")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "12.345"
<< "1.2345e+01";
QTest::newRow("C scientific no fractional part")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "1,234e2"
<< "1.234e+05";
QTest::newRow("C scientific negative no fractional part")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "-1,234e2"
<< "-1.234e+05";
QTest::newRow("C scientific no fractional and exponent")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "1,234"
<< "1.234e+03";
QTest::newRow("C scientific negative no fractional and exponent")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "-1,234"
<< "-1.234e+03";
// en locale uses '.' as decimal point and ',' as grouping separator.
// en locale groups digits by default. 'E' is used in scientific notation.
QTest::newRow("en standard no digit grouping")
<< "en" << QDoubleValidator::StandardNotation << -1 << "-12.345"
<< "-12.345";
QTest::newRow("en standard with digit grouping")
<< "en" << QDoubleValidator::StandardNotation << -1 << "12,345.678"
<< "12,345.678";
QTest::newRow("en standard with invalid digit grouping")
<< "en" << QDoubleValidator::StandardNotation << -1 << "-1,234,5.678"
<< "-12,345.678";
QTest::newRow("en standard with invalid number of decimals")
<< "en" << QDoubleValidator::StandardNotation << 2 << "12,34.678"
<< "1,234.68";
QTest::newRow("en standard no fractional part")
<< "en" << QDoubleValidator::StandardNotation << -1 << "-12,34"
<< "-1,234";
QTest::newRow("en scientific no digit grouping")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-0.98765e2"
<< "-9.8765E+01";
QTest::newRow("en scientific with digit grouping")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "1,234.98765E-4"
<< "1.23498765E-01";
QTest::newRow("en scientific with invalid digit grouping")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34.98765e2"
<< "-1.23498765E+05";
QTest::newRow("en scientific with invalid number of decimals")
<< "en" << QDoubleValidator::ScientificNotation << 2 << "12,34.98765e2"
<< "1.23E+05";
QTest::newRow("en scientific no fractional part")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "12,34e2"
<< "1.234E+05";
QTest::newRow("en scientific negative no fractional part")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34e2"
<< "-1.234E+05";
QTest::newRow("en scientific no fractional and exponent")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "1,234"
<< "1.234E+03";
QTest::newRow("en scientific negative no fractional and exponent")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-1,234"
<< "-1.234E+03";
// de locale uses ',' as decimal point and '.' as grouping separator.
// de locale groups digits by default. 'E' is used in scientific notation.
QTest::newRow("de standard no digit grouping")
<< "de" << QDoubleValidator::StandardNotation << -1 << "12,345"
<< "12,345";
QTest::newRow("de standard with digit grouping")
<< "de" << QDoubleValidator::StandardNotation << -1 << "-12.345,678"
<< "-12.345,678";
QTest::newRow("de standard with invalid digit grouping")
<< "de" << QDoubleValidator::StandardNotation << -1 << "1.234.5,678"
<< "12.345,678";
QTest::newRow("de standard with invalid number of decimals")
<< "de" << QDoubleValidator::StandardNotation << 2 << "-12.34,678"
<< "-1.234,68";
QTest::newRow("de standard no fractional part")
<< "de" << QDoubleValidator::StandardNotation << -1 << "12.34" << "1.234";
QTest::newRow("de scientific no digit grouping")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "0,98765e2"
<< "9,8765E+01";
QTest::newRow("de scientific with digit grouping")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-1.234,98765E-4"
<< "-1,23498765E-01";
QTest::newRow("de scientific with invalid digit grouping")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "12.34,98765e2"
<< "1,23498765E+05";
QTest::newRow("de scientific with invalid number of decimals")
<< "de" << QDoubleValidator::ScientificNotation << 2 << "-12.34,98765e2"
<< "-1,23E+05";
QTest::newRow("de scientific no fractional part")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "1.234e2"
<< "1,234E+05";
QTest::newRow("de scientific negative no fractional part")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-1.234e2"
<< "-1,234E+05";
QTest::newRow("de scientific no fractional and exponent")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "12.34"
<< "1,234E+03";
QTest::newRow("de scientific negative no fractional and exponent")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-12.34"
<< "-1,234E+03";
// hi locale uses '.' as decimal point and ',' as grouping separator.
// The rightmost group is of three digits, all the others contain two
// digits.
QTest::newRow("hi standard no digit grouping")
<< "hi" << QDoubleValidator::StandardNotation << -1 << "123456.78"
<< "1,23,456.78";
QTest::newRow("hi standard with digit grouping")
<< "hi" << QDoubleValidator::StandardNotation << -1 << "-12,345.678"
<< "-12,345.678";
QTest::newRow("hi standard with invalid digit grouping")
<< "hi" << QDoubleValidator::StandardNotation << -1 << "12,34,56.78"
<< "1,23,456.78";
QTest::newRow("hi standard no fractional part")
<< "hi" << QDoubleValidator::StandardNotation << -1 << "-12,345,6"
<< "-1,23,456";
QTest::newRow("hi scientific no digit grouping")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-0.123e-2"
<< "-1.23E-03";
QTest::newRow("hi scientific with digit grouping")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "12,345.678e-2"
<< "1.2345678E+02";
QTest::newRow("hi scientific with invalid digit grouping")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-1,23,45.678e-2"
<< "-1.2345678E+02";
QTest::newRow("hi scientific no fractional part")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "1,23,456e2"
<< "1.23456E+07";
QTest::newRow("hi scientific negative no fractional part")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-1,23,456e2"
<< "-1.23456E+07";
QTest::newRow("hi scientific no fractional and exponent")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "1,234,56"
<< "1.23456E+05";
QTest::newRow("hi scientific negative no fractional and exponent")
<< "hi" << QDoubleValidator::ScientificNotation << -1 << "-1,234,56"
<< "-1.23456E+05";
}
void tst_QDoubleValidator::setRangeOverloads()
{
QFETCH(QDoubleValidator::Notation, notation);
QFETCH(int, initialDecimals);
QFETCH(double, minimum);
QFETCH(double, maximum);
QFETCH(int, updatedDecimals);
QFETCH(QString, input);
QFETCH(QValidator::State, initDecimalsState);
QFETCH(QValidator::State, updDecimalsState);
QDoubleValidator dv;
dv.setLocale(QLocale::C);
dv.setNotation(notation);
dv.setDecimals(initialDecimals);
dv.setRange(minimum, maximum);
QCOMPARE(dv.decimals(), initialDecimals);
int dummy;
QCOMPARE(dv.validate(input, dummy), initDecimalsState);
dv.setRange(minimum, maximum, updatedDecimals);
QCOMPARE(dv.decimals(), updatedDecimals);
QCOMPARE(dv.validate(input, dummy), updDecimalsState);
}
void tst_QDoubleValidator::setRangeOverloads_data()
{
QTest::addColumn<QDoubleValidator::Notation>("notation");
QTest::addColumn<int>("initialDecimals");
QTest::addColumn<double>("minimum");
QTest::addColumn<double>("maximum");
QTest::addColumn<int>("updatedDecimals");
QTest::addColumn<QString>("input");
QTest::addColumn<QValidator::State>("initDecimalsState");
QTest::addColumn<QValidator::State>("updDecimalsState");
QTest::newRow("scientific, 0 digits after point")
<< QDoubleValidator::ScientificNotation << -1 << -100.0 << 100.0 << 0
<< QString("1e1") << ACC << ACC;
QTest::newRow("scientific, 1 digits after point")
<< QDoubleValidator::ScientificNotation << -1 << -100.0 << 100.0 << 0
<< QString("1.2e1") << ACC << INV;
QTest::newRow("scientific, 3 digits after point, demand fewer")
<< QDoubleValidator::ScientificNotation << 3 << -100.0 << 100.0 << 1
<< QString("10.234e-1") << ACC << INV;
QTest::newRow("scientific, 3 digits after point, not in range")
<< QDoubleValidator::ScientificNotation << 3 << -100.0 << 100.0 << 5
<< QString("1.234e3") << ITM << ITM;
QTest::newRow("standard, 0 digits after point")
<< QDoubleValidator::StandardNotation << -1 << -100.0 << 100.0 << 0
<< QString("12.") << ACC << ACC;
QTest::newRow("standard, 2 digits after point")
<< QDoubleValidator::StandardNotation << -1 << -100.0 << 100.0 << 1
<< QString("12.34") << ACC << INV;
QTest::newRow("standard, 2 digits after point, not in range")
<< QDoubleValidator::StandardNotation << -1 << -100.0 << 100.0 << 1
<< QString("123.45") << ITM << INV;
QTest::newRow("standard, 5 digits after point")
<< QDoubleValidator::StandardNotation << 5 << -100.0 << 100.0 << 3
<< QString("12.34567") << ACC << INV;
}
void tst_QDoubleValidator::validateIntEquiv_data()
{
QTest::addColumn<double>("minimum");
QTest::addColumn<double>("maximum");
QTest::addColumn<QString>("input");
QTest::addColumn<QValidator::State>("state");
QTest::newRow("1.1") << 0.0 << 10.0 << QString("") << ITM;
QTest::newRow("1.2") << 10.0 << 0.0 << QString("") << ITM;
QTest::newRow("2.1") << 0.0 << 10.0 << QString("-") << INV;
QTest::newRow("2.2") << 0.0 << 10.0 << QString("-0") << INV;
QTest::newRow("2.3") << -10.0 << -1.0 << QString("+") << INV;
QTest::newRow("2.4") << -10.0 << 10.0 << QString("-") << ITM;
QTest::newRow("2.5") << -10.0 << 10.0 << QString("+") << ITM;
QTest::newRow("2.5a") << -10.0 << -9.0 << QString("+") << INV;
QTest::newRow("2.6") << -10.0 << 10.0 << QString("+0") << ACC;
QTest::newRow("2.7") << -10.0 << 10.0 << QString("+1") << ACC;
QTest::newRow("2.8") << -10.0 << 10.0 << QString("+-") << INV;
QTest::newRow("2.9") << -10.0 << 10.0 << QString("-+") << INV;
QTest::newRow("3.1") << 0.0 << 10.0 << QString("12345678901234567890") << INV;
QTest::newRow("3.2") << 0.0 << 10.0 << QString("-12345678901234567890") << INV;
QTest::newRow("3.3") << 0.0 << 10.0 << QString("000000000000000000000") << ACC;
QTest::newRow("3.4") << 1.0 << 10.0 << QString("000000000000000000000") << ITM;
QTest::newRow("3.5") << 0.0 << 10.0 << QString("-000000000000000000000") << INV;
QTest::newRow("3.6") << -10.0 << -1.0 << QString("-000000000000000000000") << ITM;
QTest::newRow("3.7") << -10.0 << -1.0 << QString("-0000000000000000000001") << ACC;
QTest::newRow("4.1") << 0.0 << 10.0 << QString(" ") << INV;
QTest::newRow("4.2") << 0.0 << 10.0 << QString(" 1") << INV;
QTest::newRow("4.3") << 0.0 << 10.0 << QString("1 ") << INV;
QTest::newRow("4.4") << 0.0 << 10.0 << QString("1.0") << INV;
QTest::newRow("4.5") << 0.0 << 10.0 << QString("0.1") << INV;
QTest::newRow("4.6") << 0.0 << 10.0 << QString(".1") << INV;
QTest::newRow("4.7") << 0.0 << 10.0 << QString("-1.0") << INV;
QTest::newRow("5.1a") << 6.0 << 8.0 << QString("5") << ITM;
QTest::newRow("5.1b") << 6.0 << 8.0 << QString("56") << INV;
QTest::newRow("5.2") << 6.0 << 8.0 << QString("7") << ACC;
QTest::newRow("5.3a") << 6.0 << 8.0 << QString("9") << ITM;
QTest::newRow("5.3b") << 6.0 << 8.0 << QString("-") << INV;
QTest::newRow("5.4a") << -8.0 << -6.0 << QString("+") << INV;
QTest::newRow("5.4b") << -8.0 << -6.0 << QString("+5") << INV;
QTest::newRow("5.4c") << -8.0 << -6.0 << QString("-5") << ITM;
QTest::newRow("5.5") << -8.0 << -6.0 << QString("-7") << ACC;
QTest::newRow("5.6") << -8.0 << -6.0 << QString("-9") << ITM;
QTest::newRow("5.7") << -8.0 << -6.0 << QString("5") << ITM;
QTest::newRow("5.8") << -8.0 << -6.0 << QString("7") << ITM;
QTest::newRow("5.9") << -8.0 << -6.0 << QString("9") << ITM;
QTest::newRow("5.10") << -6.0 << 8.0 << QString("-5") << ACC;
QTest::newRow("5.11") << -6.0 << 8.0 << QString("5") << ACC;
QTest::newRow("5.12") << -6.0 << 8.0 << QString("-7") << ITM;
QTest::newRow("5.13") << -6.0 << 8.0 << QString("7") << ACC;
QTest::newRow("5.14") << -6.0 << 8.0 << QString("-9") << ITM;
QTest::newRow("5.15") << -6.0 << 8.0 << QString("9") << ITM;
QTest::newRow("6.1") << 100.0 << 102.0 << QString("11") << ITM;
QTest::newRow("6.2") << 100.0 << 102.0 << QString("-11") << INV;
QTest::newRow("7.1") << 0.0 << 10.0 << QString("100") << INV;
QTest::newRow("7.2") << 0.0 << -10.0 << QString("100") << INV;
QTest::newRow("7.3") << 0.0 << -10.0 << QString("-100") << INV;
QTest::newRow("7.4") << -100.0 << 10.0 << QString("100") << ITM;
}
void tst_QDoubleValidator::validateIntEquiv()
{
QFETCH(double, minimum);
QFETCH(double, maximum);
QFETCH(QString, input);
QFETCH(QValidator::State, state);
QLocale::setDefault(QLocale("C"));
QDoubleValidator dv(minimum, maximum, 0, 0);
dv.setNotation(QDoubleValidator::StandardNotation);
int dummy;
QCOMPARE(dv.validate(input, dummy), state);
}
QTEST_APPLESS_MAIN(tst_QDoubleValidator)
#include "tst_qdoublevalidator.moc"

View File

@ -0,0 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qintvalidator Test:
#####################################################################
qt_internal_add_test(tst_qintvalidator
SOURCES
tst_qintvalidator.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,316 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QSignalSpy>
#include <qvalidator.h>
class tst_QIntValidator : public QObject
{
Q_OBJECT
private slots:
void validate_data();
void validate();
void validateArabic();
void validateFrench();
void notifySignals();
void fixup();
void fixup_data();
};
Q_DECLARE_METATYPE(QValidator::State);
#define INV QValidator::Invalid
#define INT QValidator::Intermediate
#define ACC QValidator::Acceptable
void tst_QIntValidator::validate_data()
{
QTest::addColumn<int>("minimum");
QTest::addColumn<int>("maximum");
QTest::addColumn<QString>("value");
QTest::addColumn<QValidator::State>("state");
QTest::newRow("data0") << 0 << 100 << QString("50") << ACC;
QTest::newRow("data1") << 0 << 100 << QString("500") << INT;
QTest::newRow("data1a") << 0 << 100 << QString("5000") << INV;
QTest::newRow("data1b") << -100 << 0 << QString("50") << INT;
QTest::newRow("data1c") << -100 << 0 << QString("500") << INV;
QTest::newRow("data1d") << -100 << 0 << QString("5000") << INV;
QTest::newRow("data2") << 0 << 100 << QString("-35") << INV;
QTest::newRow("data3") << 0 << 100 << QString("a") << INV;
QTest::newRow("data4") << 0 << 100 << QString("-") << INV;
QTest::newRow("data5") << 0 << 100 << QString("100") << ACC;
QTest::newRow("data6") << -100 << 100 << QString("-") << INT;
QTest::newRow("data7") << -100 << 100 << QString("-500") << INV;
QTest::newRow("data8") << -100 << 100 << QString("-100") << ACC;
QTest::newRow("data9") << -100 << -10 << QString("10") << INT;
QTest::newRow("data10") << 100 << 999 << QString("") << INT;
QTest::newRow("data11") << 100 << 999 << QString("5") << INT;
QTest::newRow("data12") << 100 << 999 << QString("50") << INT;
QTest::newRow("data13") << 100 << 999 << QString("99") << INT;
QTest::newRow("data14") << 100 << 999 << QString("100") << ACC;
QTest::newRow("data15") << 100 << 999 << QString("101") << ACC;
QTest::newRow("data16") << 100 << 999 << QString("998") << ACC;
QTest::newRow("data17") << 100 << 999 << QString("999") << ACC;
QTest::newRow("data18") << 100 << 999 << QString("1000") << INV;
QTest::newRow("data19") << 100 << 999 << QString("-10") << INV;
QTest::newRow("data20") << -999 << -100 << QString("50") << INT;
QTest::newRow("data21") << -999 << -100 << QString("-") << INT;
QTest::newRow("data22") << -999 << -100 << QString("-1") << INT;
QTest::newRow("data23") << -999 << -100 << QString("-10") << INT;
QTest::newRow("data24") << -999 << -100 << QString("-100") << ACC;
QTest::newRow("data25") << -999 << -100 << QString("-500") << ACC;
QTest::newRow("data26") << -999 << -100 << QString("-998") << ACC;
QTest::newRow("data27") << -999 << -100 << QString("-999") << ACC;
QTest::newRow("data28") << -999 << -100 << QString("-1000") << INV;
QTest::newRow("data29") << -999 << -100 << QString("-2000") << INV;
QTest::newRow("1.1") << 0 << 10 << QString("") << INT;
QTest::newRow("1.2") << 10 << 0 << QString("") << INT;
QTest::newRow("2.1") << 0 << 10 << QString("-") << INV;
QTest::newRow("2.2") << 0 << 10 << QString("-0") << INV;
QTest::newRow("2.3") << -10 << -1 << QString("+") << INV;
QTest::newRow("2.4") << -10 << 10 << QString("-") << INT;
QTest::newRow("2.5") << -10 << 10 << QString("+") << INT;
QTest::newRow("2.6") << -10 << 10 << QString("+0") << ACC;
QTest::newRow("2.7") << -10 << 10 << QString("+1") << ACC;
QTest::newRow("2.8") << -10 << 10 << QString("+-") << INV;
QTest::newRow("2.9") << -10 << 10 << QString("-+") << INV;
QTest::newRow("3.1") << 0 << 10 << QString("12345678901234567890") << INV;
QTest::newRow("3.2") << 0 << 10 << QString("-12345678901234567890") << INV;
QTest::newRow("3.3") << 0 << 10 << QString("000000000000000000000") << ACC;
QTest::newRow("3.4") << 1 << 10 << QString("000000000000000000000") << INT;
QTest::newRow("3.5") << 0 << 10 << QString("-000000000000000000000") << INV;
QTest::newRow("3.6") << -10 << -1 << QString("-000000000000000000000") << INT;
QTest::newRow("3.7") << -10 << -1 << QString("-0000000000000000000001") << ACC;
QTest::newRow("4.1") << 0 << 10 << QString(" ") << INV;
QTest::newRow("4.2") << 0 << 10 << QString(" 1") << INV;
QTest::newRow("4.3") << 0 << 10 << QString("1 ") << INV;
QTest::newRow("4.4") << 0 << 10 << QString("1.0") << INV;
QTest::newRow("4.5") << 0 << 10 << QString("0.1") << INV;
QTest::newRow("4.6") << 0 << 10 << QString(".1") << INV;
QTest::newRow("4.7") << 0 << 10 << QString("-1.0") << INV;
QTest::newRow("5.1") << 6 << 8 << QString("5") << INT;
QTest::newRow("5.2") << 6 << 8 << QString("7") << ACC;
QTest::newRow("5.3") << 6 << 8 << QString("9") << INT;
QTest::newRow("5.3a") << 6 << 8 << QString("19") << INV;
QTest::newRow("5.4") << -8 << -6 << QString("-5") << INT;
QTest::newRow("5.5") << -8 << -6 << QString("-7") << ACC;
QTest::newRow("5.6") << -8 << -6 << QString("-9") << INV;
QTest::newRow("5.6a") << -8 << -6 << QString("-19") << INV;
QTest::newRow("5.7") << -8 << -6 << QString("5") << INT;
QTest::newRow("5.8") << -8 << -6 << QString("7") << INT;
QTest::newRow("5.9") << -8 << -6 << QString("9") << INT;
QTest::newRow("5.10") << -6 << 8 << QString("-5") << ACC;
QTest::newRow("5.11") << -6 << 8 << QString("5") << ACC;
QTest::newRow("5.12") << -6 << 8 << QString("-7") << INV;
QTest::newRow("5.13") << -6 << 8 << QString("7") << ACC;
QTest::newRow("5.14") << -6 << 8 << QString("-9") << INV;
QTest::newRow("5.15") << -6 << 8 << QString("9") << INT;
QTest::newRow("6.1") << 100 << 102 << QString("11") << INT;
QTest::newRow("6.2") << 100 << 102 << QString("-11") << INV;
QTest::newRow("7.1") << 0 << 10 << QString("100") << INV;
QTest::newRow("7.2") << 0 << -10 << QString("100") << INV;
QTest::newRow("7.3") << 0 << -10 << QString("-100") << INV;
QTest::newRow("7.4") << -100 << 10 << QString("100") << INT;
QTest::newRow("8.1") << -100 << -10 << QString("+") << INV;
QTest::newRow("8.2") << -100 << -10 << QString("+50") << INV;
QTest::newRow("8.3") << -100 << -10 << QString("50") << INT;
QTest::newRow("8.4") << 10 << 100 << QString("-") << INV;
QTest::newRow("8.5") << 10 << 100 << QString("-50") << INV;
QTest::newRow("8.6") << 10 << 100 << QString("5") << INT;
QTest::newRow("8.7") << -1 << 100 << QString("-") << INT;
QTest::newRow("8.8") << -1 << 100 << QString("-50") << INV;
QTest::newRow("8.9") << -1 << 100 << QString("5") << ACC;
QTest::newRow("8.10") << -1 << 100 << QString("+") << INT;
QTest::newRow("8.11") << -1 << 100 << QString("+50") << ACC;
QTest::newRow("9.0") << -10 << 10 << QString("000") << ACC;
QTest::newRow("9.1") << -10 << 10 << QString("008") << ACC;
QTest::newRow("9.2") << -10 << 10 << QString("-008") << ACC;
QTest::newRow("9.3") << -10 << 10 << QString("00010") << ACC;
QTest::newRow("9.4") << -10 << 10 << QString("-00010") << ACC;
QTest::newRow("9.5") << -10 << 10 << QString("00020") << INV;
QTest::newRow("9.6") << -10 << 10 << QString("-00020") << INV;
}
void tst_QIntValidator::validateArabic()
{
QString arabicNum;
arabicNum += QChar(1633); // "18" in arabic
arabicNum += QChar(1640);
QIntValidator validator(-20, 20, 0);
validator.setLocale(QLocale(QLocale::Arabic, QLocale::SaudiArabia));
int i;
QCOMPARE(validator.validate(arabicNum, i), QValidator::Acceptable);
}
void tst_QIntValidator::validateFrench()
{
QIntValidator validator(-2000, 2000, 0);
validator.setLocale(QLocale::French);
int i;
// Grouping separator is a narrow no-break space; QLocale accepts a space as it.
QString s = QLatin1String("1 ");
QCOMPARE(validator.validate(s, i), QValidator::Acceptable);
validator.fixup(s);
QCOMPARE(s, s);
s = QLatin1String("1 000");
QCOMPARE(validator.validate(s, i), QValidator::Acceptable);
validator.fixup(s);
QCOMPARE(s, s);
s = QLatin1String("1 0 00");
QCOMPARE(validator.validate(s, i), QValidator::Intermediate);
validator.fixup(s);
QCOMPARE(s, validator.locale().toString(1000));
// Confim no fallback to C locale
s = QLatin1String("1,000");
QCOMPARE(validator.validate(s, i), QValidator::Invalid);
validator.setLocale(QLocale::C);
QCOMPARE(validator.validate(s, i), QValidator::Acceptable);
}
void tst_QIntValidator::validate()
{
QFETCH(int, minimum);
QFETCH(int, maximum);
QFETCH(QString, value);
QFETCH(QValidator::State, state);
QIntValidator iv(minimum, maximum, 0);
iv.setLocale(QLocale::C);
int dummy;
QCOMPARE((int)iv.validate(value, dummy), (int)state);
}
void tst_QIntValidator::notifySignals()
{
QLocale::setDefault(QLocale("C"));
QIntValidator iv(0, 10, 0);
QSignalSpy topSpy(&iv, SIGNAL(topChanged(int)));
QSignalSpy bottomSpy(&iv, SIGNAL(bottomChanged(int)));
QSignalSpy changedSpy(&iv, SIGNAL(changed()));
iv.setTop(9);
QCOMPARE(topSpy.size(), 1);
QCOMPARE(changedSpy.size(), 1);
QCOMPARE(iv.top(), 9);
iv.setBottom(1);
QCOMPARE(bottomSpy.size(), 1);
QCOMPARE(changedSpy.size(), 2);
QCOMPARE(iv.bottom(), 1);
iv.setRange(1, 8);
QCOMPARE(topSpy.size(), 2);
QCOMPARE(bottomSpy.size(), 1);
QCOMPARE(changedSpy.size(), 3);
QCOMPARE(iv.top(), 8);
QCOMPARE(iv.bottom(), 1);
iv.setRange(2, 8);
QCOMPARE(topSpy.size(), 2);
QCOMPARE(bottomSpy.size(), 2);
QCOMPARE(changedSpy.size(), 4);
QCOMPARE(iv.top(), 8);
QCOMPARE(iv.bottom(), 2);
iv.setRange(3, 7);
QCOMPARE(topSpy.size(), 3);
QCOMPARE(bottomSpy.size(), 3);
QCOMPARE(changedSpy.size(), 5);
QCOMPARE(iv.top(), 7);
QCOMPARE(iv.bottom(), 3);
iv.setRange(3, 7);
QCOMPARE(topSpy.size(), 3);
QCOMPARE(bottomSpy.size(), 3);
QCOMPARE(changedSpy.size(), 5);
iv.setLocale(QLocale("C"));
QCOMPARE(changedSpy.size(), 5);
iv.setLocale(QLocale("en"));
QCOMPARE(changedSpy.size(), 6);
}
void tst_QIntValidator::fixup()
{
QFETCH(QString, localeName);
QFETCH(QString, input);
QFETCH(QString, output);
QIntValidator val;
val.setLocale(QLocale(localeName));
val.fixup(input);
QCOMPARE(input, output);
}
void tst_QIntValidator::fixup_data()
{
QTest::addColumn<QString>("localeName");
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
// C locale uses '.' as decimal point and ',' as a grouping separator.
// C locale does not group digits by default.
QTest::newRow("C no digit grouping") << "C" << "1000" << "1000";
QTest::newRow("C with digit grouping") << "C" << "1,000" << "1000";
QTest::newRow("C invalid digit grouping") << "C" << "100,00" << "10000";
QTest::newRow("C float with valid digit grouping") << "C" << "1,000.23" << "1,000.23";
QTest::newRow("C float with invalid digit grouping") << "C" << "10,00.23" << "10,00.23";
// en locale uses '.' as decimal point and ',' as a grouping separator.
// en locale groups digits by default.
QTest::newRow("en no digit grouping") << "en" << "1234567" << "1,234,567";
QTest::newRow("en with digit grouping") << "en" << "12,345,678" << "12,345,678";
QTest::newRow("en invalid digit grouping") << "en" << "1,2,34,5678" << "12,345,678";
QTest::newRow("en float with valid digit grouping") << "en" << "12,345.67" << "12,345.67";
QTest::newRow("en float with invalid digit grouping") << "en" << "1,2345.67" << "1,2345.67";
// de locale uses ',' as decimal point and '.' as grouping separator.
// de locale groups digits by default.
QTest::newRow("de no digit grouping") << "de" << "1234567" << "1.234.567";
QTest::newRow("de with digit grouping") << "de" << "12.345.678" << "12.345.678";
QTest::newRow("de invalid digit grouping") << "de" << "1.2.34.5678" << "12.345.678";
QTest::newRow("de float with valid digit grouping") << "de" << "12.345,67" << "12.345,67";
QTest::newRow("de float with invalid digit grouping") << "de" << "1.2345,67" << "1.2345,67";
// hi locale uses '.' as decimal point and ',' as grouping separator.
// The rightmost group is of three digits, all the others contain two
// digits.
QTest::newRow("hi no digit grouping") << "hi" << "1234567" << "12,34,567";
QTest::newRow("hi with digit grouping") << "hi" << "12,34,567" << "12,34,567";
QTest::newRow("hi invalid digit grouping") << "hi" << "1,234,567" << "12,34,567";
// es locale uses ',' as decimal point and '.' as grouping separator.
// Normally the groups contain three digits, but the leftmost group should
// have at least two digits.
QTest::newRow("es no digit grouping 1000") << "es" << "1000" << "1000";
QTest::newRow("es no digit grouping 10000") << "es" << "10000" << "10.000";
QTest::newRow("es with digit grouping") << "es" << "1000.000" << "1000.000";
QTest::newRow("es invalid digit grouping") << "es" << "1.000.000" << "1000.000";
}
QTEST_APPLESS_MAIN(tst_QIntValidator)
#include "tst_qintvalidator.moc"

View File

@ -0,0 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qregularexpressionvalidator Test:
#####################################################################
qt_internal_add_test(tst_qregularexpressionvalidator
SOURCES
tst_qregularexpressionvalidator.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,86 @@
// Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtGui/QRegularExpressionValidator>
#include <QTest>
#include <QSignalSpy>
class tst_QRegularExpressionValidator : public QObject
{
Q_OBJECT
private slots:
void validate_data();
void validate();
};
Q_DECLARE_METATYPE(QValidator::State)
void tst_QRegularExpressionValidator::validate_data()
{
QTest::addColumn<QRegularExpression>("re");
QTest::addColumn<QString>("value");
QTest::addColumn<QValidator::State>("state");
QTest::newRow("data0") << QRegularExpression("[1-9]\\d{0,3}") << QString("0") << QValidator::Invalid;
QTest::newRow("data1") << QRegularExpression("[1-9]\\d{0,3}") << QString("12345") << QValidator::Invalid;
QTest::newRow("data2") << QRegularExpression("[1-9]\\d{0,3}") << QString("1") << QValidator::Acceptable;
QTest::newRow("data3") << QRegularExpression("\\S+") << QString("myfile.txt") << QValidator::Acceptable;
QTest::newRow("data4") << QRegularExpression("\\S+") << QString("my file.txt") << QValidator::Invalid;
QTest::newRow("data5") << QRegularExpression("[A-C]\\d{5}[W-Z]") << QString("a12345Z") << QValidator::Invalid;
QTest::newRow("data6") << QRegularExpression("[A-C]\\d{5}[W-Z]") << QString("A12345Z") << QValidator::Acceptable;
QTest::newRow("data7") << QRegularExpression("[A-C]\\d{5}[W-Z]") << QString("B12") << QValidator::Intermediate;
QTest::newRow("data8") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("readme") << QValidator::Acceptable;
QTest::newRow("data9") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << QValidator::Invalid;
QTest::newRow("data10") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << QValidator::Intermediate;
QTest::newRow("data11") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << QValidator::Invalid;
QTest::newRow("data12") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << QValidator::Intermediate;
QTest::newRow("data13") << QRegularExpression("\\w\\d\\d") << QString("A57") << QValidator::Acceptable;
QTest::newRow("data14") << QRegularExpression("\\w\\d\\d") << QString("E5") << QValidator::Intermediate;
QTest::newRow("data15") << QRegularExpression("\\w\\d\\d") << QString("+9") << QValidator::Invalid;
QTest::newRow("emptystr1") << QRegularExpression("[T][e][s][t]") << QString("") << QValidator::Intermediate;
QTest::newRow("emptystr2") << QRegularExpression("[T][e][s][t]") << QString() << QValidator::Intermediate;
QTest::newRow("empty01") << QRegularExpression() << QString() << QValidator::Acceptable;
QTest::newRow("empty02") << QRegularExpression() << QString("test") << QValidator::Acceptable;
}
void tst_QRegularExpressionValidator::validate()
{
QFETCH(QRegularExpression, re);
QFETCH(QString, value);
QRegularExpressionValidator rv;
// setting the same regexp won't emit signals
const int signalCount = (rv.regularExpression() == re) ? 0 : 1;
QSignalSpy spy(&rv, SIGNAL(regularExpressionChanged(QRegularExpression)));
QSignalSpy changedSpy(&rv, SIGNAL(changed()));
rv.setRegularExpression(re);
QCOMPARE(rv.regularExpression(), re);
int pos = -1;
QValidator::State result = rv.validate(value, pos);
QTEST(result, "state");
if (result == QValidator::Invalid)
QCOMPARE(pos, value.size());
else
QCOMPARE(pos, -1); // ensure pos is not modified if validate returned Acceptable or Intermediate
QCOMPARE(spy.size(), signalCount);
QCOMPARE(changedSpy.size(), signalCount);
}
QTEST_GUILESS_MAIN(tst_QRegularExpressionValidator)
#include "tst_qregularexpressionvalidator.moc"

View File

@ -0,0 +1,28 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtexturefilereader Test:
#####################################################################
# Resources:
set(qtexturefilereader_resource_files
"texturefiles/car.ktx"
"texturefiles/car_mips.ktx"
"texturefiles/cubemap_float32_rgba.ktx"
"texturefiles/cubemap_metadata.ktx"
"texturefiles/newlogo.astc"
"texturefiles/newlogo_srgb.astc"
"texturefiles/pattern.pkm"
)
qt_internal_add_test(tst_qtexturefilereader
SOURCES
tst_qtexturefilereader.cpp
LIBRARIES
Qt::Gui
Qt::GuiPrivate
TESTDATA ${qtexturefilereader_resource_files}
BUILTIN_TESTDATA
)

View File

@ -0,0 +1,145 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <private/qtexturefilereader_p.h>
#include <QTest>
class tst_qtexturefilereader : public QObject
{
Q_OBJECT
private slots:
void checkHandlers_data();
void checkHandlers();
void checkMetadata();
};
void tst_qtexturefilereader::checkHandlers_data()
{
QTest::addColumn<QString>("fileName");
QTest::addColumn<QSize>("size");
QTest::addColumn<quint32>("glFormat");
QTest::addColumn<quint32>("glInternalFormat");
QTest::addColumn<quint32>("glBaseInternalFormat");
QTest::addColumn<int>("levels");
QTest::addColumn<int>("faces");
QTest::addColumn<QList<int>>("dataOffsets");
QTest::addColumn<QList<int>>("dataLengths");
QTest::addRow("pattern.pkm")
<< QStringLiteral(":/texturefiles/pattern.pkm")
<< QSize(64, 64)
<< quint32(0x0)
<< quint32(0x8d64)
<< quint32(0x0)
<< 1
<< 1
<< (QList<int>() << 16)
<< (QList<int>() << 2048);
QTest::addRow("car.ktx")
<< QStringLiteral(":/texturefiles/car.ktx")
<< QSize(146, 80)
<< quint32(0x0)
<< quint32(0x9278)
<< quint32(0x1908)
<< 1
<< 1
<< (QList<int>() << 68)
<< (QList<int>() << 11840);
QTest::addRow("car_mips.ktx")
<< QStringLiteral(":/texturefiles/car_mips.ktx")
<< QSize(146, 80)
<< quint32(0x0)
<< quint32(0x9274)
<< quint32(0x1907)
<< 8
<< 1
<< (QList<int>() << 68 << 5992 << 7516 << 7880 << 8004 << 8056 << 8068 << 8080)
<< (QList<int>() << 5920 << 1520 << 360 << 120 << 48 << 8 << 8 << 8);
QTest::addRow("cubemap_float32_rgba.ktx")
<< QStringLiteral(":/texturefiles/cubemap_float32_rgba.ktx")
<< QSize(16, 16)
<< quint32(0x1908)
<< quint32(0x8814)
<< quint32(0x1908)
<< 5
<< 6
<< (QList<int>() << 96 << 24676 << 30824 << 32364 << 32752)
<< (QList<int>() << 4096 << 1024 << 256 << 64 << 16);
QTest::addRow("newlogo.astc")
<< QStringLiteral(":/texturefiles/newlogo.astc")
<< QSize(111, 78)
<< quint32(0x0)
<< quint32(0x93b9)
<< quint32(0x0)
<< 1
<< 1
<< (QList<int>() << 16)
<< (QList<int>() << 2496);
QTest::addRow("newlogo_srgb.astc")
<< QStringLiteral(":/texturefiles/newlogo_srgb.astc")
<< QSize(111, 78)
<< quint32(0x0)
<< quint32(0x93d9)
<< quint32(0x0)
<< 1
<< 1
<< (QList<int>() << 16)
<< (QList<int>() << 2496);
}
void tst_qtexturefilereader::checkHandlers()
{
QFETCH(QString, fileName);
QFETCH(QSize, size);
QFETCH(quint32, glFormat);
QFETCH(quint32, glInternalFormat);
QFETCH(int, levels);
QFETCH(int, faces);
QFETCH(QList<int>, dataOffsets);
QFETCH(QList<int>, dataLengths);
QFile f(fileName);
QVERIFY(f.open(QIODevice::ReadOnly));
QTextureFileReader r(&f, fileName);
QVERIFY(r.canRead());
QTextureFileData tex = r.read();
QVERIFY(!tex.isNull());
QVERIFY(tex.isValid());
QCOMPARE(tex.size(), size);
QCOMPARE(tex.glFormat(), glFormat);
QCOMPARE(tex.glInternalFormat(), glInternalFormat);
QCOMPARE(tex.numLevels(), levels);
QCOMPARE(tex.numFaces(), faces);
for (int i = 0; i < tex.numLevels(); i++) {
QCOMPARE(tex.dataOffset(i), dataOffsets.at(i));
QCOMPARE(tex.dataLength(i), dataLengths.at(i));
}
}
void tst_qtexturefilereader::checkMetadata()
{
QFile f(":/texturefiles/cubemap_metadata.ktx");
QVERIFY(f.open(QIODevice::ReadOnly));
QTextureFileReader r(&f);
QTextureFileData d = r.read();
auto kvs = d.keyValueMetadata();
QVERIFY(kvs.contains("test A"));
QVERIFY(kvs.contains("test B"));
QVERIFY(kvs.contains("test C"));
QCOMPARE(kvs.value("test A"), QByteArrayLiteral("1\x0000"));
QCOMPARE(kvs.value("test B"), QByteArrayLiteral("2\x0000"));
QCOMPARE(kvs.value("test C"), QByteArrayLiteral("3\x0000"));
}
QTEST_MAIN(tst_qtexturefilereader)
#include "tst_qtexturefilereader.moc"

View File

@ -0,0 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qundogroup Test:
#####################################################################
qt_internal_add_test(tst_qundogroup
SOURCES
tst_qundogroup.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="en">
<context>
<name>QUndoGroup</name>
<message>
<source>Undo %1</source>
<translation>undo-prefix %1 undo-suffix</translation>
</message>
<message>
<source>Undo</source>
<comment>Default text for undo action</comment>
<translation>Undo-default-text</translation>
</message>
<message>
<source>Redo %1</source>
<translation>redo-prefix %1 redo-suffix</translation>
</message>
<message>
<source>Redo</source>
<comment>Default text for redo action</comment>
<translation>Redo-default-text</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,623 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QUndoGroup>
#include <QUndoStack>
#include <QAction>
#include <QSignalSpy>
#if QT_CONFIG(process)
#include <QProcess>
#endif
#include <QLibraryInfo>
#include <QTranslator>
/******************************************************************************
** Commands
*/
class InsertCommand : public QUndoCommand
{
public:
InsertCommand(QString *str, int idx, const QString &text,
QUndoCommand *parent = nullptr);
virtual void undo() override;
virtual void redo() override;
private:
QString *m_str;
int m_idx;
QString m_text;
};
class RemoveCommand : public QUndoCommand
{
public:
RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent = nullptr);
virtual void undo() override;
virtual void redo() override;
private:
QString *m_str;
int m_idx;
QString m_text;
};
class AppendCommand : public QUndoCommand
{
public:
AppendCommand(QString *str, const QString &text, QUndoCommand *parent = nullptr);
virtual void undo() override;
virtual void redo() override;
virtual int id() const override;
virtual bool mergeWith(const QUndoCommand *other) override;
bool merged;
private:
QString *m_str;
QString m_text;
};
InsertCommand::InsertCommand(QString *str, int idx, const QString &text,
QUndoCommand *parent)
: QUndoCommand(parent)
{
QVERIFY(str->size() >= idx);
setText("insert");
m_str = str;
m_idx = idx;
m_text = text;
}
void InsertCommand::redo()
{
QVERIFY(m_str->size() >= m_idx);
m_str->insert(m_idx, m_text);
}
void InsertCommand::undo()
{
QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text);
m_str->remove(m_idx, m_text.size());
}
RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent)
: QUndoCommand(parent)
{
QVERIFY(str->size() >= idx + len);
setText("remove");
m_str = str;
m_idx = idx;
m_text = m_str->mid(m_idx, len);
}
void RemoveCommand::redo()
{
QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text);
m_str->remove(m_idx, m_text.size());
}
void RemoveCommand::undo()
{
QVERIFY(m_str->size() >= m_idx);
m_str->insert(m_idx, m_text);
}
AppendCommand::AppendCommand(QString *str, const QString &text, QUndoCommand *parent)
: QUndoCommand(parent)
{
setText("append");
m_str = str;
m_text = text;
merged = false;
}
void AppendCommand::redo()
{
m_str->append(m_text);
}
void AppendCommand::undo()
{
QCOMPARE(m_str->mid(m_str->size() - m_text.size()), m_text);
m_str->truncate(m_str->size() - m_text.size());
}
int AppendCommand::id() const
{
return 1;
}
bool AppendCommand::mergeWith(const QUndoCommand *other)
{
if (other->id() != id())
return false;
m_text += static_cast<const AppendCommand*>(other)->m_text;
merged = true;
return true;
}
/******************************************************************************
** tst_QUndoStack
*/
class tst_QUndoGroup : public QObject
{
Q_OBJECT
public:
tst_QUndoGroup();
private slots:
void setActive();
void addRemoveStack();
void deleteStack();
void checkSignals();
void addStackAndDie();
void commandTextFormat();
};
tst_QUndoGroup::tst_QUndoGroup()
{
}
void tst_QUndoGroup::setActive()
{
QUndoGroup group;
QUndoStack stack1(&group), stack2(&group);
QCOMPARE(group.activeStack(), nullptr);
QCOMPARE(stack1.isActive(), false);
QCOMPARE(stack2.isActive(), false);
QUndoStack stack3;
QCOMPARE(stack3.isActive(), true);
group.addStack(&stack3);
QCOMPARE(stack3.isActive(), false);
stack1.setActive();
QCOMPARE(group.activeStack(), &stack1);
QCOMPARE(stack1.isActive(), true);
QCOMPARE(stack2.isActive(), false);
QCOMPARE(stack3.isActive(), false);
group.setActiveStack(&stack2);
QCOMPARE(group.activeStack(), &stack2);
QCOMPARE(stack1.isActive(), false);
QCOMPARE(stack2.isActive(), true);
QCOMPARE(stack3.isActive(), false);
group.removeStack(&stack2);
QCOMPARE(group.activeStack(), nullptr);
QCOMPARE(stack1.isActive(), false);
QCOMPARE(stack2.isActive(), true);
QCOMPARE(stack3.isActive(), false);
group.removeStack(&stack2);
QCOMPARE(group.activeStack(), nullptr);
QCOMPARE(stack1.isActive(), false);
QCOMPARE(stack2.isActive(), true);
QCOMPARE(stack3.isActive(), false);
}
void tst_QUndoGroup::addRemoveStack()
{
QUndoGroup group;
QUndoStack stack1(&group);
QCOMPARE(group.stacks(), {&stack1});
QUndoStack stack2;
QUndoStack *expected12[] = {&stack1, &stack2};
group.addStack(&stack2);
QCOMPARE(group.stacks(), expected12);
group.addStack(&stack1);
QCOMPARE(group.stacks(), expected12);
group.removeStack(&stack1);
QCOMPARE(group.stacks(), {&stack2});
group.removeStack(&stack1);
QCOMPARE(group.stacks(), {&stack2});
group.removeStack(&stack2);
QVERIFY(group.stacks().isEmpty());
}
void tst_QUndoGroup::deleteStack()
{
QUndoGroup group;
QUndoStack *stack1 = new QUndoStack(&group);
QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1);
QCOMPARE(group.activeStack(), nullptr);
stack1->setActive();
QCOMPARE(group.activeStack(), stack1);
QUndoStack *stack2 = new QUndoStack(&group);
QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1 << stack2);
QCOMPARE(group.activeStack(), stack1);
QUndoStack *stack3 = new QUndoStack(&group);
QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1 << stack2 << stack3);
QCOMPARE(group.activeStack(), stack1);
delete stack2;
QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1 << stack3);
QCOMPARE(group.activeStack(), stack1);
delete stack1;
QCOMPARE(group.stacks(), {stack3});
QCOMPARE(group.activeStack(), nullptr);
stack3->setActive(false);
QCOMPARE(group.activeStack(), nullptr);
stack3->setActive(true);
QCOMPARE(group.activeStack(), stack3);
group.removeStack(stack3);
QVERIFY(group.stacks().isEmpty());
QCOMPARE(group.activeStack(), nullptr);
delete stack3;
}
static QString glue(const QString &s1, const QString &s2)
{
QString result;
result.append(s1);
if (!s1.isEmpty() && !s2.isEmpty())
result.append(' ');
result.append(s2);
return result;
}
#define CHECK_STATE(_activeStack, _clean, _canUndo, _undoText, _canRedo, _redoText, \
_cleanChanged, _indexChanged, _undoChanged, _redoChanged) \
QCOMPARE(group.activeStack(), (QUndoStack*)_activeStack); \
QCOMPARE(group.isClean(), _clean); \
QCOMPARE(group.canUndo(), _canUndo); \
QCOMPARE(group.undoText(), QString(_undoText)); \
QCOMPARE(group.canRedo(), _canRedo); \
QCOMPARE(group.redoText(), QString(_redoText)); \
if (_indexChanged) { \
QCOMPARE(indexChangedSpy.count(), 1); \
indexChangedSpy.clear(); \
} else { \
QCOMPARE(indexChangedSpy.count(), 0); \
} \
if (_cleanChanged) { \
QCOMPARE(cleanChangedSpy.count(), 1); \
QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean); \
cleanChangedSpy.clear(); \
} else { \
QCOMPARE(cleanChangedSpy.count(), 0); \
} \
if (_undoChanged) { \
QCOMPARE(canUndoChangedSpy.count(), 1); \
QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo); \
QCOMPARE(undo_action->isEnabled(), _canUndo); \
QCOMPARE(undoTextChangedSpy.count(), 1); \
QCOMPARE(undoTextChangedSpy.at(0).at(0).toString(), QString(_undoText)); \
QCOMPARE(undo_action->text(), glue("foo", _undoText)); \
canUndoChangedSpy.clear(); \
undoTextChangedSpy.clear(); \
} else { \
QCOMPARE(canUndoChangedSpy.count(), 0); \
QCOMPARE(undoTextChangedSpy.count(), 0); \
} \
if (_redoChanged) { \
QCOMPARE(canRedoChangedSpy.count(), 1); \
QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo); \
QCOMPARE(redo_action->isEnabled(), _canRedo); \
QCOMPARE(redoTextChangedSpy.count(), 1); \
QCOMPARE(redoTextChangedSpy.at(0).at(0).toString(), QString(_redoText)); \
QCOMPARE(redo_action->text(), glue("bar", _redoText)); \
canRedoChangedSpy.clear(); \
redoTextChangedSpy.clear(); \
} else { \
QCOMPARE(canRedoChangedSpy.count(), 0); \
QCOMPARE(redoTextChangedSpy.count(), 0); \
}
void tst_QUndoGroup::checkSignals()
{
QUndoGroup group;
QScopedPointer<QAction> undo_action(group.createUndoAction(nullptr, QString("foo")));
QScopedPointer<QAction> redo_action(group.createRedoAction(nullptr, QString("bar")));
QSignalSpy indexChangedSpy(&group, &QUndoGroup::indexChanged);
QSignalSpy cleanChangedSpy(&group, &QUndoGroup::cleanChanged);
QSignalSpy canUndoChangedSpy(&group, &QUndoGroup::canUndoChanged);
QSignalSpy undoTextChangedSpy(&group, &QUndoGroup::undoTextChanged);
QSignalSpy canRedoChangedSpy(&group, &QUndoGroup::canRedoChanged);
QSignalSpy redoTextChangedSpy(&group, &QUndoGroup::redoTextChanged);
QString str;
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
group.undo();
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
group.redo();
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
QUndoStack *stack1 = new QUndoStack(&group);
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
stack1->push(new AppendCommand(&str, "foo"));
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
stack1->setActive();
CHECK_STATE(stack1, // activeStack
false, // clean
true, // canUndo
"append", // undoText
false, // canRedo
"", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
stack1->push(new InsertCommand(&str, 0, "bar"));
CHECK_STATE(stack1, // activeStack
false, // clean
true, // canUndo
"insert", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
stack1->undo();
CHECK_STATE(stack1, // activeStack
false, // clean
true, // canUndo
"append", // undoText
true, // canRedo
"insert", // redoText
false, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
stack1->undo();
CHECK_STATE(stack1, // activeStack
true, // clean
false, // canUndo
"", // undoText
true, // canRedo
"append", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
stack1->undo();
CHECK_STATE(stack1, // activeStack
true, // clean
false, // canUndo
"", // undoText
true, // canRedo
"append", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
group.undo();
CHECK_STATE(stack1, // activeStack
true, // clean
false, // canUndo
"", // undoText
true, // canRedo
"append", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
group.redo();
CHECK_STATE(stack1, // activeStack
false, // clean
true, // canUndo
"append", // undoText
true, // canRedo
"insert", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
stack1->setActive(false);
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
QUndoStack *stack2 = new QUndoStack(&group);
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
false, // cleanChanged
false, // indexChanged
false, // undoChanged
false) // redoChanged
stack2->setActive();
CHECK_STATE(stack2, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
stack1->setActive();
CHECK_STATE(stack1, // activeStack
false, // clean
true, // canUndo
"append", // undoText
true, // canRedo
"insert", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
delete stack1;
CHECK_STATE(0, // activeStack
true, // clean
false, // canUndo
"", // undoText
false, // canRedo
"", // redoText
true, // cleanChanged
true, // indexChanged
true, // undoChanged
true) // redoChanged
}
void tst_QUndoGroup::addStackAndDie()
{
// Test that QUndoStack doesn't keep a reference to QUndoGroup after the
// group is deleted.
QUndoStack *stack = new QUndoStack;
QUndoGroup *group = new QUndoGroup;
group->addStack(stack);
delete group;
stack->setActive(true);
delete stack;
}
void tst_QUndoGroup::commandTextFormat()
{
#if !QT_CONFIG(process)
QSKIP("No QProcess available");
#else
QString binDir = QLibraryInfo::path(QLibraryInfo::BinariesPath);
if (QProcess::execute(binDir + "/lrelease -version") != 0)
QSKIP("lrelease is missing or broken");
const QString tsFile = QFINDTESTDATA("testdata/qundogroup.ts");
QVERIFY(!tsFile.isEmpty());
QFile::remove("qundogroup.qm"); // Avoid confusion by strays.
QVERIFY(!QProcess::execute(binDir + "/lrelease -silent " + tsFile + " -qm qundogroup.qm"));
QTranslator translator;
QVERIFY(translator.load("qundogroup.qm"));
QFile::remove("qundogroup.qm");
qApp->installTranslator(&translator);
QUndoGroup group;
QScopedPointer<QAction> undo_action(group.createUndoAction(nullptr));
QScopedPointer<QAction> redo_action(group.createRedoAction(nullptr));
QCOMPARE(undo_action->text(), QString("Undo-default-text"));
QCOMPARE(redo_action->text(), QString("Redo-default-text"));
QUndoStack stack(&group);
stack.setActive();
QString str;
stack.push(new AppendCommand(&str, "foo"));
QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix"));
QCOMPARE(redo_action->text(), QString("Redo-default-text"));
stack.push(new InsertCommand(&str, 0, "bar"));
stack.undo();
QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix"));
QCOMPARE(redo_action->text(), QString("redo-prefix insert redo-suffix"));
stack.undo();
QCOMPARE(undo_action->text(), QString("Undo-default-text"));
QCOMPARE(redo_action->text(), QString("redo-prefix append redo-suffix"));
qApp->removeTranslator(&translator);
#endif
}
QTEST_MAIN(tst_QUndoGroup)
#include "tst_qundogroup.moc"

View File

@ -0,0 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qundostack Test:
#####################################################################
qt_internal_add_test(tst_qundostack
SOURCES
tst_qundostack.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="en">
<context>
<name>QUndoStack</name>
<message>
<source>Undo %1</source>
<translation>undo-prefix %1 undo-suffix</translation>
</message>
<message>
<source>Undo</source>
<comment>Default text for undo action</comment>
<translation>Undo-default-text</translation>
</message>
<message>
<source>Redo %1</source>
<translation>redo-prefix %1 redo-suffix</translation>
</message>
<message>
<source>Redo</source>
<comment>Default text for redo action</comment>
<translation>Redo-default-text</translation>
</message>
</context>
</TS>

File diff suppressed because it is too large Load Diff