openssl/test/errtest.c
Rich Salz 8908d18cb1 Change ERR_add_error_[v]data to append
The "add error data" functions now append to the current error.
Add a test for this.
Cleanup some of the ERR_put functions.
In the FIPS module, always append "(in the FIPS module)" to any errors.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9181)
2019-06-18 23:21:38 +02:00

52 lines
1.3 KiB
C

/*
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
*
* 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
*/
#include <openssl/opensslconf.h>
#include <openssl/err.h>
#include "testutil.h"
#if defined(OPENSSL_SYS_WINDOWS)
# include <windows.h>
#else
# include <errno.h>
#endif
/* Test that querying the error queue preserves the OS error. */
static int preserves_system_error(void)
{
#if defined(OPENSSL_SYS_WINDOWS)
SetLastError(ERROR_INVALID_FUNCTION);
ERR_get_error();
return TEST_int_eq(GetLastError(), ERROR_INVALID_FUNCTION);
#else
errno = EINVAL;
ERR_get_error();
return TEST_int_eq(errno, EINVAL);
#endif
}
/* Test that calls to ERR_add_error_[v]data append */
static int vdata_appends(void)
{
const char *data;
CRYPTOerr(0, ERR_R_MALLOC_FAILURE);
ERR_add_error_data(1, "hello ");
ERR_add_error_data(1, "world");
ERR_get_error_line_data(NULL, NULL, &data, NULL);
return TEST_str_eq(data, "hello world");
}
int setup_tests(void)
{
ADD_TEST(preserves_system_error);
ADD_TEST(vdata_appends);
return 1;
}