Doxygen changes
[ACE_TAO.git] / ACE / tests / Obstack_Test.cpp
blob65c5e8cc4d22e326b0ae536fa965bcafff0dad89
1 //=============================================================================
2 /**
3 * @file Obstack_Test.cpp
5 * Checks the functionality of ACE_Obstack<T>
7 * @author Steve Huston <shuston@riverace.com>
8 */
9 //=============================================================================
11 #include "test_config.h"
12 #include "ace/OS_NS_string.h"
13 #include "ace/Obstack.h"
14 #include "ace/Log_Msg.h"
16 int run_main (int, ACE_TCHAR *[])
18 ACE_START_TEST (ACE_TEXT ("Obstack_Test"));
20 int errors = 0;
21 // For this test, the length of the ACE_Obstack must be larger than
22 // both of these strings, but less than their sum.
23 const ACE_TCHAR str1[] = ACE_TEXT ("Mary had a little lamb.");
24 const ACE_TCHAR str2[] = ACE_TEXT ("It's fleece was white as snow; but....");
25 ACE_Obstack_T<ACE_TCHAR> stack (sizeof (str1) + 1);
27 for (size_t i = 0; i < ACE_OS::strlen (str1); i++)
28 stack.grow_fast (str1[i]);
30 ACE_TCHAR *str = stack.freeze ();
32 if (str == 0)
34 ACE_ERROR ((LM_ERROR, ACE_TEXT ("freeze failed!\n")));
35 ++errors;
37 else if (ACE_OS::strcmp (str, str1) != 0)
39 ACE_ERROR ((LM_ERROR,
40 ACE_TEXT("Lost first string; expected: %s, have: %s\n"),
41 str1, str));
42 ++errors;
45 for (size_t j = 0; j < ACE_OS::strlen (str2); ++j)
46 stack.grow (str2[j]);
48 ACE_TCHAR* temp = stack.freeze();
50 if (temp == 0)
52 ACE_ERROR ((LM_ERROR, ACE_TEXT ("freeze failed!\n")));
53 ++errors;
55 else if (ACE_OS::strcmp (temp, str2) != 0)
57 ACE_ERROR ((LM_ERROR,
58 ACE_TEXT("Lost second string; expected: %s, have: %s\n"),
59 str2, temp));
60 ++errors;
63 for (size_t k = 0; k < ACE_OS::strlen (str1); ++k)
64 stack.grow (str1[k]);
66 ACE_TCHAR* tmp = stack.freeze ();
67 if (tmp == 0)
69 ACE_ERROR ((LM_ERROR, ACE_TEXT ("freeze failed!\n")));
70 ++errors;
72 else if (ACE_OS::strcmp (tmp, str1) != 0)
74 ACE_ERROR ((LM_ERROR,
75 ACE_TEXT ("Lost third string; expected: %s, have: %s\n"),
76 str1, tmp));
77 ++errors;
80 stack.unwind (temp);
82 for (size_t l = 0; l < ACE_OS::strlen (str2); ++l)
83 stack.grow (str2[l]);
85 temp = stack.freeze();
87 if (temp == 0)
89 ACE_ERROR ((LM_ERROR, ACE_TEXT ("freeze failed!\n")));
90 ++errors;
92 else if (ACE_OS::strcmp (temp, str2) != 0)
94 ACE_ERROR ((LM_ERROR,
95 ACE_TEXT ("Lost fourth string; expected: %s, have: %s\n"),
96 str2, temp));
97 ++errors;
100 if (!errors)
101 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Test ok\n")));
103 ACE_END_TEST;
104 return errors == 0 ? 0 : 1;