1*c2c66affSColin Finck /***********************************************************************************
2*c2c66affSColin Finck   test_deque.cpp
3*c2c66affSColin Finck 
4*c2c66affSColin Finck  * Copyright (c) 1997
5*c2c66affSColin Finck  * Mark of the Unicorn, Inc.
6*c2c66affSColin Finck  *
7*c2c66affSColin Finck  * Permission to use, copy, modify, distribute and sell this software
8*c2c66affSColin Finck  * and its documentation for any purpose is hereby granted without fee,
9*c2c66affSColin Finck  * provided that the above copyright notice appear in all copies and
10*c2c66affSColin Finck  * that both that copyright notice and this permission notice appear
11*c2c66affSColin Finck  * in supporting documentation.  Mark of the Unicorn makes no
12*c2c66affSColin Finck  * representations about the suitability of this software for any
13*c2c66affSColin Finck  * purpose.  It is provided "as is" without express or implied warranty.
14*c2c66affSColin Finck 
15*c2c66affSColin Finck ***********************************************************************************/
16*c2c66affSColin Finck 
17*c2c66affSColin Finck #include "Tests.h"
18*c2c66affSColin Finck # if defined (EH_NEW_HEADERS)
19*c2c66affSColin Finck #  ifdef __SUNPRO_CC
20*c2c66affSColin Finck #   include <stdio.h>
21*c2c66affSColin Finck #  else
22*c2c66affSColin Finck #   include <cstdio>
23*c2c66affSColin Finck #  endif
24*c2c66affSColin Finck #  include <deque>
25*c2c66affSColin Finck # else
26*c2c66affSColin Finck #  include <stdio.h>
27*c2c66affSColin Finck #  include <deque.h>
28*c2c66affSColin Finck # endif
29*c2c66affSColin Finck #include "TestClass.h"
30*c2c66affSColin Finck #include "LeakCheck.h"
31*c2c66affSColin Finck #include "test_construct.h"
32*c2c66affSColin Finck #include "test_assign_op.h"
33*c2c66affSColin Finck #include "test_push_back.h"
34*c2c66affSColin Finck #include "test_insert.h"
35*c2c66affSColin Finck #include "test_push_front.h"
36*c2c66affSColin Finck 
37*c2c66affSColin Finck typedef TestClass DQTestClass;
38*c2c66affSColin Finck 
39*c2c66affSColin Finck typedef EH_STD::deque<DQTestClass, eh_allocator(DQTestClass) > TestDeque;
40*c2c66affSColin Finck 
41*c2c66affSColin Finck inline sequence_container_tag
container_category(const TestDeque &)42*c2c66affSColin Finck container_category(const TestDeque&)
43*c2c66affSColin Finck {
44*c2c66affSColin Finck   return sequence_container_tag();
45*c2c66affSColin Finck }
46*c2c66affSColin Finck 
test_deque()47*c2c66affSColin Finck void test_deque()
48*c2c66affSColin Finck {
49*c2c66affSColin Finck     size_t dequeSize = random_number(random_base);
50*c2c66affSColin Finck     TestDeque emptyDeque;
51*c2c66affSColin Finck     TestDeque testDeque, testDeque2;
52*c2c66affSColin Finck     while ( testDeque.size() < dequeSize )
53*c2c66affSColin Finck     {
54*c2c66affSColin Finck         DQTestClass x;
55*c2c66affSColin Finck         testDeque.push_back( x );
56*c2c66affSColin Finck         testDeque2.push_back( DQTestClass() );
57*c2c66affSColin Finck     }
58*c2c66affSColin Finck 
59*c2c66affSColin Finck     ConstCheck( testDeque, test_copy_construct<TestDeque>() );
60*c2c66affSColin Finck     WeakCheck( testDeque, test_insert_one<TestDeque>(testDeque) );
61*c2c66affSColin Finck     StrongCheck( testDeque, test_insert_one<TestDeque>(testDeque, 0) );
62*c2c66affSColin Finck     StrongCheck( testDeque, test_insert_one<TestDeque>(testDeque, (int)testDeque.size()) );
63*c2c66affSColin Finck 
64*c2c66affSColin Finck     WeakCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base) ) );
65*c2c66affSColin Finck     StrongCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base), 0 ) );
66*c2c66affSColin Finck     StrongCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base), (int)testDeque.size() ) );
67*c2c66affSColin Finck 
68*c2c66affSColin Finck     size_t insCnt = random_number(random_base);
69*c2c66affSColin Finck     DQTestClass *insFirst = new TestDeque::value_type[insCnt + 1];
70*c2c66affSColin Finck 
71*c2c66affSColin Finck     WeakCheck( testDeque, insert_range_tester(testDeque, insFirst, insFirst + insCnt) );
72*c2c66affSColin Finck     StrongCheck( testDeque, insert_range_at_begin_tester(testDeque, insFirst, insFirst + insCnt) );
73*c2c66affSColin Finck     StrongCheck( testDeque, insert_range_at_end_tester(testDeque, insFirst, insFirst + insCnt) );
74*c2c66affSColin Finck 
75*c2c66affSColin Finck     ConstCheck( 0, test_construct_pointer_range<TestDeque>(insFirst, insFirst + insCnt) );
76*c2c66affSColin Finck     delete[] insFirst;
77*c2c66affSColin Finck 
78*c2c66affSColin Finck     WeakCheck( testDeque, insert_range_tester(testDeque, testDeque2.begin(), testDeque2.end() ) );
79*c2c66affSColin Finck 
80*c2c66affSColin Finck     StrongCheck( testDeque, test_push_back<TestDeque>(testDeque) );
81*c2c66affSColin Finck     StrongCheck( emptyDeque, test_push_back<TestDeque>(emptyDeque) );
82*c2c66affSColin Finck     StrongCheck( testDeque, test_push_front<TestDeque>(testDeque) );
83*c2c66affSColin Finck     StrongCheck( emptyDeque, test_push_front<TestDeque>(emptyDeque) );
84*c2c66affSColin Finck 
85*c2c66affSColin Finck 
86*c2c66affSColin Finck     ConstCheck( 0, test_default_construct<TestDeque>() );
87*c2c66affSColin Finck     ConstCheck( 0, test_construct_n<TestDeque>( random_number(random_base) ) );
88*c2c66affSColin Finck     ConstCheck( 0, test_construct_n_instance<TestDeque>( random_number(random_base) ) );
89*c2c66affSColin Finck     ConstCheck( 0, test_construct_iter_range<TestDeque>( testDeque2 ) );
90*c2c66affSColin Finck 
91*c2c66affSColin Finck     testDeque2.resize( testDeque.size() * 3 / 2 );
92*c2c66affSColin Finck     WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
93*c2c66affSColin Finck     testDeque2.resize( testDeque.size() * 2 / 3 );
94*c2c66affSColin Finck     WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
95*c2c66affSColin Finck }
96