]> Creatis software - gdcm.git/blob - Testing/TestUtil.cxx
COMP: Remove problem with static being define in a common header file
[gdcm.git] / Testing / TestUtil.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestUtil.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/08/22 15:38:04 $
7   Version:   $Revision: 1.15 $
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= 1.0;
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
55    std::cout << "---------- float : " <<flt << " = 0x" 
56              << std::hex << flt << std::endl;
57    for (i=0;i<sizeof(float);i++) 
58    {
59       std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&flt)[i] << "] " ;
60    }
61    std::cout << std::endl;
62
63    flt= 2.0;
64    std::cout << "---------- float : " <<flt << " = 0x" 
65              << std::hex << flt << std::endl;
66    for (i=0;i<sizeof(float);i++) 
67    {
68       std::cout << std::hex <<"[" <<(uint16_t) ((uint8_t*)&flt)[i] << "] " ;
69    }
70    std::cout << std::endl;
71
72    std::cout << "---------- double : " << std::dec <<dbl << " = 0x" 
73              << std::hex << dbl << std::endl;
74    for (i=0;i<sizeof(double);i++) 
75    {
76       std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&dbl)[i] << "] " ;
77    }
78    std::cout << std::endl;
79
80    dbl=2.0;
81    std::cout << "---------- double : " << std::dec <<dbl << " = 0x" 
82              << std::hex << dbl << std::endl;
83    for (i=0;i<sizeof(double);i++) 
84    {
85       std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&dbl)[i] << "] " ;
86    }
87    std::cout << std::endl;
88
89    // CreateCleanString
90    std::string x = "a#@-bc\tdef";
91    std::string y = gdcm::Util::CreateCleanString(x);
92    std::cout << "Clean : [" << x <<"] --> [" << y <<"]" << std::endl;
93
94
95    // CountSubstring : substring id "#@-"
96    x = "abcd#@-wyz*@-lmn#@-uvw-#@ijk";
97    std::cout << "in [" << x << "] " << std::endl; 
98    std::cout << " - count '#@-' : " 
99              << gdcm::Util::CountSubstring(x, "#@-") << std::endl;
100
101    // Tokenize : tokens are '#', '@', '-'
102    std::vector<std::string> tokens;
103    std::cout << " - use tokens '#@-' :" << std::endl;
104    gdcm::Util::Tokenize (x, tokens, "#@-");
105    for (unsigned int ui=0; ui<tokens.size();ui++)
106    {
107       std::cout << "[" << tokens[ui] << "]" << std::endl;
108    }
109    tokens.clear();
110
111    // Time 
112    std::cout << "Time:" << gdcm::Util::GetCurrentDateTime() << std::endl;
113
114    // Processor ID
115    unsigned int processorID;;
116    processorID = gdcm::Util::GetCurrentProcessID();
117    std::cout << "Current Processor ID " <<  processorID << std::endl;
118
119    // MAC Adress
120    std::cout << "Mac Address:" << gdcm::Util::GetMACAddress() << std::endl;
121
122    // Unique UID test
123    std::string gdcmUid;
124    for (i=0; i<10; i++)
125    {
126       gdcmUid = gdcm::Util::CreateUniqueUID();
127       std::cout << "Current UID for gdcm " <<  gdcmUid << std::endl;
128    }
129    
130    // DicomString test
131    const char ref[] = "MONOCHROME1";
132    std::string a = "MONOCHROME1";
133    a += '\0';
134    std::string b = "MONOCHROME1 ";
135    std::string c = gdcm::Util::DicomString("MONOCHROME1");
136    std::string d = "MONOCHROME1";
137
138    if( !gdcm::Util::DicomStringEqual(a,ref) ) 
139       return 1;
140    if( !gdcm::Util::DicomStringEqual(b,ref) ) 
141       return 1;
142    if( !gdcm::Util::DicomStringEqual(c,ref) ) 
143       return 1;
144    if(  gdcm::Util::DicomStringEqual(d,ref) ) 
145       return 1;
146
147 // ----------------------------------------------------------
148 // Let's test gdcm::Debug, now.
149     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag() <<std::endl;
150     gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo.txt");
151     std::cout << "We set a Debug file"   <<std::endl;
152     if ( !gdcm::Debug::GetDebugFlag() )
153     {
154        std::cout << "Debug Flag should be TRUE... " << std::endl;
155        return 1;
156     }
157     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
158     gdcm::Debug::SetDebugFlag ( false );
159     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
160     gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo2.txt");    
161
162    return 0;
163 }