1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2005/10/24 16:00:46 $
7 Version: $Revision: 1.9 $
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(0x0000,0x0000);
46 entry = gdcm::DataEntry::New(dict);
49 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
51 entry->SetString("1");
53 entry->Print(std::cout);
54 std::cout << std::endl;
55 if( entry->GetValueCount() != 1 )
57 std::cout << " Failed" << std::endl
58 << " Number of content values is incorrect" << std::endl
59 << " Found: " << entry->GetValueCount()
60 << " - Must be: 1" << std::endl;
66 entry->SetString("1\\2");
68 entry->Print(std::cout);
69 std::cout << std::endl;
70 if( entry->GetValueCount() != 2 )
72 std::cout << " Failed" << std::endl
73 << " Number of content values is incorrect" << std::endl
74 << " Found: " << entry->GetValueCount()
75 << " - Must be: 2" << std::endl;
83 entry->Print(std::cout);
84 std::cout << std::endl;
85 if( entry->GetValueCount() != 0 )
87 std::cout << " Failed" << std::endl
88 << " Number of content values is incorrect" << std::endl
89 << " Found: " << entry->GetValueCount()
90 << " - Must be: 0" << std::endl;
96 std::cout << std::endl;
100 //------------------------------------------------------------------
101 dict = gdcm::DictEntry::New(0x0000,0x0000);
102 entry = gdcm::DataEntry::New(dict);
105 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
106 entry->SetString(data);
107 entry->Print(std::cout);
108 std::cout << std::endl;
110 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
112 std::cout << " Failed" << std::endl
113 << " Size of string is incorrect" << std::endl
114 << " Found: " << entry->GetLength()
115 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
120 if( entry->GetValueCount() != nbvalue )
122 std::cout << " Failed" << std::endl
123 << " Number of content values is incorrect" << std::endl
124 << " Found: " << entry->GetValueCount()
125 << " - Must be: " << nbvalue << std::endl;
130 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
132 std::cout << " Failed" << std::endl
133 << " Content of bin area is incorrect" << std::endl;
138 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
140 std::cout << " Failed" << std::endl
141 << " Content of string is incorrect" << std::endl
142 << " Found: " << entry->GetString().c_str()
143 << " - Must be: " << data << std::endl;
148 for(i=0;i<entry->GetValueCount();i++)
150 if( entry->GetValue(i) != svalue[i] )
152 std::cout << " Failed" << std::endl
153 << " Content of entry's values is incorrect : id " << i << std::endl
154 << " Found " << entry->GetValue(i)
155 << " - Must be " << svalue[i] << std::endl;
162 std::cout << std::endl;
166 //------------------------------------------------------------------
167 dict = gdcm::DictEntry::New(0x0000,0x0000);
168 entry = gdcm::DataEntry::New(dict);
171 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
172 entry->SetString(data);
174 entry->Print(std::cout);
175 std::cout << std::endl;
177 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
179 std::cout << " Failed" << std::endl
180 << " BinArea length is incorrect" << std::endl
181 << " Found: " << entry->GetLength()
182 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
187 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
189 std::cout << " Failed" << std::endl
190 << " Content of string is incorrect" << std::endl
191 << " Found: " << entry->GetString().c_str()
192 << " - Must be: " << data << std::endl;
197 if( entry->GetValueCount() != nbvalue )
199 std::cout << " Failed" << std::endl
200 << " Number of content values is incorrect" << std::endl
201 << " Found: " << entry->GetValueCount()
202 << " - Must be: " << nbvalue << std::endl;
207 for(i=0;i<entry->GetValueCount();i++)
209 if( entry->GetValue(i) != svalue[i] )
211 std::cout << " Failed" << std::endl
212 << " Content of entry's values is incorrect : id " << i << std::endl
213 << " Found: " << entry->GetValue(i)
214 << " - Must be: " << svalue[i] << std::endl;
221 entry->SetLength(nbvalue*sizeof(uint16_t));
222 entry->SetBinArea((uint8_t *)svalue,false);
224 entry->Print(std::cout);
225 std::cout << std::endl;
227 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
229 std::cout << " Failed" << std::endl
230 << " Content of string is incorrect" << std::endl
231 << " Found: " << entry->GetString().c_str()
232 << " - Must be: " << data << std::endl;
237 if( entry->GetValueCount() != nbvalue )
239 std::cout << " Failed" << std::endl
240 << " Number of content values is incorrect" << std::endl
241 << " Found: " << entry->GetValueCount()
242 << " - Must be: " << nbvalue << std::endl;
247 for(i=0;i<entry->GetValueCount();i++)
249 if( entry->GetValue(i) != svalue[i] )
251 std::cout << " Failed" << std::endl
252 << " Content of entry's values is incorrect : id " << i << std::endl
253 << " Found: " << entry->GetValue(i)
254 << " - Must be: " << svalue[i] << std::endl;
261 std::cout << std::endl;
265 //------------------------------------------------------------------
266 dict = gdcm::DictEntry::New(0x0000,0x0000);
267 entry = gdcm::DataEntry::New(dict);
270 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
271 entry->SetString(data);
273 entry->Print(std::cout);
274 std::cout << std::endl;
276 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
278 std::cout << " Failed" << std::endl
279 << " BinArea length is incorrect" << std::endl
280 << " Found: " << entry->GetLength()
281 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
286 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
288 std::cout << " Failed" << std::endl
289 << " Content of string is incorrect" << std::endl
290 << " Found: " << entry->GetString().c_str()
291 << " - Must be: " << data << std::endl;
296 if( entry->GetValueCount() != nbvalue )
298 std::cout << " Failed" << std::endl
299 << " Number of content values is incorrect" << std::endl
300 << " Found: " << entry->GetValueCount()
301 << " - Must be: " << nbvalue << std::endl;
306 for(i=0;i<entry->GetValueCount();i++)
308 if( entry->GetValue(i) != lvalue[i] )
310 std::cout << " Failed" << std::endl
311 << " Content of entry's values is incorrect : id " << i << std::endl
312 << " Found: " << entry->GetValue(i)
313 << " - Must be: " << lvalue[i] << std::endl;
320 entry->SetLength(nbvalue*sizeof(uint32_t));
321 entry->SetBinArea((uint8_t *)lvalue,false);
323 entry->Print(std::cout);
324 std::cout << std::endl;
326 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
328 std::cout << " Failed" << std::endl
329 << " Content of string is incorrect" << std::endl
330 << " Found: " << entry->GetString().c_str()
331 << " - Must be: " << data << std::endl;
336 if( entry->GetValueCount() != nbvalue )
338 std::cout << " Failed" << std::endl
339 << " Number of content values is incorrect" << std::endl
340 << " Found: " << entry->GetValueCount()
341 << " - Must be: " << nbvalue << std::endl;
346 for(i=0;i<entry->GetValueCount();i++)
348 if( entry->GetValue(i) != lvalue[i] )
350 std::cout << " Failed" << std::endl
351 << " Content of entry's values is incorrect : id " << i << std::endl
352 << " Found: " << entry->GetValue(i)
353 << " - Must be: " << lvalue[i] << std::endl;
360 std::cout << std::endl;
364 //------------------------------------------------------------------
365 dict = gdcm::DictEntry::New(0x0000,0x0000);
366 entry = gdcm::DataEntry::New(dict);
369 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
370 entry->SetString(fdata);
372 entry->Print(std::cout);
373 std::cout << std::endl;
375 if( entry->GetLength() != nbvalue*sizeof(float) )
377 std::cout << " Failed" << std::endl
378 << " BinArea length is incorrect" << std::endl
379 << " Found: " << entry->GetLength()
380 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
385 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
387 std::cout << " Failed" << std::endl
388 << " Content of string is incorrect" << std::endl
389 << " Found: " << entry->GetString().c_str()
390 << " - Must be: " << fdata << std::endl;
395 if( entry->GetValueCount() != nbvalue )
397 std::cout << " Failed" << std::endl
398 << " Number of content values is incorrect" << std::endl
399 << " Found: " << entry->GetValueCount()
400 << " - Must be: " << nbvalue << std::endl;
405 for(i=0;i<entry->GetValueCount();i++)
407 if( entry->GetValue(i) != fvalue[i] )
409 std::cout << " Failed" << std::endl
410 << " Content of entry's values is incorrect : id " << i << std::endl
411 << " Found: " << entry->GetValue(i)
412 << " - Must be: " << fvalue[i] << std::endl;
419 entry->SetLength(nbvalue*sizeof(float));
420 entry->SetBinArea((uint8_t *)fvalue,false);
422 entry->Print(std::cout);
423 std::cout << std::endl;
425 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
427 std::cout << " Failed" << std::endl
428 << " Content of string is incorrect" << std::endl
429 << " Found: " << entry->GetString().c_str()
430 << " - Must be: " << fdata << std::endl;
435 if( entry->GetValueCount() != nbvalue )
437 std::cout << " Failed" << std::endl
438 << " Number of content values is incorrect" << std::endl
439 << " Found: " << entry->GetValueCount()
440 << " - Must be: " << nbvalue << std::endl;
445 for(i=0;i<entry->GetValueCount();i++)
447 if( entry->GetValue(i) != fvalue[i] )
449 std::cout << " Failed" << std::endl
450 << " Content of entry's values is incorrect : id " << i << std::endl
451 << " Found: " << entry->GetValue(i)
452 << " - Must be: " << fvalue[i] << std::endl;
459 std::cout << std::endl;
463 //------------------------------------------------------------------
464 dict = gdcm::DictEntry::New(0x0000,0x0000);
465 entry = gdcm::DataEntry::New(dict);
468 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
469 entry->SetString(fdata);
471 entry->Print(std::cout);
472 std::cout << std::endl;
474 if( entry->GetLength() != nbvalue*sizeof(double) )
476 std::cout << " Failed" << std::endl
477 << " BinArea length is incorrect" << std::endl
478 << " Found: " << entry->GetLength()
479 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
484 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
486 std::cout << " Failed" << std::endl
487 << " Content of string is incorrect" << std::endl
488 << " Found: " << entry->GetString().c_str()
489 << " - Must be: " << fdata << std::endl;
494 if( entry->GetValueCount() != nbvalue )
496 std::cout << " Failed" << std::endl
497 << " Number of content values is incorrect" << std::endl
498 << " Found: " << entry->GetValueCount()
499 << " - Must be: " << nbvalue << std::endl;
504 for(i=0;i<entry->GetValueCount();i++)
506 // Never compare floating point value...
507 double dif = fabs(entry->GetValue(i) - dvalue[i]);
510 std::cout << " Failed" << std::endl
511 << " Content of entry's values is incorrect : id " << i << std::endl
512 << " Found: " << entry->GetValue(i)
513 << " - Must be: " << dvalue[i] << std::endl;
520 entry->SetLength(nbvalue*sizeof(double));
521 entry->SetBinArea((uint8_t *)dvalue,false);
523 entry->Print(std::cout);
524 std::cout << std::endl;
526 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
528 std::cout << " Failed" << std::endl
529 << " Content of string is incorrect" << std::endl
530 << " Found: " << entry->GetString().c_str()
531 << " - Must be: " << fdata << std::endl;
536 if( entry->GetValueCount() != nbvalue )
538 std::cout << " Failed" << std::endl
539 << " Number of content values is incorrect" << std::endl
540 << " Found: " << entry->GetValueCount()
541 << " - Must be: " << nbvalue << std::endl;
546 for(i=0;i<entry->GetValueCount();i++)
548 if( entry->GetValue(i) != dvalue[i] )
550 std::cout << " Failed" << std::endl
551 << " Content of entry's values is incorrect : id " << i << std::endl
552 << " Found: " << entry->GetValue(i)
553 << " - Must be: " << dvalue[i] << std::endl;
560 std::cout << std::endl;
564 //------------------------------------------------------------------
565 std::cout<<std::flush;