errtest.c 944 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/opensslconf.h>
  10. #include <openssl/err.h>
  11. #include "testutil.h"
  12. #if defined(OPENSSL_SYS_WINDOWS)
  13. # include <windows.h>
  14. #else
  15. # include <errno.h>
  16. #endif
  17. /* Test that querying the error queue preserves the OS error. */
  18. static int preserves_system_error(void)
  19. {
  20. #if defined(OPENSSL_SYS_WINDOWS)
  21. SetLastError(ERROR_INVALID_FUNCTION);
  22. ERR_get_error();
  23. return TEST_int_eq(GetLastError(), ERROR_INVALID_FUNCTION);
  24. #else
  25. errno = EINVAL;
  26. ERR_get_error();
  27. return TEST_int_eq(errno, EINVAL);
  28. #endif
  29. }
  30. int setup_tests(void)
  31. {
  32. ADD_TEST(preserves_system_error);
  33. return 1;
  34. }