1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2006/03/22 13:20:36 $
7 Version: $Revision: 1.10 $
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 //------------------------------------------------------------------
45 dict = gdcm::DictEntry::New(0x0003,0x0004);
46 // SetVR *before* making the DataEntry!
48 entry = gdcm::DataEntry::New(dict);
50 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
52 std::cout << "TagKey : [" << entry->GetKey() << "]" << std::endl;
53 std::cout << "Group : [" << entry->GetGroup() << "]" << std::endl;
54 std::cout << "Element : [" << entry->GetElement() << "]" << std::endl;
56 entry->SetString("1");
58 entry->Print(std::cout);
59 std::cout << std::endl;
60 if( entry->GetValueCount() != 1 )
62 std::cout << " Failed" << std::endl
63 << " Number of content values is incorrect" << std::endl
64 << " Found: " << entry->GetValueCount()
65 << " - Must be: 1" << std::endl;
71 entry->SetString("1\\2");
73 entry->Print(std::cout);
74 std::cout << std::endl;
75 if( entry->GetValueCount() != 2 )
77 std::cout << " Failed" << std::endl
78 << " Number of content values is incorrect" << std::endl
79 << " Found: " << entry->GetValueCount()
80 << " - Must be: 2" << std::endl;
88 entry->Print(std::cout);
89 std::cout << std::endl;
90 if( entry->GetValueCount() != 0 )
92 std::cout << " Failed" << std::endl
93 << " Number of content values is incorrect" << std::endl
94 << " Found: " << entry->GetValueCount()
95 << " - Must be: 0" << std::endl;
101 std::cout << std::endl;
105 //------------------------------------------------------------------
106 dict = gdcm::DictEntry::New(0x0000,0x0000);
107 // SetVR *before* making the DataEntry!
109 entry = gdcm::DataEntry::New(dict);
111 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
112 entry->SetString(data);
113 entry->Print(std::cout);
114 std::cout << std::endl;
116 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
118 std::cout << " Failed" << std::endl
119 << " Size of string is incorrect" << std::endl
120 << " Found: " << entry->GetLength()
121 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
126 if( entry->GetValueCount() != nbvalue )
128 std::cout << " Failed" << std::endl
129 << " Number of content values is incorrect" << std::endl
130 << " Found: " << entry->GetValueCount()
131 << " - Must be: " << nbvalue << std::endl;
136 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
138 std::cout << " Failed" << std::endl
139 << " Content of bin area is incorrect" << std::endl;
144 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
146 std::cout << " Failed" << std::endl
147 << " Content of string is incorrect" << std::endl
148 << " Found: " << entry->GetString().c_str()
149 << " - Must be: " << data << std::endl;
154 for(i=0;i<entry->GetValueCount();i++)
156 if( entry->GetValue(i) != svalue[i] )
158 std::cout << " Failed" << std::endl
159 << " Content of entry's values is incorrect : id " << i << std::endl
160 << " Found " << entry->GetValue(i)
161 << " - Must be " << svalue[i] << std::endl;
168 std::cout << std::endl;
172 //------------------------------------------------------------------
173 dict = gdcm::DictEntry::New(0x0000,0x0000);
174 // SetVR *before* making the DataEntry!
176 entry = gdcm::DataEntry::New(dict);
179 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
180 entry->SetString(data);
182 entry->Print(std::cout);
183 std::cout << std::endl;
185 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
187 std::cout << " Failed" << std::endl
188 << " BinArea length is incorrect" << std::endl
189 << " Found: " << entry->GetLength()
190 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
195 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
197 std::cout << " Failed" << std::endl
198 << " Content of string is incorrect" << std::endl
199 << " Found: " << entry->GetString().c_str()
200 << " - Must be: " << data << std::endl;
205 if( entry->GetValueCount() != nbvalue )
207 std::cout << " Failed" << std::endl
208 << " Number of content values is incorrect" << std::endl
209 << " Found: " << entry->GetValueCount()
210 << " - Must be: " << nbvalue << std::endl;
215 for(i=0;i<entry->GetValueCount();i++)
217 if( entry->GetValue(i) != svalue[i] )
219 std::cout << " Failed" << std::endl
220 << " Content of entry's values is incorrect : id " << i << std::endl
221 << " Found: " << entry->GetValue(i)
222 << " - Must be: " << svalue[i] << std::endl;
229 entry->SetLength(nbvalue*sizeof(uint16_t));
230 entry->SetBinArea((uint8_t *)svalue,false);
232 entry->Print(std::cout);
233 std::cout << std::endl;
235 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
237 std::cout << " Failed" << std::endl
238 << " Content of string is incorrect" << std::endl
239 << " Found: " << entry->GetString().c_str()
240 << " - Must be: " << data << std::endl;
245 if( entry->GetValueCount() != nbvalue )
247 std::cout << " Failed" << std::endl
248 << " Number of content values is incorrect" << std::endl
249 << " Found: " << entry->GetValueCount()
250 << " - Must be: " << nbvalue << std::endl;
255 for(i=0;i<entry->GetValueCount();i++)
257 if( entry->GetValue(i) != svalue[i] )
259 std::cout << " Failed" << std::endl
260 << " Content of entry's values is incorrect : id " << i << std::endl
261 << " Found: " << entry->GetValue(i)
262 << " - Must be: " << svalue[i] << std::endl;
269 std::cout << std::endl;
273 //------------------------------------------------------------------
274 dict = gdcm::DictEntry::New(0x0000,0x0000);
276 entry = gdcm::DataEntry::New(dict);
278 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
279 entry->SetString(data);
281 entry->Print(std::cout);
282 std::cout << std::endl;
284 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
286 std::cout << " Failed" << std::endl
287 << " BinArea length is incorrect" << std::endl
288 << " Found: " << entry->GetLength()
289 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
294 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
296 std::cout << " Failed" << std::endl
297 << " Content of string is incorrect" << std::endl
298 << " Found: " << entry->GetString().c_str()
299 << " - Must be: " << data << std::endl;
304 if( entry->GetValueCount() != nbvalue )
306 std::cout << " Failed" << std::endl
307 << " Number of content values is incorrect" << std::endl
308 << " Found: " << entry->GetValueCount()
309 << " - Must be: " << nbvalue << std::endl;
314 for(i=0;i<entry->GetValueCount();i++)
316 if( entry->GetValue(i) != lvalue[i] )
318 std::cout << " Failed" << std::endl
319 << " Content of entry's values is incorrect : id " << i << std::endl
320 << " Found: " << entry->GetValue(i)
321 << " - Must be: " << lvalue[i] << std::endl;
328 entry->SetLength(nbvalue*sizeof(uint32_t));
329 entry->SetBinArea((uint8_t *)lvalue,false);
331 entry->Print(std::cout);
332 std::cout << std::endl;
334 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
336 std::cout << " Failed" << std::endl
337 << " Content of string is incorrect" << std::endl
338 << " Found: " << entry->GetString().c_str()
339 << " - Must be: " << data << std::endl;
344 if( entry->GetValueCount() != nbvalue )
346 std::cout << " Failed" << std::endl
347 << " Number of content values is incorrect" << std::endl
348 << " Found: " << entry->GetValueCount()
349 << " - Must be: " << nbvalue << std::endl;
354 for(i=0;i<entry->GetValueCount();i++)
356 if( entry->GetValue(i) != lvalue[i] )
358 std::cout << " Failed" << std::endl
359 << " Content of entry's values is incorrect : id " << i << std::endl
360 << " Found: " << entry->GetValue(i)
361 << " - Must be: " << lvalue[i] << std::endl;
368 std::cout << std::endl;
372 //------------------------------------------------------------------
373 dict = gdcm::DictEntry::New(0x0000,0x0000);
375 entry = gdcm::DataEntry::New(dict);
377 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
378 entry->SetString(fdata);
380 entry->Print(std::cout);
381 std::cout << std::endl;
383 if( entry->GetLength() != nbvalue*sizeof(float) )
385 std::cout << " Failed" << std::endl
386 << " BinArea length is incorrect" << std::endl
387 << " Found: " << entry->GetLength()
388 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
393 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
395 std::cout << " Failed" << std::endl
396 << " Content of string is incorrect" << std::endl
397 << " Found: " << entry->GetString().c_str()
398 << " - Must be: " << fdata << std::endl;
403 if( entry->GetValueCount() != nbvalue )
405 std::cout << " Failed" << std::endl
406 << " Number of content values is incorrect" << std::endl
407 << " Found: " << entry->GetValueCount()
408 << " - Must be: " << nbvalue << std::endl;
413 for(i=0;i<entry->GetValueCount();i++)
415 if( entry->GetValue(i) != fvalue[i] )
417 std::cout << " Failed" << std::endl
418 << " Content of entry's values is incorrect : id " << i << std::endl
419 << " Found: " << entry->GetValue(i)
420 << " - Must be: " << fvalue[i] << std::endl;
427 entry->SetLength(nbvalue*sizeof(float));
428 entry->SetBinArea((uint8_t *)fvalue,false);
430 entry->Print(std::cout);
431 std::cout << std::endl;
433 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
435 std::cout << " Failed" << std::endl
436 << " Content of string is incorrect" << std::endl
437 << " Found: " << entry->GetString().c_str()
438 << " - Must be: " << fdata << std::endl;
443 if( entry->GetValueCount() != nbvalue )
445 std::cout << " Failed" << std::endl
446 << " Number of content values is incorrect" << std::endl
447 << " Found: " << entry->GetValueCount()
448 << " - Must be: " << nbvalue << std::endl;
453 for(i=0;i<entry->GetValueCount();i++)
455 if( entry->GetValue(i) != fvalue[i] )
457 std::cout << " Failed" << std::endl
458 << " Content of entry's values is incorrect : id " << i << std::endl
459 << " Found: " << entry->GetValue(i)
460 << " - Must be: " << fvalue[i] << std::endl;
467 std::cout << std::endl;
471 //------------------------------------------------------------------
472 dict = gdcm::DictEntry::New(0x0000,0x0000);
474 entry = gdcm::DataEntry::New(dict);
476 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
477 entry->SetString(fdata);
479 entry->Print(std::cout);
480 std::cout << std::endl;
482 if( entry->GetLength() != nbvalue*sizeof(double) )
484 std::cout << " Failed" << std::endl
485 << " BinArea length is incorrect" << std::endl
486 << " Found: " << entry->GetLength()
487 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
492 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
494 std::cout << " Failed" << std::endl
495 << " Content of string is incorrect" << std::endl
496 << " Found: " << entry->GetString().c_str()
497 << " - Must be: " << fdata << std::endl;
502 if( entry->GetValueCount() != nbvalue )
504 std::cout << " Failed" << std::endl
505 << " Number of content values is incorrect" << std::endl
506 << " Found: " << entry->GetValueCount()
507 << " - Must be: " << nbvalue << std::endl;
512 for(i=0;i<entry->GetValueCount();i++)
514 // Never compare floating point value...
515 double dif = fabs(entry->GetValue(i) - dvalue[i]);
518 std::cout << " Failed" << std::endl
519 << " Content of entry's values is incorrect : id " << i << std::endl
520 << " Found: " << entry->GetValue(i)
521 << " - Must be: " << dvalue[i] << std::endl;
528 entry->SetLength(nbvalue*sizeof(double));
529 entry->SetBinArea((uint8_t *)dvalue,false);
531 entry->Print(std::cout);
532 std::cout << std::endl;
534 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
536 std::cout << " Failed" << std::endl
537 << " Content of string is incorrect" << std::endl
538 << " Found: " << entry->GetString().c_str()
539 << " - Must be: " << fdata << std::endl;
544 if( entry->GetValueCount() != nbvalue )
546 std::cout << " Failed" << std::endl
547 << " Number of content values is incorrect" << std::endl
548 << " Found: " << entry->GetValueCount()
549 << " - Must be: " << nbvalue << std::endl;
554 for(i=0;i<entry->GetValueCount();i++)
556 if( entry->GetValue(i) != dvalue[i] )
558 std::cout << " Failed" << std::endl
559 << " Content of entry's values is incorrect : id " << i << std::endl
560 << " Found: " << entry->GetValue(i)
561 << " - Must be: " << dvalue[i] << std::endl;
568 std::cout << std::endl;
572 //------------------------------------------------------------------
573 std::cout<<std::flush;