Home | History | Annotate | Line # | Download | only in test
errtest.c revision 1.1.1.1.2.3
      1 /*
      2  * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
      3  *
      4  * Licensed under the OpenSSL license (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 
     10 #include <openssl/opensslconf.h>
     11 #include <openssl/err.h>
     12 
     13 #include "testutil.h"
     14 
     15 #if defined(OPENSSL_SYS_WINDOWS)
     16 # include <windows.h>
     17 #else
     18 # include <errno.h>
     19 #endif
     20 
     21 /* Test that querying the error queue preserves the OS error. */
     22 static int preserves_system_error(void)
     23 {
     24 #if defined(OPENSSL_SYS_WINDOWS)
     25     SetLastError(ERROR_INVALID_FUNCTION);
     26     ERR_get_error();
     27     return TEST_int_eq(GetLastError(), ERROR_INVALID_FUNCTION);
     28 #else
     29     errno = EINVAL;
     30     ERR_get_error();
     31     return TEST_int_eq(errno, EINVAL);
     32 #endif
     33 }
     34 
     35 int setup_tests(void)
     36 {
     37     ADD_TEST(preserves_system_error);
     38     return 1;
     39 }
     40