(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 kumpf            1.43 //
  73                       // Reads the last trace message from a given trace file and compares the
  74 mike             1.2  // 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 karl             1.27 
 126 mike             1.2      return retCode;
 127                       }
 128                       
 129                       //
 130                       // Description:
 131                       // Trace properties file, level and component are not set
 132                       // Should not log a trace message
 133                       //
 134                       // Type:
 135 kumpf            1.43 // Negative
 136 mike             1.2  //
 137                       // return 0 if the test passed
 138                       // return 1 if the test failed
 139                       //
 140                       Uint32 test1()
 141                       {
 142                           const char* METHOD_NAME = "test1";
 143 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 144 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %d",
 145                               "This message should not appear value=",123));
 146 kumpf            1.10     PEG_METHOD_EXIT();
 147 kumpf            1.34     return System::exists(FILE1) ? 1 : 0;
 148 mike             1.2  }
 149                       
 150                       //
 151                       // Description:
 152                       // Trace properties level and component are not set
 153                       // Should not log a trace message
 154                       //
 155                       // Type:
 156 kumpf            1.43 // Negative
 157 mike             1.2  //
 158                       // return 0 if the test passed
 159                       // return 1 if the test failed
 160                       //
 161                       Uint32 test2()
 162                       {
 163                           const char* METHOD_NAME = "test2";
 164                           Tracer::setTraceFile(FILE1);
 165 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 166 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %d",
 167                               "This message should not appear value=",123));
 168 thilo.boehm      1.42     Uint32 fileSize = 0;
 169 kumpf            1.34     System::getFileSize(FILE1, fileSize);
 170                           return (fileSize == 0) ? 0 : 1;
 171 mike             1.2  }
 172                       
 173                       //
 174                       // Description:
 175                       // Trace properties component is not set
 176                       // Should not log a trace message
 177                       //
 178                       // Type:
 179 kumpf            1.43 // Negative
 180 mike             1.2  //
 181                       // return 0 if the test passed
 182                       // return 1 if the test failed
 183                       //
 184                       Uint32 test3()
 185                       {
 186                           const char* METHOD_NAME = "test3";
 187                           Tracer::setTraceLevel(Tracer::LEVEL1);
 188 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 189 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s",
 190                               "This message should not appear"));
 191 thilo.boehm      1.42     Uint32 fileSize = 0;
 192 kumpf            1.34     System::getFileSize(FILE1, fileSize);
 193                           return (fileSize == 0) ? 0 : 1;
 194 mike             1.2  }
 195                       
 196                       //
 197                       // Description:
 198                       // Trace properties file, level and component are set
 199                       // should log a trace message
 200                       //
 201                       // Type:
 202 kumpf            1.43 // Positive
 203 mike             1.2  //
 204                       // return 0 if the test passed
 205                       // return 1 if the test failed
 206                       //
 207                       Uint32 test4()
 208                       {
 209                           const char* METHOD_NAME = "test4";
 210 marek            1.37     Tracer::setTraceLevel(Tracer::LEVEL1);
 211 mike             1.2      Tracer::setTraceComponents("Config");
 212 marek            1.37     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,METHOD_NAME);
 213                           return(compare(FILE1,METHOD_NAME));
 214 mike             1.2  }
 215                       
 216                       //
 217                       // Description:
 218                       // Trace component is set to an invalid component
 219                       // should not log a trace message
 220                       //
 221                       // Type:
 222 kumpf            1.43 // Negative
 223 mike             1.2  //
 224                       // return 0 if the test passed
 225                       // return 1 if the test failed
 226                       //
 227                       Uint32 test5()
 228                       {
 229                           const char* METHOD_NAME = "test5";
 230                           Tracer::setTraceComponents("Wrong Component Name");
 231 karl             1.27 
 232                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 233 marek            1.37     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,METHOD_NAME);
 234 karl             1.27     PEG_METHOD_EXIT();
 235 marek            1.37     return(compare(FILE1,"test4"));
 236 mike             1.2  }
 237                       
 238                       //
 239                       // Description:
 240 kumpf            1.43 // Trace level is set to LEVEL 2 and logs a LEVEL 4 message
 241 mike             1.2  // should not log a trace message
 242                       //
 243                       // Type:
 244 kumpf            1.43 // Negative
 245 mike             1.2  //
 246                       // return 0 if the test passed
 247                       // return 1 if the test failed
 248                       //
 249                       
 250                       Uint32 test6()
 251                       {
 252                           const char* METHOD_NAME = "test6";
 253                           Tracer::setTraceComponents("Config");
 254                           Tracer::setTraceLevel(Tracer::LEVEL2);
 255 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
 256                               "Test Message for Level2 in",METHOD_NAME));
 257                           PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
 258                               "Test Message for Level2 in",METHOD_NAME));
 259                           PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s",
 260                               "This Message should not appear"));
 261 mike             1.2      return(compare(FILE1,"Test Message for Level2 in test6"));
 262                       }
 263                       
 264                       //
 265                       // Description:
 266                       // Trace level is set to an invalid level
 267                       // should not log a trace message
 268                       //
 269                       // Type:
 270 kumpf            1.43 // Negative
 271 mike             1.2  //
 272                       // return 0 if the test passed
 273                       // return 1 if the test failed
 274                       //
 275                       Uint32 test7()
 276                       {
 277                           const char* METHOD_NAME = "test7";
 278                           Tracer::setTraceLevel(100);
 279 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 280                           PEG_METHOD_EXIT();
 281 mike             1.2      return(compare(FILE1,"Test Message for Level2 in test6"));
 282                       }
 283                       
 284                       //
 285                       // Description:
 286 kumpf            1.43 // Changes the trace file to FILE2
 287 mike             1.2  //
 288                       // Type:
 289 kumpf            1.43 // Positive
 290 mike             1.2  //
 291                       // return 0 if the test passed
 292                       // return 1 if the test failed
 293                       //
 294                       Uint32 test9()
 295                       {
 296                           const char* METHOD_NAME = "test9";
 297                           Tracer::setTraceLevel(Tracer::LEVEL3);
 298                           Tracer::setTraceFile(FILE2);
 299                       
 300 kumpf            1.10     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 301 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
 302                               "Test Message for Level3 in",METHOD_NAME));
 303 mike             1.2      return(compare(FILE2,"Test Message for Level3 in test9"));
 304                       }
 305                       
 306                       //
 307                       // Description:
 308                       // Passes invalid component in the trace call
 309                       // should not log a trace message
 310                       //
 311                       // Type:
 312 kumpf            1.43 // Negative
 313 mike             1.2  //
 314                       // return 0 if the test passed
 315                       // return 1 if the test failed
 316                       //
 317 marek            1.35 // This test not required with change to
 318 karl             1.27 // use and test macros only.
 319 mike             1.2  
 320                       Uint32 test10()
 321                       {
 322                           const char* METHOD_NAME = "test10";
 323                           Tracer::setTraceComponents("ALL");
 324 karl             1.27     PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 325                           PEG_METHOD_EXIT();
 326 mike             1.2      return(compare(FILE2,"Test Message for Level3 in test9"));
 327                       }
 328                       
 329                       //
 330                       // Description:
 331 marek            1.35 // Trace is set to level 0
 332                       // should not log a trace message
 333 mike             1.2  //
 334                       // Type:
 335 marek            1.35 // Negative
 336 mike             1.2  //
 337                       // return 0 if the test passed
 338                       // return 1 if the test failed
 339                       //
 340                       
 341                       Uint32 test11()
 342                       {
 343                           const char* METHOD_NAME = "test11";
 344                           Tracer::setTraceComponents("ALL");
 345 marek            1.35     Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL0);
 346                           PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
 347                               "Test Message for Level0 in",METHOD_NAME));
 348                           return(compare(FILE2,"Test Message for Level3 in test9"));
 349 mike             1.2  }
 350                       
 351                       //
 352                       // Description:
 353                       // Implements trace call for Tracer::Level1
 354                       // should log a trace message
 355                       //
 356                       // Type:
 357 kumpf            1.43 // Positive
 358 mike             1.2  //
 359                       // return 0 if the test passed
 360                       // return 1 if the test failed
 361                       //
 362                       
 363                       Uint32 test12()
 364                       {
 365                           const char* METHOD_NAME = "test12";
 366                           Tracer::setTraceComponents("ALL");
 367                           Tracer::setTraceLevel(Tracer::LEVEL4);
 368 marek            1.35     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,"%s %s",
 369                               "Test Message for Level1 in",METHOD_NAME));
 370                           return(compare(FILE2,"Test Message for Level1 in test12"));
 371 mike             1.2  }
 372                       
 373                       //
 374                       // Description:
 375                       // Implements trace call for Tracer::Level2
 376                       // should log a trace message
 377                       //
 378                       // Type:
 379 kumpf            1.43 // Positive
 380 mike             1.2  //
 381                       // return 0 if the test passed
 382                       // return 1 if the test failed
 383                       //
 384                       
 385                       Uint32 test13()
 386                       {
 387                           const char* METHOD_NAME = "test13";
 388                           Tracer::setTraceComponents("ALL");
 389                           Tracer::setTraceLevel(Tracer::LEVEL4);
 390 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL2,"%s %s",
 391                               "Test Message for Level2 in",METHOD_NAME));
 392 mike             1.2      return(compare(FILE2,"Test Message for Level2 in test13"));
 393                       }
 394                       
 395                       //
 396                       // Description:
 397                       // Implements trace call for Tracer::Level3
 398                       // should log a trace message
 399                       //
 400                       // Type:
 401 kumpf            1.43 // Positive
 402 mike             1.2  //
 403                       // return 0 if the test passed
 404                       // return 1 if the test failed
 405                       //
 406                       
 407                       Uint32 test14()
 408                       {
 409                           const char* METHOD_NAME = "test14";
 410                           Tracer::setTraceComponents("ALL");
 411                           Tracer::setTraceLevel(Tracer::LEVEL4);
 412                           Tracer::setTraceFile(FILE3);
 413 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL3,"%s %s",
 414                               "Test Message for Level3 in",METHOD_NAME));
 415 mike             1.2      return(compare(FILE3,"Test Message for Level3 in test14"));
 416                       }
 417                       
 418                       //
 419                       // Description:
 420                       // Implements trace call for Tracer::Level4
 421                       // should log a trace message
 422                       //
 423                       // Type:
 424 kumpf            1.43 // Positive
 425 mike             1.2  //
 426                       // return 0 if the test passed
 427                       // return 1 if the test failed
 428                       //
 429                       
 430                       Uint32 test15()
 431                       {
 432                           const char* METHOD_NAME = "test15";
 433                           Tracer::setTraceComponents("ALL");
 434                           Tracer::setTraceLevel(Tracer::LEVEL4);
 435 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
 436                               "Test Message for Level4 in",METHOD_NAME));
 437 mike             1.2      return(compare(FILE3,"Test Message for Level4 in test15"));
 438                       }
 439                       
 440                       //
 441                       // Description:
 442 marek            1.35 // Implements trace call for Tracer::Level5 (trace enter/exit)
 443                       // should log a trace message
 444                       //
 445                       // Type:
 446 kumpf            1.43 // Positive
 447 marek            1.35 //
 448                       // return 0 if the test passed
 449                       // return 1 if the test failed
 450                       //
 451                       
 452                       Uint32 test15a()
 453                       {
 454                           const char* METHOD_NAME = "test15a";
 455                           Tracer::setTraceComponents("ALL");
 456                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 457                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 458                           return(compare(FILE3,"Entering method test15a"));
 459                       }
 460                       
 461                       //
 462                       // Description:
 463                       // Implements trace call for Tracer::Level5 (trace enter/exit)
 464                       // should log a trace message
 465                       //
 466                       // Type:
 467 kumpf            1.43 // Positive
 468 marek            1.35 //
 469                       // return 0 if the test passed
 470                       // return 1 if the test failed
 471                       //
 472                       
 473                       Uint32 test15b()
 474                       {
 475                           const char* METHOD_NAME = "test15b";
 476                           Tracer::setTraceComponents("ALL");
 477                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 478                           PEG_METHOD_ENTER(TRC_CONFIG,METHOD_NAME);
 479                           PEG_METHOD_EXIT();
 480                           return(compare(FILE3,"Exiting method test15b"));
 481                       }
 482                       
 483                       //
 484                       // Description:
 485 mike             1.2  // calls the setTraceComponents with null string
 486 marek            1.35 // should not log a trace message
 487 mike             1.2  //
 488                       // Type:
 489 kumpf            1.43 // Negative
 490 mike             1.2  //
 491                       // return 0 if the test passed
 492                       // return 1 if the test failed
 493                       //
 494                       
 495                       Uint32 test16()
 496                       {
 497                           const char* METHOD_NAME = "test16";
 498 marek            1.37     Tracer::setTraceComponents("ALL");
 499                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 500 kumpf            1.43     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,"test16 - check value");
 501 mike             1.2      Tracer::setTraceComponents("");
 502                           Tracer::setTraceLevel(Tracer::LEVEL4);
 503 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
 504                           "This Message should not appear in",METHOD_NAME));
 505 marek            1.37     return(compare(FILE3,"test16 - check value"));
 506 mike             1.2  }
 507                       
 508                       //
 509                       // Description:
 510                       // calls the setTraceComponents with one valid and another invalid component
 511                       // should log a trace message
 512                       //
 513                       // Type:
 514 kumpf            1.43 // Negative
 515 mike             1.2  //
 516                       // return 0 if the test passed
 517                       // return 1 if the test failed
 518                       //
 519                       
 520                       Uint32 test17()
 521                       {
 522                           const char* METHOD_NAME = "test17";
 523 marek            1.37     Tracer::setTraceComponents("ALL");
 524                           Tracer::setTraceLevel(PEGASUS_TRACER_LEVEL5);
 525 kumpf            1.43     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,"test17 - check value");
 526 kumpf            1.3      Tracer::setTraceComponents("InvalidComp");
 527 mike             1.2      Tracer::setTraceLevel(Tracer::LEVEL4);
 528 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,"%s %s",
 529                           "This Message should not appear in",METHOD_NAME));
 530 marek            1.37     return(compare(FILE3,"test17 - check value"));
 531 mike             1.2  }
 532 kumpf            1.3  //
 533                       // Description:
 534                       // calls the _traceBuffer call
 535                       // should log a trace message
 536                       //
 537                       // Type:
 538                       // Positive
 539                       //
 540                       // return 0 if the test passed
 541                       // return 1 if the test failed
 542                       //
 543                       
 544                       Uint32 test18()
 545                       {
 546                           const char* METHOD_NAME = "test18";
 547                           Tracer::setTraceComponents("Config,InvalidComp");
 548                           Tracer::setTraceLevel(Tracer::LEVEL4);
 549 marek            1.33     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 550 marek            1.28         "This Message should appear in");
 551                           return(compare(FILE3,"This Message should appear in"));
 552 kumpf            1.3  }
 553 mike             1.2  
 554 kumpf            1.4  //
 555                       // Description:
 556                       // Trace a string.
 557 marek            1.33 // Calls the PEG_TRACE macro
 558 kumpf            1.4  // should log a trace message
 559                       //
 560                       // Type:
 561                       // Positive
 562                       //
 563                       // return 0 if the test passed
 564                       // return 1 if the test failed
 565                       //
 566                       
 567                       Uint32 test20()
 568                       {
 569                           const char* METHOD_NAME = "test20";
 570                           Tracer::setTraceFile(FILE4);
 571                           Tracer::setTraceComponents("ALL");
 572                           Tracer::setTraceLevel(Tracer::LEVEL4);
 573                       
 574                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 575 marek            1.33     PEG_TRACE((TRC_CONFIG,Tracer::LEVEL4,
 576                           "Test Message for Level4 in test20"));
 577 kumpf            1.4      return(compare(FILE4,"Test Message for Level4 in test20"));
 578                       }
 579                       
 580                       //
 581                       // Description:
 582                       // Trace a CIMException.
 583                       // Calls the traceCIMException() method
 584                       // should log a trace message
 585                       //
 586                       // Type:
 587                       // Positive
 588                       //
 589                       // return 0 if the test passed
 590                       // return 1 if the test failed
 591                       //
 592                       
 593                       Uint32 test21()
 594                       {
 595                           const char* METHOD_NAME = "test21";
 596                           Tracer::setTraceFile(FILE4);
 597                           Tracer::setTraceComponents("ALL");
 598 kumpf            1.4      Tracer::setTraceLevel(Tracer::LEVEL4);
 599                       
 600                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 601                       
 602                           // test tracing CIMException
 603                           try
 604                           {
 605                               throw PEGASUS_CIM_EXCEPTION(
 606 kumpf            1.43             CIM_ERR_NOT_SUPPORTED,
 607 kumpf            1.4              "CIM Exception Message for Level4 in test21.");
 608                           }
 609 kumpf            1.12     catch (CIMException& e)
 610 kumpf            1.4      {
 611                               Tracer::traceCIMException(TRC_CONFIG,Tracer::LEVEL4, e);
 612                           }
 613                       
 614                           return 0;
 615                       }
 616                       
 617                       //
 618                       // Description:
 619                       // Trace a string using macro.
 620                       // should log a trace message
 621                       //
 622                       // Type:
 623                       // Positive
 624                       //
 625                       // return 0 if the test passed
 626                       // return 1 if the test failed
 627                       //
 628                       Uint32 test22()
 629                       {
 630                           const char* METHOD_NAME = "test22";
 631 kumpf            1.4      Tracer::setTraceFile(FILE4);
 632                           Tracer::setTraceComponents("ALL");
 633                           Tracer::setTraceLevel(Tracer::LEVEL4);
 634                       
 635                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 636                       
 637 thilo.boehm      1.38     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 638                               "Test message for Level4 in test22.");
 639 kumpf            1.4  
 640                           return(compare(FILE4,"Test message for Level4 in test22."));
 641                       }
 642                       
 643 marek            1.28 //
 644                       // Description:
 645                       // Trace a character string using macro.
 646                       // should log a trace message
 647                       //
 648                       // Type:
 649                       // Positive
 650                       //
 651                       // return 0 if the test passed
 652                       // return 1 if the test failed
 653                       //
 654                       Uint32 test23()
 655                       {
 656                           const char* METHOD_NAME = "test23";
 657                           Tracer::setTraceFile(FILE4);
 658                           Tracer::setTraceComponents("ALL");
 659                           Tracer::setTraceLevel(Tracer::LEVEL4);
 660                       
 661                           PEG_METHOD_ENTER(TRC_CONFIG, METHOD_NAME);
 662                       
 663 karl             1.29     PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 664                                             "Test message for Level4 in test23.");
 665 marek            1.28 
 666                           return(compare(FILE4,"Test message for Level4 in test23."));
 667                       }
 668                       
 669 r.kieninger      1.36 //
 670                       // Description:
 671                       // Change traceFacility to Logger
 672                       // No more trace messages should be written
 673                       //
 674                       // Type:
 675                       // Negative
 676                       //
 677                       // return 0 if the test passed
 678                       // return 1 if the test failed
 679                       //
 680                       Uint32 test24()
 681                       {
 682                           const char* METHOD_NAME = "test24";
 683                           Tracer::setTraceFacility("Log");
 684                           Tracer::setTraceFile(FILE4);
 685                           Tracer::setTraceComponents("ALL");
 686                           Tracer::setTraceLevel(Tracer::LEVEL4);
 687                       
 688                           PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 689                                             "Test message for traceFacility=Log in test24.");
 690 r.kieninger      1.36 
 691                           return(compare(FILE4,"Test message for Level4 in test23."));
 692                       }
 693                       
 694                       //
 695                       // Description:
 696                       // Change traceFacility back to File
 697                       // Trace messages should be written again
 698                       //
 699                       // Type:
 700                       // Positive
 701                       //
 702                       // return 0 if the test passed
 703                       // return 1 if the test failed
 704                       //
 705                       Uint32 test25()
 706                       {
 707                           const char* METHOD_NAME = "test25";
 708                           Tracer::setTraceFacility("File");
 709                           Tracer::setTraceFile(FILE4);
 710                           Tracer::setTraceComponents("ALL");
 711 r.kieninger      1.36     Tracer::setTraceLevel(Tracer::LEVEL4);
 712                       
 713                           PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL4,
 714                                             "Test message for traceFacility=File in test25.");
 715                       
 716                           return(compare(FILE4,"Test message for traceFacility=File in test25."));
 717                       }
 718                       
 719 kumpf            1.43 //
 720 sushma.fernandes 1.30 // Description:
 721                       // Test the getHTTPRequestMessage method.
 722                       //
 723                       // Type:
 724                       // Positive
 725                       // Tests with a HTTP Request without a basic authorization header.
 726                       // Message is written to trace file without any changes.
 727                       //
 728                       // return 0 if the test passed
 729                       // return 1 if the test failed
 730                       //
 731 r.kieninger      1.36 Uint32 test26()
 732 sushma.fernandes 1.30 {
 733                           Tracer::setTraceFile(FILE4);
 734                           Tracer::setTraceComponents("xmlio");
 735                           Tracer::setTraceLevel(Tracer::LEVEL2);
 736                       
 737                           Uint32 queueId = 18;
 738                           CIMPropertyList propertyList;
 739                           Buffer params;
 740                           AcceptLanguageList al;
 741 kumpf            1.43     ContentLanguageList cl;
 742 sushma.fernandes 1.30 
 743                           XmlWriter::appendClassNameIParameter(
 744                               params, "ClassName", CIMName("testclass"));
 745                           Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
 746                               "localhost",
 747 kumpf            1.43         CIMNamespaceName("test/cimv2"),
 748 sushma.fernandes 1.30         CIMName ("EnumerateInstanceNames"),
 749 kumpf            1.43         "12345",
 750 sushma.fernandes 1.30         HTTP_METHOD__POST,
 751                               "Basic: Authorization AAAAA",
 752                               al,
 753                               cl,
 754 mike             1.45         params,
 755                               false);
 756 sushma.fernandes 1.30 
 757                           SharedArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(
 758                                   buffer));
 759                       
 760                           PEG_TRACE((
 761 kumpf            1.43         TRC_XML_IO,
 762 sushma.fernandes 1.30         Tracer::LEVEL2,
 763                               "<!-- Request: queue id: %u -->\n%s",
 764                               queueId,
 765                               reqMsg.get()));
 766                       
 767                           return(compare(FILE4, buffer.getData()));
 768 kumpf            1.43 }
 769                       
 770                       //
 771 sushma.fernandes 1.30 // Description:
 772                       // Test the getHTTPRequestMessage method.
 773                       //
 774                       // Type:
 775                       // Positive
 776                       // Tests with a HTTP Request that contains a Basic authorization header.
 777 kumpf            1.43 // The user/password info in the message is suppressed before writing it to
 778 sushma.fernandes 1.30 // 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 kumpf            1.43 {
 785 sushma.fernandes 1.30     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 kumpf            1.43         params,
 799                               "ClassName",
 800 sushma.fernandes 1.30         CIMName("testclass"));
 801                           Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(
 802                               "localhost",
 803 kumpf            1.43         CIMNamespaceName("test/cimv2"),
 804 sushma.fernandes 1.30         CIMName ("EnumerateInstanceNames"),
 805 kumpf            1.43         MSGID,
 806 sushma.fernandes 1.30         HTTP_METHOD__POST,
 807                               authHeader,
 808                               al,
 809                               cl,
 810 mike             1.45         params,
 811                               false);
 812 sushma.fernandes 1.30 
 813                           PEG_TRACE((
 814 kumpf            1.43         TRC_XML_IO,
 815 sushma.fernandes 1.30         Tracer::LEVEL2,
 816                               "<!-- Request: queue id: %u -->\n%s",
 817                               queueId,
 818                               Tracer::getHTTPRequestMessage(
 819                                   buffer).get()));
 820 kumpf            1.43 
 821 sushma.fernandes 1.30     String testStr(buffer.getData());
 822                           Uint32 pos = testStr.find("ABCDEABCDE==");
 823 kumpf            1.43 
 824 sushma.fernandes 1.30     for ( Uint32 i = pos; i < pos+strlen("ABCDEABCDE=="); i++)
 825                               testStr[i] = 'X';
 826                       
 827                           return(compare(FILE4, testStr.getCString()));
 828                       }
 829                       
 830 thilo.boehm      1.39 
 831                       //----------------------------------------------------------
 832                       // Tests for the traceMemoryHandler
 833                       //----------------------------------------------------------
 834                       typedef struct TTTParmType
 835                       {
 836                           Thread *trd;
 837                           TraceMemoryHandler *trcHandler;
 838                           const char* trcMessage;
 839                           Uint32 msgLen;
 840                           Uint32 number;
 841                           Boolean isVariableMsg;
 842                       } TTTParm;
 843                       
 844                       
 845                       void traceVariableArgs( TraceMemoryHandler *trcHdler,
 846                                               const char* msg, Uint32 msgLen, const char* fmt, ...)
 847                       {
 848                           va_list ap;
 849                           va_start(ap, fmt);
 850                           trcHdler->handleMessage(msg, msgLen, fmt, ap);
 851 thilo.boehm      1.39     va_end(ap);
 852                       }
 853                       
 854                       ThreadReturnType PEGASUS_THREAD_CDECL tracerThread( void* parm )
 855                       {
 856                           Thread *my_handle = (Thread *)parm;
 857                           TTTParm * my_parm = (TTTParm *)my_handle->get_parm();
 858 kumpf            1.43 
 859 thilo.boehm      1.40     Threads::yield();
 860 thilo.boehm      1.39     for (Uint32 x=0; x < my_parm->number; x++)
 861                           {
 862                               if (x % 911 == 0 )
 863                               {
 864                                   // Give other threads time to run.
 865 thilo.boehm      1.40             Threads::yield();
 866 thilo.boehm      1.39         }
 867                               if (my_parm->isVariableMsg)
 868                               {
 869                                   traceVariableArgs(my_parm->trcHandler,
 870                                                     my_parm->trcMessage,
 871                                                     my_parm->msgLen,
 872                                                     my_parm->trcMessage,
 873                                                     VAR_TEST_MESSAGE);
 874                               }
 875                               else
 876                               {
 877                                   my_parm->trcHandler->handleMessage(my_parm->trcMessage,
 878                                                                      my_parm->msgLen);
 879 kumpf            1.43         }
 880 thilo.boehm      1.39     }
 881 kumpf            1.43 
 882 thilo.boehm      1.39     return ThreadReturnType(0);
 883                       }
 884                       
 885                       Uint32 testMemoryHandler(const char* filename)
 886                       {
 887                           #define NUM_TEST_THREADS 99
 888                           Uint32 rc = 0;
 889                       
 890                           TraceMemoryHandler *trcHdler = new TraceMemoryHandler();
 891 thilo.boehm      1.42 
 892 thilo.boehm      1.39     const char* trcMsg1 = "1START A short trace message. END1";
 893                           const char* trcMsg2 = "2START A trace message which is a little longer "
 894                                                 "than the previous trace message. END2";
 895                           const char* trcMsg3 = "3START A trace message which is much longer than "
 896                                                 "the previous trace messages, which were small and a "
 897                                                 "little larger, but this one is at least double the "
 898                                                 "size as both others together. END3";
 899                           const char* trcMsg4 = "4START <%s> END4";
 900                           const char* trcMsgs[] = { trcMsg1, trcMsg2, trcMsg3, trcMsg4 };
 901                           Uint32 numMsgs = sizeof(trcMsgs) / sizeof(const char*);
 902                       
 903                           TTTParm *tttParms[NUM_TEST_THREADS];
 904 kumpf            1.43 
 905 thilo.boehm      1.39     for (int x=0; x < NUM_TEST_THREADS; x++)
 906                           {
 907                               Uint32 msgNumber = x%numMsgs;
 908                               tttParms[x] = new TTTParm();
 909                               tttParms[x]->trd = 0;
 910                               tttParms[x]->trcHandler = trcHdler;
 911                               tttParms[x]->trcMessage = trcMsgs[msgNumber];
 912                               tttParms[x]->msgLen = strlen(trcMsgs[msgNumber]);
 913                               tttParms[x]->number = 100000;
 914                               // Is the message a variable one (= the last in the list)?
 915                               tttParms[x]->isVariableMsg = (msgNumber == (numMsgs-1));
 916                           }
 917 kumpf            1.43 
 918 thilo.boehm      1.39     for (int x=0; x < NUM_TEST_THREADS; x++)
 919                           {
 920                               tttParms[x]->trd = new Thread(tracerThread, tttParms[x], false);
 921                               tttParms[x]->trd->run();
 922                           }
 923                       
 924                           for (int x=0; x < NUM_TEST_THREADS; x++)
 925                           {
 926                               tttParms[x]->trd->join();
 927                           }
 928 kumpf            1.43 
 929 kumpf            1.44     // Setting an empty trace file name should fail.
 930                           PEGASUS_TEST_ASSERT(Tracer::setTraceFile(""));
 931 kumpf            1.43 
 932                           if (Tracer::setTraceFile(filename))
 933 thilo.boehm      1.39     {
 934 thilo.boehm      1.42         cout << "Failure in call to setTraceFile for file \""
 935 thilo.boehm      1.39                 << filename << "\"\n" << endl;
 936                               PEGASUS_TEST_ASSERT(0);
 937                           }
 938 kumpf            1.43 
 939 thilo.boehm      1.39     trcHdler->flushTrace();
 940 kumpf            1.43 
 941 thilo.boehm      1.39     // To test the variable messages, we replace the variable message
 942                           // in the list with a resolved copy.
 943                           Uint32 lastMsg = numMsgs-1;
 944                           char resolvedMsg[1024];
 945                           memcpy( resolvedMsg, trcMsgs[lastMsg], strlen(trcMsgs[lastMsg]) );
 946                           sprintf( resolvedMsg+strlen(trcMsgs[lastMsg]),
 947                                    trcMsgs[lastMsg],
 948                                    VAR_TEST_MESSAGE );
 949                           trcMsgs[lastMsg] = resolvedMsg;
 950                       
 951 kumpf            1.43 
 952 thilo.boehm      1.39     // Now analyze the dumped buffer content, to ensure no messages
 953                           // were damaged.
 954 kumpf            1.43     // For this we read the buffer content line by line and check if it
 955 thilo.boehm      1.39     // matches one of the messages from the list above.
 956                           {
 957                               fstream file;
 958                               file.open(filename, fstream::in);
 959                               if (!file.good())
 960                               {
 961                                   cout << "Failed to open file \"" << filename << "\"\n" << endl;
 962                                   PEGASUS_TEST_ASSERT(0);
 963                               }
 964 kumpf            1.43 
 965                               // Keep the first line on the side, since this is probably the
 966 thilo.boehm      1.39         // wrapped remainder of the very last messsage in the buffer.
 967                               char firstLine[256];
 968                               file.getline( firstLine, 256 );
 969                       
 970                               char currentLine[256];
 971                               file.getline( currentLine, 256 );
 972                       
 973                               while( !file.eof() )
 974                               {
 975                                   Boolean found = false;
 976                                   for (Uint32 x=0; x < numMsgs; x++)
 977                                   {
 978                                       if ( strcmp(trcMsgs[x], currentLine) == 0 )
 979                                       {
 980                                           found = true;
 981                                           continue;
 982                                       }
 983                                   }
 984                                   if ( !found )
 985                                   {
 986                                       if ( strncmp(currentLine, "*EOTRACE*", strlen("*EOTRACE*")) )
 987 thilo.boehm      1.39                 {
 988                                           // if we got here, this is either an error, or we reached
 989                                           // the end of the trace buffer, where it had wrapped.
 990                                           // To check this we paste together the message in the
 991 kumpf            1.43                     // first line we read, and which is supposed to be the
 992 thilo.boehm      1.39                     // remainder of the wrapped message.
 993                                           strcat(currentLine, firstLine);
 994                                           for (Uint32 x=0; x < numMsgs; x++)
 995                                           {
 996                                               if ( strcmp(trcMsgs[x], currentLine) == 0 )
 997                                               {
 998                                                   found = true;
 999                                                   continue;
1000                                               }
1001                                           }
1002                                           if ( !found )
1003                                           {
1004                                               // Diagnostics about the error
1005                                               cout << "Compare Error: unexpected message= \n\""
1006                                                    << currentLine << "\"\n" << endl;
1007                                               PEGASUS_TEST_ASSERT(0);
1008                                           }
1009                                       }
1010                                   }
1011                                   file.getline( currentLine, 256 );
1012                               }
1013 thilo.boehm      1.39         file.close();
1014                           }
1015                       
1016                       
1017                           for (int x=0; x < NUM_TEST_THREADS; x++)
1018                           {
1019                               delete( tttParms[x]->trd );
1020                               delete( tttParms[x] );
1021                           }
1022                       
1023 thilo.boehm      1.41     // test the wrapping of a too long message:
1024                           {
1025                               #define FIX_PART_OF_MESSAGE "LongMsg:"
1026                       
1027 kumpf            1.43         // The trace buffer is not at that size used for tracing
1028 thilo.boehm      1.41         // then it is defined with PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB*1024
1029                               // The resulting message is shriked by:
1030                               // * the controll structure traceArea_t ( privat of TraceMemoryHandler)
1031                               // * the fixed message part
1032                               // * the markers,  '\n' and '\0'
1033 kumpf            1.43         Uint32 bufferDelta = 2* sizeof(Uint32)+ sizeof(char*)
1034                                                  + PEGASUS_TRC_BUFFER_EYE_CATCHER_LEN
1035 thilo.boehm      1.41                            + strlen(FIX_PART_OF_MESSAGE)
1036                                                  + strlen(PEGASUS_TRC_BUFFER_TRUNC_MARKER) + 1
1037 kumpf            1.43                            + strlen(PEGASUS_TRC_BUFFER_EOT_MARKER)+ 1
1038                                                  // this adds the '2' before the truncation marker
1039 thilo.boehm      1.41                            // should appear in the message
1040                                                  + 1;
1041                       
1042                               Uint32 sizeOfVeryLongMSG=PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB*1024;
1043                       
1044                               // Construct the big message:
1045                               //  LongMsg:111...11122222222222222
1046                               char* veryLongMSG = (char *)malloc(sizeOfVeryLongMSG);
1047                               memset((void*)veryLongMSG,'1',sizeOfVeryLongMSG-bufferDelta);
1048                               memset((void*)&(veryLongMSG[sizeOfVeryLongMSG-bufferDelta]),
1049                                      '2',bufferDelta);
1050                               veryLongMSG[sizeOfVeryLongMSG-1] = 0 ;
1051                       
1052                               traceVariableArgs(trcHdler,
1053                                                 FIX_PART_OF_MESSAGE,
1054                                                 strlen(FIX_PART_OF_MESSAGE),
1055                                                "%s",
1056                                                 veryLongMSG);
1057                       
1058 thilo.boehm      1.42         Tracer::setTraceFile(filename);
1059 thilo.boehm      1.41         trcHdler->flushTrace();
1060                       
1061                               // resuse the buffer for reading the result file.
1062                               memset((void*)veryLongMSG,0,sizeOfVeryLongMSG);
1063                       
1064                               fstream file;
1065                               file.open(filename, fstream::in);
1066                               if (!file.good())
1067                               {
1068                                   cout << "Failed to open file \"" << filename << "\"\n" << endl;
1069                                   PEGASUS_TEST_ASSERT(0);
1070                               }
1071                       
1072                               // The first line must be the trucated big message.
1073                               file.getline( veryLongMSG, sizeOfVeryLongMSG );
1074                       
1075                               // The second line must be the end of trace marker
1076                               char lastLine[256];
1077                               file.getline( lastLine, 256 );
1078                       
1079                               // The result must be in the two lines. Close the file
1080 thilo.boehm      1.41         file.close();
1081                       
1082                               // the last line must be only the end of trace marker.
1083                               if ( strncmp(lastLine, "*EOTRACE*", strlen("*EOTRACE*")) )
1084                               {
1085                                       cout << "Compare Error: unexpected message= \n\""
1086                                            << lastLine << "\"\n" << endl;
1087                                       PEGASUS_TEST_ASSERT(0);
1088                               }
1089                       
1090                               char* cursor = veryLongMSG;
1091                       
1092 kumpf            1.43         // The big messsage has the format:
1093 thilo.boehm      1.41         //  LongMsg:111...1112*TRUNC*
1094                               // To validate that the message is truncated at the right position,
1095                               // only one '2' has to show up before the truncation marker.
1096 kumpf            1.43 
1097 thilo.boehm      1.41         if ( strncmp(cursor, FIX_PART_OF_MESSAGE
1098                                            , strlen(FIX_PART_OF_MESSAGE)) )
1099                               {
1100                                       cout << "Compare Error: unexpected message= \n\""
1101                                            << cursor << "\"\n" << endl;
1102                                       PEGASUS_TEST_ASSERT(0);
1103                               }
1104                       
1105                               cursor = cursor + strlen(FIX_PART_OF_MESSAGE);
1106                               int noErrors = 0;
1107                               for (int i = 0 ; i < (int)(sizeOfVeryLongMSG-bufferDelta); i++)
1108                               {
1109                                   if (cursor[i] != '1')
1110                                   {
1111                                       noErrors++;
1112                                       cout << "Compare Error: unexpected char '"
1113 kumpf            1.43                      <<  cursor[i] << "' at position "
1114 thilo.boehm      1.41                      << strlen(FIX_PART_OF_MESSAGE) + i
1115                                            << " expecting '1'." << endl;
1116                                       // limmit the number of printed errors to 20
1117                                       if (noErrors > 20 )
1118                                       {
1119                                           cout << "Too manny missmatches. Abort long message test"
1120                                                << endl;
1121                                           PEGASUS_TEST_ASSERT(0);
1122                                       }
1123                       
1124                                   }
1125                               }
1126                       
1127                               // If any error occures in the above test, exit the test.
1128                               if (noErrors != 0)
1129                               {
1130                                 PEGASUS_TEST_ASSERT(0);
1131                               }
1132                       
1133                               if (cursor[(sizeOfVeryLongMSG-bufferDelta)] != '2')
1134                               {
1135 thilo.boehm      1.41             cout << "Compare Error: unexpected char '"
1136 kumpf            1.43                  << cursor[(sizeOfVeryLongMSG-bufferDelta)] << "' at position "
1137                                        << strlen(FIX_PART_OF_MESSAGE) +
1138 thilo.boehm      1.41                        (sizeOfVeryLongMSG-bufferDelta)
1139                                        << " expecting '2'." << endl;
1140                               }
1141                       
1142                               cursor = cursor + (sizeOfVeryLongMSG-bufferDelta) + 1;
1143                               if ( strcmp(cursor, "*TRUNC*") )
1144                               {
1145                                       cout << "Compare Error: unexpected message= \n\""
1146                                            << cursor << "\"\n" << endl;
1147                                       PEGASUS_TEST_ASSERT(0);
1148                               }
1149                       
1150                               free(veryLongMSG);
1151                           }
1152                       
1153 thilo.boehm      1.39     delete( trcHdler );
1154                           return rc;
1155                       }
1156                       
1157                       
1158                       
1159 karl             1.7  int main(int argc, char** argv)
1160 mike             1.2  {
1161                       
1162                       // Execute the tests only if trace calls are included
1163                       
1164                       #ifdef PEGASUS_REMOVE_TRACE
1165 karl             1.7      cout << argv[0] << " +++++ passed all tests" << endl;
1166 mike             1.2      return 0;
1167                       #else
1168 kumpf            1.11 
1169                           const char* tmpDir = getenv ("PEGASUS_TMP");
1170                           if (tmpDir == NULL)
1171                           {
1172                               tmpDir = ".";
1173                           }
1174                           String f1 (tmpDir);
1175 kumpf            1.13     f1.append("/testtracer1.trace");
1176 kumpf            1.14     FILE1 = f1.getCString();
1177 kumpf            1.11     String f2 (tmpDir);
1178 kumpf            1.13     f2.append("/testtracer2.trace");
1179 kumpf            1.14     FILE2 = f2.getCString();
1180 kumpf            1.11     String f3 (tmpDir);
1181 kumpf            1.13     f3.append("/testtracer3.trace");
1182 kumpf            1.14     FILE3 = f3.getCString();
1183 kumpf            1.11     String f4 (tmpDir);
1184 kumpf            1.13     f4.append("/testtracer4.trace");
1185 kumpf            1.14     FILE4 = f4.getCString();
1186 thilo.boehm      1.39     String f5 (tmpDir);
1187                           f5.append("/testtracer5.trace");
1188                           FILE5 = f5.getCString();
1189 kumpf            1.11 
1190 mike             1.2      System::removeFile(FILE1);
1191                           System::removeFile(FILE2);
1192                           System::removeFile(FILE3);
1193 kumpf            1.4      System::removeFile(FILE4);
1194 thilo.boehm      1.39     System::removeFile(FILE5);
1195 kumpf            1.34     if (test1() != 0)
1196 mike             1.2      {
1197                              cout << "Tracer test (test1) failed" << endl;
1198                              exit(1);
1199                           }
1200 kumpf            1.34     if (test2() != 0)
1201 mike             1.2      {
1202                              cout << "Tracer test (test2) failed" << endl;
1203                              exit(1);
1204                           }
1205 kumpf            1.34     if (test3() != 0)
1206 mike             1.2      {
1207                              cout << "Tracer test (test3) failed" << endl;
1208                              exit(1);
1209                           }
1210                           if (test4() != 0)
1211                           {
1212                              cout << "Tracer test (test4) failed" << endl;
1213                              exit(1);
1214                           }
1215                           if (test5() != 0)
1216                           {
1217                              cout << "Tracer test (test5) failed" << endl;
1218                              exit(1);
1219                           }
1220                           if (test6() != 0)
1221                           {
1222                              cout << "Tracer test (test6) failed" << endl;
1223                              exit(1);
1224                           }
1225                           if (test7() != 0)
1226                           {
1227 mike             1.2         cout << "Tracer test (test7) failed" << endl;
1228                              exit(1);
1229                           }
1230                           if (test9() != 0)
1231                           {
1232                              cout << "Tracer test (test9) failed" << endl;
1233                              exit(1);
1234                           }
1235 kumpf            1.43     /***************************
1236 karl             1.27        Test 10 bypassed when tests changed to
1237                              use macros.  It did an invalid call which is
1238                              not possible with macros
1239                       
1240 mike             1.2      if (test10() != 0)
1241                           {
1242                              cout << "Tracer test (test10) failed" << endl;
1243                              exit(1);
1244                           }
1245 karl             1.27     ******************************/
1246 mike             1.2      if (test11() != 0)
1247                           {
1248                              cout << "Tracer test (test11) failed" << endl;
1249                              exit(1);
1250                           }
1251                           if (test12() != 0)
1252                           {
1253                              cout << "Tracer test (test12) failed" << endl;
1254                              exit(1);
1255                           }
1256                           if (test13() != 0)
1257                           {
1258                              cout << "Tracer test (test13) failed" << endl;
1259                              exit(1);
1260                           }
1261                           if (test14() != 0)
1262                           {
1263                              cout << "Tracer test (test14) failed" << endl;
1264                              exit(1);
1265                           }
1266                           if (test15() != 0)
1267 mike             1.2      {
1268                              cout << "Tracer test (test15) failed" << endl;
1269                              exit(1);
1270                           }
1271 marek            1.37 # ifndef PEGASUS_REMOVE_METHODTRACE
1272 marek            1.35     if (test15a() != 0)
1273                           {
1274                              cout << "Tracer test (test15a) failed" << endl;
1275                              exit(1);
1276                           }
1277                           if (test15b() != 0)
1278                           {
1279                              cout << "Tracer test (test15b) failed" << endl;
1280                              exit(1);
1281                           }
1282 marek            1.37 # endif
1283 mike             1.2      if (test16() != 0)
1284                           {
1285                              cout << "Tracer test (test16) failed" << endl;
1286 kumpf            1.3         exit(1);
1287                           }
1288                           if (test17() != 0)
1289                           {
1290                              cout << "Tracer test (test17) failed" << endl;
1291                              exit(1);
1292                           }
1293                           if (test18() != 0)
1294                           {
1295                              cout << "Tracer test (test18) failed" << endl;
1296                              exit(1);
1297                           }
1298 kumpf            1.4      if (test20() != 0)
1299                           {
1300                              cout << "Tracer test (test20) failed" << endl;
1301                              exit(1);
1302                           }
1303                           if (test21() != 0)
1304                           {
1305                              cout << "Tracer test (test21) failed" << endl;
1306                              exit(1);
1307                           }
1308                           if (test22() != 0)
1309                           {
1310                              cout << "Tracer test (test22) failed" << endl;
1311                              exit(1);
1312                           }
1313 marek            1.28     if (test23() != 0)
1314                           {
1315                              cout << "Tracer test (test23) failed" << endl;
1316                              exit(1);
1317                           }
1318 sushma.fernandes 1.30     if (test24() != 0)
1319                           {
1320                              cout << "Tracer test (test24) failed" << endl;
1321                              exit(1);
1322                           }
1323                       
1324                           if (test25() != 0)
1325                           {
1326                              cout << "Tracer test (test25) failed" << endl;
1327                              exit(1);
1328                           }
1329 r.kieninger      1.36     if (test26() != 0)
1330                           {
1331                              cout << "Tracer test (test26) failed" << endl;
1332                              exit(1);
1333                           }
1334                       
1335                           if (test27() != 0)
1336                           {
1337                              cout << "Tracer test (test27) failed" << endl;
1338                              exit(1);
1339                           }
1340 sushma.fernandes 1.30 
1341 thilo.boehm      1.39     if (testMemoryHandler(FILE5) != 0)
1342                           {
1343                              cout << "Tracer test (testMemoryHandler) failed" << endl;
1344                              exit(1);
1345                           }
1346                       
1347                       
1348 karl             1.7      cout << argv[0] << " +++++ passed all tests" << endl;
1349 mike             1.2      System::removeFile(FILE1);
1350                           System::removeFile(FILE2);
1351                           System::removeFile(FILE3);
1352 kumpf            1.4      System::removeFile(FILE4);
1353 thilo.boehm      1.39     System::removeFile(FILE5);
1354 mike             1.2      return 0;
1355                       #endif
1356                       }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2