1 /*=========================================================================
4 Module: $RCSfile: TestUtil.cxx,v $
6 Date: $Date: 2007/05/23 14:18:06 $
7 Version: $Revision: 1.21 $
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 // This test should test everything in Util, since I didn't know any other
19 // way to test this class.
22 #include "gdcmDebug.h"
25 int TestUtil(int , char *[])
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;
36 std::cout << "This is gdcm version: " << GDCM_NAME_SPACE::Util::GetVersion() << std::endl;
38 std::cout << "---------- uint16 : " << std::dec << u16 << " = 0x"
39 << std::hex << u16 << std::endl;
40 for (i=0;i<sizeof(uint16_t);i++)
42 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&u16)[i] << "] " ;
43 // printf("[%0x]\n",((uint8_t*)&u16)[i]);
45 std::cout << std::endl;
47 std::cout << "---------- unit32 : "<< std::dec << u32 << " = 0x"
48 << std::hex << u32 << std::endl;
49 for (i=0;i<sizeof(uint32_t);i++)
51 std::cout << std::hex <<"[" <<(uint32_t)((uint8_t*)&u32)[i] << "] " ;
53 std::cout << std::endl;
54 std::cout << std::endl;
55 std::cout << "------------------- float -----------------" << std::endl;
56 std::cout << std::endl;
61 std::cout << "--- " << flt
63 // << std::hex << (float *)&flt << std::endl;
64 // << std::hex << (int)(float *)&flt << std::endl;
67 for (i=0;i<sizeof(float);i++)
69 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&flt)[i] << "] " ;
72 std::cout << std::endl;
75 std::cout << std::endl;
76 std::cout << std::endl;
77 std::cout << "--------------------- double ----------------" << std::endl;
78 std::cout << std::endl;
83 std::cout << "--- " << std::dec << dbl
85 for (i=0;i<sizeof(double);i++)
87 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&dbl)[i] << "] " ;
89 std::cout << std::endl;
94 std::cout << "Size of short int " << sizeof(short int) << std::endl;
95 std::cout << "Size of int " << sizeof(int) << std::endl;
96 std::cout << "Size of int* " << sizeof(int*) << std::endl;
97 std::cout << "Size of long " << sizeof(long) << std::endl;
98 std::cout << "Size of float" << sizeof(float) << std::endl;
99 std::cout << "Size of double" << sizeof(double) << std::endl;
102 std::string x = "a#@-bc\tdef";
103 std::string y = GDCM_NAME_SPACE::Util::CreateCleanString(x);
104 std::cout << "Clean : [" << x <<"] --> [" << y <<"]" << std::endl;
107 // CountSubstring : substring id "#@-"
108 x = "abcd#@-wyz*@-lmn#@-uvw-#@ijk";
109 std::cout << "in [" << x << "] " << std::endl;
110 std::cout << " - count '#@-' : "
111 << GDCM_NAME_SPACE::Util::CountSubstring(x, "#@-") << std::endl;
113 // Tokenize : tokens are '#', '@', '-'
114 std::vector<std::string> tokens;
115 std::cout << " - use tokens '#@-' :" << std::endl;
116 GDCM_NAME_SPACE::Util::Tokenize (x, tokens, "#@-");
117 for (unsigned int ui=0; ui<tokens.size();ui++)
119 std::cout << "[" << tokens[ui] << "]" << std::endl;
124 std::cout << "Time:" << GDCM_NAME_SPACE::Util::GetCurrentDateTime() << std::endl;
127 unsigned int processorID;;
128 processorID = GDCM_NAME_SPACE::Util::GetCurrentProcessID();
129 std::cout << "Current Processor ID " << processorID << std::endl;
132 std::cout << "Mac Address:" << GDCM_NAME_SPACE::Util::GetMACAddress() << std::endl;
138 gdcmUid = GDCM_NAME_SPACE::Util::CreateUniqueUID();
139 std::cout << "Current UID for gdcm " << gdcmUid << std::endl;
143 const char ref[] = "MONOCHROME1";
144 std::string a = "MONOCHROME1";
146 std::string b = "MONOCHROME1 ";
147 std::string c = GDCM_NAME_SPACE::Util::DicomString("MONOCHROME1");
148 std::string d = "MONOCHROME1";
150 if( !GDCM_NAME_SPACE::Util::DicomStringEqual(a,ref) )
152 if( !GDCM_NAME_SPACE::Util::DicomStringEqual(b,ref) )
154 if( !GDCM_NAME_SPACE::Util::DicomStringEqual(c,ref) )
156 if( GDCM_NAME_SPACE::Util::DicomStringEqual(d,ref) )
159 // ----------------------------------------------------------
160 // Let's test GDCM_NAME_SPACE::Debug, now.
161 std::cout << "GetDebugFlag : " << GDCM_NAME_SPACE::Debug::GetDebugFlag() <<std::endl;
162 GDCM_NAME_SPACE::Debug::SetOutputFileName ("DummyFileNameToWriteTo.txt");
163 std::cout << "We set a Debug file" <<std::endl;
164 if ( !GDCM_NAME_SPACE::Debug::GetDebugFlag() )
166 std::cout << "Debug Flag should be TRUE... " << std::endl;
169 std::cout << "GetDebugFlag : " << GDCM_NAME_SPACE::Debug::GetDebugFlag()<<std::endl;
170 GDCM_NAME_SPACE::Debug::SetDebugFlag ( false );
171 std::cout << "GetDebugFlag : " << GDCM_NAME_SPACE::Debug::GetDebugFlag()<<std::endl;
172 GDCM_NAME_SPACE::Debug::SetOutputFileName ("DummyFileNameToWriteTo2.txt");
176 std::cout << s1 << " --> MD5 : " << GDCM_NAME_SPACE::Util::ConvertToMD5(s1)
179 std::cout << s1 << " --> MD5 : " << GDCM_NAME_SPACE::Util::ConvertToMD5(s1)
182 std::cout << s1 << " --> MD5 : " << GDCM_NAME_SPACE::Util::ConvertToMD5(s1)
185 std::cout << s1 << " --> MD5 : " << GDCM_NAME_SPACE::Util::ConvertToMD5(s1)
188 std::cout << s1 << " --> MD5 : " << GDCM_NAME_SPACE::Util::ConvertToMD5(s1)