1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2005/10/20 15:24:05 $
7 Version: $Revision: 1.5 $
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"
21 // ===============================================================
23 char data[]="1\\2\\3\\4\\5";
24 char fdata[]="1.1\\2.2\\3.3\\4.4\\5.5";
26 short svalue[]={1,2,3,4,5};
27 long lvalue[]={1,2,3,4,5};
28 float fvalue[]={1.1f,2.2f,3.3f,4.4f,5.5f};
29 double dvalue[]={1.1,2.2,3.3,4.4,5.5};
31 unsigned long nbvalue = 5;
34 * \brief Test the DataEntry object
36 int TestDataEntry(int , char *[])
39 gdcm::DictEntry *dict;
40 gdcm::DataEntry *entry;
42 //------------------------------------------------------------------
43 dict = gdcm::DictEntry::New(0x0000,0x0000);
44 entry = new gdcm::DataEntry(dict);
47 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
49 entry->SetString("1");
51 entry->Print(std::cout);
52 std::cout << std::endl;
53 if( entry->GetValueCount() != 1 )
55 std::cout << " Failed" << std::endl
56 << " Number of content values is incorrect" << std::endl
57 << " Found: " << entry->GetValueCount()
58 << " - Must be: 1" << std::endl;
64 entry->SetString("1\\2");
66 entry->Print(std::cout);
67 std::cout << std::endl;
68 if( entry->GetValueCount() != 2 )
70 std::cout << " Failed" << std::endl
71 << " Number of content values is incorrect" << std::endl
72 << " Found: " << entry->GetValueCount()
73 << " - Must be: 2" << std::endl;
81 entry->Print(std::cout);
82 std::cout << std::endl;
83 if( entry->GetValueCount() != 0 )
85 std::cout << " Failed" << std::endl
86 << " Number of content values is incorrect" << std::endl
87 << " Found: " << entry->GetValueCount()
88 << " - Must be: 0" << std::endl;
94 std::cout << std::endl;
98 //------------------------------------------------------------------
99 dict = gdcm::DictEntry::New(0x0000,0x0000);
100 entry = new gdcm::DataEntry(dict);
103 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
104 entry->SetString(data);
105 entry->Print(std::cout);
106 std::cout << std::endl;
108 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
110 std::cout << " Failed" << std::endl
111 << " Size of string is incorrect" << std::endl
112 << " Found: " << entry->GetLength()
113 << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
118 if( entry->GetValueCount() != nbvalue )
120 std::cout << " Failed" << std::endl
121 << " Number of content values is incorrect" << std::endl
122 << " Found: " << entry->GetValueCount()
123 << " - Must be: " << nbvalue << std::endl;
128 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
130 std::cout << " Failed" << std::endl
131 << " Content of bin area is incorrect" << std::endl;
136 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
138 std::cout << " Failed" << std::endl
139 << " Content of string is incorrect" << std::endl
140 << " Found: " << entry->GetString().c_str()
141 << " - Must be: " << data << std::endl;
146 for(i=0;i<entry->GetValueCount();i++)
148 if( entry->GetValue(i) != svalue[i] )
150 std::cout << " Failed" << std::endl
151 << " Content of entry's values is incorrect : id " << i << std::endl
152 << " Found " << entry->GetValue(i)
153 << " - Must be " << svalue[i] << std::endl;
160 std::cout << std::endl;
164 //------------------------------------------------------------------
165 dict = gdcm::DictEntry::New(0x0000,0x0000);
166 entry = new gdcm::DataEntry(dict);
169 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
170 entry->SetString(data);
172 entry->Print(std::cout);
173 std::cout << std::endl;
175 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
177 std::cout << " Failed" << std::endl
178 << " BinArea length is incorrect" << std::endl
179 << " Found: " << entry->GetLength()
180 << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
185 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
187 std::cout << " Failed" << std::endl
188 << " Content of string is incorrect" << std::endl
189 << " Found: " << entry->GetString().c_str()
190 << " - Must be: " << data << std::endl;
195 if( entry->GetValueCount() != nbvalue )
197 std::cout << " Failed" << std::endl
198 << " Number of content values is incorrect" << std::endl
199 << " Found: " << entry->GetValueCount()
200 << " - Must be: " << nbvalue << std::endl;
205 for(i=0;i<entry->GetValueCount();i++)
207 if( entry->GetValue(i) != svalue[i] )
209 std::cout << " Failed" << std::endl
210 << " Content of entry's values is incorrect : id " << i << std::endl
211 << " Found: " << entry->GetValue(i)
212 << " - Must be: " << svalue[i] << std::endl;
219 entry->SetLength(nbvalue*sizeof(uint16_t));
220 entry->SetBinArea((uint8_t *)svalue,false);
222 entry->Print(std::cout);
223 std::cout << std::endl;
225 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
227 std::cout << " Failed" << std::endl
228 << " Content of string is incorrect" << std::endl
229 << " Found: " << entry->GetString().c_str()
230 << " - Must be: " << data << std::endl;
235 if( entry->GetValueCount() != nbvalue )
237 std::cout << " Failed" << std::endl
238 << " Number of content values is incorrect" << std::endl
239 << " Found: " << entry->GetValueCount()
240 << " - Must be: " << nbvalue << std::endl;
245 for(i=0;i<entry->GetValueCount();i++)
247 if( entry->GetValue(i) != svalue[i] )
249 std::cout << " Failed" << std::endl
250 << " Content of entry's values is incorrect : id " << i << std::endl
251 << " Found: " << entry->GetValue(i)
252 << " - Must be: " << svalue[i] << std::endl;
259 std::cout << std::endl;
263 //------------------------------------------------------------------
264 dict = gdcm::DictEntry::New(0x0000,0x0000);
265 entry = new gdcm::DataEntry(dict);
268 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
269 entry->SetString(data);
271 entry->Print(std::cout);
272 std::cout << std::endl;
274 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
276 std::cout << " Failed" << std::endl
277 << " BinArea length is incorrect" << std::endl
278 << " Found: " << entry->GetLength()
279 << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
284 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
286 std::cout << " Failed" << std::endl
287 << " Content of string is incorrect" << std::endl
288 << " Found: " << entry->GetString().c_str()
289 << " - Must be: " << data << std::endl;
294 if( entry->GetValueCount() != nbvalue )
296 std::cout << " Failed" << std::endl
297 << " Number of content values is incorrect" << std::endl
298 << " Found: " << entry->GetValueCount()
299 << " - Must be: " << nbvalue << std::endl;
304 for(i=0;i<entry->GetValueCount();i++)
306 if( entry->GetValue(i) != lvalue[i] )
308 std::cout << " Failed" << std::endl
309 << " Content of entry's values is incorrect : id " << i << std::endl
310 << " Found: " << entry->GetValue(i)
311 << " - Must be: " << lvalue[i] << std::endl;
318 entry->SetLength(nbvalue*sizeof(uint32_t));
319 entry->SetBinArea((uint8_t *)lvalue,false);
321 entry->Print(std::cout);
322 std::cout << std::endl;
324 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
326 std::cout << " Failed" << std::endl
327 << " Content of string is incorrect" << std::endl
328 << " Found: " << entry->GetString().c_str()
329 << " - Must be: " << data << std::endl;
334 if( entry->GetValueCount() != nbvalue )
336 std::cout << " Failed" << std::endl
337 << " Number of content values is incorrect" << std::endl
338 << " Found: " << entry->GetValueCount()
339 << " - Must be: " << nbvalue << std::endl;
344 for(i=0;i<entry->GetValueCount();i++)
346 if( entry->GetValue(i) != lvalue[i] )
348 std::cout << " Failed" << std::endl
349 << " Content of entry's values is incorrect : id " << i << std::endl
350 << " Found: " << entry->GetValue(i)
351 << " - Must be: " << lvalue[i] << std::endl;
358 std::cout << std::endl;
362 //------------------------------------------------------------------
363 dict = gdcm::DictEntry::New(0x0000,0x0000);
364 entry = new gdcm::DataEntry(dict);
367 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
368 entry->SetString(fdata);
370 entry->Print(std::cout);
371 std::cout << std::endl;
373 if( entry->GetLength() != nbvalue*sizeof(float) )
375 std::cout << " Failed" << std::endl
376 << " BinArea length is incorrect" << std::endl
377 << " Found: " << entry->GetLength()
378 << " - Must be: " << nbvalue*sizeof(float) << std::endl;
383 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
385 std::cout << " Failed" << std::endl
386 << " Content of string is incorrect" << std::endl
387 << " Found: " << entry->GetString().c_str()
388 << " - Must be: " << fdata << std::endl;
393 if( entry->GetValueCount() != nbvalue )
395 std::cout << " Failed" << std::endl
396 << " Number of content values is incorrect" << std::endl
397 << " Found: " << entry->GetValueCount()
398 << " - Must be: " << nbvalue << std::endl;
403 for(i=0;i<entry->GetValueCount();i++)
405 if( entry->GetValue(i) != fvalue[i] )
407 std::cout << " Failed" << std::endl
408 << " Content of entry's values is incorrect : id " << i << std::endl
409 << " Found: " << entry->GetValue(i)
410 << " - Must be: " << fvalue[i] << std::endl;
417 entry->SetLength(nbvalue*sizeof(float));
418 entry->SetBinArea((uint8_t *)fvalue,false);
420 entry->Print(std::cout);
421 std::cout << std::endl;
423 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
425 std::cout << " Failed" << std::endl
426 << " Content of string is incorrect" << std::endl
427 << " Found: " << entry->GetString().c_str()
428 << " - Must be: " << fdata << std::endl;
433 if( entry->GetValueCount() != nbvalue )
435 std::cout << " Failed" << std::endl
436 << " Number of content values is incorrect" << std::endl
437 << " Found: " << entry->GetValueCount()
438 << " - Must be: " << nbvalue << std::endl;
443 for(i=0;i<entry->GetValueCount();i++)
445 if( entry->GetValue(i) != fvalue[i] )
447 std::cout << " Failed" << std::endl
448 << " Content of entry's values is incorrect : id " << i << std::endl
449 << " Found: " << entry->GetValue(i)
450 << " - Must be: " << fvalue[i] << std::endl;
457 std::cout << std::endl;
461 //------------------------------------------------------------------
462 dict = gdcm::DictEntry::New(0x0000,0x0000);
463 entry = new gdcm::DataEntry(dict);
466 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
467 entry->SetString(fdata);
469 entry->Print(std::cout);
470 std::cout << std::endl;
472 if( entry->GetLength() != nbvalue*sizeof(double) )
474 std::cout << " Failed" << std::endl
475 << " BinArea length is incorrect" << std::endl
476 << " Found: " << entry->GetLength()
477 << " - Must be: " << nbvalue*sizeof(double) << std::endl;
482 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
484 std::cout << " Failed" << std::endl
485 << " Content of string is incorrect" << std::endl
486 << " Found: " << entry->GetString().c_str()
487 << " - Must be: " << fdata << std::endl;
492 if( entry->GetValueCount() != nbvalue )
494 std::cout << " Failed" << std::endl
495 << " Number of content values is incorrect" << std::endl
496 << " Found: " << entry->GetValueCount()
497 << " - Must be: " << nbvalue << std::endl;
502 for(i=0;i<entry->GetValueCount();i++)
504 if( entry->GetValue(i) != dvalue[i] )
506 std::cout << " Failed" << std::endl
507 << " Content of entry's values is incorrect : id " << i << std::endl
508 << " Found: " << entry->GetValue(i)
509 << " - Must be: " << dvalue[i] << std::endl;
516 entry->SetLength(nbvalue*sizeof(double));
517 entry->SetBinArea((uint8_t *)dvalue,false);
519 entry->Print(std::cout);
520 std::cout << std::endl;
522 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
524 std::cout << " Failed" << std::endl
525 << " Content of string is incorrect" << std::endl
526 << " Found: " << entry->GetString().c_str()
527 << " - Must be: " << fdata << std::endl;
532 if( entry->GetValueCount() != nbvalue )
534 std::cout << " Failed" << std::endl
535 << " Number of content values is incorrect" << std::endl
536 << " Found: " << entry->GetValueCount()
537 << " - Must be: " << nbvalue << std::endl;
542 for(i=0;i<entry->GetValueCount();i++)
544 if( entry->GetValue(i) != dvalue[i] )
546 std::cout << " Failed" << std::endl
547 << " Content of entry's values is incorrect : id " << i << std::endl
548 << " Found: " << entry->GetValue(i)
549 << " - Must be: " << dvalue[i] << std::endl;
556 std::cout << std::endl;
560 //------------------------------------------------------------------
561 std::cout<<std::flush;