os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_deque.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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, 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), 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, (DQTestClass *)insFirst,
    72                 insFirst+insCnt) );
    73     StrongCheck( testDeque, insert_range_at_begin_tester(testDeque, (DQTestClass *)insFirst,
    74                insFirst+insCnt) );
    75     StrongCheck( testDeque, insert_range_at_end_tester(testDeque, (DQTestClass *)insFirst,
    76                    insFirst+insCnt) );
    77 
    78     ConstCheck( 0, test_construct_pointer_range<TestDeque>( (DQTestClass *)insFirst,
    79                   insFirst+insCnt ) );
    80     delete[] insFirst;
    81 
    82     WeakCheck( testDeque, insert_range_tester(testDeque, testDeque2.begin(), testDeque2.end() ) );
    83 
    84     StrongCheck( testDeque, test_push_back<TestDeque>(testDeque) );
    85     StrongCheck( emptyDeque, test_push_back<TestDeque>(emptyDeque) );
    86     StrongCheck( testDeque, test_push_front<TestDeque>(testDeque) );
    87     StrongCheck( emptyDeque, test_push_front<TestDeque>(emptyDeque) );
    88 
    89 
    90     ConstCheck( 0, test_default_construct<TestDeque>() );
    91     ConstCheck( 0, test_construct_n<TestDeque>( random_number(random_base) ) );
    92     ConstCheck( 0, test_construct_n_instance<TestDeque>( random_number(random_base) ) );
    93     ConstCheck( 0, test_construct_iter_range<TestDeque>( testDeque2 ) );
    94 
    95     testDeque2.resize( testDeque.size() * 3 / 2 );
    96     WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
    97     testDeque2.resize( testDeque.size() * 2 / 3 );
    98     WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
    99 }