1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2005/10/23 19:46:17 $
7 Version: $Revision: 1.6 $
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 // Temporary hack, assume that long and double are correlated
31 #if GDCM_SIZEOF_LONG == 4
32 const double dvalue[]={1.1,2.2,3.3,4.4,5.5};
34 const float dvalue[]={1.1,2.2,3.3,4.4,5.5};
37 const unsigned long nbvalue = 5;
38 const float GDCM_EPS = 1e-6;
41 * \brief Test the DataEntry object
43 int TestDataEntry(int , char *[])
46 gdcm::DictEntry *dict;
47 gdcm::DataEntry *entry;
49 //------------------------------------------------------------------
50 dict = gdcm::DictEntry::New(0x0000,0x0000);
51 entry = new gdcm::DataEntry(dict);
54 std::cout << "Test for VR = " << dict->GetVR() << "..." << 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 entry = new gdcm::DataEntry(dict);
110 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
111 entry->SetString(data);
112 entry->Print(std::cout);
113 std::cout << std::endl;
115 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
117 std::cout << " Failed" << std::endl
118 << " Size of string is incorrect" << std::endl
119 << " Found: " << entry->GetLength()
120 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
125 if( entry->GetValueCount() != nbvalue )
127 std::cout << " Failed" << std::endl
128 << " Number of content values is incorrect" << std::endl
129 << " Found: " << entry->GetValueCount()
130 << " - Must be: " << nbvalue << std::endl;
135 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
137 std::cout << " Failed" << std::endl
138 << " Content of bin area is incorrect" << std::endl;
143 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
145 std::cout << " Failed" << std::endl
146 << " Content of string is incorrect" << std::endl
147 << " Found: " << entry->GetString().c_str()
148 << " - Must be: " << data << std::endl;
153 for(i=0;i<entry->GetValueCount();i++)
155 if( entry->GetValue(i) != svalue[i] )
157 std::cout << " Failed" << std::endl
158 << " Content of entry's values is incorrect : id " << i << std::endl
159 << " Found " << entry->GetValue(i)
160 << " - Must be " << svalue[i] << std::endl;
167 std::cout << std::endl;
171 //------------------------------------------------------------------
172 dict = gdcm::DictEntry::New(0x0000,0x0000);
173 entry = new gdcm::DataEntry(dict);
176 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
177 entry->SetString(data);
179 entry->Print(std::cout);
180 std::cout << std::endl;
182 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
184 std::cout << " Failed" << std::endl
185 << " BinArea length is incorrect" << std::endl
186 << " Found: " << entry->GetLength()
187 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
192 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
194 std::cout << " Failed" << std::endl
195 << " Content of string is incorrect" << std::endl
196 << " Found: " << entry->GetString().c_str()
197 << " - Must be: " << data << std::endl;
202 if( entry->GetValueCount() != nbvalue )
204 std::cout << " Failed" << std::endl
205 << " Number of content values is incorrect" << std::endl
206 << " Found: " << entry->GetValueCount()
207 << " - Must be: " << nbvalue << std::endl;
212 for(i=0;i<entry->GetValueCount();i++)
214 if( entry->GetValue(i) != svalue[i] )
216 std::cout << " Failed" << std::endl
217 << " Content of entry's values is incorrect : id " << i << std::endl
218 << " Found: " << entry->GetValue(i)
219 << " - Must be: " << svalue[i] << std::endl;
226 entry->SetLength(nbvalue*sizeof(uint16_t));
227 entry->SetBinArea((uint8_t *)svalue,false);
229 entry->Print(std::cout);
230 std::cout << std::endl;
232 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
234 std::cout << " Failed" << std::endl
235 << " Content of string is incorrect" << std::endl
236 << " Found: " << entry->GetString().c_str()
237 << " - Must be: " << data << std::endl;
242 if( entry->GetValueCount() != nbvalue )
244 std::cout << " Failed" << std::endl
245 << " Number of content values is incorrect" << std::endl
246 << " Found: " << entry->GetValueCount()
247 << " - Must be: " << nbvalue << std::endl;
252 for(i=0;i<entry->GetValueCount();i++)
254 if( entry->GetValue(i) != svalue[i] )
256 std::cout << " Failed" << std::endl
257 << " Content of entry's values is incorrect : id " << i << std::endl
258 << " Found: " << entry->GetValue(i)
259 << " - Must be: " << svalue[i] << std::endl;
266 std::cout << std::endl;
270 //------------------------------------------------------------------
271 dict = gdcm::DictEntry::New(0x0000,0x0000);
272 entry = new gdcm::DataEntry(dict);
275 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
276 entry->SetString(data);
278 entry->Print(std::cout);
279 std::cout << std::endl;
281 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
283 std::cout << " Failed" << std::endl
284 << " BinArea length is incorrect" << std::endl
285 << " Found: " << entry->GetLength()
286 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
291 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
293 std::cout << " Failed" << std::endl
294 << " Content of string is incorrect" << std::endl
295 << " Found: " << entry->GetString().c_str()
296 << " - Must be: " << data << std::endl;
301 if( entry->GetValueCount() != nbvalue )
303 std::cout << " Failed" << std::endl
304 << " Number of content values is incorrect" << std::endl
305 << " Found: " << entry->GetValueCount()
306 << " - Must be: " << nbvalue << std::endl;
311 for(i=0;i<entry->GetValueCount();i++)
313 if( entry->GetValue(i) != lvalue[i] )
315 std::cout << " Failed" << std::endl
316 << " Content of entry's values is incorrect : id " << i << std::endl
317 << " Found: " << entry->GetValue(i)
318 << " - Must be: " << lvalue[i] << std::endl;
325 entry->SetLength(nbvalue*sizeof(uint32_t));
326 entry->SetBinArea((uint8_t *)lvalue,false);
328 entry->Print(std::cout);
329 std::cout << std::endl;
331 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
333 std::cout << " Failed" << std::endl
334 << " Content of string is incorrect" << std::endl
335 << " Found: " << entry->GetString().c_str()
336 << " - Must be: " << data << std::endl;
341 if( entry->GetValueCount() != nbvalue )
343 std::cout << " Failed" << std::endl
344 << " Number of content values is incorrect" << std::endl
345 << " Found: " << entry->GetValueCount()
346 << " - Must be: " << nbvalue << std::endl;
351 for(i=0;i<entry->GetValueCount();i++)
353 if( entry->GetValue(i) != lvalue[i] )
355 std::cout << " Failed" << std::endl
356 << " Content of entry's values is incorrect : id " << i << std::endl
357 << " Found: " << entry->GetValue(i)
358 << " - Must be: " << lvalue[i] << std::endl;
365 std::cout << std::endl;
369 //------------------------------------------------------------------
370 dict = gdcm::DictEntry::New(0x0000,0x0000);
371 entry = new gdcm::DataEntry(dict);
374 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
375 entry->SetString(fdata);
377 entry->Print(std::cout);
378 std::cout << std::endl;
380 if( entry->GetLength() != nbvalue*sizeof(float) )
382 std::cout << " Failed" << std::endl
383 << " BinArea length is incorrect" << std::endl
384 << " Found: " << entry->GetLength()
385 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
390 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
392 std::cout << " Failed" << std::endl
393 << " Content of string is incorrect" << std::endl
394 << " Found: " << entry->GetString().c_str()
395 << " - Must be: " << fdata << std::endl;
400 if( entry->GetValueCount() != nbvalue )
402 std::cout << " Failed" << std::endl
403 << " Number of content values is incorrect" << std::endl
404 << " Found: " << entry->GetValueCount()
405 << " - Must be: " << nbvalue << std::endl;
410 for(i=0;i<entry->GetValueCount();i++)
412 if( entry->GetValue(i) != fvalue[i] )
414 std::cout << " Failed" << std::endl
415 << " Content of entry's values is incorrect : id " << i << std::endl
416 << " Found: " << entry->GetValue(i)
417 << " - Must be: " << fvalue[i] << std::endl;
424 entry->SetLength(nbvalue*sizeof(float));
425 entry->SetBinArea((uint8_t *)fvalue,false);
427 entry->Print(std::cout);
428 std::cout << std::endl;
430 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
432 std::cout << " Failed" << std::endl
433 << " Content of string is incorrect" << std::endl
434 << " Found: " << entry->GetString().c_str()
435 << " - Must be: " << fdata << std::endl;
440 if( entry->GetValueCount() != nbvalue )
442 std::cout << " Failed" << std::endl
443 << " Number of content values is incorrect" << std::endl
444 << " Found: " << entry->GetValueCount()
445 << " - Must be: " << nbvalue << std::endl;
450 for(i=0;i<entry->GetValueCount();i++)
452 if( entry->GetValue(i) != fvalue[i] )
454 std::cout << " Failed" << std::endl
455 << " Content of entry's values is incorrect : id " << i << std::endl
456 << " Found: " << entry->GetValue(i)
457 << " - Must be: " << fvalue[i] << std::endl;
464 std::cout << std::endl;
468 //------------------------------------------------------------------
469 dict = gdcm::DictEntry::New(0x0000,0x0000);
470 entry = new gdcm::DataEntry(dict);
473 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
474 entry->SetString(fdata);
476 entry->Print(std::cout);
477 std::cout << std::endl;
479 if( entry->GetLength() != nbvalue*sizeof(double) )
481 std::cout << " Failed" << std::endl
482 << " BinArea length is incorrect" << std::endl
483 << " Found: " << entry->GetLength()
484 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
489 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
491 std::cout << " Failed" << std::endl
492 << " Content of string is incorrect" << std::endl
493 << " Found: " << entry->GetString().c_str()
494 << " - Must be: " << fdata << std::endl;
499 if( entry->GetValueCount() != nbvalue )
501 std::cout << " Failed" << std::endl
502 << " Number of content values is incorrect" << std::endl
503 << " Found: " << entry->GetValueCount()
504 << " - Must be: " << nbvalue << std::endl;
509 for(i=0;i<entry->GetValueCount();i++)
511 // Never compare floating point value...
512 double dif = fabs(entry->GetValue(i) - dvalue[i]);
515 std::cout << " Failed" << std::endl
516 << " Content of entry's values is incorrect : id " << i << std::endl
517 << " Found: " << entry->GetValue(i)
518 << " - Must be: " << dvalue[i] << std::endl;
525 entry->SetLength(nbvalue*sizeof(double));
526 entry->SetBinArea((uint8_t *)dvalue,false);
528 entry->Print(std::cout);
529 std::cout << std::endl;
531 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
533 std::cout << " Failed" << std::endl
534 << " Content of string is incorrect" << std::endl
535 << " Found: " << entry->GetString().c_str()
536 << " - Must be: " << fdata << std::endl;
541 if( entry->GetValueCount() != nbvalue )
543 std::cout << " Failed" << std::endl
544 << " Number of content values is incorrect" << std::endl
545 << " Found: " << entry->GetValueCount()
546 << " - Must be: " << nbvalue << std::endl;
551 for(i=0;i<entry->GetValueCount();i++)
553 if( entry->GetValue(i) != dvalue[i] )
555 std::cout << " Failed" << std::endl
556 << " Content of entry's values is incorrect : id " << i << std::endl
557 << " Found: " << entry->GetValue(i)
558 << " - Must be: " << dvalue[i] << std::endl;
565 std::cout << std::endl;
569 //------------------------------------------------------------------
570 std::cout<<std::flush;