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"
24 void *operator new (size_t n
);
26 void *operator new (size_t n
, const std::nothrow_t
&) throw();
27 void operator delete (void *p
, const std::nothrow_t
&) throw ();
28 void * operator new (size_t n
, void *p
);
30 void operator delete (void *);
32 void operator delete (void *, void *);
34 /// Have we been dynamically created?
39 A::operator new (size_t n
)
41 ACE_Dynamic
*const dynamic_instance
= ACE_Dynamic::instance ();
43 if (dynamic_instance
== 0)
45 // If this ACE_TEST_ASSERT fails, it may be due to running of out TSS
46 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing
47 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
48 ACE_TEST_ASSERT (dynamic_instance
!= 0);
54 // Allocate the memory and store it (usually in thread-specific
55 // storage, depending on config flags).
56 dynamic_instance
->set ();
63 A::operator new (size_t n
, const std::nothrow_t
&) throw()
65 ACE_Dynamic
*const dynamic_instance
= ACE_Dynamic::instance ();
67 if (dynamic_instance
== 0)
69 // If this ACE_TEST_ASSERT fails, it may be due to running of out TSS
70 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing
71 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
72 ACE_TEST_ASSERT (dynamic_instance
!= 0);
78 // Allocate the memory and store it (usually in thread-specific
79 // storage, depending on config flags).
80 dynamic_instance
->set ();
82 return ::new(std::nothrow
) char[n
];
87 A::operator delete (void *p
, const std::nothrow_t
&) throw()
89 ::delete [] static_cast <char *> (p
);
93 A::operator delete (void *obj
)
95 ::delete [] static_cast <char *> (obj
);
100 this->dynamic_
= ACE_Dynamic::instance ()->is_dynamic ();
103 // Make sure to reset the flag.
104 ACE_Dynamic::instance ()->reset ();
108 run_main (int, ACE_TCHAR
*[])
110 ACE_START_TEST (ACE_TEXT ("Dynamic_Test"));
113 ACE_NEW_RETURN (heap
, A
, 1);
114 if (from_stack
.dynamic_
)
116 ACE_ERROR_RETURN ((LM_ERROR
,
117 ACE_TEXT ("dynamic_ is true for an object on the stack\n")),
123 ACE_ERROR_RETURN ((LM_ERROR
,
124 ACE_TEXT ("dynamic_ is false for an object from the heap\n")),