// Do log of some failed assert into log file. // void LogAssert( const char* inFile, const char* inFunc, vuint32 inLine, const char* inMsg ) { FBL_ASSERT_LOG_LOCK; ++gAssertFailCount; I_LogFile& log = *GetAssertsLog(); if( log.get_VerboseLevel() == 0 ) return; if( log.get_VerboseLevel() >= 1 ) // show all: { // Visual produce __FILE__ as ful path. We want extract only file name. inFile = ExtractNameFromFullPath( inFile ); log << inFile << ":" << inFunc << ":" << (vuint32) inLine << " " << inMsg << "\n"; } //log.Flush(); }
void ExtractDirectoryFromPath( const char inPath[], char* outDir ) { const char* pAppName = ExtractNameFromFullPath( inPath ); size_t len = pAppName - inPath; strncpy(outDir, inPath, len); outDir[len] = '\0'; }
FBL_Begin_Namespace /**********************************************************************************************/ #if FBL_MAC /**********************************************************************************************/ // NOTE: fullPath to item that EXISTS on disk. Otherwise file not found error. // #if FBL_SUPPORT_FSSPEC // OSErr Path2Spec_FSRef( const char *inPath, FSSpec *spec) { // parse path on parent folder and file name. const char* pFileName = ExtractNameFromFullPath(inPath); const char* pDelim = pFileName - 1; // String folder_path( inPath, vuint32(pDelim - inPath) ); vuint32 len; if( pDelim >= inPath ) len = vuint32(pDelim - inPath); else len = strlen( inPath ); MemPtr<char> folder_path( inPath, len + 1 ); folder_path[len] = 0; char* pFolderPath = folder_path.begin(); // convert the POSIX path to an FSRef of parent folder FSRef ref; OSStatus result = FSPathMakeRef( (vuint8*) pFolderPath, &ref, NULL); if( result != 0 ) return (OSErr) result; // and then convert the FSRef to an FSSpec FSSpec parent; result = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &parent, NULL); if( result != 0 ) return (OSErr) result; // now we have parent folder FSSpec, get its ID. vint32 theDirID; bool isDirectory; GetDirectoryID( parent.vRefNum, parent.parID, parent.name, &theDirID, &isDirectory ); // and now we make File spec: Str255 pasFileName; FBL::c2pstrcpy( pFileName, pasFileName ); result = FSMakeFSSpec( parent.vRefNum, theDirID, pasFileName, spec ); return (OSErr) result; }
void ExtractBaseNameFromFullPath( const char inPath[], char* outBase ) { const char* pFileName = ExtractNameFromFullPath( inPath ); const char* p = strstr(pFileName, "."); size_t len = (p) ? static_cast<size_t>( p - pFileName ) : strlen( pFileName ); strncpy(outBase, pFileName, len); outBase[len] = '\0'; }
void LogException( const char* inFile, const char* inFunc, vuint32 inLine, xException* inExc, const char* inMsg ) { ++gTestFailCount; ++gTestFailOnExceptionCount; I_LogFile& log = *GetTestsLog(); vuint8 level = log.get_VerboseLevel(); if( level == 0 ) return; FBL::String logMsg; if( level >= 1 ) // show only erros: { // Visual produce __FILE__ as ful path. We want extract only file name. inFile = ExtractNameFromFullPath( inFile ); logMsg << GetTestStatisticStr().GetIndentStr() << "FAIL: " << inFile << ":" << inFunc << ":" << (vuint32) inLine; if( inMsg ) { logMsg << " " << inMsg; } logMsg << " EXCEPTION: "; if( inExc ) logMsg << inExc->get_ErrorCode() << " : " << inExc->get_ErrorString().c_str(); else logMsg << "UNKNOWN"; logMsg << "\n"; } log << logMsg.c_str(); // XML log: logMsg.addXmlEncoding(); LogXml_Failure( logMsg.getBufferA() ); //log.Flush(); }
// Produce line as // // ......DONE: FBL_Test_I_Unknown.cpp:Test_I_Unknown:52 c1 == 100 // ......FAIL: FBL_Test_I_Unknown.cpp:Test_I_Unknown:52 c1 == 100 // void LogTest( const char* inFile, const char* inFunc, vuint32 inLine, const char* inMsg, bool inSucces, bool inEndLines ) { if( !inSucces ) ++gTestFailCount; I_LogFile& log = *GetTestsLog(); vuint8 level = log.get_VerboseLevel(); if( level == 0 ) return; // Visual produce __FILE__ as full path. We want extract only file name. inFile = ExtractNameFromFullPath( inFile ); if( level == 1 ) // show only erros: { if( inSucces == false ) { log << GetTestStatisticStr().GetIndentStr() << "FAIL: " << inFile << ":" << inFunc << ":" << (vuint32) inLine << " " << inMsg; if( inEndLines ) log << "\n"; } } if( level >= 2 ) // show all: { if( inSucces ) log << GetTestStatisticStr().GetIndentStr() << "DONE: "; else log << GetTestStatisticStr().GetIndentStr() << "FAIL: "; log << inFile << ":" << inFunc << ":" << (vuint32) inLine << " " << inMsg; if( inEndLines ) log << "\n"; } // XML: if( !inSucces ) { String logMsg; logMsg << inFile << ":" << inFunc << ":" << (vuint32) inLine << " " << inMsg; logMsg.addXmlEncoding(); LogXml_Failure( logMsg.getBufferA() ); } // log.Flush(); }