Home | History | Annotate | Download | only in eh
      1 /***********************************************************************************
      2   test_list.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 #include "TestClass.h"
     18 #include "LeakCheck.h"
     19 # if defined (EH_NEW_HEADERS)
     20 #include <list>
     21 #else
     22 #include <list.h>
     23 #endif
     24 #include "test_construct.h"
     25 #include "test_assign_op.h"
     26 #include "test_push_back.h"
     27 #include "test_insert.h"
     28 #include "test_push_front.h"
     29 #include "nc_alloc.h"
     30 
     31 typedef EH_STD::__list__<TestClass, eh_allocator(TestClass) > TestList;
     32 
     33 inline sequence_container_tag
     34 container_category(const TestList&)
     35 {
     36   return sequence_container_tag();
     37 }
     38 
     39 //
     40 //  list sort() member test operation. Does not verify stability.
     41 //
     42 struct test_list_sort
     43 {
     44     test_list_sort()
     45     {
     46         gTestController.SetCurrentTestName("list::sort()");
     47     }
     48 
     49     void operator()( TestList& list ) const
     50     {
     51         list.sort();
     52 
     53         gTestController.CancelFailureCountdown();
     54 
     55         for ( TestList::iterator p = list.begin(); p != list.end(); p++ )
     56             if ( p != list.begin() ) {
     57                 TestList::iterator tmp=p;
     58                 --tmp;
     59                 EH_ASSERT( *p >= *tmp );
     60             }
     61     }
     62 };
     63 
     64 void test_list()
     65 {
     66     TestList testList, testList2;
     67     size_t listSize = random_number(random_base);
     68 
     69     while ( testList.size() < listSize )
     70     {
     71         TestClass x;
     72         testList.push_back( x );
     73         testList2.push_back( TestClass() );
     74     }
     75 
     76     StrongCheck( testList, test_insert_one<TestList>(testList) );
     77     StrongCheck( testList, test_insert_one<TestList>(testList, 0) );
     78     StrongCheck( testList, test_insert_one<TestList>(testList, (int)testList.size()) );
     79 
     80     WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base) ) );
     81     WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), 0 ) );
     82     WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), (int)testList.size() ) );
     83 
     84     size_t insCnt = random_number(random_base);
     85     TestClass *insFirst = new TestList::value_type[1+insCnt];
     86 
     87     WeakCheck( testList, insert_range_tester(testList, insFirst, insFirst+insCnt) );
     88     WeakCheck( testList, insert_range_at_begin_tester(testList, insFirst, insFirst+insCnt) );
     89     WeakCheck( testList, insert_range_at_end_tester(testList, insFirst, insFirst+insCnt) );
     90 
     91     ConstCheck( 0, test_construct_pointer_range<TestList>(insFirst, insFirst+insCnt) );
     92     delete[] insFirst;
     93 
     94     WeakCheck( testList, insert_range_tester(testList, testList2.begin(), testList2.end() ) );
     95 
     96     StrongCheck( testList, test_push_front<TestList>(testList) );
     97     StrongCheck( testList, test_push_back<TestList>(testList) );
     98 
     99     StrongCheck( testList, test_list_sort() );  // Simply to verify strength.
    100 
    101     ConstCheck( 0, test_default_construct<TestList>() );
    102     ConstCheck( 0, test_construct_n<TestList>( random_number(random_base) ) );
    103     ConstCheck( 0, test_construct_n_instance<TestList>( random_number(random_base) ) );
    104     ConstCheck( 0, test_construct_iter_range<TestList>( testList2 ) );
    105     ConstCheck( testList, test_copy_construct<TestList>() );
    106 
    107     WeakCheck( testList, test_assign_op<TestList>( testList2 ) );
    108 }
    109