[libcxx] r233557 - 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

Marshall Clow mclow.lists at gmail.com
Mon Mar 30 09:07:11 PDT 2015


Author: marshall
Date: Mon Mar 30 11:07:11 2015
New Revision: 233557

URL: http://llvm.org/viewvc/llvm-project?rev=233557&view=rev
Log:
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

Added:
    libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp
Modified:
    libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp?rev=233557&r1=233556&r2=233557&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp Mon Mar 30 11:07:11 2015
@@ -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

Added: libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp?rev=233557&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp (added)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_size_value.pass.cpp Mon Mar 30 11:07:11 2015
@@ -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
+}





More information about the cfe-commits mailing list