Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / DLList_Test.cpp
blob182664be03735557d3bf5aee79f6658e2312dabd
2 //=============================================================================
3 /**
4 * @file DLList_Test.cpp
6 * This test illustrates the use of <ACE_DLList>.
8 * @author James Hu <jxh@cs.wustl.edu> and Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Containers.h"
15 #include "ace/SString.h"
16 #include "ace/Malloc_T.h"
18 using ACE_STRING = ACE_TCHAR *;
19 using STRLIST = ACE_DLList<ACE_STRING>;
20 using STRLIST_ITERATOR = ACE_DLList_Iterator<ACE_STRING>;
21 using STRLIST_REVERSE_ITERATOR = ACE_DLList_Reverse_Iterator<ACE_STRING>;
23 static ACE_STRING string_table[] =
25 // Note: all these casts are to appease SC 5.0 which is not pleased
26 // with using string literals (i.e. const char *'s) as char
27 // *'s. It's ugly, but necessary.
28 const_cast<ACE_TCHAR *> (ACE_TEXT ("hello")),
29 const_cast<ACE_TCHAR *> (ACE_TEXT ("guten Tag")),
30 const_cast<ACE_TCHAR *> (ACE_TEXT ("goodbye")),
31 const_cast<ACE_TCHAR *> (ACE_TEXT ("auf wiedersehen")),
32 const_cast<ACE_TCHAR *> (ACE_TEXT ("funny")),
33 const_cast<ACE_TCHAR *> (ACE_TEXT ("lustig")),
37 static void
38 run_iterate (STRLIST &list)
40 ACE_STRING *entry;
41 size_t i = 0;
43 for (STRLIST_ITERATOR iter (list);
44 (entry = iter.next ()) != 0;
45 iter.advance (), i++)
47 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("iterating (%d): [%s]\n"),
49 (ACE_TCHAR *) *entry));
53 static void
54 run_reverse_iterate (STRLIST &list)
56 ACE_STRING *entry;
57 size_t i = 0;
59 for (STRLIST_REVERSE_ITERATOR iter (list);
60 iter.next (entry) != 0;
61 iter.advance (), i++)
63 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("iterating (%d): [%s]\n"),
65 (ACE_TCHAR *) *entry));
69 static int
70 run_test ()
72 STRLIST list;
74 size_t i;
76 for (i = 0; string_table[i] != 0; i++)
78 if (ACE_EVEN (i)
79 && list.insert_tail ((ACE_STRING *) &string_table[i]) == 0)
80 ACE_ERROR_RETURN ((LM_ERROR,
81 ACE_TEXT ("%p failed for %s\n"),
82 ACE_TEXT ("insert"),
83 string_table[i]),
84 -1);
85 else if (list.insert_head ((ACE_STRING *) &string_table[i]) == 0)
86 ACE_ERROR_RETURN ((LM_ERROR,
87 ACE_TEXT ("%p failed for %s\n"),
88 ACE_TEXT ("insert"),
89 string_table[i]),
90 -1);
91 run_iterate (list);
92 run_reverse_iterate (list);
95 run_iterate (list);
96 run_reverse_iterate (list);
98 list.delete_tail ();
99 list.delete_tail ();
101 run_iterate (list);
102 run_reverse_iterate (list);
104 list.delete_head ();
105 list.delete_head ();
107 run_iterate (list);
108 run_reverse_iterate (list);
110 return 0;
114 run_main (int, ACE_TCHAR *[])
116 ACE_START_TEST (ACE_TEXT ("DLList_Test"));
118 run_test ();
120 ACE_END_TEST;
122 return 0;