| 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_back(const value_type& v); |
| 12 | // void pop_back(); |
| 13 | // void pop_front(); |
| 14 | |
| 15 | #include "asan_testing.h" |
| 16 | #include <deque> |
| 17 | #include <cassert> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | #include "min_allocator.h" |
| 21 | |
| 22 | template <class C> |
| 23 | C make(int size, int start = 0) { |
| 24 | const int b = 4096 / sizeof(int); |
| 25 | int init = 0; |
| 26 | if (start > 0) { |
| 27 | init = (start + 1) / b + ((start + 1) % b != 0); |
| 28 | init *= b; |
| 29 | --init; |
| 30 | } |
| 31 | C c(init, 0); |
| 32 | for (int i = 0; i < init - start; ++i) |
| 33 | c.pop_back(); |
| 34 | for (int i = 0; i < size; ++i) |
| 35 | c.push_back(i); |
| 36 | for (int i = 0; i < start; ++i) |
| 37 | c.pop_front(); |
| 38 | return c; |
| 39 | } |
| 40 | |
| 41 | template <class C> |
| 42 | void test(int size) { |
| 43 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; |
| 44 | const int N = sizeof(rng) / sizeof(rng[0]); |
| 45 | for (int j = 0; j < N; ++j) { |
| 46 | C c = make<C>(size, rng[j]); |
| 47 | typename C::const_iterator it = c.begin(); |
| 48 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
| 49 | for (int i = 0; i < size; ++i, ++it) |
| 50 | assert(*it == i); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int main(int, char**) { |
| 55 | { |
| 56 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; |
| 57 | const int N = sizeof(rng) / sizeof(rng[0]); |
| 58 | for (int j = 0; j < N; ++j) |
| 59 | test<std::deque<int> >(size: rng[j]); |
| 60 | } |
| 61 | #if TEST_STD_VER >= 11 |
| 62 | { |
| 63 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; |
| 64 | const int N = sizeof(rng) / sizeof(rng[0]); |
| 65 | for (int j = 0; j < N; ++j) |
| 66 | test<std::deque<int, min_allocator<int>> >(rng[j]); |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |