[libcxx] r221689 - Added vector<T>::insert tests suggested by code coverage results
Marshall Clow
mclow.lists at gmail.com
Tue Nov 11 08:44:06 PST 2014
Author: marshall
Date: Tue Nov 11 10:44:05 2014
New Revision: 221689
URL: http://llvm.org/viewvc/llvm-project?rev=221689&view=rev
Log:
Added vector<T>::insert tests suggested by code coverage results
Modified:
libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp
libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp
libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp
libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp
libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp
Modified: libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp?rev=221689&r1=221688&r2=221689&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp Tue Nov 11 10:44:05 2014
@@ -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);
Modified: libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp?rev=221689&r1=221688&r2=221689&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp Tue Nov 11 10:44:05 2014
@@ -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);
Modified: libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp?rev=221689&r1=221688&r2=221689&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp Tue Nov 11 10:44:05 2014
@@ -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]);
Modified: libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp?rev=221689&r1=221688&r2=221689&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp Tue Nov 11 10:44:05 2014
@@ -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);
Modified: libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp?rev=221689&r1=221688&r2=221689&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp Tue Nov 11 10:44:05 2014
@@ -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);
More information about the cfe-commits
mailing list