X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDataEntry.cxx;h=f0dc13f594b48e4c9727e351684bdaff91a08e53;hb=664bea34dd357bfd8d0e7de7c14a6492edd8f3b0;hp=d57dd7324f08845b55c4da73c7f3b759c12793e7;hpb=eacd2efd90ffb9015d6358f135cb17a838a29abb;p=gdcm.git diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index d57dd732..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 08:58:15 $ - Version: $Revision: 1.4 $ + 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 @@ -40,8 +42,8 @@ int TestDataEntry(int , char *[]) 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; @@ -56,9 +58,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: 1" << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } entry->SetString("1\\2"); @@ -71,9 +73,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: 2" << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } entry->SetString(""); @@ -86,18 +88,18 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: 0" << std::endl; - delete dict; - delete entry; - return(1); + 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; @@ -111,9 +113,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; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -121,17 +123,17 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + 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 ) { @@ -139,9 +141,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -151,19 +153,19 @@ 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; - delete entry; - return(1); + 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; @@ -178,9 +180,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { @@ -188,9 +190,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -198,9 +200,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -210,9 +212,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; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } } @@ -228,9 +230,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -238,9 +240,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -250,19 +252,19 @@ 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; - delete entry; - return(1); + 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; @@ -277,9 +279,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) { @@ -287,9 +289,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -297,9 +299,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -309,9 +311,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; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } } @@ -327,9 +329,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << data << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -337,9 +339,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -349,19 +351,19 @@ 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; - delete entry; - return(1); + 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; @@ -376,9 +378,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(float) << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { @@ -386,9 +388,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -396,9 +398,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -408,9 +410,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; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } } @@ -426,9 +428,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -436,9 +438,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -448,19 +450,19 @@ 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; - delete entry; - return(1); + 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; @@ -475,9 +477,9 @@ int TestDataEntry(int , char *[]) << " BinArea length is incorrect" << std::endl << " Found: " << entry->GetLength() << " - Must be: " << nbvalue*sizeof(double) << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) { @@ -485,9 +487,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -495,21 +497,23 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + 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; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } } @@ -525,9 +529,9 @@ int TestDataEntry(int , char *[]) << " Content of string is incorrect" << std::endl << " Found: " << entry->GetString().c_str() << " - Must be: " << fdata << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } if( entry->GetValueCount() != nbvalue ) { @@ -535,9 +539,9 @@ int TestDataEntry(int , char *[]) << " Number of content values is incorrect" << std::endl << " Found: " << entry->GetValueCount() << " - Must be: " << nbvalue << std::endl; - delete dict; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } for(i=0;iGetValueCount();i++) { @@ -547,15 +551,15 @@ 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; - delete entry; - return(1); + dict->Delete(); + entry->Delete(); + return 1; } } std::cout << std::endl; - delete dict; - delete entry; + dict->Delete(); + entry->Delete(); //------------------------------------------------------------------ std::cout<