summaryrefslogtreecommitdiffstats
path: root/test/testutil.h
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2017-08-04 10:49:38 +1000
committerPauli <paul.dale@oracle.com>2017-08-07 08:57:05 +1000
commit99801878c09404e45d8176739d3a555c41b77d0b (patch)
tree17849c441cb202056cfc94d91377878400c7feed /test/testutil.h
parent5f8dd0f849d3bb87b2224715f8880716f39e9b0a (diff)
Change SETUP_TEST_FIXTURE so that the fixture structure is passed by
reference not by value. This allows an error return from the setup function. Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4083)
Diffstat (limited to 'test/testutil.h')
-rw-r--r--test/testutil.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/test/testutil.h b/test/testutil.h
index 399f521a4e..f779fd5305 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -65,12 +65,13 @@
* SETUP_TEST_FIXTURE will call set_up() to create a new TEST_FIXTURE_TYPE
* object called "fixture". It will also allocate the "result" variable used
* by EXECUTE_TEST. set_up() should take a const char* specifying the test
- * case name and return a TEST_FIXTURE_TYPE by value.
+ * case name and return a TEST_FIXTURE_TYPE by reference.
*
- * EXECUTE_TEST will pass fixture to execute_func() by value, call
+ * EXECUTE_TEST will pass fixture to execute_func() by reference, call
* tear_down(), and return the result of execute_func(). execute_func() should
- * take a TEST_FIXTURE_TYPE by value and return 1 on success and 0 on
- * failure.
+ * take a TEST_FIXTURE_TYPE by reference and return 1 on success and 0 on
+ * failure. The tear_down function is responsible for deallocation of the
+ * result variable, if required.
*
* Unit tests can define their own SETUP_TEST_FIXTURE and EXECUTE_TEST
* variations like so:
@@ -91,13 +92,14 @@
* }
*/
# define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\
- TEST_FIXTURE_TYPE fixture = set_up(TEST_CASE_NAME); \
+ TEST_FIXTURE_TYPE *fixture = set_up(TEST_CASE_NAME); \
int result = 0
# define EXECUTE_TEST(execute_func, tear_down)\
+ if (fixture != NULL) {\
result = execute_func(fixture);\
tear_down(fixture);\
- return result
+ }
/*
* TEST_CASE_NAME is defined as the name of the test case function where