1 //=============================================================================
3 * @file Obstack_Test.cpp
5 * Checks the functionality of ACE_Obstack<T>
7 * @author Steve Huston <shuston@riverace.com>
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"));
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 ();
34 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("freeze failed!\n")));
37 else if (ACE_OS::strcmp (str
, str1
) != 0)
40 ACE_TEXT("Lost first string; expected: %s, have: %s\n"),
45 for (size_t j
= 0; j
< ACE_OS::strlen (str2
); ++j
)
48 ACE_TCHAR
* temp
= stack
.freeze();
52 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("freeze failed!\n")));
55 else if (ACE_OS::strcmp (temp
, str2
) != 0)
58 ACE_TEXT("Lost second string; expected: %s, have: %s\n"),
63 for (size_t k
= 0; k
< ACE_OS::strlen (str1
); ++k
)
66 ACE_TCHAR
* tmp
= stack
.freeze ();
69 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("freeze failed!\n")));
72 else if (ACE_OS::strcmp (tmp
, str1
) != 0)
75 ACE_TEXT ("Lost third string; expected: %s, have: %s\n"),
82 for (size_t l
= 0; l
< ACE_OS::strlen (str2
); ++l
)
85 temp
= stack
.freeze();
89 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("freeze failed!\n")));
92 else if (ACE_OS::strcmp (temp
, str2
) != 0)
95 ACE_TEXT ("Lost fourth string; expected: %s, have: %s\n"),
101 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Test ok\n")));
104 return errors
== 0 ? 0 : 1;