os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/set_test.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/unit/set_test.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,814 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +//Has to be first for StackAllocator swap overload to be taken
    1.20 +//into account (at least using GCC 4.0.1)
    1.21 +#include "stack_allocator.h"
    1.22 +#include <e32std.h>
    1.23 +#include <set>
    1.24 +#include <algorithm>
    1.25 +#include <functional>
    1.26 +
    1.27 +#include "cppunit/cppunit_proxy.h"
    1.28 +
    1.29 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
    1.30 +using namespace std;
    1.31 +#endif
    1.32 +
    1.33 +//
    1.34 +// TestCase class
    1.35 +//
    1.36 +class SetTest : public CPPUNIT_NS::TestCase
    1.37 +{
    1.38 +  CPPUNIT_TEST_SUITE(SetTest);
    1.39 +  CPPUNIT_TEST(set1);
    1.40 +  CPPUNIT_TEST(set2);
    1.41 +  CPPUNIT_TEST(erase);
    1.42 +  CPPUNIT_TEST(insert);
    1.43 +  CPPUNIT_TEST(find);
    1.44 +  CPPUNIT_TEST(bounds);
    1.45 +  CPPUNIT_TEST(specialized_less);
    1.46 +  CPPUNIT_TEST(implementation_check);
    1.47 +  CPPUNIT_TEST(allocator_with_state);
    1.48 +  CPPUNIT_TEST(reverse_iterator_test);
    1.49 +#if !defined (STLPORT) || !defined (_STLP_USE_CONTAINERS_EXTENSION)
    1.50 +  CPPUNIT_IGNORE;
    1.51 +#endif
    1.52 +  CPPUNIT_TEST(template_methods);
    1.53 +  CPPUNIT_TEST(set_cov1);
    1.54 +  CPPUNIT_TEST(set_cov2);
    1.55 +  CPPUNIT_TEST(set_cov3);
    1.56 +  CPPUNIT_TEST(multiset_cov1);
    1.57 +  CPPUNIT_TEST(multiset_cov2);
    1.58 +  CPPUNIT_TEST(multiset_cov3);
    1.59 +  CPPUNIT_TEST_SUITE_END();
    1.60 +
    1.61 +protected:
    1.62 +  void set1();
    1.63 +  void set2();
    1.64 +  void erase();
    1.65 +  void insert();
    1.66 +  void find();
    1.67 +  void bounds();
    1.68 +  void specialized_less();
    1.69 +  void implementation_check();
    1.70 +  void allocator_with_state();
    1.71 +  void reverse_iterator_test();
    1.72 +  void template_methods();
    1.73 +  void set_cov1();
    1.74 +  void set_cov2();
    1.75 +  void set_cov3();
    1.76 +  void multiset_cov1();
    1.77 +  void multiset_cov2();
    1.78 +  void multiset_cov3();
    1.79 +};
    1.80 +
    1.81 +CPPUNIT_TEST_SUITE_REGISTRATION(SetTest);
    1.82 +
    1.83 +
    1.84 +//
    1.85 +// tests implementation
    1.86 +//
    1.87 +void SetTest::set1()
    1.88 +{
    1.89 +  set<int, less<int> > s;
    1.90 +  CPPUNIT_ASSERT (s.count(42) == 0);
    1.91 +  s.insert(42);
    1.92 +  CPPUNIT_ASSERT (s.count(42) == 1);
    1.93 +  s.insert(42);
    1.94 +  CPPUNIT_ASSERT (s.count(42) == 1);
    1.95 +  size_t count = s.erase(42);
    1.96 +  CPPUNIT_ASSERT (count == 1);
    1.97 +}
    1.98 +
    1.99 +void SetTest::set2()
   1.100 +{
   1.101 +  typedef set<int, less<int> > int_set;
   1.102 +  int_set s;
   1.103 +  pair<int_set::iterator, bool> p = s.insert(42);
   1.104 +  CPPUNIT_ASSERT (p.second == true);
   1.105 +  p = s.insert(42);
   1.106 +  CPPUNIT_ASSERT (p.second == false);
   1.107 +
   1.108 +  int array1 [] = { 1, 3, 6, 7 };
   1.109 +  s.insert(array1, array1 + 4);
   1.110 +  CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 5);
   1.111 +
   1.112 +  int_set s2;
   1.113 +  s2.swap(s);
   1.114 +  CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 5);
   1.115 +  CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0);
   1.116 +
   1.117 +  int_set s3;
   1.118 +  s3.swap(s);
   1.119 +  s3.swap(s2);
   1.120 +  CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0);
   1.121 +  CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 0);
   1.122 +  CPPUNIT_ASSERT (distance(s3.begin(), s3.end()) == 5);
   1.123 +}
   1.124 +
   1.125 +void SetTest::erase()
   1.126 +{
   1.127 +  set<int, less<int> > s;
   1.128 +  s.insert(1);
   1.129 +  s.erase(s.begin());
   1.130 +  CPPUNIT_ASSERT( s.empty() );
   1.131 +
   1.132 +  size_t nb = s.erase(1);
   1.133 +  CPPUNIT_ASSERT(nb == 0);
   1.134 +}
   1.135 +
   1.136 +void SetTest::insert()
   1.137 +{
   1.138 +  set<int> s;
   1.139 +  set<int>::iterator i = s.insert( s.end(), 0 );
   1.140 +  CPPUNIT_ASSERT( *i == 0 );
   1.141 +}
   1.142 +
   1.143 +void SetTest::find()
   1.144 +{
   1.145 +  set<int> s;
   1.146 +
   1.147 +  CPPUNIT_ASSERT( s.find(0) == s.end() );
   1.148 +
   1.149 +  set<int> const& crs = s;
   1.150 +
   1.151 +  CPPUNIT_ASSERT( crs.find(0) == crs.end() );
   1.152 +}
   1.153 +
   1.154 +void SetTest::bounds()
   1.155 +{
   1.156 +  int array1 [] = { 1, 3, 6, 7 };
   1.157 +  set<int> s(array1, array1 + sizeof(array1) / sizeof(array1[0]));
   1.158 +  set<int> const& crs = s;
   1.159 +
   1.160 +  set<int>::iterator sit;
   1.161 +  set<int>::const_iterator scit;
   1.162 +  pair<set<int>::iterator, set<int>::iterator> pit;
   1.163 +  pair<set<int>::const_iterator, set<int>::const_iterator> pcit;
   1.164 +
   1.165 +  //Check iterator on mutable set
   1.166 +  sit = s.lower_bound(2);
   1.167 +  CPPUNIT_ASSERT( sit != s.end() );
   1.168 +  CPPUNIT_ASSERT( *sit == 3 );
   1.169 +
   1.170 +  sit = s.upper_bound(5);
   1.171 +  CPPUNIT_ASSERT( sit != s.end() );
   1.172 +  CPPUNIT_ASSERT( *sit == 6 );
   1.173 +
   1.174 +  pit = s.equal_range(6);
   1.175 +  CPPUNIT_ASSERT( pit.first != pit.second );
   1.176 +  CPPUNIT_ASSERT( pit.first != s.end() );
   1.177 +  CPPUNIT_ASSERT( *pit.first == 6 );
   1.178 +  CPPUNIT_ASSERT( pit.second != s.end() );
   1.179 +  CPPUNIT_ASSERT( *pit.second == 7 );
   1.180 +
   1.181 +  pit = s.equal_range(4);
   1.182 +  CPPUNIT_ASSERT( pit.first == pit.second );
   1.183 +  CPPUNIT_ASSERT( pit.first != s.end() );
   1.184 +  CPPUNIT_ASSERT( *pit.first == 6 );
   1.185 +  CPPUNIT_ASSERT( pit.second != s.end() );
   1.186 +  CPPUNIT_ASSERT( *pit.second == 6 );
   1.187 +
   1.188 +  //Check const_iterator on mutable set
   1.189 +  scit = s.lower_bound(2);
   1.190 +  CPPUNIT_ASSERT( scit != s.end() );
   1.191 +  CPPUNIT_ASSERT( *scit == 3 );
   1.192 +
   1.193 +  scit = s.upper_bound(5);
   1.194 +  CPPUNIT_ASSERT( scit != s.end() );
   1.195 +  CPPUNIT_ASSERT( *scit == 6 );
   1.196 +
   1.197 +#ifdef _STLP_MEMBER_TEMPLATES
   1.198 +  pcit = s.equal_range(6);
   1.199 +  CPPUNIT_ASSERT( pcit.first != pcit.second );
   1.200 +  CPPUNIT_ASSERT( pcit.first != s.end() );
   1.201 +  CPPUNIT_ASSERT( *pcit.first == 6 );
   1.202 +  CPPUNIT_ASSERT( pcit.second != s.end() );
   1.203 +  CPPUNIT_ASSERT( *pcit.second == 7 );
   1.204 +#endif
   1.205 +
   1.206 +  //Check const_iterator on const set
   1.207 +  scit = crs.lower_bound(2);
   1.208 +  CPPUNIT_ASSERT( scit != crs.end() );
   1.209 +  CPPUNIT_ASSERT( *scit == 3 );
   1.210 +
   1.211 +  scit = crs.upper_bound(5);
   1.212 +  CPPUNIT_ASSERT( scit != crs.end() );
   1.213 +  CPPUNIT_ASSERT( *scit == 6 );
   1.214 +
   1.215 +  pcit = crs.equal_range(6);
   1.216 +  CPPUNIT_ASSERT( pcit.first != pcit.second );
   1.217 +  CPPUNIT_ASSERT( pcit.first != crs.end() );
   1.218 +  CPPUNIT_ASSERT( *pcit.first == 6 );
   1.219 +  CPPUNIT_ASSERT( pcit.second != crs.end() );
   1.220 +  CPPUNIT_ASSERT( *pcit.second == 7 );
   1.221 +}
   1.222 +
   1.223 +
   1.224 +class SetTestClass {
   1.225 +public:
   1.226 +  SetTestClass (int data) : _data(data)
   1.227 +  {}
   1.228 +
   1.229 +  int data() const {
   1.230 +    return _data;
   1.231 +  }
   1.232 +
   1.233 +private:
   1.234 +  int _data;
   1.235 +};
   1.236 +
   1.237 +namespace std {
   1.238 +  template <>
   1.239 +  struct less<SetTestClass> {
   1.240 +    bool operator () (SetTestClass const& lhs, SetTestClass const& rhs) const {
   1.241 +      return lhs.data() < rhs.data();
   1.242 +    }
   1.243 +  };
   1.244 +}
   1.245 +
   1.246 +void SetTest::specialized_less()
   1.247 +{
   1.248 +  set<SetTestClass> s;
   1.249 +  s.insert(SetTestClass(1));
   1.250 +  s.insert(SetTestClass(3));
   1.251 +  s.insert(SetTestClass(2));
   1.252 +  s.insert(SetTestClass(0));
   1.253 +
   1.254 +  set<SetTestClass>::iterator sit(s.begin()), sitEnd(s.end());
   1.255 +  int i = 0;
   1.256 +  for (; sit != sitEnd; ++sit, ++i) {
   1.257 +    CPPUNIT_ASSERT( sit->data() == i );
   1.258 +  }
   1.259 +}
   1.260 +
   1.261 +void SetTest::implementation_check()
   1.262 +{
   1.263 +  set<int> tree;
   1.264 +  tree.insert(1);
   1.265 +  set<int>::iterator it = tree.begin();
   1.266 +  int const& int_ref = *it++;
   1.267 +  CPPUNIT_ASSERT( int_ref == 1 );
   1.268 +
   1.269 +  CPPUNIT_ASSERT( it == tree.end() );
   1.270 +  CPPUNIT_ASSERT( it != tree.begin() );
   1.271 +
   1.272 +  set<int>::const_iterator cit = tree.begin();
   1.273 +  int const& int_cref = *cit++;
   1.274 +  CPPUNIT_ASSERT( int_cref == 1 );
   1.275 +}
   1.276 +
   1.277 +void SetTest::reverse_iterator_test()
   1.278 +{
   1.279 +  set<int> tree;
   1.280 +  tree.insert(1);
   1.281 +  tree.insert(2);
   1.282 +
   1.283 +  {
   1.284 +    set<int>::reverse_iterator rit(tree.rbegin());
   1.285 +    CPPUNIT_ASSERT( *(rit++) == 2 );
   1.286 +    CPPUNIT_ASSERT( *(rit++) == 1 );
   1.287 +    CPPUNIT_ASSERT( rit == tree.rend() );
   1.288 +  }
   1.289 +
   1.290 +  {
   1.291 +    set<int> const& ctree = tree;
   1.292 +    set<int>::const_reverse_iterator rit(ctree.rbegin());
   1.293 +    CPPUNIT_ASSERT( *(rit++) == 2 );
   1.294 +    CPPUNIT_ASSERT( *(rit++) == 1 );
   1.295 +    CPPUNIT_ASSERT( rit == ctree.rend() );
   1.296 +  }
   1.297 +}
   1.298 +
   1.299 +void SetTest::allocator_with_state()
   1.300 +{
   1.301 +  char buf1[1024];
   1.302 +  StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
   1.303 +
   1.304 +  char buf2[1024];
   1.305 +  StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
   1.306 +
   1.307 +  int i;
   1.308 +  typedef set<int, less<int>, StackAllocator<int> > SetInt;
   1.309 +  less<int> intLess;
   1.310 +
   1.311 +  {
   1.312 +    SetInt sint1(intLess, stack1);
   1.313 +    for (i = 0; i < 5; ++i)
   1.314 +      sint1.insert(i);
   1.315 +    SetInt sint1Cpy(sint1);
   1.316 +
   1.317 +    SetInt sint2(intLess, stack2);
   1.318 +    for (; i < 10; ++i)
   1.319 +      sint2.insert(i);
   1.320 +    SetInt sint2Cpy(sint2);
   1.321 +
   1.322 +    sint1.swap(sint2);
   1.323 +
   1.324 +    CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
   1.325 +    CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
   1.326 +
   1.327 +    CPPUNIT_ASSERT( sint1 == sint2Cpy );
   1.328 +    CPPUNIT_ASSERT( sint2 == sint1Cpy );
   1.329 +    CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
   1.330 +    CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
   1.331 +  }
   1.332 +  CPPUNIT_ASSERT( stack1.ok() );
   1.333 +  CPPUNIT_ASSERT( stack2.ok() );
   1.334 +  stack1.reset(); stack2.reset();
   1.335 +
   1.336 +  {
   1.337 +    SetInt sint1(intLess, stack1);
   1.338 +    SetInt sint1Cpy(sint1);
   1.339 +
   1.340 +    SetInt sint2(intLess, stack2);
   1.341 +    for (i = 0; i < 10; ++i)
   1.342 +      sint2.insert(i);
   1.343 +    SetInt sint2Cpy(sint2);
   1.344 +
   1.345 +    sint1.swap(sint2);
   1.346 +
   1.347 +    CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
   1.348 +    CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
   1.349 +
   1.350 +    CPPUNIT_ASSERT( sint1 == sint2Cpy );
   1.351 +    CPPUNIT_ASSERT( sint2 == sint1Cpy );
   1.352 +    CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
   1.353 +    CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
   1.354 +  }
   1.355 +  CPPUNIT_ASSERT( stack1.ok() );
   1.356 +  CPPUNIT_ASSERT( stack2.ok() );
   1.357 +  stack1.reset(); stack2.reset();
   1.358 +
   1.359 +  {
   1.360 +    SetInt sint1(intLess, stack1);
   1.361 +    for (i = 0; i < 10; ++i)
   1.362 +      sint1.insert(i);
   1.363 +    SetInt sint1Cpy(sint1);
   1.364 +
   1.365 +    SetInt sint2(intLess, stack2);
   1.366 +    SetInt sint2Cpy(sint2);
   1.367 +
   1.368 +    sint1.swap(sint2);
   1.369 +
   1.370 +    CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
   1.371 +    CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
   1.372 +
   1.373 +    CPPUNIT_ASSERT( sint1 == sint2Cpy );
   1.374 +    CPPUNIT_ASSERT( sint2 == sint1Cpy );
   1.375 +    CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
   1.376 +    CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
   1.377 +  }
   1.378 +  CPPUNIT_ASSERT( stack1.ok() );
   1.379 +  CPPUNIT_ASSERT( stack2.ok() );
   1.380 +  stack1.reset(); stack2.reset();
   1.381 +}
   1.382 +
   1.383 +struct Key
   1.384 +{
   1.385 +  Key() : m_data(0) {}
   1.386 +  explicit Key(int data) : m_data(data) {}
   1.387 +
   1.388 +  int m_data;
   1.389 +};
   1.390 +
   1.391 +struct KeyCmp
   1.392 +{
   1.393 +  bool operator () (Key lhs, Key rhs) const
   1.394 +  { return lhs.m_data < rhs.m_data; }
   1.395 +
   1.396 +  bool operator () (Key lhs, int rhs) const
   1.397 +  { return lhs.m_data < rhs; }
   1.398 +
   1.399 +  bool operator () (int lhs, Key rhs) const
   1.400 +  { return lhs < rhs.m_data; }
   1.401 +};
   1.402 +
   1.403 +struct KeyCmpPtr
   1.404 +{
   1.405 +  bool operator () (Key const volatile *lhs, Key const volatile *rhs) const
   1.406 +  { return (*lhs).m_data < (*rhs).m_data; }
   1.407 +
   1.408 +  bool operator () (Key const volatile *lhs, int rhs) const
   1.409 +  { return (*lhs).m_data < rhs; }
   1.410 +
   1.411 +  bool operator () (int lhs, Key const volatile *rhs) const
   1.412 +  { return lhs < (*rhs).m_data; }
   1.413 +};
   1.414 +
   1.415 +void SetTest::template_methods()
   1.416 +{
   1.417 +#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION)
   1.418 +  {
   1.419 +    typedef set<Key, KeyCmp> KeySet;
   1.420 +    KeySet keySet;
   1.421 +    keySet.insert(Key(1));
   1.422 +    keySet.insert(Key(2));
   1.423 +    keySet.insert(Key(3));
   1.424 +    keySet.insert(Key(4));
   1.425 +
   1.426 +    CPPUNIT_ASSERT( keySet.count(Key(1)) == 1 );
   1.427 +    CPPUNIT_ASSERT( keySet.count(1) == 1 );
   1.428 +    CPPUNIT_ASSERT( keySet.count(5) == 0 );
   1.429 +
   1.430 +    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
   1.431 +    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
   1.432 +    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
   1.433 +    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
   1.434 +
   1.435 +    KeySet const& ckeySet = keySet;
   1.436 +    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
   1.437 +    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
   1.438 +    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
   1.439 +    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
   1.440 +  }
   1.441 +
   1.442 +  {
   1.443 +    typedef set<Key*, KeyCmpPtr> KeySet;
   1.444 +    KeySet keySet;
   1.445 +    Key key1(1), key2(2), key3(3), key4(4);
   1.446 +    keySet.insert(&key1);
   1.447 +    keySet.insert(&key2);
   1.448 +    keySet.insert(&key3);
   1.449 +    keySet.insert(&key4);
   1.450 +
   1.451 +    CPPUNIT_ASSERT( keySet.count(1) == 1 );
   1.452 +    CPPUNIT_ASSERT( keySet.count(5) == 0 );
   1.453 +
   1.454 +    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
   1.455 +    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
   1.456 +    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
   1.457 +    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
   1.458 +
   1.459 +    KeySet const& ckeySet = keySet;
   1.460 +    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
   1.461 +    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
   1.462 +    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
   1.463 +    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
   1.464 +  }
   1.465 +  {
   1.466 +    typedef multiset<Key, KeyCmp> KeySet;
   1.467 +    KeySet keySet;
   1.468 +    keySet.insert(Key(1));
   1.469 +    keySet.insert(Key(2));
   1.470 +    keySet.insert(Key(3));
   1.471 +    keySet.insert(Key(4));
   1.472 +
   1.473 +    CPPUNIT_ASSERT( keySet.count(Key(1)) == 1 );
   1.474 +    CPPUNIT_ASSERT( keySet.count(1) == 1 );
   1.475 +    CPPUNIT_ASSERT( keySet.count(5) == 0 );
   1.476 +
   1.477 +    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
   1.478 +    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
   1.479 +    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
   1.480 +    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
   1.481 +
   1.482 +    KeySet const& ckeySet = keySet;
   1.483 +    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
   1.484 +    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
   1.485 +    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
   1.486 +    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
   1.487 +  }
   1.488 +
   1.489 +  {
   1.490 +    typedef multiset<Key const volatile*, KeyCmpPtr> KeySet;
   1.491 +    KeySet keySet;
   1.492 +    Key key1(1), key2(2), key3(3), key4(4);
   1.493 +    keySet.insert(&key1);
   1.494 +    keySet.insert(&key2);
   1.495 +    keySet.insert(&key3);
   1.496 +    keySet.insert(&key4);
   1.497 +
   1.498 +    CPPUNIT_ASSERT( keySet.count(1) == 1 );
   1.499 +    CPPUNIT_ASSERT( keySet.count(5) == 0 );
   1.500 +
   1.501 +    CPPUNIT_ASSERT( keySet.find(2) != keySet.end() );
   1.502 +    CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() );
   1.503 +    CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() );
   1.504 +    CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) );
   1.505 +
   1.506 +    KeySet const& ckeySet = keySet;
   1.507 +    CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() );
   1.508 +    CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() );
   1.509 +    CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() );
   1.510 +    CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) );
   1.511 +  }
   1.512 +#endif
   1.513 +}
   1.514 +void SetTest::set_cov1()
   1.515 +	{
   1.516 +	  __UHEAP_MARK;
   1.517 +		{
   1.518 +		set <int, less<int> > s1;
   1.519 +		set <int, less<int> >::value_compare vc1 = s1.value_comp( );
   1.520 +		bool result1 = vc1( 2, 3 );
   1.521 +		CPPUNIT_ASSERT( result1 == true );
   1.522 +		
   1.523 +		set <int, greater<int> > s2;
   1.524 +		set<int, greater<int> >::value_compare vc2 = s2.value_comp( );
   1.525 +		bool result2 = vc2( 2, 3 );
   1.526 +		CPPUNIT_ASSERT( result2 == false );
   1.527 +		}
   1.528 +		{
   1.529 +		set <int>::iterator s2_pIter;
   1.530 +		set <int> :: size_type i;
   1.531 +		set <int, less<int> > s1, s2;
   1.532 +
   1.533 +		s1.insert( 10 );
   1.534 +		s1.insert( 20 );
   1.535 +		s1.insert( 30 );
   1.536 +		s1.insert( 40 );
   1.537 +		
   1.538 +		s2=s1;
   1.539 +		s2_pIter = s2.begin( ); 
   1.540 +		CPPUNIT_ASSERT(*s2_pIter == 10);
   1.541 +		
   1.542 +		i = s2.size( );
   1.543 +		CPPUNIT_ASSERT(i == 4);
   1.544 +		}
   1.545 +		{
   1.546 +		set <int> s1;
   1.547 +		s1.max_size( );   
   1.548 +		}
   1.549 +		  __UHEAP_MARKEND;
   1.550 +	}
   1.551 +void SetTest::set_cov2()
   1.552 +	{
   1.553 +	  __UHEAP_MARK;
   1.554 +		{
   1.555 +		set <int, less<int> > s1;
   1.556 +		set<int, less<int> >::key_compare kc1 = s1.key_comp( ) ;
   1.557 +		bool result1 = kc1( 2, 3 ) ;
   1.558 +		CPPUNIT_ASSERT( result1 == true );  
   1.559 +		}
   1.560 +		{
   1.561 +		set <int> s1;
   1.562 +		set <int> :: size_type i;
   1.563 +		set <int> :: iterator pIter, Iter1, Iter2;
   1.564 +		int i1;
   1.565 +
   1.566 +		for ( i1 = 1 ; i1 < 5 ; i1++ ) 
   1.567 +			{
   1.568 +		    s1.insert ( i1 * i1 );
   1.569 +			}
   1.570 +		Iter1 = ++s1.begin( );
   1.571 +		Iter2 = --s1.end( );
   1.572 +		s1.erase( Iter1, Iter2 );
   1.573 +		pIter = s1.begin( ) ;
   1.574 +		CPPUNIT_ASSERT(*pIter == 1);
   1.575 +		pIter++;
   1.576 +		CPPUNIT_ASSERT(*pIter == 16);
   1.577 +		i = s1.size( );
   1.578 +		CPPUNIT_ASSERT(i == 2);
   1.579 +		}
   1.580 +		  __UHEAP_MARKEND;		
   1.581 +	}
   1.582 +void SetTest::set_cov3()
   1.583 +	{
   1.584 +	  __UHEAP_MARK;
   1.585 +		{
   1.586 +		set <int> s1;
   1.587 +		   
   1.588 +		s1.insert( 1 );
   1.589 +		s1.insert( 2 );
   1.590 +		
   1.591 +		CPPUNIT_ASSERT(s1.size()== 2);
   1.592 +		s1.clear();
   1.593 +		CPPUNIT_ASSERT(s1.size()== 0);
   1.594 +		}
   1.595 +		{
   1.596 +		set <int> s1,s2;
   1.597 +		   
   1.598 +		s1.insert( 1 );
   1.599 +		s1.insert( 2 );
   1.600 +		
   1.601 +		s2.insert( 3 );
   1.602 +		s2.insert( 4 );
   1.603 +		bool val = s1 < s2; 
   1.604 +		CPPUNIT_ASSERT(val == true);
   1.605 +		}
   1.606 +		{
   1.607 +		typedef set<int, less<int> > int_set;
   1.608 +		int_set s;
   1.609 +		pair<int_set::iterator, bool> p = s.insert(42);
   1.610 +		CPPUNIT_ASSERT (p.second == true);
   1.611 +		p = s.insert(42);
   1.612 +		CPPUNIT_ASSERT (p.second == false);
   1.613 +
   1.614 +		int array1 [] = { 1, 3, 6, 7 };
   1.615 +		s.insert(array1, array1 + 4);
   1.616 +		CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 5);
   1.617 +
   1.618 +		int_set s2;
   1.619 +		swap(s2,s);
   1.620 +		CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 5);
   1.621 +		CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0);
   1.622 +		}
   1.623 +		  __UHEAP_MARKEND;
   1.624 +	}
   1.625 +void SetTest::multiset_cov1()
   1.626 +	{
   1.627 +	  __UHEAP_MARK;
   1.628 +		{
   1.629 +		multiset<int, less<int> > ms1;
   1.630 +		multiset <int, less<int> >::value_compare vc1 = ms1.value_comp( );
   1.631 +		bool result1 = vc1( 2, 3 );
   1.632 +		CPPUNIT_ASSERT( result1 == true );
   1.633 +		
   1.634 +		multiset<int, greater<int> > ms2;
   1.635 +		multiset<int, greater<int> >::value_compare vc2 = ms2.value_comp( );
   1.636 +		bool result2 = vc2( 2, 3 );
   1.637 +		CPPUNIT_ASSERT( result2 == false );
   1.638 +		}
   1.639 +		{
   1.640 +		multiset <int> ms1, ms2;
   1.641 +		multiset <int>::iterator ms1_Iter;
   1.642 +		multiset <int> :: size_type i;
   1.643 +
   1.644 +		ms1.insert( 10 );
   1.645 +		ms1.insert( 20 );
   1.646 +		ms1.insert( 30 );
   1.647 +		ms2.insert( 100 );
   1.648 +		
   1.649 +		ms1.swap( ms2 );
   1.650 +		ms1_Iter = ms1.begin( );
   1.651 +		CPPUNIT_ASSERT(*ms1_Iter== 100);
   1.652 +		
   1.653 +		i = ms1.size();
   1.654 +		CPPUNIT_ASSERT(i == 1);
   1.655 +		}
   1.656 +		{
   1.657 +		multiset<int> tree;
   1.658 +		tree.insert(1);
   1.659 +		tree.insert(2);
   1.660 +
   1.661 +			{
   1.662 +			multiset<int>::reverse_iterator rit(tree.rbegin());
   1.663 +		    CPPUNIT_ASSERT( *(rit++) == 2 );
   1.664 +		    CPPUNIT_ASSERT( *(rit++) == 1 );
   1.665 +		    CPPUNIT_ASSERT( rit == tree.rend() );
   1.666 +			}
   1.667 +
   1.668 +			{
   1.669 +			multiset<int> const& ctree = tree;
   1.670 +			multiset<int>::const_reverse_iterator rit(ctree.rbegin());
   1.671 +		    CPPUNIT_ASSERT( *(rit++) == 2 );
   1.672 +		    CPPUNIT_ASSERT( *(rit++) == 1 );
   1.673 +		    CPPUNIT_ASSERT( rit == ctree.rend() );
   1.674 +			}
   1.675 +		}
   1.676 +		  __UHEAP_MARKEND;
   1.677 +	}
   1.678 +void SetTest::multiset_cov2()
   1.679 +	{
   1.680 +	  __UHEAP_MARK;
   1.681 +		{
   1.682 +		multiset<int>::iterator ms2_pIter;
   1.683 +		multiset<int> :: size_type i;
   1.684 +		multiset<int> ms1, ms2;
   1.685 +
   1.686 +		ms1.insert( 10 );
   1.687 +		ms1.insert( 20 );
   1.688 +		ms1.insert( 30 );
   1.689 +		ms1.insert( 40 );
   1.690 +		
   1.691 +		ms2=ms1;
   1.692 +		ms2_pIter = ms2.begin( ); 
   1.693 +		CPPUNIT_ASSERT(*ms2_pIter == 10);
   1.694 +		
   1.695 +		i = ms2.size( );
   1.696 +		CPPUNIT_ASSERT(i == 4);
   1.697 +		}
   1.698 +		{
   1.699 +		multiset<int> ms1;
   1.700 +		ms1.max_size( );   
   1.701 +		}
   1.702 +		{
   1.703 +		multiset<int> ms1;
   1.704 +		multiset<int>::key_compare kc1 = ms1.key_comp( ) ;
   1.705 +		bool result1 = kc1( 2, 3 ) ;
   1.706 +		CPPUNIT_ASSERT( result1 == true );  
   1.707 +		}
   1.708 +		{
   1.709 +		char buf1[1024];
   1.710 +		StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
   1.711 +
   1.712 +		char buf2[1024];
   1.713 +		StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
   1.714 +
   1.715 +		int i;
   1.716 +		typedef multiset<int, less<int>, StackAllocator<int> > SetInt;
   1.717 +		less<int> intLess;
   1.718 +			{
   1.719 +		SetInt sint1(intLess, stack1);
   1.720 +		for (i = 0; i < 5; ++i)
   1.721 +			sint1.insert(i);
   1.722 +		SetInt sint1Cpy(sint1);
   1.723 +
   1.724 +		SetInt sint2(intLess, stack2);
   1.725 +		for (; i < 10; ++i)
   1.726 +			sint2.insert(i);
   1.727 +		SetInt sint2Cpy(sint2);
   1.728 +
   1.729 +		sint1.swap(sint2);
   1.730 +
   1.731 +		CPPUNIT_ASSERT( sint1.get_allocator().swaped() );
   1.732 +		CPPUNIT_ASSERT( sint2.get_allocator().swaped() );
   1.733 +
   1.734 +		CPPUNIT_ASSERT( sint1 == sint2Cpy );
   1.735 +		CPPUNIT_ASSERT( sint2 == sint1Cpy );
   1.736 +		CPPUNIT_ASSERT( sint1.get_allocator() == stack2 );
   1.737 +		CPPUNIT_ASSERT( sint2.get_allocator() == stack1 );
   1.738 +		}
   1.739 +		CPPUNIT_ASSERT( stack1.ok() );
   1.740 +		CPPUNIT_ASSERT( stack2.ok() );
   1.741 +		stack1.reset(); stack2.reset();
   1.742 +		}
   1.743 +		  __UHEAP_MARKEND;
   1.744 +	}
   1.745 +void SetTest::multiset_cov3()
   1.746 +	{
   1.747 +	  __UHEAP_MARK;
   1.748 +		{
   1.749 +		multiset<int> s1;
   1.750 +		multiset<int> :: size_type i;
   1.751 +		multiset<int> :: iterator pIter, Iter1, Iter2;
   1.752 +		int i1;
   1.753 +
   1.754 +		for ( i1 = 1 ; i1 < 5 ; i1++ ) 
   1.755 +			{
   1.756 +		    s1.insert ( i1 * i1 );
   1.757 +			}
   1.758 +		Iter1 = ++s1.begin( );
   1.759 +		Iter2 = --s1.end( );
   1.760 +		s1.erase( Iter1, Iter2 );
   1.761 +		pIter = s1.begin( ) ;
   1.762 +		CPPUNIT_ASSERT(*pIter == 1);
   1.763 +		pIter++;
   1.764 +		CPPUNIT_ASSERT(*pIter == 16);
   1.765 +		i = s1.size( );
   1.766 +		CPPUNIT_ASSERT(i == 2);
   1.767 +		}
   1.768 +		{
   1.769 +		multiset<int> s1;
   1.770 +		   
   1.771 +		s1.insert( 1 );
   1.772 +		s1.insert( 2 );
   1.773 +		
   1.774 +		CPPUNIT_ASSERT(s1.size()== 2);
   1.775 +		s1.clear();
   1.776 +		CPPUNIT_ASSERT(s1.size()== 0);
   1.777 +		}
   1.778 +		{
   1.779 +		multiset<int> s;
   1.780 +		multiset<int>::iterator i = s.insert( s.end(), 0 );
   1.781 +		CPPUNIT_ASSERT( *i == 0 );
   1.782 +		}
   1.783 +		{
   1.784 +		multiset<int> s;
   1.785 +		
   1.786 +		int array1 [] = { 1, 3, 6, 7 };
   1.787 +		s.insert(array1, array1 + 4);
   1.788 +		CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 4);
   1.789 +	
   1.790 +		}
   1.791 +		{
   1.792 +		multiset <int> ms1, ms2;
   1.793 +		multiset <int>::iterator ms1_Iter;
   1.794 +		multiset <int> :: size_type i;
   1.795 +
   1.796 +		ms1.insert( 10 );
   1.797 +		ms1.insert( 20 );
   1.798 +		ms1.insert( 30 );
   1.799 +		ms2.insert( 100 );
   1.800 +		
   1.801 +		swap( ms1,ms2 );
   1.802 +		ms1_Iter = ms1.begin( );
   1.803 +		CPPUNIT_ASSERT(*ms1_Iter== 100);
   1.804 +		
   1.805 +		i = ms1.size();
   1.806 +		CPPUNIT_ASSERT(i == 1);
   1.807 +		}
   1.808 +		{
   1.809 +		multiset <int> ms1, ms2;
   1.810 +
   1.811 +		ms1.insert( 10 );
   1.812 +		ms2.insert( 100 );
   1.813 +		bool val = ms1 < ms2;
   1.814 +		CPPUNIT_ASSERT( val == true);
   1.815 +		}
   1.816 +		  __UHEAP_MARKEND;
   1.817 +	}