1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <deque> |
10 | |
11 | // explicit deque(size_type n); |
12 | |
13 | #include "asan_testing.h" |
14 | #include <deque> |
15 | #include <cassert> |
16 | #include <cstddef> |
17 | |
18 | #include "test_macros.h" |
19 | #include "test_allocator.h" |
20 | #include "DefaultOnly.h" |
21 | #include "min_allocator.h" |
22 | |
23 | template <class T, class Allocator> |
24 | void |
25 | test2(unsigned n) |
26 | { |
27 | #if TEST_STD_VER > 11 |
28 | typedef std::deque<T, Allocator> C; |
29 | typedef typename C::const_iterator const_iterator; |
30 | assert(DefaultOnly::count == 0); |
31 | { |
32 | C d(n, Allocator()); |
33 | assert(static_cast<unsigned>(DefaultOnly::count) == n); |
34 | assert(d.size() == n); |
35 | assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); |
36 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d)); |
37 | for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) |
38 | assert(*i == T()); |
39 | } |
40 | assert(DefaultOnly::count == 0); |
41 | #else |
42 | ((void)n); |
43 | #endif |
44 | } |
45 | |
46 | template <class T, class Allocator> |
47 | void |
48 | test1(unsigned n) |
49 | { |
50 | typedef std::deque<T, Allocator> C; |
51 | typedef typename C::const_iterator const_iterator; |
52 | assert(DefaultOnly::count == 0); |
53 | { |
54 | C d(n); |
55 | assert(static_cast<unsigned>(DefaultOnly::count) == n); |
56 | assert(d.size() == n); |
57 | assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); |
58 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d)); |
59 | #if TEST_STD_VER >= 11 |
60 | for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) |
61 | assert(*i == T()); |
62 | #endif |
63 | } |
64 | assert(DefaultOnly::count == 0); |
65 | } |
66 | |
67 | template <class T, class Allocator> |
68 | void |
69 | test3(unsigned n, Allocator const &alloc = Allocator()) |
70 | { |
71 | #if TEST_STD_VER > 11 |
72 | typedef std::deque<T, Allocator> C; |
73 | { |
74 | C d(n, alloc); |
75 | assert(d.size() == n); |
76 | assert(d.get_allocator() == alloc); |
77 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d)); |
78 | } |
79 | #else |
80 | ((void)n); |
81 | ((void)alloc); |
82 | #endif |
83 | } |
84 | |
85 | template <class T, class Allocator> |
86 | void |
87 | test(unsigned n) |
88 | { |
89 | test1<T, Allocator> ( n ); |
90 | test2<T, Allocator> ( n ); |
91 | } |
92 | |
93 | int main(int, char**) |
94 | { |
95 | test<DefaultOnly, std::allocator<DefaultOnly> >(0); |
96 | test<DefaultOnly, std::allocator<DefaultOnly> >(1); |
97 | test<DefaultOnly, std::allocator<DefaultOnly> >(10); |
98 | test<DefaultOnly, std::allocator<DefaultOnly> >(1023); |
99 | test<DefaultOnly, std::allocator<DefaultOnly> >(1024); |
100 | test<DefaultOnly, std::allocator<DefaultOnly> >(1025); |
101 | test<DefaultOnly, std::allocator<DefaultOnly> >(2047); |
102 | test<DefaultOnly, std::allocator<DefaultOnly> >(2048); |
103 | test<DefaultOnly, std::allocator<DefaultOnly> >(2049); |
104 | test<DefaultOnly, std::allocator<DefaultOnly> >(4095); |
105 | test<DefaultOnly, std::allocator<DefaultOnly> >(4096); |
106 | test<DefaultOnly, std::allocator<DefaultOnly> >(4097); |
107 | |
108 | LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095)); |
109 | |
110 | #if TEST_STD_VER >= 11 |
111 | test<DefaultOnly, min_allocator<DefaultOnly> >(4095); |
112 | #endif |
113 | |
114 | #if TEST_STD_VER > 11 |
115 | test3<DefaultOnly, std::allocator<DefaultOnly>> (1023); |
116 | test3<int, std::allocator<int>>(1); |
117 | test3<int, min_allocator<int>> (3); |
118 | #endif |
119 | |
120 | |
121 | return 0; |
122 | } |
123 | |