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 #if defined (ACE_HAS_NEW_NOTHROW)
28 void *operator new (size_t n
, const ACE_nothrow_t
&) throw();
29 #if !defined (ACE_LACKS_PLACEMENT_OPERATOR_DELETE)
30 void operator delete (void *p
, const ACE_nothrow_t
&) throw ();
31 #endif /* ACE_LACKS_PLACEMENT_OPERATOR_DELETE */
34 void * operator new (size_t n
, void *p
);
36 void operator delete (void *);
38 #if !defined (ACE_LACKS_PLACEMENT_OPERATOR_DELETE)
39 void operator delete (void *, void *);
40 #endif /* ACE_LACKS_PLACEMENT_OPERATOR_DELETE */
42 /// Have we been dynamically created?
47 A::operator new (size_t n
)
49 ACE_Dynamic
*const dynamic_instance
= ACE_Dynamic::instance ();
51 if (dynamic_instance
== 0)
53 // If this ACE_TEST_ASSERT fails, it may be due to running of out TSS
54 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing
55 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
56 ACE_TEST_ASSERT (dynamic_instance
!= 0);
62 // Allocate the memory and store it (usually in thread-specific
63 // storage, depending on config flags).
64 dynamic_instance
->set ();
70 #if defined (ACE_HAS_NEW_NOTHROW)
72 A::operator new (size_t n
, const ACE_nothrow_t
&) throw()
74 ACE_Dynamic
*const dynamic_instance
= ACE_Dynamic::instance ();
76 if (dynamic_instance
== 0)
78 // If this ACE_TEST_ASSERT fails, it may be due to running of out TSS
79 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing
80 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
81 ACE_TEST_ASSERT (dynamic_instance
!= 0);
87 // Allocate the memory and store it (usually in thread-specific
88 // storage, depending on config flags).
89 dynamic_instance
->set ();
91 return ::new(ACE_nothrow
) char[n
];
95 #if !defined (ACE_LACKS_PLACEMENT_OPERATOR_DELETE)
97 A::operator delete (void *p
, const ACE_nothrow_t
&) throw()
99 ::delete [] static_cast <char *> (p
);
101 #endif /* ACE_LACKS_PLACEMENT_OPERATOR_DELETE */
103 #endif /* ACE_HAS_NEW_NOTHROW */
106 A::operator delete (void *obj
)
108 ::delete [] static_cast <char *> (obj
);
113 this->dynamic_
= ACE_Dynamic::instance ()->is_dynamic ();
116 // Make sure to reset the flag.
117 ACE_Dynamic::instance ()->reset ();
121 run_main (int, ACE_TCHAR
*[])
123 ACE_START_TEST (ACE_TEXT ("Dynamic_Test"));
126 ACE_NEW_RETURN (heap
, A
, 1);
127 if (from_stack
.dynamic_
)
129 ACE_ERROR_RETURN ((LM_ERROR
,
130 ACE_TEXT ("dynamic_ is true for an object on the stack\n")),
136 ACE_ERROR_RETURN ((LM_ERROR
,
137 ACE_TEXT ("dynamic_ is false for an object from the heap\n")),