os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/set_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
#include <e32std.h>
sl@0
    20
#include <set>
sl@0
    21
#include <algorithm>
sl@0
    22
#include <functional>
sl@0
    23
sl@0
    24
#include "cppunit/cppunit_proxy.h"
sl@0
    25
sl@0
    26
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
    27
using namespace std;
sl@0
    28
#endif
sl@0
    29
sl@0
    30
//
sl@0
    31
// TestCase class
sl@0
    32
//
sl@0
    33
class SetTest : public CPPUNIT_NS::TestCase
sl@0
    34
{
sl@0
    35
  CPPUNIT_TEST_SUITE(SetTest);
sl@0
    36
  CPPUNIT_TEST(set1);
sl@0
    37
  CPPUNIT_TEST(set2);
sl@0
    38
  CPPUNIT_TEST(erase);
sl@0
    39
  CPPUNIT_TEST(insert);
sl@0
    40
  CPPUNIT_TEST(find);
sl@0
    41
  CPPUNIT_TEST(bounds);
sl@0
    42
  CPPUNIT_TEST(specialized_less);
sl@0
    43
  CPPUNIT_TEST(implementation_check);
sl@0
    44
  CPPUNIT_TEST(allocator_with_state);
sl@0
    45
  CPPUNIT_TEST(reverse_iterator_test);
sl@0
    46
#if !defined (STLPORT) || !defined (_STLP_USE_CONTAINERS_EXTENSION)
sl@0
    47
  CPPUNIT_IGNORE;
sl@0
    48
#endif
sl@0
    49
  CPPUNIT_TEST(template_methods);
sl@0
    50
  CPPUNIT_TEST(set_cov1);
sl@0
    51
  CPPUNIT_TEST(set_cov2);
sl@0
    52
  CPPUNIT_TEST(set_cov3);
sl@0
    53
  CPPUNIT_TEST(multiset_cov1);
sl@0
    54
  CPPUNIT_TEST(multiset_cov2);
sl@0
    55
  CPPUNIT_TEST(multiset_cov3);
sl@0
    56
  CPPUNIT_TEST_SUITE_END();
sl@0
    57
sl@0
    58
protected:
sl@0
    59
  void set1();
sl@0
    60
  void set2();
sl@0
    61
  void erase();
sl@0
    62
  void insert();
sl@0
    63
  void find();
sl@0
    64
  void bounds();
sl@0
    65
  void specialized_less();
sl@0
    66
  void implementation_check();
sl@0
    67
  void allocator_with_state();
sl@0
    68
  void reverse_iterator_test();
sl@0
    69
  void template_methods();
sl@0
    70
  void set_cov1();
sl@0
    71
  void set_cov2();
sl@0
    72
  void set_cov3();
sl@0
    73
  void multiset_cov1();
sl@0
    74
  void multiset_cov2();
sl@0
    75
  void multiset_cov3();
sl@0
    76
};
sl@0
    77
sl@0
    78
CPPUNIT_TEST_SUITE_REGISTRATION(SetTest);
sl@0
    79
sl@0
    80
sl@0
    81
//
sl@0
    82
// tests implementation
sl@0
    83
//
sl@0
    84
void SetTest::set1()
sl@0
    85
{
sl@0
    86
  set<int, less<int> > s;
sl@0
    87
  CPPUNIT_ASSERT (s.count(42) == 0);
sl@0
    88
  s.insert(42);
sl@0
    89
  CPPUNIT_ASSERT (s.count(42) == 1);
sl@0
    90
  s.insert(42);
sl@0
    91
  CPPUNIT_ASSERT (s.count(42) == 1);
sl@0
    92
  size_t count = s.erase(42);
sl@0
    93
  CPPUNIT_ASSERT (count == 1);
sl@0
    94
}
sl@0
    95
sl@0
    96
void SetTest::set2()
sl@0
    97
{
sl@0
    98
  typedef set<int, less<int> > int_set;
sl@0
    99
  int_set s;
sl@0
   100
  pair<int_set::iterator, bool> p = s.insert(42);
sl@0
   101
  CPPUNIT_ASSERT (p.second == true);
sl@0
   102
  p = s.insert(42);
sl@0
   103
  CPPUNIT_ASSERT (p.second == false);
sl@0
   104
sl@0
   105
  int array1 [] = { 1, 3, 6, 7 };
sl@0
   106
  s.insert(array1, array1 + 4);
sl@0
   107
  CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 5);
sl@0
   108
sl@0
   109
  int_set s2;
sl@0
   110
  s2.swap(s);
sl@0
   111
  CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 5);
sl@0
   112
  CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0);
sl@0
   113
sl@0
   114
  int_set s3;
sl@0
   115
  s3.swap(s);
sl@0
   116
  s3.swap(s2);
sl@0
   117
  CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0);
sl@0
   118
  CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 0);
sl@0
   119
  CPPUNIT_ASSERT (distance(s3.begin(), s3.end()) == 5);
sl@0
   120
}
sl@0
   121
sl@0
   122
void SetTest::erase()
sl@0
   123
{
sl@0
   124
  set<int, less<int> > s;
sl@0
   125
  s.insert(1);
sl@0
   126
  s.erase(s.begin());
sl@0
   127
  CPPUNIT_ASSERT( s.empty() );
sl@0
   128
sl@0
   129
  size_t nb = s.erase(1);
sl@0
   130
  CPPUNIT_ASSERT(nb == 0);
sl@0
   131
}
sl@0
   132
sl@0
   133
void SetTest::insert()
sl@0
   134
{
sl@0
   135
  set<int> s;
sl@0
   136
  set<int>::iterator i = s.insert( s.end(), 0 );
sl@0
   137
  CPPUNIT_ASSERT( *i == 0 );
sl@0
   138
}
sl@0
   139
sl@0
   140
void SetTest::find()
sl@0
   141
{
sl@0
   142
  set<int> s;
sl@0
   143
sl@0
   144
  CPPUNIT_ASSERT( s.find(0) == s.end() );
sl@0
   145
sl@0
   146
  set<int> const& crs = s;
sl@0
   147
sl@0
   148
  CPPUNIT_ASSERT( crs.find(0) == crs.end() );
sl@0
   149
}
sl@0
   150
sl@0
   151
void SetTest::bounds()
sl@0
   152
{
sl@0
   153
  int array1 [] = { 1, 3, 6, 7 };
sl@0
   154
  set<int> s(array1, array1 + sizeof(array1) / sizeof(array1[0]));
sl@0
   155
  set<int> const& crs = s;
sl@0
   156
sl@0
   157
  set<int>::iterator sit;
sl@0
   158
  set<int>::const_iterator scit;
sl@0
   159
  pair<set<int>::iterator, set<int>::iterator> pit;
sl@0
   160
  pair<set<int>::const_iterator, set<int>::const_iterator> pcit;
sl@0
   161
sl@0
   162
  //Check iterator on mutable set
sl@0
   163
  sit = s.lower_bound(2);
sl@0
   164
  CPPUNIT_ASSERT( sit != s.end() );
sl@0
   165
  CPPUNIT_ASSERT( *sit == 3 );
sl@0
   166
sl@0
   167
  sit = s.upper_bound(5);
sl@0
   168
  CPPUNIT_ASSERT( sit != s.end() );
sl@0
   169
  CPPUNIT_ASSERT( *sit == 6 );
sl@0
   170
sl@0
   171
  pit = s.equal_range(6);
sl@0
   172
  CPPUNIT_ASSERT( pit.first != pit.second );
sl@0
   173
  CPPUNIT_ASSERT( pit.first != s.end() );
sl@0
   174
  CPPUNIT_ASSERT( *pit.first == 6 );
sl@0
   175
  CPPUNIT_ASSERT( pit.second != s.end() );
sl@0
   176
  CPPUNIT_ASSERT( *pit.second == 7 );
sl@0
   177
sl@0
   178
  pit = s.equal_range(4);
sl@0
   179
  CPPUNIT_ASSERT( pit.first == pit.second );
sl@0
   180
  CPPUNIT_ASSERT( pit.first != s.end() );
sl@0
   181
  CPPUNIT_ASSERT( *pit.first == 6 );
sl@0
   182
  CPPUNIT_ASSERT( pit.second != s.end() );
sl@0
   183
  CPPUNIT_ASSERT( *pit.second == 6 );
sl@0
   184
sl@0
   185
  //Check const_iterator on mutable set
sl@0
   186
  scit = s.lower_bound(2);
sl@0
   187
  CPPUNIT_ASSERT( scit != s.end() );
sl@0
   188
  CPPUNIT_ASSERT( *scit == 3 );
sl@0
   189
sl@0
   190
  scit = s.upper_bound(5);
sl@0
   191
  CPPUNIT_ASSERT( scit != s.end() );
sl@0
   192
  CPPUNIT_ASSERT( *scit == 6 );
sl@0
   193
sl@0
   194
#ifdef _STLP_MEMBER_TEMPLATES
sl@0
   195
  pcit = s.equal_range(6);
sl@0
   196
  CPPUNIT_ASSERT( pcit.first != pcit.second );
sl@0
   197
  CPPUNIT_ASSERT( pcit.first != s.end() );
sl@0
   198
  CPPUNIT_ASSERT( *pcit.first == 6 );
sl@0
   199
  CPPUNIT_ASSERT( pcit.second != s.end() );
sl@0
   200
  CPPUNIT_ASSERT( *pcit.second == 7 );
sl@0
   201
#endif
sl@0
   202
sl@0
   203
  //Check const_iterator on const set
sl@0
   204
  scit = crs.lower_bound(2);
sl@0
   205
  CPPUNIT_ASSERT( scit != crs.end() );
sl@0
   206
  CPPUNIT_ASSERT( *scit == 3 );
sl@0
   207
sl@0
   208
  scit = crs.upper_bound(5);
sl@0
   209
  CPPUNIT_ASSERT( scit != crs.end() );
sl@0
   210
  CPPUNIT_ASSERT( *scit == 6 );
sl@0
   211
sl@0
   212
  pcit = crs.equal_range(6);
sl@0
   213
  CPPUNIT_ASSERT( pcit.first != pcit.second );
sl@0
   214
  CPPUNIT_ASSERT( pcit.first != crs.end() );
sl@0
   215
  CPPUNIT_ASSERT( *pcit.first == 6 );
sl@0
   216
  CPPUNIT_ASSERT( pcit.second != crs.end() );
sl@0
   217
  CPPUNIT_ASSERT( *pcit.second == 7 );
sl@0
   218
}
sl@0
   219
sl@0
   220
sl@0
   221
class SetTestClass {
sl@0
   222
public:
sl@0
   223
  SetTestClass (int data) : _data(data)
sl@0
   224
  {}
sl@0
   225
sl@0
   226
  int data() const {
sl@0
   227
    return _data;
sl@0
   228
  }
sl@0
   229
sl@0
   230
private:
sl@0
   231
  int _data;
sl@0
   232
};
sl@0
   233
sl@0
   234
namespace std {
sl@0
   235
  template <>
sl@0
   236
  struct less<SetTestClass> {
sl@0
   237
    bool operator () (SetTestClass const& lhs, SetTestClass const& rhs) const {
sl@0
   238
      return lhs.data() < rhs.data();
sl@0
   239
    }
sl@0
   240
  };
sl@0
   241
}
sl@0
   242
sl@0
   243
void SetTest::specialized_less()
sl@0
   244
{
sl@0
   245
  set<SetTestClass> s;
sl@0
   246
  s.insert(SetTestClass(1));
sl@0
   247
  s.insert(SetTestClass(3));
sl@0
   248
  s.insert(SetTestClass(2));
sl@0
   249
  s.insert(SetTestClass(0));
sl@0
   250
sl@0
   251
  set<SetTestClass>::iterator sit(s.begin()), sitEnd(s.end());
sl@0
   252
  int i = 0;
sl@0
   253
  for (; sit != sitEnd; ++sit, ++i) {
sl@0
   254
    CPPUNIT_ASSERT( sit->data() == i );
sl@0
   255
  }
sl@0
   256
}
sl@0
   257
sl@0
   258
void SetTest::implementation_check()
sl@0
   259
{
sl@0
   260
  set<int> tree;
sl@0
   261
  tree.insert(1);
sl@0
   262
  set<int>::iterator it = tree.begin();
sl@0
   263
  int const& int_ref = *it++;
sl@0
   264
  CPPUNIT_ASSERT( int_ref == 1 );
sl@0
   265
sl@0
   266
  CPPUNIT_ASSERT( it == tree.end() );
sl@0
   267
  CPPUNIT_ASSERT( it != tree.begin() );
sl@0
   268
sl@0
   269
  set<int>::const_iterator cit = tree.begin();
sl@0
   270
  int const& int_cref = *cit++;
sl@0
   271
  CPPUNIT_ASSERT( int_cref == 1 );
sl@0
   272
}
sl@0
   273
sl@0
   274
void SetTest::reverse_iterator_test()
sl@0
   275
{
sl@0
   276
  set<int> tree;
sl@0
   277
  tree.insert(1);
sl@0
   278
  tree.insert(2);
sl@0
   279
sl@0
   280
  {
sl@0
   281
    set<int>::reverse_iterator rit(tree.rbegin());
sl@0
   282
    CPPUNIT_ASSERT( *(rit++) == 2 );
sl@0
   283
    CPPUNIT_ASSERT( *(rit++) == 1 );
sl@0
   284
    CPPUNIT_ASSERT( rit == tree.rend() );
sl@0
   285
  }
sl@0
   286
sl@0
   287
  {
sl@0
   288
    set<int> const& ctree = tree;
sl@0
   289
    set<int>::const_reverse_iterator rit(ctree.rbegin());
sl@0
   290
    CPPUNIT_ASSERT( *(rit++) == 2 );
sl@0
   291
    CPPUNIT_ASSERT( *(rit++) == 1 );
sl@0
   292
    CPPUNIT_ASSERT( rit == ctree.rend() );
sl@0
   293
  }
sl@0
   294
}
sl@0
   295
sl@0
   296
void SetTest::allocator_with_state()
sl@0
   297
{
sl@0
   298
  char buf1[1024];
sl@0
   299
  StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
sl@0
   300
sl@0
   301
  char buf2[1024];
sl@0
   302
  StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
sl@0
   303
sl@0
   304
  int i;
sl@0
   305
  typedef set<int, less<int>, StackAllocator<int> > SetInt;
sl@0
   306
  less<int> intLess;
sl@0
   307
sl@0
   308
  {
sl@0
   309
    SetInt sint1(intLess, stack1);
sl@0
   310
    for (i = 0; i < 5; ++i)
sl@0
   311
      sint1.insert(i);
sl@0
   312
    SetInt sint1Cpy(sint1);
sl@0
   313
sl@0
   314
    SetInt sint2(intLess, stack2);
sl@0
   315
    for (; i < 10; ++i)
sl@0
   316
      sint2.insert(i);
sl@0
   317
    SetInt sint2Cpy(sint2);
sl@0
   318
sl@0
   319
    sint1.swap(sint2);
sl@0
   320
sl@0
   321
    CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
sl@0
   322
    CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
sl@0
   323
sl@0
   324
    CPPUNIT_ASSERT( sint1 == sint2Cpy );
sl@0
   325
    CPPUNIT_ASSERT( sint2 == sint1Cpy );
sl@0
   326
    CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
sl@0
   327
    CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
sl@0
   328
  }
sl@0
   329
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
   330
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
   331
  stack1.reset(); stack2.reset();
sl@0
   332
sl@0
   333
  {
sl@0
   334
    SetInt sint1(intLess, stack1);
sl@0
   335
    SetInt sint1Cpy(sint1);
sl@0
   336
sl@0
   337
    SetInt sint2(intLess, stack2);
sl@0
   338
    for (i = 0; i < 10; ++i)
sl@0
   339
      sint2.insert(i);
sl@0
   340
    SetInt sint2Cpy(sint2);
sl@0
   341
sl@0
   342
    sint1.swap(sint2);
sl@0
   343
sl@0
   344
    CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
sl@0
   345
    CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
sl@0
   346
sl@0
   347
    CPPUNIT_ASSERT( sint1 == sint2Cpy );
sl@0
   348
    CPPUNIT_ASSERT( sint2 == sint1Cpy );
sl@0
   349
    CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
sl@0
   350
    CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
sl@0
   351
  }
sl@0
   352
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
   353
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
   354
  stack1.reset(); stack2.reset();
sl@0
   355
sl@0
   356
  {
sl@0
   357
    SetInt sint1(intLess, stack1);
sl@0
   358
    for (i = 0; i < 10; ++i)
sl@0
   359
      sint1.insert(i);
sl@0
   360
    SetInt sint1Cpy(sint1);
sl@0
   361
sl@0
   362
    SetInt sint2(intLess, stack2);
sl@0
   363
    SetInt sint2Cpy(sint2);
sl@0
   364
sl@0
   365
    sint1.swap(sint2);
sl@0
   366
sl@0
   367
    CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
sl@0
   368
    CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
sl@0
   369
sl@0
   370
    CPPUNIT_ASSERT( sint1 == sint2Cpy );
sl@0
   371
    CPPUNIT_ASSERT( sint2 == sint1Cpy );
sl@0
   372
    CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
sl@0
   373
    CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
sl@0
   374
  }
sl@0
   375
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
   376
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
   377
  stack1.reset(); stack2.reset();
sl@0
   378
}
sl@0
   379
sl@0
   380
struct Key
sl@0
   381
{
sl@0
   382
  Key() : m_data(0) {}
sl@0
   383
  explicit Key(int data) : m_data(data) {}
sl@0
   384
sl@0
   385
  int m_data;
sl@0
   386
};
sl@0
   387
sl@0
   388
struct KeyCmp
sl@0
   389
{
sl@0
   390
  bool operator () (Key lhs, Key rhs) const
sl@0
   391
  { return lhs.m_data < rhs.m_data; }
sl@0
   392
sl@0
   393
  bool operator () (Key lhs, int rhs) const
sl@0
   394
  { return lhs.m_data < rhs; }
sl@0
   395
sl@0
   396
  bool operator () (int lhs, Key rhs) const
sl@0
   397
  { return lhs < rhs.m_data; }
sl@0
   398
};
sl@0
   399
sl@0
   400
struct KeyCmpPtr
sl@0
   401
{
sl@0
   402
  bool operator () (Key const volatile *lhs, Key const volatile *rhs) const
sl@0
   403
  { return (*lhs).m_data < (*rhs).m_data; }
sl@0
   404
sl@0
   405
  bool operator () (Key const volatile *lhs, int rhs) const
sl@0
   406
  { return (*lhs).m_data < rhs; }
sl@0
   407
sl@0
   408
  bool operator () (int lhs, Key const volatile *rhs) const
sl@0
   409
  { return lhs < (*rhs).m_data; }
sl@0
   410
};
sl@0
   411
sl@0
   412
void SetTest::template_methods()
sl@0
   413
{
sl@0
   414
#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION)
sl@0
   415
  {
sl@0
   416
    typedef set<Key, KeyCmp> KeySet;
sl@0
   417
    KeySet keySet;
sl@0
   418
    keySet.insert(Key(1));
sl@0
   419
    keySet.insert(Key(2));
sl@0
   420
    keySet.insert(Key(3));
sl@0
   421
    keySet.insert(Key(4));
sl@0
   422
sl@0
   423
    CPPUNIT_ASSERT( keySet.count(Key(1)) == 1 );
sl@0
   424
    CPPUNIT_ASSERT( keySet.count(1) == 1 );
sl@0
   425
    CPPUNIT_ASSERT( keySet.count(5) == 0 );
sl@0
   426
sl@0
   427
    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
sl@0
   428
    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
sl@0
   429
    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
sl@0
   430
    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
sl@0
   431
sl@0
   432
    KeySet const& ckeySet = keySet;
sl@0
   433
    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
sl@0
   434
    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
sl@0
   435
    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
sl@0
   436
    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
sl@0
   437
  }
sl@0
   438
sl@0
   439
  {
sl@0
   440
    typedef set<Key*, KeyCmpPtr> KeySet;
sl@0
   441
    KeySet keySet;
sl@0
   442
    Key key1(1), key2(2), key3(3), key4(4);
sl@0
   443
    keySet.insert(&key1);
sl@0
   444
    keySet.insert(&key2);
sl@0
   445
    keySet.insert(&key3);
sl@0
   446
    keySet.insert(&key4);
sl@0
   447
sl@0
   448
    CPPUNIT_ASSERT( keySet.count(1) == 1 );
sl@0
   449
    CPPUNIT_ASSERT( keySet.count(5) == 0 );
sl@0
   450
sl@0
   451
    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
sl@0
   452
    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
sl@0
   453
    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
sl@0
   454
    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
sl@0
   455
sl@0
   456
    KeySet const& ckeySet = keySet;
sl@0
   457
    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
sl@0
   458
    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
sl@0
   459
    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
sl@0
   460
    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
sl@0
   461
  }
sl@0
   462
  {
sl@0
   463
    typedef multiset<Key, KeyCmp> KeySet;
sl@0
   464
    KeySet keySet;
sl@0
   465
    keySet.insert(Key(1));
sl@0
   466
    keySet.insert(Key(2));
sl@0
   467
    keySet.insert(Key(3));
sl@0
   468
    keySet.insert(Key(4));
sl@0
   469
sl@0
   470
    CPPUNIT_ASSERT( keySet.count(Key(1)) == 1 );
sl@0
   471
    CPPUNIT_ASSERT( keySet.count(1) == 1 );
sl@0
   472
    CPPUNIT_ASSERT( keySet.count(5) == 0 );
sl@0
   473
sl@0
   474
    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
sl@0
   475
    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
sl@0
   476
    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
sl@0
   477
    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
sl@0
   478
sl@0
   479
    KeySet const& ckeySet = keySet;
sl@0
   480
    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
sl@0
   481
    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
sl@0
   482
    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
sl@0
   483
    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
sl@0
   484
  }
sl@0
   485
sl@0
   486
  {
sl@0
   487
    typedef multiset<Key const volatile*, KeyCmpPtr> KeySet;
sl@0
   488
    KeySet keySet;
sl@0
   489
    Key key1(1), key2(2), key3(3), key4(4);
sl@0
   490
    keySet.insert(&key1);
sl@0
   491
    keySet.insert(&key2);
sl@0
   492
    keySet.insert(&key3);
sl@0
   493
    keySet.insert(&key4);
sl@0
   494
sl@0
   495
    CPPUNIT_ASSERT( keySet.count(1) == 1 );
sl@0
   496
    CPPUNIT_ASSERT( keySet.count(5) == 0 );
sl@0
   497
sl@0
   498
    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
sl@0
   499
    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
sl@0
   500
    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
sl@0
   501
    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
sl@0
   502
sl@0
   503
    KeySet const& ckeySet = keySet;
sl@0
   504
    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
sl@0
   505
    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
sl@0
   506
    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
sl@0
   507
    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
sl@0
   508
  }
sl@0
   509
#endif
sl@0
   510
}
sl@0
   511
void SetTest::set_cov1()
sl@0
   512
	{
sl@0
   513
	  __UHEAP_MARK;
sl@0
   514
		{
sl@0
   515
		set <int, less<int> > s1;
sl@0
   516
		set <int, less<int> >::value_compare vc1 = s1.value_comp( );
sl@0
   517
		bool result1 = vc1( 2, 3 );
sl@0
   518
		CPPUNIT_ASSERT( result1 == true );
sl@0
   519
		
sl@0
   520
		set <int, greater<int> > s2;
sl@0
   521
		set<int, greater<int> >::value_compare vc2 = s2.value_comp( );
sl@0
   522
		bool result2 = vc2( 2, 3 );
sl@0
   523
		CPPUNIT_ASSERT( result2 == false );
sl@0
   524
		}
sl@0
   525
		{
sl@0
   526
		set <int>::iterator s2_pIter;
sl@0
   527
		set <int> :: size_type i;
sl@0
   528
		set <int, less<int> > s1, s2;
sl@0
   529
sl@0
   530
		s1.insert( 10 );
sl@0
   531
		s1.insert( 20 );
sl@0
   532
		s1.insert( 30 );
sl@0
   533
		s1.insert( 40 );
sl@0
   534
		
sl@0
   535
		s2=s1;
sl@0
   536
		s2_pIter = s2.begin( ); 
sl@0
   537
		CPPUNIT_ASSERT(*s2_pIter == 10);
sl@0
   538
		
sl@0
   539
		i = s2.size( );
sl@0
   540
		CPPUNIT_ASSERT(i == 4);
sl@0
   541
		}
sl@0
   542
		{
sl@0
   543
		set <int> s1;
sl@0
   544
		s1.max_size( );   
sl@0
   545
		}
sl@0
   546
		  __UHEAP_MARKEND;
sl@0
   547
	}
sl@0
   548
void SetTest::set_cov2()
sl@0
   549
	{
sl@0
   550
	  __UHEAP_MARK;
sl@0
   551
		{
sl@0
   552
		set <int, less<int> > s1;
sl@0
   553
		set<int, less<int> >::key_compare kc1 = s1.key_comp( ) ;
sl@0
   554
		bool result1 = kc1( 2, 3 ) ;
sl@0
   555
		CPPUNIT_ASSERT( result1 == true );  
sl@0
   556
		}
sl@0
   557
		{
sl@0
   558
		set <int> s1;
sl@0
   559
		set <int> :: size_type i;
sl@0
   560
		set <int> :: iterator pIter, Iter1, Iter2;
sl@0
   561
		int i1;
sl@0
   562
sl@0
   563
		for ( i1 = 1 ; i1 < 5 ; i1++ ) 
sl@0
   564
			{
sl@0
   565
		    s1.insert ( i1 * i1 );
sl@0
   566
			}
sl@0
   567
		Iter1 = ++s1.begin( );
sl@0
   568
		Iter2 = --s1.end( );
sl@0
   569
		s1.erase( Iter1, Iter2 );
sl@0
   570
		pIter = s1.begin( ) ;
sl@0
   571
		CPPUNIT_ASSERT(*pIter == 1);
sl@0
   572
		pIter++;
sl@0
   573
		CPPUNIT_ASSERT(*pIter == 16);
sl@0
   574
		i = s1.size( );
sl@0
   575
		CPPUNIT_ASSERT(i == 2);
sl@0
   576
		}
sl@0
   577
		  __UHEAP_MARKEND;		
sl@0
   578
	}
sl@0
   579
void SetTest::set_cov3()
sl@0
   580
	{
sl@0
   581
	  __UHEAP_MARK;
sl@0
   582
		{
sl@0
   583
		set <int> s1;
sl@0
   584
		   
sl@0
   585
		s1.insert( 1 );
sl@0
   586
		s1.insert( 2 );
sl@0
   587
		
sl@0
   588
		CPPUNIT_ASSERT(s1.size()== 2);
sl@0
   589
		s1.clear();
sl@0
   590
		CPPUNIT_ASSERT(s1.size()== 0);
sl@0
   591
		}
sl@0
   592
		{
sl@0
   593
		set <int> s1,s2;
sl@0
   594
		   
sl@0
   595
		s1.insert( 1 );
sl@0
   596
		s1.insert( 2 );
sl@0
   597
		
sl@0
   598
		s2.insert( 3 );
sl@0
   599
		s2.insert( 4 );
sl@0
   600
		bool val = s1 < s2; 
sl@0
   601
		CPPUNIT_ASSERT(val == true);
sl@0
   602
		}
sl@0
   603
		{
sl@0
   604
		typedef set<int, less<int> > int_set;
sl@0
   605
		int_set s;
sl@0
   606
		pair<int_set::iterator, bool> p = s.insert(42);
sl@0
   607
		CPPUNIT_ASSERT (p.second == true);
sl@0
   608
		p = s.insert(42);
sl@0
   609
		CPPUNIT_ASSERT (p.second == false);
sl@0
   610
sl@0
   611
		int array1 [] = { 1, 3, 6, 7 };
sl@0
   612
		s.insert(array1, array1 + 4);
sl@0
   613
		CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 5);
sl@0
   614
sl@0
   615
		int_set s2;
sl@0
   616
		swap(s2,s);
sl@0
   617
		CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 5);
sl@0
   618
		CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0);
sl@0
   619
		}
sl@0
   620
		  __UHEAP_MARKEND;
sl@0
   621
	}
sl@0
   622
void SetTest::multiset_cov1()
sl@0
   623
	{
sl@0
   624
	  __UHEAP_MARK;
sl@0
   625
		{
sl@0
   626
		multiset<int, less<int> > ms1;
sl@0
   627
		multiset <int, less<int> >::value_compare vc1 = ms1.value_comp( );
sl@0
   628
		bool result1 = vc1( 2, 3 );
sl@0
   629
		CPPUNIT_ASSERT( result1 == true );
sl@0
   630
		
sl@0
   631
		multiset<int, greater<int> > ms2;
sl@0
   632
		multiset<int, greater<int> >::value_compare vc2 = ms2.value_comp( );
sl@0
   633
		bool result2 = vc2( 2, 3 );
sl@0
   634
		CPPUNIT_ASSERT( result2 == false );
sl@0
   635
		}
sl@0
   636
		{
sl@0
   637
		multiset <int> ms1, ms2;
sl@0
   638
		multiset <int>::iterator ms1_Iter;
sl@0
   639
		multiset <int> :: size_type i;
sl@0
   640
sl@0
   641
		ms1.insert( 10 );
sl@0
   642
		ms1.insert( 20 );
sl@0
   643
		ms1.insert( 30 );
sl@0
   644
		ms2.insert( 100 );
sl@0
   645
		
sl@0
   646
		ms1.swap( ms2 );
sl@0
   647
		ms1_Iter = ms1.begin( );
sl@0
   648
		CPPUNIT_ASSERT(*ms1_Iter== 100);
sl@0
   649
		
sl@0
   650
		i = ms1.size();
sl@0
   651
		CPPUNIT_ASSERT(i == 1);
sl@0
   652
		}
sl@0
   653
		{
sl@0
   654
		multiset<int> tree;
sl@0
   655
		tree.insert(1);
sl@0
   656
		tree.insert(2);
sl@0
   657
sl@0
   658
			{
sl@0
   659
			multiset<int>::reverse_iterator rit(tree.rbegin());
sl@0
   660
		    CPPUNIT_ASSERT( *(rit++) == 2 );
sl@0
   661
		    CPPUNIT_ASSERT( *(rit++) == 1 );
sl@0
   662
		    CPPUNIT_ASSERT( rit == tree.rend() );
sl@0
   663
			}
sl@0
   664
sl@0
   665
			{
sl@0
   666
			multiset<int> const& ctree = tree;
sl@0
   667
			multiset<int>::const_reverse_iterator rit(ctree.rbegin());
sl@0
   668
		    CPPUNIT_ASSERT( *(rit++) == 2 );
sl@0
   669
		    CPPUNIT_ASSERT( *(rit++) == 1 );
sl@0
   670
		    CPPUNIT_ASSERT( rit == ctree.rend() );
sl@0
   671
			}
sl@0
   672
		}
sl@0
   673
		  __UHEAP_MARKEND;
sl@0
   674
	}
sl@0
   675
void SetTest::multiset_cov2()
sl@0
   676
	{
sl@0
   677
	  __UHEAP_MARK;
sl@0
   678
		{
sl@0
   679
		multiset<int>::iterator ms2_pIter;
sl@0
   680
		multiset<int> :: size_type i;
sl@0
   681
		multiset<int> ms1, ms2;
sl@0
   682
sl@0
   683
		ms1.insert( 10 );
sl@0
   684
		ms1.insert( 20 );
sl@0
   685
		ms1.insert( 30 );
sl@0
   686
		ms1.insert( 40 );
sl@0
   687
		
sl@0
   688
		ms2=ms1;
sl@0
   689
		ms2_pIter = ms2.begin( ); 
sl@0
   690
		CPPUNIT_ASSERT(*ms2_pIter == 10);
sl@0
   691
		
sl@0
   692
		i = ms2.size( );
sl@0
   693
		CPPUNIT_ASSERT(i == 4);
sl@0
   694
		}
sl@0
   695
		{
sl@0
   696
		multiset<int> ms1;
sl@0
   697
		ms1.max_size( );   
sl@0
   698
		}
sl@0
   699
		{
sl@0
   700
		multiset<int> ms1;
sl@0
   701
		multiset<int>::key_compare kc1 = ms1.key_comp( ) ;
sl@0
   702
		bool result1 = kc1( 2, 3 ) ;
sl@0
   703
		CPPUNIT_ASSERT( result1 == true );  
sl@0
   704
		}
sl@0
   705
		{
sl@0
   706
		char buf1[1024];
sl@0
   707
		StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
sl@0
   708
sl@0
   709
		char buf2[1024];
sl@0
   710
		StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
sl@0
   711
sl@0
   712
		int i;
sl@0
   713
		typedef multiset<int, less<int>, StackAllocator<int> > SetInt;
sl@0
   714
		less<int> intLess;
sl@0
   715
			{
sl@0
   716
		SetInt sint1(intLess, stack1);
sl@0
   717
		for (i = 0; i < 5; ++i)
sl@0
   718
			sint1.insert(i);
sl@0
   719
		SetInt sint1Cpy(sint1);
sl@0
   720
sl@0
   721
		SetInt sint2(intLess, stack2);
sl@0
   722
		for (; i < 10; ++i)
sl@0
   723
			sint2.insert(i);
sl@0
   724
		SetInt sint2Cpy(sint2);
sl@0
   725
sl@0
   726
		sint1.swap(sint2);
sl@0
   727
sl@0
   728
		CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
sl@0
   729
		CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
sl@0
   730
sl@0
   731
		CPPUNIT_ASSERT( sint1 == sint2Cpy );
sl@0
   732
		CPPUNIT_ASSERT( sint2 == sint1Cpy );
sl@0
   733
		CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
sl@0
   734
		CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
sl@0
   735
		}
sl@0
   736
		CPPUNIT_ASSERT( stack1.ok() );
sl@0
   737
		CPPUNIT_ASSERT( stack2.ok() );
sl@0
   738
		stack1.reset(); stack2.reset();
sl@0
   739
		}
sl@0
   740
		  __UHEAP_MARKEND;
sl@0
   741
	}
sl@0
   742
void SetTest::multiset_cov3()
sl@0
   743
	{
sl@0
   744
	  __UHEAP_MARK;
sl@0
   745
		{
sl@0
   746
		multiset<int> s1;
sl@0
   747
		multiset<int> :: size_type i;
sl@0
   748
		multiset<int> :: iterator pIter, Iter1, Iter2;
sl@0
   749
		int i1;
sl@0
   750
sl@0
   751
		for ( i1 = 1 ; i1 < 5 ; i1++ ) 
sl@0
   752
			{
sl@0
   753
		    s1.insert ( i1 * i1 );
sl@0
   754
			}
sl@0
   755
		Iter1 = ++s1.begin( );
sl@0
   756
		Iter2 = --s1.end( );
sl@0
   757
		s1.erase( Iter1, Iter2 );
sl@0
   758
		pIter = s1.begin( ) ;
sl@0
   759
		CPPUNIT_ASSERT(*pIter == 1);
sl@0
   760
		pIter++;
sl@0
   761
		CPPUNIT_ASSERT(*pIter == 16);
sl@0
   762
		i = s1.size( );
sl@0
   763
		CPPUNIT_ASSERT(i == 2);
sl@0
   764
		}
sl@0
   765
		{
sl@0
   766
		multiset<int> s1;
sl@0
   767
		   
sl@0
   768
		s1.insert( 1 );
sl@0
   769
		s1.insert( 2 );
sl@0
   770
		
sl@0
   771
		CPPUNIT_ASSERT(s1.size()== 2);
sl@0
   772
		s1.clear();
sl@0
   773
		CPPUNIT_ASSERT(s1.size()== 0);
sl@0
   774
		}
sl@0
   775
		{
sl@0
   776
		multiset<int> s;
sl@0
   777
		multiset<int>::iterator i = s.insert( s.end(), 0 );
sl@0
   778
		CPPUNIT_ASSERT( *i == 0 );
sl@0
   779
		}
sl@0
   780
		{
sl@0
   781
		multiset<int> s;
sl@0
   782
		
sl@0
   783
		int array1 [] = { 1, 3, 6, 7 };
sl@0
   784
		s.insert(array1, array1 + 4);
sl@0
   785
		CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 4);
sl@0
   786
	
sl@0
   787
		}
sl@0
   788
		{
sl@0
   789
		multiset <int> ms1, ms2;
sl@0
   790
		multiset <int>::iterator ms1_Iter;
sl@0
   791
		multiset <int> :: size_type i;
sl@0
   792
sl@0
   793
		ms1.insert( 10 );
sl@0
   794
		ms1.insert( 20 );
sl@0
   795
		ms1.insert( 30 );
sl@0
   796
		ms2.insert( 100 );
sl@0
   797
		
sl@0
   798
		swap( ms1,ms2 );
sl@0
   799
		ms1_Iter = ms1.begin( );
sl@0
   800
		CPPUNIT_ASSERT(*ms1_Iter== 100);
sl@0
   801
		
sl@0
   802
		i = ms1.size();
sl@0
   803
		CPPUNIT_ASSERT(i == 1);
sl@0
   804
		}
sl@0
   805
		{
sl@0
   806
		multiset <int> ms1, ms2;
sl@0
   807
sl@0
   808
		ms1.insert( 10 );
sl@0
   809
		ms2.insert( 100 );
sl@0
   810
		bool val = ms1 < ms2;
sl@0
   811
		CPPUNIT_ASSERT( val == true);
sl@0
   812
		}
sl@0
   813
		  __UHEAP_MARKEND;
sl@0
   814
	}