X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDataEntry.cxx;h=ebd4892feac192eb7ec2ac27fd3142b57c801c91;hb=692c278613503559a7e64e475374f3e06f6da257;hp=b4013207e2917803edb2f15354652e9c383e9eb2;hpb=215def20c8a86fa7ce257fab3e140c4cf5bc7a5b;p=gdcm.git diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx index b4013207..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/19 15:43:58 $ - Version: $Revision: 1.3 $ + 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"); @@ -53,10 +60,12 @@ int TestDataEntry(int , char *[]) if( entry->GetValueCount() != 1 ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: 1" << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } entry->SetString("1\\2"); @@ -66,10 +75,12 @@ int TestDataEntry(int , char *[]) if( entry->GetValueCount() != 2 ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: 2" << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } entry->SetString(""); @@ -79,18 +90,20 @@ int TestDataEntry(int , char *[]) if( entry->GetValueCount() != 0 ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: 0" << std::endl; + 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"); @@ -102,34 +115,40 @@ 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; + << " Size of string is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + 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 ) { std::cout << " Failed" << std::endl - << " Content of string is incorrect" << std::endl; - delete dict; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } for(i=0;iGetValueCount();i++) { @@ -137,19 +156,20 @@ int TestDataEntry(int , char *[]) { 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; + << " Found " << entry->GetValue(i) + << " - Must be " << svalue[i] << std::endl; + 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"); @@ -162,36 +182,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; + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl; + dict->Delete(); delete entry; - return(1); + 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << svalue[i] << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -204,37 +232,43 @@ 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << svalue[i] << std::endl; + 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"); @@ -247,37 +281,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; + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl; + dict->Delete(); delete entry; - return(1); + 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(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << lvalue[i] << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -290,37 +331,43 @@ 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << data << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << lvalue[i] << std::endl; + 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"); @@ -333,36 +380,44 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != nbvalue*sizeof(float) ) { std::cout << " Failed" << std::endl - << " BinArea length is incorrect" << std::endl; - delete dict; + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(float) << std::endl; + dict->Delete(); delete entry; - return(1); + 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << fvalue[i] << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } } @@ -375,37 +430,43 @@ 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found: " << entry->GetValue(i) + << " - Must be: " << fvalue[i] << std::endl; + 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"); @@ -418,36 +479,46 @@ int TestDataEntry(int , char *[]) if( entry->GetLength() != nbvalue*sizeof(double) ) { std::cout << " Failed" << std::endl - << " BinArea length is incorrect" << std::endl; - delete dict; + << " BinArea length is incorrect" << std::endl + << " Found: " << entry->GetLength() + << " - Must be: " << nbvalue*sizeof(double) << std::endl; + dict->Delete(); delete entry; - return(1); + 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + 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; - delete dict; + << " 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); + return 1; } } @@ -460,33 +531,39 @@ 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; + << " Content of string is incorrect" << std::endl + << " Found: " << entry->GetString().c_str() + << " - Must be: " << fdata << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } if( entry->GetValueCount() != nbvalue ) { std::cout << " Failed" << std::endl - << " Number of content values is incorrect" << std::endl; - delete dict; + << " Number of content values is incorrect" << std::endl + << " Found: " << entry->GetValueCount() + << " - Must be: " << nbvalue << std::endl; + dict->Delete(); delete entry; - return(1); + return 1; } 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; + << " 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); + return 1; } } std::cout << std::endl; - delete dict; + dict->Delete(); delete entry; //------------------------------------------------------------------