/***************************************************************************** * Copyright: 2019 Johan Ouwerkerk * * * * This project is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This project is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ****************************************************************************/ #include "validators/countervalidator.h" #include #include #include #include Q_DECLARE_METATYPE(std::optional); Q_DECLARE_METATYPE(QLocale); class UnsignedLongParsingSamplesTest: public QObject { Q_OBJECT private Q_SLOTS: void testParsea(void); void testParsea_data(void); }; void UnsignedLongParsingSamplesTest::testParsea(void) { QFETCH(QString, input); QFETCH(QLocale, locale); QTEST(validators::parse(input, locale), "result"); } static void define_test_case(const QString &input, const QLocale &locale, const std::optional &result) { QTest::newRow(qPrintable(input)) << input << locale << result; } void UnsignedLongParsingSamplesTest::testParsea_data(void) { QTest::addColumn("input"); QTest::addColumn("locale"); QTest::addColumn>("result"); QLocale frFR(QLocale::French, QLocale::France); QLocale nlNL(QLocale::Dutch, QLocale::Netherlands); QLocale enUK(QLocale::English, QLocale::UnitedKingdom); define_test_case(QLatin1String("123456"), frFR, std::optional(123'456ULL)); define_test_case(QLatin1String("123 456"), frFR, std::optional(123'456ULL)); define_test_case(QLatin1String("12 3456"), frFR, std::nullopt); define_test_case(QLatin1String("1234 56"), frFR, std::nullopt); define_test_case(QLatin1String("12345 6"), frFR, std::nullopt); define_test_case(QLatin1String("123.456"), nlNL, std::optional(123'456ULL)); define_test_case(QLatin1String("123,456"), enUK, std::optional(123'456ULL)); } QTEST_APPLESS_MAIN(UnsignedLongParsingSamplesTest) #include "unsigned-long-parsing.moc"