aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/tests.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-01-31 11:06:04 -0500
committerJack Lloyd <[email protected]>2019-01-31 11:07:59 -0500
commitf52cde49f5fcf8aa3a72c15c665940c16756a16b (patch)
treeb31eb1030d7c3d1bad779488def4c26cc3e8a4c9 /src/tests/tests.h
parentb508bcf6c9f29319a198ad97975343d5ba3e8516 (diff)
Add a simple Thread_Pool test
And allow registering one-off functions as tests
Diffstat (limited to 'src/tests/tests.h')
-rw-r--r--src/tests/tests.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tests/tests.h b/src/tests/tests.h
index 4bf9fb0db..22651ff8c 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -530,6 +530,38 @@ class Test
#define BOTAN_REGISTER_TEST(type, Test_Class) \
Test::Registration<Test_Class> reg_ ## Test_Class ## _tests(type)
+typedef Test::Result (*test_fn)();
+
+class FnTest : public Test
+ {
+ public:
+ FnTest(test_fn fn) : m_fn(fn) {}
+
+ std::vector<Test::Result> run() override
+ {
+ return {m_fn()};
+ }
+
+ private:
+ test_fn m_fn;
+ };
+
+class FnRegistration
+ {
+ public:
+ FnRegistration(const std::string& name, test_fn fn)
+ {
+ if(Test::global_registry().count(name) != 0)
+ throw Test_Error("Duplicate registration of test '" + name + "'");
+
+ auto maker = [=]() -> Test* { return new FnTest(fn); };
+ Test::global_registry().insert(std::make_pair(name, maker));
+ }
+ };
+
+#define BOTAN_REGISTER_TEST_FN(test_name, fn_name) \
+ FnRegistration reg_ ## fn_name(test_name, fn_name)
+
class VarMap
{
public: