genericopenlibs/cppstdlib/stl/test/eh/test_slist.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /***********************************************************************************
       
     2   test_slist.cpp
       
     3 
       
     4  * Copyright (c) 1997
       
     5  * Mark of the Unicorn, Inc.
       
     6  *
       
     7  * Permission to use, copy, modify, distribute and sell this software
       
     8  * and its documentation for any purpose is hereby granted without fee,
       
     9  * provided that the above copyright notice appear in all copies and
       
    10  * that both that copyright notice and this permission notice appear
       
    11  * in supporting documentation.  Mark of the Unicorn makes no
       
    12  * representations about the suitability of this software for any
       
    13  * purpose.  It is provided "as is" without express or implied warranty.
       
    14 
       
    15 ***********************************************************************************/
       
    16 #include "Tests.h"
       
    17 #if defined( EH_SLIST_IMPLEMENTED )
       
    18 #  include "TestClass.h"
       
    19 #  include "LeakCheck.h"
       
    20 #  if defined (EH_NEW_HEADERS) && defined (EH_USE_SGI_STL)
       
    21 #    include <slist>
       
    22 #  else
       
    23 #    include <slist.h>
       
    24 #  endif
       
    25 #include "test_construct.h"
       
    26 #include "test_assign_op.h"
       
    27 #include "test_push_back.h"
       
    28 #include "test_insert.h"
       
    29 #include "test_push_front.h"
       
    30 
       
    31 #if defined (__GNUC__) && defined (__APPLE__)
       
    32 typedef EH_STD::slist<TestClass, eh_allocator(TestClass) > TestSList;
       
    33 #else
       
    34 typedef EH_STD::__slist__<TestClass, eh_allocator(TestClass) > TestSList;
       
    35 #endif
       
    36 
       
    37 inline sequence_container_tag
       
    38 container_category(const TestSList&) {
       
    39   return sequence_container_tag();
       
    40 }
       
    41 
       
    42 struct test_slist_sort {
       
    43   test_slist_sort() {
       
    44     gTestController.SetCurrentTestName("slist::sort()");
       
    45   }
       
    46   void operator()( TestSList& slist ) const {
       
    47     slist.sort();
       
    48     for ( TestSList::iterator p = slist.begin(), q; p != slist.end(); q = p, p++ )
       
    49       if ( p != slist.begin() )
       
    50         EH_ASSERT( *p >= *q );
       
    51   }
       
    52 };
       
    53 
       
    54 void test_slist() {
       
    55   TestSList testSList, testSList2;
       
    56   size_t slistSize = random_number(random_base);
       
    57 
       
    58   while (testSList.size() < slistSize) {
       
    59     TestClass x;
       
    60     testSList.push_front( x );
       
    61     testSList2.push_front( TestClass() );
       
    62   }
       
    63 
       
    64   StrongCheck( testSList, test_insert_one<TestSList>(testSList) );
       
    65   StrongCheck( testSList, test_insert_one<TestSList>(testSList, 0) );
       
    66   StrongCheck( testSList, test_insert_one<TestSList>(testSList, (int)testSList.size()) );
       
    67 
       
    68   WeakCheck( testSList, test_insert_n<TestSList>(testSList, random_number(random_base) ) );
       
    69   WeakCheck( testSList, test_insert_n<TestSList>(testSList, random_number(random_base), 0 ) );
       
    70   WeakCheck( testSList, test_insert_n<TestSList>(testSList, random_number(random_base), (int)testSList.size() ) );
       
    71 
       
    72   size_t insCnt = random_number(random_base);
       
    73   TestClass *insFirst = new TestSList::value_type[1+insCnt];
       
    74   WeakCheck( testSList, insert_range_tester(testSList, insFirst, insFirst+insCnt) );
       
    75 
       
    76   ConstCheck( 0, test_construct_pointer_range<TestSList>(insFirst, insFirst+insCnt) );
       
    77   delete[] insFirst;
       
    78   WeakCheck( testSList, test_insert_range<TestSList,TestSList::iterator>(testSList, testSList2.begin(), testSList2.end() ) );
       
    79   StrongCheck( testSList, test_push_front<TestSList>(testSList) );
       
    80   StrongCheck( testSList, test_slist_sort() );  // Simply to verify strength.
       
    81 
       
    82   ConstCheck( 0, test_default_construct<TestSList>() );
       
    83   ConstCheck( 0, test_construct_n<TestSList>( random_number(random_base) ) );
       
    84   ConstCheck( 0, test_construct_n_instance<TestSList>( random_number(random_base) ) );
       
    85   ConstCheck( 0, test_construct_iter_range<TestSList>( testSList2 ) );
       
    86   ConstCheck( testSList, test_copy_construct<TestSList>() );
       
    87   WeakCheck( testSList, test_assign_op<TestSList>( testSList2 ) );
       
    88 }
       
    89 
       
    90 #endif // EH_SLIST_IMPLEMENTED