]> Creatis software - gdcm.git/blob - Testing/TestDataEntry.cxx
COMP: Please VS6
[gdcm.git] / Testing / TestDataEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestDataEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/19 15:43:58 $
7   Version:   $Revision: 1.3 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDictEntry.h"
19 #include "gdcmDataEntry.h"
20
21 // ===============================================================
22
23 char data[]="1\\2\\3\\4\\5";
24 char fdata[]="1.1\\2.2\\3.3\\4.4\\5.5";
25
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};
30
31 unsigned long nbvalue = 5;
32
33 /**
34   * \brief Test the DataEntry object
35   */  
36 int TestDataEntry(int , char *[])
37 {
38    unsigned int i;
39    gdcm::DictEntry *dict;
40    gdcm::DataEntry *entry;
41
42    //------------------------------------------------------------------
43    dict = new gdcm::DictEntry(0x0000,0x0000);
44    entry = new gdcm::DataEntry(dict);
45    dict->SetVR("US");
46
47    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
48
49    entry->SetString("1");
50    std::cout << "1: ";
51    entry->Print(std::cout);
52    std::cout << std::endl;
53    if( entry->GetValueCount() != 1 )
54    {
55       std::cout << "   Failed" << std::endl
56                 << "   Number of content values is incorrect" << std::endl;
57       delete dict;
58       delete entry;
59       return(1);
60    }
61
62    entry->SetString("1\\2");
63    std::cout << "2: ";
64    entry->Print(std::cout);
65    std::cout << std::endl;
66    if( entry->GetValueCount() != 2 )
67    {
68       std::cout << "   Failed" << std::endl
69                 << "   Number of content values is incorrect" << std::endl;
70       delete dict;
71       delete entry;
72       return(1);
73    }
74
75    entry->SetString("");
76    std::cout << "3: ";
77    entry->Print(std::cout);
78    std::cout << std::endl;
79    if( entry->GetValueCount() != 0 )
80    {
81       std::cout << "   Failed" << std::endl
82                 << "   Number of content values is incorrect" << std::endl;
83       delete dict;
84       delete entry;
85       return(1);
86    }
87
88    std::cout << std::endl;
89    delete dict;
90    delete entry;
91
92    //------------------------------------------------------------------
93    dict = new gdcm::DictEntry(0x0000,0x0000);
94    entry = new gdcm::DataEntry(dict);
95    dict->SetVR("LT");
96
97    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
98    entry->SetString(data);
99    entry->Print(std::cout);
100    std::cout << std::endl;
101
102    if( entry->GetLength() != strlen(data) + strlen(data)%2 )
103    {
104       std::cout << "   Failed" << std::endl
105                 << "   Size of string is incorrect" << std::endl;
106       delete dict;
107       delete entry;
108       return(1);
109    }
110    if( entry->GetValueCount() != nbvalue )
111    {
112       std::cout << "   Failed" << std::endl
113                 << "   Number of content values is incorrect" << std::endl;
114       delete dict;
115       delete entry;
116       return(1);
117    }
118    if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 )
119    {
120       std::cout << "   Failed" << std::endl
121                 << "   Content of bin area is incorrect" << std::endl;
122       delete dict;
123       delete entry;
124       return(1);
125    }
126    if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
127    {
128       std::cout << "   Failed" << std::endl
129                 << "   Content of string is incorrect" << std::endl;
130       delete dict;
131       delete entry;
132       return(1);
133    }
134    for(i=0;i<entry->GetValueCount();i++)
135    {
136       if( entry->GetValue(i) != svalue[i] )
137       {
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;
141          delete dict;
142          delete entry;
143          return(1);
144       }
145    }
146
147    std::cout << std::endl;
148    delete dict;
149    delete entry;
150
151    //------------------------------------------------------------------
152    dict = new gdcm::DictEntry(0x0000,0x0000);
153    entry = new gdcm::DataEntry(dict);
154    dict->SetVR("US");
155
156    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
157    entry->SetString(data);
158    std::cout << "1: ";
159    entry->Print(std::cout);
160    std::cout << std::endl;
161
162    if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
163    {
164       std::cout << "   Failed" << std::endl
165                 << "   BinArea length is incorrect" << std::endl;
166       delete dict;
167       delete entry;
168       return(1);
169    }
170    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
171    {
172       std::cout << "   Failed" << std::endl
173                 << "   Content of string is incorrect" << std::endl;
174       delete dict;
175       delete entry;
176       return(1);
177    }
178    if( entry->GetValueCount() != nbvalue )
179    {
180       std::cout << "   Failed" << std::endl
181                 << "   Number of content values is incorrect" << std::endl;
182       delete dict;
183       delete entry;
184       return(1);
185    }
186    for(i=0;i<entry->GetValueCount();i++)
187    {
188       if( entry->GetValue(i) != svalue[i] )
189       {
190          std::cout << "   Failed" << std::endl
191                    << "   Content of entry's values is incorrect : id " << i << std::endl;
192          delete dict;
193          delete entry;
194          return(1);
195       }
196    }
197
198    entry->SetLength(nbvalue*sizeof(uint16_t));
199    entry->SetBinArea((uint8_t *)svalue,false);
200    std::cout << "2: ";
201    entry->Print(std::cout);
202    std::cout << std::endl;
203
204    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
205    {
206       std::cout << "   Failed" << std::endl
207                 << "   Content of string is incorrect" << std::endl;
208       delete dict;
209       delete entry;
210       return(1);
211    }
212    if( entry->GetValueCount() != nbvalue )
213    {
214       std::cout << "   Failed" << std::endl
215                 << "   Number of content values is incorrect" << std::endl;
216       delete dict;
217       delete entry;
218       return(1);
219    }
220    for(i=0;i<entry->GetValueCount();i++)
221    {
222       if( entry->GetValue(i) != svalue[i] )
223       {
224          std::cout << "   Failed" << std::endl
225                    << "   Content of entry's values is incorrect : id " << i << std::endl;
226          delete dict;
227          delete entry;
228          return(1);
229       }
230    }
231
232    std::cout << std::endl;
233    delete dict;
234    delete entry;
235
236    //------------------------------------------------------------------
237    dict = new gdcm::DictEntry(0x0000,0x0000);
238    entry = new gdcm::DataEntry(dict);
239    dict->SetVR("UL");
240
241    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
242    entry->SetString(data);
243    std::cout << "1: ";
244    entry->Print(std::cout);
245    std::cout << std::endl;
246
247    if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
248    {
249       std::cout << "   Failed" << std::endl
250                 << "   BinArea length is incorrect" << std::endl;
251       delete dict;
252       delete entry;
253       return(1);
254    }
255    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
256    {
257       std::cout << "   Failed" << std::endl
258                 << "   Content of string is incorrect" << std::endl;
259       std::cout<<"#"<<entry->GetString()<<"#"<<" / "<<"#"<<data<<"#"<<std::endl;
260       delete dict;
261       delete entry;
262       return(1);
263    }
264    if( entry->GetValueCount() != nbvalue )
265    {
266       std::cout << "   Failed" << std::endl
267                 << "   Number of content values is incorrect" << std::endl;
268       delete dict;
269       delete entry;
270       return(1);
271    }
272    for(i=0;i<entry->GetValueCount();i++)
273    {
274       if( entry->GetValue(i) != lvalue[i] )
275       {
276          std::cout << "   Failed" << std::endl
277                    << "   Content of entry's values is incorrect : id " << i << std::endl;
278          delete dict;
279          delete entry;
280          return(1);
281       }
282    }
283
284    entry->SetLength(nbvalue*sizeof(uint32_t));
285    entry->SetBinArea((uint8_t *)lvalue,false);
286    std::cout << "2: ";
287    entry->Print(std::cout);
288    std::cout << std::endl;
289
290    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
291    {
292       std::cout << "   Failed" << std::endl
293                 << "   Content of string is incorrect" << std::endl;
294       delete dict;
295       delete entry;
296       return(1);
297    }
298    if( entry->GetValueCount() != nbvalue )
299    {
300       std::cout << "   Failed" << std::endl
301                 << "   Number of content values is incorrect" << std::endl;
302       delete dict;
303       delete entry;
304       return(1);
305    }
306    for(i=0;i<entry->GetValueCount();i++)
307    {
308       if( entry->GetValue(i) != lvalue[i] )
309       {
310          std::cout << "   Failed" << std::endl
311                    << "   Content of entry's values is incorrect : id " << i << std::endl;
312          delete dict;
313          delete entry;
314          return(1);
315       }
316    }
317
318    std::cout << std::endl;
319    delete dict;
320    delete entry;
321
322    //------------------------------------------------------------------
323    dict = new gdcm::DictEntry(0x0000,0x0000);
324    entry = new gdcm::DataEntry(dict);
325    dict->SetVR("FL");
326
327    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
328    entry->SetString(fdata);
329    std::cout << "1: ";
330    entry->Print(std::cout);
331    std::cout << std::endl;
332
333    if( entry->GetLength() != nbvalue*sizeof(float) )
334    {
335       std::cout << "   Failed" << std::endl
336                 << "   BinArea length is incorrect" << std::endl;
337       delete dict;
338       delete entry;
339       return(1);
340    }
341    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
342    {
343       std::cout << "   Failed" << std::endl
344                 << "   Content of string is incorrect" << std::endl;
345       delete dict;
346       delete entry;
347       return(1);
348    }
349    if( entry->GetValueCount() != nbvalue )
350    {
351       std::cout << "   Failed" << std::endl
352                 << "   Number of content values is incorrect" << std::endl;
353       delete dict;
354       delete entry;
355       return(1);
356    }
357    for(i=0;i<entry->GetValueCount();i++)
358    {
359       if( entry->GetValue(i) != fvalue[i] )
360       {
361          std::cout << "   Failed" << std::endl
362                    << "   Content of entry's values is incorrect : id " << i << std::endl;
363          delete dict;
364          delete entry;
365          return(1);
366       }
367    }
368
369    entry->SetLength(nbvalue*sizeof(float));
370    entry->SetBinArea((uint8_t *)fvalue,false);
371    std::cout << "2: ";
372    entry->Print(std::cout);
373    std::cout << std::endl;
374
375    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
376    {
377       std::cout << "   Failed" << std::endl
378                 << "   Content of string is incorrect" << std::endl;
379       delete dict;
380       delete entry;
381       return(1);
382    }
383    if( entry->GetValueCount() != nbvalue )
384    {
385       std::cout << "   Failed" << std::endl
386                 << "   Number of content values is incorrect" << std::endl;
387       delete dict;
388       delete entry;
389       return(1);
390    }
391    for(i=0;i<entry->GetValueCount();i++)
392    {
393       if( entry->GetValue(i) != fvalue[i] )
394       {
395          std::cout << "   Failed" << std::endl
396                    << "   Content of entry's values is incorrect : id " << i << std::endl;
397          delete dict;
398          delete entry;
399          return(1);
400       }
401    }
402
403    std::cout << std::endl;
404    delete dict;
405    delete entry;
406
407    //------------------------------------------------------------------
408    dict = new gdcm::DictEntry(0x0000,0x0000);
409    entry = new gdcm::DataEntry(dict);
410    dict->SetVR("FD");
411
412    std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl;
413    entry->SetString(fdata);
414    std::cout << "1: ";
415    entry->Print(std::cout);
416    std::cout << std::endl;
417
418    if( entry->GetLength() != nbvalue*sizeof(double) )
419    {
420       std::cout << "   Failed" << std::endl
421                 << "   BinArea length is incorrect" << std::endl;
422       delete dict;
423       delete entry;
424       return(1);
425    }
426    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
427    {
428       std::cout << "   Failed" << std::endl
429                 << "   Content of string is incorrect" << std::endl;
430       delete dict;
431       delete entry;
432       return(1);
433    }
434    if( entry->GetValueCount() != nbvalue )
435    {
436       std::cout << "   Failed" << std::endl
437                 << "   Number of content values is incorrect" << std::endl;
438       delete dict;
439       delete entry;
440       return(1);
441    }
442    for(i=0;i<entry->GetValueCount();i++)
443    {
444       if( entry->GetValue(i) != dvalue[i] )
445       {
446          std::cout << "   Failed" << std::endl
447                    << "   Content of entry's values is incorrect : id " << i << std::endl;
448          delete dict;
449          delete entry;
450          return(1);
451       }
452    }
453
454    entry->SetLength(nbvalue*sizeof(double));
455    entry->SetBinArea((uint8_t *)dvalue,false);
456    std::cout << "2: ";
457    entry->Print(std::cout);
458    std::cout << std::endl;
459
460    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
461    {
462       std::cout << "   Failed" << std::endl
463                 << "   Content of string is incorrect" << std::endl;
464       delete dict;
465       delete entry;
466       return(1);
467    }
468    if( entry->GetValueCount() != nbvalue )
469    {
470       std::cout << "   Failed" << std::endl
471                 << "   Number of content values is incorrect" << std::endl;
472       delete dict;
473       delete entry;
474       return(1);
475    }
476    for(i=0;i<entry->GetValueCount();i++)
477    {
478       if( entry->GetValue(i) != dvalue[i] )
479       {
480          std::cout << "   Failed" << std::endl
481                    << "   Content of entry's values is incorrect : id " << i << std::endl;
482          delete dict;
483          delete entry;
484          return(1);
485       }
486    }
487
488    std::cout << std::endl;
489    delete dict;
490    delete entry;
491
492    //------------------------------------------------------------------
493    std::cout<<std::flush;
494    return 0;
495 }