(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 thilo.boehm 1.39 #include <Pegasus/Common/TraceMemoryHandler.h>
  39 a.arora     1.17 #include <Pegasus/Common/AutoPtr.h>
  40 sushma.fernandes 1.30 #include <Pegasus/Common/SharedPtr.h>
  41                       #include <Pegasus/Common/CIMClass.h>
  42                       #include <Pegasus/Common/CIMMessage.h>
  43                       #include <Pegasus/Common/XmlWriter.h>
  44                       #include <Pegasus/Common/AcceptLanguageList.h>
  45                       #include <Pegasus/Common/ContentLanguageList.h>
  46 mike             1.2  
  47                       PEGASUS_USING_STD;
  48                       PEGASUS_USING_PEGASUS;
  49                       
  50 marek            1.35 
  51                       // Trace Levels 0 and 5 are defined as private constants of the tracer
  52                       // class to avoid inappropriate use in the trace calls and macros.
  53                       // Therefore these tracel levels need to be set in the tests using the
  54                       // constant values directly.
  55                       const Uint32 PEGASUS_TRACER_LEVEL0 =  0;
  56                       const Uint32 PEGASUS_TRACER_LEVEL5 = (1 << 4);
  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 thilo.boehm      1.39 CString FILE5;
  67                       
  68                       // A message string for testing the tracer with variable arguments
  69                       #define VAR_TEST_MESSAGE "Variable length part of message"
  70                       
  71 mike             1.2  
  72                       // 
  73                       // Reads the last trace message from a given trace file and compares the 
  74                       // given string with the string read from file
  75                       //
  76                       // return 0 if the strings match
  77                       // return 1 if the strings do not match
  78                       //
  79 kumpf            1.31 Uint32 compare(const char* fileName, const char* expectedMessage)
  80 mike             1.2  {
  81 kumpf            1.31     int expectedMessageLength = strlen(expectedMessage);
  82                       
  83                           // Compute the size of the message in the trace file.  Include the final
  84                           // EOL character added by the Tracer.  This size will be used to seek
  85                           // from the end of the file back to the beginning of the trace message.
  86                           int seekBytes = expectedMessageLength + 1;
  87                       
  88                       #if defined(PEGASUS_OS_TYPE_WINDOWS)
  89                           // Windows converts all '\n' characters to "\r\n" sequences in the trace
  90                           // file.  Increase the seekBytes by the number of '\r' characters added
  91                           // when the message is written to the file.
  92                           for (const char* newlineChar = expectedMessage;
  93                                ((newlineChar = strchr(newlineChar, '\n')) != 0);
  94                                newlineChar++)
  95                           {
  96                               seekBytes++;
  97                           }
  98                       
  99                           // Count the '\r' character added with the final '\n' written by the Tracer
 100                           seekBytes++;
 101                       #endif
 102 kumpf            1.31 
 103                           AutoArrayPtr<char> actualMessage(new char[expectedMessageLength + 1]);
 104                       
 105                           // Read the trace message from the file, minus the message prefix and
 106                           // minus the trailing newline.
 107 mike             1.2      fstream file;
 108 kumpf            1.31     file.open(fileName, fstream::in);
 109 mike             1.2      if (!file.good())
 110                           {
 111 kumpf            1.31         return 1;
 112 mike             1.2      }
 113 kumpf            1.31     file.seekg(-seekBytes, fstream::end);
 114                           file.read(actualMessage.get(), expectedMessageLength);
 115                           file.close();
 116                           actualMessage[expectedMessageLength] = 0;
 117                       
 118                           // Compare the expected and actual messages
 119                           Uint32 retCode = strcmp(expectedMessage, actualMessage.get());
 120                       
 121 thilo.boehm      1.39     // Diagnostic to determine string differences
 122 kumpf            1.31     if (retCode)
 123                               cout << "Compare Error: expectedMessage= \n\"" << expectedMessage <<
 124                                   "\". actualMessage= \n\"" << actualMessage.get() << "\"" << endl;
 125 thilo.boehm      1.39     
 126 karl             1.27 
 127 mike             1.2      return retCode;
 128                       }
 129                       
 130                       //
 131                       // Description:
 132                       // Trace properties file, level and component are not set
 133                       // Should not log a trace message
 134                       //
 135                       // Type:
 136                       // Negative 
 137                       //
 138                       // return 0 if the test passed
 139                       // return 1 if the test failed
 140                       //
 141                       Uint32 test1()
 142                       {
 143                           const char* METHOD_NAME = "test1";
 144 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 145 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %d",
 146                               "This message should not appear value=",123));
 147 kumpf            1.10     PEG_METHOD_EXIT();
 148 kumpf            1.34     return System::exists(FILE1) ? 1 : 0;
 149 mike             1.2  }
 150                       
 151                       //
 152                       // Description:
 153                       // Trace properties level and component are not set
 154                       // Should not log a trace message
 155                       //
 156                       // Type:
 157                       // Negative 
 158                       //
 159                       // return 0 if the test passed
 160                       // return 1 if the test failed
 161                       //
 162                       Uint32 test2()
 163                       {
 164                           const char* METHOD_NAME = "test2";
 165                           Tracer::setTraceFile(FILE1);
 166 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 167 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %d",
 168                               "This message should not appear value=",123));
 169 kumpf            1.34     Uint32 fileSize;
 170                           System::getFileSize(FILE1, fileSize);
 171                           return (fileSize == 0) ? 0 : 1;
 172 mike             1.2  }
 173                       
 174                       //
 175                       // Description:
 176                       // Trace properties component is not set
 177                       // Should not log a trace message
 178                       //
 179                       // Type:
 180                       // Negative 
 181                       //
 182                       // return 0 if the test passed
 183                       // return 1 if the test failed
 184                       //
 185                       Uint32 test3()
 186                       {
 187                           const char* METHOD_NAME = "test3";
 188                           Tracer::setTraceLevel(Tracer::LEVEL1);
 189 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 190 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s",
 191                               "This message should not appear"));
 192 kumpf            1.34     Uint32 fileSize;
 193                           System::getFileSize(FILE1, fileSize);
 194                           return (fileSize == 0) ? 0 : 1;
 195 mike             1.2  }
 196                       
 197                       //
 198                       // Description:
 199                       // Trace properties file, level and component are set
 200                       // should log a trace message
 201                       //
 202                       // Type:
 203                       // Positive 
 204                       //
 205                       // return 0 if the test passed
 206                       // return 1 if the test failed
 207                       //
 208                       Uint32 test4()
 209                       {
 210                           const char* METHOD_NAME = "test4";
 211 marek            1.37     Tracer::setTraceLevel(Tracer::LEVEL1);
 212 mike             1.2      Tracer::setTraceComponents("Config");
 213 marek            1.37     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,METHOD_NAME);
 214                           return(compare(FILE1,METHOD_NAME));
 215 mike             1.2  }
 216                       
 217                       //
 218                       // Description:
 219                       // Trace component is set to an invalid component
 220                       // should not log a trace message
 221                       //
 222                       // Type:
 223                       // Negative 
 224                       //
 225                       // return 0 if the test passed
 226                       // return 1 if the test failed
 227                       //
 228                       Uint32 test5()
 229                       {
 230                           const char* METHOD_NAME = "test5";
 231                           Tracer::setTraceComponents("Wrong Component Name");
 232 karl             1.27 
 233                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 234 marek            1.37     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,METHOD_NAME);
 235 karl             1.27     PEG_METHOD_EXIT();
 236 marek            1.37     return(compare(FILE1,"test4"));
 237 mike             1.2  }
 238                       
 239                       //
 240                       // Description:
 241                       // Trace level is set to LEVEL 2 and logs a LEVEL 4 message 
 242                       // should not log a trace message
 243                       //
 244                       // Type:
 245                       // Negative 
 246                       //
 247                       // return 0 if the test passed
 248                       // return 1 if the test failed
 249                       //
 250                       
 251                       Uint32 test6()
 252                       {
 253                           const char* METHOD_NAME = "test6";
 254                           Tracer::setTraceComponents("Config");
 255                           Tracer::setTraceLevel(Tracer::LEVEL2);
 256 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
 257                               "Test Message for Level2 in",METHOD_NAME));
 258                           PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
 259                               "Test Message for Level2 in",METHOD_NAME));
 260                           PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s",
 261                               "This Message should not appear"));
 262 mike             1.2      return(compare(FILE1,"Test Message for Level2 in test6"));
 263                       }
 264                       
 265                       //
 266                       // Description:
 267                       // Trace level is set to an invalid level
 268                       // should not log a trace message
 269                       //
 270                       // Type:
 271                       // Negative 
 272                       //
 273                       // return 0 if the test passed
 274                       // return 1 if the test failed
 275                       //
 276                       Uint32 test7()
 277                       {
 278                           const char* METHOD_NAME = "test7";
 279                           Tracer::setTraceLevel(100);
 280 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 281                           PEG_METHOD_EXIT();
 282 mike             1.2      return(compare(FILE1,"Test Message for Level2 in test6"));
 283                       }
 284                       
 285                       //
 286                       // Description:
 287                       // Changes the trace file to FILE2 
 288                       //
 289                       // Type:
 290                       // Positive 
 291                       //
 292                       // return 0 if the test passed
 293                       // return 1 if the test failed
 294                       //
 295                       Uint32 test9()
 296                       {
 297                           const char* METHOD_NAME = "test9";
 298                           Tracer::setTraceLevel(Tracer::LEVEL3);
 299                           Tracer::setTraceFile(FILE2);
 300                       
 301 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 302 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
 303                               "Test Message for Level3 in",METHOD_NAME));
 304 mike             1.2      return(compare(FILE2,"Test Message for Level3 in test9"));
 305                       }
 306                       
 307                       //
 308                       // Description:
 309                       // Passes invalid component in the trace call
 310                       // should not log a trace message
 311                       //
 312                       // Type:
 313                       // Negative 
 314                       //
 315                       // return 0 if the test passed
 316                       // return 1 if the test failed
 317                       //
 318 marek            1.35 // This test not required with change to
 319 karl             1.27 // use and test macros only.
 320 mike             1.2  
 321                       Uint32 test10()
 322                       {
 323                           const char* METHOD_NAME = "test10";
 324                           Tracer::setTraceComponents("ALL");
 325 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 326                           PEG_METHOD_EXIT();
 327 mike             1.2      return(compare(FILE2,"Test Message for Level3 in test9"));
 328                       }
 329                       
 330                       //
 331                       // Description:
 332 marek            1.35 // Trace is set to level 0
 333                       // should not log a trace message
 334 mike             1.2  //
 335                       // Type:
 336 marek            1.35 // Negative
 337 mike             1.2  //
 338                       // return 0 if the test passed
 339                       // return 1 if the test failed
 340                       //
 341                       
 342                       Uint32 test11()
 343                       {
 344                           const char* METHOD_NAME = "test11";
 345                           Tracer::setTraceComponents("ALL");
 346 marek            1.35     Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL0);
 347                           PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
 348                               "Test Message for Level0 in",METHOD_NAME));
 349                           return(compare(FILE2,"Test Message for Level3 in test9"));
 350 mike             1.2  }
 351                       
 352                       //
 353                       // Description:
 354                       // Implements trace call for Tracer::Level1
 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 test12()
 365                       {
 366                           const char* METHOD_NAME = "test12";
 367                           Tracer::setTraceComponents("ALL");
 368                           Tracer::setTraceLevel(Tracer::LEVEL4);
 369 marek            1.35     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
 370                               "Test Message for Level1 in",METHOD_NAME));
 371                           return(compare(FILE2,"Test Message for Level1 in test12"));
 372 mike             1.2  }
 373                       
 374                       //
 375                       // Description:
 376                       // Implements trace call for Tracer::Level2
 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 test13()
 387                       {
 388                           const char* METHOD_NAME = "test13";
 389                           Tracer::setTraceComponents("ALL");
 390                           Tracer::setTraceLevel(Tracer::LEVEL4);
 391 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
 392                               "Test Message for Level2 in",METHOD_NAME));
 393 mike             1.2      return(compare(FILE2,"Test Message for Level2 in test13"));
 394                       }
 395                       
 396                       //
 397                       // Description:
 398                       // Implements trace call for Tracer::Level3
 399                       // should log a trace message
 400                       //
 401                       // Type:
 402                       // Positive 
 403                       //
 404                       // return 0 if the test passed
 405                       // return 1 if the test failed
 406                       //
 407                       
 408                       Uint32 test14()
 409                       {
 410                           const char* METHOD_NAME = "test14";
 411                           Tracer::setTraceComponents("ALL");
 412                           Tracer::setTraceLevel(Tracer::LEVEL4);
 413                           Tracer::setTraceFile(FILE3);
 414 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
 415                               "Test Message for Level3 in",METHOD_NAME));
 416 mike             1.2      return(compare(FILE3,"Test Message for Level3 in test14"));
 417                       }
 418                       
 419                       //
 420                       // Description:
 421                       // Implements trace call for Tracer::Level4
 422                       // should log a trace message
 423                       //
 424                       // Type:
 425                       // Positive 
 426                       //
 427                       // return 0 if the test passed
 428                       // return 1 if the test failed
 429                       //
 430                       
 431                       Uint32 test15()
 432                       {
 433                           const char* METHOD_NAME = "test15";
 434                           Tracer::setTraceComponents("ALL");
 435                           Tracer::setTraceLevel(Tracer::LEVEL4);
 436 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
 437                               "Test Message for Level4 in",METHOD_NAME));
 438 mike             1.2      return(compare(FILE3,"Test Message for Level4 in test15"));
 439                       }
 440                       
 441                       //
 442                       // Description:
 443 marek            1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
 444                       // should log a trace message
 445                       //
 446                       // Type:
 447                       // Positive 
 448                       //
 449                       // return 0 if the test passed
 450                       // return 1 if the test failed
 451                       //
 452                       
 453                       Uint32 test15a()
 454                       {
 455                           const char* METHOD_NAME = "test15a";
 456                           Tracer::setTraceComponents("ALL");
 457                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 458                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 459                           return(compare(FILE3,"Entering method test15a"));
 460                       }
 461                       
 462                       //
 463                       // Description:
 464 marek            1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
 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 test15b()
 475                       {
 476                           const char* METHOD_NAME = "test15b";
 477                           Tracer::setTraceComponents("ALL");
 478                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 479                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 480                           PEG_METHOD_EXIT();
 481                           return(compare(FILE3,"Exiting method test15b"));
 482                       }
 483                       
 484                       //
 485 marek            1.35 // Description:
 486 mike             1.2  // calls the setTraceComponents with null string
 487 marek            1.35 // should not log a trace message
 488 mike             1.2  //
 489                       // Type:
 490                       // Negative 
 491                       //
 492                       // return 0 if the test passed
 493                       // return 1 if the test failed
 494                       //
 495                       
 496                       Uint32 test16()
 497                       {
 498                           const char* METHOD_NAME = "test16";
 499 marek            1.37     Tracer::setTraceComponents("ALL");
 500                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 501                           PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,"test16 - check value");    
 502 mike             1.2      Tracer::setTraceComponents("");
 503                           Tracer::setTraceLevel(Tracer::LEVEL4);
 504 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
 505                           "This Message should not appear in",METHOD_NAME));
 506 marek            1.37     return(compare(FILE3,"test16 - check value"));
 507 mike             1.2  }
 508                       
 509                       //
 510                       // Description:
 511                       // calls the setTraceComponents with one valid and another invalid component
 512                       // should log a trace message
 513                       //
 514                       // Type:
 515                       // Negative 
 516                       //
 517                       // return 0 if the test passed
 518                       // return 1 if the test failed
 519                       //
 520                       
 521                       Uint32 test17()
 522                       {
 523                           const char* METHOD_NAME = "test17";
 524 marek            1.37     Tracer::setTraceComponents("ALL");
 525                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 526                           PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,"test17 - check value");    
 527 kumpf            1.3      Tracer::setTraceComponents("InvalidComp");
 528 mike             1.2      Tracer::setTraceLevel(Tracer::LEVEL4);
 529 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
 530                           "This Message should not appear in",METHOD_NAME));
 531 marek            1.37     return(compare(FILE3,"test17 - check value"));
 532 mike             1.2  }
 533 kumpf            1.3  //
 534                       // Description:
 535                       // calls the _traceBuffer call
 536                       // should log a trace message
 537                       //
 538                       // Type:
 539                       // Positive
 540                       //
 541                       // return 0 if the test passed
 542                       // return 1 if the test failed
 543                       //
 544                       
 545                       Uint32 test18()
 546                       {
 547                           const char* METHOD_NAME = "test18";
 548                           Tracer::setTraceComponents("Config,InvalidComp");
 549                           Tracer::setTraceLevel(Tracer::LEVEL4);
 550 marek            1.33     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 551 marek            1.28         "This Message should appear in");
 552                           return(compare(FILE3,"This Message should appear in"));
 553 kumpf            1.3  }
 554 mike             1.2  
 555 kumpf            1.4  //
 556                       // Description:
 557                       // Trace a string.
 558 marek            1.33 // Calls the PEG_TRACE macro
 559 kumpf            1.4  // should log a trace message
 560                       //
 561                       // Type:
 562                       // Positive
 563                       //
 564                       // return 0 if the test passed
 565                       // return 1 if the test failed
 566                       //
 567                       
 568                       Uint32 test20()
 569                       {
 570                           const char* METHOD_NAME = "test20";
 571                           Tracer::setTraceFile(FILE4);
 572                           Tracer::setTraceComponents("ALL");
 573                           Tracer::setTraceLevel(Tracer::LEVEL4);
 574                       
 575                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 576 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,
 577                           "Test Message for Level4 in test20"));
 578 kumpf            1.4      return(compare(FILE4,"Test Message for Level4 in test20"));
 579                       }
 580                       
 581                       //
 582                       // Description:
 583                       // Trace a CIMException.
 584                       // Calls the traceCIMException() method
 585                       // should log a trace message
 586                       //
 587                       // Type:
 588                       // Positive
 589                       //
 590                       // return 0 if the test passed
 591                       // return 1 if the test failed
 592                       //
 593                       
 594                       Uint32 test21()
 595                       {
 596                           const char* METHOD_NAME = "test21";
 597                           Tracer::setTraceFile(FILE4);
 598                           Tracer::setTraceComponents("ALL");
 599 kumpf            1.4      Tracer::setTraceLevel(Tracer::LEVEL4);
 600                       
 601                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 602                       
 603                           // test tracing CIMException
 604                           try
 605                           {
 606                               throw PEGASUS_CIM_EXCEPTION(
 607                                   CIM_ERR_NOT_SUPPORTED, 
 608                                   "CIM Exception Message for Level4 in test21.");
 609                           }
 610 kumpf            1.12     catch (CIMException& e)
 611 kumpf            1.4      {
 612                               Tracer::traceCIMException(TRC_CONFIG,Tracer::LEVEL4, e);
 613                           }
 614                       
 615                           return 0;
 616                       }
 617                       
 618                       //
 619                       // Description:
 620                       // Trace a string using macro.
 621                       // should log a trace message
 622                       //
 623                       // Type:
 624                       // Positive
 625                       //
 626                       // return 0 if the test passed
 627                       // return 1 if the test failed
 628                       //
 629                       Uint32 test22()
 630                       {
 631                           const char* METHOD_NAME = "test22";
 632 kumpf            1.4      Tracer::setTraceFile(FILE4);
 633                           Tracer::setTraceComponents("ALL");
 634                           Tracer::setTraceLevel(Tracer::LEVEL4);
 635                       
 636                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 637                       
 638 thilo.boehm      1.38     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 639                               "Test message for Level4 in test22.");
 640 kumpf            1.4  
 641                           return(compare(FILE4,"Test message for Level4 in test22."));
 642                       }
 643                       
 644 marek            1.28 //
 645                       // Description:
 646                       // Trace a character string using macro.
 647                       // should log a trace message
 648                       //
 649                       // Type:
 650                       // Positive
 651                       //
 652                       // return 0 if the test passed
 653                       // return 1 if the test failed
 654                       //
 655                       Uint32 test23()
 656                       {
 657                           const char* METHOD_NAME = "test23";
 658                           Tracer::setTraceFile(FILE4);
 659                           Tracer::setTraceComponents("ALL");
 660                           Tracer::setTraceLevel(Tracer::LEVEL4);
 661                       
 662                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 663                       
 664 karl             1.29     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 665                                             "Test message for Level4 in test23.");
 666 marek            1.28 
 667                           return(compare(FILE4,"Test message for Level4 in test23."));
 668                       }
 669                       
 670 r.kieninger      1.36 //
 671                       // Description:
 672                       // Change traceFacility to Logger
 673                       // No more trace messages should be written
 674                       //
 675                       // Type:
 676                       // Negative
 677                       //
 678                       // return 0 if the test passed
 679                       // return 1 if the test failed
 680                       //
 681                       Uint32 test24()
 682                       {
 683                           const char* METHOD_NAME = "test24";
 684                           Tracer::setTraceFacility("Log");
 685                           Tracer::setTraceFile(FILE4);
 686                           Tracer::setTraceComponents("ALL");
 687                           Tracer::setTraceLevel(Tracer::LEVEL4);
 688                       
 689                           PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 690                                             "Test message for traceFacility=Log in test24.");
 691 r.kieninger      1.36 
 692                           return(compare(FILE4,"Test message for Level4 in test23."));
 693                       }
 694                       
 695                       //
 696                       // Description:
 697                       // Change traceFacility back to File
 698                       // Trace messages should be written again
 699                       //
 700                       // Type:
 701                       // Positive
 702                       //
 703                       // return 0 if the test passed
 704                       // return 1 if the test failed
 705                       //
 706                       Uint32 test25()
 707                       {
 708                           const char* METHOD_NAME = "test25";
 709                           Tracer::setTraceFacility("File");
 710                           Tracer::setTraceFile(FILE4);
 711                           Tracer::setTraceComponents("ALL");
 712 r.kieninger      1.36     Tracer::setTraceLevel(Tracer::LEVEL4);
 713                       
 714                           PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 715                                             "Test message for traceFacility=File in test25.");
 716                       
 717                           return(compare(FILE4,"Test message for traceFacility=File in test25."));
 718                       }
 719                       
 720 sushma.fernandes 1.30 // 
 721                       // Description:
 722                       // Test the getHTTPRequestMessage method.
 723                       //
 724                       // Type:
 725                       // Positive
 726                       // Tests with a HTTP Request without a basic authorization header.
 727                       // Message is written to trace file without any changes.
 728                       //
 729                       // return 0 if the test passed
 730                       // return 1 if the test failed
 731                       //
 732 r.kieninger      1.36 Uint32 test26()
 733 sushma.fernandes 1.30 {
 734                           Tracer::setTraceFile(FILE4);
 735                           Tracer::setTraceComponents("xmlio");
 736                           Tracer::setTraceLevel(Tracer::LEVEL2);
 737                       
 738                           Uint32 queueId = 18;
 739                           CIMPropertyList propertyList;
 740                           Buffer params;
 741                           AcceptLanguageList al;
 742                           ContentLanguageList cl; 
 743                       
 744                           XmlWriter::appendClassNameIParameter(
 745                               params, "ClassName", CIMName("testclass"));
 746                           Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
 747                               "localhost",
 748                               CIMNamespaceName("test/cimv2"), 
 749                               CIMName ("EnumerateInstanceNames"),
 750                               "12345", 
 751                               HTTP_METHOD__POST,
 752                               "Basic: Authorization AAAAA",
 753                               al,
 754 sushma.fernandes 1.30         cl,
 755                               params);
 756                       
 757                           SharedArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(
 758                                   buffer));
 759                       
 760                           PEG_TRACE((
 761                               TRC_XML_IO, 
 762                               Tracer::LEVEL2,
 763                               "<!-- Request: queue id: %u -->\n%s",
 764                               queueId,
 765                               reqMsg.get()));
 766                       
 767                           return(compare(FILE4, buffer.getData()));
 768                       } 
 769                           
 770                       // 
 771                       // Description:
 772                       // Test the getHTTPRequestMessage method.
 773                       //
 774                       // Type:
 775 sushma.fernandes 1.30 // Positive
 776                       // Tests with a HTTP Request that contains a Basic authorization header.
 777                       // The user/password info in the message is suppressed before writing it to 
 778                       // the trace file.
 779                       //
 780                       // return 0 if the test passed
 781                       // return 1 if the test failed
 782                       //
 783 r.kieninger      1.36 Uint32 test27()
 784 sushma.fernandes 1.30 {   
 785                           Tracer::setTraceFile(FILE4);
 786                           Tracer::setTraceComponents("xmlio");
 787                           Tracer::setTraceLevel(Tracer::LEVEL2);
 788                       
 789                           Uint32 queueId = 18;
 790                           CIMPropertyList propertyList;
 791                           Buffer params;
 792                           AcceptLanguageList al;
 793                           ContentLanguageList cl;
 794                           String authHeader = "Authorization: Basic ABCDEABCDE==";
 795                           String MSGID = "32423424";
 796                       
 797                           XmlWriter::appendClassNameIParameter(
 798                               params, 
 799                               "ClassName", 
 800                               CIMName("testclass"));
 801                           Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
 802                               "localhost",
 803                               CIMNamespaceName("test/cimv2"), 
 804                               CIMName ("EnumerateInstanceNames"),
 805 sushma.fernandes 1.30         MSGID, 
 806                               HTTP_METHOD__POST,
 807                               authHeader,
 808                               al,
 809                               cl,
 810                               params);
 811                       
 812                           PEG_TRACE((
 813                               TRC_XML_IO, 
 814                               Tracer::LEVEL2,
 815                               "<!-- Request: queue id: %u -->\n%s",
 816                               queueId,
 817                               Tracer::getHTTPRequestMessage(
 818                                   buffer).get()));
 819                           
 820                           String testStr(buffer.getData());
 821                           Uint32 pos = testStr.find("ABCDEABCDE==");
 822                           
 823                           for ( Uint32 i = pos; i < pos+strlen("ABCDEABCDE=="); i++)
 824                               testStr[i] = 'X';
 825                       
 826 sushma.fernandes 1.30     return(compare(FILE4, testStr.getCString()));
 827                       }
 828                       
 829 thilo.boehm      1.39 
 830                       //----------------------------------------------------------
 831                       // Tests for the traceMemoryHandler
 832                       //----------------------------------------------------------
 833                       typedef struct TTTParmType
 834                       {
 835                           Thread *trd;
 836                           TraceMemoryHandler *trcHandler;
 837                           const char* trcMessage;
 838                           Uint32 msgLen;
 839                           Uint32 number;
 840                           Boolean isVariableMsg;
 841                       } TTTParm;
 842                       
 843                       
 844                       void traceVariableArgs( TraceMemoryHandler *trcHdler,
 845                                               const char* msg, Uint32 msgLen, const char* fmt, ...)
 846                       {
 847                           va_list ap;
 848                           va_start(ap, fmt);
 849                           trcHdler->handleMessage(msg, msgLen, fmt, ap);
 850 thilo.boehm      1.39     va_end(ap);
 851                       }
 852                       
 853                       ThreadReturnType PEGASUS_THREAD_CDECL tracerThread( void* parm )
 854                       {
 855                           Thread *my_handle = (Thread *)parm;
 856                           TTTParm * my_parm = (TTTParm *)my_handle->get_parm();
 857                          
 858                           Threads::sleep(1);
 859                           for (Uint32 x=0; x < my_parm->number; x++)
 860                           {
 861                               if (x % 911 == 0 )
 862                               {
 863                                   // Give other threads time to run.
 864                                   Threads::sleep(1);
 865                               }
 866                               if (my_parm->isVariableMsg)
 867                               {
 868                                   traceVariableArgs(my_parm->trcHandler,
 869                                                     my_parm->trcMessage,
 870                                                     my_parm->msgLen,
 871 thilo.boehm      1.39                               my_parm->trcMessage,
 872                                                     VAR_TEST_MESSAGE);
 873                               }
 874                               else
 875                               {
 876                                   my_parm->trcHandler->handleMessage(my_parm->trcMessage,
 877                                                                      my_parm->msgLen);
 878                               }                                           
 879                           }
 880                           
 881                           return ThreadReturnType(0);
 882                       }
 883                       
 884                       Uint32 testMemoryHandler(const char* filename)
 885                       {
 886                           #define NUM_TEST_THREADS 99
 887                           Uint32 rc = 0;
 888                       
 889                           TraceMemoryHandler *trcHdler = new TraceMemoryHandler();
 890                           
 891                           const char* trcMsg1 = "1START A short trace message. END1";
 892 thilo.boehm      1.39     const char* trcMsg2 = "2START A trace message which is a little longer "
 893                                                 "than the previous trace message. END2";
 894                           const char* trcMsg3 = "3START A trace message which is much longer than "
 895                                                 "the previous trace messages, which were small and a "
 896                                                 "little larger, but this one is at least double the "
 897                                                 "size as both others together. END3";
 898                           const char* trcMsg4 = "4START <%s> END4";
 899                           const char* trcMsgs[] = { trcMsg1, trcMsg2, trcMsg3, trcMsg4 };
 900                           Uint32 numMsgs = sizeof(trcMsgs) / sizeof(const char*);
 901                       
 902                           TTTParm *tttParms[NUM_TEST_THREADS];
 903                           
 904                           for (int x=0; x < NUM_TEST_THREADS; x++)
 905                           {
 906                               Uint32 msgNumber = x%numMsgs;
 907                               tttParms[x] = new TTTParm();
 908                               tttParms[x]->trd = 0;
 909                               tttParms[x]->trcHandler = trcHdler;
 910                               tttParms[x]->trcMessage = trcMsgs[msgNumber];
 911                               tttParms[x]->msgLen = strlen(trcMsgs[msgNumber]);
 912                               tttParms[x]->number = 100000;
 913 thilo.boehm      1.39         // Is the message a variable one (= the last in the list)?
 914                               tttParms[x]->isVariableMsg = (msgNumber == (numMsgs-1));
 915                           }
 916                           
 917                           for (int x=0; x < NUM_TEST_THREADS; x++)
 918                           {
 919                               tttParms[x]->trd = new Thread(tracerThread, tttParms[x], false);
 920                               tttParms[x]->trd->run();
 921                           }
 922                       
 923                           for (int x=0; x < NUM_TEST_THREADS; x++)
 924                           {
 925                               tttParms[x]->trd->join();
 926                           }
 927                           
 928                           
 929                           if (!trcHdler->isValidMessageDestination(filename))
 930                           {
 931                               cout << "Failure in call to isValidMessageDestination for file \""
 932                                       << filename << "\"\n" << endl;
 933                               PEGASUS_TEST_ASSERT(0);
 934 thilo.boehm      1.39     }
 935                           trcHdler->setMessageDestination(filename);
 936                           trcHdler->flushTrace();
 937                           
 938                           // To test the variable messages, we replace the variable message
 939                           // in the list with a resolved copy.
 940                           Uint32 lastMsg = numMsgs-1;
 941                           char resolvedMsg[1024];
 942                           memcpy( resolvedMsg, trcMsgs[lastMsg], strlen(trcMsgs[lastMsg]) );
 943                           sprintf( resolvedMsg+strlen(trcMsgs[lastMsg]),
 944                                    trcMsgs[lastMsg],
 945                                    VAR_TEST_MESSAGE );
 946                           trcMsgs[lastMsg] = resolvedMsg;
 947                           
 948                       
 949                           
 950                           // Now analyze the dumped buffer content, to ensure no messages
 951                           // were damaged.
 952                           // For this we read the buffer content line by line and check if it 
 953                           // matches one of the messages from the list above.
 954                           {
 955 thilo.boehm      1.39         fstream file;
 956                               file.open(filename, fstream::in);
 957                               if (!file.good())
 958                               {
 959                                   cout << "Failed to open file \"" << filename << "\"\n" << endl;
 960                                   PEGASUS_TEST_ASSERT(0);
 961                               }
 962                           
 963                               // Keep the first line on the side, since this is probably the 
 964                               // wrapped remainder of the very last messsage in the buffer.
 965                               char firstLine[256];
 966                               file.getline( firstLine, 256 );
 967                       
 968                               char currentLine[256];
 969                               file.getline( currentLine, 256 );
 970                       
 971                               while( !file.eof() )
 972                               {
 973                                   Boolean found = false;
 974                                   for (Uint32 x=0; x < numMsgs; x++)
 975                                   {
 976 thilo.boehm      1.39                 if ( strcmp(trcMsgs[x], currentLine) == 0 )
 977                                       {
 978                                           found = true;
 979                                           continue;
 980                                       }
 981                                   }
 982                                   if ( !found )
 983                                   {
 984                                       if ( strncmp(currentLine, "*EOTRACE*", strlen("*EOTRACE*")) )
 985                                       {
 986                                           // if we got here, this is either an error, or we reached
 987                                           // the end of the trace buffer, where it had wrapped.
 988                                           // To check this we paste together the message in the
 989                                           // first line we read, and which is supposed to be the 
 990                                           // remainder of the wrapped message.
 991                                           strcat(currentLine, firstLine);
 992                                           for (Uint32 x=0; x < numMsgs; x++)
 993                                           {
 994                                               if ( strcmp(trcMsgs[x], currentLine) == 0 )
 995                                               {
 996                                                   found = true;
 997 thilo.boehm      1.39                             continue;
 998                                               }
 999                                           }
1000                                           if ( !found )
1001                                           {
1002                                               // Diagnostics about the error
1003                                               cout << "Compare Error: unexpected message= \n\""
1004                                                    << currentLine << "\"\n" << endl;
1005                                               PEGASUS_TEST_ASSERT(0);
1006                                           }
1007                                       }
1008                                   }
1009                                   file.getline( currentLine, 256 );
1010                               }
1011                               file.close();
1012                           }
1013                       
1014                       
1015                           for (int x=0; x < NUM_TEST_THREADS; x++)
1016                           {
1017                               delete( tttParms[x]->trd );
1018 thilo.boehm      1.39         delete( tttParms[x] );
1019                           }
1020                       
1021                           delete( trcHdler );
1022                           return rc;
1023                       }
1024                       
1025                       
1026                       
1027 karl             1.7  int main(int argc, char** argv)
1028 mike             1.2  {
1029                       
1030                       // Execute the tests only if trace calls are included
1031                       
1032                       #ifdef PEGASUS_REMOVE_TRACE
1033 karl             1.7      cout << argv[0] << " +++++ passed all tests" << endl;
1034 mike             1.2      return 0;
1035                       #else
1036 kumpf            1.11 
1037                           const char* tmpDir = getenv ("PEGASUS_TMP");
1038                           if (tmpDir == NULL)
1039                           {
1040                               tmpDir = ".";
1041                           }
1042                           String f1 (tmpDir);
1043 kumpf            1.13     f1.append("/testtracer1.trace");
1044 kumpf            1.14     FILE1 = f1.getCString();
1045 kumpf            1.11     String f2 (tmpDir);
1046 kumpf            1.13     f2.append("/testtracer2.trace");
1047 kumpf            1.14     FILE2 = f2.getCString();
1048 kumpf            1.11     String f3 (tmpDir);
1049 kumpf            1.13     f3.append("/testtracer3.trace");
1050 kumpf            1.14     FILE3 = f3.getCString();
1051 kumpf            1.11     String f4 (tmpDir);
1052 kumpf            1.13     f4.append("/testtracer4.trace");
1053 kumpf            1.14     FILE4 = f4.getCString();
1054 thilo.boehm      1.39     String f5 (tmpDir);
1055                           f5.append("/testtracer5.trace");
1056                           FILE5 = f5.getCString();
1057 kumpf            1.11 
1058 mike             1.2      System::removeFile(FILE1);
1059                           System::removeFile(FILE2);
1060                           System::removeFile(FILE3);
1061 kumpf            1.4      System::removeFile(FILE4);
1062 thilo.boehm      1.39     System::removeFile(FILE5);
1063 kumpf            1.34     if (test1() != 0)
1064 mike             1.2      {
1065                              cout << "Tracer test (test1) failed" << endl;
1066                              exit(1);
1067                           }
1068 kumpf            1.34     if (test2() != 0)
1069 mike             1.2      {
1070                              cout << "Tracer test (test2) failed" << endl;
1071                              exit(1);
1072                           }
1073 kumpf            1.34     if (test3() != 0)
1074 mike             1.2      {
1075                              cout << "Tracer test (test3) failed" << endl;
1076                              exit(1);
1077                           }
1078                           if (test4() != 0)
1079                           {
1080                              cout << "Tracer test (test4) failed" << endl;
1081                              exit(1);
1082                           }
1083                           if (test5() != 0)
1084                           {
1085                              cout << "Tracer test (test5) failed" << endl;
1086                              exit(1);
1087                           }
1088                           if (test6() != 0)
1089                           {
1090                              cout << "Tracer test (test6) failed" << endl;
1091                              exit(1);
1092                           }
1093                           if (test7() != 0)
1094                           {
1095 mike             1.2         cout << "Tracer test (test7) failed" << endl;
1096                              exit(1);
1097                           }
1098                           if (test9() != 0)
1099                           {
1100                              cout << "Tracer test (test9) failed" << endl;
1101                              exit(1);
1102                           }
1103 karl             1.27     /*************************** 
1104                              Test 10 bypassed when tests changed to
1105                              use macros.  It did an invalid call which is
1106                              not possible with macros
1107                       
1108 mike             1.2      if (test10() != 0)
1109                           {
1110                              cout << "Tracer test (test10) failed" << endl;
1111                              exit(1);
1112                           }
1113 karl             1.27     ******************************/
1114 mike             1.2      if (test11() != 0)
1115                           {
1116                              cout << "Tracer test (test11) failed" << endl;
1117                              exit(1);
1118                           }
1119                           if (test12() != 0)
1120                           {
1121                              cout << "Tracer test (test12) failed" << endl;
1122                              exit(1);
1123                           }
1124                           if (test13() != 0)
1125                           {
1126                              cout << "Tracer test (test13) failed" << endl;
1127                              exit(1);
1128                           }
1129                           if (test14() != 0)
1130                           {
1131                              cout << "Tracer test (test14) failed" << endl;
1132                              exit(1);
1133                           }
1134                           if (test15() != 0)
1135 mike             1.2      {
1136                              cout << "Tracer test (test15) failed" << endl;
1137                              exit(1);
1138                           }
1139 marek            1.37 # ifndef PEGASUS_REMOVE_METHODTRACE
1140 marek            1.35     if (test15a() != 0)
1141                           {
1142                              cout << "Tracer test (test15a) failed" << endl;
1143                              exit(1);
1144                           }
1145                           if (test15b() != 0)
1146                           {
1147                              cout << "Tracer test (test15b) failed" << endl;
1148                              exit(1);
1149                           }
1150 marek            1.37 # endif
1151 mike             1.2      if (test16() != 0)
1152                           {
1153                              cout << "Tracer test (test16) failed" << endl;
1154 kumpf            1.3         exit(1);
1155                           }
1156                           if (test17() != 0)
1157                           {
1158                              cout << "Tracer test (test17) failed" << endl;
1159                              exit(1);
1160                           }
1161                           if (test18() != 0)
1162                           {
1163                              cout << "Tracer test (test18) failed" << endl;
1164                              exit(1);
1165                           }
1166 kumpf            1.4      if (test20() != 0)
1167                           {
1168                              cout << "Tracer test (test20) failed" << endl;
1169                              exit(1);
1170                           }
1171                           if (test21() != 0)
1172                           {
1173                              cout << "Tracer test (test21) failed" << endl;
1174                              exit(1);
1175                           }
1176                           if (test22() != 0)
1177                           {
1178                              cout << "Tracer test (test22) failed" << endl;
1179                              exit(1);
1180                           }
1181 marek            1.28     if (test23() != 0)
1182                           {
1183                              cout << "Tracer test (test23) failed" << endl;
1184                              exit(1);
1185                           }
1186 sushma.fernandes 1.30     if (test24() != 0)
1187                           {
1188                              cout << "Tracer test (test24) failed" << endl;
1189                              exit(1);
1190                           }
1191                       
1192                           if (test25() != 0)
1193                           {
1194                              cout << "Tracer test (test25) failed" << endl;
1195                              exit(1);
1196                           }
1197 r.kieninger      1.36     if (test26() != 0)
1198                           {
1199                              cout << "Tracer test (test26) failed" << endl;
1200                              exit(1);
1201                           }
1202                       
1203                           if (test27() != 0)
1204                           {
1205                              cout << "Tracer test (test27) failed" << endl;
1206                              exit(1);
1207                           }
1208 sushma.fernandes 1.30 
1209 thilo.boehm      1.39     if (testMemoryHandler(FILE5) != 0)
1210                           {
1211                              cout << "Tracer test (testMemoryHandler) failed" << endl;
1212                              exit(1);
1213                           }
1214                       
1215                       
1216 karl             1.7      cout << argv[0] << " +++++ passed all tests" << endl;
1217 mike             1.2      System::removeFile(FILE1);
1218                           System::removeFile(FILE2);
1219                           System::removeFile(FILE3);
1220 kumpf            1.4      System::removeFile(FILE4);
1221 thilo.boehm      1.39     System::removeFile(FILE5);
1222 mike             1.2      return 0;
1223                       #endif
1224                       }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2