diff options
author | Pauli <paul.dale@oracle.com> | 2017-06-19 11:21:22 +1000 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2017-06-19 22:37:16 -0400 |
commit | 8fe3127cda7ee89e169184eeeaaca5eebcf8664e (patch) | |
tree | 689fb82417454702cde2b2f03feeb76123fd497e /test/x509aux.c | |
parent | f39a5501ce69cab0c7282f5dcbf2b80d8ee259f2 (diff) |
Update tests to avoid printf to stdout/stderr when running as test cases.
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3710)
Diffstat (limited to 'test/x509aux.c')
-rw-r--r-- | test/x509aux.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/test/x509aux.c b/test/x509aux.c index 44a9db1829..024bfc9004 100644 --- a/test/x509aux.c +++ b/test/x509aux.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 licenses, (the "License"); * you may not use this file except in compliance with the License. @@ -40,27 +40,27 @@ static int test_certs(int num) for (count = 0; !err && PEM_read_bio(fp, &name, &header, &data, &len); - ++count) { + ++count) { int trusted = strcmp(name, PEM_STRING_X509_TRUSTED) == 0; d2i_X509_t d2i = trusted ? d2i_X509_AUX : d2i_X509; i2d_X509_t i2d = trusted ? i2d_X509_AUX : i2d_X509; X509 *cert = NULL; - const unsigned char *p = data; + const unsigned char *p = data; unsigned char *buf = NULL; unsigned char *bufp; long enclen; - if (!trusted + if (!trusted && strcmp(name, PEM_STRING_X509) != 0 - && strcmp(name, PEM_STRING_X509_OLD) != 0) { - fprintf(stderr, "unexpected PEM object: %s\n", name); + && strcmp(name, PEM_STRING_X509_OLD) != 0) { + TEST_error("unexpected PEM object: %s", name); err = 1; - goto next; + goto next; } cert = d2i(NULL, &p, len); if (cert == NULL || (p - data) != len) { - fprintf(stderr, "error parsing input %s\n", name); + TEST_error("error parsing input %s", name); err = 1; goto next; } @@ -68,33 +68,31 @@ static int test_certs(int num) /* Test traditional 2-pass encoding into caller allocated buffer */ enclen = i2d(cert, NULL); if (len != enclen) { - fprintf(stderr, "encoded length %ld of %s != input length %ld\n", - enclen, name, len); + TEST_error("encoded length %ld of %s != input length %ld", + enclen, name, len); err = 1; goto next; } if ((buf = bufp = OPENSSL_malloc(len)) == NULL) { - perror("malloc"); + TEST_perror("malloc"); err = 1; goto next; } enclen = i2d(cert, &bufp); if (len != enclen) { - fprintf(stderr, "encoded length %ld of %s != input length %ld\n", - enclen, name, len); + TEST_error("encoded length %ld of %s != input length %ld", + enclen, name, len); err = 1; goto next; } enclen = (long) (bufp - buf); if (enclen != len) { - fprintf(stderr, "unexpected buffer position after encoding %s\n", - name); + TEST_error("unexpected buffer position after encoding %s", name); err = 1; goto next; } if (memcmp(buf, data, len) != 0) { - fprintf(stderr, "encoded content of %s does not match input\n", - name); + TEST_error("encoded content of %s does not match input", name); err = 1; goto next; } @@ -104,14 +102,13 @@ static int test_certs(int num) /* Test 1-pass encoding into library allocated buffer */ enclen = i2d(cert, &buf); if (len != enclen) { - fprintf(stderr, "encoded length %ld of %s != input length %ld\n", - enclen, name, len); + TEST_error("encoded length %ld of %s != input length %ld", + enclen, name, len); err = 1; goto next; } if (memcmp(buf, data, len) != 0) { - fprintf(stderr, "encoded content of %s does not match input\n", - name); + TEST_error("encoded content of %s does not match input", name); err = 1; goto next; } @@ -124,27 +121,27 @@ static int test_certs(int num) /* Test 1-pass encoding into library allocated buffer */ enclen = i2d(cert, &buf); if (enclen > len) { - fprintf(stderr, "encoded length %ld of %s > input length %ld\n", - enclen, name, len); + TEST_error("encoded length %ld of %s > input length %ld", + enclen, name, len); err = 1; goto next; } if (memcmp(buf, data, enclen) != 0) { - fprintf(stderr, "encoded cert content does not match input\n"); + TEST_error("encoded cert content does not match input"); err = 1; goto next; } } - /* - * If any of these were null, PEM_read() would have failed. - */ + /* + * If any of these were null, PEM_read() would have failed. + */ next: X509_free(cert); OPENSSL_free(buf); - OPENSSL_free(name); - OPENSSL_free(header); - OPENSSL_free(data); + OPENSSL_free(name); + OPENSSL_free(header); + OPENSSL_free(data); } BIO_free(fp); |