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 | // void push_front(const value_type& v); |
12 | |
13 | #include "asan_testing.h" |
14 | #include <deque> |
15 | #include <cassert> |
16 | #include <cstddef> |
17 | |
18 | #include "test_macros.h" |
19 | #include "min_allocator.h" |
20 | |
21 | template <class C> |
22 | C |
23 | make(int size, int start = 0 ) |
24 | { |
25 | const int b = 4096 / sizeof(int); |
26 | int init = 0; |
27 | if (start > 0) |
28 | { |
29 | init = (start+1) / b + ((start+1) % b != 0); |
30 | init *= b; |
31 | --init; |
32 | } |
33 | C c(init, 0); |
34 | for (int i = 0; i < init-start; ++i) |
35 | c.pop_back(); |
36 | for (int i = 0; i < size; ++i) |
37 | c.push_back(i); |
38 | for (int i = 0; i < start; ++i) |
39 | c.pop_front(); |
40 | return c; |
41 | } |
42 | |
43 | template <class C> |
44 | void |
45 | test(C& c1, int x) |
46 | { |
47 | typedef typename C::iterator I; |
48 | std::size_t c1_osize = c1.size(); |
49 | c1.push_front(x); |
50 | assert(c1.size() == c1_osize + 1); |
51 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
52 | I i = c1.begin(); |
53 | assert(*i == x); |
54 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1)); |
55 | ++i; |
56 | for (int j = 0; static_cast<std::size_t>(j) < c1_osize; ++j, ++i) |
57 | assert(*i == j); |
58 | } |
59 | |
60 | template <class C> |
61 | void |
62 | testN(int start, int N) |
63 | { |
64 | C c1 = make<C>(N, start); |
65 | test(c1, -10); |
66 | } |
67 | |
68 | int main(int, char**) |
69 | { |
70 | { |
71 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
72 | const int N = sizeof(rng)/sizeof(rng[0]); |
73 | for (int i = 0; i < N; ++i) |
74 | for (int j = 0; j < N; ++j) |
75 | testN<std::deque<int> >(start: rng[i], N: rng[j]); |
76 | } |
77 | #if TEST_STD_VER >= 11 |
78 | { |
79 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
80 | const int N = sizeof(rng)/sizeof(rng[0]); |
81 | for (int i = 0; i < N; ++i) |
82 | for (int j = 0; j < N; ++j) |
83 | testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); |
84 | } |
85 | { |
86 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
87 | const int N = sizeof(rng)/sizeof(rng[0]); |
88 | for (int i = 0; i < N; ++i) |
89 | for (int j = 0; j < N; ++j) |
90 | testN<std::deque<int, safe_allocator<int>> >(rng[i], rng[j]); |
91 | } |
92 | #endif |
93 | |
94 | return 0; |
95 | } |
96 | |