Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Trading / export_test.cpp
blobf786547ff6ac987c57017de29c4e09db9bbb811b
1 #include "tao/Utils/ORB_Manager.h"
2 #include "Offer_Exporter.h"
3 #include "Offer_Importer.h"
4 #include "Service_Type_Exporter.h"
5 #include "ace/Auto_Ptr.h"
6 #include "orbsvcs/Trader/Trader.h"
7 #include "orbsvcs/Trader/Service_Type_Repository.h"
8 #include "ace/Get_Opt.h"
10 const ACE_TCHAR *done_file = ACE_TEXT("export_test_ready");
12 int
13 parse_args_spec (int argc, ACE_TCHAR *argv[], int help)
15 if (help!=0)
17 ACE_DEBUG ((LM_INFO,
18 "\nUsage: export_test <options>\n"
19 "Test the trader's exporter role, the options are:\n"
20 "-ORBInitRef <orb_options> E.g. '-ORBInitRef TradingService=iiop://localhost:8901/TradingService'\n"
21 "-quiet or -q (optional) Run the tests in quiet mode, don't show the query and list results.\n"
22 "-federate or -f (optional) Setup for federated trader tests.\n"
23 "-iorfile or -i (optional) Get TradingService reference through IOR instead of resolve.\n"
24 "-d <done_file> (optional) Filename for signalling that we are ready for serving dynamic properties (for import_test).\n"
25 "\n"
26 "This test needs an external TradingServer running, example:\n"
27 " Trading_Service -ORBEndpoint iiop://:8901 -TSdumpior trading.ior\n"
28 "See also TAO/docs/releasenotes/trader.html.\n\n"));
29 return -1;
31 else
33 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("d:"));
34 for (int opt; (opt = get_opts()) != -1;)
36 if (opt == 'd')
38 done_file = get_opts.opt_arg ();
42 return 0;
46 int
47 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
49 int failure = 0;
51 try
53 int help=(argc<=1);
55 TAO_ORB_Manager orb_manager;
56 orb_manager.init (argc, argv);
58 // Command line argument parser for use with comlex pearl tests.
59 if (parse_args_spec (argc, argv, help) != 0)
60 return 1;
62 // Command line argument parser for the trading tests.
63 TT_Parse_Args parse_args (argc, argv);
65 // Init the orb and bootstrap to the trading service.
66 CORBA::ORB_var orb = orb_manager.orb ();
67 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Bootstrap to the Lookup interface.\n")));
69 char* ior = parse_args.ior ();
70 CORBA::Object_var trading_obj = (ior == 0) ?
71 orb->resolve_initial_references ("TradingService") :
72 orb->string_to_object (ior);
74 if (CORBA::is_nil (trading_obj.in ()))
75 ACE_ERROR_RETURN ((LM_ERROR,
76 ACE_TEXT("ERROR, Unable to bootstrap to the Trading Service!\n")),
77 1);
79 // Narrow the lookup interface.
80 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Narrowing the lookup interface.\n")));
81 CosTrading::Lookup_var lookup_if =
82 CosTrading::Lookup::_narrow (trading_obj.in ());
84 // Run the Service Type Exporter tests.
85 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Running the Service Type Exporter tests.\n")));
86 TAO_Service_Type_Exporter type_exporter (lookup_if.in (), ! parse_args.quiet ());
88 type_exporter.remove_all_types ();
90 type_exporter.add_all_types ();
92 type_exporter.remove_all_types ();
94 type_exporter.add_all_types ();
96 if (parse_args.federated ())
98 type_exporter.add_all_types_to_all ();
101 type_exporter.list_all_types ();
103 type_exporter.describe_all_types ();
105 type_exporter.fully_describe_all_types ();
107 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Service Type Exporter tests complete.\n")));
109 // Run the Offer Exporter tests.
110 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Running the Offer Exporter tests.\n")));
111 TAO_Offer_Exporter offer_exporter (lookup_if.in (), ! parse_args.quiet ());
113 // = Test series.
115 offer_exporter.withdraw_offers ();
117 offer_exporter.export_offers ();
119 offer_exporter.describe_offers ();
121 offer_exporter.modify_offers ();
123 offer_exporter.describe_offers ();
125 offer_exporter.withdraw_offers_using_constraints ();
127 offer_exporter.describe_offers ();
129 offer_exporter.withdraw_offers ();
131 offer_exporter.export_offers ();
133 if (parse_args.federated ())
135 offer_exporter.export_offers_to_all ();
138 offer_exporter.describe_offers ();
140 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Offer Exporter tests complete.\n")));
141 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("*** Now serving dynamic properties.\n")));
143 FILE *ready_file = ACE_OS::fopen (done_file, ACE_TEXT("w"));
144 if (ready_file != 0)
146 ACE_OS::fprintf (ready_file, "The export test is ready\n");
147 ACE_OS::fclose (ready_file);
149 else
151 ACE_DEBUG ((LM_WARNING,
152 ACE_TEXT("Unable to open %s for output.\n"),
153 done_file));
156 orb_manager.run ();
158 catch (const CORBA::Exception& e)
160 e._tao_print_exception ("Trader export test ERROR!");
161 failure = 1;
164 return failure;