From 7239c8e2624f7bee04440575386457fc9c2011d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 27 Feb 2015 19:24:46 +0100 Subject: [PATCH] Refactor initializer_list tests to avoid code duplication and add some missing initializer_list overload tests --- test/flat_map_test.cpp | 37 ++-------------------- test/flat_set_test.cpp | 4 +-- test/list_test.cpp | 6 +++- test/map_test.cpp | 36 ++-------------------- test/map_test.hpp | 70 ++++++++++++++++++++++++++++++++++++++++++ test/set_test.cpp | 33 ++------------------ test/set_test.hpp | 37 ++++++++++++++++++++++ test/slist_test.cpp | 7 ++++- test/vector_test.hpp | 7 ++++- 9 files changed, 132 insertions(+), 105 deletions(-) diff --git a/test/flat_map_test.cpp b/test/flat_map_test.cpp index f21dddf..8a8ec08 100644 --- a/test/flat_map_test.cpp +++ b/test/flat_map_test.cpp @@ -411,39 +411,6 @@ int test_map_variants() return 0; } -template -bool test_support_for_initialization_list_for() -{ -#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - const std::initializer_list> il - = {std::make_pair(1, 2), std::make_pair(3, 4)}; - - const FlatMapType expected(il.begin(), il.end()); - { - const FlatMapType sil = il; - if (sil != expected) - return false; - - const FlatMapType sil_ordered(ordered_unique_range, il); - if(sil_ordered != expected) - return false; - - FlatMapType sil_assign = {std::make_pair(99, 100)}; - sil_assign = il; - if(sil_assign != expected) - return false; - } - { - FlatMapType sil; - sil.insert(il); - if(sil != expected) - return false; - } - return true; -#endif - return true; -} - int main() { using namespace boost::container::test; @@ -506,10 +473,10 @@ int main() return 1; } - if(!test_support_for_initialization_list_for >()) + if(!boost::container::test::test_map_support_for_initialization_list_for >()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_map_support_for_initialization_list_for >()) return 1; //////////////////////////////////// diff --git a/test/flat_set_test.cpp b/test/flat_set_test.cpp index f78c223..26b5a63 100644 --- a/test/flat_set_test.cpp +++ b/test/flat_set_test.cpp @@ -590,10 +590,10 @@ int main() if(!boost::container::test::test_emplace, SetOptions>()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for >()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for >()) return 1; //////////////////////////////////// diff --git a/test/list_test.cpp b/test/list_test.cpp index cea84bd..84588b7 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -126,10 +126,14 @@ bool test_support_for_initializer_list() const std::initializer_list il = {1, 10}; const list expectedList(il.begin(), il.end()); - const list testConstructor = il; + const list testConstructor((il)); if(testConstructor != expectedList) return false; + const list testConstructorAllocator(il, list::allocator_type()); + if (testConstructorAllocator != expectedList) + return false; + list testAssignOperator = {10, 11}; testAssignOperator = il; if(testAssignOperator != expectedList) diff --git a/test/map_test.cpp b/test/map_test.cpp index ed27924..ebd1eab 100644 --- a/test/map_test.cpp +++ b/test/map_test.cpp @@ -318,38 +318,6 @@ int test_map_variants() return 0; } -template -bool test_support_for_initialization_list_for() -{ -#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - const std::initializer_list> il - = {std::make_pair(1, 2), std::make_pair(3, 4)}; - const MapType expected(il.begin(), il.end()); - { - const MapType sil = il; - if (sil != expected) - return false; - - const MapType sil_ordered(ordered_unique_range, il); - if(sil_ordered != expected) - return false; - - MapType sil_assign = {std::make_pair(99, 100)}; - sil_assign = il; - if(sil_assign != expected) - return false; - } - { - MapType sil; - sil.insert(il); - if(sil != expected) - return false; - } - return true; -#endif - return true; -} - struct boost_container_map; struct boost_container_multimap; @@ -460,10 +428,10 @@ int main () if(!boost::container::test::test_propagate_allocator()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_map_support_for_initialization_list_for >()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_map_support_for_initialization_list_for >()) return 1; //////////////////////////////////// diff --git a/test/map_test.hpp b/test/map_test.hpp index 864db8f..4c87708 100644 --- a/test/map_test.hpp +++ b/test/map_test.hpp @@ -663,6 +663,76 @@ int map_test() } return 0; } +/* +template +bool test_support_for_initialization_list_for() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + const std::initializer_list> il + = {std::make_pair(1, 2), std::make_pair(3, 4)}; + const MapType expected(il.begin(), il.end()); + { + const MapType sil = il; + if (sil != expected) + return false; + + const MapType sil_ordered(ordered_unique_range, il); + if(sil_ordered != expected) + return false; + + MapType sil_assign = {std::make_pair(99, 100)}; + sil_assign = il; + if(sil_assign != expected) + return false; + } + { + MapType sil; + sil.insert(il); + if(sil != expected) + return false; + } + return true; +#endif + return true; +} +*/ +template +bool test_map_support_for_initialization_list_for() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + const std::initializer_list> il + = { std::make_pair(1, 2), std::make_pair(3, 4) }; + + const MapType expected(il.begin(), il.end()); + { + const MapType sil = il; + if (sil != expected) + return false; + + MapType sila(il, typename MapType::allocator_type()); + if (sila != expected) + return false; + + const MapType sil_ordered(ordered_unique_range, il); + if (sil_ordered != expected) + return false; + + MapType sil_assign = { std::make_pair(99, 100) }; + sil_assign = il; + if (sil_assign != expected) + return false; + } + { + MapType sil; + sil.insert(il); + if (sil != expected) + return false; + } + return true; +#endif + return true; +} + } //namespace test{ } //namespace container { diff --git a/test/set_test.cpp b/test/set_test.cpp index 9eb3157..b305868 100644 --- a/test/set_test.cpp +++ b/test/set_test.cpp @@ -322,36 +322,7 @@ int test_set_variants() return 0; } -template -bool test_support_for_initialization_list_for() -{ -#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - std::initializer_list il = {1, 2, 3, 4, 5}; - SetType expected(il.begin(), il.end()); - { - SetType sil = il; - if (sil != expected) - return false; - SetType sil_ordered(ordered_unique_range, il); - if(sil_ordered != expected) - return false; - - SetType sil_assign = {99, 100, 101, 102, 103, 104, 105}; - sil_assign = il; - if(sil_assign != expected) - return false; - } - { - SetType sil; - sil.insert(il); - if(sil != expected) - return false; - } - return true; -#endif - return true; -} int main () { //Recursive container instantiation @@ -431,10 +402,10 @@ int main () if(!boost::container::test::test_propagate_allocator()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for >()) return 1; - if(!test_support_for_initialization_list_for >()) + if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for >()) return 1; //////////////////////////////////// diff --git a/test/set_test.hpp b/test/set_test.hpp index f03dbbb..b8f043c 100644 --- a/test/set_test.hpp +++ b/test/set_test.hpp @@ -705,6 +705,43 @@ int set_test () return 0; } +template +bool test_set_methods_with_initializer_list_as_argument_for() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + std::initializer_list il = { 1, 2, 3, 4, 5, 5 }; + std::initializer_list ilu = { 1, 2, 3, 4, 5 }; + SetType expected(il.begin(), il.end()); + SetType expectedu(ilu.begin(), ilu.end()); + { + SetType sil((il)); + if (sil != expected) + return false; + + SetType sila(il, typename SetType::allocator_type()); + if (sila != expected) + return false; + + SetType sil_ordered(ordered_unique_range, ilu); + if (sil_ordered != expectedu) + return false; + + SetType sil_assign = { 99, 100, 101, 102, 103, 104, 105 }; + sil_assign = il; + if (sil_assign != expected) + return false; + } + { + SetType sil; + sil.insert(il); + if (sil != expected) + return false; + } + return true; +#endif + return true; +} + } //namespace test{ } //namespace container { } //namespace boost{ diff --git a/test/slist_test.cpp b/test/slist_test.cpp index 7c58fb0..f73056b 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -121,7 +121,12 @@ bool test_support_for_initializer_list() if(sl != expected_list) return false; } - + { + slist sl({ 1, 2 }, slist::allocator_type()); + sl = il; + if (sl != expected_list) + return false; + } { slist sl = {4, 5}; sl.assign(il); diff --git a/test/vector_test.hpp b/test/vector_test.hpp index 93cb088..6662d84 100644 --- a/test/vector_test.hpp +++ b/test/vector_test.hpp @@ -389,12 +389,17 @@ template bool test_vector_methods_with_initializer_list_as_argument_for() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + typedef typename VectorContainerType::allocator_type allocator_type; { const VectorContainerType testedVector = {1, 2, 3}; const std::vector expectedVector = {1, 2, 3}; if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; } - + { + const VectorContainerType testedVector( { 1, 2, 3 }, allocator_type() ); + const std::vector expectedVector = {1, 2, 3}; + if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; + } { VectorContainerType testedVector = {1, 2, 3}; testedVector = {11, 12, 13};