1 /*=========================================================================
4 Module: $RCSfile: TestDataEntry.cxx,v $
6 Date: $Date: 2005/10/18 19:06:29 $
7 Version: $Revision: 1.2 $
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 *[])
38 gdcm::DictEntry *dict;
39 gdcm::DataEntry *entry;
41 //------------------------------------------------------------------
42 dict = new gdcm::DictEntry(0x0000,0x0000);
43 entry = new gdcm::DataEntry(dict);
46 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
48 entry->SetString("1");
50 entry->Print(std::cout);
51 std::cout << std::endl;
52 if( entry->GetValueCount() != 1 )
54 std::cout << " Failed" << std::endl
55 << " Number of content values is incorrect" << std::endl;
61 entry->SetString("1\\2");
63 entry->Print(std::cout);
64 std::cout << std::endl;
65 if( entry->GetValueCount() != 2 )
67 std::cout << " Failed" << std::endl
68 << " Number of content values is incorrect" << std::endl;
76 entry->Print(std::cout);
77 std::cout << std::endl;
78 if( entry->GetValueCount() != 0 )
80 std::cout << " Failed" << std::endl
81 << " Number of content values is incorrect" << std::endl;
87 std::cout << std::endl;
91 //------------------------------------------------------------------
92 dict = new gdcm::DictEntry(0x0000,0x0000);
93 entry = new gdcm::DataEntry(dict);
96 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
97 entry->SetString(data);
98 entry->Print(std::cout);
99 std::cout << std::endl;
101 if( entry->GetLength() != strlen(data) + strlen(data)%2 )
103 std::cout << " Failed" << std::endl
104 << " Size of string is incorrect" << std::endl;
109 if( entry->GetValueCount() != nbvalue )
111 std::cout << " Failed" << std::endl
112 << " Number of content values is incorrect" << std::endl;
117 if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
119 std::cout << " Failed" << std::endl
120 << " Content of bin area is incorrect" << std::endl;
125 if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
127 std::cout << " Failed" << std::endl
128 << " Content of string is incorrect" << std::endl;
133 for(unsigned int i=0;i<entry->GetValueCount();i++)
135 if( entry->GetValue(i) != svalue[i] )
137 std::cout << " Failed" << std::endl
138 << " Content of entry's values is incorrect : id " << i << std::endl
139 << " Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl;
146 std::cout << std::endl;
150 //------------------------------------------------------------------
151 dict = new gdcm::DictEntry(0x0000,0x0000);
152 entry = new gdcm::DataEntry(dict);
155 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
156 entry->SetString(data);
158 entry->Print(std::cout);
159 std::cout << std::endl;
161 if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
163 std::cout << " Failed" << std::endl
164 << " BinArea length is incorrect" << std::endl;
169 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
171 std::cout << " Failed" << std::endl
172 << " Content of string is incorrect" << std::endl;
177 if( entry->GetValueCount() != nbvalue )
179 std::cout << " Failed" << std::endl
180 << " Number of content values is incorrect" << std::endl;
185 for(unsigned int i=0;i<entry->GetValueCount();i++)
187 if( entry->GetValue(i) != svalue[i] )
189 std::cout << " Failed" << std::endl
190 << " Content of entry's values is incorrect : id " << i << std::endl;
197 entry->SetLength(nbvalue*sizeof(uint16_t));
198 entry->SetBinArea((uint8_t *)svalue,false);
200 entry->Print(std::cout);
201 std::cout << std::endl;
203 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
205 std::cout << " Failed" << std::endl
206 << " Content of string is incorrect" << std::endl;
211 if( entry->GetValueCount() != nbvalue )
213 std::cout << " Failed" << std::endl
214 << " Number of content values is incorrect" << std::endl;
219 for(unsigned int i=0;i<entry->GetValueCount();i++)
221 if( entry->GetValue(i) != svalue[i] )
223 std::cout << " Failed" << std::endl
224 << " Content of entry's values is incorrect : id " << i << std::endl;
231 std::cout << std::endl;
235 //------------------------------------------------------------------
236 dict = new gdcm::DictEntry(0x0000,0x0000);
237 entry = new gdcm::DataEntry(dict);
240 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
241 entry->SetString(data);
243 entry->Print(std::cout);
244 std::cout << std::endl;
246 if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
248 std::cout << " Failed" << std::endl
249 << " BinArea length is incorrect" << std::endl;
254 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
256 std::cout << " Failed" << std::endl
257 << " Content of string is incorrect" << std::endl;
258 std::cout<<"#"<<entry->GetString()<<"#"<<" / "<<"#"<<data<<"#"<<std::endl;
263 if( entry->GetValueCount() != nbvalue )
265 std::cout << " Failed" << std::endl
266 << " Number of content values is incorrect" << std::endl;
271 for(unsigned int i=0;i<entry->GetValueCount();i++)
273 if( entry->GetValue(i) != lvalue[i] )
275 std::cout << " Failed" << std::endl
276 << " Content of entry's values is incorrect : id " << i << std::endl;
283 entry->SetLength(nbvalue*sizeof(uint32_t));
284 entry->SetBinArea((uint8_t *)lvalue,false);
286 entry->Print(std::cout);
287 std::cout << std::endl;
289 if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
291 std::cout << " Failed" << std::endl
292 << " Content of string is incorrect" << std::endl;
297 if( entry->GetValueCount() != nbvalue )
299 std::cout << " Failed" << std::endl
300 << " Number of content values is incorrect" << std::endl;
305 for(unsigned int i=0;i<entry->GetValueCount();i++)
307 if( entry->GetValue(i) != lvalue[i] )
309 std::cout << " Failed" << std::endl
310 << " Content of entry's values is incorrect : id " << i << std::endl;
317 std::cout << std::endl;
321 //------------------------------------------------------------------
322 dict = new gdcm::DictEntry(0x0000,0x0000);
323 entry = new gdcm::DataEntry(dict);
326 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
327 entry->SetString(fdata);
329 entry->Print(std::cout);
330 std::cout << std::endl;
332 if( entry->GetLength() != nbvalue*sizeof(float) )
334 std::cout << " Failed" << std::endl
335 << " BinArea length is incorrect" << std::endl;
340 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
342 std::cout << " Failed" << std::endl
343 << " Content of string is incorrect" << std::endl;
348 if( entry->GetValueCount() != nbvalue )
350 std::cout << " Failed" << std::endl
351 << " Number of content values is incorrect" << std::endl;
356 for(unsigned int i=0;i<entry->GetValueCount();i++)
358 if( entry->GetValue(i) != fvalue[i] )
360 std::cout << " Failed" << std::endl
361 << " Content of entry's values is incorrect : id " << i << std::endl;
368 entry->SetLength(nbvalue*sizeof(float));
369 entry->SetBinArea((uint8_t *)fvalue,false);
371 entry->Print(std::cout);
372 std::cout << std::endl;
374 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
376 std::cout << " Failed" << std::endl
377 << " Content of string is incorrect" << std::endl;
382 if( entry->GetValueCount() != nbvalue )
384 std::cout << " Failed" << std::endl
385 << " Number of content values is incorrect" << std::endl;
390 for(unsigned int i=0;i<entry->GetValueCount();i++)
392 if( entry->GetValue(i) != fvalue[i] )
394 std::cout << " Failed" << std::endl
395 << " Content of entry's values is incorrect : id " << i << std::endl;
402 std::cout << std::endl;
406 //------------------------------------------------------------------
407 dict = new gdcm::DictEntry(0x0000,0x0000);
408 entry = new gdcm::DataEntry(dict);
411 std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
412 entry->SetString(fdata);
414 entry->Print(std::cout);
415 std::cout << std::endl;
417 if( entry->GetLength() != nbvalue*sizeof(double) )
419 std::cout << " Failed" << std::endl
420 << " BinArea length is incorrect" << 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;
433 if( entry->GetValueCount() != nbvalue )
435 std::cout << " Failed" << std::endl
436 << " Number of content values is incorrect" << std::endl;
441 for(unsigned int i=0;i<entry->GetValueCount();i++)
443 if( entry->GetValue(i) != dvalue[i] )
445 std::cout << " Failed" << std::endl
446 << " Content of entry's values is incorrect : id " << i << std::endl;
453 entry->SetLength(nbvalue*sizeof(double));
454 entry->SetBinArea((uint8_t *)dvalue,false);
456 entry->Print(std::cout);
457 std::cout << std::endl;
459 if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
461 std::cout << " Failed" << std::endl
462 << " Content of string is incorrect" << std::endl;
467 if( entry->GetValueCount() != nbvalue )
469 std::cout << " Failed" << std::endl
470 << " Number of content values is incorrect" << std::endl;
475 for(unsigned int i=0;i<entry->GetValueCount();i++)
477 if( entry->GetValue(i) != dvalue[i] )
479 std::cout << " Failed" << std::endl
480 << " Content of entry's values is incorrect : id " << i << std::endl;
487 std::cout << std::endl;
491 //------------------------------------------------------------------
492 std::cout<<std::flush;