1 /* Shared definitions for dynarray tests.
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
27 #define DYNARRAY_STRUCT dynarray_int
28 #define DYNARRAY_ELEMENT int
29 #define DYNARRAY_PREFIX dynarray_int_
30 #define DYNARRAY_FINAL_TYPE struct int_array
31 #include <malloc/dynarray-skeleton.c>
39 #define DYNARRAY_STRUCT dynarray_str
40 #define DYNARRAY_ELEMENT char *
41 #define DYNARRAY_ELEMENT_FREE(ptr) free (*ptr)
42 #define DYNARRAY_PREFIX dynarray_str_
43 #define DYNARRAY_FINAL_TYPE struct str_array
44 #include <malloc/dynarray-skeleton.c>
46 /* Check that *DYN is equivalent to its initial state. */
47 #define CHECK_INIT_STATE(type, dyn) \
49 TEST_VERIFY_EXIT (!dynarray_##type##_has_failed (dyn)); \
50 TEST_VERIFY_EXIT (dynarray_##type##_size (dyn) == 0); \
51 TEST_VERIFY_EXIT ((dyn)->dynarray_header.array \
53 TEST_VERIFY_EXIT ((dyn)->dynarray_header.allocated > 0); \
57 /* Check that *DYN behaves as if it is in its initial state. */
58 #define CHECK_EMPTY(type, dyn) \
60 CHECK_INIT_STATE (type, (dyn)); \
61 dynarray_##type##_free (dyn); \
62 CHECK_INIT_STATE (type, (dyn)); \
63 dynarray_##type##_clear (dyn); \
64 CHECK_INIT_STATE (type, (dyn)); \
65 dynarray_##type##_remove_last (dyn); \
66 CHECK_INIT_STATE (type, (dyn)); \
67 dynarray_##type##_mark_failed (dyn); \
68 TEST_VERIFY_EXIT (dynarray_##type##_has_failed (dyn)); \
69 dynarray_##type##_clear (dyn); \
70 TEST_VERIFY_EXIT (dynarray_##type##_has_failed (dyn)); \
71 dynarray_##type##_remove_last (dyn); \
72 TEST_VERIFY_EXIT (dynarray_##type##_has_failed (dyn)); \
73 TEST_VERIFY_EXIT (dynarray_##type##_emplace (dyn) == NULL); \
74 dynarray_##type##_free (dyn); \
75 CHECK_INIT_STATE (type, (dyn)); \
76 /* These functions should not assert. */ \
77 dynarray_##type##_begin (dyn); \
78 dynarray_##type##_end (dyn); \