[libcxx-commits] [libcxx] 3442ff1 - [libc++][NFC] Slight refactoring of some std::vector tests
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 6 07:56:42 PDT 2022
Author: Louis Dionne
Date: 2022-05-06T10:56:34-04:00
New Revision: 3442ff17a560afdac6cf3bea2ab5b559589c3c15
URL: https://github.com/llvm/llvm-project/commit/3442ff17a560afdac6cf3bea2ab5b559589c3c15
DIFF: https://github.com/llvm/llvm-project/commit/3442ff17a560afdac6cf3bea2ab5b559589c3c15.diff
LOG: [libc++][NFC] Slight refactoring of some std::vector tests
Added:
Modified:
libcxx/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
index bbd461a8e954d..6a572fada2c01 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
@@ -23,7 +23,7 @@
#endif
-void test_emplaceable_concept() {
+void test() {
#if TEST_STD_VER >= 11
int arr1[] = {42};
int arr2[] = {1, 101, 42};
@@ -64,26 +64,22 @@ void test_emplaceable_concept() {
}
}
#endif
-}
-// Test with a number of elements in the source range
-// that is greater than capacity
-void test_assign_bigger() {
- typedef forward_iterator<int*> It;
+ // Test with a number of elements in the source range that is greater than capacity
+ {
+ typedef forward_iterator<int*> It;
- std::vector<int> dst(10);
+ std::vector<int> dst(10);
- size_t n = dst.capacity() * 2;
- std::vector<int> src(n);
+ size_t n = dst.capacity() * 2;
+ std::vector<int> src(n);
- dst.assign(It(src.data()), It(src.data() + src.size()));
- assert(dst == src);
+ dst.assign(It(src.data()), It(src.data() + src.size()));
+ assert(dst == src);
+ }
}
-int main(int, char**)
-{
- test_emplaceable_concept();
- test_assign_bigger();
-
+int main(int, char**) {
+ test();
return 0;
}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp
index cf85ea0dbcc03..a06031c564d8b 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp
@@ -9,6 +9,7 @@
// <vector>
// explicit vector(size_type n);
+// explicit vector(size_type n, const Allocator& alloc = Allocator());
#include <vector>
#include <cassert>
@@ -20,62 +21,55 @@
#include "asan_testing.h"
template <class C>
-void
-test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ())
+void test(typename C::size_type n,
+ typename C::allocator_type const& a = typename C::allocator_type())
{
-#if TEST_STD_VER >= 14
- C c(n, a);
- LIBCPP_ASSERT(c.__invariants());
- assert(c.size() == n);
- assert(c.get_allocator() == a);
- LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
- for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
- assert(*i == typename C::value_type());
-#else
- ((void)n);
- ((void)a);
-#endif
-}
-
-template <class C>
-void
-test1(typename C::size_type n)
-{
- C c(n);
- LIBCPP_ASSERT(c.__invariants());
- assert(c.size() == n);
- assert(c.get_allocator() == typename C::allocator_type());
- LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+ (void)a;
+ // Test without a custom allocator
+ {
+ C c(n);
+ LIBCPP_ASSERT(c.__invariants());
+ assert(c.size() == n);
+ assert(c.get_allocator() == typename C::allocator_type());
+ LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
#if TEST_STD_VER >= 11
- for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
- assert(*i == typename C::value_type());
+ for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
+ assert(*i == typename C::value_type());
#endif
-}
+ }
-template <class C>
-void
-test(typename C::size_type n)
-{
- test1<C> ( n );
- test2<C> ( n );
+ // Test with a custom allocator
+#if TEST_STD_VER >= 14
+ {
+ C c(n, a);
+ LIBCPP_ASSERT(c.__invariants());
+ assert(c.size() == n);
+ assert(c.get_allocator() == a);
+ LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+ for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
+ assert(*i == typename C::value_type());
+ }
+#endif
}
-int main(int, char**)
-{
+void tests() {
test<std::vector<int> >(0);
test<std::vector<int> >(50);
test<std::vector<DefaultOnly> >(0);
test<std::vector<DefaultOnly> >(500);
assert(DefaultOnly::count == 0);
#if TEST_STD_VER >= 11
- test<std::vector<int, min_allocator<int>> >(0);
- test<std::vector<int, min_allocator<int>> >(50);
- test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(0);
- test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500);
- test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 0, test_allocator<DefaultOnly>(23));
- test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23));
+ test<std::vector<int, min_allocator<int>>>(0);
+ test<std::vector<int, min_allocator<int>>>(50);
+ test<std::vector<DefaultOnly, min_allocator<DefaultOnly>>>(0);
+ test<std::vector<DefaultOnly, min_allocator<DefaultOnly>>>(500);
+ test<std::vector<DefaultOnly, test_allocator<DefaultOnly>>>(0, test_allocator<DefaultOnly>(23));
+ test<std::vector<DefaultOnly, test_allocator<DefaultOnly>>>(100, test_allocator<DefaultOnly>(23));
assert(DefaultOnly::count == 0);
#endif
+}
- return 0;
+int main(int, char**) {
+ tests();
+ return 0;
}
More information about the libcxx-commits
mailing list