Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / Collection_Test.cpp
blob5b92fbc35b4f979771970da2822ed8ec89397b9f
2 //=============================================================================
3 /**
4 * @file Collection_Test.cpp
6 * This is a simple test of the ACE collection classes and its
7 * iterators.
9 * @author Irfan Pyarali <irfan@cs.wustl.edu>
11 //=============================================================================
13 #include "test_config.h"
15 #include "ace/Containers.h"
16 #include "Collection_Test.h"
18 UglyThing::UglyThing (void* alloc, deletion_func dfunc)
19 : alloc_ (alloc)
20 , dfunc_ (dfunc)
24 bool
25 UglyThing::operator== (const UglyThing& r) const
27 return this->alloc_ == r.alloc_;
30 using DATA = UglyThing;
31 using UNBOUNDED_SET = ACE_Unbounded_Set<DATA>;
32 using UNBOUNDED_SET_ITERATOR = ACE_Unbounded_Set_Iterator<DATA>;
33 using UNBOUNDED_SET_CONST_ITERATOR = ACE_Unbounded_Set_Const_Iterator<DATA>;
35 using ARRAY_DATA = int;
36 using ARRAY = ACE_Array<ARRAY_DATA>;
37 using ARRAY_ITERATOR = ACE_Array_Iterator<ARRAY_DATA>;
39 void iterate_const(const UNBOUNDED_SET& set)
42 UNBOUNDED_SET_CONST_ITERATOR iterator (set);
43 while (!iterator.done ())
45 DATA *data = 0;
46 iterator.next (data);
48 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
49 data->alloc_, (void *) data->dfunc_));
51 DATA data_second = *iterator;
52 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
53 data_second.alloc_, (void *) data_second.dfunc_));
55 iterator.advance ();
60 struct DummyFunctor
62 int operator() () { return 0; }
65 int
66 run_main (int, ACE_TCHAR *[])
68 ACE_START_TEST (ACE_TEXT ("Collection_Test"));
70 deletion_func NO_DFUNC = (deletion_func)0;
71 DummyFunctor dummyfunc;
74 UNBOUNDED_SET unbounded_set;
76 unbounded_set.insert (UglyThing ((void*)&unbounded_set, NO_DFUNC));
77 unbounded_set.insert (UglyThing ((void*)&dummyfunc, NO_DFUNC));
80 for (UNBOUNDED_SET::iterator iterator = unbounded_set.begin ();
81 iterator != unbounded_set.end ();
82 ++iterator)
84 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
85 (*iterator).alloc_, (void *) (*iterator).dfunc_));
89 unbounded_set.insert (UglyThing (0, NO_DFUNC));
90 unbounded_set.remove (UglyThing ((void*)&dummyfunc, NO_DFUNC));
93 UNBOUNDED_SET_ITERATOR iterator (unbounded_set);
94 while (!iterator.done ())
96 DATA *data = 0;
97 iterator.next (data);
98 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
99 data->alloc_, (void *) data->dfunc_));
100 iterator.advance ();
103 iterate_const (unbounded_set);
105 unbounded_set.reset ();
108 DATA *data;
109 UNBOUNDED_SET_ITERATOR i (unbounded_set);
111 while (i.next (data) != 0)
113 ACE_DEBUG ((LM_DEBUG, "%x,%x\n", data->alloc_, (void *) data->dfunc_));
114 i.advance ();
117 iterate_const (unbounded_set);
121 ARRAY array;
125 ARRAY array (0);
129 ARRAY array1;
130 array1.size (2);
131 array1[0] = 4;
132 array1[1] = 4;
134 ARRAY array2 (2, 4);
136 ARRAY array3 (array2);
138 ARRAY array4;
139 array4 = array2;
141 ACE_TEST_ASSERT (array1 == array2);
142 ACE_TEST_ASSERT (array1 == array3);
143 ACE_TEST_ASSERT (array1 == array4);
146 for (size_t i = 0;
147 i != array1.size ();
148 ++i)
150 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
151 array1[i]));
152 ACE_TEST_ASSERT (array1[i] == 4);
157 ARRAY_ITERATOR iterator (array1);
158 while (!iterator.done ())
160 ARRAY_DATA *data = 0;
161 iterator.next (data);
162 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
163 (*data)));
164 ACE_TEST_ASSERT (*data == 4);
165 iterator.advance ();
171 ACE_END_TEST;
173 return 0;