os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_map.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/***********************************************************************************
sl@0
     2
  test_map.cpp
sl@0
     3
sl@0
     4
 * Copyright (c) 1997
sl@0
     5
 * Mark of the Unicorn, Inc.
sl@0
     6
 *
sl@0
     7
 * Permission to use, copy, modify, distribute and sell this software
sl@0
     8
 * and its documentation for any purpose is hereby granted without fee,
sl@0
     9
 * provided that the above copyright notice appear in all copies and
sl@0
    10
 * that both that copyright notice and this permission notice appear
sl@0
    11
 * in supporting documentation.  Mark of the Unicorn makes no
sl@0
    12
 * representations about the suitability of this software for any
sl@0
    13
 * purpose.  It is provided "as is" without express or implied warranty.
sl@0
    14
sl@0
    15
***********************************************************************************/
sl@0
    16
#include "Tests.h"
sl@0
    17
#include "TestClass.h"
sl@0
    18
#include "LeakCheck.h"
sl@0
    19
# if defined (EH_NEW_HEADERS)
sl@0
    20
#include <map>
sl@0
    21
# else
sl@0
    22
#include <multimap.h>
sl@0
    23
#include <map.h>
sl@0
    24
# endif
sl@0
    25
sl@0
    26
#include "test_construct.h"
sl@0
    27
#include "test_assign_op.h"
sl@0
    28
#include "test_push_back.h"
sl@0
    29
#include "test_insert.h"
sl@0
    30
#include "test_push_front.h"
sl@0
    31
#include "ThrowCompare.h"
sl@0
    32
#include "test_insert.h"
sl@0
    33
sl@0
    34
template <class K, class V, class Comp, class A>
sl@0
    35
inline multimap_tag
sl@0
    36
container_category(const EH_STD::__multimap__<K,V,Comp, A>&)
sl@0
    37
{
sl@0
    38
    return multimap_tag();
sl@0
    39
}
sl@0
    40
sl@0
    41
template <class K, class V, class Comp, class A >
sl@0
    42
inline map_tag
sl@0
    43
container_category(const EH_STD::__map__<K,V,Comp, A>&)
sl@0
    44
{
sl@0
    45
    return map_tag();
sl@0
    46
}
sl@0
    47
sl@0
    48
typedef EH_STD::__multimap__<TestClass, TestClass, ThrowCompare, eh_allocator(TestClass) > TestMultiMap;
sl@0
    49
sl@0
    50
void test_multimap()
sl@0
    51
{
sl@0
    52
    TestMultiMap testMultiMap, testMultiMap2;
sl@0
    53
sl@0
    54
    const size_t mapSize = random_number(random_base);
sl@0
    55
sl@0
    56
    while ( testMultiMap.size() < mapSize )
sl@0
    57
    {
sl@0
    58
        TestMultiMap::value_type x;
sl@0
    59
        testMultiMap.insert( x );
sl@0
    60
        testMultiMap2.insert( TestMultiMap::value_type() );
sl@0
    61
    }
sl@0
    62
sl@0
    63
    StrongCheck( testMultiMap, test_insert_value<TestMultiMap>(testMultiMap) );
sl@0
    64
sl@0
    65
    size_t insCnt = 1 + random_number(random_base);
sl@0
    66
    TestMultiMap::value_type *insFirst = new TestMultiMap::value_type[insCnt];
sl@0
    67
sl@0
    68
    WeakCheck( testMultiMap, insert_range_tester(testMultiMap, insFirst, insFirst+insCnt) );
sl@0
    69
sl@0
    70
    ConstCheck( 0, test_construct_pointer_range<TestMultiMap>(insFirst, insFirst+insCnt) );
sl@0
    71
    delete[] insFirst;
sl@0
    72
sl@0
    73
sl@0
    74
    WeakCheck( testMultiMap, insert_range_tester(testMultiMap, testMultiMap2.begin(), testMultiMap2.end() ) );
sl@0
    75
sl@0
    76
sl@0
    77
    ConstCheck( 0, test_default_construct<TestMultiMap>() );
sl@0
    78
sl@0
    79
    ConstCheck( 0, test_construct_iter_range<TestMultiMap>( testMultiMap2 ) );
sl@0
    80
sl@0
    81
    ConstCheck( testMultiMap, test_copy_construct<TestMultiMap>() );
sl@0
    82
sl@0
    83
    WeakCheck( testMultiMap, test_assign_op<TestMultiMap>( testMultiMap2 ) );
sl@0
    84
}
sl@0
    85
sl@0
    86
typedef EH_STD::__map__<TestClass, TestClass, ThrowCompare, eh_allocator(TestClass) > TestMap;
sl@0
    87
sl@0
    88
void CheckInvariant( const TestMap& m );
sl@0
    89
sl@0
    90
void CheckInvariant( const TestMap& m )
sl@0
    91
{
sl@0
    92
//  assert( map.__rb_verify() );
sl@0
    93
    size_t total = 0;
sl@0
    94
    EH_DISTANCE( m.begin(), m.end(), total );
sl@0
    95
    assert( m.size() == total );
sl@0
    96
}
sl@0
    97
sl@0
    98
void test_map()
sl@0
    99
{
sl@0
   100
    TestMap testMap, testMap2;
sl@0
   101
sl@0
   102
    const size_t mapSize = random_number(random_base);
sl@0
   103
sl@0
   104
    while ( testMap.size() < mapSize )
sl@0
   105
    {
sl@0
   106
        TestMap::value_type x;
sl@0
   107
        testMap.insert( x );
sl@0
   108
        testMap2.insert( TestMap::value_type() );
sl@0
   109
    }
sl@0
   110
sl@0
   111
    StrongCheck( testMap, test_insert_value<TestMap>(testMap) );
sl@0
   112
sl@0
   113
    size_t insCnt = random_number(random_base);
sl@0
   114
    TestMap::value_type *insFirst = new TestMap::value_type[1+insCnt];
sl@0
   115
sl@0
   116
    WeakCheck( testMap, insert_range_tester(testMap, insFirst, insFirst+insCnt) );
sl@0
   117
sl@0
   118
    ConstCheck( 0, test_construct_pointer_range<TestMap>(insFirst, insFirst+insCnt) );
sl@0
   119
    delete[] insFirst;
sl@0
   120
sl@0
   121
    WeakCheck( testMap, insert_range_tester(testMap, testMap2.begin(), testMap2.end() ) );
sl@0
   122
    ConstCheck( 0, test_default_construct<TestMap>() );
sl@0
   123
    ConstCheck( 0, test_construct_iter_range<TestMap>( testMap2 ) );
sl@0
   124
    ConstCheck( testMap, test_copy_construct<TestMap>() );
sl@0
   125
    WeakCheck( testMap, test_assign_op<TestMap>( testMap2 ) );
sl@0
   126
}
sl@0
   127