summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-06-08 13:36:16 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-20 12:38:32 +0200
commit902638e379317dd62bd925c4b9c8f664e0ecd633 (patch)
tree0c2f48cfab4984bc0293f7465bfb8bae43d37895 /tests
parent7f139e88444860baf275daaa35b387e7e8a448a3 (diff)
Add leading zeros to years below 1000 in QDate::toString().
QDate::toString(Qt::ISODate) lacks prefixed 0's on years below 1000. The ISO 8601 standard dictates that this should be the case. Task-number: QTBUG-16476 Change-Id: I7e73152bba0f5894bcbaa3f4418732b74ce86bc5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qdate/tst_qdate.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
index 1c8c515f22..f83e2064c8 100644
--- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
@@ -47,7 +47,6 @@ class tst_QDate : public QObject
{
Q_OBJECT
private slots:
- void toString();
void isNull_data();
void isNull();
void isValid_data();
@@ -86,6 +85,8 @@ private slots:
void fromStringFormat();
void toStringFormat_data();
void toStringFormat();
+ void toStringDateFormat_data();
+ void toStringDateFormat();
void isLeapYear();
void yearsZeroToNinetyNine();
void negativeYear() const;
@@ -106,6 +107,7 @@ private:
};
Q_DECLARE_METATYPE(QDate)
+Q_DECLARE_METATYPE(Qt::DateFormat)
void tst_QDate::isNull_data()
{
@@ -960,6 +962,33 @@ void tst_QDate::toStringFormat()
QCOMPARE( t.toString( format ), str );
}
+void tst_QDate::toStringDateFormat_data()
+{
+ QTest::addColumn<QDate>("date");
+ QTest::addColumn<Qt::DateFormat>("format");
+ QTest::addColumn<QString>("expectedStr");
+
+ QTest::newRow("data0") << QDate(1,1,1) << Qt::ISODate << QString("0001-01-01");
+ QTest::newRow("data1") << QDate(11,1,1) << Qt::ISODate << QString("0011-01-01");
+ QTest::newRow("data2") << QDate(111,1,1) << Qt::ISODate << QString("0111-01-01");
+ QTest::newRow("data3") << QDate(1974,12,1) << Qt::ISODate << QString("1974-12-01");
+}
+
+void tst_QDate::toStringDateFormat()
+{
+ QFETCH(QDate, date);
+ QFETCH(Qt::DateFormat, format);
+ QFETCH(QString, expectedStr);
+
+ QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
+ QCOMPARE(date.toString(Qt::LocaleDate), QLocale().toString(date, QLocale::ShortFormat));
+ QLocale::setDefault(QLocale::German);
+ QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
+ QCOMPARE(date.toString(Qt::LocaleDate), QLocale().toString(date, QLocale::ShortFormat));
+
+ QCOMPARE(date.toString(format), expectedStr);
+}
+
void tst_QDate::isLeapYear()
{
QVERIFY(QDate::isLeapYear(-4801));
@@ -1053,19 +1082,6 @@ void tst_QDate::yearsZeroToNinetyNine()
}
}
-void tst_QDate::toString()
-{
- QDate date(1974,12,1);
- QCOMPARE(date.toString(Qt::SystemLocaleDate),
- QLocale::system().toString(date, QLocale::ShortFormat));
- QCOMPARE(date.toString(Qt::LocaleDate),
- QLocale().toString(date, QLocale::ShortFormat));
- QLocale::setDefault(QLocale::German);
- QCOMPARE(date.toString(Qt::SystemLocaleDate),
- QLocale::system().toString(date, QLocale::ShortFormat));
- QCOMPARE(date.toString(Qt::LocaleDate),
- QLocale().toString(date, QLocale::ShortFormat));
-}
void tst_QDate::negativeYear() const
{