hayai.hpp
Go to the documentation of this file.
00001 #ifndef __HAYAI
00002 #define __HAYAI
00003 
00004 #include "hayai/hayai_benchmarker.hpp"
00005 #include "hayai/hayai_test.hpp"
00006 #include "hayai/hayai_default_test_factory.hpp"
00007 #include "hayai/hayai_fixture.hpp"
00008 #include "hayai/hayai_console_outputter.hpp"
00009 #include "hayai/hayai_json_outputter.hpp"
00010 #include "hayai/hayai_junit_xml_outputter.hpp"
00011 
00012 
00013 #define HAYAI_VERSION "1.0.1"
00014 
00015 
00016 #define BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name) \
00017     fixture_name ## _ ## benchmark_name ## _Benchmark
00018 
00019 #define BENCHMARK_(fixture_name,                                        \
00020                    benchmark_name,                                      \
00021                    fixture_class_name,                                  \
00022                    runs,                                                \
00023                    iterations)                                          \
00024     class BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)           \
00025         :   public fixture_class_name                                   \
00026     {                                                                   \
00027     public:                                                             \
00028         BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)()           \
00029         {                                                               \
00030                                                                         \
00031         }                                                               \
00032     protected:                                                          \
00033         virtual void TestBody();                                        \
00034     private:                                                            \
00035         static const ::hayai::TestDescriptor* _descriptor;              \
00036     };                                                                  \
00037                                                                         \
00038     const ::hayai::TestDescriptor*                                      \
00039     BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)::_descriptor =  \
00040         ::hayai::Benchmarker::Instance().RegisterTest(                  \
00041             #fixture_name,                                              \
00042             #benchmark_name,                                            \
00043             runs,                                                       \
00044             iterations,                                                 \
00045             new ::hayai::TestFactoryDefault<                            \
00046                 BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)     \
00047             >(),                                                        \
00048             ::hayai::TestParametersDescriptor());                       \
00049                                                                         \
00050     void BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)::TestBody()
00051 
00052 #define BENCHMARK_F(fixture_name,                        \
00053                     benchmark_name,                      \
00054                     runs,                                \
00055                     iterations)                          \
00056     BENCHMARK_(fixture_name,                             \
00057                benchmark_name,                           \
00058                fixture_name,                             \
00059                runs,                                     \
00060                iterations)
00061 
00062 #define BENCHMARK(fixture_name,                          \
00063                   benchmark_name,                        \
00064                   runs,                                  \
00065                   iterations)                            \
00066     BENCHMARK_(fixture_name,                             \
00067                benchmark_name,                           \
00068                ::hayai::Test,                            \
00069                runs,                                     \
00070                iterations)
00071 
00072 // Parametrized benchmarks.
00073 #define BENCHMARK_P_(fixture_name,                                      \
00074                      benchmark_name,                                    \
00075                      fixture_class_name,                                \
00076                      runs,                                              \
00077                      iterations,                                        \
00078                      arguments)                                         \
00079     class BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)           \
00080         :   public fixture_class_name {                                 \
00081     public:                                                             \
00082         BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name) () {}       \
00083         virtual ~ BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name) () {} \
00084         static const std::size_t _runs = runs;                          \
00085         static const std::size_t _iterations = iterations;              \
00086         static const char* _argumentsDeclaration() { return #arguments;  } \
00087     protected:                                                          \
00088         inline void TestPayload arguments;                              \
00089     };                                                                  \
00090     void BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)::TestPayload arguments
00091 
00092 #define BENCHMARK_P(fixture_name,               \
00093                     benchmark_name,             \
00094                     runs,                       \
00095                     iterations,                 \
00096                     arguments)                  \
00097     BENCHMARK_P_(fixture_name,                  \
00098                  benchmark_name,                \
00099                  hayai::Fixture,                \
00100                  runs,                          \
00101                  iterations,                    \
00102                  arguments)
00103 
00104 #define BENCHMARK_P_F(fixture_name, benchmark_name, runs, iterations, arguments) \
00105         BENCHMARK_P_(fixture_name, benchmark_name, fixture_name, runs, iterations, arguments)
00106 
00107 #define BENCHMARK_P_CLASS_NAME_(fixture_name, benchmark_name, id)   \
00108         fixture_name ## _ ## benchmark_name ## _Benchmark_ ## id
00109 
00110 #define BENCHMARK_P_INSTANCE1(fixture_name, benchmark_name, arguments, id) \
00111     class BENCHMARK_P_CLASS_NAME_(fixture_name, benchmark_name, id):    \
00112         public BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name) {    \
00113     protected:                                                          \
00114         virtual void TestBody() { this->TestPayload arguments; }        \
00115     private:                                                            \
00116         static const ::hayai::TestDescriptor* _descriptor;              \
00117     };                                                                  \
00118     const ::hayai::TestDescriptor* BENCHMARK_P_CLASS_NAME_(fixture_name, benchmark_name, id)::_descriptor = \
00119         ::hayai::Benchmarker::Instance().RegisterTest(                  \
00120             #fixture_name, #benchmark_name,                             \
00121             BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)::_runs, \
00122             BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)::_iterations, \
00123             new ::hayai::TestFactoryDefault< BENCHMARK_P_CLASS_NAME_(fixture_name, benchmark_name, id) >(), \
00124             ::hayai::TestParametersDescriptor(BENCHMARK_CLASS_NAME_(fixture_name, benchmark_name)::_argumentsDeclaration(), #arguments))
00125 
00126 #if defined(__COUNTER__)
00127 #   define BENCHMARK_P_ID_ __COUNTER__
00128 #else
00129 #   define BENCHMARK_P_ID_ __LINE__
00130 #endif
00131 
00132 #define BENCHMARK_P_INSTANCE(fixture_name, benchmark_name, arguments)   \
00133     BENCHMARK_P_INSTANCE1(fixture_name, benchmark_name, arguments, BENCHMARK_P_ID_)
00134 
00135 
00136 #endif


hayai
Author(s): Nick Bruun
autogenerated on Thu Jun 6 2019 18:13:43