2 * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <openssl/bio.h>
13 static int test_bio_meth(void)
16 BIO_METHOD *meth1 = NULL, *meth2 = NULL, *meth3 = NULL;
17 BIO *membio = NULL, *bio1 = NULL, *bio2 = NULL, *bio3 = NULL;
19 id = BIO_get_new_index();
20 if (!TEST_int_eq(id, BIO_TYPE_START + 1))
23 if (!TEST_ptr(meth1 = BIO_meth_new(id, "Method1"))
24 || !TEST_ptr(meth2 = BIO_meth_new(BIO_TYPE_NONE, "Method2"))
25 || !TEST_ptr(meth3 = BIO_meth_new(BIO_TYPE_NONE|BIO_TYPE_FILTER, "Method3"))
26 || !TEST_ptr(bio1 = BIO_new(meth1))
27 || !TEST_ptr(bio2 = BIO_new(meth2))
28 || !TEST_ptr(bio3 = BIO_new(meth3))
29 || !TEST_ptr(membio = BIO_new(BIO_s_mem())))
32 BIO_set_next(bio3, bio2);
33 BIO_set_next(bio2, bio1);
34 BIO_set_next(bio1, membio);
36 /* Check that we get an error if we exhaust BIO_get_new_index() */
37 for (i = id + 1; i <= BIO_TYPE_MASK; ++i) {
38 if (!TEST_int_eq(BIO_get_new_index(), i))
41 if (!TEST_int_eq(BIO_get_new_index(), -1))
44 /* test searching works */
45 if (!TEST_ptr_eq(BIO_find_type(bio3, BIO_TYPE_MEM), membio)
46 || !TEST_ptr_eq(BIO_find_type(bio3, id), bio1))
49 /* Check searching for BIO_TYPE_NONE returns NULL */
50 if (!TEST_ptr_null(BIO_find_type(bio3, BIO_TYPE_NONE)))
52 /* Check searching for BIO_TYPE_NONE + BIO_TYPE_FILTER works */
53 if (!TEST_ptr_eq(BIO_find_type(bio3, BIO_TYPE_FILTER), bio3))
69 ADD_TEST(test_bio_meth);