[libcxx] r221644 - EricQWF's code coverage work showed that none of the libc++ tests were exercising some code in vector<bool>. Add more tests in an attempt to get better coverage
Marshall Clow
mclow.lists at gmail.com
Mon Nov 10 16:16:31 PST 2014
Author: marshall
Date: Mon Nov 10 18:16:30 2014
New Revision: 221644
URL: http://llvm.org/viewvc/llvm-project?rev=221644&view=rev
Log:
EricQWF's code coverage work showed that none of the libc++ tests were exercising some code in vector<bool>. Add more tests in an attempt to get better coverage
Modified:
libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp
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.bool/resize_size.pass.cpp
Modified: libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp?rev=221644&r1=221643&r2=221644&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp Mon Nov 10 18:16:30 2014
@@ -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<bool> 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<bool>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const bool*>(a),
+ forward_iterator<const bool*>(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<bool> 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<bool>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const bool*>(a),
+ forward_iterator<const bool*>(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<bool, min_allocator<bool>> 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
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=221644&r1=221643&r2=221644&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 Mon Nov 10 18:16:30 2014
@@ -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<bool> v(100);
+ while(v.size() < v.capacity()) v.push_back(false);
+ 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
@@ -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
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=221644&r1=221643&r2=221644&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 Mon Nov 10 18:16:30 2014
@@ -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<bool> v(100);
+ while(v.size() < v.capacity()) v.push_back(false);
+ 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
@@ -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
Modified: libcxx/trunk/test/containers/sequences/vector.bool/resize_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/resize_size.pass.cpp?rev=221644&r1=221643&r2=221644&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/resize_size.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector.bool/resize_size.pass.cpp Mon Nov 10 18:16:30 2014
@@ -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
}
More information about the cfe-commits
mailing list