From a773ab1d8d5bcb10c9b90e29e07f03473268da0b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 11 Nov 2014 00:16:30 +0000 Subject: [PATCH] EricQWF's code coverage work showed that none of the libc++ tests were exercising some code in vector. Add more tests in an attempt to get better coverage llvm-svn: 221644 --- .../insert_iter_iter_iter.pass.cpp | 43 +++++++++++++++++-- .../insert_iter_size_value.pass.cpp | 19 +++++++- .../vector.bool/insert_iter_value.pass.cpp | 18 +++++++- .../vector.bool/resize_size.pass.cpp | 8 ++++ 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp index c49ef9bfaced..e51f8b589c7f 100644 --- a/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp @@ -33,7 +33,7 @@ int main() assert(v[j] == 0); for (int k = 0; k < N; ++j, ++k) assert(v[j] == a[k]); - for (; j < 105; ++j) + for (; j < v.size(); ++j) assert(v[j] == 0); } { @@ -52,6 +52,43 @@ int main() for (; j < 105; ++j) assert(v[j] == 0); } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(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 v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); v.pop_back(); + size_t sz = v.size(); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(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); + } #if __cplusplus >= 201103L { std::vector> v(100); @@ -66,7 +103,7 @@ int main() assert(v[j] == 0); for (int k = 0; k < N; ++j, ++k) assert(v[j] == a[k]); - for (; j < 105; ++j) + for (; j < v.size(); ++j) assert(v[j] == 0); } { @@ -82,7 +119,7 @@ int main() assert(v[j] == 0); for (int k = 0; k < N; ++j, ++k) assert(v[j] == a[k]); - for (; j < 105; ++j) + for (; j < v.size(); ++j) assert(v[j] == 0); } #endif diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp index f9cb65cb8087..f819a31f93a1 100644 --- a/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp @@ -29,7 +29,22 @@ int main() assert(v[j] == 0); for (; j < 15; ++j) assert(v[j] == 1); - for (++j; j < 105; ++j) + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + std::vector::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 @@ -43,7 +58,7 @@ int main() assert(v[j] == 0); for (; j < 15; ++j) assert(v[j] == 1); - for (++j; j < 105; ++j) + for (++j; j < v.size(); ++j) assert(v[j] == 0); } #endif diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp index 1213985f53f9..78a89e72044e 100644 --- a/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp @@ -28,7 +28,21 @@ int main() for (j = 0; j < 10; ++j) assert(v[j] == 0); assert(v[j] == 1); - for (++j; j < 101; ++j) + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + std::vector::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 @@ -41,7 +55,7 @@ int main() for (j = 0; j < 10; ++j) assert(v[j] == 0); assert(v[j] == 1); - for (++j; j < 101; ++j) + for (++j; j < v.size(); ++j) assert(v[j] == 0); } #endif diff --git a/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp b/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp index 77d54e5efc17..f75720c94ea3 100644 --- a/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp +++ b/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp @@ -27,6 +27,10 @@ int main() v.resize(200); assert(v.size() == 200); assert(v.capacity() >= 200); + v.reserve(400); + v.resize(300); // check the case when resizing and we already have room + assert(v.size() == 300); + assert(v.capacity() >= 400); } #if __cplusplus >= 201103L { @@ -37,6 +41,10 @@ int main() v.resize(200); assert(v.size() == 200); assert(v.capacity() >= 200); + v.reserve(400); + v.resize(300); // check the case when resizing and we already have room + assert(v.size() == 300); + assert(v.capacity() >= 400); } #endif }