X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestAllEntryVerify.cxx;h=9069a132653842ed52ddeb03c40c0b75a20176b3;hb=eaf1ca262cccaac8f8560427a305f10cc6f9e517;hp=889f73bca425d8439e8bb96ca03c2cca321a231c;hpb=10c1c646ed20f022c10647f4b3a829a67d70f7e0;p=gdcm.git diff --git a/Testing/TestAllEntryVerify.cxx b/Testing/TestAllEntryVerify.cxx index 889f73bc..9069a132 100644 --- a/Testing/TestAllEntryVerify.cxx +++ b/Testing/TestAllEntryVerify.cxx @@ -1,8 +1,8 @@ +#include "gdcmHeader.h" #include #include #include #include -#include "gdcmHeader.h" //Generated file: #include "gdcmDataImages.h" @@ -129,6 +129,8 @@ bool ReferenceFileParser::AddKeyValuePairToMap( string& key, string& value ) if ( CurrentMapEntryValuesPtr->count(key) != 0 ) return false; (*CurrentMapEntryValuesPtr)[key] = value; + + return true; //?? } void ReferenceFileParser::Print() @@ -161,7 +163,7 @@ bool ReferenceFileParser::Check() { string fileName = DataPath + i->first; cout << Indent << "FileName: " << fileName << endl; - gdcmHeader* tested = new gdcmHeader( fileName.c_str(), false, true ); + gdcmHeader* tested = new gdcmHeader( fileName.c_str() ); if( !tested->IsReadable() ) { cerr << Indent << "Image not gdcm compatible:" @@ -194,15 +196,17 @@ bool ReferenceFileParser::Check() if ( testedValue != j->second ) { cout << Indent << "Uncorrect value for key " << key << endl - << Indent << " read value " << testedValue << endl - << Indent << " reference value " << j->second << endl; + << Indent << " read value [" << testedValue << "]" << endl + << Indent << " reference value [" << j->second << "]" + << endl; return false; } } delete tested; - cout << Indent << endl; + cout << Indent << " OK" << endl; } cout << Indent << endl; + return true; } istream& ReferenceFileParser::eatwhite( istream& is ) @@ -245,7 +249,7 @@ string ReferenceFileParser::ExtractValue( string& toSplit ) string::size_type beginPos = toSplit.find_first_of( '"' ); string::size_type endPos = toSplit.find_last_of( '"' ); - // Make sure we have at most to " in toSplit: + // Make sure we have at most two " in toSplit: string noQuotes = toSplit.substr( beginPos + 1, endPos - beginPos - 1); if ( noQuotes.find_first_of( '"' ) != string::npos ) throw ParserException( "more than two quote character" ); @@ -368,9 +372,6 @@ void ReferenceFileParser::FirstPassReferenceFile() throw ( ParserException ) // Uncommented line outside of block is not clean: if ( !inBlock && !beginBlock ) { - cerr << Indent - << "Syntax warning: outside of block [] data at line " - << lineNumber++ << " not considered." << endl; continue; } @@ -432,6 +433,7 @@ bool ReferenceFileParser::Open( string& referenceFileName ) } from.close(); + return true; //?? } void ReferenceFileParser::CleanUpLine( string& line ) @@ -444,7 +446,7 @@ void ReferenceFileParser::CleanUpLine( string& line ) if ( line.find_last_of( "]" ) != string::npos ) line.erase( line.find_last_of( "]" ) + 1 ); - // Cleanup leanding whites and skip empty lines: + // Cleanup leading whites and skip empty lines: eatwhite( line ); } @@ -490,9 +492,8 @@ bool ReferenceFileParser::HandleValue( string& line ) string newCurrentValue = ExtractValue(line); if ( newCurrentValue.length() == 0 ) { - ostringstream error; - error << "missing value for key:" << CurrentKey; - throw ParserException( error.str() ); + cout << Indent << "Warning: empty value for key:" + << CurrentKey << endl; } CurrentValue += newCurrentValue; @@ -580,6 +581,7 @@ bool ReferenceFileParser::SecondPassReferenceFile() ParseRegularLine( line ); } + return true; //?? } int TestAllEntryVerify(int argc, char* argv[]) @@ -590,50 +592,35 @@ int TestAllEntryVerify(int argc, char* argv[]) << " (no arguments needed)." << endl; return 1; } - - cout << " Description (Test::TestAllEntryVerify): " - << endl; - cout << " For all images in gdcmData (and not blacklisted in " - "Test/CMakeLists.txt)" - << endl; - cout << " apply the following to each filename.xxx: " - << endl; - cout << " step 1: parse the image (as gdcmHeader) and call" - << " IsReadable(). " - << endl; string referenceDir = GDCM_DATA_ROOT; referenceDir += "/"; string referenceFilename = referenceDir + "TestAllEntryVerifyReference.txt"; + + cout << " Description (Test::TestAllEntryVerify): " + << endl; + cout << " For all images (not blacklisted in gdcm/Test/CMakeLists.txt)" + << endl; + cout << " encountered in directory: " << GDCM_DATA_ROOT << endl; + cout << " apply the following tests : "<< endl; + cout << " step 1: parse the image and call IsReadable(). " << endl; + cout << " step 2: look for the entry corresponding to the image" << endl; + cout << " in the reference file: " << referenceFilename << endl; + cout << " step 3: check that each reference tag value listed for this" + << endl; + cout << " entry matches the tag encountered at parsing step 1." + << endl << endl; ReferenceFileParser Parser; - Parser.Open(referenceFilename); - Parser.SetDataPath(referenceDir); - // Parser.Print(); - Parser.Check(); -/* - int i = 0; - while( gdcmDataImages[i] != 0 ) + if ( !Parser.Open(referenceFilename) ) { - string filename = GDCM_DATA_ROOT; - filename += "/"; //doh! - filename += gdcmDataImages[i++]; - - cout << " Testing: " << filename << endl; - - gdcmHeader* tested = new gdcmHeader( filename.c_str(), false, true ); - if( !tested->GetHeader()->IsReadable() ) - { - cout << " Image not gdcm compatible:" - << filename << endl; - delete tested; - return 1; - } - - //////////////// Clean up: - delete tested; + cout << " Corrupted reference file name: " + << referenceFilename << endl; + return 1; } -*/ - - return 0; + Parser.SetDataPath(referenceDir); + // Parser.Print(); + if ( Parser.Check() ) + return 0; + return 1; }