From 8e05483bbc7b617a5de9c090d47d919a01b888df Mon Sep 17 00:00:00 2001 From: khizmax Date: Wed, 4 Mar 2015 18:24:27 +0300 Subject: [PATCH] Added tree consistency checking to the map unit test --- tests/unit/map2/map_delodd.cpp | 12 +----------- tests/unit/map2/map_find_int.cpp | 2 ++ tests/unit/map2/map_find_string.cpp | 2 ++ tests/unit/map2/map_insdel_func.cpp | 2 ++ tests/unit/map2/map_insdel_int.cpp | 1 + tests/unit/map2/map_insdel_item_int.cpp | 2 ++ tests/unit/map2/map_insdel_item_string.cpp | 2 ++ tests/unit/map2/map_insdel_string.cpp | 1 + tests/unit/map2/map_insdelfind.cpp | 2 ++ tests/unit/map2/map_insfind_int.cpp | 2 ++ tests/unit/map2/map_types.h | 19 ++++++++++++++++--- 11 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tests/unit/map2/map_delodd.cpp b/tests/unit/map2/map_delodd.cpp index 02332e1e..a57c5d58 100644 --- a/tests/unit/map2/map_delodd.cpp +++ b/tests/unit/map2/map_delodd.cpp @@ -126,16 +126,6 @@ namespace boost { namespace map2 { - template - static inline void check_before_clear( Map& /*s*/ ) - {} - - template - static inline void check_before_clear( cds::container::EllenBinTreeMap& s ) - { - CPPUNIT_CHECK_CURRENT( s.check_consistency() ); - } - class Map_DelOdd: public CppUnitMini::TestCase { std::vector m_arrData; @@ -628,7 +618,7 @@ namespace map2 { CPPUNIT_CHECK_EX( nErrorCount == 0, "Totals: " << nErrorCount << " keys is not found"); } - check_before_clear( testMap ); + check_before_cleanup( testMap ); CPPUNIT_MSG( " Clear map (single-threaded)..." ); timer.reset(); diff --git a/tests/unit/map2/map_find_int.cpp b/tests/unit/map2/map_find_int.cpp index 789fc180..d796e48b 100644 --- a/tests/unit/map2/map_find_int.cpp +++ b/tests/unit/map2/map_find_int.cpp @@ -198,6 +198,8 @@ namespace map2 { CPPUNIT_ASSERT( pThread->m_KeyNotExists.nSuccess == (m_Arr.size() - m_nRealMapSize) * c_nPassCount ); } + check_before_cleanup( testMap ); + testMap.clear(); additional_check( testMap ); print_stat( testMap ); diff --git a/tests/unit/map2/map_find_string.cpp b/tests/unit/map2/map_find_string.cpp index d796bef6..fbdc0e48 100644 --- a/tests/unit/map2/map_find_string.cpp +++ b/tests/unit/map2/map_find_string.cpp @@ -199,6 +199,8 @@ namespace map2 { CPPUNIT_ASSERT( pThread->m_KeyNotExists.nFailed == 0 ); } + check_before_cleanup( testMap ); + testMap.clear(); additional_check( testMap ); print_stat( testMap ); diff --git a/tests/unit/map2/map_insdel_func.cpp b/tests/unit/map2/map_insdel_func.cpp index 2ebadc4d..65b970b7 100644 --- a/tests/unit/map2/map_insdel_func.cpp +++ b/tests/unit/map2/map_insdel_func.cpp @@ -484,6 +484,8 @@ namespace map2 { // nTestFunctorRef is call count of insert functor CPPUNIT_CHECK_EX( nTestFunctorRef == nInsertSuccess, "nInsertSuccess=" << nInsertSuccess << " functor nTestFunctorRef=" << nTestFunctorRef ); + check_before_cleanup( testMap ); + CPPUNIT_MSG( " Clear map (single-threaded)..." ); timer.reset(); for ( size_t nItem = 0; nItem < c_nMapSize; ++nItem ) { diff --git a/tests/unit/map2/map_insdel_int.cpp b/tests/unit/map2/map_insdel_int.cpp index 57a2031d..a6ecc149 100644 --- a/tests/unit/map2/map_insdel_int.cpp +++ b/tests/unit/map2/map_insdel_int.cpp @@ -197,6 +197,7 @@ namespace map2 { << " Map size=" << testMap.size() ); + check_before_cleanup( testMap ); CPPUNIT_MSG( " Clear map (single-threaded)..." ); timer.reset(); diff --git a/tests/unit/map2/map_insdel_item_int.cpp b/tests/unit/map2/map_insdel_item_int.cpp index deb0432f..cb4376e7 100644 --- a/tests/unit/map2/map_insdel_item_int.cpp +++ b/tests/unit/map2/map_insdel_item_int.cpp @@ -225,6 +225,8 @@ namespace map2 { } CPPUNIT_MSG( " Duration=" << timer.duration() ); + check_before_cleanup( testMap ); + testMap.clear(); additional_check( testMap ); print_stat( testMap ); diff --git a/tests/unit/map2/map_insdel_item_string.cpp b/tests/unit/map2/map_insdel_item_string.cpp index 44ea87a2..fd062d1c 100644 --- a/tests/unit/map2/map_insdel_item_string.cpp +++ b/tests/unit/map2/map_insdel_item_string.cpp @@ -202,6 +202,8 @@ namespace map2 { } CPPUNIT_MSG( " Duration=" << timer.duration() ); + check_before_cleanup( testMap ); + testMap.clear(); additional_check( testMap ); print_stat( testMap ); diff --git a/tests/unit/map2/map_insdel_string.cpp b/tests/unit/map2/map_insdel_string.cpp index f95b838b..a3f36f79 100644 --- a/tests/unit/map2/map_insdel_string.cpp +++ b/tests/unit/map2/map_insdel_string.cpp @@ -195,6 +195,7 @@ namespace map2 { << " Map size=" << testMap.size() ); + check_before_cleanup( testMap ); CPPUNIT_MSG( " Clear map (single-threaded)..." ); timer.reset(); diff --git a/tests/unit/map2/map_insdelfind.cpp b/tests/unit/map2/map_insdelfind.cpp index 79bfc2fd..83965cb8 100644 --- a/tests/unit/map2/map_insdelfind.cpp +++ b/tests/unit/map2/map_insdelfind.cpp @@ -175,6 +175,8 @@ namespace map2 { ); + check_before_cleanup( testMap ); + CPPUNIT_MSG( " Clear map (single-threaded)..." ); timer.reset(); testMap.clear(); diff --git a/tests/unit/map2/map_insfind_int.cpp b/tests/unit/map2/map_insfind_int.cpp index fc13e27f..3b279ad4 100644 --- a/tests/unit/map2/map_insfind_int.cpp +++ b/tests/unit/map2/map_insfind_int.cpp @@ -145,6 +145,8 @@ namespace map2 { CPPUNIT_ASSERT( nInsertFailed == 0 ); CPPUNIT_ASSERT( nFindFailed == 0 ); + check_before_cleanup( testMap ); + testMap.clear(); additional_check( testMap ); print_stat( testMap ); diff --git a/tests/unit/map2/map_types.h b/tests/unit/map2/map_types.h index 5c1c3eb7..d246c42a 100644 --- a/tests/unit/map2/map_types.h +++ b/tests/unit/map2/map_types.h @@ -1838,6 +1838,10 @@ namespace map2 { static inline void print_stat( Map const& /*m*/ ) {} + template + static inline void check_before_cleanup( Map& /*m*/ ) + {} + template static inline void additional_cleanup( Map& /*m*/ ) {} @@ -1908,16 +1912,25 @@ namespace map2 { ellen_bintree_check::check_stat( s.statistics() ); } + template + static inline void check_before_cleanup( cc::EllenBinTreeMap& m ) + { + CPPUNIT_MSG( " Check internal consistency (single-threaded)..." ); + CPPUNIT_CHECK_CURRENT( m.check_consistency() ); + } + + // BronsonAVLTreeMap template - static inline void print_stat( cc::BronsonAVLTreeMap const& s ) + static inline void print_stat( cc::BronsonAVLTreeMap const& m ) { - CPPUNIT_MSG( s.statistics() ); + CPPUNIT_MSG( m.statistics() ); } template - static inline void additional_check( cc::BronsonAVLTreeMap& m ) + static inline void check_before_cleanup( cc::BronsonAVLTreeMap& m ) { + CPPUNIT_MSG( " Check internal consistency (single-threaded)..." ); m.check_consistency([]( size_t nLevel, size_t hLeft, size_t hRight ) { CPPUNIT_MSG( "Tree violation on level=" << nLevel << ": hLeft=" << hLeft << ", hRight=" << hRight ) -- 2.34.1