2 //=============================================================================
4 * @file Collection_Test.cpp
6 * This is a simple test of the ACE collection classes and its
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
)
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 ())
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_
));
62 int operator() () { return 0; }
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 ();
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 ())
98 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%x,%x\n"),
99 data
->alloc_
, (void *) data
->dfunc_
));
103 iterate_const (unbounded_set
);
105 unbounded_set
.reset ();
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_
));
117 iterate_const (unbounded_set
);
136 ARRAY
array3 (array2
);
141 ACE_TEST_ASSERT (array1
== array2
);
142 ACE_TEST_ASSERT (array1
== array3
);
143 ACE_TEST_ASSERT (array1
== array4
);
150 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d\n"),
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"),
164 ACE_TEST_ASSERT (*data
== 4);