diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2015-03-30 16:07:11 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2015-03-30 16:07:11 +0000 |
commit | 21471e0906a16381668184d53f02f465931d3bcb (patch) | |
tree | 2937562379afc910af5179b0c5ec6e7d69a8b3dc | |
parent | 3cfe2e06fb897d1a0e3d0438bfa8d5d7990b4aee (diff) | |
download | bcm5719-llvm-21471e0906a16381668184d53f02f465931d3bcb.tar.gz bcm5719-llvm-21471e0906a16381668184d53f02f465931d3bcb.zip |
While testing Erik's code coverage scripts, I found a hole in the test suite - vector::assign where a reallocation was not required had no tests. Add some
llvm-svn: 233557
-rw-r--r-- | libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp | 39 | ||||
-rw-r--r-- | libcxx/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp | 51 |
2 files changed, 74 insertions, 16 deletions
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp index f5c06b1a1bd..dd9a1e61545 100644 --- a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp @@ -17,29 +17,36 @@ #include "min_allocator.h" #include "asan_testing.h" +template <typename Vec> +void test ( Vec &v ) +{ + v.assign({3, 4, 5, 6}); + assert(v.size() == 4); + assert(is_contiguous_container_asan_correct(v)); + assert(v[0] == 3); + assert(v[1] == 4); + assert(v[2] == 5); + assert(v[3] == 6); +} + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS { - std::vector<int> d; - d.assign({3, 4, 5, 6}); - assert(d.size() == 4); - assert(is_contiguous_container_asan_correct(d)); - assert(d[0] == 3); - assert(d[1] == 4); - assert(d[2] == 5); - assert(d[3] == 6); + typedef std::vector<int> V; + V d1; + V d2(10); // no reallocation during assign. + test(d1); + test(d2); } + #if __cplusplus >= 201103L { - std::vector<int, min_allocator<int>> d; - d.assign({3, 4, 5, 6}); - assert(d.size() == 4); - assert(is_contiguous_container_asan_correct(d)); - assert(d[0] == 3); - assert(d[1] == 4); - assert(d[2] == 5); - assert(d[3] == 6); + typedef std::vector<int, min_allocator<int>> V; + V d1; + V d2(10); // no reallocation during assign. + test(d1); + test(d2); } #endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..9ec833e4974 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void assign(size_type n, const_reference v); + +#include <vector> +#include <algorithm> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +bool is6(int x) { return x == 6; } + +template <typename Vec> +void test ( Vec &v ) +{ + v.assign(5, 6); + assert(v.size() == 5); + assert(is_contiguous_container_asan_correct(v)); + assert(std::all_of(v.begin(), v.end(), is6)); +} + +int main() +{ + { + typedef std::vector<int> V; + V d1; + V d2(10); // no reallocation during assign. + test(d1); + test(d2); + } + +#if __cplusplus >= 201103L + { + typedef std::vector<int, min_allocator<int>> V; + V d1; + V d2(10); // no reallocation during assign. + test(d1); + test(d2); + } +#endif +} |