summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-03-04 04:57:40 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-03-04 05:21:56 (GMT)
commit78254634c87f8e1b9c79841d87c530d3af8c9734 (patch)
tree4d8cd9691f55072906b8b57f3350647466c3498e /tests
parent0559b8d2af9f1f9277ff3bedd9a33cca7e255abb (diff)
downloadQt-78254634c87f8e1b9c79841d87c530d3af8c9734.zip
Qt-78254634c87f8e1b9c79841d87c530d3af8c9734.tar.gz
Qt-78254634c87f8e1b9c79841d87c530d3af8c9734.tar.bz2
Add formatting functions to QML's global Qt object.
The plan is for these to replace DateTimeFormatter.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/formatting.qml19
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp29
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeqt/data/formatting.qml b/tests/auto/declarative/qdeclarativeqt/data/formatting.qml
new file mode 100644
index 0000000..e62749a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/formatting.qml
@@ -0,0 +1,19 @@
+import Qt 4.6
+
+QtObject {
+ property date date1: "2008-12-24"
+ property string test1: Qt.formatDate(date1)
+ property string test2: Qt.formatDate(date1, Qt.DefaultLocaleLongDate)
+ property string test3: Qt.formatDate(date1, "ddd MMMM d yy")
+
+ property var time1: new Date(0,0,0,14,15,38,200)
+ property string test4: Qt.formatTime(time1)
+ property string test5: Qt.formatTime(time1, Qt.DefaultLocaleLongDate)
+ property string test6: Qt.formatTime(time1, "H:m:s a")
+ property string test7: Qt.formatTime(time1, "hh:mm:ss.zzz")
+
+ property var dateTime1: new Date(1978,2,4,9,13,54)
+ property string test8: Qt.formatDateTime(dateTime1)
+ property string test9: Qt.formatDateTime(dateTime1, Qt.DefaultLocaleLongDate)
+ property string test10: Qt.formatDateTime(dateTime1, "M/d/yy H:m:s a")
+}
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index 9ec6872..484cbd4 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -73,6 +73,7 @@ private slots:
void createComponent();
void createQmlObject();
void consoleLog();
+ void formatting();
private:
QDeclarativeEngine engine;
@@ -364,6 +365,34 @@ void tst_qdeclarativeqt::consoleLog()
delete object;
}
+void tst_qdeclarativeqt::formatting()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("formatting.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QDate date1(2008,12,24);
+ QCOMPARE(object->property("date1").toDate(), date1);
+ QCOMPARE(object->property("test1").toString(), date1.toString(Qt::DefaultLocaleShortDate));
+ QCOMPARE(object->property("test2").toString(), date1.toString(Qt::DefaultLocaleLongDate));
+ QCOMPARE(object->property("test3").toString(), date1.toString("ddd MMMM d yy"));
+
+ QTime time1(14,15,38,200);
+ QCOMPARE(object->property("time1").toTime(), time1);
+ QCOMPARE(object->property("test4").toString(), time1.toString(Qt::DefaultLocaleShortDate));
+ QCOMPARE(object->property("test5").toString(), time1.toString(Qt::DefaultLocaleLongDate));
+ QCOMPARE(object->property("test6").toString(), time1.toString("H:m:s a"));
+ QCOMPARE(object->property("test7").toString(), time1.toString("hh:mm:ss.zzz"));
+
+ QDateTime dateTime1(QDate(1978,03,04),QTime(9,13,54));
+ QCOMPARE(object->property("dateTime1").toDateTime(),dateTime1);
+ QCOMPARE(object->property("test8").toString(), dateTime1.toString(Qt::DefaultLocaleShortDate));
+ QCOMPARE(object->property("test9").toString(), dateTime1.toString(Qt::DefaultLocaleLongDate));
+ QCOMPARE(object->property("test10").toString(), dateTime1.toString("M/d/yy H:m:s a"));
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeqt)
#include "tst_qdeclarativeqt.moc"