113 lines · cpp
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-exception6//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 23template <class T, class Allocator>24void test2(unsigned n) {25#if TEST_STD_VER > 1126 typedef std::deque<T, Allocator> C;27 typedef typename C::const_iterator const_iterator;28 assert(DefaultOnly::count == 0);29 {30 C d(n, Allocator());31 assert(static_cast<unsigned>(DefaultOnly::count) == n);32 assert(d.size() == n);33 assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());34 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));35 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)36 assert(*i == T());37 }38 assert(DefaultOnly::count == 0);39#else40 ((void)n);41#endif42}43 44template <class T, class Allocator>45void test1(unsigned n) {46 typedef std::deque<T, Allocator> C;47 typedef typename C::const_iterator const_iterator;48 assert(DefaultOnly::count == 0);49 {50 C d(n);51 assert(static_cast<unsigned>(DefaultOnly::count) == n);52 assert(d.size() == n);53 assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());54 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));55#if TEST_STD_VER >= 1156 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)57 assert(*i == T());58#endif59 }60 assert(DefaultOnly::count == 0);61}62 63template <class T, class Allocator>64void test3(unsigned n, Allocator const& alloc = Allocator()) {65#if TEST_STD_VER > 1166 typedef std::deque<T, Allocator> C;67 {68 C d(n, alloc);69 assert(d.size() == n);70 assert(d.get_allocator() == alloc);71 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));72 }73#else74 ((void)n);75 ((void)alloc);76#endif77}78 79template <class T, class Allocator>80void test(unsigned n) {81 test1<T, Allocator>(n);82 test2<T, Allocator>(n);83}84 85int main(int, char**) {86 test<DefaultOnly, std::allocator<DefaultOnly> >(0);87 test<DefaultOnly, std::allocator<DefaultOnly> >(1);88 test<DefaultOnly, std::allocator<DefaultOnly> >(10);89 test<DefaultOnly, std::allocator<DefaultOnly> >(1023);90 test<DefaultOnly, std::allocator<DefaultOnly> >(1024);91 test<DefaultOnly, std::allocator<DefaultOnly> >(1025);92 test<DefaultOnly, std::allocator<DefaultOnly> >(2047);93 test<DefaultOnly, std::allocator<DefaultOnly> >(2048);94 test<DefaultOnly, std::allocator<DefaultOnly> >(2049);95 test<DefaultOnly, std::allocator<DefaultOnly> >(4095);96 test<DefaultOnly, std::allocator<DefaultOnly> >(4096);97 test<DefaultOnly, std::allocator<DefaultOnly> >(4097);98 99 LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095));100 101#if TEST_STD_VER >= 11102 test<DefaultOnly, min_allocator<DefaultOnly> >(4095);103#endif104 105#if TEST_STD_VER > 11106 test3<DefaultOnly, std::allocator<DefaultOnly>>(1023);107 test3<int, std::allocator<int>>(1);108 test3<int, min_allocator<int>>(3);109#endif110 111 return 0;112}113