Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / tests / Hash_Multi_Map_Manager_Test.cpp
blob3c687bc65b08d7de73c18b26491dc872c32c6335
2 //=============================================================================
3 /**
4 * @file Hash_Multi_Map_Manager_Test.cpp
6 * This test illustrates the use of <ACE_Hash_Multi_Map_Manager> to
7 * maintain a hash table using strings.
9 * @author Shanshan Jiang <shanshan.jiang@vanderbilt.edu>
11 //=============================================================================
14 #include "test_config.h"
15 #include "ace/Hash_Multi_Map_Manager_T.h"
16 #include "ace/Null_Mutex.h"
19 using HASH_STRING_MAP = ACE_Hash_Multi_Map_Manager<const ACE_TCHAR *, const ACE_TCHAR *, ACE_Hash<const ACE_TCHAR *>, ACE_Equal_To<const ACE_TCHAR *>, ACE_Null_Mutex>;
21 using HASH_STRING_ENTRY = HASH_STRING_MAP::ENTRY;
22 using HASH_STRING_VALUE_SET = HASH_STRING_ENTRY::VALUE_SET;
23 using HASH_STRING_VALUE_SET_ITERATOR = HASH_STRING_ENTRY::VALUE_SET_ITERATOR;
24 using HASH_STRING_ITERATOR = HASH_STRING_MAP::ITERATOR;
25 using HASH_STRING_CONST_ITERATOR = HASH_STRING_MAP::CONST_ITERATOR;
26 using HASH_STRING_REVERSE_ITERATOR = HASH_STRING_MAP::REVERSE_ITERATOR;
28 static const ACE_TCHAR *color_sorts[] = {ACE_TEXT ("warm"), ACE_TEXT ("cold"), ACE_TEXT ("neutral"), 0};
29 static const ACE_TCHAR *warm_colors[] = {ACE_TEXT ("red"), ACE_TEXT ("yellow"), ACE_TEXT ("orange"), 0};
30 static const ACE_TCHAR *cold_colors[] = {ACE_TEXT ("blue"), ACE_TEXT ("cyan"), 0};
31 static const ACE_TCHAR *neutral_colors[] = {ACE_TEXT ("green"), ACE_TEXT ("purple"), 0};
33 static int
34 run_test ()
36 HASH_STRING_MAP colors;
38 size_t i;
40 // Check the <bind> operation.
41 for (i = 0; warm_colors[i] != 0; i++)
43 if (colors.bind (color_sorts[0],
44 warm_colors[i]) == -1)
45 ACE_ERROR_RETURN ((LM_ERROR,
46 ACE_TEXT ("bind failed for %s in %s\n"),
47 warm_colors[i],
48 color_sorts[0]),
49 -1);
52 HASH_STRING_ENTRY *entry = 0;
53 for (i = 0; cold_colors[i] != 0; i++)
55 if (colors.bind (color_sorts[1],
56 cold_colors[i],
57 entry) == -1)
58 ACE_ERROR_RETURN ((LM_ERROR,
59 ACE_TEXT ("bind failed for %s in %s\n"),
60 cold_colors[i],
61 color_sorts[1]),
62 -1);
65 HASH_STRING_VALUE_SET value_set;
66 entry = 0;
67 for (i = 0; neutral_colors[i] != 0; i++)
68 value_set.insert (neutral_colors[i]);
69 if (colors.bind (color_sorts[2],
70 value_set,
71 entry) == -1)
72 ACE_ERROR_RETURN ((LM_ERROR,
73 ACE_TEXT ("bind failed for %s\n"),
74 color_sorts[2]),
75 -1);
77 // Check the <trybind> operation.
78 value_set.reset ();
79 if (colors.trybind (color_sorts[2],
80 value_set) == -1)
81 ACE_ERROR_RETURN ((LM_ERROR,
82 ACE_TEXT ("bind failed for %s\n"),
83 color_sorts[2]),
84 -1);
86 value_set.reset ();
87 entry = 0;
88 if (colors.trybind (color_sorts[2],
89 value_set,
90 entry) == -1)
91 ACE_ERROR_RETURN ((LM_ERROR,
92 ACE_TEXT ("bind failed for %s\n"),
93 color_sorts[2]),
94 -1);
96 value_set.reset ();
97 entry = 0;
98 if (colors.trybind (color_sorts[2],
99 value_set,
100 entry) == -1)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 ACE_TEXT ("bind failed for %s\n"),
103 color_sorts[2]),
104 -1);
106 // Check the <rebind> operation.
107 value_set.reset ();
108 value_set.insert (neutral_colors[0]);
109 if (colors.rebind (color_sorts[2],
110 value_set) == -1)
111 ACE_ERROR_RETURN ((LM_ERROR,
112 ACE_TEXT ("bind failed for %s\n"),
113 color_sorts[2]),
114 -1);
116 value_set.reset ();
117 value_set.insert (neutral_colors[1]);
118 entry = 0;
119 if (colors.rebind (color_sorts[2],
120 value_set,
121 entry) == -1)
122 ACE_ERROR_RETURN ((LM_ERROR,
123 ACE_TEXT ("bind failed for %s\n"),
124 color_sorts[2]),
125 -1);
127 value_set.reset ();
128 value_set.insert (neutral_colors[0]);
129 HASH_STRING_VALUE_SET old_value_set;
130 if (colors.rebind (color_sorts[2],
131 value_set,
132 old_value_set) == -1)
133 ACE_ERROR_RETURN ((LM_ERROR,
134 ACE_TEXT ("bind failed for %s\n"),
135 color_sorts[2]),
136 -1);
138 value_set.reset ();
139 value_set.insert (neutral_colors[1]);
140 old_value_set.reset ();
141 entry = 0;
142 if (colors.rebind (color_sorts[2],
143 value_set,
144 old_value_set,
145 entry) == -1)
146 ACE_ERROR_RETURN ((LM_ERROR,
147 ACE_TEXT ("bind failed for %s\n"),
148 color_sorts[2]),
149 -1);
151 value_set.reset ();
152 value_set.insert (neutral_colors[0]);
153 const ACE_TCHAR *old_key;
154 old_value_set.reset ();
155 if (colors.rebind (color_sorts[2],
156 value_set,
157 old_key,
158 old_value_set) == -1)
159 ACE_ERROR_RETURN ((LM_ERROR,
160 ACE_TEXT ("bind failed for %s\n"),
161 color_sorts[2]),
162 -1);
164 value_set.reset ();
165 for (i = 0; neutral_colors[i] != 0; i++)
166 value_set.insert (neutral_colors[i]);
167 old_key = 0;
168 old_value_set.reset ();
169 entry = 0;
170 if (colors.rebind (color_sorts[2],
171 value_set,
172 old_key,
173 old_value_set,
174 entry) == -1)
175 ACE_ERROR_RETURN ((LM_ERROR,
176 ACE_TEXT ("bind failed for %s\n"),
177 color_sorts[2]),
178 -1);
180 // Check the <find> operation.
181 for (i = 0; color_sorts[i] != 0; i++)
182 if (colors.find (color_sorts[i]) == 0)
183 ACE_DEBUG ((LM_DEBUG,
184 ACE_TEXT ("%s found\n"),
185 color_sorts[i]));
186 else
187 ACE_ERROR_RETURN ((LM_ERROR,
188 ACE_TEXT ("%s not found\n"),
189 color_sorts[i]),
190 -1);
192 entry = 0;
193 for (i = 0; color_sorts[i] != 0; i++)
194 if (colors.find (color_sorts[i],
195 entry) == 0)
196 ACE_DEBUG ((LM_DEBUG,
197 ACE_TEXT ("%s found\n"),
198 color_sorts[i]));
199 else
200 ACE_ERROR_RETURN ((LM_ERROR,
201 ACE_TEXT ("%s not found\n"),
202 color_sorts[i]),
203 -1);
205 value_set.reset ();
206 for (i = 0; color_sorts[i] != 0; i++)
207 if (colors.find (color_sorts[i],
208 value_set) == 0)
209 ACE_DEBUG ((LM_DEBUG,
210 ACE_TEXT ("%s found\n"),
211 color_sorts[i]));
212 else
213 ACE_ERROR_RETURN ((LM_ERROR,
214 ACE_TEXT ("%s not found\n"),
215 color_sorts[i]),
216 -1);
218 for (i = 0; warm_colors[i] != 0; i++)
219 if (colors.find (color_sorts[0],
220 warm_colors[i]) == 0)
221 ACE_DEBUG ((LM_DEBUG,
222 ACE_TEXT ("%s color %s found\n"),
223 color_sorts[0],
224 warm_colors[i]));
225 else
226 ACE_ERROR_RETURN ((LM_ERROR,
227 ACE_TEXT ("%s color %s not found\n"),
228 color_sorts[0],
229 warm_colors[i]),
230 -1);
232 // Check the iterator.
233 i = 0;
234 entry = 0;
235 for (HASH_STRING_ITERATOR hash_iter (colors);
236 hash_iter.next (entry) != 0;
237 hash_iter.advance ())
239 ACE_DEBUG ((LM_DEBUG,
240 ACE_TEXT ("iterating (%d): %s:\n"),
242 entry->key ()));
243 i++;
245 for (HASH_STRING_VALUE_SET_ITERATOR iter (entry->item ());
246 iter != entry->item ().end ();
247 iter++)
249 ACE_DEBUG ((LM_DEBUG,
250 ACE_TEXT ("%s \n"),
251 *iter));
255 // Check the unbind operation.
256 if (colors.unbind (color_sorts[0]) == -1)
257 ACE_ERROR_RETURN ((LM_ERROR,
258 ACE_TEXT ("unbind failed for %s\n"),
259 color_sorts[1]),
260 -1);
261 for (i = 0; warm_colors[i] != 0; i++)
263 if (colors.bind (color_sorts[0],
264 warm_colors[i]) == -1)
265 ACE_ERROR_RETURN ((LM_ERROR,
266 ACE_TEXT ("bind failed for %s in %s\n"),
267 warm_colors[i],
268 color_sorts[0]),
269 -1);
272 value_set.reset ();
273 if (colors.unbind (color_sorts[0], value_set) == -1)
274 ACE_ERROR_RETURN ((LM_ERROR,
275 ACE_TEXT ("unbind failed for %s\n"),
276 color_sorts[1]),
277 -1);
278 for (i = 0; warm_colors[i] != 0; i++)
280 if (colors.bind (color_sorts[0],
281 warm_colors[i]) == -1)
282 ACE_ERROR_RETURN ((LM_ERROR,
283 ACE_TEXT ("bind failed for %s in %s\n"),
284 warm_colors[i],
285 color_sorts[0]),
286 -1);
289 for (i = 0; warm_colors[i] != 0; i++)
291 if (colors.unbind (color_sorts[0],
292 warm_colors[i]) == -1)
293 ACE_ERROR_RETURN ((LM_ERROR,
294 ACE_TEXT ("unbind failed for %s in %s\n"),
295 warm_colors[i],
296 color_sorts[0]),
297 -1);
300 // Check the reverse iterator.
301 i = 0;
302 entry = 0;
303 for (HASH_STRING_REVERSE_ITERATOR hash_iter (colors);
304 hash_iter.next (entry) != 0;
305 hash_iter.advance ())
307 ACE_DEBUG ((LM_DEBUG,
308 ACE_TEXT ("reverse iterating (%d): %s\n"),
310 entry->key ()));
311 i++;
313 for (HASH_STRING_VALUE_SET_ITERATOR iter (entry->item ());
314 iter != entry->item ().end ();
315 iter++)
317 ACE_DEBUG ((LM_DEBUG,
318 ACE_TEXT ("%s \n"),
319 *iter));
323 entry = 0;
324 colors.find (color_sorts[1], entry);
325 if (colors.unbind (entry) == -1)
326 ACE_ERROR_RETURN ((LM_ERROR,
327 ACE_TEXT ("unbind failed for %s\n"),
328 color_sorts[1]),
329 -1);
331 // Check the const iterator.
332 i = 0;
333 entry = 0;
334 for (HASH_STRING_CONST_ITERATOR hash_iter (colors);
335 hash_iter.next (entry) != 0;
336 hash_iter.advance ())
338 ACE_DEBUG ((LM_DEBUG,
339 ACE_TEXT ("const iterating (%d): %s\n"),
341 entry->key ()));
342 i++;
344 for (HASH_STRING_VALUE_SET_ITERATOR iter (entry->item ());
345 iter != entry->item ().end ();
346 iter++)
348 ACE_DEBUG ((LM_DEBUG,
349 ACE_TEXT ("%s \n"),
350 *iter));
354 // Check the unbind_all operation.
355 if (colors.unbind_all () != 0)
356 ACE_ERROR_RETURN ((LM_ERROR,
357 ACE_TEXT ("unbind_all failed\n")),
358 -1);
360 return 0;
364 run_main (int, ACE_TCHAR *[])
366 ACE_START_TEST (ACE_TEXT ("Hash_Multi_Map_Manager_Test"));
368 run_test ();
370 ACE_END_TEST;
372 return 0;