2 //=============================================================================
4 * @file Dynamic_Test.cpp
6 * This tests the ACE_Dynamic class
8 * @author Johnny Willemsen <jwillemsen@remedy.nl>
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/OS_NS_string.h"
15 #include "ace/Dynamic.h"
16 #include "ace/OS_Memory.h"
25 void *operator new (size_t n
);
27 void *operator new (size_t n
, const std::nothrow_t
&) throw();
28 void operator delete (void *p
, const std::nothrow_t
&) throw ();
29 void * operator new (size_t n
, void *p
);
31 void operator delete (void *);
33 void operator delete (void *, void *);
35 /// Have we been dynamically created?
40 A::operator new (size_t n
)
42 ACE_Dynamic
*const dynamic_instance
= ACE_Dynamic::instance ();
44 if (dynamic_instance
== 0)
46 // If this ACE_TEST_ASSERT fails, it may be due to running of out TSS
47 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing
48 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
49 ACE_TEST_ASSERT (dynamic_instance
!= 0);
55 // Allocate the memory and store it (usually in thread-specific
56 // storage, depending on config flags).
57 dynamic_instance
->set ();
64 A::operator new (size_t n
, const std::nothrow_t
&) throw()
66 ACE_Dynamic
*const dynamic_instance
= ACE_Dynamic::instance ();
68 if (dynamic_instance
== 0)
70 // If this ACE_TEST_ASSERT fails, it may be due to running of out TSS
71 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing
72 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
73 ACE_TEST_ASSERT (dynamic_instance
!= 0);
79 // Allocate the memory and store it (usually in thread-specific
80 // storage, depending on config flags).
81 dynamic_instance
->set ();
83 return ::new(std::nothrow
) char[n
];
88 A::operator delete (void *p
, const std::nothrow_t
&) throw()
90 ::delete [] static_cast <char *> (p
);
94 A::operator delete (void *obj
)
96 ::delete [] static_cast <char *> (obj
);
101 this->dynamic_
= ACE_Dynamic::instance ()->is_dynamic ();
104 // Make sure to reset the flag.
105 ACE_Dynamic::instance ()->reset ();
109 run_main (int, ACE_TCHAR
*[])
111 ACE_START_TEST (ACE_TEXT ("Dynamic_Test"));
114 ACE_NEW_RETURN (heap
, A
, 1);
115 if (from_stack
.dynamic_
)
117 ACE_ERROR_RETURN ((LM_ERROR
,
118 ACE_TEXT ("dynamic_ is true for an object on the stack\n")),
124 ACE_ERROR_RETURN ((LM_ERROR
,
125 ACE_TEXT ("dynamic_ is false for an object from the heap\n")),