Files
inja/test/hayai/hayai_test.hpp
pantor 699c207c8c Inja v2 (#67)
* inja2

* header only

* reduce dependencies

* code cleaning

* c++17

* use stdc++

* code cleaning

* infrastructure

* header only

* add infrastructure

* fix tests

* use minimum clang 6

* code cleaning, polyfill for c++11

* fix some file tests

* fix readme

* update appveyor

* fix polyfill and ci

* fix polyfill

* fix ci?

* test msvc __cplusplus

* add doxygen

* activate all tests

* code cleaning

* add coveralls, set default to dot notation

* add html test

* add doxygen comments

* test single_include file

* change build folder in appveyor

* correct make arguments in appveyor

* fix appveyor arguments
2018-12-23 16:13:15 +01:00

84 lines
1.9 KiB
C++
Executable File

#ifndef __HAYAI_TEST
#define __HAYAI_TEST
#include <cstddef>
#include "hayai_clock.hpp"
#include "hayai_test_result.hpp"
namespace hayai
{
/// Base test class.
/// @ref SetUp is invoked before each run, and @ref TearDown is invoked
/// once the run is finished. Iterations rely on the same fixture
/// for every run.
///
/// The default test class does not contain any actual code in the
/// SetUp and TearDown methods, which means that tests can inherit
/// this class directly for non-fixture based benchmarking tests.
class Test
{
public:
/// Set up the testing fixture for execution of a run.
virtual void SetUp()
{
}
/// Tear down the previously set up testing fixture after the
/// execution run.
virtual void TearDown()
{
}
/// Run the test.
/// @param iterations Number of iterations to gather data for.
/// @returns the number of nanoseconds the run took.
uint64_t Run(std::size_t iterations)
{
std::size_t iteration = iterations;
// Set up the testing fixture.
SetUp();
// Get the starting time.
Clock::TimePoint startTime, endTime;
startTime = Clock::Now();
// Run the test body for each iteration.
while (iteration--)
TestBody();
// Get the ending time.
endTime = Clock::Now();
// Tear down the testing fixture.
TearDown();
// Return the duration in nanoseconds.
return Clock::Duration(startTime, endTime);
}
virtual ~Test()
{
}
protected:
/// Test body.
/// Executed for each iteration the benchmarking test is run.
virtual void TestBody()
{
}
};
}
#endif