os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_rope.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /***********************************************************************************
     2   test_rope.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 # ifdef __SUNPRO_CC
    18 #  define _STLP_NO_MEMBER_TEMPLATE_CLASSES 1
    19 # endif
    20 
    21 #include "Prefix.h"
    22 #include "Tests.h"
    23 #include "TestClass.h"
    24 #include "LeakCheck.h"
    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( EH_ROPE_IMPLEMENTED )
    32 #if !( defined(__MWERKS__) && __MWERKS__ < 0x1900 )    // CW1.8 can't compile this!
    33 # define __STD_STUFF 1
    34 # if defined (EH_NEW_HEADERS)
    35 #include <rope>
    36 #else
    37 #include <rope.h>
    38 #endif
    39 
    40 
    41 typedef STLPORT::rope<char, eh_allocator(char) > TestRope;
    42 
    43 # if ( _STLP_STATIC_TEMPLATE_DATA < 1 )
    44 
    45 // Instantiate TestRope static data members
    46 const unsigned long TestRope::_S_min_len[46] = { \
    47 /* 0 */1, /* 1 */2, /* 2 */3, /* 3 */5, /* 4 */8, /* 5 */13, /* 6 */21,         \
    48 /* 7 */34, /* 8 */55, /* 9 */89, /* 10 */144, /* 11 */233, /* 12 */377,         \
    49 /* 13 */610, /* 14 */987, /* 15 */1597, /* 16 */2584, /* 17 */4181,             \
    50 /* 18 */6765ul, /* 19 */10946ul, /* 20 */17711ul, /* 21 */28657ul, /* 22 */46368ul,   \
    51 /* 23 */75025ul, /* 24 */121393ul, /* 25 */196418ul, /* 26 */317811ul,                \
    52 /* 27 */514229ul, /* 28 */832040ul, /* 29 */1346269ul, /* 30 */2178309ul,             \
    53 /* 31 */3524578ul, /* 32 */5702887ul, /* 33 */9227465ul, /* 34 */14930352ul,          \
    54 /* 35 */24157817ul, /* 36 */39088169ul, /* 37 */63245986ul, /* 38 */102334155ul,      \
    55 /* 39 */165580141ul, /* 40 */267914296ul, /* 41 */433494437ul,                        \
    56 /* 42 */701408733ul, /* 43 */1134903170ul, /* 44 */1836311903ul,                      \
    57 /* 45 */2971215073ul };
    58 
    59 # endif /* ( _STLP_STATIC_TEMPLATE_DATA < 1 ) */
    60 
    61 inline sequence_container_tag
    62 container_category(const TestRope&)
    63 {
    64   return sequence_container_tag();
    65 }
    66 
    67 void test_rope()
    68 {
    69     TestRope testRope, testRope2;
    70     size_t ropeSize = random_number(random_base);
    71 
    72     while ( testRope.size() < ropeSize )
    73     {
    74         TestRope::value_type x = TestRope::value_type(random_number(random_base));  // initialize before use
    75         testRope.push_back( x );
    76         testRope2.push_back( TestRope::value_type() );
    77     }
    78     WeakCheck( testRope, test_insert_one<TestRope>(testRope) );
    79     WeakCheck( testRope, test_insert_one<TestRope>(testRope, 0) );
    80     WeakCheck( testRope, test_insert_one<TestRope>(testRope, (int)testRope.size()) );
    81 
    82     WeakCheck( testRope, test_insert_n<TestRope>(testRope, random_number(random_base) ) );
    83     WeakCheck( testRope, test_insert_n<TestRope>(testRope, random_number(random_base), 0 ) );
    84     WeakCheck( testRope, test_insert_n<TestRope>(testRope, random_number(random_base), (int)testRope.size() ) );
    85 
    86     size_t insCnt = random_number(random_base);
    87     TestRope::value_type *insFirst = new TestRope::value_type[1+insCnt];
    88 
    89     WeakCheck( testRope, insert_range_tester(testRope, insFirst, insFirst+insCnt) );
    90     WeakCheck( testRope, insert_range_at_begin_tester(testRope, insFirst, insFirst+insCnt) );
    91     WeakCheck( testRope, insert_range_at_end_tester(testRope, insFirst, insFirst+insCnt) );
    92 
    93     ConstCheck( 0, test_construct_pointer_range<TestRope>(insFirst, insFirst+insCnt) );
    94     delete[] insFirst;
    95 
    96     WeakCheck( testRope, insert_range_tester(testRope, testRope2.begin(), testRope2.end() ) );
    97 
    98     WeakCheck( testRope, test_push_front<TestRope>(testRope) );
    99     WeakCheck( testRope, test_push_back<TestRope>(testRope) );
   100 
   101     ConstCheck( 0, test_default_construct<TestRope>() );
   102 
   103 // dwa 1/25/00 - not actually valid for rope, because it doesn't
   104 // have the constructor in question! The code will compile, but with the
   105 // wrong result (the constructor that gets used does something different).
   106 
   107 //  ConstCheck( 0, test_construct_n<TestRope>( random_number(random_base) ) );
   108 
   109     ConstCheck( 0, test_construct_n_instance<TestRope>( random_number(random_base) ) );
   110     ConstCheck( 0, test_construct_iter_range<TestRope>( testRope2 ) );
   111     ConstCheck( testRope, test_copy_construct<TestRope>() );
   112 
   113     WeakCheck( testRope, test_assign_op<TestRope>( testRope2 ) );
   114 }
   115 #endif // __MWERKS__
   116 
   117 #endif // EH_ROPE_IMPLEMENTED