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