#include "gdcmAttribute.h"
#include <cmath>
#include <limits>
int TestAttributeAE() { return 0; }
int TestAttributeAS() { return 0; }
int TestAttributeAT() { return 0; }
int TestAttributeDA() { return 0; }
int TestAttributeDS()
{
const double values[] = {-158.135803,-179.035797,-75.699997};
const double newvalues[] = {12.34,56.78,90.0};
const unsigned int numvalues = sizeof(values) / sizeof(values[0]);
gdcm::Attribute<0x0020,0x0032> ipp = {{-158.135803,-179.035797,-75.699997}};
if( ipp.GetVM() != gdcm::VM::VM3 ) return 1;
if( ipp.GetVR() != gdcm::VR::DS ) return 1;
if( ipp.GetNumberOfValues() != numvalues ) return 1;
for(unsigned int i = 0; i < numvalues; ++i)
if( fabs(ipp.GetValue(i) - values[i]) > std::numeric_limits<double>::epsilon() ) return 1;
ipp.Print( std::cout );
std::cout << std::endl;
gdcm::DataElement de = ipp.GetAsDataElement();
std::cout << de << std::endl;
ipp.SetValues( newvalues );
if( ipp.GetNumberOfValues() != numvalues ) return 1;
for(unsigned int i = 0; i < numvalues; ++i)
if( fabs(ipp.GetValue(i) - newvalues[i]) > std::numeric_limits<double>::epsilon() ) return 1;
ipp.Print( std::cout );
std::cout << std::endl;
de = ipp.GetAsDataElement();
std::cout << de << std::endl;
{
const char v[] = "1.960000000000662 ";
gdcm::DataElement invalid( gdcm::Tag(0x10,0x1030) ); invalid.SetVR( gdcm::VR::DS );
invalid.SetByteValue( v, (uint32_t)strlen(v) );
gdcm::Attribute<0x0010,0x1030> pw;
pw.SetFromDataElement( invalid );
gdcm::DataElement valid = pw.GetAsDataElement();
std::ostringstream os;
os << valid.GetValue();
std::string s = os.str();
size_t l = s.size();
if( l > 16 )
{
return 1;
}
}
return 0;
}
int TestAttributeDT() { return 0; }
int TestAttributeFL() { return 0; }
int TestAttributeFD() { return 0; }
int TestAttributeIS()
{
gdcm::Attribute<0x0018,0x1182, gdcm::VR::IS, gdcm::VM::VM1> fd1 = {0};
if( fd1.GetVM() != gdcm::VM::VM1 ) return 1;
gdcm::Attribute<0x0018,0x1182, gdcm::VR::IS, gdcm::VM::VM2> fd2 = {{0,1}};
if( fd2.GetVM() != gdcm::VM::VM2 ) return 1;
return 0;
}
int TestAttributeLO() { return 0; }
int TestAttributeLT() { return 0; }
int TestAttributeOB() { return 0; }
int TestAttributeOD() { return 0; }
int TestAttributeOF()
{
gdcm::DataSet ds;
const float array[] = { 0, 1, 2, 3, 4 };
gdcm::Attribute<0x5600,0x0020, gdcm::VR::OF, gdcm::VM::VM1_n> at;
at.SetValues( array, sizeof( array ) / sizeof( *array ) );
ds.Insert( at.GetAsDataElement() );
if( at.GetNumberOfValues() != 5 ) return 1;
gdcm::Attribute<0x0066,0x0016> at1;
float value = 1.f;
at1.SetValue( value );
ds.Insert( at1.GetAsDataElement() );
return 0;
}
int TestAttributeOL() { return 0; }
int TestAttributeOW() { return 0; }
int TestAttributePN() { return 0; }
int TestAttributeSH() { return 0; }
int TestAttributeSL() { return 0; }
int TestAttributeSQ() { return 0; }
int TestAttributeSS() { return 0; }
int TestAttributeST() { return 0; }
int TestAttributeTM() { return 0; }
int TestAttributeUI() { return 0; }
int TestAttributeUL() { return 0; }
int TestAttributeUN() { return 0; }
int TestAttributeUS() { return 0; }
int TestAttributeUT() { return 0; }
int TestAttribute1(int , char *[])
{
int numerrors = 0;
numerrors += TestAttributeAE();
numerrors += TestAttributeAS();
numerrors += TestAttributeAT();
numerrors += TestAttributeDA();
numerrors += TestAttributeDS();
numerrors += TestAttributeDT();
numerrors += TestAttributeFL();
numerrors += TestAttributeFD();
numerrors += TestAttributeIS();
numerrors += TestAttributeLO();
numerrors += TestAttributeLT();
numerrors += TestAttributeOB();
numerrors += TestAttributeOD();
numerrors += TestAttributeOF();
numerrors += TestAttributeOL();
numerrors += TestAttributeOW();
numerrors += TestAttributePN();
numerrors += TestAttributeSH();
numerrors += TestAttributeSL();
numerrors += TestAttributeSQ();
numerrors += TestAttributeSS();
numerrors += TestAttributeST();
numerrors += TestAttributeTM();
numerrors += TestAttributeUI();
numerrors += TestAttributeUL();
numerrors += TestAttributeUN();
numerrors += TestAttributeUS();
numerrors += TestAttributeUT();
return numerrors;
}