diff --git a/autotests/kformattest.cpp b/autotests/kformattest.cpp --- a/autotests/kformattest.cpp +++ b/autotests/kformattest.cpp @@ -23,10 +23,11 @@ #include "kformattest.h" -#include - #include "kformat.h" +#include +#include + void KFormatTest::formatByteSize() { QLocale locale(QLocale::c()); @@ -290,8 +291,8 @@ { KFormat format(QLocale::c()); - QCOMPARE(format.formatDecimalDuration(10), QStringLiteral("10 millisecond(s)")); - QCOMPARE(format.formatDecimalDuration(10, 3), QStringLiteral("10 millisecond(s)")); + QCOMPARE(format.formatDecimalDuration(10), QCoreApplication::translate("KFormat", "%n millisecond(s)", nullptr, 10)); + QCOMPARE(format.formatDecimalDuration(10, 3), QCoreApplication::translate("KFormat", "%n millisecond(s)", nullptr, 10)); QCOMPARE(format.formatDecimalDuration(1 * MSecsInSecond + 10), QStringLiteral("1.01 seconds")); QCOMPARE(format.formatDecimalDuration(1 * MSecsInSecond + 1, 3), QStringLiteral("1.001 seconds")); QCOMPARE(format.formatDecimalDuration(1 * MSecsInMinute + 10 * MSecsInSecond), QStringLiteral("1.17 minutes")); @@ -306,22 +307,31 @@ { KFormat format(QLocale::c()); - QCOMPARE(format.formatSpelloutDuration(1000), QStringLiteral("1 second(s)")); - QCOMPARE(format.formatSpelloutDuration(5000), QStringLiteral("5 second(s)")); - QCOMPARE(format.formatSpelloutDuration(60000), QStringLiteral("1 minute(s)")); - QCOMPARE(format.formatSpelloutDuration(300000), QStringLiteral("5 minute(s)")); - QCOMPARE(format.formatSpelloutDuration(3600000), QStringLiteral("1 hour(s)")); - QCOMPARE(format.formatSpelloutDuration(18000000), QStringLiteral("5 hour(s)")); - QCOMPARE(format.formatSpelloutDuration(75000), QStringLiteral("1 minute(s) and 15 second(s)")); + QCOMPARE(format.formatSpelloutDuration(1000), QCoreApplication::translate("KFormat", "%n second(s)", nullptr, 1)); + QCOMPARE(format.formatSpelloutDuration(5000), QCoreApplication::translate("KFormat", "%n second(s)", nullptr, 5)); + QCOMPARE(format.formatSpelloutDuration(60000), QCoreApplication::translate("KFormat", "%n minute(s)", nullptr, 1)); + QCOMPARE(format.formatSpelloutDuration(300000), QCoreApplication::translate("KFormat", "%n minute(s)", nullptr, 5)); + QCOMPARE(format.formatSpelloutDuration(3600000), QCoreApplication::translate("KFormat", "%n hour(s)", nullptr, 1)); + QCOMPARE(format.formatSpelloutDuration(18000000), QCoreApplication::translate("KFormat", "%n hour(s)", nullptr, 5)); + + QString s = QCoreApplication::translate("KFormat", "%1 and %2").arg( + QCoreApplication::translate("KFormat", "%n minute(s)", nullptr, 1), + QCoreApplication::translate("KFormat", "%n second(s)", nullptr, 15)); + + QCOMPARE(format.formatSpelloutDuration(75000), s); // Problematic case #1 (there is a reference to this case on kformat.cpp) - QCOMPARE(format.formatSpelloutDuration(119999), QStringLiteral("2 minute(s)")); + QCOMPARE(format.formatSpelloutDuration(119999), QCoreApplication::translate("KFormat", "%n minute(s)", nullptr, 2)); // This case is strictly 2 hours, 15 minutes and 59 seconds. However, since the range is // pretty high between hours and seconds, formatSpelloutDuration always omits seconds when there // are hours in scene. - QCOMPARE(format.formatSpelloutDuration(8159000), QStringLiteral("2 hour(s) and 15 minute(s)")); + s = QCoreApplication::translate("KFormat", "%1 and %2").arg( + QCoreApplication::translate("KFormat", "%n hour(s)", nullptr, 2), + QCoreApplication::translate("KFormat", "%n minute(s)", nullptr, 15)); + + QCOMPARE(format.formatSpelloutDuration(8159000), s); // This case is strictly 1 hour and 10 seconds. For the same reason, formatSpelloutDuration // detects that 10 seconds is just garbage compared to 1 hour, and omits it on the result. - QCOMPARE(format.formatSpelloutDuration(3610000), QStringLiteral("1 hour(s)")); + QCOMPARE(format.formatSpelloutDuration(3610000), QCoreApplication::translate("KFormat", "%n hour(s)", nullptr, 1)); } void KFormatTest::formatRelativeDate()