summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmldatetimeformatter
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-02-11 21:35:45 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-02-11 22:49:39 (GMT)
commitfe9e91d5b9a5504fdc00f53abd5972621e7fa7dd (patch)
tree28c25d69001ef4dd4181ddf465b373491a61932b /tests/auto/declarative/qmldatetimeformatter
parent6e0c76a209b87e306e48266962f5668237e63c62 (diff)
downloadQt-fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd.zip
Qt-fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd.tar.gz
Qt-fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd.tar.bz2
Adds qml prefix to all declarative autotests
Diffstat (limited to 'tests/auto/declarative/qmldatetimeformatter')
-rw-r--r--tests/auto/declarative/qmldatetimeformatter/qmldatetimeformatter.pro5
-rw-r--r--tests/auto/declarative/qmldatetimeformatter/tst_qmldatetimeformatter.cpp150
2 files changed, 155 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmldatetimeformatter/qmldatetimeformatter.pro b/tests/auto/declarative/qmldatetimeformatter/qmldatetimeformatter.pro
new file mode 100644
index 0000000..2b1947d
--- /dev/null
+++ b/tests/auto/declarative/qmldatetimeformatter/qmldatetimeformatter.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qmldatetimeformatter.cpp
diff --git a/tests/auto/declarative/qmldatetimeformatter/tst_qmldatetimeformatter.cpp b/tests/auto/declarative/qmldatetimeformatter/tst_qmldatetimeformatter.cpp
new file mode 100644
index 0000000..3302cfa
--- /dev/null
+++ b/tests/auto/declarative/qmldatetimeformatter/tst_qmldatetimeformatter.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlcomponent.h>
+#include <private/qmldatetimeformatter_p.h>
+#include <QDebug>
+
+class tst_datetimeformatter : public QObject
+{
+ Q_OBJECT
+public:
+ tst_datetimeformatter() {}
+
+private slots:
+ void date();
+ void time();
+ void dateTime();
+};
+
+void tst_datetimeformatter::date()
+{
+ QmlEngine engine;
+ QmlComponent formatterComponent(&engine);
+ formatterComponent.setData(QByteArray("import Qt 4.6\n DateTimeFormatter { date: \"2008-12-24\" }"),
+ QUrl::fromLocalFile(""));
+ QmlDateTimeFormatter *formatter = qobject_cast<QmlDateTimeFormatter*>(formatterComponent.create());
+ if(formatterComponent.isError())
+ qDebug() << formatterComponent.errors();
+ QVERIFY(formatter != 0);
+
+ QDate date(2008,12,24);
+ QCOMPARE(formatter->date(), date);
+ QCOMPARE(formatter->dateTime().date(), date);
+ QCOMPARE(formatter->dateText(),date.toString(Qt::SystemLocaleShortDate));
+
+ formatter->setLongStyle(true);
+ QVERIFY(formatter->longStyle());
+ QCOMPARE(formatter->dateText(),date.toString(Qt::SystemLocaleLongDate));
+
+ formatter->setDateFormat("ddd MMMM d yy");
+ QCOMPARE(formatter->dateFormat(), QLatin1String("ddd MMMM d yy"));
+ QCOMPARE(formatter->dateText(),date.toString("ddd MMMM d yy"));
+
+ QVERIFY(formatter->timeText().isEmpty());
+ QVERIFY(formatter->dateTimeText().isEmpty());
+
+ delete formatter;
+}
+
+void tst_datetimeformatter::time()
+{
+ QmlEngine engine;
+ QmlComponent formatterComponent(&engine);
+ formatterComponent.setData("import Qt 4.6\n DateTimeFormatter { time: \"14:15:38.200\" }", QUrl::fromLocalFile(""));
+ QmlDateTimeFormatter *formatter = qobject_cast<QmlDateTimeFormatter*>(formatterComponent.create());
+ if(formatterComponent.isError())
+ qDebug() << formatterComponent.errors();
+ QVERIFY(formatter != 0);
+
+ QTime time(14,15,38,200);
+
+ QCOMPARE(formatter->time(),time);
+ QCOMPARE(formatter->dateTime().time(),time);
+
+ QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleShortDate));
+
+ formatter->setLongStyle(true);
+ QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleLongDate));
+
+ formatter->setTimeFormat("H:m:s a");
+ QCOMPARE(formatter->timeFormat(), QLatin1String("H:m:s a"));
+ QCOMPARE(formatter->timeText(),time.toString("H:m:s a"));
+
+ formatter->setTimeFormat("hh:mm:ss.zzz");
+ QCOMPARE(formatter->timeText(),time.toString("hh:mm:ss.zzz"));
+
+ QVERIFY(formatter->dateText().isEmpty());
+ QVERIFY(formatter->dateTimeText().isEmpty());
+
+ delete formatter;
+}
+
+void tst_datetimeformatter::dateTime()
+{
+ QmlEngine engine;
+ QmlComponent formatterComponent(&engine);
+ formatterComponent.setData("import Qt 4.6\n DateTimeFormatter { dateTime: \"1978-03-04T09:13:54\" }", QUrl::fromLocalFile(""));
+ QmlDateTimeFormatter *formatter = qobject_cast<QmlDateTimeFormatter*>(formatterComponent.create());
+ if(formatterComponent.isError())
+ qDebug() << formatterComponent.errors();
+ QVERIFY(formatter != 0);
+
+ QDateTime dateTime(QDate(1978,03,04),QTime(9,13,54));
+ QCOMPARE(formatter->dateTime(),dateTime);
+ QCOMPARE(formatter->date(),dateTime.date());
+ QCOMPARE(formatter->time(),dateTime.time());
+ QCOMPARE(formatter->dateTimeText(),dateTime.toString(Qt::SystemLocaleShortDate));
+
+ formatter->setLongStyle(true);
+ QCOMPARE(formatter->dateTimeText(),dateTime.toString(Qt::SystemLocaleLongDate));
+
+ formatter->setDateTimeFormat("M/d/yy H:m:s a");
+ QCOMPARE(formatter->dateTimeFormat(), QLatin1String("M/d/yy H:m:s a"));
+ QCOMPARE(formatter->dateTimeText(),dateTime.toString("M/d/yy H:m:s a"));
+
+ delete formatter;
+}
+
+QTEST_MAIN(tst_datetimeformatter)
+
+#include "tst_datetimeformatter.moc"