cppcheck/test/testtimer.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

/*
* Cppcheck - A tool for static C/C++ code analysis
2021-09-26 11:34:56 +02:00
* Copyright (C) 2007-2021 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "testsuite.h"
2017-05-27 04:33:47 +02:00
#include "timer.h"
2017-05-27 04:33:47 +02:00
#include <cmath>
#include <ctime>
class TestTimer : public TestFixture {
public:
2021-08-07 20:51:18 +02:00
TestTimer() : TestFixture("TestTimer") {}
private:
2019-01-12 15:45:25 +01:00
void run() OVERRIDE {
TEST_CASE(result);
}
2014-11-20 14:20:09 +01:00
void result() const {
TimerResultsData t1;
2018-06-16 22:28:14 +02:00
t1.mClocks = ~(std::clock_t)0;
ASSERT(t1.seconds() > 100.0);
2018-06-16 22:28:14 +02:00
t1.mClocks = CLOCKS_PER_SEC * 5 / 2;
ASSERT(std::fabs(t1.seconds()-2.5) < 0.01);
}
};
REGISTER_TEST(TestTimer)