summaryrefslogtreecommitdiffstats
path: root/test/mdc2_internal_test.c
diff options
context:
space:
mode:
authorEmilia Kasper <emilia@openssl.org>2016-11-04 16:06:12 +0100
committerEmilia Kasper <emilia@openssl.org>2016-11-07 16:55:16 +0100
commitd836d71b2da026b4ed9a2233657b2289ab8e4be0 (patch)
treec4c9b9e2112eaea750871d66914868ea8585a6da /test/mdc2_internal_test.c
parentAdd a test for the wrong version number in a record (diff)
downloadopenssl-d836d71b2da026b4ed9a2233657b2289ab8e4be0.tar.xz
openssl-d836d71b2da026b4ed9a2233657b2289ab8e4be0.zip
Simplify tests part 2
1) Remove some unnecessary fixtures 2) Add EXECUTE_TEST_NO_TEARDOWN shorthand when a fixture exists but has no teardown. 3) Fix return values in ct_test.c (introduced by an earlier refactoring, oops) Note that for parameterized tests, the index (test vector) usually holds all the customization, and there should be no need for a separate test fixture. The CTS test is an exception: it demonstrates how to combine customization with parameterization. Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'test/mdc2_internal_test.c')
-rw-r--r--test/mdc2_internal_test.c69
1 files changed, 23 insertions, 46 deletions
diff --git a/test/mdc2_internal_test.c b/test/mdc2_internal_test.c
index 3ed52de5ac..3353507c63 100644
--- a/test/mdc2_internal_test.c
+++ b/test/mdc2_internal_test.c
@@ -21,46 +21,6 @@ typedef struct {
const unsigned char expected[MDC2_DIGEST_LENGTH];
} TESTDATA;
-typedef struct {
- const char *case_name;
- int num;
- const TESTDATA *data;
-} SIMPLE_FIXTURE;
-
-/**********************************************************************
- *
- * Test of mdc2 internal functions
- *
- ***/
-
-static SIMPLE_FIXTURE setup_mdc2(const char *const test_case_name)
-{
- SIMPLE_FIXTURE fixture;
- fixture.case_name = test_case_name;
- return fixture;
-}
-
-static int execute_mdc2(SIMPLE_FIXTURE fixture)
-{
- unsigned char md[MDC2_DIGEST_LENGTH];
- MDC2_CTX c;
-
- MDC2_Init(&c);
- MDC2_Update(&c, (const unsigned char *)fixture.data->input,
- strlen(fixture.data->input));
- MDC2_Final(&(md[0]), &c);
-
- if (memcmp(fixture.data->expected, md, MDC2_DIGEST_LENGTH)) {
- fprintf(stderr, "mdc2 test %d: unexpected output\n", fixture.num);
- return 0;
- }
-
- return 1;
-}
-
-static void teardown_mdc2(SIMPLE_FIXTURE fixture)
-{
-}
/**********************************************************************
*
@@ -78,17 +38,34 @@ static TESTDATA tests[] = {
}
};
-static int drive_tests(int idx)
+/**********************************************************************
+ *
+ * Test of mdc2 internal functions
+ *
+ ***/
+
+static int test_mdc2(int idx)
{
- SETUP_TEST_FIXTURE(SIMPLE_FIXTURE, setup_mdc2);
- fixture.num = idx;
- fixture.data = &tests[idx];
- EXECUTE_TEST(execute_mdc2, teardown_mdc2);
+ unsigned char md[MDC2_DIGEST_LENGTH];
+ MDC2_CTX c;
+ const TESTDATA testdata = tests[idx];
+
+ MDC2_Init(&c);
+ MDC2_Update(&c, (const unsigned char *)testdata.input,
+ strlen(testdata.input));
+ MDC2_Final(&(md[0]), &c);
+
+ if (memcmp(testdata.expected, md, MDC2_DIGEST_LENGTH)) {
+ fprintf(stderr, "mdc2 test %d: unexpected output\n", idx);
+ return 0;
+ }
+
+ return 1;
}
int main(int argc, char **argv)
{
- ADD_ALL_TESTS(drive_tests, OSSL_NELEM(tests));
+ ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
return run_tests(argv[0]);
}