Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / twoway / Collocated_Test.cpp
blob507c484bccc919e94c3656f5db30ff09695955b9
1 // This include is needed for static builds to initialize DII_Arguments_Converter
2 // service object.
3 //#include "tao/DynamicInterface/DII_Arguments_Converter_Impl.h"
5 #include "Server_Task.h"
6 #include "Client_Task.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Argv_Type_Converter.h"
9 #include "ace/SString.h"
10 #include "ace/Manual_Event.h"
12 const ACE_TCHAR *output = ACE_TEXT("server.ior");
13 const ACE_TCHAR *input = ACE_TEXT("file://server.ior");
14 const ACE_TCHAR *simple_test_output = ACE_TEXT("simple_test.ior");
15 const ACE_TCHAR *simple_test_input = ACE_TEXT("file://simple_test.ior");
16 // static int named_orbs = 0;
17 ACE_CString server_orb;
18 ACE_CString client_orb;
20 CORBA::Boolean debug = 0;
22 int
23 parse_args (int argc, ACE_TCHAR *argv[])
25 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:nd"));
26 int c;
28 while ((c = get_opts ()) != -1)
29 switch (c)
31 case 'o':
32 output = get_opts.opt_arg ();
33 break;
34 case 'k':
35 input = get_opts.opt_arg ();
36 break;
37 case 'n':
38 // named_orbs = 1;
39 server_orb.set ("server_orb");
40 client_orb.set ("client_orb");
41 break;
42 case 'd':
43 debug = 1;
44 break;
45 case '?':
46 default:
47 // This is a hack but that is okay!
48 return 0;
50 // Indicates successful parsing of the command line
51 return 0;
54 int
55 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
57 if (parse_args (argc,
58 argv) == -1)
59 return -1;
61 try
63 ACE_Argv_Type_Converter satc (argc, argv);
64 CORBA::ORB_var sorb =
65 CORBA::ORB_init (satc.get_argc (),
66 satc.get_TCHAR_argv (),
67 server_orb.c_str ());
69 ACE_Manual_Event me;
70 Server_Task server_task (output,
71 simple_test_output,
72 sorb.in (),
73 me,
74 ACE_Thread_Manager::instance ());
76 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
78 1) == -1)
80 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
83 // Wait for the server thread to do some processing
84 me.wait ();
86 ACE_Argv_Type_Converter catc (argc, argv);
87 CORBA::ORB_var corb =
88 CORBA::ORB_init (catc.get_argc (),
89 catc.get_TCHAR_argv (),
90 client_orb.c_str ());
92 Client_Task client_task (input,
93 simple_test_input,
94 corb.in (),
95 ACE_Thread_Manager::instance ());
97 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
99 1) == -1)
101 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
104 // Wait for the client and server to finish
105 ACE_Thread_Manager::instance ()->wait ();
107 // Now that all threads have completed we can destroy the ORB
108 sorb->destroy ();
109 if (server_orb != client_orb)
111 corb->destroy ();
114 CORBA::ULong errors = client_task.error_count () + server_task.error_count ();
115 if (errors == 0)
117 ACE_DEBUG((LM_DEBUG, "(%P|%t) test passed\n"));
119 else
121 ACE_DEBUG((LM_DEBUG, "(%P|%t) test failed - error_count=%u\n", errors));
122 return 1;
125 catch (const CORBA::Exception&)
127 // Ignore exceptions..
129 return 0;