Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / DLL_Test_Impl.cpp
blob3a6ae2e428da06ea9bdddf2c9e4a2b339fec8f34
2 //=============================================================================
3 /**
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>
9 */
10 //=============================================================================
12 #include "DLL_Test_Impl.h"
13 #include "ace/ACE.h"
14 #include "ace/OS_Errno.h"
15 #include "ace/svc_export.h"
16 #include "ace/OS_NS_string.h"
17 #include <utility>
18 #include <memory>
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"));
30 void
31 Hello_Impl::say_next ()
33 ACE_DEBUG ((LM_DEBUG,
34 ACE_TEXT ("How are you?\n")));
37 ACE_TCHAR *
38 Hello_Impl::new_info ()
40 return ACE::strnew (ACE_TEXT ("Hello_Impl::new_info() allocated by ACE::strnew()"));
43 ACE_TCHAR *
44 Hello_Impl::malloc_info ()
46 return ACE_OS::strdup (ACE_TEXT ("Hello_Impl::new_info() allocated by ACE_OS::malloc()"));
49 void *
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.
57 void *
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];
64 void
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);
71 void
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 *
79 get_hello ()
81 Hello *hello {};
83 ACE_NEW_RETURN (hello,
84 Hello_Impl,
85 nullptr);
87 return hello;
90 class Static_Constructor_Test
92 public:
93 Static_Constructor_Test ()
95 ACE_DEBUG ((LM_DEBUG,
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 // --------------------------------------------------------
109 Child::Child ()
113 Child::~Child ()
117 void
118 Child::test ()
120 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("child test called\n")));
122 Data d;
123 Data f(d);
124 Data g;
125 g = d;
126 g = std::move(d);
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();
136 catch (const Base&)
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();
158 catch (const Base&)
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 // --------------------------------------------------------
179 // Test dynamic cast
180 extern "C" ACE_Svc_Export int
181 dynamic_cast_test (Parent *target)
183 Child *c {};
184 c = dynamic_cast<Child*> (target);
185 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("dynamic_cast_test: parent %@; child %@\n"),
186 target, c));
187 return target == c ? 0 : -1;