From ab08634fe03b13a94f56e3da66b991b929367a9b Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 26 Mar 2016 17:32:19 +0300 Subject: [PATCH] Migrated StripedSet unit tests to gtest framework --- projects/Win/vc14/gtest-striped-set.vcxproj | 12 + .../vc14/gtest-striped-set.vcxproj.filters | 36 + test/unit/striped-set/CMakeLists.txt | 11 + test/unit/striped-set/set_boost_flatset.cpp | 69 ++ test/unit/striped-set/set_boost_list.cpp | 69 ++ test/unit/striped-set/set_boost_set.cpp | 69 ++ test/unit/striped-set/set_boost_slist.cpp | 69 ++ .../striped-set/set_boost_stable_vector.cpp | 69 ++ .../striped-set/set_boost_unordered_set.cpp | 59 ++ test/unit/striped-set/set_boost_vector.cpp | 69 ++ test/unit/striped-set/set_std_list.cpp | 55 ++ test/unit/striped-set/set_std_set.cpp | 55 ++ .../striped-set/set_std_unordered_set.cpp | 55 ++ test/unit/striped-set/set_std_vector.cpp | 55 ++ test/unit/striped-set/test_set.h | 38 +- test/unit/striped-set/test_striped_set.h | 768 ++++++++++++++++++ 16 files changed, 1556 insertions(+), 2 deletions(-) create mode 100644 test/unit/striped-set/set_boost_flatset.cpp create mode 100644 test/unit/striped-set/set_boost_list.cpp create mode 100644 test/unit/striped-set/set_boost_set.cpp create mode 100644 test/unit/striped-set/set_boost_slist.cpp create mode 100644 test/unit/striped-set/set_boost_stable_vector.cpp create mode 100644 test/unit/striped-set/set_boost_unordered_set.cpp create mode 100644 test/unit/striped-set/set_boost_vector.cpp create mode 100644 test/unit/striped-set/set_std_list.cpp create mode 100644 test/unit/striped-set/set_std_set.cpp create mode 100644 test/unit/striped-set/set_std_unordered_set.cpp create mode 100644 test/unit/striped-set/set_std_vector.cpp create mode 100644 test/unit/striped-set/test_striped_set.h diff --git a/projects/Win/vc14/gtest-striped-set.vcxproj b/projects/Win/vc14/gtest-striped-set.vcxproj index 4175bbbd..f41966ac 100644 --- a/projects/Win/vc14/gtest-striped-set.vcxproj +++ b/projects/Win/vc14/gtest-striped-set.vcxproj @@ -58,11 +58,23 @@ _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + + + + + + + + + + {648021D3-6E18-4B94-88B8-F6A59609E210} diff --git a/projects/Win/vc14/gtest-striped-set.vcxproj.filters b/projects/Win/vc14/gtest-striped-set.vcxproj.filters index a8e171dc..e0f5f7e4 100644 --- a/projects/Win/vc14/gtest-striped-set.vcxproj.filters +++ b/projects/Win/vc14/gtest-striped-set.vcxproj.filters @@ -48,6 +48,39 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -59,5 +92,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/test/unit/striped-set/CMakeLists.txt b/test/unit/striped-set/CMakeLists.txt index e4229aef..fa30a1e0 100644 --- a/test/unit/striped-set/CMakeLists.txt +++ b/test/unit/striped-set/CMakeLists.txt @@ -14,6 +14,17 @@ set(CDSGTEST_SET_SOURCES intrusive_boost_treap_set.cpp intrusive_boost_unordered_set.cpp intrusive_cuckoo_set.cpp + set_boost_flatset.cpp + set_boost_list.cpp + set_boost_set.cpp + set_boost_slist.cpp + set_boost_stable_vector.cpp + set_boost_unordered_set.cpp + set_boost_vector.cpp + set_std_list.cpp + set_std_set.cpp + set_std_unordered_set.cpp + set_std_vector.cpp ) include_directories( diff --git a/test/unit/striped-set/set_boost_flatset.cpp b/test/unit/striped-set/set_boost_flatset.cpp new file mode 100644 index 00000000..755a925c --- /dev/null +++ b/test/unit/striped-set/set_boost_flatset.cpp @@ -0,0 +1,69 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include +#if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION < 105600 + // Skipped; for Microsoft Visual C++ 2013 and boost::container::flat_set you should use boost version 1.56 or above" ); +#elif BOOST_VERSION >= 104800 + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::container::flat_set< cds_test::container_set::int_item, cds_test::container_set::less > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& set, iterator itWhat ) + { + set.insert( *itWhat ); + } + }; + + static bool const c_hasFindWith = false; + static bool const c_hasEraseWith = false; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostFlatSet, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostFlatSet, RefinableSet, test_traits ); + +} // namespace + +#else // BOOST_VERSION < 104800 + // Skipped; for boost::container::flat_set you should use boost version 1.48 or above +#endif // BOOST_VERSION + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_boost_list.cpp b/test/unit/striped-set/set_boost_list.cpp new file mode 100644 index 00000000..0b6de586 --- /dev/null +++ b/test/unit/striped-set/set_boost_list.cpp @@ -0,0 +1,69 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include +#if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION < 105600 + // Skipped; for Microsoft Visual C++ 2013 and boost::container::list you should use boost version 1.56 or above" ); +#elif BOOST_VERSION >= 104800 + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::container::list< cds_test::container_set::int_item > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& list, iterator itInsert, iterator itWhat ) + { + list.insert( itInsert, *itWhat ); + } + }; + + static bool const c_hasFindWith = true; + static bool const c_hasEraseWith = true; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostList, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostList, RefinableSet, test_traits ); + +} // namespace + +#else // BOOST_VERSION < 104800 + // Skipped; for boost::container::list you should use boost version 1.48 or above +#endif // BOOST_VERSION + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_boost_set.cpp b/test/unit/striped-set/set_boost_set.cpp new file mode 100644 index 00000000..3c802f2e --- /dev/null +++ b/test/unit/striped-set/set_boost_set.cpp @@ -0,0 +1,69 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include +#if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION < 105500 + // Skipped; for Microsoft Visual C++ 2013 and boost::container::set you should use boost version 1.55 or above" ); +#elif BOOST_VERSION >= 104800 + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::container::set< cds_test::container_set::int_item, cds_test::container_set::less > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& set, iterator itWhat ) + { + set.insert( *itWhat ); + } + }; + + static bool const c_hasFindWith = false; + static bool const c_hasEraseWith = false; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostSet, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostSet, RefinableSet, test_traits ); + +} // namespace + +#else // BOOST_VERSION < 104800 + // Skipped; for boost::container::set you should use boost version 1.48 or above +#endif // BOOST_VERSION + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_boost_slist.cpp b/test/unit/striped-set/set_boost_slist.cpp new file mode 100644 index 00000000..82c047e5 --- /dev/null +++ b/test/unit/striped-set/set_boost_slist.cpp @@ -0,0 +1,69 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include +#if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION < 105500 + // Skipped; for Microsoft Visual C++ 2013 and boost::container::slist you should use boost version 1.55 or above" ); +#elif BOOST_VERSION >= 104800 + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::container::slist< cds_test::container_set::int_item > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& list, iterator itInsert, iterator itWhat ) + { + list.insert_after( itInsert, *itWhat ); + } + }; + + static bool const c_hasFindWith = true; + static bool const c_hasEraseWith = true; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostSList, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostSList, RefinableSet, test_traits ); + +} // namespace + +#else // BOOST_VERSION < 104800 + // Skipped; for boost::container::slist you should use boost version 1.48 or above +#endif // BOOST_VERSION + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_boost_stable_vector.cpp b/test/unit/striped-set/set_boost_stable_vector.cpp new file mode 100644 index 00000000..3973d423 --- /dev/null +++ b/test/unit/striped-set/set_boost_stable_vector.cpp @@ -0,0 +1,69 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include +#if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION < 105500 + // Skipped; for Microsoft Visual C++ 2013 and boost::container::stable_vector you should use boost version 1.55 or above" ); +#elif BOOST_VERSION >= 104800 + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::container::stable_vector< cds_test::container_set::int_item > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& vec, iterator itInsert, iterator itWhat ) + { + vec.insert( itInsert, *itWhat ); + } + }; + + static bool const c_hasFindWith = true; + static bool const c_hasEraseWith = true; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostStableVector, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostStableVector, RefinableSet, test_traits ); + +} // namespace + +#else // BOOST_VERSION < 104800 + // Skipped; for boost::container::stable_vector you should use boost version 1.48 or above +#endif // BOOST_VERSION + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_boost_unordered_set.cpp b/test/unit/striped-set/set_boost_unordered_set.cpp new file mode 100644 index 00000000..92ba828f --- /dev/null +++ b/test/unit/striped-set/set_boost_unordered_set.cpp @@ -0,0 +1,59 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::unordered_set< cds_test::container_set::int_item, cds_test::container_set::hash2, cds_test::container_set::equal_to > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& set, iterator itWhat ) + { + set.insert( *itWhat ); + } + }; + + static bool const c_hasFindWith = false; + static bool const c_hasEraseWith = false; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostUnorderedSet, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostUnorderedSet, RefinableSet, test_traits ); + +} // namespace + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_boost_vector.cpp b/test/unit/striped-set/set_boost_vector.cpp new file mode 100644 index 00000000..84cb71c6 --- /dev/null +++ b/test/unit/striped-set/set_boost_vector.cpp @@ -0,0 +1,69 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER + +#include +#include +#if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION < 105500 + // Skipped; for Microsoft Visual C++ 2013 and boost::container::vector you should use boost version 1.55 or above +#elif BOOST_VERSION >= 104800 + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef boost::container::vector< cds_test::container_set::int_item > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& vector, iterator itInsert, iterator itWhat ) + { + vector.insert( itInsert, *itWhat ); + } + }; + + static bool const c_hasFindWith = true; + static bool const c_hasEraseWith = true; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( BoostVector, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( BoostVector, RefinableSet, test_traits ); + +} // namespace + +#else // BOOST_VERSION < 104800 + // Skipped; for boost::container::vector you should use boost version 1.48 or above +#endif // BOOST_VERSION + +#endif // CDSUNIT_ENABLE_BOOST_CONTAINER diff --git a/test/unit/striped-set/set_std_list.cpp b/test/unit/striped-set/set_std_list.cpp new file mode 100644 index 00000000..225f6477 --- /dev/null +++ b/test/unit/striped-set/set_std_list.cpp @@ -0,0 +1,55 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef std::list< cds_test::container_set::int_item > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& list, iterator itInsert, iterator itWhat ) + { + list.insert( itInsert, *itWhat ); + } + }; + + static bool const c_hasFindWith = true; + static bool const c_hasEraseWith = true; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( StdList, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( StdList, RefinableSet, test_traits ); + +} // namespace diff --git a/test/unit/striped-set/set_std_set.cpp b/test/unit/striped-set/set_std_set.cpp new file mode 100644 index 00000000..0de7ee49 --- /dev/null +++ b/test/unit/striped-set/set_std_set.cpp @@ -0,0 +1,55 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef std::set< cds_test::container_set::int_item, cds_test::container_set::less > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& set, iterator itWhat ) + { + set.insert( *itWhat ); + } + }; + + static bool const c_hasFindWith = false; + static bool const c_hasEraseWith = false; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( StdSet, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( StdSet, RefinableSet, test_traits ); + +} // namespace diff --git a/test/unit/striped-set/set_std_unordered_set.cpp b/test/unit/striped-set/set_std_unordered_set.cpp new file mode 100644 index 00000000..d3aacf3e --- /dev/null +++ b/test/unit/striped-set/set_std_unordered_set.cpp @@ -0,0 +1,55 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef std::unordered_set< cds_test::container_set::int_item, cds_test::container_set::hash2, cds_test::container_set::equal_to > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& set, iterator itWhat ) + { + set.insert( *itWhat ); + } + }; + + static bool const c_hasFindWith = false; + static bool const c_hasEraseWith = false; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( StdUnorderedSet, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( StdUnorderedSet, RefinableSet, test_traits ); + +} // namespace diff --git a/test/unit/striped-set/set_std_vector.cpp b/test/unit/striped-set/set_std_vector.cpp new file mode 100644 index 00000000..85e475ba --- /dev/null +++ b/test/unit/striped-set/set_std_vector.cpp @@ -0,0 +1,55 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "test_striped_set.h" + +namespace { + struct test_traits + { + typedef std::vector< cds_test::container_set::int_item > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& list, iterator itInsert, iterator itWhat ) + { + list.insert( itInsert, *itWhat ); + } + }; + + static bool const c_hasFindWith = true; + static bool const c_hasEraseWith = true; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( StdVector, StripedSet, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( StdVector, RefinableSet, test_traits ); + +} // namespace diff --git a/test/unit/striped-set/test_set.h b/test/unit/striped-set/test_set.h index a678b90e..33a7d290 100644 --- a/test/unit/striped-set/test_set.h +++ b/test/unit/striped-set/test_set.h @@ -60,10 +60,20 @@ namespace cds_test { clear_stat(); } + stat( stat const& s ) + { + copy_stat( s ); + } + void clear_stat() { memset( this, 0, sizeof( *this ) ); } + + void copy_stat( stat const& s ) + { + memcpy( this, &s, sizeof( *this )); + } }; struct other_item { @@ -102,13 +112,15 @@ namespace cds_test { {} int_item( int_item const& src ) - : nKey( src.nKey ) + : stat( src ) + , nKey( src.nKey ) , nVal( src.nVal ) , strVal( src.strVal ) {} int_item( int_item&& src ) - : nKey( src.nKey ) + : stat( src ) + , nKey( src.nKey ) , nVal( src.nVal ) , strVal( std::move( src.strVal ) ) {} @@ -124,6 +136,28 @@ namespace cds_test { , nVal( s.key() * 2 ) {} + int_item& operator=( int_item const& src ) + { + if ( &src != this ) { + copy_stat( src ); + nKey = src.nKey; + nVal = src.nVal; + strVal = src.strVal; + } + return *this; + } + + int_item& operator=( int_item&& src ) + { + if ( &src != this ) { + copy_stat( src ); + nKey = src.nKey; + nVal = src.nVal; + strVal = std::move( src.strVal ); + } + return *this; + } + int key() const { return nKey; diff --git a/test/unit/striped-set/test_striped_set.h b/test/unit/striped-set/test_striped_set.h new file mode 100644 index 00000000..8ce32dc7 --- /dev/null +++ b/test/unit/striped-set/test_striped_set.h @@ -0,0 +1,768 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSUNIT_SET_TEST_STRIPED_SET_H +#define CDSUNIT_SET_TEST_STRIPED_SET_H + +#include "test_set.h" + +#include + +namespace { + namespace cc = cds::container; + + template + struct call_contains_with + { + bool operator()( Set& s, int key ) const + { + return s.contains( cds_test::container_set::other_item( key ), cds_test::container_set::other_less()); + } + }; + + template + struct call_contains_with + { + bool operator()( Set& s, int key ) const + { + return s.contains( key ); + } + }; + + template + struct call_find_with + { + template + bool operator()( Set& s, int key, Func f ) const + { + return s.find_with( cds_test::container_set::other_item( key ), cds_test::container_set::other_less(), f ); + } + }; + + template + struct call_find_with + { + template + bool operator()( Set& s, int key, Func f ) const + { + return s.find( key, [&f]( typename Set::value_type& v, int key ) { + cds_test::container_set::other_item oi( key ); + f( v, oi ); + }); + } + }; + + template + struct call_erase_with + { + bool operator()( Set& s, int key ) const + { + return s.erase_with( cds_test::container_set::other_item( key ), cds_test::container_set::other_less()); + } + + template + bool operator()( Set& s, int key, Func f ) const + { + return s.erase_with( cds_test::container_set::other_item( key ), cds_test::container_set::other_less(), f ); + } + }; + + template + struct call_erase_with + { + bool operator()( Set& s, int key ) const + { + return s.erase( key ); + } + + template + bool operator()( Set& s, int key, Func f ) const + { + return s.erase( key, f ); + } + }; + + template + class StripedSet : public cds_test::container_set + { + protected: + typedef cds_test::container_set base_class; + + typedef typename Traits::container_type container_type; + typedef typename Traits::copy_policy copy_policy; + + static bool const c_hasFindWith = Traits::c_hasFindWith; + static bool const c_hasEraseWith = Traits::c_hasEraseWith; + + //void SetUp() + //{} + + //void TearDown() + //{} + + template + void test( Set& s ) + { + // Precondition: set is empty + // Postcondition: set is empty + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + size_t const nSetSize = kSize; + + typedef typename Set::value_type value_type; + + std::vector< value_type > data; + std::vector< size_t> indices; + data.reserve( kSize ); + indices.reserve( kSize ); + for ( size_t key = 0; key < kSize; ++key ) { + data.push_back( value_type( static_cast(key) ) ); + indices.push_back( key ); + } + shuffle( indices.begin(), indices.end() ); + + // insert/find + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_FALSE( s.contains( i.nKey ) ); + ASSERT_FALSE( s.contains( i )); + ASSERT_FALSE( (call_contains_with< c_hasFindWith, Set >()( s, i.key()))); + ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} ) ); + ASSERT_FALSE( s.find( i, []( value_type&, value_type const& ) {} ) ); + ASSERT_FALSE( (call_find_with< c_hasFindWith, Set >()(s, i.key(), []( value_type&, other_item const& ) {} ))); + + std::pair updResult; + + std::string str; + updResult = s.update( i.key(), []( bool bNew, value_type&, int ) + { + ASSERT_TRUE( false ); + }, false ); + EXPECT_FALSE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + switch ( idx % 8 ) { + case 0: + ASSERT_TRUE( s.insert( i ) ); + ASSERT_FALSE( s.insert( i ) ); + updResult = s.update( i, []( bool bNew, value_type& val, value_type const& arg ) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( val.key(), arg.key() ); + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + break; + case 1: + ASSERT_TRUE( s.insert( i.key() ) ); + ASSERT_FALSE( s.insert( i.key() ) ); + updResult = s.update( i.key(), []( bool bNew, value_type& val, int arg ) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( val.key(), arg ); + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + break; + case 2: + ASSERT_TRUE( s.insert( i, []( value_type& v ) { ++v.nFindCount; } ) ); + ASSERT_FALSE( s.insert( i, []( value_type& v ) { ++v.nFindCount; } ) ); + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) + { + EXPECT_EQ( v.key(), key ); + EXPECT_EQ( v.nFindCount, 1 ); + } ) ); + break; + case 3: + ASSERT_TRUE( s.insert( i.key(), []( value_type& v ) { ++v.nFindCount; } ) ); + ASSERT_FALSE( s.insert( i.key(), []( value_type& v ) { ++v.nFindCount; } ) ); + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) + { + EXPECT_EQ( v.key(), key ); + EXPECT_EQ( v.nFindCount, 1 ); + } ) ); + break; + case 4: + updResult = s.update( i, []( bool bNew, value_type& v, value_type const& arg ) + { + EXPECT_TRUE( bNew ); + EXPECT_EQ( v.key(), arg.key() ); + ++v.nUpdateNewCount; + } ); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + + updResult = s.update( i, []( bool bNew, value_type& v, value_type const& arg ) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.key(), arg.key() ); + ++v.nUpdateNewCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) + { + EXPECT_EQ( v.key(), key ); + EXPECT_EQ( v.nUpdateNewCount, 2 ); + } ) ); + break; + case 5: + updResult = s.update( i.key(), []( bool bNew, value_type& v, int arg ) + { + EXPECT_TRUE( bNew ); + EXPECT_EQ( v.key(), arg ); + ++v.nUpdateNewCount; + } ); + EXPECT_TRUE( updResult.first ); + EXPECT_TRUE( updResult.second ); + + updResult = s.update( i.key(), []( bool bNew, value_type& v, int arg ) + { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.key(), arg ); + ++v.nUpdateNewCount; + }, false ); + EXPECT_TRUE( updResult.first ); + EXPECT_FALSE( updResult.second ); + + ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) + { + EXPECT_EQ( v.key(), arg.key() ); + EXPECT_EQ( v.nUpdateNewCount, 2 ); + } ) ); + break; + case 6: + ASSERT_TRUE( s.emplace( i.key() ) ); + ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) + { + EXPECT_EQ( v.key(), arg.key() ); + EXPECT_EQ( v.nVal, arg.nVal ); + } ) ); + break; + case 7: + str = "Hello!"; + ASSERT_TRUE( s.emplace( i.key(), std::move( str ) ) ); + EXPECT_TRUE( str.empty() ); + ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg ) + { + EXPECT_EQ( v.key(), arg.key() ); + EXPECT_EQ( v.nVal, arg.nVal ); + EXPECT_EQ( v.strVal, std::string( "Hello!" ) ); + } ) ); + break; + default: + // forgot anything?.. + ASSERT_TRUE( false ); + } + + ASSERT_TRUE( s.contains( i.nKey ) ); + ASSERT_TRUE( s.contains( i ) ); + ASSERT_TRUE( (call_contains_with< c_hasFindWith, Set>()( s, i.key() ))); + ASSERT_TRUE( s.find( i.nKey, []( value_type&, int ) {} ) ); + ASSERT_TRUE( s.find( i, []( value_type&, value_type const& ) {} ) ); + ASSERT_TRUE( (call_find_with< c_hasFindWith, Set >()(s, i.key(), []( value_type&, other_item const& ) {}))); + } + + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + // erase + shuffle( indices.begin(), indices.end() ); + for ( auto idx : indices ) { + auto& i = data[idx]; + + ASSERT_TRUE( s.contains( i.nKey ) ); + ASSERT_TRUE( s.contains( i ) ); + ASSERT_TRUE( (call_contains_with()(s, i.key()))); + ASSERT_TRUE( s.find( i.nKey, []( value_type& v, int ) + { + v.nFindCount = 1; + } )); + ASSERT_TRUE( s.find( i, []( value_type& v, value_type const& ) + { + EXPECT_EQ( ++v.nFindCount, 2 ); + } )); + ASSERT_TRUE( (call_find_with< c_hasFindWith, Set >()(s, i.key(), []( value_type& v, other_item const& ) { + EXPECT_EQ( ++v.nFindCount, 3 ); + }))); + + int nKey = i.key() - 1; + switch ( idx % 6 ) { + case 0: + ASSERT_TRUE( s.erase( i.key() ) ); + ASSERT_FALSE( s.erase( i.key() ) ); + break; + case 1: + ASSERT_TRUE( s.erase( i ) ); + ASSERT_FALSE( s.erase( i ) ); + break; + case 2: + ASSERT_TRUE( (call_erase_with()( s, i.key()))); + ASSERT_FALSE( (call_erase_with()(s, i.key()))); + break; + case 3: + ASSERT_TRUE( s.erase( i.key(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + } )); + EXPECT_EQ( i.key(), nKey ); + + nKey = i.key() - 1; + ASSERT_FALSE( s.erase( i.key(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + } ) ); + EXPECT_EQ( i.key(), nKey + 1 ); + break; + case 4: + ASSERT_TRUE( s.erase( i, [&nKey]( value_type const& v ) + { + nKey = v.key(); + } ) ); + EXPECT_EQ( i.key(), nKey ); + + nKey = i.key() - 1; + ASSERT_FALSE( s.erase( i, [&nKey]( value_type const& v ) + { + nKey = v.key(); + } ) ); + EXPECT_EQ( i.key(), nKey + 1 ); + break; + case 5: + ASSERT_TRUE( (call_erase_with()(s, i.key(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + }))); + EXPECT_EQ( i.key(), nKey ); + + nKey = i.key() - 1; + ASSERT_FALSE( (call_erase_with()(s, i.key(), [&nKey]( value_type const& v ) + { + nKey = v.key(); + }))); + EXPECT_EQ( i.key(), nKey + 1 ); + break; + } + + ASSERT_FALSE( s.contains( i.nKey ) ); + ASSERT_FALSE( s.contains( i ) ); + ASSERT_FALSE( (call_contains_with()( s, i.key()))); + ASSERT_FALSE( s.find( i.nKey, []( value_type&, int ) {} ) ); + ASSERT_FALSE( s.find( i, []( value_type&, value_type const& ) {} )); + ASSERT_FALSE( (call_find_with()( s, i.key(), []( value_type&, other_item const& ) {}))); + } + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + + + // clear + for ( auto& i : data ) { + ASSERT_TRUE( s.insert( i ) ); + } + + ASSERT_FALSE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, nSetSize ); + + s.clear(); + + ASSERT_TRUE( s.empty() ); + ASSERT_CONTAINER_SIZE( s, 0 ); + } + + }; + + template + class RefinableSet: public StripedSet< Traits > + {}; + + TYPED_TEST_CASE_P( StripedSet ); + TYPED_TEST_CASE_P( RefinableSet ); + +// **************************************************************** +// striped set + + TYPED_TEST_P( StripedSet, compare ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::mutex_policy< cc::striped_set::striping<>> + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( StripedSet, less ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less > + > set_type; + + set_type s; + this->test( s ); + } + + + TYPED_TEST_P( StripedSet, cmpmix ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp > + > set_type; + + set_type s( 32 ); + this->test( s ); + } + + TYPED_TEST_P( StripedSet, spinlock ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::striping>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp > + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( StripedSet, load_factor_resizing ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<4>> + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( StripedSet, load_factor_resizing_rt ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<0>> + > set_type; + + set_type s( 30, cc::striped_set::load_factor_resizing<0>( 8 )); + this->test( s ); + } + + TYPED_TEST_P( StripedSet, single_bucket_resizing ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<6>> + > set_type; + + set_type s( 30 ); + this->test( s ); + } + + TYPED_TEST_P( StripedSet, single_bucket_resizing_rt ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<0>> + > set_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + set_type s( 24, resizing_policy ); + this->test( s ); + } + + TYPED_TEST_P( StripedSet, copy_policy_copy ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<4>>, + cds::opt::copy_policy< cc::striped_set::copy_item > + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( StripedSet, copy_policy_move ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<0>>, + cds::opt::copy_policy< cc::striped_set::move_item > + > set_type; + + set_type s( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( s ); + } + + TYPED_TEST_P( StripedSet, copy_policy_swap ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<6>>, + cds::opt::copy_policy< cc::striped_set::swap_item > + > set_type; + + set_type s( 30 ); + this->test( s ); + } + + TYPED_TEST_P( StripedSet, copy_policy_special ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<0>>, + cds::opt::copy_policy< typename TestFixture::copy_policy > + > set_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + set_type s( 24, resizing_policy ); + this->test( s ); + } + + +// **************************************************************** +// refinable set + + TYPED_TEST_P( RefinableSet, compare ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp > + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, less ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less > + > set_type; + + set_type s; + this->test( s ); + } + + + TYPED_TEST_P( RefinableSet, cmpmix ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp > + > set_type; + + set_type s( 32 ); + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, spinlock ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp > + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, load_factor_resizing ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<4>> + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, load_factor_resizing_rt ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<0>> + > set_type; + + set_type s( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, single_bucket_resizing ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<6>> + > set_type; + + set_type s( 30 ); + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, single_bucket_resizing_rt ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<0>> + > set_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + set_type s( 24, resizing_policy ); + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, copy_policy_copy ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<4>>, + cds::opt::copy_policy< cc::striped_set::copy_item > + > set_type; + + set_type s; + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, copy_policy_move ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::load_factor_resizing<0>>, + cds::opt::copy_policy< cc::striped_set::move_item > + > set_type; + + set_type s( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, copy_policy_swap ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<6>>, + cds::opt::copy_policy< cc::striped_set::swap_item > + > set_type; + + set_type s( 30 ); + this->test( s ); + } + + TYPED_TEST_P( RefinableSet, copy_policy_special ) + { + typedef cc::StripedSet< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::resizing_policy< cc::striped_set::single_bucket_size_threshold<0>>, + cds::opt::copy_policy< typename TestFixture::copy_policy > + > set_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + set_type s( 24, resizing_policy ); + this->test( s ); + } + + REGISTER_TYPED_TEST_CASE_P( StripedSet, + compare, less, cmpmix, spinlock, load_factor_resizing, load_factor_resizing_rt, single_bucket_resizing, single_bucket_resizing_rt, copy_policy_copy, copy_policy_move, copy_policy_swap, copy_policy_special + ); + + REGISTER_TYPED_TEST_CASE_P( RefinableSet, + compare, less, cmpmix, spinlock, load_factor_resizing, load_factor_resizing_rt, single_bucket_resizing, single_bucket_resizing_rt, copy_policy_copy, copy_policy_move, copy_policy_swap, copy_policy_special + ); + +} // namespace + +#endif // CDSUNIT_SET_TEST_INTRUSIVE_STRIPED_SET_H -- 2.34.1