From: Kristina Bessonova Date: Tue, 20 Apr 2021 17:50:29 +0000 (+0200) Subject: [libcxx][test] Construct non-empty containers in iterator's debug mode tests X-Git-Tag: llvmorg-14-init~9037 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a292eda25bc999ec175f0d21b87cb0225b6da86;p=platform%2Fupstream%2Fllvm.git [libcxx][test] Construct non-empty containers in iterator's debug mode tests The debug mode tests for map/set's iterators construct empty containers, making the code after the first increment meaningless. It's never executed since the tests exit earlier. It doesn't seem to be intentional, so the patch makes the tests to construct containers that include at least one element. Reviewed By: curdeius, Quuxplusone Differential Revision: https://reviews.llvm.org/D100029 --- diff --git a/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp index 29b0636..762551d 100644 --- a/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp @@ -23,9 +23,13 @@ int main(int, char**) { typedef std::unordered_map C; - C c(1); - C::local_iterator i = c.begin(0); + C c; + c.insert(std::make_pair(42, std::string())); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_9.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_9.pass.cpp index 85e72b5..e0d3eac 100644 --- a/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_9.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_9.pass.cpp @@ -27,9 +27,12 @@ int main(int, char**) { typedef std::unordered_map, std::equal_to, min_allocator>> C; - C c(1); - C::local_iterator i = c.begin(0); + C c({{42, std::string()}}); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp index d90ccc3..4f48b6c 100644 --- a/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp @@ -23,9 +23,13 @@ int main(int, char**) { typedef std::unordered_multimap C; - C c(1); - C::local_iterator i = c.begin(0); + C c; + c.insert(std::make_pair(42, std::string())); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_9.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_9.pass.cpp index ded95049..dede94c 100644 --- a/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_9.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.multimap/db_local_iterators_9.pass.cpp @@ -28,9 +28,13 @@ int main(int, char**) { typedef std::unordered_multimap, std::equal_to, min_allocator>> C; - C c(1); - C::local_iterator i = c.begin(0); + C c({{1, std::string()}}); + c.insert(std::make_pair(42, std::string())); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_7.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_7.pass.cpp index 20cf082..2fc397a 100644 --- a/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_7.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_7.pass.cpp @@ -23,8 +23,10 @@ int main(int, char**) { typedef int T; typedef std::unordered_multiset C; - C c(1); + C c; + c.insert(42); C::iterator i = c.begin(); + assert(i != c.end()); ++i; assert(i == c.end()); ++i; diff --git a/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_9.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_9.pass.cpp index 60027c4..29ca4a6 100644 --- a/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_9.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.multiset/db_iterators_9.pass.cpp @@ -26,8 +26,9 @@ int main(int, char**) { typedef int T; typedef std::unordered_multiset, std::equal_to, min_allocator> C; - C c(1); + C c({42}); C::iterator i = c.begin(); + assert(i != c.end()); ++i; assert(i == c.end()); ++i; diff --git a/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp index d4748a5..bef45d4 100644 --- a/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp @@ -23,9 +23,13 @@ int main(int, char**) { typedef int T; typedef std::unordered_multiset C; - C c(1); - C::local_iterator i = c.begin(0); + C c; + c.insert(42); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_9.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_9.pass.cpp index 24e2949..9fbc69a 100644 --- a/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_9.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.multiset/db_local_iterators_9.pass.cpp @@ -26,9 +26,12 @@ int main(int, char**) { typedef int T; typedef std::unordered_multiset, std::equal_to, min_allocator> C; - C c(1); - C::local_iterator i = c.begin(0); + C c({42}); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_7.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_7.pass.cpp index fea8d1f..03d1727 100644 --- a/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_7.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_7.pass.cpp @@ -23,8 +23,10 @@ int main(int, char**) { typedef int T; typedef std::unordered_set C; - C c(1); + C c; + c.insert(42); C::iterator i = c.begin(); + assert(i != c.end()); ++i; assert(i == c.end()); ++i; diff --git a/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_9.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_9.pass.cpp index 18617d2..7ea8a06 100644 --- a/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_9.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.set/db_iterators_9.pass.cpp @@ -26,8 +26,9 @@ int main(int, char**) { typedef int T; typedef std::unordered_set, std::equal_to, min_allocator> C; - C c(1); + C c({42}); C::iterator i = c.begin(); + assert(i != c.end()); ++i; assert(i == c.end()); ++i; diff --git a/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_7.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_7.pass.cpp index 44da897..5fa9983 100644 --- a/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_7.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_7.pass.cpp @@ -23,9 +23,13 @@ int main(int, char**) { typedef int T; typedef std::unordered_set C; - C c(1); - C::local_iterator i = c.begin(0); + C c; + c.insert(42); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false); diff --git a/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_9.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_9.pass.cpp index 98d5a2e..89fc71a 100644 --- a/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_9.pass.cpp +++ b/libcxx/test/libcxx/containers/unord/unord.set/db_local_iterators_9.pass.cpp @@ -26,9 +26,12 @@ int main(int, char**) { typedef int T; typedef std::unordered_set, std::equal_to, min_allocator> C; - C c(1); - C::local_iterator i = c.begin(0); + C c({42}); + C::size_type b = c.bucket(42); + C::local_iterator i = c.begin(b); + assert(i != c.end(b)); ++i; + assert(i == c.end(b)); ++i; assert(false);