X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDataEntry.cxx;h=f0dc13f594b48e4c9727e351684bdaff91a08e53;hb=030b22f65c2933ac680497672f8a236dcf2a460b;hp=7c2977c65753c98222f4ae888491c78df3577c0b;hpb=6a7c2fbcb5bfc240a3b9875ad4836f5dc058e069;p=gdcm.git diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index 7c2977c6..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/20 15:24:05 $ - Version: $Revision: 1.5 $ + 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,18 +17,20 @@ =========================================================================*/ #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 @@ -41,7 +43,7 @@ int TestDataEntry(int , char *[]) //------------------------------------------------------------------ dict = gdcm::DictEntry::New(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + entry = gdcm::DataEntry::New(dict); dict->SetVR("US"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -57,8 +59,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: 1" << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } entry->SetString("1\\2"); @@ -72,8 +74,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: 2" << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } entry->SetString(""); @@ -87,17 +89,17 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: 0" << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } std::cout << std::endl; dict->Delete(); - delete entry; + entry->Delete(); //------------------------------------------------------------------ dict = gdcm::DictEntry::New(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + entry = gdcm::DataEntry::New(dict); dict->SetVR("LT"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -112,8 +114,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetLength() << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -122,16 +124,16 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + 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; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 ) { @@ -140,8 +142,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -152,18 +154,18 @@ int TestDataEntry(int , char *[]) << " Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } std::cout << std::endl; dict->Delete(); - delete entry; + entry->Delete(); //------------------------------------------------------------------ dict = gdcm::DictEntry::New(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + entry = gdcm::DataEntry::New(dict); dict->SetVR("US"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -179,8 +181,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { @@ -189,8 +191,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -199,8 +201,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -211,8 +213,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << svalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } @@ -229,8 +231,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -239,8 +241,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -251,18 +253,18 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << svalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } std::cout << std::endl; dict->Delete(); - delete entry; + entry->Delete(); //------------------------------------------------------------------ dict = gdcm::DictEntry::New(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + entry = gdcm::DataEntry::New(dict); dict->SetVR("UL"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -278,8 +280,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { @@ -288,8 +290,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -298,8 +300,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -310,8 +312,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << lvalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } @@ -328,8 +330,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -338,8 +340,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -350,18 +352,18 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << lvalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } std::cout << std::endl; dict->Delete(); - delete entry; + entry->Delete(); //------------------------------------------------------------------ dict = gdcm::DictEntry::New(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + entry = gdcm::DataEntry::New(dict); dict->SetVR("FL"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -377,8 +379,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(float) << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { @@ -387,8 +389,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -397,8 +399,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -409,8 +411,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << fvalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } @@ -427,8 +429,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -437,8 +439,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -449,18 +451,18 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << fvalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } std::cout << std::endl; dict->Delete(); - delete entry; + entry->Delete(); //------------------------------------------------------------------ dict = gdcm::DictEntry::New(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); + entry = gdcm::DataEntry::New(dict); dict->SetVR("FD"); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; @@ -476,8 +478,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(double) << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { @@ -486,8 +488,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -496,20 +498,22 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + 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; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } @@ -526,8 +530,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -536,8 +540,8 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -548,14 +552,14 @@ int TestDataEntry(int , char *[]) << " Found: " << entry->GetValue(i) << " - Must be: " << dvalue[i] << std::endl; dict->Delete(); - delete entry; - return(1); + entry->Delete(); + return 1; } } std::cout << std::endl; dict->Delete(); - delete entry; + entry->Delete(); //------------------------------------------------------------------ std::cout<