• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***********************************************************************************
2   test_hash_set.cpp
3 
4  * Copyright (c) 1997
5  * Mark of the Unicorn, Inc.
6  *
7  * Permission to use, copy, modify, distribute and sell this software
8  * and its documentation for any purpose is hereby granted without fee,
9  * provided that the above copyright notice appear in all copies and
10  * that both that copyright notice and this permission notice appear
11  * in supporting documentation.  Mark of the Unicorn makes no
12  * representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied warranty.
14 
15 ***********************************************************************************/
16 #include "Tests.h"
17 
18 #if defined( EH_HASHED_CONTAINERS_IMPLEMENTED )
19 
20 #  include <hash_set>
21 
22 #include "TestClass.h"
23 #include "LeakCheck.h"
24 #include "test_construct.h"
25 #include "test_assign_op.h"
26 #include "test_push_back.h"
27 #include "test_insert.h"
28 #include "test_push_front.h"
29 #include "ThrowCompare.h"
30 #include "test_hash_resize.h"
31 
32 typedef EH_STD::__hash_multiset__<TestClass, ThrowHash, ThrowEqual,
33   eh_allocator(TestClass) > TestMultiSet;
34 
35 inline multiset_tag
container_category(const TestMultiSet &)36 container_category(const TestMultiSet&)
37 {
38   return multiset_tag();
39 }
40 
test_hash_multiset()41 void test_hash_multiset()
42 {
43 # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
44   TestMultiSet testMultiSet, testMultiSet2;
45 
46         const size_t hash_setSize = random_number(random_base);
47 
48   while ( testMultiSet.size() < hash_setSize )
49   {
50     TestMultiSet::value_type x;
51     testMultiSet.insert( x );
52     testMultiSet2.insert( TestMultiSet::value_type() );
53   }
54 
55 #  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
56   WeakCheck( testMultiSet, test_hash_resize<TestMultiSet>() );
57   // TestMultiSet == TestMultiSet: no such operator! - ptr
58   // StrongCheck( testMultiSet, test_insert_noresize<TestMultiSet>(testMultiSet) );
59 #  endif
60   WeakCheck( testMultiSet, test_insert_value<TestMultiSet>(testMultiSet) );
61 
62   size_t insCnt = random_number(random_base);
63   TestMultiSet::value_type *insFirst = new TestMultiSet::value_type[1+insCnt];
64   WeakCheck( testMultiSet, insert_range_tester(testMultiSet, insFirst, insFirst+insCnt) );
65   ConstCheck( 0, test_construct_pointer_range<TestMultiSet>(insFirst, insFirst+insCnt) );
66   delete[] insFirst;
67 
68   WeakCheck( testMultiSet, insert_range_tester(testMultiSet, testMultiSet2.begin(), testMultiSet2.end() ) );
69 
70   ConstCheck( 0, test_default_construct<TestMultiSet>() );
71 #  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
72   ConstCheck( 0, test_construct_iter_range_n<TestMultiSet>( testMultiSet2 ) );
73 #  endif
74   ConstCheck( testMultiSet, test_copy_construct<TestMultiSet>() );
75 
76   WeakCheck( testMultiSet, test_assign_op<TestMultiSet>( testMultiSet2 ) );
77 # endif
78 }
79 
80 typedef EH_STD::__hash_set__<TestClass, ThrowHash, ThrowEqual, eh_allocator(TestClass) > TestSet;
81 
82 inline set_tag
container_category(const TestSet &)83 container_category(const TestSet&)
84 {
85   return set_tag();
86 }
87 
test_hash_set()88 void test_hash_set()
89 {
90 # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
91   TestSet testSet, testSet2;
92 
93         const size_t hash_setSize = random_number(random_base);
94 
95   while ( testSet.size() < hash_setSize )
96   {
97     TestSet::value_type x;
98     testSet.insert( x );
99     testSet2.insert( TestSet::value_type() );
100   }
101 
102 #  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
103   WeakCheck( testSet, test_hash_resize<TestSet>() );
104   // TestMultiSet == TestMultiSet: no such operator! - ptr
105   // StrongCheck( testSet, test_insert_noresize<TestSet>(testSet) );
106 #  endif
107   WeakCheck( testSet, test_insert_value<TestSet>(testSet) );
108 
109   size_t insCnt = random_number(random_base);
110   TestSet::value_type *insFirst = new TestSet::value_type[1+insCnt];
111   WeakCheck( testSet, insert_range_tester(testSet, insFirst, insFirst+insCnt) );
112   ConstCheck( 0, test_construct_pointer_range<TestSet>(insFirst, insFirst+insCnt) );
113   delete[] insFirst;
114 
115   WeakCheck( testSet, insert_range_tester(testSet, testSet2.begin(), testSet2.end() ) );
116 
117   ConstCheck( 0, test_default_construct<TestSet>() );
118 #  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
119   ConstCheck( 0, test_construct_iter_range_n<TestSet>( testSet2 ) );
120 #  endif
121   ConstCheck( testSet, test_copy_construct<TestSet>() );
122 
123   WeakCheck( testSet, test_assign_op<TestSet>( testSet2 ) );
124 # endif
125 }
126 
127 #endif  // EH_HASHED_CONTAINERS_IMPLEMENTED
128