ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / Object_Manager_Test.cpp
blob27870763f34ef63ebd3e670f148a478bece59ae3
2 //=============================================================================
3 /**
4 * @file Object_Manager_Test.cpp
6 * Tests the basic functions of the ACE_Object_Manager.
8 * @author David L. Levine <levine@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Object_Manager.h"
15 #include "ace/OS_Memory.h"
16 #include "ace/Init_ACE.h"
20 static u_int *ip;
22 extern "C"
23 void
24 hook1 (void)
26 delete ip;
27 ip = 0;
30 extern "C"
31 void
32 hook2 (void * /* object */, void *param)
34 u_int *paramp = reinterpret_cast<u_int *> (param);
36 // We can use ACE_Log_Msg in an ACE_Object_Manager cleanup hook.
37 // But NOT in an ACE_OS::atexit () hook! However, the ACE_END_TEST
38 // invocation in main () will prevent this from being output to the
39 // log stream.
40 ACE_DEBUG ((LM_DEBUG,
41 ACE_TEXT ("hook2: %d\n"),
42 *paramp));
43 delete paramp;
46 int
47 run_main (int, ACE_TCHAR *[])
49 ACE::init ();
51 ACE_START_TEST (ACE_TEXT ("Object_Manager_Test"));
53 u_int errors = 0;
55 // If hook1 never gets called, this will show up as a memory leak.
56 ACE_NEW_RETURN (ip,
57 u_int,
58 -1);
60 const int starting_up =
61 ACE_Object_Manager::instance ()->starting_up ();
62 const int shutting_down =
63 ACE_Object_Manager::instance ()->shutting_down ();
65 ACE_DEBUG ((LM_DEBUG,
66 ACE_TEXT ("starting_up: %d, shutting_down: %d\n"),
67 starting_up,
68 shutting_down));
70 if (starting_up || shutting_down)
72 ++errors;
73 ACE_ERROR ((LM_ERROR,
74 ACE_TEXT ("%p\n"),
75 ACE_TEXT ("starting_up and shutting_down are supposed to ")
76 ACE_TEXT (" be 0!!!!")));
79 if (ACE_OS::atexit (hook1) != 0)
81 ++errors;
82 ACE_ERROR ((LM_ERROR,
83 ACE_TEXT ("%p\n"),
84 ACE_TEXT ("ACE_OS::atexit () returned non-zero!!!!")));
87 for (u_int i = 0; i < 10; ++i)
89 u_int *paramp;
90 ACE_NEW_RETURN (paramp,
91 u_int,
92 -1);
93 *paramp = i;
95 // The first paramp argument is only used to distinguish the
96 // at_exit entries. The ACE_Object_Manager only allows one
97 // at_exit per object. It's not used in the hook.
98 if (ACE_Object_Manager::instance ()->at_exit (paramp,
99 hook2,
100 paramp))
102 ++errors;
103 ACE_ERROR ((LM_ERROR,
104 ACE_TEXT ("%p\n"),
105 ACE_TEXT ("ACE_Object_Manager::at_exit () ")
106 ACE_TEXT ("returned non-zero!!!!")));
110 ACE_END_TEST;
111 ACE::fini ();
112 return errors == 0 ? 0 : 1;