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

Diff for /pegasus/src/Pegasus/Common/tests/Tracer/Tracer.cpp between version 1.27.22.2 and 1.28

version 1.27.22.2, 2007/05/25 17:39:01 version 1.28, 2007/03/16 17:16:51
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
   // Author: Sushma Fernandes (sushma_fernandes@hp.com)
   //
   // Modified By: Jenny Yu (jenny_yu@hp.com)
   //              Carol Ann Krug Graves, Hewlett-Packard Company
   //                (carolann_graves@hp.com)
   //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
   //              David Dillard, VERITAS Software Corp.
   //                  (david.dillard@veritas.com)
   //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <fstream> #include <fstream>
Line 36 
Line 45 
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/AutoPtr.h> #include <Pegasus/Common/AutoPtr.h>
 #include <Pegasus/Common/CIMClass.h>  
 #include <Pegasus/Common/CIMMessage.h>  
 #include <Pegasus/Common/XmlWriter.h>  
 #include <Pegasus/Common/AcceptLanguageList.h>  
 #include <Pegasus/Common/ContentLanguageList.h>  
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
 PEGASUS_USING_PEGASUS; PEGASUS_USING_PEGASUS;
  
   // If Windows platform then set the EOF_CHAR to 2
   #if defined(PEGASUS_OS_TYPE_WINDOWS)
       #define EOF_CHAR 2
   #else
       #define EOF_CHAR 1
   #endif
   
 // Trace files for test purposes // Trace files for test purposes
 // Will be created in the $(PEGASUS_TMP) directory, or if not set, // Will be created in the $(PEGASUS_TMP) directory, or if not set,
 // in the current directory // in the current directory
Line 60 
Line 71 
 // return 0 if the strings match // return 0 if the strings match
 // return 1 if the strings do not match // return 1 if the strings do not match
 // //
 Uint32 compare(const char* fileName, const char* expectedMessage)  Uint32 compare(const char* fileName, const char* compareStr)
 {  
     int expectedMessageLength = strlen(expectedMessage);  
   
     // Compute the size of the message in the trace file.  Include the final  
     // EOL character added by the Tracer.  This size will be used to seek  
     // from the end of the file back to the beginning of the trace message.  
     int seekBytes = expectedMessageLength + 1;  
   
 #if defined(PEGASUS_OS_TYPE_WINDOWS)  
     // Windows converts all '\n' characters to "\r\n" sequences in the trace  
     // file.  Increase the seekBytes by the number of '\r' characters added  
     // when the message is written to the file.  
     for (const char* newlineChar = expectedMessage;  
          ((newlineChar = strchr(newlineChar, '\n')) != 0);  
          newlineChar++)  
     {     {
         seekBytes++;      Uint32 count=0;
     }      Uint32 retCode=0;
   
     // Count the '\r' character added with the final '\n' written by the Tracer  
     seekBytes++;  
 #endif  
   
     AutoArrayPtr<char> actualMessage(new char[expectedMessageLength + 1]);  
   
     // Read the trace message from the file, minus the message prefix and  
     // minus the trailing newline.  
     fstream file;     fstream file;
       Uint32 size= static_cast<Uint32>(strlen(compareStr));
       AutoArrayPtr<char> readStr(new char[size+EOF_CHAR+1]);
   
     file.open(fileName, fstream::in);     file.open(fileName, fstream::in);
     if (!file.good())     if (!file.good())
     {     {
         return 1;         return 1;
     }     }
     file.seekg(-seekBytes, fstream::end);      file.seekg((Sint32) -(static_cast<Sint32>(size)+EOF_CHAR),fstream::end);
     file.read(actualMessage.get(), expectedMessageLength);      memset(readStr.get(), 0, (size+EOF_CHAR+1)*sizeof(char));
     file.close();      file.read(readStr.get(),size+EOF_CHAR);
     actualMessage.get()[expectedMessageLength] = 0;      (readStr.get())[size]='\0';
       retCode=strcmp(compareStr,readStr.get());
     // Compare the expected and actual messages  
     Uint32 retCode = strcmp(expectedMessage, actualMessage.get());      /* Diagnostic to determnine string differences
       if (!retCode)
     /* Diagnostic to determine string differences          cout << "Compare Error: compareStr= \n\"" << compareStr
     if (retCode)              << "\". readStr= \n\"" << readStr.get() << "\"" << endl;
         cout << "Compare Error: expectedMessage= \n\"" << expectedMessage <<  
             "\". actualMessage= \n\"" << actualMessage.get() << "\"" << endl;  
     */     */
  
       file.close();
     return retCode;     return retCode;
 } }
  
Line 593 
Line 582 
     return(compare(FILE4,"Test message for Level4 in test23."));     return(compare(FILE4,"Test message for Level4 in test23."));
 } }
  
 //  
 // Description:  
 // Test the getHTTPRequestMessage method.  
 //  
 // Type:  
 // Positive  
 // Tests with a HTTP Request without a basic authorization header.  
 // Message is written to trace file without any changes.  
 //  
 // return 0 if the test passed  
 // return 1 if the test failed  
 //  
 Uint32 test24()  
 {  
     Tracer::setTraceFile(FILE4);  
     Tracer::setTraceComponents("xmlio");  
     Tracer::setTraceLevel(Tracer::LEVEL2);  
   
     Uint32 queueId = 18;  
     CIMPropertyList propertyList;  
     Buffer params;  
     AcceptLanguageList al;  
     ContentLanguageList cl;  
   
     XmlWriter::appendClassNameIParameter(  
         params, "ClassName", CIMName("testclass"));  
     Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(  
         "localhost",  
         CIMNamespaceName("test/cimv2"),  
         CIMName ("EnumerateInstanceNames"),  
         "12345",  
         HTTP_METHOD__POST,  
         "Basic: Authorization AAAAA",  
         al,  
         cl,  
         params);  
   
     AutoArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(  
             buffer));  
   
     PEG_TRACE((  
         TRC_XML_IO,  
         Tracer::LEVEL2,  
         "<!-- Request: queue id: %u -->\n%s",  
         queueId,  
         reqMsg.get()));  
   
     return(compare(FILE4, buffer.getData()));  
 }  
   
 //  
 // Description:  
 // Test the getHTTPRequestMessage method.  
 //  
 // Type:  
 // Positive  
 // Tests with a HTTP Request that contains a Basic authorization header.  
 // The user/password info in the message is suppressed before writing it to  
 // the trace file.  
 //  
 // return 0 if the test passed  
 // return 1 if the test failed  
 //  
 Uint32 test25()  
 {  
     Tracer::setTraceFile(FILE4);  
     Tracer::setTraceComponents("xmlio");  
     Tracer::setTraceLevel(Tracer::LEVEL2);  
   
     Uint32 queueId = 18;  
     CIMPropertyList propertyList;  
     Buffer params;  
     AcceptLanguageList al;  
     ContentLanguageList cl;  
     String authHeader = "Authorization: Basic ABCDEABCDE==";  
     String MSGID = "32423424";  
   
     XmlWriter::appendClassNameIParameter(  
         params,  
         "ClassName",  
         CIMName("testclass"));  
     Buffer buffer = XmlWriter::formatSimpleIMethodReqMessage(  
         "localhost",  
         CIMNamespaceName("test/cimv2"),  
         CIMName ("EnumerateInstanceNames"),  
         MSGID,  
         HTTP_METHOD__POST,  
         authHeader,  
         al,  
         cl,  
         params);  
   
     AutoArrayPtr<char> reqMsg(Tracer::getHTTPRequestMessage(buffer));  
   
     PEG_TRACE((  
         TRC_XML_IO,  
         Tracer::LEVEL2,  
         "<!-- Request: queue id: %u -->\n%s",  
         queueId,  
         reqMsg.get()));  
   
     String testStr(buffer.getData());  
     Uint32 pos = testStr.find("ABCDEABCDE==");  
   
     for ( Uint32 i = pos; i < pos+strlen("ABCDEABCDE=="); i++)  
         testStr[i] = 'X';  
   
     return(compare(FILE4, testStr.getCString()));  
 }  
   
 int main(int argc, char** argv) int main(int argc, char** argv)
 { {
  
Line 846 
Line 725 
        cout << "Tracer test (test23) failed" << endl;        cout << "Tracer test (test23) failed" << endl;
        exit(1);        exit(1);
     }     }
     if (test24() != 0)  
     {  
        cout << "Tracer test (test24) failed" << endl;  
        exit(1);  
     }  
   
     if (test25() != 0)  
     {  
        cout << "Tracer test (test25) failed" << endl;  
        exit(1);  
     }  
     cout << argv[0] << " +++++ passed all tests" << endl;     cout << argv[0] << " +++++ passed all tests" << endl;
     System::removeFile(FILE1);     System::removeFile(FILE1);
     System::removeFile(FILE2);     System::removeFile(FILE2);


Legend:
Removed from v.1.27.22.2  
changed lines
  Added in v.1.28

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2