Changeset View
Changeset View
Standalone View
Standalone View
tests/units/utils/datetimetest.cpp
Show All 25 Lines | |||||
26 | #include "utils/datetime.h" | 26 | #include "utils/datetime.h" | ||
27 | 27 | | |||
28 | using namespace Utils; | 28 | using namespace Utils; | ||
29 | 29 | | |||
30 | class DateTimeTest : public QObject | 30 | class DateTimeTest : public QObject | ||
31 | { | 31 | { | ||
32 | Q_OBJECT | 32 | Q_OBJECT | ||
33 | private slots: | 33 | private slots: | ||
34 | void shouldNotOverrideCurrentDateTime() | | |||
35 | { | | |||
36 | // GIVEN | | |||
37 | const auto todayDate = QDateTime::currentDateTime(); | | |||
38 | | ||||
39 | // WHEN | | |||
40 | const QDateTime zanshinDate = DateTime::currentDateTime(); | | |||
41 | | ||||
42 | // THEN | | |||
43 | QCOMPARE(zanshinDate.date(), todayDate.date()); | | |||
44 | } | | |||
45 | | ||||
46 | void shouldOverrideCurrentDateTime() | | |||
47 | { | | |||
48 | // GIVEN | | |||
49 | const QByteArray dateExpected = "2015-03-10"; | | |||
50 | qputenv("ZANSHIN_OVERRIDE_DATETIME", dateExpected); | | |||
51 | | ||||
52 | // WHEN | | |||
53 | const QDateTime zanshinDate = DateTime::currentDateTime(); | | |||
54 | | ||||
55 | // THEN | | |||
56 | QCOMPARE(zanshinDate.date(), QDateTime::fromString(QString::fromLocal8Bit(dateExpected), Qt::ISODate).date()); | | |||
57 | } | | |||
58 | | ||||
59 | void shouldNotOverrideCurrentDateTimeWhenInvalidDate() | | |||
60 | { | | |||
61 | // GIVEN | | |||
62 | const QByteArray dateExpected = "Invalid!"; | | |||
63 | qputenv("ZANSHIN_OVERRIDE_DATETIME", dateExpected); | | |||
64 | | ||||
65 | // WHEN | | |||
66 | const QDateTime zanshinDate = DateTime::currentDateTime(); | | |||
67 | | ||||
68 | // THEN | | |||
69 | QCOMPARE(zanshinDate.date(), QDateTime::currentDateTime().date()); | | |||
70 | } | | |||
71 | | ||||
72 | void shouldNotOverrideCurrentDate() | 34 | void shouldNotOverrideCurrentDate() | ||
73 | { | 35 | { | ||
74 | // GIVEN | 36 | // GIVEN | ||
75 | const auto todayDate = QDate::currentDate(); | 37 | const auto todayDate = QDate::currentDate(); | ||
76 | 38 | | |||
77 | // WHEN | 39 | // WHEN | ||
78 | const QDate zanshinDate = DateTime::currentDate(); | 40 | const QDate zanshinDate = DateTime::currentDate(); | ||
79 | 41 | | |||
Show All 34 Lines |