Specify array sizes
[openssl.git] / test / getsettest.c
1 /*
2  * Copyright 2016 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/bio.h>
12 #include <openssl/crypto.h>
13 #include <openssl/ssl.h>
14
15
16 int main(int argc, char *argv[])
17 {
18     SSL_CTX *ctx = NULL;
19     SSL *con = NULL;
20     BIO *err;
21     int testresult = 0;
22
23     err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
24
25     CRYPTO_set_mem_debug(1);
26     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
27
28     /* Test tlsext_status_type */
29     ctx = SSL_CTX_new(TLS_method());
30
31     if (SSL_CTX_get_tlsext_status_type(ctx) != -1) {
32         printf("Unexpected initial value for "
33                "SSL_CTX_get_tlsext_status_type()\n");
34         goto end;
35     }
36
37     con = SSL_new(ctx);
38
39     if (SSL_get_tlsext_status_type(con) != -1) {
40         printf("Unexpected initial value for SSL_get_tlsext_status_type()\n");
41         goto end;
42     }
43
44     if (!SSL_set_tlsext_status_type(con, TLSEXT_STATUSTYPE_ocsp)) {
45         printf("Unexpected fail for SSL_set_tlsext_status_type()\n");
46         goto end;
47     }
48
49     if (SSL_get_tlsext_status_type(con) != TLSEXT_STATUSTYPE_ocsp) {
50         printf("Unexpected result for SSL_get_tlsext_status_type()\n");
51         goto end;
52     }
53
54     SSL_free(con);
55     con = NULL;
56
57     if (!SSL_CTX_set_tlsext_status_type(ctx, TLSEXT_STATUSTYPE_ocsp)) {
58         printf("Unexpected fail for SSL_CTX_set_tlsext_status_type()\n");
59         goto end;
60     }
61
62     if (SSL_CTX_get_tlsext_status_type(ctx) != TLSEXT_STATUSTYPE_ocsp) {
63         printf("Unexpected result for SSL_CTX_get_tlsext_status_type()\n");
64         goto end;
65     }
66
67     con = SSL_new(ctx);
68
69     if (SSL_get_tlsext_status_type(con) != TLSEXT_STATUSTYPE_ocsp) {
70         printf("Unexpected result for SSL_get_tlsext_status_type() (test 2)\n");
71         goto end;
72     }
73
74     testresult = 1;
75
76  end:
77     SSL_free(con);
78     SSL_CTX_free(ctx);
79
80 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
81     if (CRYPTO_mem_leaks(err) <= 0)
82         testresult = 0;
83 #endif
84     BIO_free(err);
85
86     if (testresult)
87         printf("PASS\n");
88
89     return testresult?0:1;
90 }