1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
// $Id$
// ============================================================================
//
// = LIBRARY
// tests
//
// = FILENAME
// Collection_Test.cpp
//
// = DESCRIPTION
// This is a simple test of the ACE collection classes and its
// iterators.
//
// = AUTHOR
// Irfan Pyarali <irfan@cs.wustl.edu>
//
// ============================================================================
#include "test_config.h"
ACE_RCSID(tests, Collection_Test, "$Id$")
#include "ace/Containers.h"
typedef void (*deletion_func)(void* p);
struct UglyThing
{
void *alloc_;
deletion_func dfunc_;
UglyThing (void* alloc = 0, deletion_func dfunc = 0);
int operator== (const UglyThing& r) const;
};
UglyThing::UglyThing (void* alloc, deletion_func dfunc)
: alloc_ (alloc)
, dfunc_ (dfunc)
{
}
int
UglyThing::operator== (const UglyThing& r) const
{
return this->alloc_ == r.alloc_;
}
typedef UglyThing DATA;
typedef ACE_Unbounded_Set<DATA> UNBOUNDED_SET;
typedef ACE_Unbounded_Set_Iterator<DATA> UNBOUNDED_SET_ITERATOR;
typedef ACE_Unbounded_Set_Const_Iterator<DATA> UNBOUNDED_SET_CONST_ITERATOR;
typedef int ARRAY_DATA;
typedef ACE_Array<ARRAY_DATA> ARRAY;
typedef ACE_Array_Iterator<ARRAY_DATA> ARRAY_ITERATOR;
void iterate_const(const UNBOUNDED_SET& set)
{
{
UNBOUNDED_SET_CONST_ITERATOR iterator (set);
while (!iterator.done ())
{
DATA *data = 0;
iterator.next (data);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
data->alloc_, data->dfunc_));
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
(*data)));
DATA data_second = *iterator;
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
(data_second)));
iterator.advance ();
}
}
}
int dummyfunc() { return 0; }
int main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Collection_Test"));
deletion_func NO_DFUNC = (deletion_func)0;
{
UNBOUNDED_SET unbounded_set;
unbounded_set.insert (UglyThing ((void*)&unbounded_set, NO_DFUNC));
unbounded_set.insert (UglyThing ((void*)&dummyfunc, NO_DFUNC));
{
for (UNBOUNDED_SET::iterator iterator = unbounded_set.begin ();
iterator != unbounded_set.end ();
++iterator)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
(*iterator).alloc_, (*iterator).dfunc_));
}
}
unbounded_set.insert (UglyThing (0, NO_DFUNC));
unbounded_set.remove (UglyThing ((void*)&dummyfunc, NO_DFUNC));
{
UNBOUNDED_SET_ITERATOR iterator (unbounded_set);
while (!iterator.done ())
{
DATA *data = 0;
iterator.next (data);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
data->alloc_, data->dfunc_));
iterator.advance ();
}
}
iterate_const (unbounded_set);
unbounded_set.reset ();
{
DATA *data;
UNBOUNDED_SET_ITERATOR i (unbounded_set);
while (i.next (data) != 0)
{
ACE_DEBUG ((LM_DEBUG, "%x,%x\n", data->alloc_, data->dfunc_));
i.advance ();
}
}
iterate_const (unbounded_set);
}
{
ARRAY array;
}
{
ARRAY array (0);
}
{
ARRAY array1;
array1.size (2);
array1[0] = 4;
array1[1] = 4;
ARRAY array2 (2, 4);
ARRAY array3 (array2);
ARRAY array4;
array4 = array2;
ACE_ASSERT (array1 == array2);
ACE_ASSERT (array1 == array3);
ACE_ASSERT (array1 == array4);
{
for (size_t i = 0;
i != array1.size ();
++i)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
array1[i]));
ACE_ASSERT (array1[i] == 4);
}
}
{
ARRAY_ITERATOR iterator (array1);
while (!iterator.done ())
{
ARRAY_DATA *data = 0;
iterator.next (data);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
(*data)));
ACE_ASSERT (*data == 4);
iterator.advance ();
}
}
}
ACE_END_TEST;
return 0;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Unbounded_Set<DATA>;
template class ACE_Unbounded_Set_Iterator<DATA>;
template class ACE_Unbounded_Set_Const_Iterator<DATA>;
template class ACE_Node<DATA>;
#if (ACE_SIZEOF_INT != 4)
// These might be already instantiated in ace/stats.cpp
// (if ACE_INT32 == int)
ptemplate class ACE_Node<DATA>;
#endif /* ACE_SIZEOF_INT != 4 */
template class ACE_Array<ARRAY_DATA>;
template class ACE_Array_Base<ARRAY_DATA>;
template class ACE_Array_Iterator<ARRAY_DATA>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Unbounded_Set<DATA>
#pragma instantiate ACE_Unbounded_Set_Iterator<DATA>
#pragma instantiate ACE_Unbounded_Set_Const_Iterator<DATA>
#pragma instantiate ACE_Node<DATA>
#pragma instantiate ACE_Array<ARRAY_DATA>
#pragma instantiate ACE_Array_Base<ARRAY_DATA>
#pragma instantiate ACE_Array_Iterator<ARRAY_DATA>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|