Home | History | Annotate | Download | only in eh
      1 /***********************************************************************************
      2   test_deque.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 
     17 #include "Tests.h"
     18 # if defined (EH_NEW_HEADERS)
     19 #  ifdef __SUNPRO_CC
     20 #   include <stdio.h>
     21 #  else
     22 #   include <cstdio>
     23 #  endif
     24 #  include <deque>
     25 # else
     26 #  include <stdio.h>
     27 #  include <deque.h>
     28 # endif
     29 #include "TestClass.h"
     30 #include "LeakCheck.h"
     31 #include "test_construct.h"
     32 #include "test_assign_op.h"
     33 #include "test_push_back.h"
     34 #include "test_insert.h"
     35 #include "test_push_front.h"
     36 
     37 typedef TestClass DQTestClass;
     38 
     39 typedef EH_STD::deque<DQTestClass, eh_allocator(DQTestClass) > TestDeque;
     40 
     41 inline sequence_container_tag
     42 container_category(const TestDeque&)
     43 {
     44   return sequence_container_tag();
     45 }
     46 
     47 void test_deque()
     48 {
     49     size_t dequeSize = random_number(random_base);
     50     TestDeque emptyDeque;
     51     TestDeque testDeque, testDeque2;
     52     while ( testDeque.size() < dequeSize )
     53     {
     54         DQTestClass x;
     55         testDeque.push_back( x );
     56         testDeque2.push_back( DQTestClass() );
     57     }
     58 
     59     ConstCheck( testDeque, test_copy_construct<TestDeque>() );
     60     WeakCheck( testDeque, test_insert_one<TestDeque>(testDeque) );
     61     StrongCheck( testDeque, test_insert_one<TestDeque>(testDeque, 0) );
     62     StrongCheck( testDeque, test_insert_one<TestDeque>(testDeque, (int)testDeque.size()) );
     63 
     64     WeakCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base) ) );
     65     StrongCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base), 0 ) );
     66     StrongCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base), (int)testDeque.size() ) );
     67 
     68     size_t insCnt = random_number(random_base);
     69     DQTestClass *insFirst = new TestDeque::value_type[insCnt + 1];
     70 
     71     WeakCheck( testDeque, insert_range_tester(testDeque, insFirst, insFirst + insCnt) );
     72     StrongCheck( testDeque, insert_range_at_begin_tester(testDeque, insFirst, insFirst + insCnt) );
     73     StrongCheck( testDeque, insert_range_at_end_tester(testDeque, insFirst, insFirst + insCnt) );
     74 
     75     ConstCheck( 0, test_construct_pointer_range<TestDeque>(insFirst, insFirst + insCnt) );
     76     delete[] insFirst;
     77 
     78     WeakCheck( testDeque, insert_range_tester(testDeque, testDeque2.begin(), testDeque2.end() ) );
     79 
     80     StrongCheck( testDeque, test_push_back<TestDeque>(testDeque) );
     81     StrongCheck( emptyDeque, test_push_back<TestDeque>(emptyDeque) );
     82     StrongCheck( testDeque, test_push_front<TestDeque>(testDeque) );
     83     StrongCheck( emptyDeque, test_push_front<TestDeque>(emptyDeque) );
     84 
     85 
     86     ConstCheck( 0, test_default_construct<TestDeque>() );
     87     ConstCheck( 0, test_construct_n<TestDeque>( random_number(random_base) ) );
     88     ConstCheck( 0, test_construct_n_instance<TestDeque>( random_number(random_base) ) );
     89     ConstCheck( 0, test_construct_iter_range<TestDeque>( testDeque2 ) );
     90 
     91     testDeque2.resize( testDeque.size() * 3 / 2 );
     92     WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
     93     testDeque2.resize( testDeque.size() * 2 / 3 );
     94     WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
     95 }
     96