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
=========================================================================*/
#include "gdcmDictEntry.h"
#include "gdcmDataEntry.h"
+#include <math.h>
// ===============================================================
-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);
<< " 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");
<< " 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("");
<< " 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);
<< " 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 )
{
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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);
<< " 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 )
{
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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;
}
}
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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);
<< " 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 )
{
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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;
}
}
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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);
<< " 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 )
{
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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;
}
}
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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);
<< " 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 )
{
<< " 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 )
{
<< " 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;i<entry->GetValueCount();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;
}
}
<< " 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 )
{
<< " 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;i<entry->GetValueCount();i++)
{
<< " 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<<std::flush;
+ */
return 0;
}