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 "teststopwatch.h" 0021 #include "stopwatch.h" 0022 0023 #include <QTime> 0024 0025 void TestStopwatch::testInactive() 0026 { 0027 Stopwatch stopwatch; 0028 0029 QVERIFY(not stopwatch.isRunning()); 0030 QVERIFY(not stopwatch.isPaused()); 0031 QVERIFY(stopwatch.isInactive()); 0032 } 0033 0034 void TestStopwatch::testRunning() 0035 { 0036 Stopwatch stopwatch; 0037 0038 stopwatch.start(); 0039 0040 QVERIFY(stopwatch.isRunning()); 0041 QVERIFY(not stopwatch.isPaused()); 0042 QVERIFY(not stopwatch.isInactive()); 0043 } 0044 0045 void TestStopwatch::testPaused() 0046 { 0047 Stopwatch stopwatch; 0048 0049 stopwatch.pause(); 0050 0051 QVERIFY(not stopwatch.isRunning()); 0052 QVERIFY(stopwatch.isPaused()); 0053 QVERIFY(not stopwatch.isInactive()); 0054 } 0055 0056 void TestStopwatch::testReset() 0057 { 0058 Stopwatch stopwatch; 0059 0060 stopwatch.reset(); 0061 0062 QVERIFY(not stopwatch.isRunning()); 0063 QVERIFY(not stopwatch.isPaused()); 0064 QVERIFY(stopwatch.isInactive()); 0065 } 0066 0067 void TestStopwatch::testInitialize() 0068 { 0069 Stopwatch s1, s2; 0070 0071 s1.start(); 0072 QTest::qSleep(100); 0073 s1.pause(); 0074 int t = s1.raw(); 0075 0076 QVERIFY(s2.initialize(t)); 0077 QVERIFY(s2.isPaused()); 0078 QCOMPARE(s2.raw(), t); 0079 } 0080 0081 QTEST_MAIN(TestStopwatch)