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.35 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
|
207 mike 1.2 Tracer::setTraceComponents("Config");
|
208 kumpf 1.10 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
209 mike 1.2 return(compare(FILE1,"Entering method test4"));
210 }
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 PEG_METHOD_EXIT();
|
230 mike 1.2 return(compare(FILE1,"Entering method test4"));
231 }
232
233 //
234 // Description:
235 // Trace level is set to LEVEL 2 and logs a LEVEL 4 message
236 // should not log a trace message
237 //
238 // Type:
239 // Negative
240 //
241 // return 0 if the test passed
242 // return 1 if the test failed
243 //
244
245 Uint32 test6()
246 {
247 const char* METHOD_NAME = "test6";
248 Tracer::setTraceComponents("Config");
249 Tracer::setTraceLevel(Tracer::LEVEL2);
|
250 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
251 "Test Message for Level2 in",METHOD_NAME));
252 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
253 "Test Message for Level2 in",METHOD_NAME));
254 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s",
255 "This Message should not appear"));
|
256 mike 1.2 return(compare(FILE1,"Test Message for Level2 in test6"));
257 }
258
259 //
260 // Description:
261 // Trace level is set to an invalid level
262 // should not log a trace message
263 //
264 // Type:
265 // Negative
266 //
267 // return 0 if the test passed
268 // return 1 if the test failed
269 //
270 Uint32 test7()
271 {
272 const char* METHOD_NAME = "test7";
273 Tracer::setTraceLevel(100);
|
274 karl 1.27 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
275 PEG_METHOD_EXIT();
|
276 mike 1.2 return(compare(FILE1,"Test Message for Level2 in test6"));
277 }
278
279 //
280 // Description:
281 // Changes the trace file to FILE2
282 //
283 // Type:
284 // Positive
285 //
286 // return 0 if the test passed
287 // return 1 if the test failed
288 //
289 Uint32 test9()
290 {
291 const char* METHOD_NAME = "test9";
292 Tracer::setTraceLevel(Tracer::LEVEL3);
293 Tracer::setTraceFile(FILE2);
294
|
295 kumpf 1.10 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
|
296 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
297 "Test Message for Level3 in",METHOD_NAME));
|
298 mike 1.2 return(compare(FILE2,"Test Message for Level3 in test9"));
299 }
300
301 //
302 // Description:
303 // Passes invalid component in the trace call
304 // should not log a trace message
305 //
306 // Type:
307 // Negative
308 //
309 // return 0 if the test passed
310 // return 1 if the test failed
311 //
|
312 marek 1.35 // This test not required with change to
|
313 karl 1.27 // use and test macros only.
|
314 mike 1.2
315 Uint32 test10()
316 {
317 const char* METHOD_NAME = "test10";
318 Tracer::setTraceComponents("ALL");
|
319 karl 1.27 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
320 PEG_METHOD_EXIT();
|
321 mike 1.2 return(compare(FILE2,"Test Message for Level3 in test9"));
322 }
323
324 //
325 // Description:
|
326 marek 1.35 // Trace is set to level 0
327 // should not log a trace message
|
328 mike 1.2 //
329 // Type:
|
330 marek 1.35 // Negative
|
331 mike 1.2 //
332 // return 0 if the test passed
333 // return 1 if the test failed
334 //
335
336 Uint32 test11()
337 {
338 const char* METHOD_NAME = "test11";
339 Tracer::setTraceComponents("ALL");
|
340 marek 1.35 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL0);
341 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
342 "Test Message for Level0 in",METHOD_NAME));
343 return(compare(FILE2,"Test Message for Level3 in test9"));
|
344 mike 1.2 }
345
346 //
347 // Description:
348 // Implements trace call for Tracer::Level1
349 // should log a trace message
350 //
351 // Type:
352 // Positive
353 //
354 // return 0 if the test passed
355 // return 1 if the test failed
356 //
357
358 Uint32 test12()
359 {
360 const char* METHOD_NAME = "test12";
361 Tracer::setTraceComponents("ALL");
362 Tracer::setTraceLevel(Tracer::LEVEL4);
|
363 marek 1.35 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
364 "Test Message for Level1 in",METHOD_NAME));
365 return(compare(FILE2,"Test Message for Level1 in test12"));
|
366 mike 1.2 }
367
368 //
369 // Description:
370 // Implements trace call for Tracer::Level2
371 // should log a trace message
372 //
373 // Type:
374 // Positive
375 //
376 // return 0 if the test passed
377 // return 1 if the test failed
378 //
379
380 Uint32 test13()
381 {
382 const char* METHOD_NAME = "test13";
383 Tracer::setTraceComponents("ALL");
384 Tracer::setTraceLevel(Tracer::LEVEL4);
|
385 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
386 "Test Message for Level2 in",METHOD_NAME));
|
387 mike 1.2 return(compare(FILE2,"Test Message for Level2 in test13"));
388 }
389
390 //
391 // Description:
392 // Implements trace call for Tracer::Level3
393 // should log a trace message
394 //
395 // Type:
396 // Positive
397 //
398 // return 0 if the test passed
399 // return 1 if the test failed
400 //
401
402 Uint32 test14()
403 {
404 const char* METHOD_NAME = "test14";
405 Tracer::setTraceComponents("ALL");
406 Tracer::setTraceLevel(Tracer::LEVEL4);
407 Tracer::setTraceFile(FILE3);
|
408 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
409 "Test Message for Level3 in",METHOD_NAME));
|
410 mike 1.2 return(compare(FILE3,"Test Message for Level3 in test14"));
411 }
412
413 //
414 // Description:
415 // Implements trace call for Tracer::Level4
416 // should log a trace message
417 //
418 // Type:
419 // Positive
420 //
421 // return 0 if the test passed
422 // return 1 if the test failed
423 //
424
425 Uint32 test15()
426 {
427 const char* METHOD_NAME = "test15";
428 Tracer::setTraceComponents("ALL");
429 Tracer::setTraceLevel(Tracer::LEVEL4);
|
430 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
431 "Test Message for Level4 in",METHOD_NAME));
|
432 mike 1.2 return(compare(FILE3,"Test Message for Level4 in test15"));
433 }
434
435 //
436 // Description:
|
437 marek 1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
438 // should log a trace message
439 //
440 // Type:
441 // Positive
442 //
443 // return 0 if the test passed
444 // return 1 if the test failed
445 //
446
447 Uint32 test15a()
448 {
449 const char* METHOD_NAME = "test15a";
450 Tracer::setTraceComponents("ALL");
451 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
452 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
453 return(compare(FILE3,"Entering method test15a"));
454 }
455
456 //
457 // Description:
458 marek 1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
459 // should log a trace message
460 //
461 // Type:
462 // Positive
463 //
464 // return 0 if the test passed
465 // return 1 if the test failed
466 //
467
468 Uint32 test15b()
469 {
470 const char* METHOD_NAME = "test15b";
471 Tracer::setTraceComponents("ALL");
472 Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
473 PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
474 PEG_METHOD_EXIT();
475 return(compare(FILE3,"Exiting method test15b"));
476 }
477
478 //
479 marek 1.35 // Description:
|
480 mike 1.2 // calls the setTraceComponents with null string
|
481 marek 1.35 // should not log a trace message
|
482 mike 1.2 //
483 // Type:
484 // Negative
485 //
486 // return 0 if the test passed
487 // return 1 if the test failed
488 //
489
490 Uint32 test16()
491 {
492 const char* METHOD_NAME = "test16";
493 Tracer::setTraceComponents("");
494 Tracer::setTraceLevel(Tracer::LEVEL4);
|
495 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
496 "This Message should not appear in",METHOD_NAME));
|
497 marek 1.35 return(compare(FILE3,"Exiting method test15b"));
|
498 mike 1.2 }
499
500 //
501 // Description:
502 // calls the setTraceComponents with one valid and another invalid component
503 // should log a trace message
504 //
505 // Type:
506 // Negative
507 //
508 // return 0 if the test passed
509 // return 1 if the test failed
510 //
511
512 Uint32 test17()
513 {
514 const char* METHOD_NAME = "test17";
|
515 kumpf 1.3 Tracer::setTraceComponents("InvalidComp");
|
516 mike 1.2 Tracer::setTraceLevel(Tracer::LEVEL4);
|
517 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
518 "This Message should not appear in",METHOD_NAME));
|
519 marek 1.35 return(compare(FILE3,"Exiting method test15b"));
|
520 mike 1.2 }
|
521 kumpf 1.3 //
522 // Description:
523 // calls the _traceBuffer call
524 // should log a trace message
525 //
526 // Type:
527 // Positive
528 //
529 // return 0 if the test passed
530 // return 1 if the test failed
531 //
532
533 Uint32 test18()
534 {
535 const char* METHOD_NAME = "test18";
536 Tracer::setTraceComponents("Config,InvalidComp");
537 Tracer::setTraceLevel(Tracer::LEVEL4);
|
538 marek 1.33 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
|
539 marek 1.28 "This Message should appear in");
540 return(compare(FILE3,"This Message should appear in"));
|
541 kumpf 1.3 }
|
542 mike 1.2
|
543 kumpf 1.4 //
544 // Description:
545 // Trace a string.
|
546 marek 1.33 // Calls the PEG_TRACE macro
|
547 kumpf 1.4 // should log a trace message
548 //
549 // Type:
550 // Positive
551 //
552 // return 0 if the test passed
553 // return 1 if the test failed
554 //
555
556 Uint32 test20()
557 {
558 const char* METHOD_NAME = "test20";
559 Tracer::setTraceFile(FILE4);
560 Tracer::setTraceComponents("ALL");
561 Tracer::setTraceLevel(Tracer::LEVEL4);
562
563 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
|
564 marek 1.33 PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,
565 "Test Message for Level4 in test20"));
|
566 kumpf 1.4 return(compare(FILE4,"Test Message for Level4 in test20"));
567 }
568
569 //
570 // Description:
571 // Trace a CIMException.
572 // Calls the traceCIMException() method
573 // should log a trace message
574 //
575 // Type:
576 // Positive
577 //
578 // return 0 if the test passed
579 // return 1 if the test failed
580 //
581
582 Uint32 test21()
583 {
584 const char* METHOD_NAME = "test21";
585 Tracer::setTraceFile(FILE4);
586 Tracer::setTraceComponents("ALL");
587 kumpf 1.4 Tracer::setTraceLevel(Tracer::LEVEL4);
588
589 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
590
591 // test tracing CIMException
592 try
593 {
594 throw PEGASUS_CIM_EXCEPTION(
595 CIM_ERR_NOT_SUPPORTED,
596 "CIM Exception Message for Level4 in test21.");
597 }
|
598 kumpf 1.12 catch (CIMException& e)
|
599 kumpf 1.4 {
600 Tracer::traceCIMException(TRC_CONFIG,Tracer::LEVEL4, e);
601 }
602
603 return 0;
604 }
605
606 //
607 // Description:
608 // Trace a string using macro.
609 // should log a trace message
610 //
611 // Type:
612 // Positive
613 //
614 // return 0 if the test passed
615 // return 1 if the test failed
616 //
617 Uint32 test22()
618 {
619 const char* METHOD_NAME = "test22";
620 kumpf 1.4 Tracer::setTraceFile(FILE4);
621 Tracer::setTraceComponents("ALL");
622 Tracer::setTraceLevel(Tracer::LEVEL4);
623
624 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
625
|
626 karl 1.29 PEG_TRACE_STRING(TRC_CONFIG,Tracer::LEVEL4,
|
627 marek 1.33 String("Test message for Level4 in test22."));
|
628 kumpf 1.4
629 return(compare(FILE4,"Test message for Level4 in test22."));
630 }
631
|
632 marek 1.28 //
633 // Description:
634 // Trace a character string using macro.
635 // should log a trace message
636 //
637 // Type:
638 // Positive
639 //
640 // return 0 if the test passed
641 // return 1 if the test failed
642 //
643 Uint32 test23()
644 {
645 const char* METHOD_NAME = "test23";
646 Tracer::setTraceFile(FILE4);
647 Tracer::setTraceComponents("ALL");
648 Tracer::setTraceLevel(Tracer::LEVEL4);
649
650 PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
651
|
652 karl 1.29 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
653 "Test message for Level4 in test23.");
|
654 marek 1.28
655 return(compare(FILE4,"Test message for Level4 in test23."));
656 }
657
|
658 r.kieninger 1.36 //
659 // Description:
660 // Change traceFacility to Logger
661 // No more trace messages should be written
662 //
663 // Type:
664 // Negative
665 //
666 // return 0 if the test passed
667 // return 1 if the test failed
668 //
669 Uint32 test24()
670 {
671 const char* METHOD_NAME = "test24";
672 Tracer::setTraceFacility("Log");
673 Tracer::setTraceFile(FILE4);
674 Tracer::setTraceComponents("ALL");
675 Tracer::setTraceLevel(Tracer::LEVEL4);
676
677 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
678 "Test message for traceFacility=Log in test24.");
679 r.kieninger 1.36
680 return(compare(FILE4,"Test message for Level4 in test23."));
681 }
682
683 //
684 // Description:
685 // Change traceFacility back to File
686 // Trace messages should be written again
687 //
688 // Type:
689 // Positive
690 //
691 // return 0 if the test passed
692 // return 1 if the test failed
693 //
694 Uint32 test25()
695 {
696 const char* METHOD_NAME = "test25";
697 Tracer::setTraceFacility("File");
698 Tracer::setTraceFile(FILE4);
699 Tracer::setTraceComponents("ALL");
700 r.kieninger 1.36 Tracer::setTraceLevel(Tracer::LEVEL4);
701
702 PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
703 "Test message for traceFacility=File in test25.");
704
705 return(compare(FILE4,"Test message for traceFacility=File in test25."));
706 }
707
|
708 sushma.fernandes 1.30 //
709 // Description:
710 // Test the getHTTPRequestMessage method.
711 //
712 // Type:
713 // Positive
714 // Tests with a HTTP Request without a basic authorization header.
715 // Message is written to trace file without any changes.
716 //
717 // return 0 if the test passed
718 // return 1 if the test failed
719 //
|
720 r.kieninger 1.36 Uint32 test26()
|
721 sushma.fernandes 1.30 {
722 Tracer::setTraceFile(FILE4);
723 Tracer::setTraceComponents("xmlio");
724 Tracer::setTraceLevel(Tracer::LEVEL2);
725
726 Uint32 queueId = 18;
727 CIMPropertyList propertyList;
728 Buffer params;
729 AcceptLanguageList al;
730 ContentLanguageList cl;
731
732 XmlWriter::appendClassNameIParameter(
733 params, "ClassName", CIMName("testclass"));
734 Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
735 "localhost",
736 CIMNamespaceName("test/cimv2"),
737 CIMName ("EnumerateInstanceNames"),
738 "12345",
739 HTTP_METHOD__POST,
740 "Basic: Authorization AAAAA",
741 al,
742 sushma.fernandes 1.30 cl,
743 params);
744
745 SharedArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(
746 buffer));
747
748 PEG_TRACE((
749 TRC_XML_IO,
750 Tracer::LEVEL2,
751 "<!-- Request: queue id: %u -->\n%s",
752 queueId,
753 reqMsg.get()));
754
755 return(compare(FILE4, buffer.getData()));
756 }
757
758 //
759 // Description:
760 // Test the getHTTPRequestMessage method.
761 //
762 // Type:
763 sushma.fernandes 1.30 // Positive
764 // Tests with a HTTP Request that contains a Basic authorization header.
765 // The user/password info in the message is suppressed before writing it to
766 // the trace file.
767 //
768 // return 0 if the test passed
769 // return 1 if the test failed
770 //
|
771 r.kieninger 1.36 Uint32 test27()
|
772 sushma.fernandes 1.30 {
773 Tracer::setTraceFile(FILE4);
774 Tracer::setTraceComponents("xmlio");
775 Tracer::setTraceLevel(Tracer::LEVEL2);
776
777 Uint32 queueId = 18;
778 CIMPropertyList propertyList;
779 Buffer params;
780 AcceptLanguageList al;
781 ContentLanguageList cl;
782 String authHeader = "Authorization: Basic ABCDEABCDE==";
783 String MSGID = "32423424";
784
785 XmlWriter::appendClassNameIParameter(
786 params,
787 "ClassName",
788 CIMName("testclass"));
789 Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
790 "localhost",
791 CIMNamespaceName("test/cimv2"),
792 CIMName ("EnumerateInstanceNames"),
793 sushma.fernandes 1.30 MSGID,
794 HTTP_METHOD__POST,
795 authHeader,
796 al,
797 cl,
798 params);
799
800 PEG_TRACE((
801 TRC_XML_IO,
802 Tracer::LEVEL2,
803 "<!-- Request: queue id: %u -->\n%s",
804 queueId,
805 Tracer::getHTTPRequestMessage(
806 buffer).get()));
807
808 String testStr(buffer.getData());
809 Uint32 pos = testStr.find("ABCDEABCDE==");
810
811 for ( Uint32 i = pos; i < pos+strlen("ABCDEABCDE=="); i++)
812 testStr[i] = 'X';
813
814 sushma.fernandes 1.30 return(compare(FILE4, testStr.getCString()));
815 }
816
|
817 karl 1.7 int main(int argc, char** argv)
|
818 mike 1.2 {
819
820 // Execute the tests only if trace calls are included
821
822 #ifdef PEGASUS_REMOVE_TRACE
|
823 karl 1.7 cout << argv[0] << " +++++ passed all tests" << endl;
|
824 mike 1.2 return 0;
825 #else
|
826 kumpf 1.11
827 const char* tmpDir = getenv ("PEGASUS_TMP");
828 if (tmpDir == NULL)
829 {
830 tmpDir = ".";
831 }
832 String f1 (tmpDir);
|
833 kumpf 1.13 f1.append("/testtracer1.trace");
|
834 kumpf 1.14 FILE1 = f1.getCString();
|
835 kumpf 1.11 String f2 (tmpDir);
|
836 kumpf 1.13 f2.append("/testtracer2.trace");
|
837 kumpf 1.14 FILE2 = f2.getCString();
|
838 kumpf 1.11 String f3 (tmpDir);
|
839 kumpf 1.13 f3.append("/testtracer3.trace");
|
840 kumpf 1.14 FILE3 = f3.getCString();
|
841 kumpf 1.11 String f4 (tmpDir);
|
842 kumpf 1.13 f4.append("/testtracer4.trace");
|
843 kumpf 1.14 FILE4 = f4.getCString();
|
844 kumpf 1.11
|
845 mike 1.2 System::removeFile(FILE1);
846 System::removeFile(FILE2);
847 System::removeFile(FILE3);
|
848 kumpf 1.4 System::removeFile(FILE4);
|
849 kumpf 1.34 if (test1() != 0)
|
850 mike 1.2 {
851 cout << "Tracer test (test1) failed" << endl;
852 exit(1);
853 }
|
854 kumpf 1.34 if (test2() != 0)
|
855 mike 1.2 {
856 cout << "Tracer test (test2) failed" << endl;
857 exit(1);
858 }
|
859 kumpf 1.34 if (test3() != 0)
|
860 mike 1.2 {
861 cout << "Tracer test (test3) failed" << endl;
862 exit(1);
863 }
864 if (test4() != 0)
865 {
866 cout << "Tracer test (test4) failed" << endl;
867 exit(1);
868 }
869 if (test5() != 0)
870 {
871 cout << "Tracer test (test5) failed" << endl;
872 exit(1);
873 }
874 if (test6() != 0)
875 {
876 cout << "Tracer test (test6) failed" << endl;
877 exit(1);
878 }
879 if (test7() != 0)
880 {
881 mike 1.2 cout << "Tracer test (test7) failed" << endl;
882 exit(1);
883 }
884 if (test9() != 0)
885 {
886 cout << "Tracer test (test9) failed" << endl;
887 exit(1);
888 }
|
889 karl 1.27 /***************************
890 Test 10 bypassed when tests changed to
891 use macros. It did an invalid call which is
892 not possible with macros
893
|
894 mike 1.2 if (test10() != 0)
895 {
896 cout << "Tracer test (test10) failed" << endl;
897 exit(1);
898 }
|
899 karl 1.27 ******************************/
|
900 mike 1.2 if (test11() != 0)
901 {
902 cout << "Tracer test (test11) failed" << endl;
903 exit(1);
904 }
905 if (test12() != 0)
906 {
907 cout << "Tracer test (test12) failed" << endl;
908 exit(1);
909 }
910 if (test13() != 0)
911 {
912 cout << "Tracer test (test13) failed" << endl;
913 exit(1);
914 }
915 if (test14() != 0)
916 {
917 cout << "Tracer test (test14) failed" << endl;
918 exit(1);
919 }
920 if (test15() != 0)
921 mike 1.2 {
922 cout << "Tracer test (test15) failed" << endl;
923 exit(1);
924 }
|
925 marek 1.35 if (test15a() != 0)
926 {
927 cout << "Tracer test (test15a) failed" << endl;
928 exit(1);
929 }
930 if (test15b() != 0)
931 {
932 cout << "Tracer test (test15b) failed" << endl;
933 exit(1);
934 }
|
935 mike 1.2 if (test16() != 0)
936 {
937 cout << "Tracer test (test16) failed" << endl;
|
938 kumpf 1.3 exit(1);
939 }
940 if (test17() != 0)
941 {
942 cout << "Tracer test (test17) failed" << endl;
943 exit(1);
944 }
945 if (test18() != 0)
946 {
947 cout << "Tracer test (test18) failed" << endl;
948 exit(1);
949 }
|
950 kumpf 1.4 if (test20() != 0)
951 {
952 cout << "Tracer test (test20) failed" << endl;
953 exit(1);
954 }
955 if (test21() != 0)
956 {
957 cout << "Tracer test (test21) failed" << endl;
958 exit(1);
959 }
960 if (test22() != 0)
961 {
962 cout << "Tracer test (test22) failed" << endl;
963 exit(1);
964 }
|
965 marek 1.28 if (test23() != 0)
966 {
967 cout << "Tracer test (test23) failed" << endl;
968 exit(1);
969 }
|
970 sushma.fernandes 1.30 if (test24() != 0)
971 {
972 cout << "Tracer test (test24) failed" << endl;
973 exit(1);
974 }
975
976 if (test25() != 0)
977 {
978 cout << "Tracer test (test25) failed" << endl;
979 exit(1);
980 }
|
981 r.kieninger 1.36 if (test26() != 0)
982 {
983 cout << "Tracer test (test26) failed" << endl;
984 exit(1);
985 }
986
987 if (test27() != 0)
988 {
989 cout << "Tracer test (test27) failed" << endl;
990 exit(1);
991 }
|
992 sushma.fernandes 1.30
|
993 karl 1.7 cout << argv[0] << " +++++ passed all tests" << endl;
|
994 mike 1.2 System::removeFile(FILE1);
995 System::removeFile(FILE2);
996 System::removeFile(FILE3);
|
997 kumpf 1.4 System::removeFile(FILE4);
|
998 mike 1.2 return 0;
999 #endif
1000 }
|