1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2006/04/07 14:14:40 $
7 Version: $Revision: 1.12 $
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 *[])
40 /* Most of the tests are out of date!
41 (we don't use any longer DictEntry to build a DocEntry!
44 gdcm::DictEntry *dict;
45 gdcm::DataEntry *entry;
47 dict = gdcm::DictEntry::New(0x0003,0x0004);
48 // SetVR *before* making the DataEntry!
50 entry = gdcm::DataEntry::New(dict);
52 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
54 std::cout << "TagKey : [" << entry->GetKey() << "]" << std::endl;
55 std::cout << "Group : [" << entry->GetGroup() << "]" << std::endl;
56 std::cout << "Element : [" << entry->GetElement() << "]" << std::endl;
58 entry->SetString("1");
60 entry->Print(std::cout);
61 std::cout << std::endl;
62 if( entry->GetValueCount() != 1 )
64 std::cout << " Failed" << std::endl
65 << " Number of content values is incorrect" << std::endl
66 << " Found: " << entry->GetValueCount()
67 << " - Must be: 1" << std::endl;
73 entry->SetString("1\\2");
75 entry->Print(std::cout);
76 std::cout << std::endl;
77 if( entry->GetValueCount() != 2 )
79 std::cout << " Failed" << std::endl
80 << " Number of content values is incorrect" << std::endl
81 << " Found: " << entry->GetValueCount()
82 << " - Must be: 2" << std::endl;
90 entry->Print(std::cout);
91 std::cout << std::endl;
92 if( entry->GetValueCount() != 0 )
94 std::cout << " Failed" << std::endl
95 << " Number of content values is incorrect" << std::endl
96 << " Found: " << entry->GetValueCount()
97 << " - Must be: 0" << std::endl;
103 std::cout << std::endl;
107 //------------------------------------------------------------------
108 dict = gdcm::DictEntry::New(0x0000,0x0000);
109 // SetVR *before* making the DataEntry!
111 entry = gdcm::DataEntry::New(dict);
113 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
114 entry->SetString(data);
115 entry->Print(std::cout);
116 std::cout << std::endl;
118 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
120 std::cout << " Failed" << std::endl
121 << " Size of string is incorrect" << std::endl
122 << " Found: " << entry->GetLength()
123 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
128 if( entry->GetValueCount() != nbvalue )
130 std::cout << " Failed" << std::endl
131 << " Number of content values is incorrect" << std::endl
132 << " Found: " << entry->GetValueCount()
133 << " - Must be: " << nbvalue << std::endl;
138 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
140 std::cout << " Failed" << std::endl
141 << " Content of bin area is incorrect" << std::endl;
146 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
148 std::cout << " Failed" << std::endl
149 << " Content of string is incorrect" << std::endl
150 << " Found: " << entry->GetString().c_str()
151 << " - Must be: " << data << std::endl;
156 for(i=0;i<entry->GetValueCount();i++)
158 if( entry->GetValue(i) != svalue[i] )
160 std::cout << " Failed" << std::endl
161 << " Content of entry's values is incorrect : id " << i << std::endl
162 << " Found " << entry->GetValue(i)
163 << " - Must be " << svalue[i] << std::endl;
170 std::cout << std::endl;
174 //------------------------------------------------------------------
175 dict = gdcm::DictEntry::New(0x0000,0x0000);
176 // SetVR *before* making the DataEntry!
178 entry = gdcm::DataEntry::New(dict);
181 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
182 entry->SetString(data);
184 entry->Print(std::cout);
185 std::cout << std::endl;
187 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
189 std::cout << " Failed" << std::endl
190 << " BinArea length is incorrect" << std::endl
191 << " Found: " << entry->GetLength()
192 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
197 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
199 std::cout << " Failed" << std::endl
200 << " Content of string is incorrect" << std::endl
201 << " Found: " << entry->GetString().c_str()
202 << " - Must be: " << data << std::endl;
207 if( entry->GetValueCount() != nbvalue )
209 std::cout << " Failed" << std::endl
210 << " Number of content values is incorrect" << std::endl
211 << " Found: " << entry->GetValueCount()
212 << " - Must be: " << nbvalue << std::endl;
217 for(i=0;i<entry->GetValueCount();i++)
219 if( entry->GetValue(i) != svalue[i] )
221 std::cout << " Failed" << std::endl
222 << " Content of entry's values is incorrect : id " << i << std::endl
223 << " Found: " << entry->GetValue(i)
224 << " - Must be: " << svalue[i] << std::endl;
231 entry->SetLength(nbvalue*sizeof(uint16_t));
232 entry->SetBinArea((uint8_t *)svalue,false);
234 entry->Print(std::cout);
235 std::cout << std::endl;
237 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
239 std::cout << " Failed" << std::endl
240 << " Content of string is incorrect" << std::endl
241 << " Found: " << entry->GetString().c_str()
242 << " - Must be: " << data << std::endl;
247 if( entry->GetValueCount() != nbvalue )
249 std::cout << " Failed" << std::endl
250 << " Number of content values is incorrect" << std::endl
251 << " Found: " << entry->GetValueCount()
252 << " - Must be: " << nbvalue << std::endl;
257 for(i=0;i<entry->GetValueCount();i++)
259 if( entry->GetValue(i) != svalue[i] )
261 std::cout << " Failed" << std::endl
262 << " Content of entry's values is incorrect : id " << i << std::endl
263 << " Found: " << entry->GetValue(i)
264 << " - Must be: " << svalue[i] << std::endl;
271 std::cout << std::endl;
275 //------------------------------------------------------------------
276 dict = gdcm::DictEntry::New(0x0000,0x0000);
278 entry = gdcm::DataEntry::New(dict);
280 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
281 entry->SetString(data);
283 entry->Print(std::cout);
284 std::cout << std::endl;
286 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
288 std::cout << " Failed" << std::endl
289 << " BinArea length is incorrect" << std::endl
290 << " Found: " << entry->GetLength()
291 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
296 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
298 std::cout << " Failed" << std::endl
299 << " Content of string is incorrect" << std::endl
300 << " Found: " << entry->GetString().c_str()
301 << " - Must be: " << data << std::endl;
306 if( entry->GetValueCount() != nbvalue )
308 std::cout << " Failed" << std::endl
309 << " Number of content values is incorrect" << std::endl
310 << " Found: " << entry->GetValueCount()
311 << " - Must be: " << nbvalue << std::endl;
316 for(i=0;i<entry->GetValueCount();i++)
318 if( entry->GetValue(i) != lvalue[i] )
320 std::cout << " Failed" << std::endl
321 << " Content of entry's values is incorrect : id " << i << std::endl
322 << " Found: " << entry->GetValue(i)
323 << " - Must be: " << lvalue[i] << std::endl;
330 entry->SetLength(nbvalue*sizeof(uint32_t));
331 entry->SetBinArea((uint8_t *)lvalue,false);
333 entry->Print(std::cout);
334 std::cout << std::endl;
336 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
338 std::cout << " Failed" << std::endl
339 << " Content of string is incorrect" << std::endl
340 << " Found: " << entry->GetString().c_str()
341 << " - Must be: " << data << std::endl;
346 if( entry->GetValueCount() != nbvalue )
348 std::cout << " Failed" << std::endl
349 << " Number of content values is incorrect" << std::endl
350 << " Found: " << entry->GetValueCount()
351 << " - Must be: " << nbvalue << std::endl;
356 for(i=0;i<entry->GetValueCount();i++)
358 if( entry->GetValue(i) != lvalue[i] )
360 std::cout << " Failed" << std::endl
361 << " Content of entry's values is incorrect : id " << i << std::endl
362 << " Found: " << entry->GetValue(i)
363 << " - Must be: " << lvalue[i] << std::endl;
370 std::cout << std::endl;
374 //------------------------------------------------------------------
375 dict = gdcm::DictEntry::New(0x0000,0x0000);
377 entry = gdcm::DataEntry::New(dict);
379 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
380 entry->SetString(fdata);
382 entry->Print(std::cout);
383 std::cout << std::endl;
385 if( entry->GetLength() != nbvalue*sizeof(float) )
387 std::cout << " Failed" << std::endl
388 << " BinArea length is incorrect" << std::endl
389 << " Found: " << entry->GetLength()
390 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
395 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
397 std::cout << " Failed" << std::endl
398 << " Content of string is incorrect" << std::endl
399 << " Found: " << entry->GetString().c_str()
400 << " - Must be: " << fdata << std::endl;
405 if( entry->GetValueCount() != nbvalue )
407 std::cout << " Failed" << std::endl
408 << " Number of content values is incorrect" << std::endl
409 << " Found: " << entry->GetValueCount()
410 << " - Must be: " << nbvalue << std::endl;
415 for(i=0;i<entry->GetValueCount();i++)
417 if( entry->GetValue(i) != fvalue[i] )
419 std::cout << " Failed" << std::endl
420 << " Content of entry's values is incorrect : id " << i << std::endl
421 << " Found: " << entry->GetValue(i)
422 << " - Must be: " << fvalue[i] << std::endl;
429 entry->SetLength(nbvalue*sizeof(float));
430 entry->SetBinArea((uint8_t *)fvalue,false);
432 entry->Print(std::cout);
433 std::cout << std::endl;
435 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
437 std::cout << " Failed" << std::endl
438 << " Content of string is incorrect" << std::endl
439 << " Found: " << entry->GetString().c_str()
440 << " - Must be: " << fdata << std::endl;
445 if( entry->GetValueCount() != nbvalue )
447 std::cout << " Failed" << std::endl
448 << " Number of content values is incorrect" << std::endl
449 << " Found: " << entry->GetValueCount()
450 << " - Must be: " << nbvalue << std::endl;
455 for(i=0;i<entry->GetValueCount();i++)
457 if( entry->GetValue(i) != fvalue[i] )
459 std::cout << " Failed" << std::endl
460 << " Content of entry's values is incorrect : id " << i << std::endl
461 << " Found: " << entry->GetValue(i)
462 << " - Must be: " << fvalue[i] << std::endl;
469 std::cout << std::endl;
473 //------------------------------------------------------------------
474 dict = gdcm::DictEntry::New(0x0000,0x0000);
476 entry = gdcm::DataEntry::New(dict);
478 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
479 entry->SetString(fdata);
481 entry->Print(std::cout);
482 std::cout << std::endl;
484 if( entry->GetLength() != nbvalue*sizeof(double) )
486 std::cout << " Failed" << std::endl
487 << " BinArea length is incorrect" << std::endl
488 << " Found: " << entry->GetLength()
489 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
494 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
496 std::cout << " Failed" << std::endl
497 << " Content of string is incorrect" << std::endl
498 << " Found: " << entry->GetString().c_str()
499 << " - Must be: " << fdata << std::endl;
504 if( entry->GetValueCount() != nbvalue )
506 std::cout << " Failed" << std::endl
507 << " Number of content values is incorrect" << std::endl
508 << " Found: " << entry->GetValueCount()
509 << " - Must be: " << nbvalue << std::endl;
514 for(i=0;i<entry->GetValueCount();i++)
516 // Never compare floating point value...
517 double dif = fabs(entry->GetValue(i) - dvalue[i]);
520 std::cout << " Failed" << std::endl
521 << " Content of entry's values is incorrect : id " << i << std::endl
522 << " Found: " << entry->GetValue(i)
523 << " - Must be: " << dvalue[i] << std::endl;
530 entry->SetLength(nbvalue*sizeof(double));
531 entry->SetBinArea((uint8_t *)dvalue,false);
533 entry->Print(std::cout);
534 std::cout << std::endl;
536 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
538 std::cout << " Failed" << std::endl
539 << " Content of string is incorrect" << std::endl
540 << " Found: " << entry->GetString().c_str()
541 << " - Must be: " << fdata << std::endl;
546 if( entry->GetValueCount() != nbvalue )
548 std::cout << " Failed" << std::endl
549 << " Number of content values is incorrect" << std::endl
550 << " Found: " << entry->GetValueCount()
551 << " - Must be: " << nbvalue << std::endl;
556 for(i=0;i<entry->GetValueCount();i++)
558 if( entry->GetValue(i) != dvalue[i] )
560 std::cout << " Failed" << std::endl
561 << " Content of entry's values is incorrect : id " << i << std::endl
562 << " Found: " << entry->GetValue(i)
563 << " - Must be: " << dvalue[i] << std::endl;
570 std::cout << std::endl;
574 //------------------------------------------------------------------
575 std::cout<<std::flush;