X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDataEntry.cxx;h=190f50a4caca205379191043aa568b845b268a01;hb=9d461db5c5d954548cd07d1fa095e9bad43a0cac;hp=d57dd7324f08845b55c4da73c7f3b759c12793e7;hpb=eacd2efd90ffb9015d6358f135cb17a838a29abb;p=gdcm.git diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index d57dd732..190f50a4 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: 2006/04/07 14:14:40 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,35 +17,44 @@ =========================================================================*/ #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 *[]) { + /* Most of the tests are out of date! + (we don't use any longer DictEntry to build a DocEntry! + unsigned int i; gdcm::DictEntry *dict; gdcm::DataEntry *entry; - - //------------------------------------------------------------------ - dict = new gdcm::DictEntry(0x0000,0x0000); - entry = new gdcm::DataEntry(dict); - dict->SetVR("US"); + + dict = gdcm::DictEntry::New(0x0003,0x0004); + // SetVR *before* making the DataEntry! + dict->SetVR("US"); + entry = gdcm::DataEntry::New(dict); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + std::cout << "TagKey : [" << entry->GetKey() << "]" << std::endl; + std::cout << "Group : [" << entry->GetGroup() << "]" << std::endl; + std::cout << "Element : [" << entry->GetElement() << "]" << std::endl; + entry->SetString("1"); std::cout << "1: "; entry->Print(std::cout); @@ -56,9 +65,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 +80,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,19 +95,20 @@ 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); + // SetVR *before* making the DataEntry! dict->SetVR("LT"); + entry = gdcm::DataEntry::New(dict); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; entry->SetString(data); @@ -111,9 +121,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 +131,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 +149,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,20 +161,22 @@ 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); + // SetVR *before* making the DataEntry! dict->SetVR("US"); + entry = gdcm::DataEntry::New(dict); + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; entry->SetString(data); @@ -178,9 +190,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 +200,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 +210,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 +222,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 +240,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 +250,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,20 +262,20 @@ 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); dict->SetVR("UL"); + entry = gdcm::DataEntry::New(dict); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; entry->SetString(data); @@ -277,9 +289,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 +299,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 +309,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 +321,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 +339,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 +349,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,20 +361,20 @@ 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); dict->SetVR("FL"); + entry = gdcm::DataEntry::New(dict); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; entry->SetString(fdata); @@ -376,9 +388,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 +398,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 +408,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 +420,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 +438,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 +448,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,20 +460,20 @@ 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); dict->SetVR("FD"); + entry = gdcm::DataEntry::New(dict); std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; entry->SetString(fdata); @@ -475,9 +487,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 +497,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 +507,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 +539,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 +549,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,17 +561,18 @@ 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<