1 /*=========================================================================
4 Module: $RCSfile: TestUtil.cxx,v $
6 Date: $Date: 2005/02/17 11:14:56 $
7 Version: $Revision: 1.13 $
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 << "---------- uint16 : " << std::dec <<u16 << " = 0x"
37 << std::hex << u16 << std::endl;
38 for (i=0;i<sizeof(uint16_t);i++)
40 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&u16)[i] << "] " ;
41 // printf("[%0x]\n",((uint8_t*)&u16)[i]);
43 std::cout << std::endl;
45 std::cout << "---------- unit32 : "<< std::dec << u32 << " = 0x"
46 << std::hex << u32 << std::endl;
47 for (i=0;i<sizeof(uint32_t);i++)
49 std::cout << std::hex <<"[" <<(uint32_t)((uint8_t*)&u32)[i] << "] " ;
51 std::cout << std::endl;
53 std::cout << "---------- float : " <<flt << " = 0x"
54 << std::hex << flt << std::endl;
55 for (i=0;i<sizeof(float);i++)
57 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&flt)[i] << "] " ;
59 std::cout << std::endl;
62 std::cout << "---------- float : " <<flt << " = 0x"
63 << std::hex << flt << std::endl;
64 for (i=0;i<sizeof(float);i++)
66 std::cout << std::hex <<"[" <<(uint16_t) ((uint8_t*)&flt)[i] << "] " ;
68 std::cout << std::endl;
70 std::cout << "---------- double : " << std::dec <<dbl << " = 0x"
71 << std::hex << dbl << std::endl;
72 for (i=0;i<sizeof(double);i++)
74 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&dbl)[i] << "] " ;
76 std::cout << std::endl;
79 std::cout << "---------- double : " << std::dec <<dbl << " = 0x"
80 << std::hex << dbl << std::endl;
81 for (i=0;i<sizeof(double);i++)
83 std::cout << std::hex <<"[" <<(uint16_t)((uint8_t*)&dbl)[i] << "] " ;
85 std::cout << std::endl;
88 std::string x = "a#@-bc\tdef";
89 std::string y = gdcm::Util::CreateCleanString(x);
90 std::cout << "Clean : [" << x <<"] --> [" << y <<"]" << std::endl;
93 // CountSubstring : substring id "#@-"
94 x = "abcd#@-wyz*@-lmn#@-uvw-#@ijk";
95 std::cout << "in [" << x << "] " << std::endl;
96 std::cout << " - count '#@-' : "
97 << gdcm::Util::CountSubstring(x, "#@-") << std::endl;
99 // Tokenize : tokens are '#', '@', '-'
100 std::vector<std::string> tokens;
101 std::cout << " - use tokens '#@-' :" << std::endl;
102 gdcm::Util::Tokenize (x, tokens, "#@-");
103 for (unsigned int ui=0; ui<tokens.size();ui++)
105 std::cout << "[" << tokens[ui] << "]" << std::endl;
110 std::cout << "Time:" << gdcm::Util::GetCurrentDateTime() << std::endl;
113 unsigned int processorID;;
114 processorID = gdcm::Util::GetCurrentProcessID();
115 std::cout << "Current Processor ID " << processorID << std::endl;
118 std::cout << "Mac Address:" << gdcm::Util::GetMACAddress() << std::endl;
124 gdcmUid = gdcm::Util::CreateUniqueUID();
125 std::cout << "Current UID for gdcm " << gdcmUid << std::endl;
129 const char ref[] = "MONOCHROME1";
130 std::string a = "MONOCHROME1";
132 std::string b = "MONOCHROME1 ";
133 std::string c = gdcm::Util::DicomString("MONOCHROME1");
134 std::string d = "MONOCHROME1";
136 if( !gdcm::Util::DicomStringEqual(a,ref) )
138 if( !gdcm::Util::DicomStringEqual(b,ref) )
140 if( !gdcm::Util::DicomStringEqual(c,ref) )
142 if( gdcm::Util::DicomStringEqual(d,ref) )
145 // ----------------------------------------------------------
146 // Let's test gdcm::Debug, now.
147 std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag() <<std::endl;
148 gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo.txt");
149 std::cout << "We set a Debug file" <<std::endl;
150 if ( !gdcm::Debug::GetDebugFlag() )
152 std::cout << "Debug Flag should be TRUE... " << std::endl;
155 std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
156 gdcm::Debug::SetDebugFlag ( false );
157 std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
158 gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo2.txt");