File indexing completed on 2024-05-12 17:21:31

0001 /*
0002     Copyright (C) 2015 by Elvis Angelaccio <elvis.angelaccio@kde.org>
0003 
0004     This file is part of Kronometer.
0005 
0006     Kronometer is free software: you can redistribute it and/or modify
0007     it under the terms of the GNU General Public License as published by
0008     the Free Software Foundation, either version 2 of the License, or
0009     (at your option) any later version.
0010 
0011     Kronometer is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014     GNU General Public License for more details.
0015 
0016     You should have received a copy of the GNU General Public License
0017     along with Kronometer.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #include "testtimeformat.h"
0021 #include "timeformat.h"
0022 
0023 #include <QTime>
0024 
0025 void TestTimeFormat::testDefaultFormat()
0026 {
0027     TimeFormat timeFormat;
0028     QTime t {0, 0};
0029 
0030     QCOMPARE(timeFormat.format(t), QStringLiteral("00:00.00"));
0031     QCOMPARE(timeFormat.secondFractions(), TimeFormat::UpToHundredths);
0032     QVERIFY(not timeFormat.hasHours());
0033     QVERIFY(timeFormat.hasMinutes());
0034     QVERIFY(timeFormat.hasFractions());
0035 }
0036 
0037 void TestTimeFormat::testFullFormat()
0038 {
0039     TimeFormat timeFormat {true, true, TimeFormat::UpToMilliseconds};
0040     QTime t {0, 0};
0041 
0042     QCOMPARE(timeFormat.format(t), QStringLiteral("00:00:00.000"));
0043     QCOMPARE(timeFormat.secondFractions(), TimeFormat::UpToMilliseconds);
0044     QVERIFY(timeFormat.hasHours());
0045     QVERIFY(timeFormat.hasMinutes());
0046     QVERIFY(timeFormat.hasFractions());
0047 }
0048 
0049 void TestTimeFormat::testMinimalFormat()
0050 {
0051     TimeFormat timeFormat {false, false, TimeFormat::NoFractions};
0052     QTime t {0, 0};
0053 
0054     QCOMPARE(timeFormat.format(t), QStringLiteral("00"));
0055     QCOMPARE(timeFormat.secondFractions(), TimeFormat::NoFractions);
0056     QVERIFY(not timeFormat.hasHours());
0057     QVERIFY(not timeFormat.hasMinutes());
0058     QVERIFY(not timeFormat.hasFractions());
0059 }
0060 
0061 void TestTimeFormat::testNoDividers()
0062 {
0063     TimeFormat timeFormat;
0064     QTime t {0, 0};
0065 
0066     timeFormat.showDividers(false);
0067 
0068     QCOMPARE(timeFormat.format(t), QStringLiteral("000000"));
0069 }
0070 
0071 void TestTimeFormat::testEquality()
0072 {
0073     TimeFormat timeFormat1;
0074     TimeFormat timeFormat2;
0075 
0076     QCOMPARE(timeFormat1, timeFormat2);
0077 }
0078 
0079 void TestTimeFormat::testInequality()
0080 {
0081     TimeFormat timeFormat1;
0082     TimeFormat timeFormat2 {true, false};
0083 
0084     QVERIFY(timeFormat1 != timeFormat2);
0085 }
0086 
0087 void TestTimeFormat::testOverrideHours()
0088 {
0089     TimeFormat timeFormat {false, true, TimeFormat::NoFractions};
0090     QTime t {0, 0};
0091 
0092     QCOMPARE(timeFormat.format(t), QStringLiteral("00:00"));
0093 
0094     timeFormat.overrideHours();
0095 
0096     QCOMPARE(timeFormat.format(t), QStringLiteral("00:00:00"));
0097 }
0098 
0099 void TestTimeFormat::testOverrideMinutes()
0100 {
0101     TimeFormat timeFormat {false, false, TimeFormat::UpToTenths};
0102     QTime t {0, 0};
0103 
0104     QCOMPARE(timeFormat.format(t), QStringLiteral("00.0"));
0105 
0106     timeFormat.overrideMinutes();
0107 
0108     QCOMPARE(timeFormat.format(t), QStringLiteral("00:00.0"));
0109 }
0110 
0111 QTEST_MAIN(TestTimeFormat)