diff options
Diffstat (limited to 'tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp')
-rw-r--r-- | tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp | 130 |
1 files changed, 84 insertions, 46 deletions
diff --git a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp index 5dc7cba2c2..bfa69c90b8 100644 --- a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp +++ b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -41,6 +16,8 @@ private slots: void validateArabic(); void validateFrench(); void notifySignals(); + void fixup(); + void fixup_data(); }; Q_DECLARE_METATYPE(QValidator::State); @@ -188,8 +165,10 @@ 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); + // Shouldn't end with a group separator + QCOMPARE(validator.validate(s, i), QValidator::Intermediate); validator.fixup(s); QCOMPARE(s, s); @@ -234,45 +213,104 @@ void tst_QIntValidator::notifySignals() QSignalSpy changedSpy(&iv, SIGNAL(changed())); iv.setTop(9); - QCOMPARE(topSpy.count(), 1); - QCOMPARE(changedSpy.count(), 1); + QCOMPARE(topSpy.size(), 1); + QCOMPARE(changedSpy.size(), 1); QCOMPARE(iv.top(), 9); iv.setBottom(1); - QCOMPARE(bottomSpy.count(), 1); - QCOMPARE(changedSpy.count(), 2); + QCOMPARE(bottomSpy.size(), 1); + QCOMPARE(changedSpy.size(), 2); QCOMPARE(iv.bottom(), 1); iv.setRange(1, 8); - QCOMPARE(topSpy.count(), 2); - QCOMPARE(bottomSpy.count(), 1); - QCOMPARE(changedSpy.count(), 3); + 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.count(), 2); - QCOMPARE(bottomSpy.count(), 2); - QCOMPARE(changedSpy.count(), 4); + 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.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(changedSpy.count(), 5); + 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.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(changedSpy.count(), 5); + QCOMPARE(topSpy.size(), 3); + QCOMPARE(bottomSpy.size(), 3); + QCOMPARE(changedSpy.size(), 5); iv.setLocale(QLocale("C")); - QCOMPARE(changedSpy.count(), 5); + QCOMPARE(changedSpy.size(), 5); iv.setLocale(QLocale("en")); - QCOMPARE(changedSpy.count(), 6); + 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 with digit grouping 10000") << "es" << "10000" << "10.000"; + QTest::newRow("es with digit grouping million") << "es" << "1.000.000" << "1.000.000"; + QTest::newRow("es invalid digit grouping") << "es" << "1000.000" << "1.000.000"; } QTEST_APPLESS_MAIN(tst_QIntValidator) |