1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2006/04/07 10:58:51 $
7 Version: $Revision: 1.11 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 #include "gdcmDictEntry.h"
19 #include "gdcmDataEntry.h"
22 // ===============================================================
24 const char data[] = "1\\2\\3\\4\\5";
25 const char fdata[] = "1.1\\2.2\\3.3\\4.4\\5.5";
27 const int16_t svalue[]={1,2,3,4,5};
28 const int32_t lvalue[]={1,2,3,4,5};
29 const float fvalue[]={1.1f,2.2f,3.3f,4.4f,5.5f};
30 const double dvalue[]={1.1,2.2,3.3,4.4,5.5};
32 const unsigned long nbvalue = 5;
33 const double GDCM_EPS = 1e-6;
36 * \brief Test the DataEntry object
38 int TestDataEntry(int , char *[])
41 gdcm::DictEntry *dict;
42 gdcm::DataEntry *entry;
44 //------------------------------------------------------------------
46 /* Most of the tests are out of date!
47 (we don't use any longer DictEntry to build a DocEntry!
49 dict = gdcm::DictEntry::New(0x0003,0x0004);
50 // SetVR *before* making the DataEntry!
52 entry = gdcm::DataEntry::New(dict);
54 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
56 std::cout << "TagKey : [" << entry->GetKey() << "]" << std::endl;
57 std::cout << "Group : [" << entry->GetGroup() << "]" << std::endl;
58 std::cout << "Element : [" << entry->GetElement() << "]" << std::endl;
60 entry->SetString("1");
62 entry->Print(std::cout);
63 std::cout << std::endl;
64 if( entry->GetValueCount() != 1 )
66 std::cout << " Failed" << std::endl
67 << " Number of content values is incorrect" << std::endl
68 << " Found: " << entry->GetValueCount()
69 << " - Must be: 1" << std::endl;
75 entry->SetString("1\\2");
77 entry->Print(std::cout);
78 std::cout << std::endl;
79 if( entry->GetValueCount() != 2 )
81 std::cout << " Failed" << std::endl
82 << " Number of content values is incorrect" << std::endl
83 << " Found: " << entry->GetValueCount()
84 << " - Must be: 2" << std::endl;
92 entry->Print(std::cout);
93 std::cout << std::endl;
94 if( entry->GetValueCount() != 0 )
96 std::cout << " Failed" << std::endl
97 << " Number of content values is incorrect" << std::endl
98 << " Found: " << entry->GetValueCount()
99 << " - Must be: 0" << std::endl;
105 std::cout << std::endl;
109 //------------------------------------------------------------------
110 dict = gdcm::DictEntry::New(0x0000,0x0000);
111 // SetVR *before* making the DataEntry!
113 entry = gdcm::DataEntry::New(dict);
115 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
116 entry->SetString(data);
117 entry->Print(std::cout);
118 std::cout << std::endl;
120 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
122 std::cout << " Failed" << std::endl
123 << " Size of string is incorrect" << std::endl
124 << " Found: " << entry->GetLength()
125 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
130 if( entry->GetValueCount() != nbvalue )
132 std::cout << " Failed" << std::endl
133 << " Number of content values is incorrect" << std::endl
134 << " Found: " << entry->GetValueCount()
135 << " - Must be: " << nbvalue << std::endl;
140 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
142 std::cout << " Failed" << std::endl
143 << " Content of bin area is incorrect" << std::endl;
148 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
150 std::cout << " Failed" << std::endl
151 << " Content of string is incorrect" << std::endl
152 << " Found: " << entry->GetString().c_str()
153 << " - Must be: " << data << std::endl;
158 for(i=0;i<entry->GetValueCount();i++)
160 if( entry->GetValue(i) != svalue[i] )
162 std::cout << " Failed" << std::endl
163 << " Content of entry's values is incorrect : id " << i << std::endl
164 << " Found " << entry->GetValue(i)
165 << " - Must be " << svalue[i] << std::endl;
172 std::cout << std::endl;
176 //------------------------------------------------------------------
177 dict = gdcm::DictEntry::New(0x0000,0x0000);
178 // SetVR *before* making the DataEntry!
180 entry = gdcm::DataEntry::New(dict);
183 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
184 entry->SetString(data);
186 entry->Print(std::cout);
187 std::cout << std::endl;
189 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
191 std::cout << " Failed" << std::endl
192 << " BinArea length is incorrect" << std::endl
193 << " Found: " << entry->GetLength()
194 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
199 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
201 std::cout << " Failed" << std::endl
202 << " Content of string is incorrect" << std::endl
203 << " Found: " << entry->GetString().c_str()
204 << " - Must be: " << data << std::endl;
209 if( entry->GetValueCount() != nbvalue )
211 std::cout << " Failed" << std::endl
212 << " Number of content values is incorrect" << std::endl
213 << " Found: " << entry->GetValueCount()
214 << " - Must be: " << nbvalue << std::endl;
219 for(i=0;i<entry->GetValueCount();i++)
221 if( entry->GetValue(i) != svalue[i] )
223 std::cout << " Failed" << std::endl
224 << " Content of entry's values is incorrect : id " << i << std::endl
225 << " Found: " << entry->GetValue(i)
226 << " - Must be: " << svalue[i] << std::endl;
233 entry->SetLength(nbvalue*sizeof(uint16_t));
234 entry->SetBinArea((uint8_t *)svalue,false);
236 entry->Print(std::cout);
237 std::cout << std::endl;
239 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
241 std::cout << " Failed" << std::endl
242 << " Content of string is incorrect" << std::endl
243 << " Found: " << entry->GetString().c_str()
244 << " - Must be: " << data << std::endl;
249 if( entry->GetValueCount() != nbvalue )
251 std::cout << " Failed" << std::endl
252 << " Number of content values is incorrect" << std::endl
253 << " Found: " << entry->GetValueCount()
254 << " - Must be: " << nbvalue << std::endl;
259 for(i=0;i<entry->GetValueCount();i++)
261 if( entry->GetValue(i) != svalue[i] )
263 std::cout << " Failed" << std::endl
264 << " Content of entry's values is incorrect : id " << i << std::endl
265 << " Found: " << entry->GetValue(i)
266 << " - Must be: " << svalue[i] << std::endl;
273 std::cout << std::endl;
277 //------------------------------------------------------------------
278 dict = gdcm::DictEntry::New(0x0000,0x0000);
280 entry = gdcm::DataEntry::New(dict);
282 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
283 entry->SetString(data);
285 entry->Print(std::cout);
286 std::cout << std::endl;
288 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
290 std::cout << " Failed" << std::endl
291 << " BinArea length is incorrect" << std::endl
292 << " Found: " << entry->GetLength()
293 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
298 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
300 std::cout << " Failed" << std::endl
301 << " Content of string is incorrect" << std::endl
302 << " Found: " << entry->GetString().c_str()
303 << " - Must be: " << data << std::endl;
308 if( entry->GetValueCount() != nbvalue )
310 std::cout << " Failed" << std::endl
311 << " Number of content values is incorrect" << std::endl
312 << " Found: " << entry->GetValueCount()
313 << " - Must be: " << nbvalue << std::endl;
318 for(i=0;i<entry->GetValueCount();i++)
320 if( entry->GetValue(i) != lvalue[i] )
322 std::cout << " Failed" << std::endl
323 << " Content of entry's values is incorrect : id " << i << std::endl
324 << " Found: " << entry->GetValue(i)
325 << " - Must be: " << lvalue[i] << std::endl;
332 entry->SetLength(nbvalue*sizeof(uint32_t));
333 entry->SetBinArea((uint8_t *)lvalue,false);
335 entry->Print(std::cout);
336 std::cout << std::endl;
338 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
340 std::cout << " Failed" << std::endl
341 << " Content of string is incorrect" << std::endl
342 << " Found: " << entry->GetString().c_str()
343 << " - Must be: " << data << std::endl;
348 if( entry->GetValueCount() != nbvalue )
350 std::cout << " Failed" << std::endl
351 << " Number of content values is incorrect" << std::endl
352 << " Found: " << entry->GetValueCount()
353 << " - Must be: " << nbvalue << std::endl;
358 for(i=0;i<entry->GetValueCount();i++)
360 if( entry->GetValue(i) != lvalue[i] )
362 std::cout << " Failed" << std::endl
363 << " Content of entry's values is incorrect : id " << i << std::endl
364 << " Found: " << entry->GetValue(i)
365 << " - Must be: " << lvalue[i] << std::endl;
372 std::cout << std::endl;
376 //------------------------------------------------------------------
377 dict = gdcm::DictEntry::New(0x0000,0x0000);
379 entry = gdcm::DataEntry::New(dict);
381 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
382 entry->SetString(fdata);
384 entry->Print(std::cout);
385 std::cout << std::endl;
387 if( entry->GetLength() != nbvalue*sizeof(float) )
389 std::cout << " Failed" << std::endl
390 << " BinArea length is incorrect" << std::endl
391 << " Found: " << entry->GetLength()
392 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
397 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
399 std::cout << " Failed" << std::endl
400 << " Content of string is incorrect" << std::endl
401 << " Found: " << entry->GetString().c_str()
402 << " - Must be: " << fdata << std::endl;
407 if( entry->GetValueCount() != nbvalue )
409 std::cout << " Failed" << std::endl
410 << " Number of content values is incorrect" << std::endl
411 << " Found: " << entry->GetValueCount()
412 << " - Must be: " << nbvalue << std::endl;
417 for(i=0;i<entry->GetValueCount();i++)
419 if( entry->GetValue(i) != fvalue[i] )
421 std::cout << " Failed" << std::endl
422 << " Content of entry's values is incorrect : id " << i << std::endl
423 << " Found: " << entry->GetValue(i)
424 << " - Must be: " << fvalue[i] << std::endl;
431 entry->SetLength(nbvalue*sizeof(float));
432 entry->SetBinArea((uint8_t *)fvalue,false);
434 entry->Print(std::cout);
435 std::cout << std::endl;
437 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
439 std::cout << " Failed" << std::endl
440 << " Content of string is incorrect" << std::endl
441 << " Found: " << entry->GetString().c_str()
442 << " - Must be: " << fdata << std::endl;
447 if( entry->GetValueCount() != nbvalue )
449 std::cout << " Failed" << std::endl
450 << " Number of content values is incorrect" << std::endl
451 << " Found: " << entry->GetValueCount()
452 << " - Must be: " << nbvalue << std::endl;
457 for(i=0;i<entry->GetValueCount();i++)
459 if( entry->GetValue(i) != fvalue[i] )
461 std::cout << " Failed" << std::endl
462 << " Content of entry's values is incorrect : id " << i << std::endl
463 << " Found: " << entry->GetValue(i)
464 << " - Must be: " << fvalue[i] << std::endl;
471 std::cout << std::endl;
475 //------------------------------------------------------------------
476 dict = gdcm::DictEntry::New(0x0000,0x0000);
478 entry = gdcm::DataEntry::New(dict);
480 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
481 entry->SetString(fdata);
483 entry->Print(std::cout);
484 std::cout << std::endl;
486 if( entry->GetLength() != nbvalue*sizeof(double) )
488 std::cout << " Failed" << std::endl
489 << " BinArea length is incorrect" << std::endl
490 << " Found: " << entry->GetLength()
491 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
496 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
498 std::cout << " Failed" << std::endl
499 << " Content of string is incorrect" << std::endl
500 << " Found: " << entry->GetString().c_str()
501 << " - Must be: " << fdata << std::endl;
506 if( entry->GetValueCount() != nbvalue )
508 std::cout << " Failed" << std::endl
509 << " Number of content values is incorrect" << std::endl
510 << " Found: " << entry->GetValueCount()
511 << " - Must be: " << nbvalue << std::endl;
516 for(i=0;i<entry->GetValueCount();i++)
518 // Never compare floating point value...
519 double dif = fabs(entry->GetValue(i) - dvalue[i]);
522 std::cout << " Failed" << std::endl
523 << " Content of entry's values is incorrect : id " << i << std::endl
524 << " Found: " << entry->GetValue(i)
525 << " - Must be: " << dvalue[i] << std::endl;
532 entry->SetLength(nbvalue*sizeof(double));
533 entry->SetBinArea((uint8_t *)dvalue,false);
535 entry->Print(std::cout);
536 std::cout << std::endl;
538 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
540 std::cout << " Failed" << std::endl
541 << " Content of string is incorrect" << std::endl
542 << " Found: " << entry->GetString().c_str()
543 << " - Must be: " << fdata << std::endl;
548 if( entry->GetValueCount() != nbvalue )
550 std::cout << " Failed" << std::endl
551 << " Number of content values is incorrect" << std::endl
552 << " Found: " << entry->GetValueCount()
553 << " - Must be: " << nbvalue << std::endl;
558 for(i=0;i<entry->GetValueCount();i++)
560 if( entry->GetValue(i) != dvalue[i] )
562 std::cout << " Failed" << std::endl
563 << " Content of entry's values is incorrect : id " << i << std::endl
564 << " Found: " << entry->GetValue(i)
565 << " - Must be: " << dvalue[i] << std::endl;
572 std::cout << std::endl;
576 //------------------------------------------------------------------
577 std::cout<<std::flush;