2 //=============================================================================
4 * @file DLL_Test_Impl.cpp
6 * This test illustrates the use of <ACE_DLL> wrapper class.
8 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
10 //=============================================================================
12 #include "DLL_Test_Impl.h"
14 #include "ace/OS_Errno.h"
15 #include "ace/svc_export.h"
16 #include "ace/OS_NS_string.h"
20 Hello_Impl::Hello_Impl ()
22 ACE_DEBUG ((LM_DEBUG
, "Hello_Impl::Hello_Impl\n"));
25 Hello_Impl::~Hello_Impl ()
27 ACE_DEBUG ((LM_DEBUG
, "Hello_Impl::~Hello_Impl\n"));
31 Hello_Impl::say_next ()
34 ACE_TEXT ("How are you?\n")));
38 Hello_Impl::new_info ()
40 return ACE::strnew (ACE_TEXT ("Hello_Impl::new_info() allocated by ACE::strnew()"));
44 Hello_Impl::malloc_info ()
46 return ACE_OS::strdup (ACE_TEXT ("Hello_Impl::new_info() allocated by ACE_OS::malloc()"));
50 Hello_Impl::operator new (size_t bytes
)
52 ACE_DEBUG ((LM_INFO
, "Hello_Impl::new\n"));
53 return ::new char[bytes
];
56 /// Overloaded new operator, nothrow_t variant.
58 Hello_Impl::operator new (size_t bytes
, const std::nothrow_t
&nt
)
60 ACE_DEBUG ((LM_INFO
, "Hello_Impl::new\n"));
61 return ::new (nt
) char[bytes
];
65 Hello_Impl::operator delete (void *ptr
, const std::nothrow_t
&) noexcept
67 ACE_DEBUG ((LM_INFO
, "Hello_Impl::delete\n"));
68 ::delete [] static_cast<char *> (ptr
);
72 Hello_Impl::operator delete (void *ptr
)
74 ACE_DEBUG ((LM_INFO
, "Hello_Impl::delete\n"));
75 ::delete [] static_cast<char *> (ptr
);
78 extern "C" ACE_Svc_Export Hello
*
83 ACE_NEW_RETURN (hello
,
90 class Static_Constructor_Test
93 Static_Constructor_Test ()
96 "Static_Constructor_Test::Static_Constructor_Test\n"));
98 ~Static_Constructor_Test ()
100 ACE_DEBUG ((LM_DEBUG
,
101 "Static_Constructor_Test::~Static_Constructor_Test\n"));
105 static Static_Constructor_Test the_instance
;
107 // --------------------------------------------------------
120 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("child test called\n")));
128 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("testing base exception\n")));
130 std::unique_ptr
<Base
> base_excep (new Base ());
133 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("throwing base exception\n")));
134 base_excep
->_raise();
138 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("caught base\n")));
141 std::unique_ptr
<Derived
> derived_excep (new Derived ());
144 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("throwing derived exception\n")));
145 derived_excep
->_raise();
147 catch (const Derived
&)
149 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("caught derived\n")));
152 std::unique_ptr
<Derived
> derived_excep_base (new Derived ());
155 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("throwing derived exception\n")));
156 derived_excep_base
->_raise();
160 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("caught derived as base\n")));
163 std::unique_ptr
<Base
> derived_excep_alloc (Derived::_alloc ());
166 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("throwing derived exception allocated with _alloc\n")));
167 derived_excep_base
->_raise();
169 catch (const Derived
&)
171 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("caught derived exception\n")));
174 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("testing exceptions finished\n")));
177 // --------------------------------------------------------
180 extern "C" ACE_Svc_Export
int
181 dynamic_cast_test (Parent
*target
)
184 c
= dynamic_cast<Child
*> (target
);
185 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("dynamic_cast_test: parent %@; child %@\n"),
187 return target
== c
? 0 : -1;