HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
Test Runner

Runs the tests. More...

Classes

struct  CLIConfig
 Holds values set by the user via CLI interface. More...
 
class  AudioTestBuilder< SampleType >
 A DSP host used for building and running tests inside a test case. More...
 
class  TestRegistry
 Runs the test cases. More...
 

Macros

#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 + '\"')
 Fails a test case unconditionally with a text message.
 
#define HART_FAIL_TEST()   throw hart::TestAssertException (std::string ("HART_FAIL_TEST() triggered test fail at line ") + std::to_string (__LINE__))
 Fails a test case unconditionally.
 
#define HART_ASSERT_TRUE(condition)    if (!(condition)) throw hart::TestAssertException (std::string ("HART_ASSERT_TRUE() failed at line ") + std::to_string (__LINE__) + ": \"" #condition "\"");
 Use to check some condition inside a test case. Failing will abort the test runner.
 
#define HART_EXPECT_TRUE(condition)    if (!(condition)) hart::ExpectationFailureMessages::get().emplace_back (std::string ("HART_EXPECT_TRUE() failed at line ") + std::to_string (__LINE__) + ": \"" #condition "\"");
 Use to check some condition inside a test case. Failing will not abort the test runner.
 
#define HART_TEST_WITH_TAGS(name, tags)   HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::test)
 Declares a test case with tags.
 
#define HART_GENERATE_WITH_TAGS(name, tags)   HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::generate)
 Declares a generator with tags.
 
#define HART_TEST(name)   HART_TEST_WITH_TAGS(name, "")
 Declares a test case.
 
#define HART_GENERATE(name)   HART_GENERATE_WITH_TAGS(name, "")
 Declares a generator.
 
#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"); }
 Put it at the beginning of your tese case if it requires a properly set data path.
 
#define HART_RUN_ALL_TESTS(argc, argv)
 Runs all tests or generators.
 

Enumerations

enum class  Save { always , whenFails , never }
 Determines when to save a file. More...
 
enum class  ResetSignal { no , yes }
 Determines whether to reset the Signal in a given context. More...
 

Functions

template<typename DSPType >
AudioTestBuilder< typename std::decay< DSPType >::type::SampleTypePublicAlias > processAudioWith (DSPType &&dsp)
 Call this to start building your test using a DSP object.
 
template<typename DSPType >
AudioTestBuilder< typename DSPType::SampleTypePublicAlias > processAudioWith (std::unique_ptr< DSPType > &&dsp)
 Call this to start building your test using a smart pointer to a DSP object.
 
AudioTestBuilder< floatprocessAudioWith (std::function< float(float)> dspFunction, const std::string &label={})
 Call this to start building your test using a sample-wise function.
 
AudioTestBuilder< floatprocessAudioWith (std::function< void(AudioBuffer< float > &)> dspFunction, const std::string &label={})
 Call this to start building your test using a block-wise in-place function.
 
AudioTestBuilder< floatprocessAudioWith (std::function< void(const AudioBuffer< float > &, AudioBuffer< float > &)> dspFunction, const std::string &label={})
 Call this to start building your test using a block-wise non-replacing function.
 
AudioTestBuilder< doubleprocessAudioWith (std::function< double(double)> dspFunction, const std::string &label={})
 See the description of the float version of this function.
 
AudioTestBuilder< doubleprocessAudioWith (std::function< void(AudioBuffer< double > &)> dspFunction, const std::string &label={})
 See the description of the float version of this function.
 
AudioTestBuilder< doubleprocessAudioWith (std::function< void(const AudioBuffer< double > &, AudioBuffer< double > &)> dspFunction, const std::string &label={})
 See the description of the float version of this function.
 

Detailed Description

Runs the tests.

Macro Definition Documentation

◆ HART_FAIL_TEST_MSG

#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 + '\"')

Fails a test case unconditionally with a text message.

Parameters
messageMessage to be displayed

Definition at line 29 of file hart.hpp.

◆ HART_FAIL_TEST

#define HART_FAIL_TEST ( )    throw hart::TestAssertException (std::string ("HART_FAIL_TEST() triggered test fail at line ") + std::to_string (__LINE__))

Fails a test case unconditionally.

Definition at line 33 of file hart.hpp.

◆ HART_ASSERT_TRUE

#define HART_ASSERT_TRUE (   condition)     if (!(condition)) throw hart::TestAssertException (std::string ("HART_ASSERT_TRUE() failed at line ") + std::to_string (__LINE__) + ": \"" #condition "\"");

Use to check some condition inside a test case. Failing will abort the test runner.

Helpful for free-standing checks (before or after rendering audio)

Parameters
conditionA condition or boolean value to be checked. Will be triggered if it evaluates to false.

Definition at line 39 of file hart.hpp.

◆ HART_EXPECT_TRUE

#define HART_EXPECT_TRUE (   condition)     if (!(condition)) hart::ExpectationFailureMessages::get().emplace_back (std::string ("HART_EXPECT_TRUE() failed at line ") + std::to_string (__LINE__) + ": \"" #condition "\"");

Use to check some condition inside a test case. Failing will not abort the test runner.

Helpful for free-standing checks (before or after rendering audio)

Parameters
conditionA condition or boolean value to be checked. Will be triggered if it evaluates to false.

Definition at line 46 of file hart.hpp.

◆ HART_TEST_WITH_TAGS

#define HART_TEST_WITH_TAGS (   name,
  tags 
)    HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::test)

Declares a test case with tags.

Warning
Tags aren't supported yet
Parameters
nameName for the test case
tagsTags like "[my-tag-1][my-tag-2]"

Definition at line 70 of file hart.hpp.

◆ HART_GENERATE_WITH_TAGS

#define HART_GENERATE_WITH_TAGS (   name,
  tags 
)    HART_ITEM_WITH_TAGS(name, tags, hart::TaskCategory::generate)

Declares a generator with tags.

Pretty much the same as a usual test case, but will be called only if the --run-generators CLI flag is set

Warning
Tags aren't supported yet
Parameters
nameName for the generator
tagsTags like "[my-tag-1][my-tag-2]"

Definition at line 78 of file hart.hpp.

◆ HART_TEST

#define HART_TEST (   name)    HART_TEST_WITH_TAGS(name, "")

Declares a test case.

Parameters
nameName for the test case

Definition at line 83 of file hart.hpp.

◆ HART_GENERATE

#define HART_GENERATE (   name)    HART_GENERATE_WITH_TAGS(name, "")

Declares a generator.

Pretty much the same as a usual test case, but will be called only if the --run-generators CLI flag is set

Parameters
nameName for generator

Definition at line 89 of file hart.hpp.

◆ HART_REQUIRES_DATA_PATH_ARG

#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"); }

Put it at the beginning of your tese case if it requires a properly set data path.

For example, when using relative paths to the wav files. The test will instantly fail is the path is not set.

Definition at line 100 of file hart.hpp.

◆ HART_RUN_ALL_TESTS

#define HART_RUN_ALL_TESTS (   argc,
  argv 
)
Value:
do \
{ \
hart::CLIConfig::getInstance().initCommandLineArgs(); \
CLI11_PARSE (hart::CLIConfig::getInstance().getCLIApp(), argc, argv); \
return hart::TestRegistry::getInstance().runAll(); \
} \
while (false);
static TestRegistry & getInstance()
Gets the singleton instance.
static CLIConfig & getInstance()
Get the singleton instance.

Runs all tests or generators.

Place this macro in your main() function

Definition at line 106 of file hart.hpp.

Enumeration Type Documentation

◆ Save

enum class Save
strong

Determines when to save a file.

Enumerator
always 

File will be saved always, after the test is performed.

whenFails 

File will be saved only when the test has failed.

never 

File will not be saved.

Definition at line 31 of file hart_process_audio.hpp.

◆ ResetSignal

Determines whether to reset the Signal in a given context.

Enumerator
no 

The signal will continue from whatever state it was in.

yes 

The signal's state will be reset.

Definition at line 40 of file hart_process_audio.hpp.

Function Documentation

◆ processAudioWith() [1/8]

template<typename DSPType >
AudioTestBuilder< typename std::decay< DSPType >::type::SampleTypePublicAlias > processAudioWith ( DSPType &&  dsp)

Call this to start building your test using a DSP object.

Parameters
dspInstance of your DSP effect
Returns
AudioTestBuilder instance - you can chain a bunch of test parameters with it.

Definition at line 844 of file hart_process_audio.hpp.

◆ processAudioWith() [2/8]

template<typename DSPType >
AudioTestBuilder< typename DSPType::SampleTypePublicAlias > processAudioWith ( std::unique_ptr< DSPType > &&  dsp)

Call this to start building your test using a smart pointer to a DSP object.

Call this for DSP objects that do not support moving or copying

Parameters
dspInstance of your DSP effect wrapped in a smart pointer
Returns
AudioTestBuilder instance - you can chain a bunch of test parameters with it.

Definition at line 855 of file hart_process_audio.hpp.

◆ processAudioWith() [3/8]

AudioTestBuilder< float > processAudioWith ( std::function< float(float)>  dspFunction,
const std::string &  label = {} 
)
inline

Call this to start building your test using a sample-wise function.

This overload allows defining a DSP processor using a function or lambda that operates on individual samples.

Function signature
float (float value)
A DSP processor defined by a user-provided function.

The function is applied independently to each sample.

For more details, see DSPFunction documentation, as it merely forwards the arguments to its constructor.

Note
If your DSP requires access to sample rate or channel context, consider using one of the block-wise overloads instead.
Parameters
dspFunctionFunction to process each sample.
labelOptional human-readable label for error reporting.
Returns
AudioTestBuilder instance - you can chain a bunch of test parameters with it.

Definition at line 886 of file hart_process_audio.hpp.

◆ processAudioWith() [4/8]

AudioTestBuilder< float > processAudioWith ( std::function< void(AudioBuffer< float > &)>  dspFunction,
const std::string &  label = {} 
)
inline

Call this to start building your test using a block-wise in-place function.

The provided function processes audio in-place. The buffer is pre-filled with input data and must be modified directly.

Function signature
Buffer invariants
The function must not change:
  • Number of channels
  • Number of frames
  • Sample rate

For more details, see DSPFunction documentation, as it merely forwards the arguments to its constructor.

Parameters
dspFunctionFunction that processes the buffer in-place.
labelOptional human-readable label for error reporting.
Returns
AudioTestBuilder instance - you can chain a bunch of test parameters with it.

Definition at line 914 of file hart_process_audio.hpp.

◆ processAudioWith() [5/8]

AudioTestBuilder< float > processAudioWith ( std::function< void(const AudioBuffer< float > &, AudioBuffer< float > &)>  dspFunction,
const std::string &  label = {} 
)
inline

Call this to start building your test using a block-wise non-replacing function.

This overload provides separate input and output buffers for processing.

Function signature
Buffer invariants
The function must not change:
  • Number of channels
  • Number of frames
  • Sample rate

For more details, see DSPFunction documentation, as it merely forwards the arguments to its constructor.

Parameters
dspFunctionFunction that generates output from input.
labelOptional human-readable label for error reporting.
Returns
AudioTestBuilder instance - you can chain a bunch of test parameters with it.

Definition at line 941 of file hart_process_audio.hpp.

◆ processAudioWith() [6/8]

AudioTestBuilder< double > processAudioWith ( std::function< double(double)>  dspFunction,
const std::string &  label = {} 
)
inline

See the description of the float version of this function.

Definition at line 955 of file hart_process_audio.hpp.

◆ processAudioWith() [7/8]

AudioTestBuilder< double > processAudioWith ( std::function< void(AudioBuffer< double > &)>  dspFunction,
const std::string &  label = {} 
)
inline

See the description of the float version of this function.

Definition at line 962 of file hart_process_audio.hpp.

◆ processAudioWith() [8/8]

AudioTestBuilder< double > processAudioWith ( std::function< void(const AudioBuffer< double > &, AudioBuffer< double > &)>  dspFunction,
const std::string &  label = {} 
)
inline

See the description of the float version of this function.

Definition at line 969 of file hart_process_audio.hpp.