2 * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include <openssl/bio.h>
16 static int my_param_count;
17 static BIO *my_param_b[MAXCOUNT];
18 static int my_param_oper[MAXCOUNT];
19 static const char *my_param_argp[MAXCOUNT];
20 static int my_param_argi[MAXCOUNT];
21 static long my_param_argl[MAXCOUNT];
22 static long my_param_ret[MAXCOUNT];
24 static long my_bio_callback(BIO *b, int oper, const char *argp, int argi,
27 if (my_param_count >= MAXCOUNT)
29 my_param_b[my_param_count] = b;
30 my_param_oper[my_param_count] = oper;
31 my_param_argp[my_param_count] = argp;
32 my_param_argi[my_param_count] = argi;
33 my_param_argl[my_param_count] = argl;
34 my_param_ret[my_param_count] = ret;
39 static int test_bio_callback(void)
45 char *test2 = "hello";
49 bio = BIO_new(BIO_s_mem());
53 BIO_set_callback(bio, my_bio_callback);
54 i = BIO_write(bio, test1, 4);
55 if (!TEST_int_eq(i, 4)
56 || !TEST_int_eq(my_param_count, 2)
57 || !TEST_ptr_eq(my_param_b[0], bio)
58 || !TEST_int_eq(my_param_oper[0], BIO_CB_WRITE)
59 || !TEST_ptr_eq(my_param_argp[0], test1)
60 || !TEST_int_eq(my_param_argi[0], 4)
61 || !TEST_long_eq(my_param_argl[0], 0L)
62 || !TEST_long_eq(my_param_ret[0], 1L)
63 || !TEST_ptr_eq(my_param_b[1], bio)
64 || !TEST_int_eq(my_param_oper[1], BIO_CB_WRITE | BIO_CB_RETURN)
65 || !TEST_ptr_eq(my_param_argp[1], test1)
66 || !TEST_int_eq(my_param_argi[1], 4)
67 || !TEST_long_eq(my_param_argl[1], 0L)
68 || !TEST_long_eq(my_param_ret[1], 4L))
71 i = BIO_puts(bio, test2);
72 if (!TEST_int_eq(i, 5)
73 || !TEST_int_eq(my_param_count, 4)
74 || !TEST_ptr_eq(my_param_b[2], bio)
75 || !TEST_int_eq(my_param_oper[2], BIO_CB_PUTS)
76 || !TEST_ptr_eq(my_param_argp[2], test2)
77 || !TEST_int_eq(my_param_argi[2], 0)
78 || !TEST_long_eq(my_param_argl[2], 0L)
79 || !TEST_long_eq(my_param_ret[2], 1L)
80 || !TEST_ptr_eq(my_param_b[3], bio)
81 || !TEST_int_eq(my_param_oper[3], BIO_CB_PUTS | BIO_CB_RETURN)
82 || !TEST_ptr_eq(my_param_argp[3], test2)
83 || !TEST_int_eq(my_param_argi[3], 0)
84 || !TEST_long_eq(my_param_argl[3], 0L)
85 || !TEST_long_eq(my_param_ret[3], 5L))
90 if (!TEST_int_eq(i, 1)
91 || !TEST_int_eq(my_param_count, 5)
92 || !TEST_ptr_eq(my_param_b[4], bio)
93 || !TEST_int_eq(my_param_oper[4], BIO_CB_FREE)
94 || !TEST_ptr_eq(my_param_argp[4], NULL)
95 || !TEST_int_eq(my_param_argi[4], 0)
96 || !TEST_long_eq(my_param_argl[4], 0L)
97 || !TEST_long_eq(my_param_ret[4], 1L))
107 /* This helps finding memory leaks with ASAN */
108 memset(my_param_b, 0, sizeof(my_param_b));
109 memset(my_param_argp, 0, sizeof(my_param_argp));
113 int setup_tests(void)
115 ADD_TEST(test_bio_callback);