Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / OrdMultiSet_Test.cpp
blobefd30bb1d5148e8891e2897b9c3f89f8bf50ff36
2 //=============================================================================
3 /**
4 * @file OrdMultiSet_Test.cpp
6 * This is a simple test of the <ACE_Ordered_MultiSet> and
7 * <ACE_Ordered_MultiSet_Iterator> class templates, instantiating
8 * them with type int. No command line arguments are needed to run
9 * the test.
11 * @author Chris Gill <cdgill@cs.wustl.edu>
13 //=============================================================================
16 // Note, for this test the config.h file *must* come first!
17 #include "ace/config-all.h"
19 #include "test_config.h"
20 #include "ace/Containers.h"
23 int
24 run_main (int, ACE_TCHAR *[])
26 int ret = 0;
27 int *ptr = 0;
29 ACE_START_TEST (ACE_TEXT ("OrdMultiSet_Test"));
31 // make an empty set of int and an iterator
32 ACE_Ordered_MultiSet<int> set;
33 ACE_Ordered_MultiSet_Iterator<int> iter(set);
35 // Put in a range of odd ints, without an iterator.
36 int i;
37 for (i = -10; i < 10; ++i)
38 set.insert (2 * i + 1);
40 // Put in an interleaved range of even ints, using an iterator.
41 for (i = -10; i <= 10; ++i)
42 set.insert (2 * i, iter);
44 // Remove the first and last elements of range.
45 while (set.remove (-20) == 0)
47 // No action.
50 while (set.remove (20) == 0)
52 // No action.
55 // Should still have 39 elements in the set.
56 ACE_TEST_ASSERT (set.is_empty () == 0);
57 ACE_TEST_ASSERT (set.size () == 39);
59 // Iterate forward through the range we created: should be one of
60 // each.
61 iter.first ();
63 for (i = -19; i <= 19; ++i)
65 // we should still be in the set
66 ACE_TEST_ASSERT (iter.done () == 0);
68 // make sure the current element is what we expect
69 iter.next (ptr);
70 ACE_TEST_ASSERT (ptr != 0);
71 ACE_TEST_ASSERT (*ptr == i);
73 // move to the next element in the set
74 iter.advance ();
77 // We should have iterated through the entire set.
78 ACE_TEST_ASSERT (iter.done () != 0);
80 // Iterate backward through the range we created: should be one of
81 // each.
82 iter.last ();
84 for (i = 19; i >= -19; --i)
86 // We should still be in the set.
87 ACE_TEST_ASSERT (iter.done () == 0);
89 // Make sure the current element is what we expect.
90 int *ptr = 0;
91 iter.next (ptr);
92 ACE_TEST_ASSERT (ptr != 0);
93 ACE_TEST_ASSERT (*ptr == i);
95 // Move to the previous element in the set.
96 iter.retreat ();
99 // We should have iterated through the entire set.
100 ACE_TEST_ASSERT (iter.done () != 0);
102 // Iterate through the set and use the operator* to get the element
103 iter.first ();
105 for (i = -19; i <= 19; ++i)
107 // we should still be in the set
108 ACE_TEST_ASSERT (iter.done () == 0);
110 // make sure the current element is what we expect
111 int& l = *iter;
112 ACE_TEST_ASSERT (l == i);
114 // move to the next element in the set
115 iter.advance ();
118 // We should have iterated through the entire set.
119 ACE_TEST_ASSERT (iter.done () != 0);
121 // Clear the set, restart the iterator, and make sure the iterator
122 // is out of range at both ends, the set is empty, and a subsequent
123 // advance or retreat on an out of range iterator does not cause
124 // problems
125 set.reset ();
126 ACE_TEST_ASSERT (set.is_empty () != 0);
127 iter.first ();
128 ACE_TEST_ASSERT (iter.done () != 0);
129 iter.retreat ();
130 iter.last ();
131 ACE_TEST_ASSERT (iter.done () != 0);
132 iter.advance ();
134 // Put in a bunch of ints in various relative positions, using an
135 // iterator for the odds and no iterator for the evens.
136 set.insert (203, iter);
137 set.insert (202);
138 set.insert (204);
139 set.insert (201, iter);
140 set.insert (205, iter);
142 set.insert (203, iter);
143 set.insert (203, iter);
145 set.insert (204);
146 set.insert (204);
147 set.insert (204);
148 set.insert (205, iter);
149 set.insert (205, iter);
150 set.insert (205, iter);
151 set.insert (205, iter);
152 set.insert (202);
154 // remove the middle elements
155 while (set.remove (204) == 0)
157 // No action.
160 while (set.remove (202) == 0)
162 // No action.
165 while (set.remove (203) == 0)
167 // No action.
170 // Put the iterator out of range and make sure it stays
171 // that way for finds on the missing elements.
172 iter.last ();
173 iter.advance ();
174 set.find (203, iter);
175 ACE_TEST_ASSERT (iter.done () != 0);
176 set.find (202, iter);
177 ACE_TEST_ASSERT (iter.done () != 0);
178 set.find (204, iter);
179 ACE_TEST_ASSERT (iter.done () != 0);
181 // Make sure the other elements can be found.
182 set.find (205, iter);
183 ACE_TEST_ASSERT (iter.done () == 0);
184 iter.next (ptr);
185 ACE_TEST_ASSERT (ptr != 0);
186 ACE_TEST_ASSERT (*ptr == 205);
187 set.find (201, iter);
188 ACE_TEST_ASSERT (iter.done () == 0);
189 iter.next (ptr);
190 ACE_TEST_ASSERT (ptr != 0);
191 ACE_TEST_ASSERT (*ptr == 201);
193 // Finally, iterate through the set and make sure its contents are
194 // correct (one 201 and five 205s).
195 iter.first ();
196 ACE_TEST_ASSERT (iter.done () == 0);
197 iter.next (ptr);
198 ACE_TEST_ASSERT (ptr != 0);
199 ACE_TEST_ASSERT (*ptr == 201);
200 iter.advance ();
202 for (i = 1; i <= 5; ++i)
204 // Should be in the set, able to access the element, value
205 // should be 205
206 ACE_TEST_ASSERT (iter.done () == 0);
207 iter.next (ptr);
208 ACE_TEST_ASSERT (ptr != 0);
209 ACE_TEST_ASSERT (*ptr == 205);
211 // Move to the next element in the set.
212 iter.advance ();
215 // Should not be anything else in the set.
216 ACE_TEST_ASSERT (iter.done () != 0);
218 // remove the rest
219 while (set.remove (205) == 0)
221 // No action.
224 while (set.remove (201) == 0)
226 // No action.
229 // Should have no more elements in the set.
230 ACE_TEST_ASSERT (set.is_empty () != 0);
231 ACE_TEST_ASSERT (set.size () == 0);
232 iter.first ();
233 ACE_TEST_ASSERT (iter.done () != 0);
234 iter.last ();
235 ACE_TEST_ASSERT (iter.done () != 0);
237 ACE_END_TEST;
239 return ret;