1 karl 1.26 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.18 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.16 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.18 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.21 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.26 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 kumpf 1.9 //
|
21 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
|
30 karl 1.29 //=============================================================================
|
31 mike 1.2 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <fstream>
35 #include <cstring>
36 #include <Pegasus/Common/System.h>
37 #include <Pegasus/Common/Tracer.h>
|
38 a.arora 1.17 #include <Pegasus/Common/AutoPtr.h>
|
39 sushma.fernandes 1.30 #include <Pegasus/Common/SharedPtr.h>
40 #include <Pegasus/Common/CIMClass.h>
41 #include <Pegasus/Common/CIMMessage.h>
42 #include <Pegasus/Common/XmlWriter.h>
43 #include <Pegasus/Common/AcceptLanguageList.h>
44 #include <Pegasus/Common/ContentLanguageList.h>
|
45 mike 1.2
46 PEGASUS_USING_STD;
47 PEGASUS_USING_PEGASUS;
48
|
49 marek 1.35
50 // Trace Levels 0 and 5 are defined as private constants of the tracer
51 // class to avoid inappropriate use in the trace calls and macros.
52 // Therefore these tracel levels need to be set in the tests using the
53 // constant values directly.
54 const Uint32 PEGASUS_TRACER_LEVEL0 = 0;
55 const Uint32 PEGASUS_TRACER_LEVEL5 = (1 << 4);
56
57
58
|
59 mike 1.2 // Trace files for test purposes
|
60 kumpf 1.11 // Will be created in the $(PEGASUS_TMP) directory, or if not set,
61 // in the current directory
|
62 kumpf 1.15 CString FILE1;
63 CString FILE2;
64 CString FILE3;
65 CString FILE4;
|
66 mike 1.2
67 //
68 // Reads the last trace message from a given trace file and compares the
69 // given string with the string read from file
70 //
71 // return 0 if the strings match
72 // return 1 if the strings do not match
73 //
|
74 kumpf 1.31 Uint32 compare(const char* fileName, const char* expectedMessage)
|
75 mike 1.2 {
|
76 kumpf 1.31 int expectedMessageLength = strlen(expectedMessage);
77
78 // Compute the size of the message in the trace file. Include the final
79 // EOL character added by the Tracer. This size will be used to seek
80 // from the end of the file back to the beginning of the trace message.
81 int seekBytes = expectedMessageLength + 1;
82
83 #if defined(PEGASUS_OS_TYPE_WINDOWS)
84 // Windows converts all '\n' characters to "\r\n" sequences in the trace
85 // file. Increase the seekBytes by the number of '\r' characters added
86 // when the message is written to the file.
87 for (const char* newlineChar = expectedMessage;
88 ((newlineChar = strchr(newlineChar, '\n')) != 0);
89 newlineChar++)
90 {
91 seekBytes++;
92 }
93
94 // Count the '\r' character added with the final '\n' written by the Tracer
95 seekBytes++;
96 #endif
97 kumpf 1.31
98 AutoArrayPtr<char> actualMessage(new char[expectedMessageLength + 1]);
99
100 // Read the trace message from the file, minus the message prefix and
101 // minus the trailing newline.
|
102 mike 1.2 fstream file;
|
103 kumpf 1.31 file.open(fileName, fstream::in);
|
104 mike 1.2 if (!file.good())
105 {
|
106 kumpf 1.31 return 1;
|
107 mike 1.2 }
|
108 kumpf 1.31 file.seekg(-seekBytes, fstream::end);
109 file.read(actualMessage.get(), expectedMessageLength);
110 file.close();
111 actualMessage[expectedMessageLength] = 0;
112
113 // Compare the expected and actual messages
114 Uint32 retCode = strcmp(expectedMessage, actualMessage.get());
115
116 /* Diagnostic to determine string differences
117 if (retCode)
118 cout << "Compare Error: expectedMessage= \n\"" << expectedMessage <<
119 "\". actualMessage= \n\"" << actualMessage.get() << "\"" << endl;
|
120 karl 1.27 */
121
|
122 mike 1.2 return retCode;
123 }
124
125 //
126 // Description:
127 // Trace properties file, level and component are not set
128 // Should not log a trace message
129 //
130 // Type:
131 // Negative
132 //
133 // return 0 if the test passed
134 // return 1 if the test failed
135 //
136 Uint32 test1()
137 {
138 const char* METHOD_NAME = "test1";
|
139 kumpf 1.10 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
140 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %d",
141 "This message should not appear value=",123));
|
142 kumpf 1.10 PEG_METHOD_EXIT();
|
143 kumpf 1.34 return System::exists(FILE1) ? 1 : 0;
|
144 mike 1.2 }
145
146 //
147 // Description:
148 // Trace properties level and component are not set
149 // Should not log a trace message
150 //
151 // Type:
152 // Negative
153 //
154 // return 0 if the test passed
155 // return 1 if the test failed
156 //
157 Uint32 test2()
158 {
159 const char* METHOD_NAME = "test2";
160 Tracer::setTraceFile(FILE1);
|
161 kumpf 1.10 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
162 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %d",
163 "This message should not appear value=",123));
|
164 kumpf 1.34 Uint32 fileSize;
165 System::getFileSize(FILE1, fileSize);
166 return (fileSize == 0) ? 0 : 1;
|
167 mike 1.2 }
168
169 //
170 // Description:
171 // Trace properties component is not set
172 // Should not log a trace message
173 //
174 // Type:
175 // Negative
176 //
177 // return 0 if the test passed
178 // return 1 if the test failed
179 //
180 Uint32 test3()
181 {
182 const char* METHOD_NAME = "test3";
183 Tracer::setTraceLevel(Tracer::LEVEL1);
|
184 kumpf 1.10 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
185 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s",
186 "This message should not appear"));
|
187 kumpf 1.34 Uint32 fileSize;
188 System::getFileSize(FILE1, fileSize);
189 return (fileSize == 0) ? 0 : 1;
|
190 mike 1.2 }
191
192 //
193 // Description:
194 // Trace properties file, level and component are set
195 // should log a trace message
196 //
197 // Type:
198 // Positive
199 //
200 // return 0 if the test passed
201 // return 1 if the test failed
202 //
203 Uint32 test4()
204 {
205 const char* METHOD_NAME = "test4";
|
206 marek 1.37 Tracer::setTraceLevel(Tracer::LEVEL1);
|
207 mike 1.2 Tracer::setTraceComponents("Config");
|
208 marek 1.37 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,METHOD_NAME);
209 return(compare(FILE1,METHOD_NAME));
|
210 mike 1.2 }
211
212 //
213 // Description:
214 // Trace component is set to an invalid component
215 // should not log a trace message
216 //
217 // Type:
218 // Negative
219 //
220 // return 0 if the test passed
221 // return 1 if the test failed
222 //
223 Uint32 test5()
224 {
225 const char* METHOD_NAME = "test5";
226 Tracer::setTraceComponents("Wrong Component Name");
|
227 karl 1.27
228 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
229 marek 1.37 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,METHOD_NAME);
|
230 karl 1.27 PEG_METHOD_EXIT();
|
231 marek 1.37 return(compare(FILE1,"test4"));
|
232 mike 1.2 }
233
234 //
235 // Description:
236 // Trace level is set to LEVEL 2 and logs a LEVEL 4 message
237 // should not log a trace message
238 //
239 // Type:
240 // Negative
241 //
242 // return 0 if the test passed
243 // return 1 if the test failed
244 //
245
246 Uint32 test6()
247 {
248 const char* METHOD_NAME = "test6";
249 Tracer::setTraceComponents("Config");
250 Tracer::setTraceLevel(Tracer::LEVEL2);
|
251 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
252 "Test Message for Level2 in",METHOD_NAME));
253 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
254 "Test Message for Level2 in",METHOD_NAME));
255 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s",
256 "This Message should not appear"));
|
257 mike 1.2 return(compare(FILE1,"Test Message for Level2 in test6"));
258 }
259
260 //
261 // Description:
262 // Trace level is set to an invalid level
263 // should not log a trace message
264 //
265 // Type:
266 // Negative
267 //
268 // return 0 if the test passed
269 // return 1 if the test failed
270 //
271 Uint32 test7()
272 {
273 const char* METHOD_NAME = "test7";
274 Tracer::setTraceLevel(100);
|
275 karl 1.27 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
276 PEG_METHOD_EXIT();
|
277 mike 1.2 return(compare(FILE1,"Test Message for Level2 in test6"));
278 }
279
280 //
281 // Description:
282 // Changes the trace file to FILE2
283 //
284 // Type:
285 // Positive
286 //
287 // return 0 if the test passed
288 // return 1 if the test failed
289 //
290 Uint32 test9()
291 {
292 const char* METHOD_NAME = "test9";
293 Tracer::setTraceLevel(Tracer::LEVEL3);
294 Tracer::setTraceFile(FILE2);
295
|
296 kumpf 1.10 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
297 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
298 "Test Message for Level3 in",METHOD_NAME));
|
299 mike 1.2 return(compare(FILE2,"Test Message for Level3 in test9"));
300 }
301
302 //
303 // Description:
304 // Passes invalid component in the trace call
305 // should not log a trace message
306 //
307 // Type:
308 // Negative
309 //
310 // return 0 if the test passed
311 // return 1 if the test failed
312 //
|
313 marek 1.35 // This test not required with change to
|
314 karl 1.27 // use and test macros only.
|
315 mike 1.2
316 Uint32 test10()
317 {
318 const char* METHOD_NAME = "test10";
319 Tracer::setTraceComponents("ALL");
|
320 karl 1.27 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
321 PEG_METHOD_EXIT();
|
322 mike 1.2 return(compare(FILE2,"Test Message for Level3 in test9"));
323 }
324
325 //
326 // Description:
|
327 marek 1.35 // Trace is set to level 0
328 // should not log a trace message
|
329 mike 1.2 //
330 // Type:
|
331 marek 1.35 // Negative
|
332 mike 1.2 //
333 // return 0 if the test passed
334 // return 1 if the test failed
335 //
336
337 Uint32 test11()
338 {
339 const char* METHOD_NAME = "test11";
340 Tracer::setTraceComponents("ALL");
|
341 marek 1.35 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL0);
342 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
343 "Test Message for Level0 in",METHOD_NAME));
344 return(compare(FILE2,"Test Message for Level3 in test9"));
|
345 mike 1.2 }
346
347 //
348 // Description:
349 // Implements trace call for Tracer::Level1
350 // should log a trace message
351 //
352 // Type:
353 // Positive
354 //
355 // return 0 if the test passed
356 // return 1 if the test failed
357 //
358
359 Uint32 test12()
360 {
361 const char* METHOD_NAME = "test12";
362 Tracer::setTraceComponents("ALL");
363 Tracer::setTraceLevel(Tracer::LEVEL4);
|
364 marek 1.35 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
365 "Test Message for Level1 in",METHOD_NAME));
366 return(compare(FILE2,"Test Message for Level1 in test12"));
|
367 mike 1.2 }
368
369 //
370 // Description:
371 // Implements trace call for Tracer::Level2
372 // should log a trace message
373 //
374 // Type:
375 // Positive
376 //
377 // return 0 if the test passed
378 // return 1 if the test failed
379 //
380
381 Uint32 test13()
382 {
383 const char* METHOD_NAME = "test13";
384 Tracer::setTraceComponents("ALL");
385 Tracer::setTraceLevel(Tracer::LEVEL4);
|
386 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
387 "Test Message for Level2 in",METHOD_NAME));
|
388 mike 1.2 return(compare(FILE2,"Test Message for Level2 in test13"));
389 }
390
391 //
392 // Description:
393 // Implements trace call for Tracer::Level3
394 // should log a trace message
395 //
396 // Type:
397 // Positive
398 //
399 // return 0 if the test passed
400 // return 1 if the test failed
401 //
402
403 Uint32 test14()
404 {
405 const char* METHOD_NAME = "test14";
406 Tracer::setTraceComponents("ALL");
407 Tracer::setTraceLevel(Tracer::LEVEL4);
408 Tracer::setTraceFile(FILE3);
|
409 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
410 "Test Message for Level3 in",METHOD_NAME));
|
411 mike 1.2 return(compare(FILE3,"Test Message for Level3 in test14"));
412 }
413
414 //
415 // Description:
416 // Implements trace call for Tracer::Level4
417 // should log a trace message
418 //
419 // Type:
420 // Positive
421 //
422 // return 0 if the test passed
423 // return 1 if the test failed
424 //
425
426 Uint32 test15()
427 {
428 const char* METHOD_NAME = "test15";
429 Tracer::setTraceComponents("ALL");
430 Tracer::setTraceLevel(Tracer::LEVEL4);
|
431 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
432 "Test Message for Level4 in",METHOD_NAME));
|
433 mike 1.2 return(compare(FILE3,"Test Message for Level4 in test15"));
434 }
435
436 //
437 // Description:
|
438 marek 1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
439 // should log a trace message
440 //
441 // Type:
442 // Positive
443 //
444 // return 0 if the test passed
445 // return 1 if the test failed
446 //
447
448 Uint32 test15a()
449 {
450 const char* METHOD_NAME = "test15a";
451 Tracer::setTraceComponents("ALL");
452 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
453 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
454 return(compare(FILE3,"Entering method test15a"));
455 }
456
457 //
458 // Description:
459 marek 1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
460 // should log a trace message
461 //
462 // Type:
463 // Positive
464 //
465 // return 0 if the test passed
466 // return 1 if the test failed
467 //
468
469 Uint32 test15b()
470 {
471 const char* METHOD_NAME = "test15b";
472 Tracer::setTraceComponents("ALL");
473 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
474 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
475 PEG_METHOD_EXIT();
476 return(compare(FILE3,"Exiting method test15b"));
477 }
478
479 //
480 marek 1.35 // Description:
|
481 mike 1.2 // calls the setTraceComponents with null string
|
482 marek 1.35 // should not log a trace message
|
483 mike 1.2 //
484 // Type:
485 // Negative
486 //
487 // return 0 if the test passed
488 // return 1 if the test failed
489 //
490
491 Uint32 test16()
492 {
493 const char* METHOD_NAME = "test16";
|
494 marek 1.37 Tracer::setTraceComponents("ALL");
495 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
496 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,"test16 - check value");
|
497 mike 1.2 Tracer::setTraceComponents("");
498 Tracer::setTraceLevel(Tracer::LEVEL4);
|
499 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
500 "This Message should not appear in",METHOD_NAME));
|
501 marek 1.37 return(compare(FILE3,"test16 - check value"));
|
502 mike 1.2 }
503
504 //
505 // Description:
506 // calls the setTraceComponents with one valid and another invalid component
507 // should log a trace message
508 //
509 // Type:
510 // Negative
511 //
512 // return 0 if the test passed
513 // return 1 if the test failed
514 //
515
516 Uint32 test17()
517 {
518 const char* METHOD_NAME = "test17";
|
519 marek 1.37 Tracer::setTraceComponents("ALL");
520 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
521 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,"test17 - check value");
|
522 kumpf 1.3 Tracer::setTraceComponents("InvalidComp");
|
523 mike 1.2 Tracer::setTraceLevel(Tracer::LEVEL4);
|
524 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
525 "This Message should not appear in",METHOD_NAME));
|
526 marek 1.37 return(compare(FILE3,"test17 - check value"));
|
527 mike 1.2 }
|
528 kumpf 1.3 //
529 // Description:
530 // calls the _traceBuffer call
531 // should log a trace message
532 //
533 // Type:
534 // Positive
535 //
536 // return 0 if the test passed
537 // return 1 if the test failed
538 //
539
540 Uint32 test18()
541 {
542 const char* METHOD_NAME = "test18";
543 Tracer::setTraceComponents("Config,InvalidComp");
544 Tracer::setTraceLevel(Tracer::LEVEL4);
|
545 marek 1.33 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
|
546 marek 1.28 "This Message should appear in");
547 return(compare(FILE3,"This Message should appear in"));
|
548 kumpf 1.3 }
|
549 mike 1.2
|
550 kumpf 1.4 //
551 // Description:
552 // Trace a string.
|
553 marek 1.33 // Calls the PEG_TRACE macro
|
554 kumpf 1.4 // should log a trace message
555 //
556 // Type:
557 // Positive
558 //
559 // return 0 if the test passed
560 // return 1 if the test failed
561 //
562
563 Uint32 test20()
564 {
565 const char* METHOD_NAME = "test20";
566 Tracer::setTraceFile(FILE4);
567 Tracer::setTraceComponents("ALL");
568 Tracer::setTraceLevel(Tracer::LEVEL4);
569
570 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
|
571 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,
572 "Test Message for Level4 in test20"));
|
573 kumpf 1.4 return(compare(FILE4,"Test Message for Level4 in test20"));
574 }
575
576 //
577 // Description:
578 // Trace a CIMException.
579 // Calls the traceCIMException() method
580 // should log a trace message
581 //
582 // Type:
583 // Positive
584 //
585 // return 0 if the test passed
586 // return 1 if the test failed
587 //
588
589 Uint32 test21()
590 {
591 const char* METHOD_NAME = "test21";
592 Tracer::setTraceFile(FILE4);
593 Tracer::setTraceComponents("ALL");
594 kumpf 1.4 Tracer::setTraceLevel(Tracer::LEVEL4);
595
596 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
597
598 // test tracing CIMException
599 try
600 {
601 throw PEGASUS_CIM_EXCEPTION(
602 CIM_ERR_NOT_SUPPORTED,
603 "CIM Exception Message for Level4 in test21.");
604 }
|
605 kumpf 1.12 catch (CIMException& e)
|
606 kumpf 1.4 {
607 Tracer::traceCIMException(TRC_CONFIG,Tracer::LEVEL4, e);
608 }
609
610 return 0;
611 }
612
613 //
614 // Description:
615 // Trace a string using macro.
616 // should log a trace message
617 //
618 // Type:
619 // Positive
620 //
621 // return 0 if the test passed
622 // return 1 if the test failed
623 //
624 Uint32 test22()
625 {
626 const char* METHOD_NAME = "test22";
627 kumpf 1.4 Tracer::setTraceFile(FILE4);
628 Tracer::setTraceComponents("ALL");
629 Tracer::setTraceLevel(Tracer::LEVEL4);
630
631 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
632
|
633 karl 1.29 PEG_TRACE_STRING(TRC_CONFIG,Tracer::LEVEL4,
|
634 marek 1.33 String("Test message for Level4 in test22."));
|
635 kumpf 1.4
636 return(compare(FILE4,"Test message for Level4 in test22."));
637 }
638
|
639 marek 1.28 //
640 // Description:
641 // Trace a character string using macro.
642 // should log a trace message
643 //
644 // Type:
645 // Positive
646 //
647 // return 0 if the test passed
648 // return 1 if the test failed
649 //
650 Uint32 test23()
651 {
652 const char* METHOD_NAME = "test23";
653 Tracer::setTraceFile(FILE4);
654 Tracer::setTraceComponents("ALL");
655 Tracer::setTraceLevel(Tracer::LEVEL4);
656
657 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
658
|
659 karl 1.29 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
660 "Test message for Level4 in test23.");
|
661 marek 1.28
662 return(compare(FILE4,"Test message for Level4 in test23."));
663 }
664
|
665 r.kieninger 1.36 //
666 // Description:
667 // Change traceFacility to Logger
668 // No more trace messages should be written
669 //
670 // Type:
671 // Negative
672 //
673 // return 0 if the test passed
674 // return 1 if the test failed
675 //
676 Uint32 test24()
677 {
678 const char* METHOD_NAME = "test24";
679 Tracer::setTraceFacility("Log");
680 Tracer::setTraceFile(FILE4);
681 Tracer::setTraceComponents("ALL");
682 Tracer::setTraceLevel(Tracer::LEVEL4);
683
684 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
685 "Test message for traceFacility=Log in test24.");
686 r.kieninger 1.36
687 return(compare(FILE4,"Test message for Level4 in test23."));
688 }
689
690 //
691 // Description:
692 // Change traceFacility back to File
693 // Trace messages should be written again
694 //
695 // Type:
696 // Positive
697 //
698 // return 0 if the test passed
699 // return 1 if the test failed
700 //
701 Uint32 test25()
702 {
703 const char* METHOD_NAME = "test25";
704 Tracer::setTraceFacility("File");
705 Tracer::setTraceFile(FILE4);
706 Tracer::setTraceComponents("ALL");
707 r.kieninger 1.36 Tracer::setTraceLevel(Tracer::LEVEL4);
708
709 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
710 "Test message for traceFacility=File in test25.");
711
712 return(compare(FILE4,"Test message for traceFacility=File in test25."));
713 }
714
|
715 sushma.fernandes 1.30 //
716 // Description:
717 // Test the getHTTPRequestMessage method.
718 //
719 // Type:
720 // Positive
721 // Tests with a HTTP Request without a basic authorization header.
722 // Message is written to trace file without any changes.
723 //
724 // return 0 if the test passed
725 // return 1 if the test failed
726 //
|
727 r.kieninger 1.36 Uint32 test26()
|
728 sushma.fernandes 1.30 {
729 Tracer::setTraceFile(FILE4);
730 Tracer::setTraceComponents("xmlio");
731 Tracer::setTraceLevel(Tracer::LEVEL2);
732
733 Uint32 queueId = 18;
734 CIMPropertyList propertyList;
735 Buffer params;
736 AcceptLanguageList al;
737 ContentLanguageList cl;
738
739 XmlWriter::appendClassNameIParameter(
740 params, "ClassName", CIMName("testclass"));
741 Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
742 "localhost",
743 CIMNamespaceName("test/cimv2"),
744 CIMName ("EnumerateInstanceNames"),
745 "12345",
746 HTTP_METHOD__POST,
747 "Basic: Authorization AAAAA",
748 al,
749 sushma.fernandes 1.30 cl,
750 params);
751
752 SharedArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(
753 buffer));
754
755 PEG_TRACE((
756 TRC_XML_IO,
757 Tracer::LEVEL2,
758 "<!-- Request: queue id: %u -->\n%s",
759 queueId,
760 reqMsg.get()));
761
762 return(compare(FILE4, buffer.getData()));
763 }
764
765 //
766 // Description:
767 // Test the getHTTPRequestMessage method.
768 //
769 // Type:
770 sushma.fernandes 1.30 // Positive
771 // Tests with a HTTP Request that contains a Basic authorization header.
772 // The user/password info in the message is suppressed before writing it to
773 // the trace file.
774 //
775 // return 0 if the test passed
776 // return 1 if the test failed
777 //
|
778 r.kieninger 1.36 Uint32 test27()
|
779 sushma.fernandes 1.30 {
780 Tracer::setTraceFile(FILE4);
781 Tracer::setTraceComponents("xmlio");
782 Tracer::setTraceLevel(Tracer::LEVEL2);
783
784 Uint32 queueId = 18;
785 CIMPropertyList propertyList;
786 Buffer params;
787 AcceptLanguageList al;
788 ContentLanguageList cl;
789 String authHeader = "Authorization: Basic ABCDEABCDE==";
790 String MSGID = "32423424";
791
792 XmlWriter::appendClassNameIParameter(
793 params,
794 "ClassName",
795 CIMName("testclass"));
796 Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
797 "localhost",
798 CIMNamespaceName("test/cimv2"),
799 CIMName ("EnumerateInstanceNames"),
800 sushma.fernandes 1.30 MSGID,
801 HTTP_METHOD__POST,
802 authHeader,
803 al,
804 cl,
805 params);
806
807 PEG_TRACE((
808 TRC_XML_IO,
809 Tracer::LEVEL2,
810 "<!-- Request: queue id: %u -->\n%s",
811 queueId,
812 Tracer::getHTTPRequestMessage(
813 buffer).get()));
814
815 String testStr(buffer.getData());
816 Uint32 pos = testStr.find("ABCDEABCDE==");
817
818 for ( Uint32 i = pos; i < pos+strlen("ABCDEABCDE=="); i++)
819 testStr[i] = 'X';
820
821 sushma.fernandes 1.30 return(compare(FILE4, testStr.getCString()));
822 }
823
|
824 karl 1.7 int main(int argc, char** argv)
|
825 mike 1.2 {
826
827 // Execute the tests only if trace calls are included
828
829 #ifdef PEGASUS_REMOVE_TRACE
|
830 karl 1.7 cout << argv[0] << " +++++ passed all tests" << endl;
|
831 mike 1.2 return 0;
832 #else
|
833 kumpf 1.11
834 const char* tmpDir = getenv ("PEGASUS_TMP");
835 if (tmpDir == NULL)
836 {
837 tmpDir = ".";
838 }
839 String f1 (tmpDir);
|
840 kumpf 1.13 f1.append("/testtracer1.trace");
|
841 kumpf 1.14 FILE1 = f1.getCString();
|
842 kumpf 1.11 String f2 (tmpDir);
|
843 kumpf 1.13 f2.append("/testtracer2.trace");
|
844 kumpf 1.14 FILE2 = f2.getCString();
|
845 kumpf 1.11 String f3 (tmpDir);
|
846 kumpf 1.13 f3.append("/testtracer3.trace");
|
847 kumpf 1.14 FILE3 = f3.getCString();
|
848 kumpf 1.11 String f4 (tmpDir);
|
849 kumpf 1.13 f4.append("/testtracer4.trace");
|
850 kumpf 1.14 FILE4 = f4.getCString();
|
851 kumpf 1.11
|
852 mike 1.2 System::removeFile(FILE1);
853 System::removeFile(FILE2);
854 System::removeFile(FILE3);
|
855 kumpf 1.4 System::removeFile(FILE4);
|
856 kumpf 1.34 if (test1() != 0)
|
857 mike 1.2 {
858 cout << "Tracer test (test1) failed" << endl;
859 exit(1);
860 }
|
861 kumpf 1.34 if (test2() != 0)
|
862 mike 1.2 {
863 cout << "Tracer test (test2) failed" << endl;
864 exit(1);
865 }
|
866 kumpf 1.34 if (test3() != 0)
|
867 mike 1.2 {
868 cout << "Tracer test (test3) failed" << endl;
869 exit(1);
870 }
871 if (test4() != 0)
872 {
873 cout << "Tracer test (test4) failed" << endl;
874 exit(1);
875 }
876 if (test5() != 0)
877 {
878 cout << "Tracer test (test5) failed" << endl;
879 exit(1);
880 }
881 if (test6() != 0)
882 {
883 cout << "Tracer test (test6) failed" << endl;
884 exit(1);
885 }
886 if (test7() != 0)
887 {
888 mike 1.2 cout << "Tracer test (test7) failed" << endl;
889 exit(1);
890 }
891 if (test9() != 0)
892 {
893 cout << "Tracer test (test9) failed" << endl;
894 exit(1);
895 }
|
896 karl 1.27 /***************************
897 Test 10 bypassed when tests changed to
898 use macros. It did an invalid call which is
899 not possible with macros
900
|
901 mike 1.2 if (test10() != 0)
902 {
903 cout << "Tracer test (test10) failed" << endl;
904 exit(1);
905 }
|
906 karl 1.27 ******************************/
|
907 mike 1.2 if (test11() != 0)
908 {
909 cout << "Tracer test (test11) failed" << endl;
910 exit(1);
911 }
912 if (test12() != 0)
913 {
914 cout << "Tracer test (test12) failed" << endl;
915 exit(1);
916 }
917 if (test13() != 0)
918 {
919 cout << "Tracer test (test13) failed" << endl;
920 exit(1);
921 }
922 if (test14() != 0)
923 {
924 cout << "Tracer test (test14) failed" << endl;
925 exit(1);
926 }
927 if (test15() != 0)
928 mike 1.2 {
929 cout << "Tracer test (test15) failed" << endl;
930 exit(1);
931 }
|
932 marek 1.37 # ifndef PEGASUS_REMOVE_METHODTRACE
|
933 marek 1.35 if (test15a() != 0)
934 {
935 cout << "Tracer test (test15a) failed" << endl;
936 exit(1);
937 }
938 if (test15b() != 0)
939 {
940 cout << "Tracer test (test15b) failed" << endl;
941 exit(1);
942 }
|
943 marek 1.37 # endif
|
944 mike 1.2 if (test16() != 0)
945 {
946 cout << "Tracer test (test16) failed" << endl;
|
947 kumpf 1.3 exit(1);
948 }
949 if (test17() != 0)
950 {
951 cout << "Tracer test (test17) failed" << endl;
952 exit(1);
953 }
954 if (test18() != 0)
955 {
956 cout << "Tracer test (test18) failed" << endl;
957 exit(1);
958 }
|
959 kumpf 1.4 if (test20() != 0)
960 {
961 cout << "Tracer test (test20) failed" << endl;
962 exit(1);
963 }
964 if (test21() != 0)
965 {
966 cout << "Tracer test (test21) failed" << endl;
967 exit(1);
968 }
969 if (test22() != 0)
970 {
971 cout << "Tracer test (test22) failed" << endl;
972 exit(1);
973 }
|
974 marek 1.28 if (test23() != 0)
975 {
976 cout << "Tracer test (test23) failed" << endl;
977 exit(1);
978 }
|
979 sushma.fernandes 1.30 if (test24() != 0)
980 {
981 cout << "Tracer test (test24) failed" << endl;
982 exit(1);
983 }
984
985 if (test25() != 0)
986 {
987 cout << "Tracer test (test25) failed" << endl;
988 exit(1);
989 }
|
990 r.kieninger 1.36 if (test26() != 0)
991 {
992 cout << "Tracer test (test26) failed" << endl;
993 exit(1);
994 }
995
996 if (test27() != 0)
997 {
998 cout << "Tracer test (test27) failed" << endl;
999 exit(1);
1000 }
|
1001 sushma.fernandes 1.30
|
1002 karl 1.7 cout << argv[0] << " +++++ passed all tests" << endl;
|
1003 mike 1.2 System::removeFile(FILE1);
1004 System::removeFile(FILE2);
1005 System::removeFile(FILE3);
|
1006 kumpf 1.4 System::removeFile(FILE4);
|
1007 mike 1.2 return 0;
1008 #endif
1009 }
|