os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_map.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_map.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,127 @@
     1.4 +/***********************************************************************************
     1.5 +  test_map.cpp
     1.6 +
     1.7 + * Copyright (c) 1997
     1.8 + * Mark of the Unicorn, Inc.
     1.9 + *
    1.10 + * Permission to use, copy, modify, distribute and sell this software
    1.11 + * and its documentation for any purpose is hereby granted without fee,
    1.12 + * provided that the above copyright notice appear in all copies and
    1.13 + * that both that copyright notice and this permission notice appear
    1.14 + * in supporting documentation.  Mark of the Unicorn makes no
    1.15 + * representations about the suitability of this software for any
    1.16 + * purpose.  It is provided "as is" without express or implied warranty.
    1.17 +
    1.18 +***********************************************************************************/
    1.19 +#include "Tests.h"
    1.20 +#include "TestClass.h"
    1.21 +#include "LeakCheck.h"
    1.22 +# if defined (EH_NEW_HEADERS)
    1.23 +#include <map>
    1.24 +# else
    1.25 +#include <multimap.h>
    1.26 +#include <map.h>
    1.27 +# endif
    1.28 +
    1.29 +#include "test_construct.h"
    1.30 +#include "test_assign_op.h"
    1.31 +#include "test_push_back.h"
    1.32 +#include "test_insert.h"
    1.33 +#include "test_push_front.h"
    1.34 +#include "ThrowCompare.h"
    1.35 +#include "test_insert.h"
    1.36 +
    1.37 +template <class K, class V, class Comp, class A>
    1.38 +inline multimap_tag
    1.39 +container_category(const EH_STD::__multimap__<K,V,Comp, A>&)
    1.40 +{
    1.41 +    return multimap_tag();
    1.42 +}
    1.43 +
    1.44 +template <class K, class V, class Comp, class A >
    1.45 +inline map_tag
    1.46 +container_category(const EH_STD::__map__<K,V,Comp, A>&)
    1.47 +{
    1.48 +    return map_tag();
    1.49 +}
    1.50 +
    1.51 +typedef EH_STD::__multimap__<TestClass, TestClass, ThrowCompare, eh_allocator(TestClass) > TestMultiMap;
    1.52 +
    1.53 +void test_multimap()
    1.54 +{
    1.55 +    TestMultiMap testMultiMap, testMultiMap2;
    1.56 +
    1.57 +    const size_t mapSize = random_number(random_base);
    1.58 +
    1.59 +    while ( testMultiMap.size() < mapSize )
    1.60 +    {
    1.61 +        TestMultiMap::value_type x;
    1.62 +        testMultiMap.insert( x );
    1.63 +        testMultiMap2.insert( TestMultiMap::value_type() );
    1.64 +    }
    1.65 +
    1.66 +    StrongCheck( testMultiMap, test_insert_value<TestMultiMap>(testMultiMap) );
    1.67 +
    1.68 +    size_t insCnt = 1 + random_number(random_base);
    1.69 +    TestMultiMap::value_type *insFirst = new TestMultiMap::value_type[insCnt];
    1.70 +
    1.71 +    WeakCheck( testMultiMap, insert_range_tester(testMultiMap, insFirst, insFirst+insCnt) );
    1.72 +
    1.73 +    ConstCheck( 0, test_construct_pointer_range<TestMultiMap>(insFirst, insFirst+insCnt) );
    1.74 +    delete[] insFirst;
    1.75 +
    1.76 +
    1.77 +    WeakCheck( testMultiMap, insert_range_tester(testMultiMap, testMultiMap2.begin(), testMultiMap2.end() ) );
    1.78 +
    1.79 +
    1.80 +    ConstCheck( 0, test_default_construct<TestMultiMap>() );
    1.81 +
    1.82 +    ConstCheck( 0, test_construct_iter_range<TestMultiMap>( testMultiMap2 ) );
    1.83 +
    1.84 +    ConstCheck( testMultiMap, test_copy_construct<TestMultiMap>() );
    1.85 +
    1.86 +    WeakCheck( testMultiMap, test_assign_op<TestMultiMap>( testMultiMap2 ) );
    1.87 +}
    1.88 +
    1.89 +typedef EH_STD::__map__<TestClass, TestClass, ThrowCompare, eh_allocator(TestClass) > TestMap;
    1.90 +
    1.91 +void CheckInvariant( const TestMap& m );
    1.92 +
    1.93 +void CheckInvariant( const TestMap& m )
    1.94 +{
    1.95 +//  assert( map.__rb_verify() );
    1.96 +    size_t total = 0;
    1.97 +    EH_DISTANCE( m.begin(), m.end(), total );
    1.98 +    assert( m.size() == total );
    1.99 +}
   1.100 +
   1.101 +void test_map()
   1.102 +{
   1.103 +    TestMap testMap, testMap2;
   1.104 +
   1.105 +    const size_t mapSize = random_number(random_base);
   1.106 +
   1.107 +    while ( testMap.size() < mapSize )
   1.108 +    {
   1.109 +        TestMap::value_type x;
   1.110 +        testMap.insert( x );
   1.111 +        testMap2.insert( TestMap::value_type() );
   1.112 +    }
   1.113 +
   1.114 +    StrongCheck( testMap, test_insert_value<TestMap>(testMap) );
   1.115 +
   1.116 +    size_t insCnt = random_number(random_base);
   1.117 +    TestMap::value_type *insFirst = new TestMap::value_type[1+insCnt];
   1.118 +
   1.119 +    WeakCheck( testMap, insert_range_tester(testMap, insFirst, insFirst+insCnt) );
   1.120 +
   1.121 +    ConstCheck( 0, test_construct_pointer_range<TestMap>(insFirst, insFirst+insCnt) );
   1.122 +    delete[] insFirst;
   1.123 +
   1.124 +    WeakCheck( testMap, insert_range_tester(testMap, testMap2.begin(), testMap2.end() ) );
   1.125 +    ConstCheck( 0, test_default_construct<TestMap>() );
   1.126 +    ConstCheck( 0, test_construct_iter_range<TestMap>( testMap2 ) );
   1.127 +    ConstCheck( testMap, test_copy_construct<TestMap>() );
   1.128 +    WeakCheck( testMap, test_assign_op<TestMap>( testMap2 ) );
   1.129 +}
   1.130 +