libarc-validate/arc/validate/test.hxx

80 lines
1.8 KiB
C++
Raw Normal View History

#ifndef arc__validate__test_hxx_
#define arc__validate__test_hxx_
#include <arc/validate/export.hxx>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define ARC_VALIDATE_DEFINE_TEST_3(file, line, name) \
static void test_func_##line(); \
static ::arc::validate::test_t test_##line(file, line, name, test_func_##line); \
static void test_func_##line()
#define ARC_VALIDATE_DEFINE_TEST_2(file, line, name) ARC_VALIDATE_DEFINE_TEST_3(file, line, name)
#ifndef ARC_VALIDATE_UNPREFIXED_MACROS
# define ARC_VALIDATE_DEFINE_TEST(name) ARC_VALIDATE_DEFINE_TEST_2(__FILE__, __LINE__, #name)
#else
# define DEFINE_TEST(name) ARC_VALIDATE_DEFINE_TEST_2(__FILE__, __LINE__, #name)
#endif
namespace arc::validate
{
/// Represents a single test case.
///
class LIBARC_VALIDATE_SYMEXPORT test_t
{
public:
test_t(std::string, int, std::string, std::function<void()>);
test_t(test_t const&) = delete;
test_t(test_t&&) = delete;
~test_t() noexcept;
std::string const&
file() const;
int
line() const;
std::string const&
name() const;
std::function<void()> const&
function() const;
test_t& operator=(test_t const&) = delete;
test_t& operator=(test_t&&) = delete;
static
std::vector<test_t*>
get_tests();
static
std::vector<test_t*>
get_tests(std::set<std::string> const&,
std::set<std::string> const&);
private:
std::string file_;
int line_;
std::string name_;
std::function<void()> function_;
/// Holds a map of all registered tests.
///
static std::map<std::string, test_t*> tests_;
};
} // namespace arc::validate
#endif