Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3559_Regression / Bug_3559_Regression_Test.cpp
blobbacd17277fcce5d847e1443326982ee8ab7104f9
1 #include "tao/ORB.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/ACE.h"
7 const ACE_TCHAR* log_file_;
9 int
10 parse_args (int argc, ACE_TCHAR* argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("l:"));
14 int c;
16 while ((c = get_opts()) != -1)
18 switch (c)
20 case 'l':
21 log_file_ = get_opts.opt_arg();
22 return 0;
25 return 1;
29 int
30 check_logging()
32 ACE_TCHAR buf[1024];
33 FILE* fp = ACE_OS::fopen (log_file_,
34 ACE_TEXT ("r"));
36 if (fp == 0)
38 ACE_ERROR ((LM_ERROR,
39 ACE_TEXT ("error opening log file %s\n"),
40 log_file_));
41 return 1;
45 while (ACE_OS::fgets (buf, sizeof (buf), fp) != 0)
47 ///When verbose is on, a line contains a timestamp and a @ character
48 if (ACE_OS::strchr (buf, ACE_TEXT('@')) != 0)
50 ACE_DEBUG((LM_DEBUG,
51 ACE_TEXT ("Test OK, a timestamp was found\n")));
52 (void) ACE_OS::fclose (fp);
53 return 0;
56 ACE_ERROR ((LM_ERROR,
57 ACE_TEXT ("Test failed, no timestamp found in log\n")));
58 (void) ACE_OS::fclose (fp);
59 return 1;
62 int
63 check_flags (const u_long& flags, const int& verbose)
65 int result = 0;
66 switch (verbose)
68 case 0:
69 /// Both VERBOSE and VERBOSE_LITE shouldn't be set
70 if ((flags & ACE_Log_Msg::VERBOSE) != 0 &&
71 (flags & ACE_Log_Msg::VERBOSE_LITE) != 0)
73 ACE_ERROR ((LM_ERROR,
74 ACE_TEXT ("Test failed: Verbose flag not set properly when verbose=0\n")));
75 result = 1;
77 break;
78 case 1:
79 /// VERBOSE_LITE should be set
80 if ((flags & ACE_Log_Msg::VERBOSE_LITE) == 0)
82 ACE_ERROR ((LM_ERROR,
83 ACE_TEXT ("Test failed: Verbose flag not set properly when verbose=1\n")));
84 result = 1;
86 break;
87 default:
88 /// VERBOSE should be set
89 if ((flags & ACE_Log_Msg::VERBOSE) == 0)
91 ACE_ERROR ((LM_ERROR,
92 ACE_TEXT ("Test failed: Verbose flag not set properly when verbose=unknown\n")));
93 result = 1;
95 break;
97 return result;
101 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
103 int result = 0;
104 int extra_argc = 25;
108 if (parse_args(argc, argv) != 0)
110 ACE_ERROR((LM_ERROR,
111 ACE_TEXT ("Usage:\n\n")
112 ACE_TEXT ("OPTIONS:\n\n")
113 ACE_TEXT ("\t[-l Log file]\n\n")));
114 return 1;
117 for (int verbose = 0; verbose < 3; verbose++)
119 ACE_DEBUG ((LM_DEBUG,
120 ACE_TEXT ("Start ORB_init with ORBVerboseLogging=%d\n"),
121 verbose));
123 ACE_TCHAR **extra = 0;
124 ACE_NEW_RETURN (extra, ACE_TCHAR *[extra_argc], -1);
125 extra[0] = ACE::strnew (ACE_TEXT ("-ORBCDRTradeoff"));
126 extra[1] = ACE::strnew (ACE_TEXT ("2048"));
127 extra[2] = ACE::strnew (ACE_TEXT ("-ORBCollocation"));
128 extra[3] = ACE::strnew (ACE_TEXT ("per-orb"));
129 extra[4] = ACE::strnew (ACE_TEXT ("-ORBDebug"));
130 extra[5] = ACE::strnew (ACE_TEXT ("-ORBDebugLevel"));
131 extra[6] = ACE::strnew (ACE_TEXT ("10"));
132 extra[7] = ACE::strnew (ACE_TEXT ("-ORBDefaultInitRef"));
133 extra[8] = ACE::strnew (ACE_TEXT ("corbaloc::localhost:4177"));
134 extra[9] = ACE::strnew (ACE_TEXT ("-ORBDottedDecimalAddresses"));
135 extra[10] = ACE::strnew (ACE_TEXT ("1"));
136 extra[11] = ACE::strnew (ACE_TEXT ("-ORBId"));
137 extra[12] = ACE::strnew (ACE_TEXT ("Client"));
138 extra[13] = ACE::strnew (ACE_TEXT ("-ORBListenEndpoints"));
139 extra[14] = ACE::strnew (ACE_TEXT ("iiop://:4178"));
140 extra[15] = ACE::strnew (ACE_TEXT ("-ORBLogFile"));
141 ACE_NEW_RETURN (extra[16],
142 ACE_TCHAR[ACE_OS::strlen(log_file_) + 1],
143 -1);
144 ACE_OS::sprintf (extra[16], ACE_TEXT("%s"), log_file_);
145 extra[17] = ACE::strnew (ACE_TEXT ("-ORBNegotiateCodesets"));
146 extra[18] = ACE::strnew (ACE_TEXT ("0"));
147 extra[19] = ACE::strnew (ACE_TEXT ("-ORBNodelay"));
148 extra[20] = ACE::strnew (ACE_TEXT ("1"));
149 extra[21] = ACE::strnew (ACE_TEXT ("-ORBSvcConfDirective"));
150 extra[22] = ACE::strnew (ACE_TEXT ("\"static Client_Strategy_Factory '-ORBWaitStrategy mt_noupcall'\""));
151 extra[23] = ACE::strnew (ACE_TEXT ("-ORBVerboseLogging"));
152 ACE_NEW_RETURN (extra[24],
153 ACE_TCHAR[2],
154 -1);
155 ACE_OS::sprintf (extra[24], ACE_TEXT ("%d"), verbose);
157 ACE_TCHAR **largv = new ACE_TCHAR *[argc+extra_argc];
158 for (int i = 0; i < argc; i++)
159 largv[i] = argv[i];
161 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("server adding args: ")));
162 for (int i = 0; i < extra_argc; i++)
164 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s "), extra[i]));
165 largv[argc+i] = extra[i];
167 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
169 argc += extra_argc;
171 ACE_TCHAR orb_name[25];
172 ACE_OS::sprintf (orb_name, ACE_TEXT ("VERBOSE_LOGGING_TEST_%d"), verbose);
174 CORBA::ORB_var orb = CORBA::ORB_init (argc, largv, orb_name);
176 u_long log_flags = ACE_LOG_MSG->flags();
178 ACE_DEBUG ((LM_DEBUG,
179 ACE_TEXT ("log flags %d verbose: %d\n"),
180 log_flags, verbose));
182 result += check_flags (log_flags, verbose);
184 orb->destroy ();
185 orb = CORBA::ORB::_nil ();
186 ACE_LOG_MSG->restart ();
188 for (int i = 0; i < extra_argc; i++)
189 ACE::strdelete (extra[i]);
190 delete [] extra;
191 delete [] largv;
194 catch (const CORBA::Exception& ex)
196 ex._tao_print_exception ("Exception caught:");
197 return 1;
200 result += check_logging ();
202 if (result == 0)
203 ACE_DEBUG ((LM_DEBUG,
204 ACE_TEXT ("Test passed!")));
205 else
206 ACE_ERROR ((LM_ERROR,
207 ACE_TEXT ("Test failed. Result: %d\n"),
208 result));
209 return result;