2 //=============================================================================
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
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"
25 run_main (int, ACE_TCHAR
*[])
30 ACE_START_TEST (ACE_TEXT ("OrdMultiSet_Test"));
32 // make an empty set of int and an iterator
33 ACE_Ordered_MultiSet
<int> set
;
34 ACE_Ordered_MultiSet_Iterator
<int> iter(set
);
36 // Put in a range of odd ints, without an iterator.
38 for (i
= -10; i
< 10; ++i
)
39 set
.insert (2 * i
+ 1);
41 // Put in an interleaved range of even ints, using an iterator.
42 for (i
= -10; i
<= 10; ++i
)
43 set
.insert (2 * i
, iter
);
45 // Remove the first and last elements of range.
46 while (set
.remove (-20) == 0)
51 while (set
.remove (20) == 0)
56 // Should still have 39 elements in the set.
57 ACE_TEST_ASSERT (set
.is_empty () == 0);
58 ACE_TEST_ASSERT (set
.size () == 39);
60 // Iterate forward through the range we created: should be one of
64 for (i
= -19; i
<= 19; ++i
)
66 // we should still be in the set
67 ACE_TEST_ASSERT (iter
.done () == 0);
69 // make sure the current element is what we expect
71 ACE_TEST_ASSERT (ptr
!= 0);
72 ACE_TEST_ASSERT (*ptr
== i
);
74 // move to the next element in the set
78 // We should have iterated through the entire set.
79 ACE_TEST_ASSERT (iter
.done () != 0);
81 // Iterate backward through the range we created: should be one of
85 for (i
= 19; i
>= -19; --i
)
87 // We should still be in the set.
88 ACE_TEST_ASSERT (iter
.done () == 0);
90 // Make sure the current element is what we expect.
93 ACE_TEST_ASSERT (ptr
!= 0);
94 ACE_TEST_ASSERT (*ptr
== i
);
96 // Move to the previous element in the set.
100 // We should have iterated through the entire set.
101 ACE_TEST_ASSERT (iter
.done () != 0);
103 // Iterate through the set and use the operator* to get the element
106 for (i
= -19; i
<= 19; ++i
)
108 // we should still be in the set
109 ACE_TEST_ASSERT (iter
.done () == 0);
111 // make sure the current element is what we expect
113 ACE_TEST_ASSERT (l
== i
);
115 // move to the next element in the set
119 // We should have iterated through the entire set.
120 ACE_TEST_ASSERT (iter
.done () != 0);
122 // Clear the set, restart the iterator, and make sure the iterator
123 // is out of range at both ends, the set is empty, and a subsequent
124 // advance or retreat on an out of range iterator does not cause
127 ACE_TEST_ASSERT (set
.is_empty () != 0);
129 ACE_TEST_ASSERT (iter
.done () != 0);
132 ACE_TEST_ASSERT (iter
.done () != 0);
135 // Put in a bunch of ints in various relative positions, using an
136 // iterator for the odds and no iterator for the evens.
137 set
.insert (203, iter
);
140 set
.insert (201, iter
);
141 set
.insert (205, iter
);
143 set
.insert (203, iter
);
144 set
.insert (203, iter
);
149 set
.insert (205, iter
);
150 set
.insert (205, iter
);
151 set
.insert (205, iter
);
152 set
.insert (205, iter
);
155 // remove the middle elements
156 while (set
.remove (204) == 0)
161 while (set
.remove (202) == 0)
166 while (set
.remove (203) == 0)
171 // Put the iterator out of range and make sure it stays
172 // that way for finds on the missing elements.
175 set
.find (203, iter
);
176 ACE_TEST_ASSERT (iter
.done () != 0);
177 set
.find (202, iter
);
178 ACE_TEST_ASSERT (iter
.done () != 0);
179 set
.find (204, iter
);
180 ACE_TEST_ASSERT (iter
.done () != 0);
182 // Make sure the other elements can be found.
183 set
.find (205, iter
);
184 ACE_TEST_ASSERT (iter
.done () == 0);
186 ACE_TEST_ASSERT (ptr
!= 0);
187 ACE_TEST_ASSERT (*ptr
== 205);
188 set
.find (201, iter
);
189 ACE_TEST_ASSERT (iter
.done () == 0);
191 ACE_TEST_ASSERT (ptr
!= 0);
192 ACE_TEST_ASSERT (*ptr
== 201);
194 // Finally, iterate through the set and make sure its contents are
195 // correct (one 201 and five 205s).
197 ACE_TEST_ASSERT (iter
.done () == 0);
199 ACE_TEST_ASSERT (ptr
!= 0);
200 ACE_TEST_ASSERT (*ptr
== 201);
203 for (i
= 1; i
<= 5; ++i
)
205 // Should be in the set, able to access the element, value
207 ACE_TEST_ASSERT (iter
.done () == 0);
209 ACE_TEST_ASSERT (ptr
!= 0);
210 ACE_TEST_ASSERT (*ptr
== 205);
212 // Move to the next element in the set.
216 // Should not be anything else in the set.
217 ACE_TEST_ASSERT (iter
.done () != 0);
220 while (set
.remove (205) == 0)
225 while (set
.remove (201) == 0)
230 // Should have no more elements in the set.
231 ACE_TEST_ASSERT (set
.is_empty () != 0);
232 ACE_TEST_ASSERT (set
.size () == 0);
234 ACE_TEST_ASSERT (iter
.done () != 0);
236 ACE_TEST_ASSERT (iter
.done () != 0);