2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Author: Lars Uebernickel <lars.uebernickel@canonical.com>
19#include "timeformatter.h"
20#include "relativetimeformatter.h"
27class TimeFormatterTest : public QObject
31 void addTestData(QList<int> daysToAdd = QList<int>()) {
32 QTest::addColumn<QDateTime>("time");
34 Q_FOREACH(int dayToAdd, daysToAdd) {
35 QDateTime time = QDateTime::currentDateTime().addDays(dayToAdd);
36 QDateTime am(time); am.setTime(QTime(1, 1, 1));
37 QDateTime midday(time); midday.setTime(QTime(12, 0, 0));
38 QDateTime pm(time); pm.setTime(QTime(17, 59, 59));
40 QTest::newRow(QString("%1day-am").arg(dayToAdd).toLatin1()) << am;
41 QTest::newRow(QString("%1day-midday").arg(dayToAdd).toLatin1()) << midday;
42 QTest::newRow(QString("%1day-pm").arg(dayToAdd).toLatin1()) << pm;
50 setenv("UNITY_TEST_ENV", "1", 1);
53 void cleanupTestCase()
55 unsetenv("UNITY_TEST_ENV");
58 void testTimeFormatter_Format_data() { addTestData(QList<int>() << 0); }
59 void testTimeFormatter_Format()
61 QFETCH(QDateTime, time);
62 const QString format = "hh:mm dd.MM.yy";
64 TimeFormatter formatter;
65 formatter.setTime(time.toMSecsSinceEpoch() * 1000);
66 formatter.setFormat(format);
68 QCOMPARE(formatter.timeString(), time.toString(format));
71 void tesGDatetTimeFormatter_Format_data() { addTestData(QList<int>() << 0); }
72 void tesGDatetTimeFormatter_Format()
74 QFETCH(QDateTime, time);
75 const QString format = "%d-%m-%Y %I:%M%p";
77 GDateTimeFormatter formatter;
78 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
79 formatter.setFormat(format);
81 QCOMPARE(formatter.timeString(), time.toString("dd-MM-yyyy hh:mmAP"));
84 void tesRelativeTimeFormatter_FarBack_data() { addTestData(QList<int>() << -200 << -20 << -7); }
85 void tesRelativeTimeFormatter_FarBack()
87 QFETCH(QDateTime, time);
89 RelativeTimeFormatter formatter;
90 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
92 QCOMPARE(formatter.timeString(), time.toString("ddd dd MMM\u2003HH:mm"));
95 void tesRelativeTimeFormatter_WeekBack_data() { addTestData(QList<int>() << -6 << -2); }
96 void tesRelativeTimeFormatter_WeekBack()
98 QFETCH(QDateTime, time);
100 RelativeTimeFormatter formatter;
101 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
103 QCOMPARE(formatter.timeString(), time.toString("ddd\u2003HH:mm"));
106 void tesRelativeTimeFormatter_Yesterday_data() { addTestData(QList<int>() << -1); }
107 void tesRelativeTimeFormatter_Yesterday()
109 QFETCH(QDateTime, time);
111 RelativeTimeFormatter formatter;
112 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
114 QCOMPARE(formatter.timeString(), QString("Yesterday\u2003%1").arg(time.toString("HH:mm")));
117 void tesRelativeTimeFormatter_Today_data() { addTestData(QList<int>() << 0); }
118 void tesRelativeTimeFormatter_Today()
120 QFETCH(QDateTime, time);
122 RelativeTimeFormatter formatter;
123 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
125 QCOMPARE(formatter.timeString(), time.toString("HH:mm"));
128 void tesRelativeTimeFormatter_Tomorrow_data() { addTestData(QList<int>() << 1); }
129 void tesRelativeTimeFormatter_Tomorrow()
131 QFETCH(QDateTime, time);
133 RelativeTimeFormatter formatter;
134 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
136 QCOMPARE(formatter.timeString(), QString("Tomorrow\u2003%1").arg(time.toString("HH:mm")));
140 void tesRelativeTimeFormatter_WeekForward_data() { addTestData(QList<int>() << 2 << 6); }
141 void tesRelativeTimeFormatter_WeekForward()
143 QFETCH(QDateTime, time);
145 RelativeTimeFormatter formatter;
146 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
148 QCOMPARE(formatter.timeString(), time.toString("ddd\u2003HH:mm"));
151 void tesRelativeTimeFormatter_FarForward_data() { addTestData(QList<int>() << 7 << 20 << 200); }
152 void tesRelativeTimeFormatter_FarForward()
154 QFETCH(QDateTime, time);
156 RelativeTimeFormatter formatter;
157 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
159 QCOMPARE(formatter.timeString(), time.toString("ddd dd MMM\u2003HH:mm"));
163QTEST_GUILESS_MAIN(TimeFormatterTest)
165#include "timeformattertest.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list