aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-02-05 10:27:10 -0500
committerJack Lloyd <[email protected]>2019-02-05 10:27:10 -0500
commit11d30b5d9f40b196458c2aab835df0e9dacd508d (patch)
treeb0391d825137cf57efc9ace45fd9a1a4b0f77b30 /src/tests
parentb17e60cfa93a514ebb58dfc6138bc41f3000293d (diff)
Clean up test registration a bit
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/tests.cpp10
-rw-r--r--src/tests/tests.h45
2 files changed, 31 insertions, 24 deletions
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 6b44bccd9..537c27b3e 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -479,6 +479,16 @@ std::map<std::string, std::function<Test* ()>>& Test::global_registry()
}
//static
+void Test::register_test(const std::string& name,
+ std::function<Test* ()> maker_fn)
+ {
+ if(Test::global_registry().count(name) != 0)
+ throw Test_Error("Duplicate registration of test '" + name + "'");
+
+ Test::global_registry().insert(std::make_pair(name, maker_fn));
+ }
+
+//static
uint64_t Test::timestamp()
{
auto now = std::chrono::high_resolution_clock::now().time_since_epoch();
diff --git a/src/tests/tests.h b/src/tests/tests.h
index 22651ff8c..267026f35 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -446,19 +446,8 @@ class Test
virtual std::vector<std::string> possible_providers(const std::string&);
- template<typename Test_Class>
- class Registration
- {
- public:
- Registration(const std::string& name)
- {
- if(Test::global_registry().count(name) != 0)
- throw Test_Error("Duplicate registration of test '" + name + "'");
-
- auto maker = []() -> Test* { return new Test_Class; };
- Test::global_registry().insert(std::make_pair(name, maker));
- }
- };
+ static void register_test(const std::string& name,
+ std::function<Test* ()> maker_fn);
static std::map<std::string, std::function<Test* ()>>& global_registry();
@@ -527,8 +516,19 @@ class Test
/*
* Register the test with the runner
*/
-#define BOTAN_REGISTER_TEST(type, Test_Class) \
- Test::Registration<Test_Class> reg_ ## Test_Class ## _tests(type)
+template<typename Test_Class>
+class TestClassRegistration
+ {
+ public:
+ TestClassRegistration(const std::string& name)
+ {
+ auto test_maker = []() -> Test* { return new Test_Class; };
+ Test::register_test(name, test_maker);
+ }
+ };
+
+#define BOTAN_REGISTER_TEST(name, Test_Class) \
+ TestClassRegistration<Test_Class> reg_ ## Test_Class ## _tests(name)
typedef Test::Result (*test_fn)();
@@ -546,21 +546,18 @@ class FnTest : public Test
test_fn m_fn;
};
-class FnRegistration
+class TestFnRegistration
{
public:
- FnRegistration(const std::string& name, test_fn fn)
+ TestFnRegistration(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));
+ auto test_maker = [=]() -> Test* { return new FnTest(fn); };
+ Test::register_test(name, test_maker);
}
};
-#define BOTAN_REGISTER_TEST_FN(test_name, fn_name) \
- FnRegistration reg_ ## fn_name(test_name, fn_name)
+#define BOTAN_REGISTER_TEST_FN(name, fn_name) \
+ TestFnRegistration reg_ ## fn_name(name, fn_name)
class VarMap
{