X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDataEntry.cxx;h=f0dc13f594b48e4c9727e351684bdaff91a08e53;hb=f14e091ab076314a54459f1b2b0efeaa03a2bc56;hp=c6fc0d312f2eb54d4bb0d0b32e153021f0499775;hpb=cd605bf3181b4cd75120619921569dcdfae845b6;p=gdcm.git diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index c6fc0d31..f0dc13f5 100644 --- a/Testing/TestDataEntry.cxx +++ b/Testing/TestDataEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestDataEntry.cxx,v $ Language: C++ - Date: $Date: 2005/10/18 19:06:29 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/10/24 16:00:46 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,30 +17,33 @@ =========================================================================*/ #include "gdcmDictEntry.h" #include "gdcmDataEntry.h" +#include // =============================================================== -char data[]="1\\2\\3\\4\\5"; -char fdata[]="1.1\\2.2\\3.3\\4.4\\5.5"; +const char data[] = "1\\2\\3\\4\\5"; +const char fdata[] = "1.1\\2.2\\3.3\\4.4\\5.5"; -short svalue[]={1,2,3,4,5}; -long lvalue[]={1,2,3,4,5}; -float fvalue[]={1.1f,2.2f,3.3f,4.4f,5.5f}; -double dvalue[]={1.1,2.2,3.3,4.4,5.5}; +const int16_t svalue[]={1,2,3,4,5}; +const int32_t lvalue[]={1,2,3,4,5}; +const float fvalue[]={1.1f,2.2f,3.3f,4.4f,5.5f}; +const double dvalue[]={1.1,2.2,3.3,4.4,5.5}; -unsigned long nbvalue = 5; +const unsigned long nbvalue = 5; +const double GDCM_EPS = 1e-6; /** * \brief Test the DataEntry object */ int TestDataEntry(int , char *[]) { + unsigned int i; gdcm::DictEntry *dict; gdcm::DataEntry *entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + dict = gdcm::DictEntry::New(0x0000,0x0000); + entry = gdcm::DataEntry::New(dict); dict->SetVR("US"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -52,10 +55,12 @@ int TestDataEntry(int , char *[]) if( entry->GetValueCount() != 1 ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: 1" << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } entry->SetString("1\\2"); @@ -65,10 +70,12 @@ int TestDataEntry(int , char *[]) if( entry->GetValueCount() != 2 ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: 2" << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } entry->SetString(""); @@ -78,19 +85,21 @@ int TestDataEntry(int , char *[]) if( entry->GetValueCount() != 0 ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: 0" << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + dict = gdcm::DictEntry::New(0x0000,0x0000); + entry = gdcm::DataEntry::New(dict); dict->SetVR("LT"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -101,55 +110,62 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != strlen(data) + strlen(data)%2 ) { std::cout << " Failed" << std::endl - << " Size of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Size of string is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 ) { std::cout << " Failed" << std::endl << " Content of bin area is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != svalue[i] ) { std::cout << " Failed" << std::endl << " Content of entry's values is incorrect : id " << i << std::endl - << " Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl; - delete dict; - delete entry; - return(1); + << " Found " << entry->GetValue(i) + << " - Must be " << svalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + dict = gdcm::DictEntry::New(0x0000,0x0000); + entry = gdcm::DataEntry::New(dict); dict->SetVR("US"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -161,36 +177,44 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != nbvalue*sizeof(uint16_t) ) { std::cout << " Failed" << std::endl - << " BinArea length is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != svalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << svalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } @@ -203,38 +227,44 @@ int TestDataEntry(int , char *[]) if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != svalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << svalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + dict = gdcm::DictEntry::New(0x0000,0x0000); + entry = gdcm::DataEntry::New(dict); dict->SetVR("UL"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -246,37 +276,44 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != nbvalue*sizeof(uint32_t) ) { std::cout << " Failed" << std::endl - << " BinArea length is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - std::cout<<"#"<GetString()<<"#"<<" / "<<"#"<GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != lvalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << lvalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } @@ -289,38 +326,44 @@ int TestDataEntry(int , char *[]) if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != lvalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << lvalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + dict = gdcm::DictEntry::New(0x0000,0x0000); + entry = gdcm::DataEntry::New(dict); dict->SetVR("FL"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -332,36 +375,44 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != nbvalue*sizeof(float) ) { std::cout << " Failed" << std::endl - << " BinArea length is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(float) << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != fvalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << fvalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } @@ -374,38 +425,44 @@ int TestDataEntry(int , char *[]) if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != fvalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << fvalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + dict = gdcm::DictEntry::New(0x0000,0x0000); + entry = gdcm::DataEntry::New(dict); dict->SetVR("FD"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -417,36 +474,46 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != nbvalue*sizeof(double) ) { std::cout << " Failed" << std::endl - << " BinArea length is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(double) << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); - } - for(unsigned int i=0;iGetValueCount();i++) - { - if( entry->GetValue(i) != dvalue[i] ) + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; + } + for(i=0;iGetValueCount();i++) + { + // Never compare floating point value... + double dif = fabs(entry->GetValue(i) - dvalue[i]); + if( dif > GDCM_EPS) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << dvalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } @@ -459,34 +526,40 @@ int TestDataEntry(int , char *[]) if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; - delete entry; - return(1); + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } - for(unsigned int i=0;iGetValueCount();i++) + for(i=0;iGetValueCount();i++) { if( entry->GetValue(i) != dvalue[i] ) { std::cout << " Failed" << std::endl - << " Content of entry's values is incorrect : id " << i << std::endl; - delete dict; - delete entry; - return(1); + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << dvalue[i] << std::endl; + dict->Delete(); + entry->Delete(); + return 1; } } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ std::cout<