File indexing completed on 2025-01-05 05:00:01
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Theo Vaucher <theo.vaucher@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include <testlib/qtest_zanshin.h> 0008 0009 #include "utils/datetime.h" 0010 0011 using namespace Utils; 0012 0013 class DateTimeTest : public QObject 0014 { 0015 Q_OBJECT 0016 private slots: 0017 void shouldNotOverrideCurrentDate() 0018 { 0019 // GIVEN 0020 const auto todayDate = QDate::currentDate(); 0021 0022 // WHEN 0023 const QDate zanshinDate = DateTime::currentDate(); 0024 0025 // THEN 0026 QCOMPARE(zanshinDate, todayDate); 0027 } 0028 0029 void shouldOverrideCurrentDate() 0030 { 0031 // GIVEN 0032 const QByteArray dateExpected = "2015-03-10"; 0033 qputenv("ZANSHIN_OVERRIDE_DATE", dateExpected); 0034 0035 // WHEN 0036 const QDate zanshinDate = DateTime::currentDate(); 0037 0038 // THEN 0039 QCOMPARE(zanshinDate, QDate(2015, 3, 10)); 0040 } 0041 0042 void shouldNotOverrideCurrentDateWhenInvalidDate() 0043 { 0044 // GIVEN 0045 const QByteArray dateExpected = "Invalid!"; 0046 qputenv("ZANSHIN_OVERRIDE_DATE", dateExpected); 0047 0048 // WHEN 0049 const QDate zanshinDate = DateTime::currentDate(); 0050 0051 // THEN 0052 QCOMPARE(zanshinDate, QDate::currentDate()); 0053 } 0054 }; 0055 0056 ZANSHIN_TEST_MAIN(DateTimeTest) 0057 0058 #include "datetimetest.moc"