From 3957111c05b05d0b8c200c8cb50b5a3545dfd8d4 Mon Sep 17 00:00:00 2001 From: khizmax Date: Tue, 5 Apr 2016 23:35:11 +0300 Subject: [PATCH] Migrated a part of StripedMap unit test to gtest --- projects/Win/vc14/gtest-striped-map.vcxproj | 3 + .../vc14/gtest-striped-map.vcxproj.filters | 9 + test/unit/striped-map/CMakeLists.txt | 3 + test/unit/striped-map/cuckoo_map.cpp | 4 +- test/unit/striped-map/map_std_list.cpp | 55 ++ test/unit/striped-map/map_std_map.cpp | 55 ++ test/unit/striped-map/test_map.h | 2 +- test/unit/striped-map/test_striped_map.h | 830 ++++++++++++++++++ 8 files changed, 958 insertions(+), 3 deletions(-) create mode 100644 test/unit/striped-map/map_std_list.cpp create mode 100644 test/unit/striped-map/map_std_map.cpp create mode 100644 test/unit/striped-map/test_striped_map.h diff --git a/projects/Win/vc14/gtest-striped-map.vcxproj b/projects/Win/vc14/gtest-striped-map.vcxproj index 79bf993d..f8eee533 100644 --- a/projects/Win/vc14/gtest-striped-map.vcxproj +++ b/projects/Win/vc14/gtest-striped-map.vcxproj @@ -42,10 +42,13 @@ CDSUNIT_ENABLE_BOOST_CONTAINER;_SCL_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) CDSUNIT_ENABLE_BOOST_CONTAINER;_SCL_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + {00FD5CB8-E1A4-40CA-B613-30A06A75622B} diff --git a/projects/Win/vc14/gtest-striped-map.vcxproj.filters b/projects/Win/vc14/gtest-striped-map.vcxproj.filters index 3a4078e4..c61d1edd 100644 --- a/projects/Win/vc14/gtest-striped-map.vcxproj.filters +++ b/projects/Win/vc14/gtest-striped-map.vcxproj.filters @@ -21,6 +21,12 @@ Source Files + + Source Files + + + Source Files + @@ -29,5 +35,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/test/unit/striped-map/CMakeLists.txt b/test/unit/striped-map/CMakeLists.txt index a760a6d1..420f07a5 100644 --- a/test/unit/striped-map/CMakeLists.txt +++ b/test/unit/striped-map/CMakeLists.txt @@ -4,6 +4,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCDSUNIT_ENABLE_BOOST_CONTAINER") set(CDSGTEST_STRIPED_MAP_SOURCES ../main.cpp + cuckoo_map.cpp + map_std_list.cpp + map_std_map.cpp ) include_directories( diff --git a/test/unit/striped-map/cuckoo_map.cpp b/test/unit/striped-map/cuckoo_map.cpp index a287c969..c623fe5f 100644 --- a/test/unit/striped-map/cuckoo_map.cpp +++ b/test/unit/striped-map/cuckoo_map.cpp @@ -35,10 +35,10 @@ namespace { namespace cc = cds::container; - class CuckooMap : public cds_test::striped_map + class CuckooMap : public cds_test::container_map { protected: - typedef cds_test::striped_map base_class; + typedef cds_test::container_map base_class; template void test( Set& m ) diff --git a/test/unit/striped-map/map_std_list.cpp b/test/unit/striped-map/map_std_list.cpp new file mode 100644 index 00000000..c15c86f6 --- /dev/null +++ b/test/unit/striped-map/map_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_map.h" + +namespace { + struct test_traits + { + typedef std::list< std::pair< cds_test::striped_map_fixture::key_type const, cds_test::striped_map_fixture::value_type >> 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, StripedMap, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( StdList, RefinableMap, test_traits ); + +} // namespace diff --git a/test/unit/striped-map/map_std_map.cpp b/test/unit/striped-map/map_std_map.cpp new file mode 100644 index 00000000..92822d72 --- /dev/null +++ b/test/unit/striped-map/map_std_map.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_map.h" + +namespace { + struct test_traits + { + typedef std::map< cds_test::striped_map_fixture::key_type, cds_test::striped_map_fixture::value_type, cds_test::striped_map_fixture::less > container_type; + + struct copy_policy { + typedef container_type::iterator iterator; + + void operator()( container_type& m, iterator /*itInsert*/, iterator itWhat ) + { + m.insert( *itWhat ); + } + }; + + static bool const c_hasFindWith = false; + static bool const c_hasEraseWith = false; + }; + + INSTANTIATE_TYPED_TEST_CASE_P( StdMap, StripedMap, test_traits ); + INSTANTIATE_TYPED_TEST_CASE_P( StdMap, RefinableMap, test_traits ); + +} // namespace diff --git a/test/unit/striped-map/test_map.h b/test/unit/striped-map/test_map.h index e1e615f4..4a25dc6f 100644 --- a/test/unit/striped-map/test_map.h +++ b/test/unit/striped-map/test_map.h @@ -38,7 +38,7 @@ namespace cds { namespace container {} } namespace cds_test { - class striped_map: public striped_map_fixture + class container_map: public striped_map_fixture { public: static size_t const kSize = 1000; diff --git a/test/unit/striped-map/test_striped_map.h b/test/unit/striped-map/test_striped_map.h new file mode 100644 index 00000000..b39acb43 --- /dev/null +++ b/test/unit/striped-map/test_striped_map.h @@ -0,0 +1,830 @@ +/* + 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_STRIPED_MAP_TEST_STRIPED_MAP_H +#define CDSUNIT_STRIPED_MAP_TEST_STRIPED_MAP_H + +#include "test_map_data.h" + +#include + +namespace { + namespace cc = cds::container; + + template + struct call_contains_with + { + bool operator()( Map& m, int key ) const + { + return m.contains( cds_test::striped_map_fixture::other_item( key ), cds_test::striped_map_fixture::other_less() ); + } + }; + + template + struct call_contains_with + { + bool operator()( Map& m, int key ) const + { + return m.contains( key ); + } + }; + + template + struct call_find_with + { + template + bool operator()( Map& m, int key, Func f ) const + { + return m.find_with( cds_test::striped_map_fixture::other_item( key ), cds_test::striped_map_fixture::other_less(), f ); + } + }; + + template + struct call_find_with + { + template + bool operator()( Map& m, int key, Func f ) const + { + return m.find( key, f ); + } + }; + + template + struct call_erase_with + { + bool operator()( Map& m, int key ) const + { + return m.erase_with( cds_test::striped_map_fixture::other_item( key ), cds_test::striped_map_fixture::other_less() ); + } + + template + bool operator()( Map& m, int key, Func f ) const + { + return m.erase_with( cds_test::striped_map_fixture::other_item( key ), cds_test::striped_map_fixture::other_less(), f ); + } + }; + + template + struct call_erase_with + { + bool operator()( Map& m, int key ) const + { + return m.erase( key ); + } + + template + bool operator()( Map& m, int key, Func f ) const + { + return m.erase( key, f ); + } + }; + + template + class StripedMap: public cds_test::striped_map_fixture + { + public: + static size_t const kSize = 1000; + + protected: + 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( Map& m ) + { + // Precondition: map is empty + // Postcondition: map is empty + + ASSERT_TRUE( m.empty()); + ASSERT_CONTAINER_SIZE( m, 0 ); + + typedef typename Map::value_type map_pair; + + size_t const kkSize = kSize; + + std::vector arrKeys; + for ( int i = 0; i < static_cast(kkSize); ++i ) + arrKeys.push_back( key_type( i )); + shuffle( arrKeys.begin(), arrKeys.end()); + + std::vector< value_type > arrVals; + for ( size_t i = 0; i < kkSize; ++i ) { + value_type val; + val.nVal = static_cast( i ); + val.strVal = std::to_string( i ); + arrVals.push_back( val ); + } + + // insert/find + for ( auto const& i : arrKeys ) { + value_type const& val( arrVals.at( i.nKey )); + + ASSERT_FALSE( m.contains( i.nKey )); + ASSERT_FALSE( m.contains( i )); + ASSERT_FALSE(( call_contains_with()( m, i.nKey ) )); + ASSERT_FALSE( m.find( i, []( map_pair const& ) { + ASSERT_TRUE( false ); + } )); + ASSERT_FALSE( m.find( i.nKey, []( map_pair const& ) { + EXPECT_TRUE( false ); + } )); + ASSERT_FALSE(( call_find_with< c_hasFindWith, Map>()( m, i.nKey, []( map_pair const& ) { + EXPECT_TRUE( false ); + } ))); + + std::pair< bool, bool > updResult; + + switch ( i.nKey % 16 ) { + case 0: + ASSERT_TRUE( m.insert( i )); + ASSERT_FALSE( m.insert( i )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 1: + ASSERT_TRUE( m.insert( i.nKey )); + ASSERT_FALSE( m.insert( i.nKey )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 2: + ASSERT_TRUE( m.insert( std::to_string( i.nKey ))); + ASSERT_FALSE( m.insert( std::to_string( i.nKey ))); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 3: + ASSERT_TRUE( m.insert( i, val )); + ASSERT_FALSE( m.insert( i, val )); + break; + case 4: + ASSERT_TRUE( m.insert( i.nKey, val.strVal )); + ASSERT_FALSE( m.insert( i.nKey, val.strVal )); + break; + case 5: + ASSERT_TRUE( m.insert( val.strVal, i.nKey )); + ASSERT_FALSE( m.insert( val.strVal, i.nKey )); + break; + case 6: + ASSERT_TRUE( m.insert_with( i, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + ASSERT_FALSE( m.insert_with( i, []( map_pair& v ) { + EXPECT_TRUE( false ); + } )); + break; + case 7: + ASSERT_TRUE( m.insert_with( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + ASSERT_FALSE( m.insert_with( i.nKey, []( map_pair& v ) { + EXPECT_TRUE( false ); + } )); + break; + case 8: + ASSERT_TRUE( m.insert_with( val.strVal, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + ASSERT_FALSE( m.insert_with( val.strVal, []( map_pair& v ) { + EXPECT_TRUE( false ); + } )); + break; + case 9: + updResult = m.update( i.nKey, []( bool, map_pair& ) { + EXPECT_TRUE( false ); + }, false ); + ASSERT_FALSE( updResult.first ); + ASSERT_FALSE( updResult.second ); + + updResult = m.update( i.nKey, []( bool bNew, map_pair& v ) { + EXPECT_TRUE( bNew ); + v.second.nVal = v.first.nKey; + }); + ASSERT_TRUE( updResult.first ); + ASSERT_TRUE( updResult.second ); + + updResult = m.update( i.nKey, []( bool bNew, map_pair& v ) { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.first.nKey, v.second.nVal ); + v.second.strVal = std::to_string( v.second.nVal ); + } ); + ASSERT_TRUE( updResult.first ); + ASSERT_FALSE( updResult.second ); + break; + case 10: + updResult = m.update( i, []( bool, map_pair& ) { + EXPECT_TRUE( false ); + }, false ); + ASSERT_FALSE( updResult.first ); + ASSERT_FALSE( updResult.second ); + + updResult = m.update( i, []( bool bNew, map_pair& v ) { + EXPECT_TRUE( bNew ); + v.second.nVal = v.first.nKey; + }); + ASSERT_TRUE( updResult.first ); + ASSERT_TRUE( updResult.second ); + + updResult = m.update( i, []( bool bNew, map_pair& v ) { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.first.nKey, v.second.nVal ); + v.second.strVal = std::to_string( v.second.nVal ); + } ); + ASSERT_TRUE( updResult.first ); + ASSERT_FALSE( updResult.second ); + break; + case 11: + updResult = m.update( val.strVal, []( bool, map_pair& ) { + EXPECT_TRUE( false ); + }, false ); + ASSERT_FALSE( updResult.first ); + ASSERT_FALSE( updResult.second ); + + updResult = m.update( val.strVal, []( bool bNew, map_pair& v ) { + EXPECT_TRUE( bNew ); + v.second.nVal = v.first.nKey; + }); + ASSERT_TRUE( updResult.first ); + ASSERT_TRUE( updResult.second ); + + updResult = m.update( val.strVal, []( bool bNew, map_pair& v ) { + EXPECT_FALSE( bNew ); + EXPECT_EQ( v.first.nKey, v.second.nVal ); + v.second.strVal = std::to_string( v.second.nVal ); + } ); + ASSERT_TRUE( updResult.first ); + ASSERT_FALSE( updResult.second ); + break; + case 12: + ASSERT_TRUE( m.emplace( i.nKey )); + ASSERT_FALSE( m.emplace( i.nKey )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair& v ) { + v.second.nVal = v.first.nKey; + v.second.strVal = std::to_string( v.first.nKey ); + } )); + break; + case 13: + ASSERT_TRUE( m.emplace( i, i.nKey )); + ASSERT_FALSE( m.emplace( i, i.nKey )); + break; + case 14: + { + std::string str = val.strVal; + ASSERT_TRUE( m.emplace( i, std::move( str ))); + ASSERT_TRUE( str.empty()); + str = val.strVal; + ASSERT_FALSE( m.emplace( i, std::move( str ))); + ASSERT_TRUE( str.empty()); + } + break; + case 15: + { + std::string str = val.strVal; + ASSERT_TRUE( m.emplace( i, i.nKey, std::move( str ))); + ASSERT_TRUE( str.empty()); + str = val.strVal; + ASSERT_FALSE( m.emplace( i, i.nKey, std::move( str ))); + ASSERT_TRUE( str.empty()); + } + break; + } + + ASSERT_TRUE( m.contains( i.nKey )); + ASSERT_TRUE( m.contains( i )); + ASSERT_TRUE(( call_contains_with()( m, i.nKey ) )); + ASSERT_TRUE( m.find( i, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE(( call_find_with()( m, i.nKey, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } ))); + } + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + shuffle( arrKeys.begin(), arrKeys.end() ); + + // erase/find + for ( auto const& i : arrKeys ) { + value_type const& val( arrVals.at( i.nKey ) ); + + ASSERT_TRUE( m.contains( i.nKey )); + ASSERT_TRUE( m.contains( val.strVal ) ); + ASSERT_TRUE( m.contains( i )); + ASSERT_TRUE(( call_contains_with()( m, i.nKey ))); + ASSERT_TRUE( m.find( i, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE( m.find( i.nKey, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } )); + ASSERT_TRUE(( call_find_with()( m, i.nKey, []( map_pair const& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + } ))); + + + switch ( i.nKey % 8 ) { + case 0: + ASSERT_TRUE( m.erase( i )); + ASSERT_FALSE( m.erase( i )); + break; + case 1: + ASSERT_TRUE( m.erase( i.nKey )); + ASSERT_FALSE( m.erase( i.nKey )); + break; + case 2: + ASSERT_TRUE( m.erase( val.strVal )); + ASSERT_FALSE( m.erase( val.strVal )); + break; + case 3: + ASSERT_TRUE(( call_erase_with< c_hasEraseWith, Map>()( m, i.nKey ))); + ASSERT_FALSE(( call_erase_with< c_hasEraseWith, Map>()( m, i.nKey ))); + break; + case 4: + ASSERT_TRUE( m.erase( i, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase( i, []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + case 5: + ASSERT_TRUE( m.erase( i.nKey, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase( i.nKey, []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + case 6: + ASSERT_TRUE( m.erase( val.strVal, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + })); + ASSERT_FALSE( m.erase( val.strVal, []( map_pair& ) { + EXPECT_TRUE( false ); + })); + break; + case 7: + ASSERT_TRUE(( call_erase_with< c_hasEraseWith, Map >()( m, i.nKey, []( map_pair& v ) { + EXPECT_EQ( v.first.nKey, v.second.nVal ); + EXPECT_EQ( std::to_string( v.first.nKey ), v.second.strVal ); + }))); + ASSERT_FALSE(( call_erase_with< c_hasEraseWith, Map >()( m, i.nKey, []( map_pair& ) { + EXPECT_TRUE( false ); + }))); + break; + } + + ASSERT_FALSE( m.contains( i.nKey )); + ASSERT_FALSE( m.contains( i )); + ASSERT_FALSE( m.contains( val.strVal )); + ASSERT_FALSE(( call_contains_with< c_hasFindWith, Map >()( m, i.nKey ))); + ASSERT_FALSE( m.find( i, []( map_pair const& ) { + ASSERT_TRUE( false ); + } )); + ASSERT_FALSE( m.find( i.nKey, []( map_pair const& ) { + EXPECT_TRUE( false ); + } )); + ASSERT_FALSE(( call_find_with< c_hasFindWith, Map >()( m, i.nKey, []( map_pair const& ) { + EXPECT_TRUE( false ); + } ))); + } + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + + // clear + for ( auto const& i : arrKeys ) + ASSERT_TRUE( m.insert( i )); + + ASSERT_FALSE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, kkSize ); + + m.clear(); + + ASSERT_TRUE( m.empty() ); + ASSERT_CONTAINER_SIZE( m, 0 ); + } + }; + + template + class RefinableMap: public StripedMap< Traits > + {}; + + TYPED_TEST_CASE_P( StripedMap ); + TYPED_TEST_CASE_P( RefinableMap ); + + + // **************************************************************** + // striped map + + TYPED_TEST_P( StripedMap, compare ) + { + typedef cc::StripedMap< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp >, + cds::opt::mutex_policy< cc::striped_set::striping<>> + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( StripedMap, less ) + { + typedef cc::StripedMap< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less > + > map_type; + + map_type m; + this->test( m ); + } + + + TYPED_TEST_P( StripedMap, cmpmix ) + { + typedef cc::StripedMap< + typename TestFixture::container_type, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less >, + cds::opt::compare< typename TestFixture::cmp > + > map_type; + + map_type m( 32 ); + this->test( m ); + } + + TYPED_TEST_P( StripedMap, spinlock ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( StripedMap, load_factor_resizing ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( StripedMap, load_factor_resizing_rt ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + map_type m( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( m ); + } + + TYPED_TEST_P( StripedMap, single_bucket_resizing ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + map_type m( 30 ); + this->test( m ); + } + + TYPED_TEST_P( StripedMap, single_bucket_resizing_rt ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + map_type m( 24, resizing_policy ); + this->test( m ); + } + + TYPED_TEST_P( StripedMap, copy_policy_copy ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( StripedMap, copy_policy_move ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( m ); + } + + TYPED_TEST_P( StripedMap, copy_policy_swap ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m( 30 ); + this->test( m ); + } + + TYPED_TEST_P( StripedMap, copy_policy_special ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + map_type m( 24, resizing_policy ); + this->test( m ); + } + + + // **************************************************************** + // refinable map + + TYPED_TEST_P( RefinableMap, compare ) + { + typedef cc::StripedMap< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::compare< typename TestFixture::cmp > + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, less ) + { + typedef cc::StripedMap< + typename TestFixture::container_type, + cds::opt::mutex_policy< cc::striped_set::refinable<>>, + cds::opt::hash< typename TestFixture::hash1 >, + cds::opt::less< typename TestFixture::less > + > map_type; + + map_type m; + this->test( m ); + } + + + TYPED_TEST_P( RefinableMap, cmpmix ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m( 32 ); + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, spinlock ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, load_factor_resizing ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, load_factor_resizing_rt ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + map_type m( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, single_bucket_resizing ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + map_type m( 30 ); + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, single_bucket_resizing_rt ) + { + typedef cc::StripedMap< + 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>> + > map_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + map_type m( 24, resizing_policy ); + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, copy_policy_copy ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m; + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, copy_policy_move ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m( 30, cc::striped_set::load_factor_resizing<0>( 8 ) ); + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, copy_policy_swap ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + map_type m( 30 ); + this->test( m ); + } + + TYPED_TEST_P( RefinableMap, copy_policy_special ) + { + typedef cc::StripedMap< + 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 > + > map_type; + + cc::striped_set::single_bucket_size_threshold<0> resizing_policy( 8 ); + map_type m( 24, resizing_policy ); + this->test( m ); + } + + REGISTER_TYPED_TEST_CASE_P( StripedMap, + 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( RefinableMap, + 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 // #ifndef CDSUNIT_STRIPED_MAP_TEST_STRIPED_MAP_H -- 2.34.1