HART  0.2.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
11#include "dsp/hart_dsp_all.hpp"
13#include "envelopes/hart_envelopes_all.hpp"
16#include "matchers/hart_matchers_all.hpp"
17#include "metrics/hart_metrics_all.hpp"
21#include "signals/hart_signals_all.hpp"
23#include "hart_str.hpp"
25#include "hart_units.hpp"
27
28namespace hart
29{
30
31/// @brief Fails a test case unconditionally with a text message
32/// @param message Message to be displayed
33/// @ingroup TestRunner
34#define HART_FAIL_TEST_MSG(message) throw hart::TestAssertException (std::string ("HART_FAIL_TEST_MSG() triggered test fail at line ") + std::to_string (__LINE__) + " with message: \"" + message + '\"')
35
36/// @brief Fails a test case unconditionally
37/// @ingroup TestRunner
38#define HART_FAIL_TEST() throw hart::TestAssertException (std::string ("HART_FAIL_TEST() triggered test fail at line ") + std::to_string (__LINE__))
39
40#define HART_CONCAT_IMPL(x, y) x##y
41#define HART_CONCAT(x, y) HART_CONCAT_IMPL(x, y)
42#define HART_UNIQUE_ID(x) HART_CONCAT(x, __LINE__)
43
44#define HART_ITEM_WITH_TAGS(name, tags, category)
45 static void HART_UNIQUE_ID(HART_RunTask)();
46 namespace {
47 struct HART_UNIQUE_ID(HART_RegistrarType) {
48 HART_UNIQUE_ID(HART_RegistrarType)() {
49 hart::TestRegistry::getInstance().add (name, tags, __FILE__, __LINE__, category, &HART_UNIQUE_ID (HART_RunTask));
50 }
51 };
52 }
53 static HART_UNIQUE_ID(HART_RegistrarType) HART_UNIQUE_ID(HART_registrar);
54 static void HART_UNIQUE_ID(HART_RunTask)()
55
56/// @brief Declares a test case with tags
57/// @warning Tags aren't supported yet
58/// @param name Name for the test case
59/// @param tags Tags like "[my-tag-1][my-tag-2]"
60/// @ingroup TestRunner
61#define HART_TEST_WITH_TAGS(name, tags) HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::test)
62
63/// @brief Declares a generator with tags
64/// @details Pretty much the same as a usual test case, but will be called only if the `--run-generators` CLI flag is set
65/// @warning Tags aren't supported yet
66/// @param name Name for the generator
67/// @param tags Tags like "[my-tag-1][my-tag-2]"
68/// @ingroup TestRunner
69#define HART_GENERATE_WITH_TAGS(name, tags) HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::generate)
70
71/// @brief Declares a test case
72/// @param name Name for the test case
73/// @ingroup TestRunner
74#define HART_TEST(name) HART_TEST_WITH_TAGS(name, "")
75
76/// @brief Declares a generator
77/// @details Pretty much the same as a usual test case, but will be called only if the `--run-generators` CLI flag is set
78/// @param name Name for generator
79/// @ingroup TestRunner
80#define HART_GENERATE(name) HART_GENERATE_WITH_TAGS(name, "")
81
82#if HART_DO_NOT_THROW_EXCEPTIONS
83/// @brief Put it at the beginning of your tese case if it requires a properly set data path
84/// @details For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.
85/// @ingroup TestRunner
86#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; }
87#else
88/// @brief Put it at the beginning of your tese case if it requires a properly set data path
89/// @details For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.
90/// @ingroup TestRunner
91#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"); }
92#endif // HART_DO_NOT_THROW_EXCEPTIONS
93
94/// @brief Runs all tests or generators
95/// @details Place this macro in your `main()` function
96/// @ingroup TestRunner
97#define HART_RUN_ALL_TESTS(argc, argv)
98 do
99 {
100 hart::CLIConfig::getInstance().initCommandLineArgs();
101 CLI11_PARSE (hart::CLIConfig::getInstance().getCLIApp(), argc, argv);
102 return hart::TestRegistry::getInstance().runAll();
103 }
104 while (false);
105
106/// @brief Put it before you test cases to use hart classes without hart:: namespace prefix and explicit `float` template value
107#define HART_DECLARE_ALIASES_FOR_FLOAT using namespace hart::aliases_float
108
109/// @brief Put it before you test cases to use hart classes without hart:: namespace prefix and explicit `double` template value
110#define HART_DECLARE_ALIASES_FOR_DOUBLE using namespace hart::aliases_double
111
112} // namespace hart
#define HART_GENERATE_WITH_TAGS(name, tags)
Declares a generator with tags.
Definition hart.hpp:69
#define HART_TEST_WITH_TAGS(name, tags)
Declares a test case with tags.
Definition hart.hpp:61
#define HART_CONCAT(x, y)
Definition hart.hpp:41
#define HART_UNIQUE_ID(x)
Definition hart.hpp:42
#define HART_CONCAT_IMPL(x, y)
Definition hart.hpp:40
#define HART_ITEM_WITH_TAGS(name, tags, category)
Definition hart.hpp:44