1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2005/10/19 15:43:58 $
7 Version: $Revision: 1.3 $
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 = new gdcm::DictEntry(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;
62 entry->SetString("1\\2");
64 entry->Print(std::cout);
65 std::cout << std::endl;
66 if( entry->GetValueCount() != 2 )
68 std::cout << " Failed" << std::endl
69 << " Number of content values is incorrect" << std::endl;
77 entry->Print(std::cout);
78 std::cout << std::endl;
79 if( entry->GetValueCount() != 0 )
81 std::cout << " Failed" << std::endl
82 << " Number of content values is incorrect" << std::endl;
88 std::cout << std::endl;
92 //------------------------------------------------------------------
93 dict = new gdcm::DictEntry(0x0000,0x0000);
94 entry = new gdcm::DataEntry(dict);
97 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
98 entry->SetString(data);
99 entry->Print(std::cout);
100 std::cout << std::endl;
102 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
104 std::cout << " Failed" << std::endl
105 << " Size of string is incorrect" << std::endl;
110 if( entry->GetValueCount() != nbvalue )
112 std::cout << " Failed" << std::endl
113 << " Number of content values is incorrect" << std::endl;
118 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
120 std::cout << " Failed" << std::endl
121 << " Content of bin area is incorrect" << std::endl;
126 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
128 std::cout << " Failed" << std::endl
129 << " Content of string is incorrect" << std::endl;
134 for(i=0;i<entry->GetValueCount();i++)
136 if( entry->GetValue(i) != svalue[i] )
138 std::cout << " Failed" << std::endl
139 << " Content of entry's values is incorrect : id " << i << std::endl
140 << " Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl;
147 std::cout << std::endl;
151 //------------------------------------------------------------------
152 dict = new gdcm::DictEntry(0x0000,0x0000);
153 entry = new gdcm::DataEntry(dict);
156 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
157 entry->SetString(data);
159 entry->Print(std::cout);
160 std::cout << std::endl;
162 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
164 std::cout << " Failed" << std::endl
165 << " BinArea length is incorrect" << std::endl;
170 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
172 std::cout << " Failed" << std::endl
173 << " Content of string is incorrect" << std::endl;
178 if( entry->GetValueCount() != nbvalue )
180 std::cout << " Failed" << std::endl
181 << " Number of content values is incorrect" << std::endl;
186 for(i=0;i<entry->GetValueCount();i++)
188 if( entry->GetValue(i) != svalue[i] )
190 std::cout << " Failed" << std::endl
191 << " Content of entry's values is incorrect : id " << i << std::endl;
198 entry->SetLength(nbvalue*sizeof(uint16_t));
199 entry->SetBinArea((uint8_t *)svalue,false);
201 entry->Print(std::cout);
202 std::cout << std::endl;
204 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
206 std::cout << " Failed" << std::endl
207 << " Content of string is incorrect" << std::endl;
212 if( entry->GetValueCount() != nbvalue )
214 std::cout << " Failed" << std::endl
215 << " Number of content values is incorrect" << std::endl;
220 for(i=0;i<entry->GetValueCount();i++)
222 if( entry->GetValue(i) != svalue[i] )
224 std::cout << " Failed" << std::endl
225 << " Content of entry's values is incorrect : id " << i << std::endl;
232 std::cout << std::endl;
236 //------------------------------------------------------------------
237 dict = new gdcm::DictEntry(0x0000,0x0000);
238 entry = new gdcm::DataEntry(dict);
241 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
242 entry->SetString(data);
244 entry->Print(std::cout);
245 std::cout << std::endl;
247 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
249 std::cout << " Failed" << std::endl
250 << " BinArea length is incorrect" << std::endl;
255 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
257 std::cout << " Failed" << std::endl
258 << " Content of string is incorrect" << std::endl;
259 std::cout<<"#"<<entry->GetString()<<"#"<<" / "<<"#"<<data<<"#"<<std::endl;
264 if( entry->GetValueCount() != nbvalue )
266 std::cout << " Failed" << std::endl
267 << " Number of content values is incorrect" << std::endl;
272 for(i=0;i<entry->GetValueCount();i++)
274 if( entry->GetValue(i) != lvalue[i] )
276 std::cout << " Failed" << std::endl
277 << " Content of entry's values is incorrect : id " << i << std::endl;
284 entry->SetLength(nbvalue*sizeof(uint32_t));
285 entry->SetBinArea((uint8_t *)lvalue,false);
287 entry->Print(std::cout);
288 std::cout << std::endl;
290 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
292 std::cout << " Failed" << std::endl
293 << " Content of string is incorrect" << std::endl;
298 if( entry->GetValueCount() != nbvalue )
300 std::cout << " Failed" << std::endl
301 << " Number of content values is incorrect" << 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;
318 std::cout << std::endl;
322 //------------------------------------------------------------------
323 dict = new gdcm::DictEntry(0x0000,0x0000);
324 entry = new gdcm::DataEntry(dict);
327 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
328 entry->SetString(fdata);
330 entry->Print(std::cout);
331 std::cout << std::endl;
333 if( entry->GetLength() != nbvalue*sizeof(float) )
335 std::cout << " Failed" << std::endl
336 << " BinArea length is incorrect" << std::endl;
341 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
343 std::cout << " Failed" << std::endl
344 << " Content of string is incorrect" << std::endl;
349 if( entry->GetValueCount() != nbvalue )
351 std::cout << " Failed" << std::endl
352 << " Number of content values is incorrect" << std::endl;
357 for(i=0;i<entry->GetValueCount();i++)
359 if( entry->GetValue(i) != fvalue[i] )
361 std::cout << " Failed" << std::endl
362 << " Content of entry's values is incorrect : id " << i << std::endl;
369 entry->SetLength(nbvalue*sizeof(float));
370 entry->SetBinArea((uint8_t *)fvalue,false);
372 entry->Print(std::cout);
373 std::cout << std::endl;
375 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
377 std::cout << " Failed" << std::endl
378 << " Content of string is incorrect" << std::endl;
383 if( entry->GetValueCount() != nbvalue )
385 std::cout << " Failed" << std::endl
386 << " Number of content values is incorrect" << std::endl;
391 for(i=0;i<entry->GetValueCount();i++)
393 if( entry->GetValue(i) != fvalue[i] )
395 std::cout << " Failed" << std::endl
396 << " Content of entry's values is incorrect : id " << i << std::endl;
403 std::cout << std::endl;
407 //------------------------------------------------------------------
408 dict = new gdcm::DictEntry(0x0000,0x0000);
409 entry = new gdcm::DataEntry(dict);
412 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
413 entry->SetString(fdata);
415 entry->Print(std::cout);
416 std::cout << std::endl;
418 if( entry->GetLength() != nbvalue*sizeof(double) )
420 std::cout << " Failed" << std::endl
421 << " BinArea length is incorrect" << std::endl;
426 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
428 std::cout << " Failed" << std::endl
429 << " Content of string is incorrect" << std::endl;
434 if( entry->GetValueCount() != nbvalue )
436 std::cout << " Failed" << std::endl
437 << " Number of content values is incorrect" << std::endl;
442 for(i=0;i<entry->GetValueCount();i++)
444 if( entry->GetValue(i) != dvalue[i] )
446 std::cout << " Failed" << std::endl
447 << " Content of entry's values is incorrect : id " << i << std::endl;
454 entry->SetLength(nbvalue*sizeof(double));
455 entry->SetBinArea((uint8_t *)dvalue,false);
457 entry->Print(std::cout);
458 std::cout << std::endl;
460 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
462 std::cout << " Failed" << std::endl
463 << " Content of string is incorrect" << std::endl;
468 if( entry->GetValueCount() != nbvalue )
470 std::cout << " Failed" << std::endl
471 << " Number of content values is incorrect" << std::endl;
476 for(i=0;i<entry->GetValueCount();i++)
478 if( entry->GetValue(i) != dvalue[i] )
480 std::cout << " Failed" << std::endl
481 << " Content of entry's values is incorrect : id " << i << std::endl;
488 std::cout << std::endl;
492 //------------------------------------------------------------------
493 std::cout<<std::flush;