Fixed minor gcc warnings
[libcds.git] / test / unit / set / test_set.h
index d3a7a90806105bce2cd2af853476884084d0a8b9..af88b5b58b4ea75287ca4b13d2e1537db630eacf 100644 (file)
@@ -5,7 +5,7 @@
 
     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:
 
     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.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #ifndef CDSUNIT_SET_TEST_SET_H
 #define CDSUNIT_SET_TEST_SET_H
 
-#include <cds_test/check_size.h>
-#include <cds_test/fixture.h>
+#include "test_set_data.h"
 
 #include <cds/opt/hash.h>
-#include <functional>   // ref
-
-// forward declaration
-namespace cds { namespace container {}}
 
 namespace cds_test {
-    namespace co = cds::opt;
 
-    class container_set : public fixture
+    class container_set : public container_set_data
     {
-    public:
-        static size_t const kSize = 1000;
-
-        struct stat
-        {
-            unsigned int nFindCount;
-            unsigned int nUpdateNewCount;
-            unsigned int nUpdateCount;
-            mutable unsigned int nEraseCount;
-
-            stat()
-            {
-                clear_stat();
-            }
-
-            void clear_stat()
-            {
-                memset( this, 0, sizeof( *this ) );
-            }
-        };
-
-        struct other_item {
-            int nKey;
-
-            explicit other_item( int k )
-                : nKey( k )
-            {}
-
-            int key() const
-            {
-                return nKey;
-            }
-        };
-
-        struct int_item: public stat
-        {
-            int nKey;
-            int nVal;
-            std::string strVal;
-
-            int_item()
-                : nKey( 0 )
-                , nVal( 0 )
-            {}
-
-            explicit int_item( int k )
-                : nKey( k )
-                , nVal( k * 2 )
-            {}
-
-            template <typename Q>
-            explicit int_item( Q const& src )
-                : nKey( src.key() )
-                , nVal( 0 )
-            {}
-
-            int_item( int_item const& src )
-                : nKey( src.nKey )
-                , nVal( src.nVal )
-                , strVal( src.strVal )
-            {}
-
-            int_item( int_item&& src )
-                : nKey( src.nKey )
-                , nVal( src.nVal )
-                , strVal( std::move( src.strVal ) )
-            {}
-
-            int_item( int k, std::string&& s )
-                : nKey( k )
-                , nVal( k * 2 )
-                , strVal( std::move( s ) )
-            {}
-
-            explicit int_item( other_item const& s )
-                : nKey( s.key() )
-                , nVal( s.key() * 2 )
-            {}
-
-            int key() const
-            {
-                return nKey;
-            }
-        };
-
-        struct hash_int {
-            size_t operator()( int i ) const
-            {
-                return co::v::hash<int>()(i);
-            }
-            template <typename Item>
-            size_t operator()( const Item& i ) const
-            {
-                return (*this)(i.key());
-            }
-        };
-
-        struct simple_item_counter {
-            size_t  m_nCount;
-
-            simple_item_counter()
-                : m_nCount( 0 )
-            {}
-
-            size_t operator ++()
-            {
-                return ++m_nCount;
-            }
-
-            size_t operator --()
-            {
-                return --m_nCount;
-            }
-
-            void reset()
-            {
-                m_nCount = 0;
-            }
-
-            operator size_t() const
-            {
-                return m_nCount;
-            }
-
-        };
-
-        struct less
-        {
-            bool operator ()( int_item const& v1, int_item const& v2 ) const
-            {
-                return v1.key() < v2.key();
-            }
-
-            template <typename Q>
-            bool operator ()( int_item const& v1, const Q& v2 ) const
-            {
-                return v1.key() < v2;
-            }
-
-            template <typename Q>
-            bool operator ()( const Q& v1, int_item const& v2 ) const
-            {
-                return v1 < v2.key();
-            }
-        };
-
-        struct cmp {
-            int operator ()( int_item const& v1, int_item const& v2 ) const
-            {
-                if ( v1.key() < v2.key() )
-                    return -1;
-                return v1.key() > v2.key() ? 1 : 0;
-            }
-
-            template <typename T>
-            int operator ()( T const& v1, int v2 ) const
-            {
-                if ( v1.key() < v2 )
-                    return -1;
-                return v1.key() > v2 ? 1 : 0;
-            }
-
-            template <typename T>
-            int operator ()( int v1, T const& v2 ) const
-            {
-                if ( v1 < v2.key() )
-                    return -1;
-                return v1 > v2.key() ? 1 : 0;
-            }
-        };
-
-        struct other_less {
-            template <typename Q, typename T>
-            bool operator()( Q const& lhs, T const& rhs ) const
-            {
-                return lhs.key() < rhs.key();
-            }
-        };
-
     protected:
         template <typename Set>
         void test( Set& s )
@@ -261,7 +76,7 @@ namespace cds_test {
                 std::pair<bool, bool> updResult;
 
                 std::string str;
-                updResult = s.update( i.key(), []( bool bNew, value_type&, int )
+                updResult = s.update( i.key(), []( bool, value_type&, int )
                 {
                     ASSERT_TRUE( false );
                 }, false );
@@ -297,7 +112,7 @@ namespace cds_test {
                     ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) 
                         {
                             EXPECT_EQ( v.key(), key );
-                            EXPECT_EQ( v.nFindCount, 1 );
+                            EXPECT_EQ( v.nFindCount, 1u );
                         }));
                     break;
                 case 3:
@@ -306,7 +121,7 @@ namespace cds_test {
                     ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key ) 
                         {
                             EXPECT_EQ( v.key(), key );
-                            EXPECT_EQ( v.nFindCount, 1 );
+                            EXPECT_EQ( v.nFindCount, 1u );
                         }));
                     break;
                 case 4:
@@ -331,7 +146,7 @@ namespace cds_test {
                     ASSERT_TRUE( s.find( i.nKey, []( value_type const& v, int key )
                         {
                             EXPECT_EQ( v.key(), key );
-                            EXPECT_EQ( v.nUpdateNewCount, 2 );
+                            EXPECT_EQ( v.nUpdateNewCount, 2u );
                         }));
                     break;
                 case 5:
@@ -356,7 +171,7 @@ namespace cds_test {
                     ASSERT_TRUE( s.find( i, []( value_type const& v, value_type const& arg )
                         {
                             EXPECT_EQ( v.key(), arg.key() );
-                            EXPECT_EQ( v.nUpdateNewCount, 2 );
+                            EXPECT_EQ( v.nUpdateNewCount, 2u );
                         }));
                     break;
                 case 6:
@@ -408,11 +223,11 @@ namespace cds_test {
                     }));
                 ASSERT_TRUE( s.find( i, []( value_type& v, value_type const& ) 
                     { 
-                        EXPECT_EQ( ++v.nFindCount, 2 );
+                        EXPECT_EQ( ++v.nFindCount, 2u );
                     }));
                 ASSERT_TRUE( s.find_with( other_item( i.key() ), other_less(), []( value_type& v, other_item const& ) 
                     { 
-                        EXPECT_EQ( ++v.nFindCount, 3 );
+                        EXPECT_EQ( ++v.nFindCount, 3u );
                     }));
 
                 int nKey = i.key() - 1;
@@ -481,7 +296,7 @@ namespace cds_test {
                 ASSERT_FALSE( s.find_with( other_item( i.key()), other_less(), []( value_type&, other_item const& ) {} ));
             }
             ASSERT_TRUE( s.empty() );
-            ASSERT_CONTAINER_SIZE( s, 0 );
+            ASSERT_CONTAINER_SIZE( s, 0u );
 
 
             // clear
@@ -495,7 +310,7 @@ namespace cds_test {
             s.clear();
 
             ASSERT_TRUE( s.empty() );
-            ASSERT_CONTAINER_SIZE( s, 0 );
+            ASSERT_CONTAINER_SIZE( s, 0u );
 
             ASSERT_TRUE( s.begin() == s.end() );
             ASSERT_TRUE( s.cbegin() == s.cend() );