File indexing completed on 2024-12-08 05:12:17
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 "circuitmodel.h" 0012 0013 static_assert(std::is_copy_assignable<CircuitModel>::value, "Should be copy assignable"); 0014 static_assert(std::is_copy_constructible<CircuitModel>::value, "Should be copy constructible"); 0015 static_assert(std::is_move_assignable<CircuitModel>::value, "Should be move assignable"); 0016 static_assert(std::is_move_constructible<CircuitModel>::value, "Should be move constructible"); 0017 0018 class CircuitModelTest : public QObject 0019 { 0020 Q_OBJECT 0021 private slots: 0022 void shouldHaveDefaultState() 0023 { 0024 // GIVEN 0025 auto model = CircuitModel{}; 0026 0027 // THEN 0028 QCOMPARE(model.name(), QString()); 0029 QCOMPARE(model.isEmpty(), true); 0030 QCOMPARE(model.size(), 0); 0031 } 0032 0033 void shouldBeConstructibleFromVector() 0034 { 0035 // GIVEN 0036 const auto models = QVector<TimerModel>{ 0037 {"run"}, 0038 {"rest", 10}, 0039 {"rest", 20} 0040 }; 0041 const auto model = CircuitModel{"foo", models}; 0042 0043 // THEN 0044 QCOMPARE(model.name(), QString("foo")); 0045 QCOMPARE(model.isEmpty(), false); 0046 QCOMPARE(model.size(), 3); 0047 QCOMPARE(model.at(0), models.at(0)); 0048 QCOMPARE(model.at(1), models.at(1)); 0049 QCOMPARE(model.at(2), models.at(2)); 0050 } 0051 0052 void shouldBeConstructibleFromInitializerList() 0053 { 0054 // GIVEN 0055 const auto models = QVector<TimerModel>{ 0056 {"run"}, 0057 {"rest", 10}, 0058 {"rest", 20} 0059 }; 0060 const auto model = CircuitModel{ 0061 "foo", 0062 { 0063 {"run"}, 0064 {"rest", 10}, 0065 {"rest", 20} 0066 } 0067 }; 0068 0069 // THEN 0070 QCOMPARE(model.name(), QString("foo")); 0071 QCOMPARE(model.isEmpty(), false); 0072 QCOMPARE(model.size(), 3); 0073 QCOMPARE(model.at(0), models.at(0)); 0074 QCOMPARE(model.at(1), models.at(1)); 0075 QCOMPARE(model.at(2), models.at(2)); 0076 } 0077 0078 void shouldBeCopyable() 0079 { 0080 // GIVEN 0081 auto model = CircuitModel{ 0082 "baz", 0083 { 0084 {"rest", 10000} 0085 } 0086 }; 0087 0088 // WHEN 0089 model = CircuitModel{ 0090 "bleh", 0091 { 0092 {"foo", 5000}, 0093 {"bar"} 0094 } 0095 }; 0096 0097 // THEN 0098 QCOMPARE(model.name(), QString("bleh")); 0099 QCOMPARE(model.isEmpty(), false); 0100 QCOMPARE(model.size(), 2); 0101 QCOMPARE(model.at(0).text(), QString("foo")); 0102 QCOMPARE(model.at(0).duration(), 5000); 0103 QCOMPARE(model.at(1).text(), QString("bar")); 0104 QCOMPARE(model.at(1).duration(), 0); 0105 } 0106 0107 void shouldBeComparable() 0108 { 0109 // GIVEN 0110 auto model1 = CircuitModel{ 0111 "foo", 0112 { 0113 {"rest", 10000} 0114 } 0115 }; 0116 auto model2 = CircuitModel{ 0117 "foo", 0118 { 0119 {"rest", 10000} 0120 } 0121 }; 0122 auto model3 = CircuitModel{ 0123 "foo", 0124 { 0125 {"foo", 5000}, 0126 {"bar"} 0127 } 0128 }; 0129 auto model4 = CircuitModel{ 0130 "bar", 0131 { 0132 {"foo", 5000}, 0133 {"bar"} 0134 } 0135 }; 0136 0137 // THEN 0138 QCOMPARE((model1 == model2), true); 0139 QCOMPARE((model1 != model2), false); 0140 QCOMPARE((model1 == model3), false); 0141 QCOMPARE((model1 != model3), true); 0142 QCOMPARE((model1 == model3), false); 0143 QCOMPARE((model1 != model3), true); 0144 QCOMPARE((model3 == model4), false); 0145 QCOMPARE((model3 != model4), true); 0146 } 0147 }; 0148 0149 QTEST_APPLESS_MAIN(CircuitModelTest) 0150 0151 #include "circuitmodeltest.moc"