X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=test%2Fd2i_test.c;h=3ce38485bd22137231c89ac57ee0eed2def5cdf6;hp=0413ceb2378c612d81d3a14e5b1be8358ca23fc9;hb=fb82cbfe3da846d61e1d4c6d14bf7f4111cccbb2;hpb=f5864227dced7e214fdcf338d024a7431f22a788 diff --git a/test/d2i_test.c b/test/d2i_test.c index 0413ceb237..3ce38485bd 100644 --- a/test/d2i_test.c +++ b/test/d2i_test.c @@ -1,7 +1,7 @@ /* * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -13,7 +13,6 @@ #include #include "testutil.h" -#include "test_main_custom.h" #include #include @@ -21,7 +20,7 @@ #include #include #include -#include "e_os.h" +#include "internal/nelem.h" static const ASN1_ITEM *item_type; static const char *test_file; @@ -42,7 +41,7 @@ typedef struct { static expected_error_t expected_error = ASN1_UNKNOWN; -static int test_bad_asn1() +static int test_bad_asn1(void) { BIO *bio = NULL; ASN1_VALUE *value = NULL; @@ -68,7 +67,7 @@ static int test_bad_asn1() * performs sanity checks on the input and can reject it before the * decoder is called. */ - len = BIO_read(bio, buf, sizeof buf); + len = BIO_read(bio, buf, sizeof(buf)); if (!TEST_int_ge(len, 0)) goto err; @@ -107,11 +106,13 @@ static int test_bad_asn1() return ret; } +OPT_TEST_DECLARE_USAGE("item_name expected_error test_file.der\n") + /* - * Usage: d2i_test , e.g. + * Usage: d2i_test , e.g. * d2i_test generalname bad_generalname.der */ -int test_main(int argc, char *argv[]) +int setup_tests(void) { const char *test_type_name; const char *expected_error_string; @@ -126,28 +127,24 @@ int test_main(int argc, char *argv[]) {"compare", ASN1_COMPARE} }; - if (!TEST_int_eq(argc, 4)) { - fprintf(stderr, "Usage: d2i_test item_name expected_error file.der\n"); - return 1; - } - - test_type_name = argv[1]; - expected_error_string = argv[2]; - test_file = argv[3]; + if (!TEST_ptr(test_type_name = test_get_argument(0)) + || !TEST_ptr(expected_error_string = test_get_argument(1)) + || !TEST_ptr(test_file = test_get_argument(2))) + return 0; item_type = ASN1_ITEM_lookup(test_type_name); if (item_type == NULL) { - TEST_error("Unknown type %s\n", test_type_name); - fprintf(stderr, "Supported types:\n"); + TEST_error("Unknown type %s", test_type_name); + TEST_note("Supported types:"); for (i = 0;; i++) { const ASN1_ITEM *it = ASN1_ITEM_get(i); if (it == NULL) break; - fprintf(stderr, "\t%s\n", it->sname); + TEST_note("\t%s", it->sname); } - return 1; + return 0; } for (i = 0; i < OSSL_NELEM(expected_errors); i++) { @@ -159,10 +156,9 @@ int test_main(int argc, char *argv[]) if (expected_error == ASN1_UNKNOWN) { TEST_error("Unknown expected error %s\n", expected_error_string); - return 1; + return 0; } ADD_TEST(test_bad_asn1); - - return run_tests(argv[0]); + return 1; }