(file) Return to Tracer.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common / tests / Tracer

  1 kumpf 1.1.2.1 //%/////////////////////////////////////////////////////////////////////////////
  2               //
  3               // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
  4               // The Open Group, Tivoli Systems
  5               //
  6               // Permission is hereby granted, free of charge, to any person obtaining a copy
  7               // of this software and associated documentation files (the "Software"), to
  8               // deal in the Software without restriction, including without limitation the
  9               // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10               // sell copies of the Software, and to permit persons to whom the Software is
 11               // furnished to do so, subject to the following conditions:
 12               //
 13               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14               // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15               // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16               // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17               // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18               // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19               // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20               // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21               //
 22 kumpf 1.1.2.1 //==============================================================================
 23               //
 24               // Author: Sushma Fernandes (sushma_fernandes@hp.com)
 25               //
 26               // Modified By:
 27               //
 28               //%/////////////////////////////////////////////////////////////////////////////
 29               
 30               #include <fstream.h>
 31               #include <string.h>
 32               #include <Pegasus/Common/System.h>
 33               #include <Pegasus/Common/Tracer.h>
 34               
 35               PEGASUS_USING_STD;
 36 mday  1.1.2.2 PEGASUS_USING_PEGASUS;
 37 kumpf 1.1.2.1 
 38               
 39               // Trace files for test purposes
 40               // Will be created in the current directory
 41               
 42               const char* FILE1 = "testtracer1.trace";
 43               const char* FILE2 = "testtracer2.trace";
 44               const char* FILE3 = "testtracer1.trace";
 45               
 46               // 
 47               // Reads the last trace message from a given trace file and compares the 
 48               // given string with the string read from file
 49               //
 50               // return 0 if the strings match
 51               // return 1 if the strings do not match
 52               //
 53               Uint32 compare(const char* fileName, const char* compareStr)
 54               {
 55                   Uint32 count=0;
 56                   Uint32 retCode=0;
 57                   fstream file;
 58 kumpf 1.1.2.1     Uint32 size=strlen(compareStr);
 59                   char* readStr= new char[size+1];
 60               
 61                   file.open(fileName,fstream::in);
 62                   if (!file.good())
 63                   {
 64                       delete []readStr;
 65               	return 1;
 66                   }
 67                   file.seekg(-(size+1),fstream::end);
 68               
 69                   file.read(readStr,size+1);
 70                   readStr[size]='\0';
 71                   retCode=strcmp(compareStr,readStr);
 72                   delete []readStr;
 73                   file.close();
 74                   return retCode;
 75               }
 76               
 77               //
 78               // Description:
 79 kumpf 1.1.2.1 // Trace properties file, level and component are not set
 80               // Should not log a trace message
 81               //
 82               // Type:
 83               // Negative 
 84               //
 85               // return 0 if the test passed
 86               // return 1 if the test failed
 87               //
 88               Uint32 test1()
 89               {
 90                   const char* METHOD_NAME = "test1";
 91                   PEG_FUNC_ENTER(TRC_CONFIG,METHOD_NAME);
 92                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %d",
 93               	"This message should not appear value=",123);
 94                   PEG_FUNC_EXIT(TRC_CONFIG,METHOD_NAME);
 95                   return(compare(FILE1,""));
 96               }
 97               
 98               //
 99               // Description:
100 kumpf 1.1.2.1 // Trace properties level and component are not set
101               // Should not log a trace message
102               //
103               // Type:
104               // Negative 
105               //
106               // return 0 if the test passed
107               // return 1 if the test failed
108               //
109               Uint32 test2()
110               {
111                   const char* METHOD_NAME = "test2";
112                   Tracer::setTraceFile(FILE1);
113                   PEG_FUNC_ENTER(TRC_CONFIG,METHOD_NAME);
114                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %d",
115               	"This message should not appear value=",123);
116                   return(compare(FILE1,"This message should not appear value=123"));
117               }
118               
119               //
120               // Description:
121 kumpf 1.1.2.1 // Trace properties component is not set
122               // Should not log a trace message
123               //
124               // Type:
125               // Negative 
126               //
127               // return 0 if the test passed
128               // return 1 if the test failed
129               //
130               Uint32 test3()
131               {
132                   const char* METHOD_NAME = "test3";
133                   Tracer::setTraceLevel(Tracer::LEVEL1);
134                   PEG_FUNC_ENTER(TRC_CONFIG,METHOD_NAME);
135                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s",
136               	"This message should not appear");
137                   return(compare(FILE1,"This message should not appear"));
138               }
139               
140               //
141               // Description:
142 kumpf 1.1.2.1 // Trace properties file, level and component are set
143               // should log a trace message
144               //
145               // Type:
146               // Positive 
147               //
148               // return 0 if the test passed
149               // return 1 if the test failed
150               //
151               Uint32 test4()
152               {
153                   const char* METHOD_NAME = "test4";
154                   Tracer::setTraceComponents("Config");
155                   PEG_FUNC_ENTER(TRC_CONFIG,METHOD_NAME);
156                   return(compare(FILE1,"Entering method test4"));
157               }
158               
159               //
160               // Description:
161               // Trace component is set to an invalid component
162               // should not log a trace message
163 kumpf 1.1.2.1 //
164               // Type:
165               // Negative 
166               //
167               // return 0 if the test passed
168               // return 1 if the test failed
169               //
170               Uint32 test5()
171               {
172                   const char* METHOD_NAME = "test5";
173                   Tracer::setTraceComponents("Wrong Component Name");
174                   PEG_FUNC_EXIT(TRC_CONFIG,METHOD_NAME);
175                   return(compare(FILE1,"Entering method test4"));
176               }
177               
178               //
179               // Description:
180               // Trace level is set to LEVEL 2 and logs a LEVEL 4 message 
181               // should not log a trace message
182               //
183               // Type:
184 kumpf 1.1.2.1 // Negative 
185               //
186               // return 0 if the test passed
187               // return 1 if the test failed
188               //
189               
190               Uint32 test6()
191               {
192                   const char* METHOD_NAME = "test6";
193                   Tracer::setTraceComponents("Config");
194                   Tracer::setTraceLevel(Tracer::LEVEL2);
195                   Tracer::trace(TRC_CONFIG,Tracer::LEVEL2,"%s %s",
196               	"Test Message for Level2 in",METHOD_NAME);
197                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %s",
198               	"Test Message for Level2 in",METHOD_NAME);
199                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s",
200               	"This Message should not appear");
201                   return(compare(FILE1,"Test Message for Level2 in test6"));
202               }
203               
204               //
205 kumpf 1.1.2.1 // Description:
206               // Trace level is set to an invalid level
207               // should not log a trace message
208               //
209               // Type:
210               // Negative 
211               //
212               // return 0 if the test passed
213               // return 1 if the test failed
214               //
215               Uint32 test7()
216               {
217                   const char* METHOD_NAME = "test7";
218                   Tracer::setTraceLevel(100);
219                   PEG_FUNC_EXIT(TRC_CONFIG,METHOD_NAME);
220                   return(compare(FILE1,"Test Message for Level2 in test6"));
221               }
222               
223               //
224               // Description:
225               // Trace level is set to LEVEL1 for a non entry/exit message
226 kumpf 1.1.2.1 // should not log a trace message, should log an error
227               //
228               // Type:
229               // Negative 
230               //
231               // return 0 if the test passed
232               // return 1 if the test failed
233               //
234               Uint32 test8()
235               {
236                   const char* METHOD_NAME = "test8";
237                   Tracer::setTraceLevel(Tracer::LEVEL1);
238                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL1,"%s",
239               	"Test Message for Level4");
240                   return(compare(FILE1,"Test Message for Level2 in test6"));
241               }
242               
243               //
244               // Description:
245               // Changes the trace file to FILE2 
246               //
247 kumpf 1.1.2.1 // Type:
248               // Positive 
249               //
250               // return 0 if the test passed
251               // return 1 if the test failed
252               //
253               Uint32 test9()
254               {
255                   const char* METHOD_NAME = "test9";
256                   Tracer::setTraceLevel(Tracer::LEVEL3);
257                   Tracer::setTraceFile(FILE2);
258               
259                   PEG_FUNC_ENTER(TRC_CONFIG,METHOD_NAME);
260                   Tracer::trace(TRC_CONFIG,Tracer::LEVEL3,"%s %s",
261               	"Test Message for Level3 in",METHOD_NAME);
262                   return(compare(FILE2,"Test Message for Level3 in test9"));
263               }
264               
265               //
266               // Description:
267               // Passes invalid component in the trace call
268 kumpf 1.1.2.1 // should not log a trace message
269               //
270               // Type:
271               // Negative 
272               //
273               // return 0 if the test passed
274               // return 1 if the test failed
275               //
276               
277               Uint32 test10()
278               {
279                   const char* METHOD_NAME = "test10";
280                   Tracer::setTraceComponents("ALL");
281                   PEG_FUNC_EXIT((TRC_IND_DELIVERY+1),METHOD_NAME);
282                   PEG_FUNC_EXIT(-1,METHOD_NAME);
283                   return(compare(FILE2,"Test Message for Level3 in test9"));
284               }
285               
286               //
287               // Description:
288               // Implements trace call for Tracer::Level1
289 kumpf 1.1.2.1 // should log a trace message
290               //
291               // Type:
292               // Positive 
293               //
294               // return 0 if the test passed
295               // return 1 if the test failed
296               //
297               
298               Uint32 test11()
299               {
300                   const char* METHOD_NAME = "test11";
301                   Tracer::setTraceComponents("ALL");
302                   Tracer::setTraceLevel(Tracer::LEVEL4);
303                   PEG_FUNC_ENTER(TRC_CONFIG,METHOD_NAME);
304                   return(compare(FILE2,"Entering method test11"));
305               }
306               
307               //
308               // Description:
309               // Implements trace call for Tracer::Level1
310 kumpf 1.1.2.1 // should log a trace message
311               //
312               // Type:
313               // Positive 
314               //
315               // return 0 if the test passed
316               // return 1 if the test failed
317               //
318               
319               Uint32 test12()
320               {
321                   const char* METHOD_NAME = "test12";
322                   Tracer::setTraceComponents("ALL");
323                   Tracer::setTraceLevel(Tracer::LEVEL4);
324                   PEG_FUNC_EXIT(TRC_CONFIG,METHOD_NAME);
325                   return(compare(FILE2,"Exiting method test12"));
326               }
327               
328               //
329               // Description:
330               // Implements trace call for Tracer::Level2
331 kumpf 1.1.2.1 // should log a trace message
332               //
333               // Type:
334               // Positive 
335               //
336               // return 0 if the test passed
337               // return 1 if the test failed
338               //
339               
340               Uint32 test13()
341               {
342                   const char* METHOD_NAME = "test13";
343                   Tracer::setTraceComponents("ALL");
344                   Tracer::setTraceLevel(Tracer::LEVEL4);
345                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %s",
346               	"Test Message for Level2 in",METHOD_NAME);
347                   return(compare(FILE2,"Test Message for Level2 in test13"));
348               }
349               
350               //
351               // Description:
352 kumpf 1.1.2.1 // Implements trace call for Tracer::Level3
353               // should log a trace message
354               //
355               // Type:
356               // Positive 
357               //
358               // return 0 if the test passed
359               // return 1 if the test failed
360               //
361               
362               Uint32 test14()
363               {
364                   const char* METHOD_NAME = "test14";
365                   Tracer::setTraceComponents("ALL");
366                   Tracer::setTraceLevel(Tracer::LEVEL4);
367                   Tracer::setTraceFile(FILE3);
368                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL3,"%s %s",
369               	"Test Message for Level3 in",METHOD_NAME);
370                   return(compare(FILE3,"Test Message for Level3 in test14"));
371               }
372               
373 kumpf 1.1.2.1 //
374               // Description:
375               // Implements trace call for Tracer::Level4
376               // should log a trace message
377               //
378               // Type:
379               // Positive 
380               //
381               // return 0 if the test passed
382               // return 1 if the test failed
383               //
384               
385               Uint32 test15()
386               {
387                   const char* METHOD_NAME = "test15";
388                   Tracer::setTraceComponents("ALL");
389                   Tracer::setTraceLevel(Tracer::LEVEL4);
390                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s %s",
391               	"Test Message for Level4 in",METHOD_NAME);
392                   return(compare(FILE3,"Test Message for Level4 in test15"));
393               }
394 kumpf 1.1.2.1 
395               //
396               // Description:
397               // calls the setTraceComponents with null string
398               // should log a trace message
399               //
400               // Type:
401               // Negative 
402               //
403               // return 0 if the test passed
404               // return 1 if the test failed
405               //
406               
407               Uint32 test16()
408               {
409                   const char* METHOD_NAME = "test16";
410                   Tracer::setTraceComponents("");
411                   Tracer::setTraceLevel(Tracer::LEVEL4);
412                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s %s",
413               	"This Message should not appear in",METHOD_NAME);
414                   return(compare(FILE3,"Test Message for Level4 in test15"));
415 kumpf 1.1.2.1 }
416               
417               //
418               // Description:
419               // calls the setTraceComponents with one valid and another invalid component
420               // should log a trace message
421               //
422               // Type:
423               // Negative 
424               //
425               // return 0 if the test passed
426               // return 1 if the test failed
427               //
428               
429               Uint32 test17()
430               {
431                   const char* METHOD_NAME = "test17";
432                   Tracer::setTraceComponents("Config,InvalidComp");
433                   Tracer::setTraceLevel(Tracer::LEVEL4);
434                   Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s %s",
435               	"This Message should not appear in",METHOD_NAME);
436 kumpf 1.1.2.1     return(compare(FILE3,"Test Message for Level4 in test15"));
437               }
438               
439               int main()
440               {
441               
442               // Execute the tests only if trace calls are included
443               
444               #ifdef PEGASUS_REMOVE_TRACE
445                   cout << "+++++ passed all tests" << endl;
446                   return 0;
447               #else
448                   System::removeFile(FILE1);
449                   System::removeFile(FILE2);
450                   System::removeFile(FILE3);
451                   if (test1() == 0)
452                   {
453                      cout << "Tracer test (test1) failed" << endl;
454                      exit(1);
455                   }
456                   if (test2() == 0)
457 kumpf 1.1.2.1     {
458                      cout << "Tracer test (test2) failed" << endl;
459                      exit(1);
460                   }
461                   if (test3() == 0)
462                   {
463                      cout << "Tracer test (test3) failed" << endl;
464                      exit(1);
465                   }
466                   if (test4() != 0)
467                   {
468                      cout << "Tracer test (test4) failed" << endl;
469                      exit(1);
470                   }
471                   if (test5() != 0)
472                   {
473                      cout << "Tracer test (test5) failed" << endl;
474                      exit(1);
475                   }
476                   if (test6() != 0)
477                   {
478 kumpf 1.1.2.1        cout << "Tracer test (test6) failed" << endl;
479                      exit(1);
480                   }
481                   if (test7() != 0)
482                   {
483                      cout << "Tracer test (test7) failed" << endl;
484                      exit(1);
485                   }
486                   if (test8() != 0)
487                   {
488                      cout << "Tracer test (test8) failed" << endl;
489                      exit(1);
490                   }
491                   if (test9() != 0)
492                   {
493                      cout << "Tracer test (test9) failed" << endl;
494                      exit(1);
495                   }
496                   if (test10() != 0)
497                   {
498                      cout << "Tracer test (test10) failed" << endl;
499 kumpf 1.1.2.1        exit(1);
500                   }
501                   if (test11() != 0)
502                   {
503                      cout << "Tracer test (test11) failed" << endl;
504                      exit(1);
505                   }
506                   if (test12() != 0)
507                   {
508                      cout << "Tracer test (test12) failed" << endl;
509                      exit(1);
510                   }
511                   if (test13() != 0)
512                   {
513                      cout << "Tracer test (test13) failed" << endl;
514                      exit(1);
515                   }
516                   if (test14() != 0)
517                   {
518                      cout << "Tracer test (test14) failed" << endl;
519                      exit(1);
520 kumpf 1.1.2.1     }
521                   if (test15() != 0)
522                   {
523                      cout << "Tracer test (test15) failed" << endl;
524                      exit(1);
525                   }
526                   if (test16() != 0)
527                   {
528                      cout << "Tracer test (test16) failed" << endl;
529                      exit(1);
530                   }
531                   cout << "+++++ passed all tests" << endl;
532                   System::removeFile(FILE1);
533                   System::removeFile(FILE2);
534                   System::removeFile(FILE3);
535                   return 0;
536               #endif
537               }
538               

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2