X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=test%2Fmdc2_internal_test.c;h=64aa2dc1685204528818938c3be5018f938a1286;hp=7f6a95cf4aa43d887dcaab58a22d098fe495c4bf;hb=1a54618ba6ec09b85f00f5ca12ef275b429ff18a;hpb=97f1e97114822a04a7720b817a789cc9d2553e2b diff --git a/test/mdc2_internal_test.c b/test/mdc2_internal_test.c index 7f6a95cf4a..64aa2dc168 100644 --- a/test/mdc2_internal_test.c +++ b/test/mdc2_internal_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,54 +14,13 @@ #include #include "testutil.h" -#include "e_os.h" +#include "internal/nelem.h" typedef struct { const char *input; 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) -{ - ERR_print_errors_fp(stderr); -} /********************************************************************** * @@ -79,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 (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH, + md, MDC2_DIGEST_LENGTH)) { + TEST_info("mdc2 test %d: unexpected output", idx); + return 0; + } + + return 1; } -int main(int argc, char **argv) +int setup_tests() { - ADD_ALL_TESTS(drive_tests, OSSL_NELEM(tests)); - - return run_tests(argv[0]); + ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests)); + return 1; }