2 //=============================================================================
4 * @file Object_Manager_Flipping_Test.cpp
7 * Tests the basic function of the ACE_Service_Config in scenarios
8 * where the ACE_Object_Manager is being
9 * flipped. i.e. ACE::init/ACE::fini() are called in sequence
10 * (which can occur with loading DLLs). More specifically we test
11 * that the OM correctly controlls the lifecycle of the default SC
12 * instance, which is pointed to by a TSS pointer.
14 * @author Iliyan Jeliazkov <iliyan@ociweb.com>
16 //=============================================================================
18 #include "test_config.h"
19 #include "ace/Object_Manager.h"
20 #include "ace/OS_Memory.h"
21 #include "ace/Init_ACE.h"
22 #include "ace/Service_Config.h"
23 #include "ace/Intrusive_Auto_Ptr.h"
35 int run_main (int, ACE_TCHAR
*[])
37 // Causing the creation of a SC instance and the corresponding TSS
38 // key. It is not registered with the Object Manager, but beware -
39 // OM finalization will destroy it too.
40 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt
> p0 (ACE_Service_Config::instance ());
41 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt
> p1
;
47 ACE_START_TEST (ACE_TEXT ("Object_Manager_Flipping_Test"));
49 // If hook1 never gets called, this will show up as a memory leak.
54 if (ACE_OS::atexit (hook1
) != 0)
59 ACE_TEXT ("ACE_OS::atexit () returned non-zero!!!!")));
62 // Obtain a SC instance which will be later used to compare with others.
63 p1
= ACE_Service_Config::instance ();
65 // ACE_TEST_ASSERT uses Log_Msg::instance() and needs to be done only
66 // after ACE_START_TEST
68 // Additional ACE::init() should not have changed the context
69 ACE_TEST_ASSERT (p0
== p1
);
71 // It should appear open
72 ACE_TEST_ASSERT (!p0
->is_opened ());
77 // ACE::fini() destroys the SC (unmanaged) singleton ...
78 // Next time we ask for one, it will be a different instance.
82 // This is a legitimate test, but more importantly an
83 // attemp to dereference p1 should succeed. If SC's TSS
84 // was not cleaned correctly this will SEGV. As will the
85 // following ACE::init, as it tries to use the SC instance.
87 if (ACE_Service_Config::instance ()->is_opened ())
90 // Not using ACE_TEST_ASSERT because ACE is not initialized yet.
94 ACE_START_TEST (ACE_TEXT ("Object_Manager_Flipping_Test"));
96 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt
> p2 (ACE_Service_Config::instance ());
98 // ACE_TEST_ASSERT uses Log_Msg::instance() and needs to be done only
99 // after ACE_START_TEST
100 // An attempt to dereference should be fine.
101 ACE_TEST_ASSERT (!p2
->is_opened ());
104 ACE::fini(); // Flipped twice
107 return errors
== 0 ? 0 : 1;