X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDataEntry.cxx;h=ebd4892feac192eb7ec2ac27fd3142b57c801c91;hb=692c278613503559a7e64e475374f3e06f6da257;hp=d57dd7324f08845b55c4da73c7f3b759c12793e7;hpb=eacd2efd90ffb9015d6358f135cb17a838a29abb;p=gdcm.git diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index d57dd732..ebd4892f 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/20 08:58:15 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/10/23 19:46:17 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,18 +17,25 @@ =========================================================================*/ #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}; +// Temporary hack, assume that long and double are correlated +#if GDCM_SIZEOF_LONG == 4 +const double dvalue[]={1.1,2.2,3.3,4.4,5.5}; +#else +const float dvalue[]={1.1,2.2,3.3,4.4,5.5}; +#endif -unsigned long nbvalue = 5; +const unsigned long nbvalue = 5; +const float GDCM_EPS = 1e-6; /** * \brief Test the DataEntry object @@ -40,7 +47,7 @@ int TestDataEntry(int , char *[]) gdcm::DataEntry *entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); + dict = gdcm::DictEntry::New(0x0000,0x0000); entry = new gdcm::DataEntry(dict); dict->SetVR("US"); @@ -56,9 +63,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: 1" << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } entry->SetString("1\\2"); @@ -71,9 +78,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: 2" << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } entry->SetString(""); @@ -86,17 +93,17 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: 0" << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); + dict = gdcm::DictEntry::New(0x0000,0x0000); entry = new gdcm::DataEntry(dict); dict->SetVR("LT"); @@ -111,9 +118,9 @@ int TestDataEntry(int , char *[]) << " Size of string is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -121,17 +128,17 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + 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; + dict->Delete(); delete entry; - return(1); + return 1; } if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 ) { @@ -139,9 +146,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -151,18 +158,18 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); + dict = gdcm::DictEntry::New(0x0000,0x0000); entry = new gdcm::DataEntry(dict); dict->SetVR("US"); @@ -178,9 +185,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { @@ -188,9 +195,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -198,9 +205,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -210,9 +217,9 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << svalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -228,9 +235,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -238,9 +245,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -250,18 +257,18 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << svalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); + dict = gdcm::DictEntry::New(0x0000,0x0000); entry = new gdcm::DataEntry(dict); dict->SetVR("UL"); @@ -277,9 +284,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { @@ -287,9 +294,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -297,9 +304,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -309,9 +316,9 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << lvalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -327,9 +334,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -337,9 +344,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -349,18 +356,18 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << lvalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); + dict = gdcm::DictEntry::New(0x0000,0x0000); entry = new gdcm::DataEntry(dict); dict->SetVR("FL"); @@ -376,9 +383,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(float) << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { @@ -386,9 +393,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -396,9 +403,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -408,9 +415,9 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << fvalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -426,9 +433,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -436,9 +443,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -448,18 +455,18 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << fvalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); + dict = gdcm::DictEntry::New(0x0000,0x0000); entry = new gdcm::DataEntry(dict); dict->SetVR("FD"); @@ -475,9 +482,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(double) << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { @@ -485,9 +492,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -495,21 +502,23 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { - if( entry->GetValue(i) != dvalue[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 << " Found: " << entry->GetValue(i) << " - Must be: " << dvalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -525,9 +534,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -535,9 +544,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -547,14 +556,14 @@ int TestDataEntry(int , char *[]) << " Content of entry's values is incorrect : id " << i << std::endl << " Found: " << entry->GetValue(i) << " - Must be: " << dvalue[i] << std::endl; - delete dict; + dict->Delete(); delete entry; - return(1); + return 1; } } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------