/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Andrew Kaster * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include // intentionally first -- we redefine VERIFY and friends in here #include #include #include #include namespace Test { using TestFunction = Function; class TestCase : public RefCounted { public: TestCase(const String& name, TestFunction&& fn, bool is_benchmark) : m_name(name) , m_function(move(fn)) , m_is_benchmark(is_benchmark) { } bool is_benchmark() const { return m_is_benchmark; } const String& name() const { return m_name; } const TestFunction& func() const { return m_function; } private: String m_name; TestFunction m_function; bool m_is_benchmark; }; // Helper to hide implementation of TestSuite from users void add_test_case_to_suite(const NonnullRefPtr& test_case); } #define __TESTCASE_FUNC(x) __test_##x #define __TESTCASE_TYPE(x) __TestCase_##x #define TEST_CASE(x) \ static void __TESTCASE_FUNC(x)(); \ struct __TESTCASE_TYPE(x) { \ __TESTCASE_TYPE(x) \ () { add_test_case_to_suite(adopt_ref(*new ::Test::TestCase(#x, __TESTCASE_FUNC(x), false))); } \ }; \ static struct __TESTCASE_TYPE(x) __TESTCASE_TYPE(x); \ static void __TESTCASE_FUNC(x)() #define __BENCHMARK_FUNC(x) __benchmark_##x #define __BENCHMARK_TYPE(x) __BenchmarkCase_##x #define BENCHMARK_CASE(x) \ static void __BENCHMARK_FUNC(x)(); \ struct __BENCHMARK_TYPE(x) { \ __BENCHMARK_TYPE(x) \ () { add_test_case_to_suite(adopt_ref(*new ::Test::TestCase(#x, __BENCHMARK_FUNC(x), true))); } \ }; \ static struct __BENCHMARK_TYPE(x) __BENCHMARK_TYPE(x); \ static void __BENCHMARK_FUNC(x)()