From 677119b93c6eff63ed955679dff21973e9efd9f9 Mon Sep 17 00:00:00 2001 From: khizmax Date: Mon, 14 Sep 2015 23:17:50 +0300 Subject: [PATCH] Added support for MS VC++ 2015 Removed deprecated functions ensure() and find(key) from tree unit tests --- cds/compiler/vc/defs.h | 3 + cds/details/lib.h | 4 +- .../Win/vc14/hdr-test-striped-set.vcxproj | 8 +- tests/test-hdr/set/hdr_cuckoo_set.cpp | 5 - tests/test-hdr/set/hdr_cuckoo_set.h | 71 +++++----- tests/test-hdr/set/hdr_intrusive_cuckoo_set.h | 33 ++--- .../test-hdr/set/hdr_intrusive_striped_set.h | 51 ++++---- tests/test-hdr/set/hdr_striped_set.h | 122 +++++++++--------- 8 files changed, 154 insertions(+), 143 deletions(-) diff --git a/cds/compiler/vc/defs.h b/cds/compiler/vc/defs.h index 9fe924f0..596a7a3d 100644 --- a/cds/compiler/vc/defs.h +++ b/cds/compiler/vc/defs.h @@ -20,12 +20,15 @@ #if _MSC_VER == 1800 # define CDS_COMPILER__NAME "MS Visual C++ 2013" # define CDS_COMPILER__NICK "vc12" +# define CDS_COMPILER_LIBCDS_SUFFIX "vc12" #elif _MSC_VER == 1900 # define CDS_COMPILER__NAME "MS Visual C++ 2015" # define CDS_COMPILER__NICK "vc14" +# define CDS_COMPILER_LIBCDS_SUFFIX "vcv140" #else # define CDS_COMPILER__NAME "MS Visual C++" # define CDS_COMPILER__NICK "msvc" +# define CDS_COMPILER_LIBCDS_SUFFIX "vc" #endif // OS interface diff --git a/cds/details/lib.h b/cds/details/lib.h index e129e6c9..73b4f43b 100644 --- a/cds/details/lib.h +++ b/cds/details/lib.h @@ -15,9 +15,9 @@ #endif #if CDS_COMPILER == CDS_COMPILER_MSVC -# pragma comment( lib, "libcds-" CDS_PROCESSOR__NICK "-" CDS_COMPILER__NICK CDS_LIB_DEBUG_SUFFIX ) +# pragma comment( lib, "libcds-" CDS_PROCESSOR__NICK "-" CDS_COMPILER_LIBCDS_SUFFIX CDS_LIB_DEBUG_SUFFIX ) #elif CDS_COMPILER == CDS_COMPILER_INTEL -# pragma comment( lib, "libcds-" CDS_PROCESSOR__NICK "-" CDS_COMPILER__NICK CDS_LIB_DEBUG_SUFFIX ) +# pragma comment( lib, "libcds-" CDS_PROCESSOR__NICK "-" CDS_COMPILER_LIBCDS_SUFFIX CDS_LIB_DEBUG_SUFFIX ) #endif #undef CDS_LIB_DEBUG_SUFFIX diff --git a/projects/Win/vc14/hdr-test-striped-set.vcxproj b/projects/Win/vc14/hdr-test-striped-set.vcxproj index 22dfaceb..d7e2bde1 100644 --- a/projects/Win/vc14/hdr-test-striped-set.vcxproj +++ b/projects/Win/vc14/hdr-test-striped-set.vcxproj @@ -262,7 +262,7 @@ /bigobj /Zc:inline %(AdditionalOptions) Disabled $(SolutionDir)..\..\..;$(SolutionDir)..\..\..\tests\test-hdr;$(SolutionDir)..\..\..\tests;$(BOOST_PATH);%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions);_SCL_SECURE_NO_WARNINGS true EnableFastChecks MultiThreadedDebugDLL @@ -322,7 +322,7 @@ /bigobj /Zc:inline %(AdditionalOptions) Disabled $(SolutionDir)..\..\..;$(SolutionDir)..\..\..\tests\test-hdr;$(SolutionDir)..\..\..\tests;$(BOOST_PATH);%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions);_SCL_SECURE_NO_WARNINGS true EnableFastChecks MultiThreadedDebugDLL @@ -535,7 +535,7 @@ /bigobj /Zc:inline %(AdditionalOptions) Disabled $(SolutionDir)..\..\..;$(SolutionDir)..\..\..\tests\test-hdr;$(SolutionDir)..\..\..\tests;$(BOOST_PATH);%(AdditionalIncludeDirectories) - CDS_USE_VLD;WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions) + CDS_USE_VLD;WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions);_SCL_SECURE_NO_WARNINGS true EnableFastChecks MultiThreadedDebugDLL @@ -567,7 +567,7 @@ /bigobj /Zc:inline %(AdditionalOptions) Disabled $(SolutionDir)..\..\..;$(SolutionDir)..\..\..\tests\test-hdr;$(SolutionDir)..\..\..\tests;$(BOOST_PATH);%(AdditionalIncludeDirectories) - CDS_USE_VLD;WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions) + CDS_USE_VLD;WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;_SCL_SECURE=0;%(PreprocessorDefinitions);_SCL_SECURE_NO_WARNINGS true EnableFastChecks MultiThreadedDebugDLL diff --git a/tests/test-hdr/set/hdr_cuckoo_set.cpp b/tests/test-hdr/set/hdr_cuckoo_set.cpp index b88f6449..546d1393 100644 --- a/tests/test-hdr/set/hdr_cuckoo_set.cpp +++ b/tests/test-hdr/set/hdr_cuckoo_set.cpp @@ -13,11 +13,6 @@ namespace set { }; typedef cc::CuckooSet< item, set_traits > set_t; - // cc::cuckoo::make_traits< - // co::equal_to< equal< item > > - // ,co::hash< std::tuple< hash1, hash2 > > - // >::type - //> set_t; test_int >(); } diff --git a/tests/test-hdr/set/hdr_cuckoo_set.h b/tests/test-hdr/set/hdr_cuckoo_set.h index 36742936..58ea036e 100644 --- a/tests/test-hdr/set/hdr_cuckoo_set.h +++ b/tests/test-hdr/set/hdr_cuckoo_set.h @@ -29,8 +29,8 @@ namespace set { struct stat { unsigned int nFindCount ; // count of find-functor calling - unsigned int nEnsureNewCount; - unsigned int nEnsureCount; + unsigned int nUpdateNewCount; + unsigned int nUpdateCount; stat() { @@ -40,8 +40,8 @@ namespace set { void copy( stat const& s ) { nFindCount = s.nFindCount; - nEnsureCount = s.nEnsureCount; - nEnsureNewCount = s.nEnsureNewCount; + nUpdateCount = s.nUpdateCount; + nUpdateNewCount = s.nUpdateNewCount; } }; @@ -306,20 +306,20 @@ namespace set { }; template - static void ensure_func( bool bNew, Item& i, Q& /*val*/ ) + static void update_func( bool bNew, Item& i, Q& /*val*/ ) { if ( bNew ) - ++i.nEnsureNewCount; + ++i.nUpdateNewCount; else - ++i.nEnsureCount; + ++i.nUpdateCount; } - struct ensure_functor + struct update_functor { template void operator()( bool bNew, Item& i, Q& val ) { - ensure_func( bNew, i, val ); + update_func( bNew, i, val ); } }; @@ -332,22 +332,22 @@ namespace set { int key; // insert/find test - CPPUNIT_ASSERT( !s.find( 10 ) ); + CPPUNIT_ASSERT( !s.contains( 10 ) ); CPPUNIT_ASSERT( s.insert( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); - CPPUNIT_ASSERT( s.find( 10 ) ); + CPPUNIT_ASSERT( s.contains( 10 ) ); CPPUNIT_ASSERT( !s.insert( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); - CPPUNIT_ASSERT( !s.find_with( 20, pred ) ); + CPPUNIT_ASSERT( !s.contains( 20, pred ) ); CPPUNIT_ASSERT( s.insert( std::make_pair(20, 25) )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( s.find_with( 10, pred ) ); - CPPUNIT_ASSERT( s.find( key = 20 ) ); + CPPUNIT_ASSERT( s.contains( 10, pred ) ); + CPPUNIT_ASSERT( s.contains( key = 20 ) ); CPPUNIT_ASSERT( s.find_with( key, pred, find_functor() ) ); { copy_found f; @@ -368,7 +368,7 @@ namespace set { CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( !s.find( 25 ) ); + CPPUNIT_ASSERT( !s.contains( 25 ) ); CPPUNIT_ASSERT( s.insert( std::make_pair(25, -1), insert_functor() )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); @@ -380,18 +380,18 @@ namespace set { CPPUNIT_ASSERT( f.m_found.nVal == 2500 ); } - // ensure test + // update() test key = 10; { copy_found f; CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 10 ); CPPUNIT_ASSERT( f.m_found.nVal == 10 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 0 ); } - std::pair ensureResult = s.ensure( key, ensure_functor() ); - CPPUNIT_ASSERT( ensureResult.first && !ensureResult.second ); + std::pair updateResult = s.update( key, update_functor() ); + CPPUNIT_ASSERT( updateResult.first && !updateResult.second ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); { @@ -399,12 +399,15 @@ namespace set { CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 10 ); CPPUNIT_ASSERT( f.m_found.nVal == 10 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 1 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 1 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 0 ); } - ensureResult = s.ensure( std::make_pair(13, 1300), ensure_functor() ); - CPPUNIT_ASSERT( ensureResult.first && ensureResult.second ); + updateResult = s.update(std::make_pair(13, 1300), update_functor(), false); + CPPUNIT_ASSERT(!updateResult.first && !updateResult.second); + + updateResult = s.update( std::make_pair(13, 1300), update_functor() ); + CPPUNIT_ASSERT( updateResult.first && updateResult.second ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 4 )); { @@ -413,29 +416,29 @@ namespace set { CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 13 ); CPPUNIT_ASSERT( f.m_found.nVal == 1300 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 1 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 1 ); } // erase test CPPUNIT_ASSERT( s.erase(13) ); - CPPUNIT_ASSERT( !s.find( 13 )); + CPPUNIT_ASSERT( !s.contains( 13 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); CPPUNIT_ASSERT( !s.erase(13) ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); - CPPUNIT_ASSERT( s.find( 10 )); + CPPUNIT_ASSERT( s.contains( 10 )); CPPUNIT_ASSERT( s.erase_with( 10, pred )); - CPPUNIT_ASSERT( !s.find( 10 )); + CPPUNIT_ASSERT( !s.contains( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); CPPUNIT_ASSERT( !s.erase_with(10, pred) ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( s.find(20) ); + CPPUNIT_ASSERT( s.contains(20) ); { copy_found f; CPPUNIT_ASSERT( s.erase( 20, std::ref( f ) ) ); @@ -447,7 +450,7 @@ namespace set { CPPUNIT_ASSERT( f.m_found.nKey == 235 ); CPPUNIT_ASSERT( f.m_found.nVal == 235 ); } - CPPUNIT_ASSERT( !s.find( 20 )); + CPPUNIT_ASSERT( !s.contains( 20 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); @@ -462,9 +465,9 @@ namespace set { CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); - CPPUNIT_ASSERT( s.find(151)); - CPPUNIT_ASSERT( s.find_with(174, pred )); - CPPUNIT_ASSERT( s.find(190)); + CPPUNIT_ASSERT( s.contains(151)); + CPPUNIT_ASSERT( s.contains(174, pred )); + CPPUNIT_ASSERT( s.contains(190)); { copy_found f; diff --git a/tests/test-hdr/set/hdr_intrusive_cuckoo_set.h b/tests/test-hdr/set/hdr_intrusive_cuckoo_set.h index db09fd5e..7965126e 100644 --- a/tests/test-hdr/set/hdr_intrusive_cuckoo_set.h +++ b/tests/test-hdr/set/hdr_intrusive_cuckoo_set.h @@ -196,7 +196,7 @@ namespace set { } }; - struct ensure_functor { + struct update_functor { template void operator()( bool bNew, Item& e, Item& arg ) { @@ -309,16 +309,16 @@ namespace set { CPPUNIT_ASSERT( s.empty() ); CPPUNIT_ASSERT( s.size() == 0 ); - CPPUNIT_ASSERT( !s.find(k1)); - CPPUNIT_ASSERT( !s.find_with(k2, typename std::conditional::type() )); - CPPUNIT_ASSERT( !s.find(k3)); + CPPUNIT_ASSERT( !s.contains(k1)); + CPPUNIT_ASSERT( !s.contains(k2, typename std::conditional::type() )); + CPPUNIT_ASSERT( !s.contains(k3)); CPPUNIT_ASSERT( s.insert(e1)); - CPPUNIT_ASSERT( s.find(e1)); - CPPUNIT_ASSERT( s.find(k1)); - CPPUNIT_ASSERT( s.find_with(k1, typename std::conditional::type())); - CPPUNIT_ASSERT( !s.find(e2)); - CPPUNIT_ASSERT( !s.find(e3)); + CPPUNIT_ASSERT( s.contains(e1)); + CPPUNIT_ASSERT( s.contains(k1)); + CPPUNIT_ASSERT( s.contains(k1, typename std::conditional::type())); + CPPUNIT_ASSERT( !s.contains(e2)); + CPPUNIT_ASSERT( !s.contains(e3)); CPPUNIT_ASSERT( e2.nInsertCount == 0 ); CPPUNIT_ASSERT( s.insert(e2, insert_functor() )); @@ -346,7 +346,10 @@ namespace set { CPPUNIT_ASSERT( e3.nEnsureNewCount == 0 ); CPPUNIT_ASSERT( e3.nEnsureCount == 0 ); - CPPUNIT_ASSERT( s.ensure( e3, ensure_functor() ) == std::make_pair(true, true)); + CPPUNIT_ASSERT(s.update(e3, update_functor(), false) == std::make_pair(false, false)); + CPPUNIT_ASSERT(e3.nEnsureNewCount == 0); + CPPUNIT_ASSERT(e3.nEnsureCount == 0); + CPPUNIT_ASSERT( s.update( e3, update_functor() ) == std::make_pair(true, true)); CPPUNIT_ASSERT( e3.nEnsureNewCount == 1 ); CPPUNIT_ASSERT( e3.nEnsureCount == 0 ); CPPUNIT_ASSERT( s.find_with(find_key(k1), typename std::conditional::type(), find_functor() )); @@ -358,10 +361,10 @@ namespace set { CPPUNIT_ASSERT( s.find_with(k2, typename std::conditional::type(), find_functor() )); CPPUNIT_ASSERT( e2.nFindCount == s2.nFindCount + 1 ); CPPUNIT_ASSERT( e2.nFindArgCount == s2.nFindArgCount ); - CPPUNIT_ASSERT( s.find_with(find_key(k2), typename std::conditional::type() )); + CPPUNIT_ASSERT( s.contains(find_key(k2), typename std::conditional::type() )); CPPUNIT_ASSERT( e2.nFindCount == s2.nFindCount + 1 ) ; // unchanged, no find_functor CPPUNIT_ASSERT( e2.nFindArgCount == s2.nFindArgCount ); - CPPUNIT_ASSERT( s.find_with(k3, typename std::conditional::type() )); + CPPUNIT_ASSERT( s.contains(k3, typename std::conditional::type() )); CPPUNIT_ASSERT( e3.nFindCount == s3.nFindCount ) ; // unchanged, no find_functor CPPUNIT_ASSERT( e3.nFindArgCount == s3.nFindArgCount ); CPPUNIT_ASSERT( s.find_with(find_key(k3), typename std::conditional::type(), find_functor() )); @@ -377,7 +380,7 @@ namespace set { CPPUNIT_ASSERT( !s.insert( eu, insert_functor() )); CPPUNIT_ASSERT( e2.nInsertCount == s2.nInsertCount ); - CPPUNIT_ASSERT( s.ensure( eu, ensure_functor()) == std::make_pair(true, false)); + CPPUNIT_ASSERT( s.update( eu, update_functor()) == std::make_pair(true, false)); CPPUNIT_ASSERT( e2.nInsertCount == s2.nInsertCount ); CPPUNIT_ASSERT( e2.nEnsureCount == s2.nEnsureCount + 1 ); CPPUNIT_ASSERT( e2.nEnsureNewCount == s2.nEnsureNewCount ); @@ -447,14 +450,14 @@ namespace set { CPPUNIT_ASSERT_EX( s.insert( *p, insert_functor() ), "i=" << i ); CPPUNIT_ASSERT_EX( p->nInsertCount == 1, "i=" << i ); //for ( size_t j = 0; j <= i; ++j ) { - // if ( !s.find((int) j) ) { + // if ( !s.contains((int) j) ) { // CPPUNIT_MSG( "Key " << j << " is not found after inserting key " << i ); // } //} } for ( size_t i = 0; i < nSize; ++i ) - CPPUNIT_ASSERT_EX( s.find((int) i), "Key " << i << " is not found" ); + CPPUNIT_ASSERT_EX( s.contains((int) i), "Key " << i << " is not found" ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( s.size() == nSize ); diff --git a/tests/test-hdr/set/hdr_intrusive_striped_set.h b/tests/test-hdr/set/hdr_intrusive_striped_set.h index 36243a65..a67f99cd 100644 --- a/tests/test-hdr/set/hdr_intrusive_striped_set.h +++ b/tests/test-hdr/set/hdr_intrusive_striped_set.h @@ -23,8 +23,8 @@ namespace set { unsigned int nFindCount ; // count of find-functor calling unsigned int nFindArgCount; unsigned int nInsertCount; - unsigned int nEnsureNewCount; - unsigned int nEnsureCount; + unsigned int nUpdateNewCount; + unsigned int nUpdateCount; unsigned int nEraseCount; stat() @@ -196,16 +196,16 @@ namespace set { } }; - struct ensure_functor { + struct update_functor { template void operator()( bool bNew, Item& e, Item& arg ) { if ( bNew ) { - ++e.nEnsureNewCount; + ++e.nUpdateNewCount; CPPUNIT_ASSERT_CURRENT( &e == &arg ); } else - ++e.nEnsureCount; + ++e.nUpdateCount; } }; @@ -286,15 +286,15 @@ namespace set { CPPUNIT_ASSERT( s.empty() ); CPPUNIT_ASSERT( s.size() == 0 ); - CPPUNIT_ASSERT( !s.find(k1)); - CPPUNIT_ASSERT( !s.find(k2)); - CPPUNIT_ASSERT( !s.find(k3)); + CPPUNIT_ASSERT( !s.contains(k1)); + CPPUNIT_ASSERT( !s.contains(k2)); + CPPUNIT_ASSERT( !s.contains(k3)); CPPUNIT_ASSERT( s.insert(e1)); - CPPUNIT_ASSERT( s.find(e1)); - CPPUNIT_ASSERT( s.find(k1)); - CPPUNIT_ASSERT( !s.find(e2)); - CPPUNIT_ASSERT( !s.find(e3)); + CPPUNIT_ASSERT( s.contains(e1)); + CPPUNIT_ASSERT( s.contains(k1)); + CPPUNIT_ASSERT( !s.contains(e2)); + CPPUNIT_ASSERT( !s.contains(e3)); CPPUNIT_ASSERT( e2.nInsertCount == 0 ); CPPUNIT_ASSERT( s.insert(e2, insert_functor() )); @@ -320,11 +320,14 @@ namespace set { s1 = e1 ; s2 = e2 ; s3 = e3; - CPPUNIT_ASSERT( e3.nEnsureNewCount == 0 ); - CPPUNIT_ASSERT( e3.nEnsureCount == 0 ); - CPPUNIT_ASSERT( s.ensure( e3, ensure_functor() ) == std::make_pair(true, true)); - CPPUNIT_ASSERT( e3.nEnsureNewCount == 1 ); - CPPUNIT_ASSERT( e3.nEnsureCount == 0 ); + CPPUNIT_ASSERT( e3.nUpdateNewCount == 0 ); + CPPUNIT_ASSERT( e3.nUpdateCount == 0 ); + CPPUNIT_ASSERT(s.update(e3, update_functor(), false) == std::make_pair(false, false)); + CPPUNIT_ASSERT(e3.nUpdateNewCount == 0); + CPPUNIT_ASSERT(e3.nUpdateCount == 0); + CPPUNIT_ASSERT( s.update( e3, update_functor() ) == std::make_pair(true, true)); + CPPUNIT_ASSERT( e3.nUpdateNewCount == 1 ); + CPPUNIT_ASSERT( e3.nUpdateCount == 0 ); CPPUNIT_ASSERT( s.find_with(find_key(k1), less2(), find_functor() )); CPPUNIT_ASSERT( e1.nFindCount == s1.nFindCount + 1 ); CPPUNIT_ASSERT( e1.nFindArgCount == s1.nFindArgCount ); @@ -334,10 +337,10 @@ namespace set { CPPUNIT_ASSERT( s.find_with(k2, less2(), find_functor() )); CPPUNIT_ASSERT( e2.nFindCount == s2.nFindCount + 1 ); CPPUNIT_ASSERT( e2.nFindArgCount == s2.nFindArgCount ); - CPPUNIT_ASSERT( s.find_with(find_key(k2), less2() )); + CPPUNIT_ASSERT( s.contains(find_key(k2), less2() )); CPPUNIT_ASSERT( e2.nFindCount == s2.nFindCount + 1 ) ; // unchanged, no find_functor CPPUNIT_ASSERT( e2.nFindArgCount == s2.nFindArgCount ); - CPPUNIT_ASSERT( s.find_with(k3, less2() )); + CPPUNIT_ASSERT( s.contains(k3, less2() )); CPPUNIT_ASSERT( e3.nFindCount == s3.nFindCount ) ; // unchanged, no find_functor CPPUNIT_ASSERT( e3.nFindArgCount == s3.nFindArgCount ); CPPUNIT_ASSERT( s.find_with(find_key(k3), less2(), find_functor() )); @@ -353,10 +356,10 @@ namespace set { CPPUNIT_ASSERT( !s.insert( eu, insert_functor() )); CPPUNIT_ASSERT( e2.nInsertCount == s2.nInsertCount ); - CPPUNIT_ASSERT( s.ensure( eu, ensure_functor()) == std::make_pair(true, false)); + CPPUNIT_ASSERT( s.update( eu, update_functor()) == std::make_pair(true, false)); CPPUNIT_ASSERT( e2.nInsertCount == s2.nInsertCount ); - CPPUNIT_ASSERT( e2.nEnsureCount == s2.nEnsureCount + 1 ); - CPPUNIT_ASSERT( e2.nEnsureNewCount == s2.nEnsureNewCount ); + CPPUNIT_ASSERT( e2.nUpdateCount == s2.nUpdateCount + 1 ); + CPPUNIT_ASSERT( e2.nUpdateNewCount == s2.nUpdateNewCount ); } s1 = e1 ; s2 = e2 ; s3 = e3; @@ -423,14 +426,14 @@ namespace set { CPPUNIT_ASSERT_EX( s.insert( *p, insert_functor() ), "i=" << i ); CPPUNIT_ASSERT_EX( p->nInsertCount == 1, "i=" << i ); //for ( size_t j = 0; j <= i; ++j ) { - // if ( !s.find((int) j) ) { + // if ( !s.contains((int) j) ) { // CPPUNIT_MSG( "Key " << j << " is not found after inserting key " << i ); // } //} } for ( size_t i = 0; i < nSize; ++i ) - CPPUNIT_ASSERT_EX( s.find((int) i), "Key " << i << " is not found" ); + CPPUNIT_ASSERT_EX( s.contains((int) i), "Key " << i << " is not found" ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( s.size() == nSize ); diff --git a/tests/test-hdr/set/hdr_striped_set.h b/tests/test-hdr/set/hdr_striped_set.h index 3ff6a3c3..8964c5dc 100644 --- a/tests/test-hdr/set/hdr_striped_set.h +++ b/tests/test-hdr/set/hdr_striped_set.h @@ -29,8 +29,8 @@ namespace set { struct stat { unsigned int nFindCount ; // count of find-functor calling - unsigned int nEnsureNewCount; - unsigned int nEnsureCount; + unsigned int nUpdateNewCount; + unsigned int nUpdateCount; stat() { @@ -40,8 +40,8 @@ namespace set { void copy( stat const& s ) { nFindCount = s.nFindCount; - nEnsureCount = s.nEnsureCount; - nEnsureNewCount = s.nEnsureNewCount; + nUpdateCount = s.nUpdateCount; + nUpdateNewCount = s.nUpdateNewCount; } }; @@ -294,20 +294,20 @@ namespace set { }; template - static void ensure_func( bool bNew, Item& i, Q& /*val*/ ) + static void update_func( bool bNew, Item& i, Q& /*val*/ ) { if ( bNew ) - ++i.nEnsureNewCount; + ++i.nUpdateNewCount; else - ++i.nEnsureCount; + ++i.nUpdateCount; } - struct ensure_functor + struct update_functor { template void operator()( bool bNew, Item& i, Q& val ) { - ensure_func( bNew, i, val ); + update_func( bNew, i, val ); } }; @@ -346,22 +346,22 @@ namespace set { int key; // insert/find test - CPPUNIT_ASSERT( !s.find( 10 ) ); + CPPUNIT_ASSERT( !s.contains( 10 ) ); CPPUNIT_ASSERT( s.insert( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); - CPPUNIT_ASSERT( s.find( 10 ) ); + CPPUNIT_ASSERT( s.contains( 10 ) ); CPPUNIT_ASSERT( !s.insert( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); - CPPUNIT_ASSERT( !s.find( 20 ) ); + CPPUNIT_ASSERT( !s.contains( 20 ) ); CPPUNIT_ASSERT( s.insert( std::make_pair(20, 25) )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( s.find( 10 ) ); - CPPUNIT_ASSERT( s.find( key = 20 ) ); + CPPUNIT_ASSERT( s.contains( 10 ) ); + CPPUNIT_ASSERT( s.contains( key = 20 ) ); CPPUNIT_ASSERT( s.find( key, find_functor() ) ); { copy_found f; @@ -383,7 +383,7 @@ namespace set { CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( !s.find( 25 ) ); + CPPUNIT_ASSERT( !s.contains( 25 ) ); CPPUNIT_ASSERT( s.insert( std::make_pair(25, -1), insert_functor() )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); @@ -395,18 +395,18 @@ namespace set { CPPUNIT_ASSERT( f.m_found.nVal == 2500 ); } - // ensure test + // update() test key = 10; { copy_found f; CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 10 ); CPPUNIT_ASSERT( f.m_found.nVal == 10 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 0 ); } - std::pair ensureResult = s.ensure( key, ensure_functor() ); - CPPUNIT_ASSERT( ensureResult.first && !ensureResult.second ); + std::pair updateResult = s.update( key, update_functor() ); + CPPUNIT_ASSERT( updateResult.first && !updateResult.second ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); { @@ -414,12 +414,14 @@ namespace set { CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 10 ); CPPUNIT_ASSERT( f.m_found.nVal == 10 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 1 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 1 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 0 ); } - ensureResult = s.ensure( std::make_pair(13, 1300), ensure_functor() ); - CPPUNIT_ASSERT( ensureResult.first && ensureResult.second ); + updateResult = s.update(std::make_pair(13, 1300), update_functor(), false); + CPPUNIT_ASSERT(!updateResult.first && !updateResult.second); + updateResult = s.update( std::make_pair(13, 1300), update_functor() ); + CPPUNIT_ASSERT( updateResult.first && updateResult.second ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 4 )); { @@ -428,29 +430,29 @@ namespace set { CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 13 ); CPPUNIT_ASSERT( f.m_found.nVal == 1300 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 1 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 1 ); } // erase test CPPUNIT_ASSERT( s.erase(13) ); - CPPUNIT_ASSERT( !s.find( 13 )); + CPPUNIT_ASSERT( !s.contains( 13 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); CPPUNIT_ASSERT( !s.erase(13) ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); - CPPUNIT_ASSERT( s.find( 10 )); + CPPUNIT_ASSERT( s.contains( 10 )); CPPUNIT_ASSERT( s.erase( 10 )); - CPPUNIT_ASSERT( !s.find( 10 )); + CPPUNIT_ASSERT( !s.contains( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); CPPUNIT_ASSERT( !s.erase(10) ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( s.find(20) ); + CPPUNIT_ASSERT( s.contains(20) ); { copy_found f; CPPUNIT_ASSERT( s.erase( 20, std::ref( f ) ) ); @@ -462,7 +464,7 @@ namespace set { CPPUNIT_ASSERT( f.m_found.nKey == 235 ); CPPUNIT_ASSERT( f.m_found.nVal == 235 ); } - CPPUNIT_ASSERT( !s.find( 20 )); + CPPUNIT_ASSERT( !s.contains( 20 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); @@ -477,9 +479,9 @@ namespace set { CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); - CPPUNIT_ASSERT( s.find(151)); - CPPUNIT_ASSERT( s.find(174)); - CPPUNIT_ASSERT( s.find(190)); + CPPUNIT_ASSERT( s.contains(151)); + CPPUNIT_ASSERT( s.contains(174)); + CPPUNIT_ASSERT( s.contains(190)); { copy_found f; @@ -538,22 +540,22 @@ namespace set { int key; // insert/find test - CPPUNIT_ASSERT( !s.find( 10 ) ); + CPPUNIT_ASSERT( !s.contains( 10 ) ); CPPUNIT_ASSERT( s.insert( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); - CPPUNIT_ASSERT( s.find( 10 ) ); + CPPUNIT_ASSERT( s.contains( 10 ) ); CPPUNIT_ASSERT( !s.insert( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); - CPPUNIT_ASSERT( !s.find_with( 20, less() ) ); + CPPUNIT_ASSERT( !s.contains( 20, less() ) ); CPPUNIT_ASSERT( s.insert( std::make_pair(20, 25) )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( s.find( 10 ) ); - CPPUNIT_ASSERT( s.find_with( key = 20, less() ) ); + CPPUNIT_ASSERT( s.contains( 10 ) ); + CPPUNIT_ASSERT( s.contains( key = 20, less() ) ); CPPUNIT_ASSERT( s.find_with( key, less(), find_functor() ) ); { copy_found f; @@ -575,7 +577,7 @@ namespace set { CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( !s.find( 25 ) ); + CPPUNIT_ASSERT( !s.contains( 25 ) ); CPPUNIT_ASSERT( s.insert( std::make_pair(25, -1), insert_functor() )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); @@ -587,18 +589,18 @@ namespace set { CPPUNIT_ASSERT( f.m_found.nVal == 2500 ); } - // ensure test + // update() test key = 10; { copy_found f; CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 10 ); CPPUNIT_ASSERT( f.m_found.nVal == 10 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 0 ); } - std::pair ensureResult = s.ensure( key, ensure_functor() ); - CPPUNIT_ASSERT( ensureResult.first && !ensureResult.second ); + std::pair updateResult = s.update( key, update_functor() ); + CPPUNIT_ASSERT( updateResult.first && !updateResult.second ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); { @@ -606,12 +608,14 @@ namespace set { CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 10 ); CPPUNIT_ASSERT( f.m_found.nVal == 10 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 1 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 1 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 0 ); } - ensureResult = s.ensure( std::make_pair(13, 1300), ensure_functor() ); - CPPUNIT_ASSERT( ensureResult.first && ensureResult.second ); + updateResult = s.update(std::make_pair(13, 1300), update_functor(), false); + CPPUNIT_ASSERT(!updateResult.first && !updateResult.second); + updateResult = s.update( std::make_pair(13, 1300), update_functor() ); + CPPUNIT_ASSERT( updateResult.first && updateResult.second ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 4 )); { @@ -620,29 +624,29 @@ namespace set { CPPUNIT_ASSERT( s.find( key, std::ref( f ) ) ); CPPUNIT_ASSERT( f.m_found.nKey == 13 ); CPPUNIT_ASSERT( f.m_found.nVal == 1300 ); - CPPUNIT_ASSERT( f.m_found.nEnsureCount == 0 ); - CPPUNIT_ASSERT( f.m_found.nEnsureNewCount == 1 ); + CPPUNIT_ASSERT( f.m_found.nUpdateCount == 0 ); + CPPUNIT_ASSERT( f.m_found.nUpdateNewCount == 1 ); } // erase test CPPUNIT_ASSERT( s.erase(13) ); - CPPUNIT_ASSERT( !s.find( 13 )); + CPPUNIT_ASSERT( !s.contains( 13 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); CPPUNIT_ASSERT( !s.erase(13) ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); - CPPUNIT_ASSERT( s.find( 10 )); + CPPUNIT_ASSERT( s.contains( 10 )); CPPUNIT_ASSERT( s.erase_with( 10, less() )); - CPPUNIT_ASSERT( !s.find( 10 )); + CPPUNIT_ASSERT( !s.contains( 10 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); CPPUNIT_ASSERT( !s.erase_with( 10, less() ) ); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 2 )); - CPPUNIT_ASSERT( s.find(20) ); + CPPUNIT_ASSERT( s.contains(20) ); { copy_found f; CPPUNIT_ASSERT( s.erase( 20, std::ref( f ) ) ); @@ -654,7 +658,7 @@ namespace set { CPPUNIT_ASSERT( f.m_found.nKey == 235 ); CPPUNIT_ASSERT( f.m_found.nVal == 235 ); } - CPPUNIT_ASSERT( !s.find( 20 )); + CPPUNIT_ASSERT( !s.contains( 20 )); CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 1 )); @@ -669,9 +673,9 @@ namespace set { CPPUNIT_ASSERT( !s.empty() ); CPPUNIT_ASSERT( check_size( s, 3 )); - CPPUNIT_ASSERT( s.find(151)); - CPPUNIT_ASSERT( s.find(174)); - CPPUNIT_ASSERT( s.find(190)); + CPPUNIT_ASSERT( s.contains(151)); + CPPUNIT_ASSERT( s.contains(174)); + CPPUNIT_ASSERT( s.contains(190)); { copy_found f; -- 2.34.1