Make x.0.10 publicly available
[ACE_TAO.git] / ACE / tests / Object_Manager_Test.cpp
blob790647e3954fb0bec03f788eb231f70e906b8437
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"
19 static u_int *ip;
21 extern "C"
22 void
23 hook1 ()
25 delete ip;
26 ip = 0;
29 extern "C"
30 void
31 hook2 (void * /* object */, void *param)
33 u_int *paramp = reinterpret_cast<u_int *> (param);
35 // We can use ACE_Log_Msg in an ACE_Object_Manager cleanup hook.
36 // But NOT in an ACE_OS::atexit () hook! However, the ACE_END_TEST
37 // invocation in main () will prevent this from being output to the
38 // log stream.
39 ACE_DEBUG ((LM_DEBUG,
40 ACE_TEXT ("hook2: %d\n"),
41 *paramp));
42 delete paramp;
45 int
46 run_main (int, ACE_TCHAR *[])
48 ACE::init ();
50 ACE_START_TEST (ACE_TEXT ("Object_Manager_Test"));
52 u_int errors = 0;
54 // If hook1 never gets called, this will show up as a memory leak.
55 ACE_NEW_RETURN (ip,
56 u_int,
57 -1);
59 const int starting_up =
60 ACE_Object_Manager::instance ()->starting_up ();
61 const int shutting_down =
62 ACE_Object_Manager::instance ()->shutting_down ();
64 ACE_DEBUG ((LM_DEBUG,
65 ACE_TEXT ("starting_up: %d, shutting_down: %d\n"),
66 starting_up,
67 shutting_down));
69 if (starting_up || shutting_down)
71 ++errors;
72 ACE_ERROR ((LM_ERROR,
73 ACE_TEXT ("%p\n"),
74 ACE_TEXT ("starting_up and shutting_down are supposed to ")
75 ACE_TEXT (" be 0!!!!")));
78 if (ACE_OS::atexit (hook1) != 0)
80 ++errors;
81 ACE_ERROR ((LM_ERROR,
82 ACE_TEXT ("%p\n"),
83 ACE_TEXT ("ACE_OS::atexit () returned non-zero!!!!")));
86 for (u_int i = 0; i < 10; ++i)
88 u_int *paramp;
89 ACE_NEW_RETURN (paramp,
90 u_int,
91 -1);
92 *paramp = i;
94 // The first paramp argument is only used to distinguish the
95 // at_exit entries. The ACE_Object_Manager only allows one
96 // at_exit per object. It's not used in the hook.
97 if (ACE_Object_Manager::instance ()->at_exit (paramp,
98 hook2,
99 paramp))
101 ++errors;
102 ACE_ERROR ((LM_ERROR,
103 ACE_TEXT ("%p\n"),
104 ACE_TEXT ("ACE_Object_Manager::at_exit () ")
105 ACE_TEXT ("returned non-zero!!!!")));
109 ACE_END_TEST;
110 ACE::fini ();
111 return errors == 0 ? 0 : 1;