HART  0.1.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart.hpp
Go to the documentation of this file.
1#pragma once
2
3#if defined (HART_IMPLEMENTATION)
4#define DR_WAV_IMPLEMENTATION // Wav single header library's implementation
5#endif
6
7#include <stdexcept>
8
10#include "dsp/hart_dsp_all.hpp"
12#include "envelopes/hart_envelopes_all.hpp"
15#include "matchers/hart_matchers_all.hpp"
17#include "signals/hart_signals_all.hpp"
19#include "hart_units.hpp"
21
22namespace hart
23{
24
25#define HART_FAIL_TEST_MSG(msg) throw hart::TestAssertException (std::string ("HART_FAIL_TEST_MSG() triggered test fail at line ") + std::to_string (__LINE__) + " with message: \"" + msg + '\"')
26#define HART_FAIL_TEST() throw hart::TestAssertException (std::string ("HART_FAIL_TEST() triggered test fail at line ") + std::to_string (__LINE__))
27
28#define HART_ASSERT_TRUE(cond)
29 if (!(cond)) throw hart::TestAssertException (std::string ("HART_ASSERT_TRUE() failed at line ") + std::to_string (__LINE__) + ": \"" #cond "\"");
30
31#define HART_EXPECT_TRUE(cond)
32 if (!(cond)) hart::ExpectationFailureMessages::get().emplace_back (std::string ("HART_EXPECT_TRUE() failed at line ") + std::to_string (__LINE__) + ": \"" #cond "\"");
33
34#define HART_CONCAT_IMPL(x, y) x##y
35#define HART_CONCAT(x, y) HART_CONCAT_IMPL(x, y)
36#define HART_UNIQUE_ID(x) HART_CONCAT(x, __LINE__)
37
38#define HART_ITEM_WITH_TAGS(name, tags, category)
39 static void HART_UNIQUE_ID(HART_RunTask)();
40 namespace {
41 struct HART_UNIQUE_ID(HART_RegistrarType) {
42 HART_UNIQUE_ID(HART_RegistrarType)() {
43 hart::TestRegistry::getInstance().add (name, tags, category, &HART_UNIQUE_ID (HART_RunTask));
44 }
45 };
46 }
47 static HART_UNIQUE_ID(HART_RegistrarType) HART_UNIQUE_ID(HART_registrar);
48 static void HART_UNIQUE_ID(HART_RunTask)()
49
50/// @brief Declares a test case with tags
51/// @warning Tags aren't supported yet
52/// @param name Name for the test case
53/// @param tags Tags like "[my-tag-1][my-tag-2]"
54/// @ingroup TestRunner
55#define HART_TEST_WITH_TAGS(name, tags) HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::test)
56
57/// @brief Declares a generator with tags
58/// @details Pretty much the same as a usual test case, but will be called only if the `--run-generators` CLI flag is set
59/// @warning Tags aren't supported yet
60/// @param name Name for the generator
61/// @param tags Tags like "[my-tag-1][my-tag-2]"
62/// @ingroup TestRunner
63#define HART_GENERATE_WITH_TAGS(name, tags) HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::generate)
64
65/// @brief Declares a test case
66/// @param name Name for the test case
67/// @ingroup TestRunner
68#define HART_TEST(name) HART_TEST_WITH_TAGS(name, "")
69
70/// @brief Declares a generator
71/// @details Pretty much the same as a usual test case, but will be called only if the `--run-generators` CLI flag is set
72/// @param name Name for generator
73/// @ingroup TestRunner
74#define HART_GENERATE(name) HART_GENERATE_WITH_TAGS(name, "")
75
76#if HART_DO_NOT_THROW_EXCEPTIONS
77/// @brief Put it at the beginning of your tese case if it requires a properly set data path
78/// @details For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.
79/// @ingroup TestRunner
80#define HART_REQUIRES_DATA_PATH_ARG if (hart::CLIConfig::getInstance().getDataRootPath().empty()) { hart::ExpectationFailureMessages::get().emplace_back ("This test requires a data path set by the --data-root-path CLI argument, but it's empty"); return; }
81#else
82/// @brief Put it at the beginning of your tese case if it requires a properly set data path
83/// @details For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.
84/// @ingroup TestRunner
85#define HART_REQUIRES_DATA_PATH_ARG if (hart::CLIConfig::getInstance().getDataRootPath().empty()) { throw hart::ConfigurationError ("This test requires a data path set by the --data-root-path CLI argument, but it's empty"); }
86#endif // HART_DO_NOT_THROW_EXCEPTIONS
87
88/// @brief Runs all tests or generators
89/// @prief Place this macro in your `main()` function
90/// @ingroup TestRunner
91#define HART_RUN_ALL_TESTS(argc, argv)
92 do
93 {
94 hart::CLIConfig::getInstance().initCommandLineArgs();
95 CLI11_PARSE (hart::CLIConfig::getInstance().getCLIApp(), argc, argv);
96 return hart::TestRegistry::getInstance().runAll();
97 }
98 while (false);
99
100/// @brief Put it before you test cases to use hart classes without hart:: namespace prefix and explicit <float> template value
101#define HART_DECLARE_ALIASES_FOR_FLOAT using namespace hart::aliases_float
102
103/// @brief Put it before you test cases to use hart classes without hart:: namespace prefix and explicit <double> template value
104#define HART_DECLARE_ALIASES_FOR_DOUBLE using namespace hart::aliases_double
105
106} // namespace hart
#define HART_GENERATE_WITH_TAGS(name, tags)
Declares a generator with tags.
Definition hart.hpp:63
#define HART_TEST_WITH_TAGS(name, tags)
Declares a test case with tags.
Definition hart.hpp:55
#define HART_CONCAT(x, y)
Definition hart.hpp:35
#define HART_UNIQUE_ID(x)
Definition hart.hpp:36
#define HART_CONCAT_IMPL(x, y)
Definition hart.hpp:34
#define HART_ITEM_WITH_TAGS(name, tags, category)
Definition hart.hpp:38