]> Creatis software - gdcm.git/blob - Testing/TestUtil.cxx
Add some prints
[gdcm.git] / Testing / TestUtil.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestUtil.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/21 08:35:13 $
7   Version:   $Revision: 1.16 $
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 // This test should test everything in Util, since I didn't know any other 
19 // way to test this class.
20
21 #include "gdcmUtil.h"
22 #include "gdcmDebug.h"
23 #include <iostream>
24
25 int TestUtil(int , char *[])
26 {
27    unsigned int i;
28
29    // Seeing at a glance HOW int16, int32, float, double, 
30    // are implanted in memory
31    uint16_t u16 = 0x0102;
32    uint32_t u32 = 0x01020304;
33    float flt;
34    double dbl=1.0;
35
36    std::cout << "This is gdcm version: " << gdcm::Util::GetVersion() << std::endl;
37
38    std::cout << "---------- uint16 : " << std::dec << u16 << " = 0x" 
39              << std::hex << u16 << std::endl;
40    for (i=0;i<sizeof(uint16_t);i++) 
41    {
42       std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&u16)[i] << "] " ;
43      // printf("[%0x]\n",((uint8_t*)&u16)[i]);
44    }
45    std::cout << std::endl;
46
47    std::cout << "---------- unit32 : "<< std::dec << u32 << " = 0x" 
48              << std::hex << u32 << std::endl;
49    for (i=0;i<sizeof(uint32_t);i++) 
50    {
51       std::cout << std::hex <<"[" <<(uint32_t)((uint8_t*)&u32)[i] << "] " ;
52    }
53    std::cout << std::endl;
54    std::cout << std::endl;
55    std::cout << "------------------- float -----------------" << std::endl;
56    std::cout << std::endl;
57    flt = -5;
58    int k;   
59    for (k=0; k<11;k++)
60    {
61       std::cout << "--- " << flt 
62              // << " = 0x" 
63              // << std::hex << (float *)&flt << std::endl;   
64              // << std::hex << (int)(float *)&flt << std::endl;
65              // << std::hex << flt 
66                 << std::endl;
67       for (i=0;i<sizeof(float);i++) 
68       {
69          std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&flt)[i] << "] " ;
70       }
71       flt += 1.0;
72       std::cout << std::endl;
73    }
74
75    std::cout << std::endl;
76    std::cout << std::endl;
77    std::cout << "--------------------- double ----------------" << std::endl;
78    std::cout << std::endl;
79
80    dbl = -5.0;
81    for (k=0; k<11; k++)
82    {
83       std::cout << "---  " << std::dec << dbl
84                 << std::endl;
85       for (i=0;i<sizeof(double);i++) 
86       {
87          std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&dbl)[i] << "] " ;
88       }
89       std::cout << std::endl;
90       dbl += 1.0;
91    }
92
93    // CreateCleanString
94    std::string x = "a#@-bc\tdef";
95    std::string y = gdcm::Util::CreateCleanString(x);
96    std::cout << "Clean : [" << x <<"] --> [" << y <<"]" << std::endl;
97
98
99    // CountSubstring : substring id "#@-"
100    x = "abcd#@-wyz*@-lmn#@-uvw-#@ijk";
101    std::cout << "in [" << x << "] " << std::endl; 
102    std::cout << " - count '#@-' : " 
103              << gdcm::Util::CountSubstring(x, "#@-") << std::endl;
104
105    // Tokenize : tokens are '#', '@', '-'
106    std::vector<std::string> tokens;
107    std::cout << " - use tokens '#@-' :" << std::endl;
108    gdcm::Util::Tokenize (x, tokens, "#@-");
109    for (unsigned int ui=0; ui<tokens.size();ui++)
110    {
111       std::cout << "[" << tokens[ui] << "]" << std::endl;
112    }
113    tokens.clear();
114
115    // Time 
116    std::cout << "Time:" << gdcm::Util::GetCurrentDateTime() << std::endl;
117
118    // Processor ID
119    unsigned int processorID;;
120    processorID = gdcm::Util::GetCurrentProcessID();
121    std::cout << "Current Processor ID " <<  processorID << std::endl;
122
123    // MAC Adress
124    std::cout << "Mac Address:" << gdcm::Util::GetMACAddress() << std::endl;
125
126    // Unique UID test
127    std::string gdcmUid;
128    for (i=0; i<10; i++)
129    {
130       gdcmUid = gdcm::Util::CreateUniqueUID();
131       std::cout << "Current UID for gdcm " <<  gdcmUid << std::endl;
132    }
133    
134    // DicomString test
135    const char ref[] = "MONOCHROME1";
136    std::string a = "MONOCHROME1";
137    a += '\0';
138    std::string b = "MONOCHROME1 ";
139    std::string c = gdcm::Util::DicomString("MONOCHROME1");
140    std::string d = "MONOCHROME1";
141
142    if( !gdcm::Util::DicomStringEqual(a,ref) ) 
143       return 1;
144    if( !gdcm::Util::DicomStringEqual(b,ref) ) 
145       return 1;
146    if( !gdcm::Util::DicomStringEqual(c,ref) ) 
147       return 1;
148    if(  gdcm::Util::DicomStringEqual(d,ref) ) 
149       return 1;
150
151 // ----------------------------------------------------------
152 // Let's test gdcm::Debug, now.
153     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag() <<std::endl;
154     gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo.txt");
155     std::cout << "We set a Debug file"   <<std::endl;
156     if ( !gdcm::Debug::GetDebugFlag() )
157     {
158        std::cout << "Debug Flag should be TRUE... " << std::endl;
159        return 1;
160     }
161     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
162     gdcm::Debug::SetDebugFlag ( false );
163     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
164     gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo2.txt");    
165
166    return 0;
167 }