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

  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                       // Trace files for test purposes
 50 kumpf            1.11 // Will be created in the $(PEGASUS_TMP) directory, or if not set,
 51                       // in the current directory
 52 kumpf            1.15 CString FILE1;
 53                       CString FILE2;
 54                       CString FILE3;
 55                       CString FILE4;
 56 mike             1.2  
 57                       // 
 58                       // Reads the last trace message from a given trace file and compares the 
 59                       // given string with the string read from file
 60                       //
 61                       // return 0 if the strings match
 62                       // return 1 if the strings do not match
 63                       //
 64 kumpf            1.31 Uint32 compare(const char* fileName, const char* expectedMessage)
 65 mike             1.2  {
 66 kumpf            1.31     int expectedMessageLength = strlen(expectedMessage);
 67                       
 68                           // Compute the size of the message in the trace file.  Include the final
 69                           // EOL character added by the Tracer.  This size will be used to seek
 70                           // from the end of the file back to the beginning of the trace message.
 71                           int seekBytes = expectedMessageLength + 1;
 72                       
 73                       #if defined(PEGASUS_OS_TYPE_WINDOWS)
 74                           // Windows converts all '\n' characters to "\r\n" sequences in the trace
 75                           // file.  Increase the seekBytes by the number of '\r' characters added
 76                           // when the message is written to the file.
 77                           for (const char* newlineChar = expectedMessage;
 78                                ((newlineChar = strchr(newlineChar, '\n')) != 0);
 79                                newlineChar++)
 80                           {
 81                               seekBytes++;
 82                           }
 83                       
 84                           // Count the '\r' character added with the final '\n' written by the Tracer
 85                           seekBytes++;
 86                       #endif
 87 kumpf            1.31 
 88                           AutoArrayPtr<char> actualMessage(new char[expectedMessageLength + 1]);
 89                       
 90                           // Read the trace message from the file, minus the message prefix and
 91                           // minus the trailing newline.
 92 mike             1.2      fstream file;
 93 kumpf            1.31     file.open(fileName, fstream::in);
 94 mike             1.2      if (!file.good())
 95                           {
 96 kumpf            1.31         return 1;
 97 mike             1.2      }
 98 kumpf            1.31     file.seekg(-seekBytes, fstream::end);
 99                           file.read(actualMessage.get(), expectedMessageLength);
100                           file.close();
101                           actualMessage[expectedMessageLength] = 0;
102                       
103                           // Compare the expected and actual messages
104                           Uint32 retCode = strcmp(expectedMessage, actualMessage.get());
105                       
106                           /* Diagnostic to determine string differences
107                           if (retCode)
108                               cout << "Compare Error: expectedMessage= \n\"" << expectedMessage <<
109                                   "\". actualMessage= \n\"" << actualMessage.get() << "\"" << endl;
110 karl             1.27     */
111                       
112 mike             1.2      return retCode;
113                       }
114                       
115                       //
116                       // Description:
117                       // Trace properties file, level and component are not set
118                       // Should not log a trace message
119                       //
120                       // Type:
121                       // Negative 
122                       //
123                       // return 0 if the test passed
124                       // return 1 if the test failed
125                       //
126                       Uint32 test1()
127                       {
128                           const char* METHOD_NAME = "test1";
129 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
130 mike             1.2      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %d",
131 karl             1.29     "This message should not appear value=",123);
132 kumpf            1.10     PEG_METHOD_EXIT();
133 mike             1.2      return(compare(FILE1,""));
134                       }
135                       
136                       //
137                       // Description:
138                       // Trace properties level and component are not set
139                       // Should not log a trace message
140                       //
141                       // Type:
142                       // Negative 
143                       //
144                       // return 0 if the test passed
145                       // return 1 if the test failed
146                       //
147                       Uint32 test2()
148                       {
149                           const char* METHOD_NAME = "test2";
150                           Tracer::setTraceFile(FILE1);
151 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
152 mike             1.2      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %d",
153 karl             1.29     "This message should not appear value=",123);
154 mike             1.2      return(compare(FILE1,"This message should not appear value=123"));
155                       }
156                       
157                       //
158                       // Description:
159                       // Trace properties component is not set
160                       // Should not log a trace message
161                       //
162                       // Type:
163                       // Negative 
164                       //
165                       // return 0 if the test passed
166                       // return 1 if the test failed
167                       //
168                       Uint32 test3()
169                       {
170                           const char* METHOD_NAME = "test3";
171                           Tracer::setTraceLevel(Tracer::LEVEL1);
172 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
173 mike             1.2      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s",
174 karl             1.29     "This message should not appear");
175 mike             1.2      return(compare(FILE1,"This message should not appear"));
176                       }
177                       
178                       //
179                       // Description:
180                       // Trace properties file, level and component are set
181                       // should log a trace message
182                       //
183                       // Type:
184                       // Positive 
185                       //
186                       // return 0 if the test passed
187                       // return 1 if the test failed
188                       //
189                       Uint32 test4()
190                       {
191                           const char* METHOD_NAME = "test4";
192                           Tracer::setTraceComponents("Config");
193 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
194 mike             1.2      return(compare(FILE1,"Entering method test4"));
195                       }
196                       
197                       //
198                       // Description:
199                       // Trace component is set to an invalid component
200                       // should not log a trace message
201                       //
202                       // Type:
203                       // Negative 
204                       //
205                       // return 0 if the test passed
206                       // return 1 if the test failed
207                       //
208                       Uint32 test5()
209                       {
210                           const char* METHOD_NAME = "test5";
211                           Tracer::setTraceComponents("Wrong Component Name");
212 karl             1.27 
213                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
214                           PEG_METHOD_EXIT();
215 mike             1.2      return(compare(FILE1,"Entering method test4"));
216                       }
217                       
218                       //
219                       // Description:
220                       // Trace level is set to LEVEL 2 and logs a LEVEL 4 message 
221                       // should not log a trace message
222                       //
223                       // Type:
224                       // Negative 
225                       //
226                       // return 0 if the test passed
227                       // return 1 if the test failed
228                       //
229                       
230                       Uint32 test6()
231                       {
232                           const char* METHOD_NAME = "test6";
233                           Tracer::setTraceComponents("Config");
234                           Tracer::setTraceLevel(Tracer::LEVEL2);
235                           Tracer::trace(TRC_CONFIG,Tracer::LEVEL2,"%s %s",
236 karl             1.29     "Test Message for Level2 in",METHOD_NAME);
237 mike             1.2      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %s",
238 karl             1.29     "Test Message for Level2 in",METHOD_NAME);
239 mike             1.2      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s",
240 karl             1.29     "This Message should not appear");
241 mike             1.2      return(compare(FILE1,"Test Message for Level2 in test6"));
242                       }
243                       
244                       //
245                       // Description:
246                       // Trace level is set to an invalid level
247                       // should not log a trace message
248                       //
249                       // Type:
250                       // Negative 
251                       //
252                       // return 0 if the test passed
253                       // return 1 if the test failed
254                       //
255                       Uint32 test7()
256                       {
257                           const char* METHOD_NAME = "test7";
258                           Tracer::setTraceLevel(100);
259 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
260                           PEG_METHOD_EXIT();
261 mike             1.2      return(compare(FILE1,"Test Message for Level2 in test6"));
262                       }
263                       
264                       //
265                       // Description:
266                       // Changes the trace file to FILE2 
267                       //
268                       // Type:
269                       // Positive 
270                       //
271                       // return 0 if the test passed
272                       // return 1 if the test failed
273                       //
274                       Uint32 test9()
275                       {
276                           const char* METHOD_NAME = "test9";
277                           Tracer::setTraceLevel(Tracer::LEVEL3);
278                           Tracer::setTraceFile(FILE2);
279                       
280 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
281 mike             1.2      Tracer::trace(TRC_CONFIG,Tracer::LEVEL3,"%s %s",
282 karl             1.29     "Test Message for Level3 in",METHOD_NAME);
283 mike             1.2      return(compare(FILE2,"Test Message for Level3 in test9"));
284                       }
285                       
286                       //
287                       // Description:
288                       // Passes invalid component in the trace call
289                       // should not log a trace message
290                       //
291                       // Type:
292                       // Negative 
293                       //
294                       // return 0 if the test passed
295                       // return 1 if the test failed
296                       //
297 karl             1.27 // This test not required with change t0
298                       // use and test macros only.
299 mike             1.2  
300                       Uint32 test10()
301                       {
302                           const char* METHOD_NAME = "test10";
303                           Tracer::setTraceComponents("ALL");
304 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
305                           PEG_METHOD_EXIT();
306 mike             1.2      return(compare(FILE2,"Test Message for Level3 in test9"));
307                       }
308                       
309                       //
310                       // Description:
311                       // Implements trace call for Tracer::Level1
312                       // should log a trace message
313                       //
314                       // Type:
315                       // Positive 
316                       //
317                       // return 0 if the test passed
318                       // return 1 if the test failed
319                       //
320                       
321                       Uint32 test11()
322                       {
323                           const char* METHOD_NAME = "test11";
324                           Tracer::setTraceComponents("ALL");
325                           Tracer::setTraceLevel(Tracer::LEVEL4);
326 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
327 mike             1.2      return(compare(FILE2,"Entering method test11"));
328                       }
329                       
330                       //
331                       // Description:
332                       // Implements trace call for Tracer::Level1
333                       // should log a trace message
334                       //
335                       // Type:
336                       // Positive 
337                       //
338                       // return 0 if the test passed
339                       // return 1 if the test failed
340                       //
341                       
342                       Uint32 test12()
343                       {
344                           const char* METHOD_NAME = "test12";
345                           Tracer::setTraceComponents("ALL");
346                           Tracer::setTraceLevel(Tracer::LEVEL4);
347 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
348                           PEG_METHOD_EXIT();
349 mike             1.2      return(compare(FILE2,"Exiting method test12"));
350                       }
351                       
352                       //
353                       // Description:
354                       // Implements trace call for Tracer::Level2
355                       // should log a trace message
356                       //
357                       // Type:
358                       // Positive 
359                       //
360                       // return 0 if the test passed
361                       // return 1 if the test failed
362                       //
363                       
364                       Uint32 test13()
365                       {
366                           const char* METHOD_NAME = "test13";
367                           Tracer::setTraceComponents("ALL");
368                           Tracer::setTraceLevel(Tracer::LEVEL4);
369                           Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL2,"%s %s",
370 karl             1.29     "Test Message for Level2 in",METHOD_NAME);
371 mike             1.2      return(compare(FILE2,"Test Message for Level2 in test13"));
372                       }
373                       
374                       //
375                       // Description:
376                       // Implements trace call for Tracer::Level3
377                       // should log a trace message
378                       //
379                       // Type:
380                       // Positive 
381                       //
382                       // return 0 if the test passed
383                       // return 1 if the test failed
384                       //
385                       
386                       Uint32 test14()
387                       {
388                           const char* METHOD_NAME = "test14";
389                           Tracer::setTraceComponents("ALL");
390                           Tracer::setTraceLevel(Tracer::LEVEL4);
391                           Tracer::setTraceFile(FILE3);
392 mike             1.2      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL3,"%s %s",
393 karl             1.29     "Test Message for Level3 in",METHOD_NAME);
394 mike             1.2      return(compare(FILE3,"Test Message for Level3 in test14"));
395                       }
396                       
397                       //
398                       // Description:
399                       // Implements trace call for Tracer::Level4
400                       // should log a trace message
401                       //
402                       // Type:
403                       // Positive 
404                       //
405                       // return 0 if the test passed
406                       // return 1 if the test failed
407                       //
408                       
409                       Uint32 test15()
410                       {
411                           const char* METHOD_NAME = "test15";
412                           Tracer::setTraceComponents("ALL");
413                           Tracer::setTraceLevel(Tracer::LEVEL4);
414                           Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s %s",
415 karl             1.29     "Test Message for Level4 in",METHOD_NAME);
416 mike             1.2      return(compare(FILE3,"Test Message for Level4 in test15"));
417                       }
418                       
419                       //
420                       // Description:
421                       // calls the setTraceComponents with null string
422                       // should log a trace message
423                       //
424                       // Type:
425                       // Negative 
426                       //
427                       // return 0 if the test passed
428                       // return 1 if the test failed
429                       //
430                       
431                       Uint32 test16()
432                       {
433                           const char* METHOD_NAME = "test16";
434                           Tracer::setTraceComponents("");
435                           Tracer::setTraceLevel(Tracer::LEVEL4);
436                           Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s %s",
437 karl             1.29     "This Message should not appear in",METHOD_NAME);
438 mike             1.2      return(compare(FILE3,"Test Message for Level4 in test15"));
439                       }
440                       
441                       //
442                       // Description:
443                       // calls the setTraceComponents with one valid and another invalid component
444                       // should log a trace message
445                       //
446                       // Type:
447                       // Negative 
448                       //
449                       // return 0 if the test passed
450                       // return 1 if the test failed
451                       //
452                       
453                       Uint32 test17()
454                       {
455                           const char* METHOD_NAME = "test17";
456 kumpf            1.3      Tracer::setTraceComponents("InvalidComp");
457 mike             1.2      Tracer::setTraceLevel(Tracer::LEVEL4);
458                           Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,"%s %s",
459 karl             1.29     "This Message should not appear in",METHOD_NAME);
460 mike             1.2      return(compare(FILE3,"Test Message for Level4 in test15"));
461                       }
462 kumpf            1.3  //
463                       // Description:
464                       // calls the _traceBuffer call
465                       // should log a trace message
466                       //
467                       // Type:
468                       // Positive
469                       //
470                       // return 0 if the test passed
471                       // return 1 if the test failed
472                       //
473                       
474                       Uint32 test18()
475                       {
476                           const char* METHOD_NAME = "test18";
477                           Tracer::setTraceComponents("Config,InvalidComp");
478                           Tracer::setTraceLevel(Tracer::LEVEL4);
479 marek            1.28     Tracer::traceCString(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,
480                               "This Message should appear in");
481                           return(compare(FILE3,"This Message should appear in"));
482 kumpf            1.3  }
483 mike             1.2  
484 kumpf            1.4  //
485                       // Description:
486                       // Trace a string.
487                       // Calls the _traceString() method
488                       // should log a trace message
489                       //
490                       // Type:
491                       // Positive
492                       //
493                       // return 0 if the test passed
494                       // return 1 if the test failed
495                       //
496                       
497                       Uint32 test20()
498                       {
499                           const char* METHOD_NAME = "test20";
500                           Tracer::setTraceFile(FILE4);
501                           Tracer::setTraceComponents("ALL");
502                           Tracer::setTraceLevel(Tracer::LEVEL4);
503                       
504                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
505 kumpf            1.4      Tracer::trace(__FILE__,__LINE__,TRC_CONFIG,Tracer::LEVEL4,
506 karl             1.29     "Test Message for Level4 in test20");
507 kumpf            1.4      return(compare(FILE4,"Test Message for Level4 in test20"));
508                       }
509                       
510                       //
511                       // Description:
512                       // Trace a CIMException.
513                       // Calls the traceCIMException() method
514                       // should log a trace message
515                       //
516                       // Type:
517                       // Positive
518                       //
519                       // return 0 if the test passed
520                       // return 1 if the test failed
521                       //
522                       
523                       Uint32 test21()
524                       {
525                           const char* METHOD_NAME = "test21";
526                           Tracer::setTraceFile(FILE4);
527                           Tracer::setTraceComponents("ALL");
528 kumpf            1.4      Tracer::setTraceLevel(Tracer::LEVEL4);
529                       
530                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
531                       
532                           // test tracing CIMException
533                           try
534                           {
535                               throw PEGASUS_CIM_EXCEPTION(
536                                   CIM_ERR_NOT_SUPPORTED, 
537                                   "CIM Exception Message for Level4 in test21.");
538                           }
539 kumpf            1.12     catch (CIMException& e)
540 kumpf            1.4      {
541                               Tracer::traceCIMException(TRC_CONFIG,Tracer::LEVEL4, e);
542                           }
543                       
544                           return 0;
545                       }
546                       
547                       //
548                       // Description:
549                       // Trace a string using macro.
550                       // should log a trace message
551                       //
552                       // Type:
553                       // Positive
554                       //
555                       // return 0 if the test passed
556                       // return 1 if the test failed
557                       //
558                       Uint32 test22()
559                       {
560                           const char* METHOD_NAME = "test22";
561 kumpf            1.4      Tracer::setTraceFile(FILE4);
562                           Tracer::setTraceComponents("ALL");
563                           Tracer::setTraceLevel(Tracer::LEVEL4);
564                       
565                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
566                       
567 karl             1.29     PEG_TRACE_STRING(TRC_CONFIG,Tracer::LEVEL4,
568                                            "Test message for Level4 in test22.");
569 kumpf            1.4  
570                           return(compare(FILE4,"Test message for Level4 in test22."));
571                       }
572                       
573 marek            1.28 //
574                       // Description:
575                       // Trace a character string using macro.
576                       // should log a trace message
577                       //
578                       // Type:
579                       // Positive
580                       //
581                       // return 0 if the test passed
582                       // return 1 if the test failed
583                       //
584                       Uint32 test23()
585                       {
586                           const char* METHOD_NAME = "test23";
587                           Tracer::setTraceFile(FILE4);
588                           Tracer::setTraceComponents("ALL");
589                           Tracer::setTraceLevel(Tracer::LEVEL4);
590                       
591                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
592                       
593 karl             1.29     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
594                                             "Test message for Level4 in test23.");
595 marek            1.28 
596                           return(compare(FILE4,"Test message for Level4 in test23."));
597                       }
598                       
599 sushma.fernandes 1.30 // 
600                       // Description:
601                       // Test the getHTTPRequestMessage method.
602                       //
603                       // Type:
604                       // Positive
605                       // Tests with a HTTP Request without a basic authorization header.
606                       // Message is written to trace file without any changes.
607                       //
608                       // return 0 if the test passed
609                       // return 1 if the test failed
610                       //
611                       Uint32 test24()
612                       {
613                           Tracer::setTraceFile(FILE4);
614                           Tracer::setTraceComponents("xmlio");
615                           Tracer::setTraceLevel(Tracer::LEVEL2);
616                       
617                           Uint32 queueId = 18;
618                           CIMPropertyList propertyList;
619                           Buffer params;
620 sushma.fernandes 1.30     AcceptLanguageList al;
621                           ContentLanguageList cl; 
622                       
623                           XmlWriter::appendClassNameIParameter(
624                               params, "ClassName", CIMName("testclass"));
625                           Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
626                               "localhost",
627                               CIMNamespaceName("test/cimv2"), 
628                               CIMName ("EnumerateInstanceNames"),
629                               "12345", 
630                               HTTP_METHOD__POST,
631                               "Basic: Authorization AAAAA",
632                               al,
633                               cl,
634                               params);
635                       
636                           SharedArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(
637                                   buffer));
638                       
639                           PEG_TRACE((
640                               TRC_XML_IO, 
641 sushma.fernandes 1.30         Tracer::LEVEL2,
642                               "<!-- Request: queue id: %u -->\n%s",
643                               queueId,
644                               reqMsg.get()));
645                       
646                           return(compare(FILE4, buffer.getData()));
647                       } 
648                           
649                       // 
650                       // Description:
651                       // Test the getHTTPRequestMessage method.
652                       //
653                       // Type:
654                       // Positive
655                       // Tests with a HTTP Request that contains a Basic authorization header.
656                       // The user/password info in the message is suppressed before writing it to 
657                       // the trace file.
658                       //
659                       // return 0 if the test passed
660                       // return 1 if the test failed
661                       //
662 sushma.fernandes 1.30 Uint32 test25()
663                       {   
664                           Tracer::setTraceFile(FILE4);
665                           Tracer::setTraceComponents("xmlio");
666                           Tracer::setTraceLevel(Tracer::LEVEL2);
667                       
668                           Uint32 queueId = 18;
669                           CIMPropertyList propertyList;
670                           Buffer params;
671                           AcceptLanguageList al;
672                           ContentLanguageList cl;
673                           String authHeader = "Authorization: Basic ABCDEABCDE==";
674                           String MSGID = "32423424";
675                       
676                           XmlWriter::appendClassNameIParameter(
677                               params, 
678                               "ClassName", 
679                               CIMName("testclass"));
680                           Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
681                               "localhost",
682                               CIMNamespaceName("test/cimv2"), 
683 sushma.fernandes 1.30         CIMName ("EnumerateInstanceNames"),
684                               MSGID, 
685                               HTTP_METHOD__POST,
686                               authHeader,
687                               al,
688                               cl,
689                               params);
690                       
691                           PEG_TRACE((
692                               TRC_XML_IO, 
693                               Tracer::LEVEL2,
694                               "<!-- Request: queue id: %u -->\n%s",
695                               queueId,
696                               Tracer::getHTTPRequestMessage(
697                                   buffer).get()));
698                           
699                           String testStr(buffer.getData());
700                           Uint32 pos = testStr.find("ABCDEABCDE==");
701                           
702                           for ( Uint32 i = pos; i < pos+strlen("ABCDEABCDE=="); i++)
703                               testStr[i] = 'X';
704 sushma.fernandes 1.30 
705                           return(compare(FILE4, testStr.getCString()));
706                       }
707                       
708 karl             1.7  int main(int argc, char** argv)
709 mike             1.2  {
710                       
711                       // Execute the tests only if trace calls are included
712                       
713                       #ifdef PEGASUS_REMOVE_TRACE
714 karl             1.7      cout << argv[0] << " +++++ passed all tests" << endl;
715 mike             1.2      return 0;
716                       #else
717 kumpf            1.11 
718                           const char* tmpDir = getenv ("PEGASUS_TMP");
719                           if (tmpDir == NULL)
720                           {
721                               tmpDir = ".";
722                           }
723                           String f1 (tmpDir);
724 kumpf            1.13     f1.append("/testtracer1.trace");
725 kumpf            1.14     FILE1 = f1.getCString();
726 kumpf            1.11     String f2 (tmpDir);
727 kumpf            1.13     f2.append("/testtracer2.trace");
728 kumpf            1.14     FILE2 = f2.getCString();
729 kumpf            1.11     String f3 (tmpDir);
730 kumpf            1.13     f3.append("/testtracer3.trace");
731 kumpf            1.14     FILE3 = f3.getCString();
732 kumpf            1.11     String f4 (tmpDir);
733 kumpf            1.13     f4.append("/testtracer4.trace");
734 kumpf            1.14     FILE4 = f4.getCString();
735 kumpf            1.11 
736 mike             1.2      System::removeFile(FILE1);
737                           System::removeFile(FILE2);
738                           System::removeFile(FILE3);
739 kumpf            1.4      System::removeFile(FILE4);
740 mike             1.2      if (test1() == 0)
741                           {
742                              cout << "Tracer test (test1) failed" << endl;
743                              exit(1);
744                           }
745                           if (test2() == 0)
746                           {
747                              cout << "Tracer test (test2) failed" << endl;
748                              exit(1);
749                           }
750                           if (test3() == 0)
751                           {
752                              cout << "Tracer test (test3) failed" << endl;
753                              exit(1);
754                           }
755                           if (test4() != 0)
756                           {
757                              cout << "Tracer test (test4) failed" << endl;
758                              exit(1);
759                           }
760                           if (test5() != 0)
761 mike             1.2      {
762                              cout << "Tracer test (test5) failed" << endl;
763                              exit(1);
764                           }
765                           if (test6() != 0)
766                           {
767                              cout << "Tracer test (test6) failed" << endl;
768                              exit(1);
769                           }
770                           if (test7() != 0)
771                           {
772                              cout << "Tracer test (test7) failed" << endl;
773                              exit(1);
774                           }
775                           if (test9() != 0)
776                           {
777                              cout << "Tracer test (test9) failed" << endl;
778                              exit(1);
779                           }
780 karl             1.27     /*************************** 
781                              Test 10 bypassed when tests changed to
782                              use macros.  It did an invalid call which is
783                              not possible with macros
784                       
785 mike             1.2      if (test10() != 0)
786                           {
787                              cout << "Tracer test (test10) failed" << endl;
788                              exit(1);
789                           }
790 karl             1.27     ******************************/
791 mike             1.2      if (test11() != 0)
792                           {
793                              cout << "Tracer test (test11) failed" << endl;
794                              exit(1);
795                           }
796                           if (test12() != 0)
797                           {
798                              cout << "Tracer test (test12) failed" << endl;
799                              exit(1);
800                           }
801                           if (test13() != 0)
802                           {
803                              cout << "Tracer test (test13) failed" << endl;
804                              exit(1);
805                           }
806                           if (test14() != 0)
807                           {
808                              cout << "Tracer test (test14) failed" << endl;
809                              exit(1);
810                           }
811                           if (test15() != 0)
812 mike             1.2      {
813                              cout << "Tracer test (test15) failed" << endl;
814                              exit(1);
815                           }
816                           if (test16() != 0)
817                           {
818                              cout << "Tracer test (test16) failed" << endl;
819 kumpf            1.3         exit(1);
820                           }
821                           if (test17() != 0)
822                           {
823                              cout << "Tracer test (test17) failed" << endl;
824                              exit(1);
825                           }
826                           if (test18() != 0)
827                           {
828                              cout << "Tracer test (test18) failed" << endl;
829                              exit(1);
830                           }
831 kumpf            1.4      if (test20() != 0)
832                           {
833                              cout << "Tracer test (test20) failed" << endl;
834                              exit(1);
835                           }
836                           if (test21() != 0)
837                           {
838                              cout << "Tracer test (test21) failed" << endl;
839                              exit(1);
840                           }
841                           if (test22() != 0)
842                           {
843                              cout << "Tracer test (test22) failed" << endl;
844                              exit(1);
845                           }
846 marek            1.28     if (test23() != 0)
847                           {
848                              cout << "Tracer test (test23) failed" << endl;
849                              exit(1);
850                           }
851 sushma.fernandes 1.30     if (test24() != 0)
852                           {
853                              cout << "Tracer test (test24) failed" << endl;
854                              exit(1);
855                           }
856                       
857                           if (test25() != 0)
858                           {
859                              cout << "Tracer test (test25) failed" << endl;
860                              exit(1);
861                           }
862                       
863 karl             1.7      cout << argv[0] << " +++++ passed all tests" << endl;
864 mike             1.2      System::removeFile(FILE1);
865                           System::removeFile(FILE2);
866                           System::removeFile(FILE3);
867 kumpf            1.4      System::removeFile(FILE4);
868 mike             1.2      return 0;
869                       #endif
870                       }
871                       

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2