Added vector<T>::insert tests suggested by code coverage results
authorMarshall Clow <mclow.lists@gmail.com>
Tue, 11 Nov 2014 16:44:05 +0000 (16:44 +0000)
committerMarshall Clow <mclow.lists@gmail.com>
Tue, 11 Nov 2014 16:44:05 +0000 (16:44 +0000)
llvm-svn: 221689

libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp
libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp
libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp
libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp
libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp

index f819a31..710ad48 100644 (file)
@@ -47,6 +47,22 @@ int main()
         for (++j; j < v.size(); ++j)
             assert(v[j] == 0);
     }
+    {
+        std::vector<bool> v(100);
+        while(v.size() < v.capacity()) v.push_back(false);
+        v.pop_back(); v.pop_back();
+        size_t sz = v.size();
+        std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
+        assert(v.size() == sz + 5);
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        for (; j < 15; ++j)
+            assert(v[j] == 1);
+        for (++j; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
 #if __cplusplus >= 201103L
     {
         std::vector<bool, min_allocator<bool>> v(100);
index 78a89e7..51c4626 100644 (file)
@@ -45,6 +45,21 @@ int main()
         for (++j; j < v.size(); ++j)
             assert(v[j] == 0);
     }
+    {
+        std::vector<bool> v(100);
+        while(v.size() < v.capacity()) v.push_back(false);
+        v.pop_back(); v.pop_back();
+        size_t sz = v.size();
+        std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1);
+        assert(v.size() == sz + 1);
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        assert(v[j] == 1);
+        for (++j; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
 #if __cplusplus >= 201103L
     {
         std::vector<bool, min_allocator<bool>> v(100);
index cf24a87..782437b 100644 (file)
@@ -60,6 +60,42 @@ int main()
             assert(v[j] == 0);
     }
     {
+        std::vector<int> v(100);
+        while(v.size() < v.capacity()) v.push_back(0); // force reallocation
+        size_t sz = v.size();
+        int a[] = {1, 2, 3, 4, 5};
+        const unsigned N = sizeof(a)/sizeof(a[0]);
+        std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
+                                        forward_iterator<const int*>(a+N));
+        assert(v.size() == sz + N);
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        for (int k = 0; k < N; ++j, ++k)
+            assert(v[j] == a[k]);
+        for (; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
+    {
+        std::vector<int> v(100);
+        v.reserve(128); // force no reallocation
+        size_t sz = v.size();
+        int a[] = {1, 2, 3, 4, 5};
+        const unsigned N = sizeof(a)/sizeof(a[0]);
+        std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
+                                        forward_iterator<const int*>(a+N));
+        assert(v.size() == sz + N);
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        for (int k = 0; k < N; ++j, ++k)
+            assert(v[j] == a[k]);
+        for (; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
+    {
         std::vector<int, stack_allocator<int, 308> > v(100);
         int a[] = {1, 2, 3, 4, 5};
         const int N = sizeof(a)/sizeof(a[0]);
index 42effc7..6997284 100644 (file)
@@ -38,6 +38,38 @@ int main()
             assert(v[j] == 0);
     }
     {
+        std::vector<int> v(100);
+        while(v.size() < v.capacity()) v.push_back(0); // force reallocation
+        size_t sz = v.size();
+        std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
+        assert(v.size() == sz + 5);
+        assert(is_contiguous_container_asan_correct(v)); 
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        for (; j < 15; ++j)
+            assert(v[j] == 1);
+        for (++j; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
+    {
+        std::vector<int> v(100);
+        v.reserve(128); // force no reallocation
+        size_t sz = v.size();
+        std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
+        assert(v.size() == sz + 5);
+        assert(is_contiguous_container_asan_correct(v)); 
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        for (; j < 15; ++j)
+            assert(v[j] == 1);
+        for (++j; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
+    {
         std::vector<int, stack_allocator<int, 300> > v(100);
         std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1);
         assert(v.size() == 105);
index feb74c0..782e752 100644 (file)
@@ -37,6 +37,37 @@ int main()
             assert(v[j] == 0);
     }
     {
+        std::vector<int> v(100);
+        while(v.size() < v.capacity()) v.push_back(0); // force reallocation
+        size_t sz = v.size();
+        std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
+        assert(v.size() == sz + 1);
+        assert(is_contiguous_container_asan_correct(v)); 
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        assert(v[j] == 1);
+        for (++j; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
+    {
+        std::vector<int> v(100);
+        while(v.size() < v.capacity()) v.push_back(0);
+        v.pop_back(); v.pop_back(); // force no reallocation
+        size_t sz = v.size();
+        std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
+        assert(v.size() == sz + 1);
+        assert(is_contiguous_container_asan_correct(v)); 
+        assert(i == v.begin() + 10);
+        int j;
+        for (j = 0; j < 10; ++j)
+            assert(v[j] == 0);
+        assert(v[j] == 1);
+        for (++j; j < v.size(); ++j)
+            assert(v[j] == 0);
+    }
+    {
         std::vector<int, stack_allocator<int, 300> > v(100);
         std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 1);
         assert(v.size() == 101);