File indexing completed on 2024-04-21 16:32:07

0001 /* This file is part of Kairo Timer
0002 
0003    SPDX-FileCopyrightText: 2016 (c) Kevin Ottens <ervin@kde.org>
0004 
0005    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 
0007 */
0008 
0009 #include <QtTest>
0010 
0011 #include "timermodel.h"
0012 
0013 static_assert(std::is_copy_assignable<TimerModel>::value, "Should be copy assignable");
0014 static_assert(std::is_copy_constructible<TimerModel>::value, "Should be copy constructible");
0015 static_assert(std::is_move_assignable<TimerModel>::value, "Should be move assignable");
0016 static_assert(std::is_move_constructible<TimerModel>::value, "Should be move constructible");
0017 
0018 class TimerModelTest : public QObject
0019 {
0020     Q_OBJECT
0021 private slots:
0022     void initTestCase()
0023     {
0024         qRegisterMetaType<TimerModel>();
0025     }
0026 
0027     void shouldHaveDefaultState()
0028     {
0029         // GIVEN
0030         auto model = TimerModel{};
0031 
0032         // THEN
0033         QCOMPARE(model.text(), QString());
0034         QCOMPARE(model.duration(), -1);
0035         QCOMPARE(model.type(), TimerModel::Invalid);
0036         QVERIFY(!model.isValid());
0037     }
0038 
0039     void shouldConstructCountdown()
0040     {
0041         // GIVEN
0042         auto model = TimerModel{"rest", 10000};
0043 
0044         // THEN
0045         QCOMPARE(model.text(), QString("rest"));
0046         QCOMPARE(model.duration(), 10000);
0047         QCOMPARE(model.type(), TimerModel::Countdown);
0048         QVERIFY(model.isValid());
0049     }
0050 
0051     void shouldConstructStopwatch()
0052     {
0053         // GIVEN
0054         auto model = TimerModel{"run"};
0055 
0056         // THEN
0057         QCOMPARE(model.text(), QString("run"));
0058         QCOMPARE(model.duration(), 0);
0059         QCOMPARE(model.type(), TimerModel::Stopwatch);
0060         QVERIFY(model.isValid());
0061     }
0062 
0063     void shouldBeCopyable()
0064     {
0065         // GIVEN
0066         auto model = TimerModel{"rest", 10000};
0067 
0068         // WHEN
0069         model = TimerModel{"foo", 5000};
0070 
0071         // THEN
0072         QCOMPARE(model.text(), QString("foo"));
0073         QCOMPARE(model.duration(), 5000);
0074     }
0075 
0076     void shouldBeComparable_data()
0077     {
0078         QTest::addColumn<TimerModel>("model1");
0079         QTest::addColumn<TimerModel>("model2");
0080         QTest::addColumn<bool>("expected");
0081 
0082         QTest::newRow("equal") << TimerModel{"foo", 5000} << TimerModel{"foo", 5000} << true;
0083         QTest::newRow("differ by text") << TimerModel{"foo", 5000} << TimerModel{"bar", 5000} << false;
0084         QTest::newRow("differ by duration") << TimerModel{"foo", 5000} << TimerModel{"foo", 15000} << false;
0085         QTest::newRow("differ completely") << TimerModel{"foo", 5000} << TimerModel{"bar", 15000} << false;
0086     }
0087 
0088     void shouldBeComparable()
0089     {
0090         // GIVEN
0091         QFETCH(TimerModel, model1);
0092         QFETCH(TimerModel, model2);
0093         QFETCH(bool, expected);
0094 
0095         // THEN
0096         QCOMPARE((model1 == model2), expected);
0097         QCOMPARE((model1 != model2), !expected);
0098     }
0099 };
0100 
0101 QTEST_APPLESS_MAIN(TimerModelTest)
0102 
0103 #include "timermodeltest.moc"