Compile fixes
[ACE_TAO.git] / ACE / tests / Singleton_Restart_Test.cpp
blobf18966df0300a41297457343e8c4ccaf5f651fa9
1 #define ACE_DOESNT_DEFINE_MAIN
3 #include "test_config.h"
5 #include "ace/Init_ACE.h"
6 #include "ace/Singleton.h"
8 int restart_test_logging (const ACE_TCHAR *program)
10 if (ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM |
11 ACE_Log_Msg::VERBOSE_LITE) != 0)
12 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
13 ACE_TEXT ("open log_msg failed")), -1);
14 if (ace_file_stream::instance()->set_output (program, 1) != 0)
15 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
16 ACE_TEXT ("set_output failed")), -1);
17 return 0;
20 void report_error (const ACE_TCHAR *lock)
22 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE_Singleton<int, %s> ")
23 ACE_TEXT ("failed to allocate\n"), lock));
26 using Singleton1 = ACE_Singleton<int, ACE_MT_SYNCH::MUTEX>;
27 using Singleton2 = ACE_Singleton<int, ACE_MT_SYNCH::RECURSIVE_MUTEX>;
29 int main ()
31 ACE::init ();
32 ACE_START_TEST (ACE_TEXT ("Singleton_Restart_Test"));
34 *Singleton1::instance () = 1;
35 *Singleton2::instance () = 2;
37 ACE::fini ();
38 ACE::init ();
39 if (restart_test_logging (program) != 0) // program defined in ACE_START_TEST
40 return -1;
42 int *i1 = Singleton1::instance ();
43 if (!i1)
44 report_error (ACE_TEXT ("ACE_SYNCH_MUTEX"));
46 int *i2 = Singleton2::instance ();
47 if (!i2)
48 report_error (ACE_TEXT ("ACE_SYNCH_RECURSIVE_MUTEX"));
50 ACE_END_TEST;
51 ACE::fini ();
53 return (i1 && i2) ? 0 : 1;