2012-09-15 20:43:37 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2012-09-15 20:43:37 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2022-01-27 19:03:20 +01:00
|
|
|
#include "config.h"
|
2012-09-15 20:43:37 +02:00
|
|
|
#include "testsuite.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
#include "timer.h"
|
2012-09-15 20:43:37 +02:00
|
|
|
|
2017-05-27 04:33:47 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <ctime>
|
2015-03-11 22:26:33 +01:00
|
|
|
|
2012-09-15 20:43:37 +02:00
|
|
|
class TestTimer : public TestFixture {
|
|
|
|
public:
|
2021-08-07 20:51:18 +02:00
|
|
|
TestTimer() : TestFixture("TestTimer") {}
|
2012-09-15 20:43:37 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-01-12 15:45:25 +01:00
|
|
|
void run() OVERRIDE {
|
2012-09-15 20:43:37 +02:00
|
|
|
TEST_CASE(result);
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void result() const {
|
2012-09-15 20:43:37 +02:00
|
|
|
TimerResultsData t1;
|
2018-06-16 22:28:14 +02:00
|
|
|
t1.mClocks = ~(std::clock_t)0;
|
2012-09-15 20:43:37 +02:00
|
|
|
ASSERT(t1.seconds() > 100.0);
|
|
|
|
|
2018-06-16 22:28:14 +02:00
|
|
|
t1.mClocks = CLOCKS_PER_SEC * 5 / 2;
|
2012-09-15 20:43:37 +02:00
|
|
|
ASSERT(std::fabs(t1.seconds()-2.5) < 0.01);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestTimer)
|