| 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 assign(size_type n, 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 "test_iterators.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(C& c1, int size, int v) { |
| 43 | typedef typename C::const_iterator CI; |
| 44 | c1.assign(size, v); |
| 45 | assert(c1.size() == static_cast<std::size_t>(size)); |
| 46 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
| 47 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1)); |
| 48 | for (CI i = c1.begin(); i != c1.end(); ++i) |
| 49 | assert(*i == v); |
| 50 | } |
| 51 | |
| 52 | template <class C> |
| 53 | void testN(int start, int N, int M) { |
| 54 | C c1 = make<C>(N, start); |
| 55 | test(c1, M, -10); |
| 56 | } |
| 57 | |
| 58 | int main(int, char**) { |
| 59 | { |
| 60 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
| 61 | const int N = sizeof(rng) / sizeof(rng[0]); |
| 62 | for (int i = 0; i < N; ++i) |
| 63 | for (int j = 0; j < N; ++j) |
| 64 | for (int k = 0; k < N; ++k) |
| 65 | testN<std::deque<int> >(start: rng[i], N: rng[j], M: rng[k]); |
| 66 | } |
| 67 | #if TEST_STD_VER >= 11 |
| 68 | { |
| 69 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
| 70 | const int N = sizeof(rng) / sizeof(rng[0]); |
| 71 | for (int i = 0; i < N; ++i) |
| 72 | for (int j = 0; j < N; ++j) |
| 73 | for (int k = 0; k < N; ++k) |
| 74 | testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |