os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/map_test.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
//Has to be first for StackAllocator swap overload to be taken
sl@0
    17
//into account (at least using GCC 4.0.1)
sl@0
    18
#include "stack_allocator.h"
sl@0
    19
sl@0
    20
#include <map>
sl@0
    21
#include <algorithm>
sl@0
    22
#include <functional>
sl@0
    23
#include <e32std.h>
sl@0
    24
sl@0
    25
#include "cppunit/cppunit_proxy.h"
sl@0
    26
sl@0
    27
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
    28
using namespace std;
sl@0
    29
#endif
sl@0
    30
sl@0
    31
//
sl@0
    32
// TestCase class
sl@0
    33
//
sl@0
    34
class MapTest : public CPPUNIT_NS::TestCase
sl@0
    35
{
sl@0
    36
  CPPUNIT_TEST_SUITE(MapTest);
sl@0
    37
  CPPUNIT_TEST(map1);
sl@0
    38
  CPPUNIT_TEST(mmap1);
sl@0
    39
  CPPUNIT_TEST(mmap2);
sl@0
    40
  CPPUNIT_TEST(iterators);
sl@0
    41
  CPPUNIT_TEST(equal_range);
sl@0
    42
  CPPUNIT_TEST(allocator_with_state);
sl@0
    43
#if !defined (STLPORT) || !defined (_STLP_USE_CONTAINERS_EXTENSION)
sl@0
    44
  CPPUNIT_IGNORE;
sl@0
    45
#endif
sl@0
    46
  CPPUNIT_TEST(template_methods);
sl@0
    47
  CPPUNIT_TEST(map_cov1);
sl@0
    48
  CPPUNIT_TEST(map_cov2);
sl@0
    49
  CPPUNIT_TEST(map_cov3);
sl@0
    50
  CPPUNIT_TEST(map_cov4);
sl@0
    51
  CPPUNIT_TEST(multimap_cov1);
sl@0
    52
  CPPUNIT_TEST(multimap_cov2);
sl@0
    53
  CPPUNIT_TEST(multimap_cov3);
sl@0
    54
  CPPUNIT_TEST(multimap_cov4);
sl@0
    55
  CPPUNIT_TEST_SUITE_END();
sl@0
    56
sl@0
    57
protected:
sl@0
    58
  void map1();
sl@0
    59
  void mmap1();
sl@0
    60
  void mmap2();
sl@0
    61
  void iterators();
sl@0
    62
  void equal_range();
sl@0
    63
  void allocator_with_state();
sl@0
    64
  void template_methods();
sl@0
    65
  void map_cov1();
sl@0
    66
  void map_cov2();
sl@0
    67
  void map_cov3();
sl@0
    68
  void map_cov4();
sl@0
    69
  void multimap_cov1();
sl@0
    70
  void multimap_cov2();
sl@0
    71
  void multimap_cov3();
sl@0
    72
  void multimap_cov4();
sl@0
    73
};
sl@0
    74
sl@0
    75
CPPUNIT_TEST_SUITE_REGISTRATION(MapTest);
sl@0
    76
sl@0
    77
//
sl@0
    78
// tests implementation
sl@0
    79
//
sl@0
    80
void MapTest::map1()
sl@0
    81
{
sl@0
    82
  typedef map<char, int, less<char> > maptype;
sl@0
    83
  maptype m;
sl@0
    84
  // Store mappings between roman numerals and decimals.
sl@0
    85
  m['l'] = 50;
sl@0
    86
  m['x'] = 20; // Deliberate mistake.
sl@0
    87
  m['v'] = 5;
sl@0
    88
  m['i'] = 1;
sl@0
    89
//  cout << "m['x'] = " << m['x'] << endl;
sl@0
    90
  CPPUNIT_ASSERT( m['x']== 20 );
sl@0
    91
  m['x'] = 10; // Correct mistake.
sl@0
    92
  CPPUNIT_ASSERT( m['x']== 10 );
sl@0
    93
  CPPUNIT_ASSERT( m['z']== 0 );
sl@0
    94
  //cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
sl@0
    95
  CPPUNIT_ASSERT( m.count('z') == 1 );
sl@0
    96
  //cout << "m.count('z') = " << m.count('z') << endl;
sl@0
    97
  pair<maptype::iterator, bool> p = m.insert(pair<const char, int>('c', 100));
sl@0
    98
  CPPUNIT_ASSERT( p.second );
sl@0
    99
  CPPUNIT_ASSERT( p.first != m.end() );
sl@0
   100
  CPPUNIT_ASSERT( (*p.first).first == 'c' );
sl@0
   101
  CPPUNIT_ASSERT( (*p.first).second == 100 );
sl@0
   102
sl@0
   103
  p = m.insert(pair<const char, int>('c', 100));
sl@0
   104
  CPPUNIT_ASSERT( !p.second ); // already existing pair
sl@0
   105
  CPPUNIT_ASSERT( p.first != m.end() );
sl@0
   106
  CPPUNIT_ASSERT( (*p.first).first == 'c' );
sl@0
   107
  CPPUNIT_ASSERT( (*p.first).second == 100 );
sl@0
   108
}
sl@0
   109
sl@0
   110
void MapTest::mmap1()
sl@0
   111
{
sl@0
   112
  typedef multimap<char, int, less<char> > mmap;
sl@0
   113
  mmap m;
sl@0
   114
  CPPUNIT_ASSERT(m.count('X')==0);
sl@0
   115
sl@0
   116
  m.insert(pair<const char, int>('X', 10)); // Standard way.
sl@0
   117
  CPPUNIT_ASSERT(m.count('X')==1);
sl@0
   118
sl@0
   119
  m.insert(pair<const char, int>('X', 20)); // jbuck: standard way
sl@0
   120
  CPPUNIT_ASSERT(m.count('X')==2);
sl@0
   121
sl@0
   122
  m.insert(pair<const char, int>('Y', 32)); // jbuck: standard way
sl@0
   123
  mmap::iterator i = m.find('X'); // Find first match.
sl@0
   124
  pair<const char, int> p('X', 10);
sl@0
   125
  CPPUNIT_ASSERT(*i == p);
sl@0
   126
  CPPUNIT_ASSERT((*i).first == 'X');
sl@0
   127
  CPPUNIT_ASSERT((*i).second == 10);
sl@0
   128
  i++;
sl@0
   129
  CPPUNIT_ASSERT((*i).first == 'X');
sl@0
   130
  CPPUNIT_ASSERT((*i).second == 20);
sl@0
   131
  i++;
sl@0
   132
  CPPUNIT_ASSERT((*i).first == 'Y');
sl@0
   133
  CPPUNIT_ASSERT((*i).second == 32);
sl@0
   134
  i++;
sl@0
   135
  CPPUNIT_ASSERT(i == m.end());
sl@0
   136
sl@0
   137
  size_t count = m.erase('X');
sl@0
   138
  CPPUNIT_ASSERT(count==2);
sl@0
   139
}
sl@0
   140
void MapTest::mmap2()
sl@0
   141
{
sl@0
   142
  typedef pair<const int, char> pair_type;
sl@0
   143
sl@0
   144
  pair_type p1(3, 'c');
sl@0
   145
  pair_type p2(6, 'f');
sl@0
   146
  pair_type p3(1, 'a');
sl@0
   147
  pair_type p4(2, 'b');
sl@0
   148
  pair_type p5(3, 'x');
sl@0
   149
  pair_type p6(6, 'f');
sl@0
   150
sl@0
   151
  typedef multimap<int, char, less<int> > mmap;
sl@0
   152
sl@0
   153
  pair_type array [] = {
sl@0
   154
    p1,
sl@0
   155
    p2,
sl@0
   156
    p3,
sl@0
   157
    p4,
sl@0
   158
    p5,
sl@0
   159
    p6
sl@0
   160
  };
sl@0
   161
sl@0
   162
  mmap m(array + 0, array + 6);
sl@0
   163
  mmap::iterator i;
sl@0
   164
  i = m.lower_bound(3);
sl@0
   165
  CPPUNIT_ASSERT((*i).first==3);
sl@0
   166
  CPPUNIT_ASSERT((*i).second=='c');
sl@0
   167
sl@0
   168
  i = m.upper_bound(3);
sl@0
   169
  CPPUNIT_ASSERT((*i).first==6);
sl@0
   170
  CPPUNIT_ASSERT((*i).second=='f');
sl@0
   171
}
sl@0
   172
sl@0
   173
sl@0
   174
void MapTest::iterators()
sl@0
   175
{
sl@0
   176
  typedef map<int, char, less<int> > int_map;
sl@0
   177
  int_map imap;
sl@0
   178
  {
sl@0
   179
    int_map::iterator ite(imap.begin());
sl@0
   180
    int_map::const_iterator cite(imap.begin());
sl@0
   181
    CPPUNIT_ASSERT( ite == cite );
sl@0
   182
    CPPUNIT_ASSERT( !(ite != cite) );
sl@0
   183
    CPPUNIT_ASSERT( cite == ite );
sl@0
   184
    CPPUNIT_ASSERT( !(cite != ite) );
sl@0
   185
  }
sl@0
   186
sl@0
   187
  typedef multimap<int, char, less<int> > mmap;
sl@0
   188
  typedef mmap::value_type pair_type;
sl@0
   189
sl@0
   190
  pair_type p1(3, 'c');
sl@0
   191
  pair_type p2(6, 'f');
sl@0
   192
  pair_type p3(1, 'a');
sl@0
   193
  pair_type p4(2, 'b');
sl@0
   194
  pair_type p5(3, 'x');
sl@0
   195
  pair_type p6(6, 'f');
sl@0
   196
sl@0
   197
  pair_type array [] = {
sl@0
   198
    p1,
sl@0
   199
    p2,
sl@0
   200
    p3,
sl@0
   201
    p4,
sl@0
   202
    p5,
sl@0
   203
    p6
sl@0
   204
  };
sl@0
   205
sl@0
   206
  mmap m(array+0, array + 6);
sl@0
   207
sl@0
   208
  {
sl@0
   209
    mmap::iterator ite(m.begin());
sl@0
   210
    mmap::const_iterator cite(m.begin());
sl@0
   211
    //test compare between const_iterator and iterator
sl@0
   212
    CPPUNIT_ASSERT( ite == cite );
sl@0
   213
    CPPUNIT_ASSERT( !(ite != cite) );
sl@0
   214
    CPPUNIT_ASSERT( cite == ite );
sl@0
   215
    CPPUNIT_ASSERT( !(cite != ite) );
sl@0
   216
  }
sl@0
   217
sl@0
   218
#if 0
sl@0
   219
  /*
sl@0
   220
   * A check that map and multimap iterators are NOT comparable
sl@0
   221
   * the following code should generate a compile time error
sl@0
   222
   */
sl@0
   223
  {
sl@0
   224
    int_map::iterator mite(imap.begin());
sl@0
   225
    int_map::const_iterator mcite(imap.begin());
sl@0
   226
    mmap::iterator mmite(m.begin());
sl@0
   227
    mmap::const_iterator mmcite(m.begin());
sl@0
   228
    CPPUNIT_ASSERT( !(mite == mmite) );
sl@0
   229
    CPPUNIT_ASSERT( !(mcite == mmcite) );
sl@0
   230
    CPPUNIT_ASSERT( mite != mmite );
sl@0
   231
    CPPUNIT_ASSERT( mcite != mmcite );
sl@0
   232
    CPPUNIT_ASSERT( !(mite == mmcite) );
sl@0
   233
    CPPUNIT_ASSERT( !(mite == mmcite) );
sl@0
   234
    CPPUNIT_ASSERT( mite != mmcite );
sl@0
   235
    CPPUNIT_ASSERT( mite != mmcite );
sl@0
   236
  }
sl@0
   237
sl@0
   238
#endif
sl@0
   239
sl@0
   240
  mmap::reverse_iterator ri = m.rbegin();
sl@0
   241
  CPPUNIT_ASSERT( ri != m.rend() );
sl@0
   242
  CPPUNIT_ASSERT( ri == m.rbegin() );
sl@0
   243
  CPPUNIT_ASSERT( (*ri).first == 6 );
sl@0
   244
  CPPUNIT_ASSERT( (*ri++).second == 'f' );
sl@0
   245
  CPPUNIT_ASSERT( (*ri).first == 6 );
sl@0
   246
  CPPUNIT_ASSERT( (*ri).second == 'f' );
sl@0
   247
sl@0
   248
  mmap const& cm = m;
sl@0
   249
  mmap::const_reverse_iterator rci = cm.rbegin();
sl@0
   250
  CPPUNIT_ASSERT( rci != cm.rend() );
sl@0
   251
  CPPUNIT_ASSERT( (*rci).first == 6 );
sl@0
   252
  CPPUNIT_ASSERT( (*rci++).second == 'f' );
sl@0
   253
  CPPUNIT_ASSERT( (*rci).first == 6 );
sl@0
   254
  CPPUNIT_ASSERT( (*rci).second == 'f' );
sl@0
   255
}
sl@0
   256
sl@0
   257
void MapTest::equal_range()
sl@0
   258
{
sl@0
   259
  typedef map<char, int, less<char> > maptype;
sl@0
   260
  {
sl@0
   261
    maptype m;
sl@0
   262
    m['x'] = 10;
sl@0
   263
sl@0
   264
    pair<maptype::iterator, maptype::iterator> ret;
sl@0
   265
    ret = m.equal_range('x');
sl@0
   266
    CPPUNIT_ASSERT( ret.first != ret.second );
sl@0
   267
    CPPUNIT_ASSERT( (*(ret.first)).first == 'x' );
sl@0
   268
    CPPUNIT_ASSERT( (*(ret.first)).second == 10 );
sl@0
   269
    CPPUNIT_ASSERT( ++(ret.first) == ret.second );
sl@0
   270
  }
sl@0
   271
  {
sl@0
   272
    {
sl@0
   273
      maptype m;
sl@0
   274
sl@0
   275
      maptype::iterator i = m.lower_bound( 'x' );
sl@0
   276
      CPPUNIT_ASSERT( i == m.end() );
sl@0
   277
sl@0
   278
      i = m.upper_bound( 'x' );
sl@0
   279
      CPPUNIT_ASSERT( i == m.end() );
sl@0
   280
sl@0
   281
      pair<maptype::iterator, maptype::iterator> ret;
sl@0
   282
      ret = m.equal_range('x');
sl@0
   283
      CPPUNIT_ASSERT( ret.first == ret.second );
sl@0
   284
      CPPUNIT_ASSERT( ret.first == m.end() );
sl@0
   285
    }
sl@0
   286
sl@0
   287
    {
sl@0
   288
      const maptype m;
sl@0
   289
      pair<maptype::const_iterator, maptype::const_iterator> ret;
sl@0
   290
      ret = m.equal_range('x');
sl@0
   291
      CPPUNIT_ASSERT( ret.first == ret.second );
sl@0
   292
      CPPUNIT_ASSERT( ret.first == m.end() );
sl@0
   293
    }
sl@0
   294
  }
sl@0
   295
}
sl@0
   296
sl@0
   297
void MapTest::allocator_with_state()
sl@0
   298
{
sl@0
   299
  char buf1[1024];
sl@0
   300
  StackAllocator<pair<const int, int> > stack1(buf1, buf1 + sizeof(buf1));
sl@0
   301
sl@0
   302
  char buf2[1024];
sl@0
   303
  StackAllocator<pair<const int, int> > stack2(buf2, buf2 + sizeof(buf2));
sl@0
   304
sl@0
   305
  {
sl@0
   306
    typedef map<int, int, less<int>, StackAllocator<pair<const int, int> > > MapInt;
sl@0
   307
    less<int> intLess;
sl@0
   308
    MapInt mint1(intLess, stack1);
sl@0
   309
    int i;
sl@0
   310
    for (i = 0; i < 5; ++i)
sl@0
   311
      mint1.insert(MapInt::value_type(i, i));
sl@0
   312
    MapInt mint1Cpy(mint1);
sl@0
   313
sl@0
   314
    MapInt mint2(intLess, stack2);
sl@0
   315
    for (; i < 10; ++i)
sl@0
   316
      mint2.insert(MapInt::value_type(i, i));
sl@0
   317
    MapInt mint2Cpy(mint2);
sl@0
   318
sl@0
   319
    mint1.swap(mint2);
sl@0
   320
sl@0
   321
    CPPUNIT_ASSERT( mint1.get_allocator().swaped() );
sl@0
   322
    CPPUNIT_ASSERT( mint2.get_allocator().swaped() );
sl@0
   323
sl@0
   324
    CPPUNIT_ASSERT( mint1 == mint2Cpy );
sl@0
   325
    CPPUNIT_ASSERT( mint2 == mint1Cpy );
sl@0
   326
    CPPUNIT_ASSERT( mint1.get_allocator() == stack2 );
sl@0
   327
    CPPUNIT_ASSERT( mint2.get_allocator() == stack1 );
sl@0
   328
  }
sl@0
   329
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
   330
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
   331
}
sl@0
   332
sl@0
   333
struct Key
sl@0
   334
{
sl@0
   335
  Key() : m_data(0) {}
sl@0
   336
  explicit Key(int data) : m_data(data) {}
sl@0
   337
sl@0
   338
  int m_data;
sl@0
   339
};
sl@0
   340
sl@0
   341
struct KeyCmp
sl@0
   342
{
sl@0
   343
  bool operator () (Key lhs, Key rhs) const
sl@0
   344
  { return lhs.m_data < rhs.m_data; }
sl@0
   345
sl@0
   346
  bool operator () (Key lhs, int rhs) const
sl@0
   347
  { return lhs.m_data < rhs; }
sl@0
   348
sl@0
   349
  bool operator () (int lhs, Key rhs) const
sl@0
   350
  { return lhs < rhs.m_data; }
sl@0
   351
};
sl@0
   352
sl@0
   353
struct KeyCmpPtr
sl@0
   354
{
sl@0
   355
  bool operator () (Key const volatile *lhs, Key const volatile *rhs) const
sl@0
   356
  { return (*lhs).m_data < (*rhs).m_data; }
sl@0
   357
sl@0
   358
  bool operator () (Key const volatile *lhs, int rhs) const
sl@0
   359
  { return (*lhs).m_data < rhs; }
sl@0
   360
sl@0
   361
  bool operator () (int lhs, Key const volatile *rhs) const
sl@0
   362
  { return lhs < (*rhs).m_data; }
sl@0
   363
};
sl@0
   364
sl@0
   365
void MapTest::template_methods()
sl@0
   366
{
sl@0
   367
#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION)
sl@0
   368
  {
sl@0
   369
    typedef map<Key, int, KeyCmp> Container;
sl@0
   370
    typedef Container::value_type value;
sl@0
   371
    Container cont;
sl@0
   372
    cont.insert(value(Key(1), 1));
sl@0
   373
    cont.insert(value(Key(2), 2));
sl@0
   374
    cont.insert(value(Key(3), 3));
sl@0
   375
    cont.insert(value(Key(4), 4));
sl@0
   376
sl@0
   377
    CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
sl@0
   378
    CPPUNIT_ASSERT( cont.count(1) == 1 );
sl@0
   379
    CPPUNIT_ASSERT( cont.count(5) == 0 );
sl@0
   380
sl@0
   381
    CPPUNIT_ASSERT( cont.find(2) != cont.end() );
sl@0
   382
    CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
sl@0
   383
    CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
sl@0
   384
    CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
sl@0
   385
sl@0
   386
    Container const& ccont = cont;
sl@0
   387
    CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
sl@0
   388
    CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
sl@0
   389
    CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
sl@0
   390
    CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
sl@0
   391
  }
sl@0
   392
sl@0
   393
  {
sl@0
   394
    typedef map<Key*, int, KeyCmpPtr> Container;
sl@0
   395
    typedef Container::value_type value;
sl@0
   396
    Container cont;
sl@0
   397
    Key key1(1), key2(2), key3(3), key4(4);
sl@0
   398
    cont.insert(value(&key1, 1));
sl@0
   399
    cont.insert(value(&key2, 2));
sl@0
   400
    cont.insert(value(&key3, 3));
sl@0
   401
    cont.insert(value(&key4, 4));
sl@0
   402
sl@0
   403
    CPPUNIT_ASSERT( cont.count(1) == 1 );
sl@0
   404
    CPPUNIT_ASSERT( cont.count(5) == 0 );
sl@0
   405
sl@0
   406
    CPPUNIT_ASSERT( cont.find(2) != cont.end() );
sl@0
   407
    CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
sl@0
   408
    CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
sl@0
   409
    CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
sl@0
   410
sl@0
   411
    Container const& ccont = cont;
sl@0
   412
    CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
sl@0
   413
    CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
sl@0
   414
    CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
sl@0
   415
    CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
sl@0
   416
  }
sl@0
   417
  {
sl@0
   418
    typedef multimap<Key, int, KeyCmp> Container;
sl@0
   419
    typedef Container::value_type value;
sl@0
   420
    Container cont;
sl@0
   421
    cont.insert(value(Key(1), 1));
sl@0
   422
    cont.insert(value(Key(2), 2));
sl@0
   423
    cont.insert(value(Key(3), 3));
sl@0
   424
    cont.insert(value(Key(4), 4));
sl@0
   425
sl@0
   426
    CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
sl@0
   427
    CPPUNIT_ASSERT( cont.count(1) == 1 );
sl@0
   428
    CPPUNIT_ASSERT( cont.count(5) == 0 );
sl@0
   429
sl@0
   430
    CPPUNIT_ASSERT( cont.find(2) != cont.end() );
sl@0
   431
    CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
sl@0
   432
    CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
sl@0
   433
    CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
sl@0
   434
sl@0
   435
    Container const& ccont = cont;
sl@0
   436
    CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
sl@0
   437
    CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
sl@0
   438
    CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
sl@0
   439
    CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
sl@0
   440
  }
sl@0
   441
sl@0
   442
  {
sl@0
   443
    typedef multimap<Key const volatile*, int, KeyCmpPtr> Container;
sl@0
   444
    typedef Container::value_type value;
sl@0
   445
    Container cont;
sl@0
   446
    Key key1(1), key2(2), key3(3), key4(4);
sl@0
   447
    cont.insert(value(&key1, 1));
sl@0
   448
    cont.insert(value(&key2, 2));
sl@0
   449
    cont.insert(value(&key3, 3));
sl@0
   450
    cont.insert(value(&key4, 4));
sl@0
   451
sl@0
   452
    CPPUNIT_ASSERT( cont.count(1) == 1 );
sl@0
   453
    CPPUNIT_ASSERT( cont.count(5) == 0 );
sl@0
   454
sl@0
   455
    CPPUNIT_ASSERT( cont.find(2) != cont.end() );
sl@0
   456
    CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
sl@0
   457
    CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
sl@0
   458
    CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
sl@0
   459
sl@0
   460
    Container const& ccont = cont;
sl@0
   461
    CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
sl@0
   462
    CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
sl@0
   463
    CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
sl@0
   464
    CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
sl@0
   465
  }
sl@0
   466
#endif
sl@0
   467
}
sl@0
   468
sl@0
   469
void MapTest::map_cov1()
sl@0
   470
	{
sl@0
   471
	  __UHEAP_MARK;
sl@0
   472
		{
sl@0
   473
		map<int, int> m1;
sl@0
   474
	    map<int, int>::size_type i;
sl@0
   475
	    typedef pair<int, int> Int_Pair;
sl@0
   476
	    m1.insert(Int_Pair(1, 1));
sl@0
   477
	    m1.insert(Int_Pair(2, 4));
sl@0
   478
sl@0
   479
	    i = m1.size();
sl@0
   480
	    CPPUNIT_ASSERT( i==2 );
sl@0
   481
	    m1.clear();
sl@0
   482
	    i = m1.size();
sl@0
   483
	    CPPUNIT_ASSERT( i==0 );
sl@0
   484
		}
sl@0
   485
		{
sl@0
   486
		map <int, int> m1, m2;
sl@0
   487
		bool flag;
sl@0
   488
		typedef pair <int, int> Int_Pair;
sl@0
   489
		
sl@0
   490
		m1.insert ( Int_Pair ( 1, 1 ) );
sl@0
   491
		flag = m1.empty();
sl@0
   492
		CPPUNIT_ASSERT( flag==false );
sl@0
   493
		flag = m2.empty();
sl@0
   494
		CPPUNIT_ASSERT( flag==true );
sl@0
   495
		}
sl@0
   496
		{
sl@0
   497
		map <int, int> m1;
sl@0
   498
		map <int, int> :: iterator m1_Iter;
sl@0
   499
		map <int, int> :: reverse_iterator m1_rIter;
sl@0
   500
		typedef pair <int, int> Int_Pair;
sl@0
   501
		
sl@0
   502
		m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   503
 	    m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   504
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   505
		m1_rIter = m1.rbegin( );
sl@0
   506
		CPPUNIT_ASSERT( m1_rIter->first == 3 );
sl@0
   507
		m1_rIter = m1.rend( );
sl@0
   508
		m1_rIter--;
sl@0
   509
		CPPUNIT_ASSERT( m1_rIter->first == 1 );
sl@0
   510
		}	
sl@0
   511
		  __UHEAP_MARKEND;
sl@0
   512
	}
sl@0
   513
void MapTest::map_cov2()
sl@0
   514
	{
sl@0
   515
	  __UHEAP_MARK;
sl@0
   516
		{
sl@0
   517
		map<int, int> m1, m2, m3;
sl@0
   518
	    map<int, int>::iterator pIter, Iter1, Iter2;
sl@0
   519
	    int i;
sl@0
   520
	    typedef pair<int, int> Int_Pair;
sl@0
   521
	    
sl@0
   522
	    for (i = 1; i < 5; i++)
sl@0
   523
	        {
sl@0
   524
	        m1.insert(Int_Pair(i, i));
sl@0
   525
	        m2.insert(Int_Pair(i, i*i));
sl@0
   526
	        m3.insert(Int_Pair(i, i-1));
sl@0
   527
	        }
sl@0
   528
	    Iter1 = ++m1.begin();
sl@0
   529
	    m1.erase(Iter1);
sl@0
   530
sl@0
   531
	    pIter = m1.begin(); 
sl@0
   532
	    CPPUNIT_ASSERT( pIter->second == 1 );
sl@0
   533
	    pIter++;
sl@0
   534
	    CPPUNIT_ASSERT( pIter->second == 3 );
sl@0
   535
	    pIter++;
sl@0
   536
	    CPPUNIT_ASSERT( pIter->second == 4 );
sl@0
   537
	    
sl@0
   538
	    Iter1 = ++m2.begin();
sl@0
   539
	    Iter2 = --m2.end();
sl@0
   540
	    m2.erase(Iter1, Iter2);
sl@0
   541
	    pIter = m2.begin(); 
sl@0
   542
	    CPPUNIT_ASSERT( pIter->second == 1 );
sl@0
   543
	    pIter++;
sl@0
   544
	    CPPUNIT_ASSERT( pIter->second == 16 );
sl@0
   545
	    
sl@0
   546
	    map<int, int>::size_type n = m3.erase(2);
sl@0
   547
	    pIter = m3.begin(); 
sl@0
   548
	    CPPUNIT_ASSERT( pIter->second == 0 );
sl@0
   549
	    pIter++;
sl@0
   550
	    CPPUNIT_ASSERT( pIter->second == 2 );
sl@0
   551
	    pIter++;
sl@0
   552
	    CPPUNIT_ASSERT( pIter->second == 3 );
sl@0
   553
		}
sl@0
   554
		{
sl@0
   555
		map <int, int> m1;
sl@0
   556
		m1.max_size( );
sl@0
   557
		}
sl@0
   558
		  __UHEAP_MARKEND;
sl@0
   559
	}
sl@0
   560
void MapTest::map_cov3()
sl@0
   561
	{
sl@0
   562
	  __UHEAP_MARK;
sl@0
   563
		{
sl@0
   564
		map <int, int> m1;
sl@0
   565
sl@0
   566
		map <int, int> :: iterator m1_Iter;
sl@0
   567
		map <int, int> :: reverse_iterator m1_rIter;
sl@0
   568
		map <int, int> :: const_reverse_iterator m1_crIter;
sl@0
   569
		typedef pair <int, int> Int_Pair;
sl@0
   570
	
sl@0
   571
		m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   572
 	    m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   573
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   574
		m1_crIter = m1.rbegin( );
sl@0
   575
		CPPUNIT_ASSERT( m1_crIter->first == 3 );
sl@0
   576
		m1_crIter = m1.rend( );
sl@0
   577
		m1_crIter--;
sl@0
   578
		CPPUNIT_ASSERT( m1_crIter->first == 1 );
sl@0
   579
		}
sl@0
   580
		{
sl@0
   581
		map <int, int, less<int> > m1;
sl@0
   582
		map <int, int, less<int> >::value_compare vc1 = m1.value_comp( );
sl@0
   583
		pair< map<int,int>::iterator, bool > pr1, pr2;
sl@0
   584
		   
sl@0
   585
		pr1= m1.insert ( map <int, int> :: value_type ( 1, 10 ) );
sl@0
   586
		pr2= m1.insert ( map <int, int> :: value_type ( 2, 5 ) );
sl@0
   587
sl@0
   588
		CPPUNIT_ASSERT( vc1( *pr1.first, *pr2.first ) == true );
sl@0
   589
		}
sl@0
   590
		{
sl@0
   591
		map <int, int> m1, m2;
sl@0
   592
		typedef pair <int, int> Int_Pair;
sl@0
   593
		map <int, int>::iterator m2_Iter;
sl@0
   594
		map<int, int>::size_type i;
sl@0
   595
    	m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   596
		m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   597
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   598
		m2=m1;
sl@0
   599
		m2_Iter = m2.begin( ); 
sl@0
   600
		CPPUNIT_ASSERT(m2_Iter -> second == 10);
sl@0
   601
	    i = m2.size();
sl@0
   602
		CPPUNIT_ASSERT(i == 3);			
sl@0
   603
		}
sl@0
   604
		  __UHEAP_MARKEND;
sl@0
   605
	}
sl@0
   606
void MapTest::map_cov4()
sl@0
   607
	{
sl@0
   608
	  __UHEAP_MARK;
sl@0
   609
		{
sl@0
   610
		map <int, int> m1, m3;
sl@0
   611
		map <int, int>::iterator m1_Iter;
sl@0
   612
		typedef pair <int, int> Int_Pair;
sl@0
   613
sl@0
   614
		m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   615
		m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   616
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   617
		m3.insert ( Int_Pair ( 30, 300 ) );
sl@0
   618
		
sl@0
   619
		swap(m1,m3);
sl@0
   620
		m1_Iter = m1.begin();
sl@0
   621
		
sl@0
   622
		CPPUNIT_ASSERT(m1_Iter -> second == 300);
sl@0
   623
		}
sl@0
   624
		{
sl@0
   625
		map <int, int> m1, m3;
sl@0
   626
		typedef pair <int, int> Int_Pair;
sl@0
   627
sl@0
   628
		m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   629
		m3.insert ( Int_Pair ( 30, 300 ) );
sl@0
   630
		
sl@0
   631
		bool x = m1 < m3;
sl@0
   632
		CPPUNIT_ASSERT(x == true);
sl@0
   633
		}
sl@0
   634
		  __UHEAP_MARKEND;
sl@0
   635
	}
sl@0
   636
sl@0
   637
void MapTest::multimap_cov1()
sl@0
   638
	{
sl@0
   639
	  __UHEAP_MARK;
sl@0
   640
		{
sl@0
   641
		multimap<int, int> m1;
sl@0
   642
		multimap<int, int>::size_type i;
sl@0
   643
		typedef pair<int, int> Int_Pair;
sl@0
   644
sl@0
   645
		m1.insert(Int_Pair(1, 1));
sl@0
   646
		m1.insert(Int_Pair(2, 4));
sl@0
   647
sl@0
   648
		i = m1.size();
sl@0
   649
	    CPPUNIT_ASSERT( i==2 );
sl@0
   650
	    m1.clear();
sl@0
   651
	    i = m1.size();
sl@0
   652
	    CPPUNIT_ASSERT( i==0 );
sl@0
   653
		}
sl@0
   654
		{
sl@0
   655
		multimap <int, int> m1, m2;
sl@0
   656
		bool flag;
sl@0
   657
		typedef pair <int, int> Int_Pair;
sl@0
   658
		
sl@0
   659
		m1.insert ( Int_Pair ( 1, 1 ) );
sl@0
   660
		flag = m1.empty();
sl@0
   661
		CPPUNIT_ASSERT( flag==false );
sl@0
   662
		flag = m2.empty();
sl@0
   663
		CPPUNIT_ASSERT( flag==true );
sl@0
   664
		}
sl@0
   665
		{
sl@0
   666
		multimap <int, int>::allocator_type m1_Alloc;
sl@0
   667
		multimap <int, int>::allocator_type m2_Alloc;
sl@0
   668
		multimap <int, int>::allocator_type m4_Alloc;
sl@0
   669
	
sl@0
   670
		multimap <int, int> m1;
sl@0
   671
		multimap <int, int, allocator<int> > m2;
sl@0
   672
		m1_Alloc = m1.get_allocator( );
sl@0
   673
		m2_Alloc = m2.get_allocator( );
sl@0
   674
		map <int, int> m4( less<int>( ), m1_Alloc );
sl@0
   675
		m4_Alloc = m4.get_allocator( );
sl@0
   676
	
sl@0
   677
		CPPUNIT_ASSERT( m1_Alloc == m4_Alloc );
sl@0
   678
		}
sl@0
   679
		  __UHEAP_MARKEND;
sl@0
   680
	}
sl@0
   681
void MapTest::multimap_cov2()
sl@0
   682
	{
sl@0
   683
	  __UHEAP_MARK;
sl@0
   684
		{
sl@0
   685
		multimap<int, int> m1, m2;
sl@0
   686
		multimap<int, int>::iterator pIter, Iter1, Iter2;
sl@0
   687
	    int i;
sl@0
   688
	    typedef pair<int, int> Int_Pair;
sl@0
   689
	    
sl@0
   690
	    for (i = 1; i < 5; i++)
sl@0
   691
	        {
sl@0
   692
	        m1.insert(Int_Pair(i, i));
sl@0
   693
	        m2.insert(Int_Pair(i, i*i));
sl@0
   694
	        }
sl@0
   695
	    Iter1 = ++m1.begin();
sl@0
   696
	    m1.erase(Iter1);
sl@0
   697
sl@0
   698
	    pIter = m1.begin(); 
sl@0
   699
	    CPPUNIT_ASSERT( pIter->second == 1 );
sl@0
   700
	    pIter++;
sl@0
   701
	    CPPUNIT_ASSERT( pIter->second == 3 );
sl@0
   702
	    pIter++;
sl@0
   703
	    CPPUNIT_ASSERT( pIter->second == 4 );
sl@0
   704
	    
sl@0
   705
	    Iter1 = ++m2.begin();
sl@0
   706
	    Iter2 = --m2.end();
sl@0
   707
	    m2.erase(Iter1, Iter2);
sl@0
   708
	    pIter = m2.begin(); 
sl@0
   709
	    CPPUNIT_ASSERT( pIter->second == 1 );
sl@0
   710
	    pIter++;
sl@0
   711
	    CPPUNIT_ASSERT( pIter->second == 16 );
sl@0
   712
		}
sl@0
   713
		{
sl@0
   714
		multimap <int, int>::iterator m1_pIter, m2_pIter;
sl@0
   715
		multimap <int, int> :: reverse_iterator m1_rIter;
sl@0
   716
		multimap <int, int> m1, m2;
sl@0
   717
		typedef pair <int, int> Int_Pair;
sl@0
   718
		
sl@0
   719
		m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   720
		m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   721
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   722
		m1.insert( --m1.end( ), Int_Pair ( 4, 40 )  );
sl@0
   723
		
sl@0
   724
		m1_rIter = m1.rbegin( );
sl@0
   725
		CPPUNIT_ASSERT( m1_rIter->first == 4 );
sl@0
   726
sl@0
   727
		m2.insert ( Int_Pair ( 10, 100 ) );
sl@0
   728
		m2.insert( ++m1.begin( ), --m1.end( ) );
sl@0
   729
		m2_pIter = m2.begin( ); 
sl@0
   730
		CPPUNIT_ASSERT(m2_pIter -> first == 2);
sl@0
   731
		}
sl@0
   732
		{
sl@0
   733
		multimap <int, int> m1;
sl@0
   734
		m1.max_size( );
sl@0
   735
		}
sl@0
   736
		  __UHEAP_MARKEND;
sl@0
   737
	}
sl@0
   738
void MapTest::multimap_cov3()
sl@0
   739
	{
sl@0
   740
	  __UHEAP_MARK;
sl@0
   741
		{
sl@0
   742
		multimap <int, int, less<int> > m1;
sl@0
   743
		multimap <int, int, less<int> >::key_compare kc1 = m1.key_comp( ) ;
sl@0
   744
		bool result1 = kc1( 2, 3 ) ;
sl@0
   745
		CPPUNIT_ASSERT(result1 == true);
sl@0
   746
		
sl@0
   747
		multimap <int, int, greater_equal<int> > m2;
sl@0
   748
		multimap <int, int, greater_equal<int> >::key_compare kc2 = m2.key_comp( );
sl@0
   749
		bool result2 = kc2( 3, 3 ) ;
sl@0
   750
		CPPUNIT_ASSERT(result1 == true);
sl@0
   751
		}
sl@0
   752
		{
sl@0
   753
	    multimap<int, int> m1, m2;
sl@0
   754
	    multimap<int, int>::size_type i;
sl@0
   755
	    typedef pair<int, int> Int_Pair;
sl@0
   756
sl@0
   757
	    m1.insert(Int_Pair(1, 1));
sl@0
   758
	    i = m1.size();
sl@0
   759
		CPPUNIT_ASSERT(i == 1);			
sl@0
   760
	    m1.insert(Int_Pair(2, 4));
sl@0
   761
	    i = m1.size();
sl@0
   762
		CPPUNIT_ASSERT(i == 2);			
sl@0
   763
		}
sl@0
   764
		{
sl@0
   765
		multimap <int, int> m1, m2;
sl@0
   766
		multimap <int, int>::iterator m1_Iter;
sl@0
   767
		typedef pair <int, int> Int_Pair;
sl@0
   768
	    multimap<int, int>::size_type i;
sl@0
   769
	    
sl@0
   770
    	m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   771
		m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   772
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   773
		m2.insert ( Int_Pair ( 30, 300 ) );
sl@0
   774
		m1.swap( m2 );
sl@0
   775
		m1_Iter = m1.begin( ); 
sl@0
   776
		CPPUNIT_ASSERT(m1_Iter -> second == 300);
sl@0
   777
	    i = m1.size();
sl@0
   778
		CPPUNIT_ASSERT(i == 1);			
sl@0
   779
		}
sl@0
   780
		  __UHEAP_MARKEND;
sl@0
   781
	}
sl@0
   782
void MapTest::multimap_cov4()
sl@0
   783
	{
sl@0
   784
	  __UHEAP_MARK;
sl@0
   785
		{
sl@0
   786
		multimap <int, int, less<int> > m1;
sl@0
   787
		multimap <int, int, less<int> >::value_compare vc1 = m1.value_comp( );
sl@0
   788
		multimap<int,int>::iterator Iter1, Iter2;
sl@0
   789
sl@0
   790
		Iter1= m1.insert ( multimap <int, int> :: value_type ( 1, 10 ) );
sl@0
   791
		Iter2= m1.insert ( multimap <int, int> :: value_type ( 2, 5 ) );
sl@0
   792
		CPPUNIT_ASSERT( vc1( *Iter1, *Iter2 ) == true );
sl@0
   793
		}
sl@0
   794
		{
sl@0
   795
		multimap <int, int> m1, m2;
sl@0
   796
		typedef pair <int, int> Int_Pair;
sl@0
   797
		multimap <int, int>::iterator m2_Iter;
sl@0
   798
	    multimap<int, int>::size_type i;
sl@0
   799
	    
sl@0
   800
    	m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   801
		m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   802
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   803
		
sl@0
   804
		m2=m1;
sl@0
   805
		m2_Iter = m2.begin( ); 
sl@0
   806
		CPPUNIT_ASSERT(m2_Iter -> second == 10);
sl@0
   807
	    i = m2.size();
sl@0
   808
		CPPUNIT_ASSERT(i == 3);			
sl@0
   809
sl@0
   810
		}
sl@0
   811
		{
sl@0
   812
		multimap <int, int> m1, m2;
sl@0
   813
		multimap <int, int>::iterator m1_Iter;
sl@0
   814
		typedef pair <int, int> Int_Pair;
sl@0
   815
	    multimap<int, int>::size_type i;
sl@0
   816
	    
sl@0
   817
    	m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   818
		m1.insert ( Int_Pair ( 2, 20 ) );
sl@0
   819
		m1.insert ( Int_Pair ( 3, 30 ) );
sl@0
   820
		m2.insert ( Int_Pair ( 30, 300 ) );
sl@0
   821
		swap( m1,m2 );
sl@0
   822
		m1_Iter = m1.begin( ); 
sl@0
   823
		CPPUNIT_ASSERT(m1_Iter -> second == 300);
sl@0
   824
	    i = m1.size();
sl@0
   825
		CPPUNIT_ASSERT(i == 1);			
sl@0
   826
		}
sl@0
   827
		{
sl@0
   828
		multimap <int, int> m1, m2;
sl@0
   829
		typedef pair <int, int> Int_Pair;
sl@0
   830
	    
sl@0
   831
    	m1.insert ( Int_Pair ( 1, 10 ) );
sl@0
   832
		m2.insert ( Int_Pair ( 30, 300 ) );
sl@0
   833
		
sl@0
   834
		bool val = m1 < m2;
sl@0
   835
		CPPUNIT_ASSERT(val == true);
sl@0
   836
		val = (m1 == m2);
sl@0
   837
		CPPUNIT_ASSERT(val == false);
sl@0
   838
		}
sl@0
   839
		  __UHEAP_MARKEND;
sl@0
   840
	}