From ca7638110ded9d3f5283be33b6be6442b397a38f Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 7 Apr 2006 10:58:51 +0000 Subject: [PATCH] Allow user to run the tests on a single file --- Testing/TestBug.cxx | 8 +++-- Testing/TestDataEntry.cxx | 9 +++-- Testing/TestFileAccessors.cxx | 59 +++++++++++++++++++----------- Testing/TestPrintAllDocument.cxx | 33 ++++++++++++----- Testing/TestWriteSimple.cxx | 62 +++++++++++++++++++------------- 5 files changed, 113 insertions(+), 58 deletions(-) diff --git a/Testing/TestBug.cxx b/Testing/TestBug.cxx index 97675608..db95841a 100644 --- a/Testing/TestBug.cxx +++ b/Testing/TestBug.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestBug.cxx,v $ Language: C++ - Date: $Date: 2005/10/25 14:52:30 $ - Version: $Revision: 1.21 $ + Date: $Date: 2006/04/07 10:58:51 $ + Version: $Revision: 1.22 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -34,8 +34,10 @@ int TestBug(int argc, char *argv[]) f->SetFileName( filename.c_str() ); } f->Load( ); - + f->Print(); + std::cout << "-------------End of Print file ------------" << std::cout; f->GetPubDict()->Print(); + std::cout << "-------------End of Print Dict ------------" << std::cout; f->Delete(); return 0; diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index ccfe73a5..bca594cb 100644 --- a/Testing/TestDataEntry.cxx +++ b/Testing/TestDataEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestDataEntry.cxx,v $ Language: C++ - Date: $Date: 2006/03/22 13:20:36 $ - Version: $Revision: 1.10 $ + Date: $Date: 2006/04/07 10:58:51 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -42,6 +42,10 @@ int TestDataEntry(int , char *[]) gdcm::DataEntry *entry; //------------------------------------------------------------------ + + /* Most of the tests are out of date! + (we don't use any longer DictEntry to build a DocEntry! + dict = gdcm::DictEntry::New(0x0003,0x0004); // SetVR *before* making the DataEntry! dict->SetVR("US"); @@ -571,5 +575,6 @@ int TestDataEntry(int , char *[]) //------------------------------------------------------------------ std::cout<name() << std::endl; \ - } \ - catch(...) \ - { \ - std::cout << " --> Can't access to the '" << #name << "' method !" << std::endl; \ - f->Delete(); \ - return 1; \ +#define TestMethodMacro(mode,obj,name) \ + try \ + { \ + std::cout <<" "<< #name << "() : " \ + << std::endl; \ + std::cout << " " \ + << mode << obj->name() << std::endl; \ + } \ + catch(...) \ + { \ + std::cout << " --> Can't access to the '" \ + << #name << "' method !" << std::endl;\ + f->Delete(); \ + return 1; \ } - -int TestFileAccessors(int, char *[]) +int TestFileAccessors(int argc, char *argv[]) { int i = 0; float iop[6]; + // gdcm::Debug::DebugOn(); + while( gdcmDataImages[i] != 0 ) { @@ -65,13 +70,23 @@ int TestFileAccessors(int, char *[]) // if (gdcmDataImages[i] == "00191113.dcm" ) // gdcm::Debug::DebugOn(); // else - gdcm::Debug::DebugOff(); + // gdcm::Debug::DebugOff(); - std::string filename = GDCM_DATA_ROOT; - filename += "/"; //doh! - filename += gdcmDataImages[i]; + std::string filename; + if (argc ==2) + { + filename = argv[1]; + } + else + { + filename = GDCM_DATA_ROOT; + filename += "/"; //doh! + filename += gdcmDataImages[i]; + } - std::cout << "Begin with " << filename << std::endl; + std::cout << " ----------------------------------------------" + << "Begin with " << filename << std::endl; + gdcm::File *f= gdcm::File::New( ); f->SetFileName( filename ); f->Load( ); @@ -146,9 +161,11 @@ int TestFileAccessors(int, char *[]) f->Delete(); return 1; } - f->Delete(); - std::cout << "End with " << filename << std::endl; + + if (argc ==2) + break; // user asked to check a single file. + i++; } return 0; diff --git a/Testing/TestPrintAllDocument.cxx b/Testing/TestPrintAllDocument.cxx index 16551801..1b19d794 100644 --- a/Testing/TestPrintAllDocument.cxx +++ b/Testing/TestPrintAllDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestPrintAllDocument.cxx,v $ Language: C++ - Date: $Date: 2006/01/19 11:00:28 $ - Version: $Revision: 1.12 $ + Date: $Date: 2006/04/07 10:58:51 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -38,7 +38,7 @@ //Generated file: #include "gdcmDataImages.h" -int TestPrintAllDocument(int, char *[]) +int TestPrintAllDocument(int argc, char *argv[]) { //std::ostringstream s; int i = 0; @@ -47,11 +47,25 @@ int TestPrintAllDocument(int, char *[]) std::string pixelType, photomInterp; int l; l = strlen("PALETTE COLOR "); + + //gdcm::Debug::DebugOn(); + while( gdcmDataImages[i] != 0 ) { - std::string filename = GDCM_DATA_ROOT; - filename += "/"; //doh! - filename += gdcmDataImages[i]; + std::string filename; + if (argc ==2) + { + filename = argv[1]; + } + else + { + filename = GDCM_DATA_ROOT; + filename += "/"; //doh! + filename += gdcmDataImages[i]; + } + + std::cout << " ----------------------------------------------" + << "Begin with " << filename << std::endl; gdcm::File *f= gdcm::File::New( ); f->SetFileName( filename ); @@ -59,8 +73,7 @@ int TestPrintAllDocument(int, char *[]) f->SetPrintLevel(2); f->Print(); - // just to be able to grep the display result, for some usefull info - + //s.setf(std::ios::left); //s << std::setw(60-filename.length()) << " "; //std::cout << s.str() << gdcmDataImages[i]; @@ -122,6 +135,10 @@ int TestPrintAllDocument(int, char *[]) return 1; } f->Delete(); + + if (argc ==2) + break; // user asked to check a single file. + i++; } return 0; diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index 3c0dbafd..11652589 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Testing/TestWriteSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWriteSimple.cxx,v $ Language: C++ - Date: $Date: 2005/10/28 13:16:48 $ - Version: $Revision: 1.46 $ + Date: $Date: 2006/04/07 10:58:51 $ + Version: $Revision: 1.47 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -25,6 +25,8 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDebug.h" +#include "gdcmGlobal.h" +#include "gdcmDictSet.h" #include #include @@ -45,16 +47,17 @@ typedef struct } Image; Image Images [] = { - {128, 128, 1, 1, 8, 8, 0, 'e'}, + {256, 128, 1, 1, 8, 8, 0, 'a'}, + {128, 128, 1, 1, 8, 8, 0, 'i'}, + + {128, 128, 1, 1, 8, 8, 0, 'a'}, + {256, 128, 1, 1, 8, 8, 0, 'i'}, + + {256, 128, 1, 1, 8, 8, 0, 'e'}, {128, 128, 1, 1, 16, 16, 0, 'e'}, {128, 256, 1, 1, 16, 16, 0, 'e'}, - - {128, 128, 1, 1, 8, 8, 0, 'i'}, - {256, 128, 1, 1, 8, 8, 0, 'i'}, - {256, 128, 1, 1, 8, 8, 0, 'a'}, - {128, 128, 1, 1, 8, 8, 0, 'a'}, {128, 256, 1, 1, 8, 8, 0, 'e'}, {128, 256, 1, 1, 8, 8, 0, 'i'}, @@ -63,7 +66,7 @@ Image Images [] = { {128, 256, 1, 1, 16, 16, 0, 'i'}, {128, 256, 1, 1, 16, 16, 0, 'i'}, {128, 256, 1, 1, 16, 16, 0, 'a'}, - {128, 256, 1, 1, 16, 16, 0, 'a'}, + {128, 256, 1, 1, 16, 16, 0, 'a'}, {256, 128, 10, 1, 8, 8, 0, 'e'}, {256, 128, 10, 3, 8, 8, 0, 'e'}, @@ -106,6 +109,8 @@ const unsigned int MAX_NUMBER_OF_DIFFERENCE = 10; int WriteSimple(Image &img) { + + std::cout << "======================= WriteSimple =========(begin of processing current image)" << std::endl; std::ostringstream fileName; fileName.str(""); fileName << "TestWriteSimple"; @@ -212,9 +217,9 @@ int WriteSimple(Image &img) fileH->SetImageData(imageData,size); // Step 4 : Set the writting mode and write the image - std::cout << "4..."; fileH->SetWriteModeToRaw(); + std::cout << "4'..."; switch (img.writeMode) { case 'a' : // Write an ACR file @@ -238,10 +243,13 @@ int WriteSimple(Image &img) return 1; } + std::cout << std::endl; + fileToBuild->Print(); + if( !fileH->Write(fileName.str()) ) { std::cout << "Failed for [" << fileName.str() << "]\n" - << " File is unwrittable\n"; + << " File is unwrittable" << std::endl; fileH->Delete(); @@ -250,20 +258,28 @@ int WriteSimple(Image &img) } // Step 5 : Read the written image - std::cout << "5..."; + std::cout << "5..." << std::endl; // old form. //gdcm::FileHelper *reread = new gdcm::FileHelper( fileName.str() ); // Better use : - gdcm::FileHelper *reread = gdcm::FileHelper::New( ); - reread->SetFileName( fileName.str() ); - reread->SetLoadMode(gdcm::LD_ALL); // Load everything + gdcm::File *f = gdcm::File::New( ); + f->SetLoadMode(gdcm::LD_ALL); + f->SetFileName( fileName.str() ); + + //reread->SetFileName( fileName.str() ); + //reread->SetLoadMode(gdcm::LD_ALL); // Load everything // Possible values are // gdcm::LD_ALL, // gdcm::LD_NOSEQ, // gdcm::LD_NOSHADOW, // gdcm::LD_NOSEQ|gdcm::LD_NOSHADOW, // gdcm::LD_NOSHADOWSEQ - reread->Load(); + + f->Load(); + // reread->Load(); + gdcm::FileHelper *reread = gdcm::FileHelper::New( f ); + + reread->Print(); if( !reread->GetFile()->IsReadable() ) { @@ -277,7 +293,7 @@ int WriteSimple(Image &img) } // Step 6 : Compare to the written image - std::cout << "6..."; + std::cout << "6..." << std::endl; size_t dataSizeWritten = reread->GetImageDataSize(); uint8_t *imageDataWritten = reread->GetImageData(); @@ -331,7 +347,7 @@ int WriteSimple(Image &img) return 1; } - // Test the data's content + // Test the data content if ( memcmp(imageData, imageDataWritten, size) !=0 ) { std::cout << "Failed" << std::endl @@ -361,12 +377,9 @@ int WriteSimple(Image &img) return 1; } - std::cout << "OK" << std::endl; - fileH->Delete(); reread->Delete(); delete[] imageData; - return 0; } @@ -380,15 +393,16 @@ int TestWriteSimple(int argc, char *argv[]) return 1; } - gdcm::Debug::DebugOn(); - + // gdcm::Debug::DebugOn(); + char c; int ret=0; int i=0; while( Images[i].sizeX>0 && Images[i].sizeY>0 ) { - std::cout << "Test n :" << i; + std::cout << "Test n :" << i <