]> Creatis software - gdcm.git/blob - Testing/TestUtil.cxx
COMP: Fix stupid VS6 bug
[gdcm.git] / Testing / TestUtil.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestUtil.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/14 16:46:15 $
7   Version:   $Revision: 1.12 $
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    // CreateCleanString
28    std::string x = "a#@-bc\tdef";
29    std::string y = gdcm::Util::CreateCleanString(x);
30    std::cout << "[" << x <<"] --> [" << y <<"]" << std::endl;
31
32    // CountSubstring : substring id "#@-"
33    x = "abcd#@-wyz*@-lmn#@-uvw-#@ijk";
34    std::cout << "count '#@-' in [" << x << "] : " 
35              << gdcm::Util::CountSubstring(x, "#@-") << std::endl;
36
37    // Tokenize : tokens are '#', '@', '-'
38    std::vector<std::string> tokens;
39    gdcm::Util::Tokenize (x, tokens, "#@-");
40    for (unsigned int ui=0; ui<tokens.size();ui++)
41    {
42       std::cout << "[" << tokens[ui] << "]" << std::endl;
43    }
44    tokens.clear();
45
46    // Time 
47    std::cout << "Time:" << gdcm::Util::GetCurrentDateTime() << std::endl;
48
49    // Processor ID
50    unsigned int processorID;;
51    processorID = gdcm::Util::GetCurrentProcessID();
52    std::cout << "Current Processor ID " <<  processorID << std::endl;
53
54    // MAC Adress
55    std::cout << "Mac Address:" << gdcm::Util::GetMACAddress() << std::endl;
56
57    // Unique UID test
58    std::string gdcmUid;
59    for (int i=0; i<10; i++)
60    {
61       gdcmUid = gdcm::Util::CreateUniqueUID();
62       std::cout << "Current UID for gdcm " <<  gdcmUid << std::endl;
63    }
64    
65    // DicomString test
66    const char ref[] = "MONOCHROME1";
67    std::string a = "MONOCHROME1";
68    a += '\0';
69    std::string b = "MONOCHROME1 ";
70    std::string c = gdcm::Util::DicomString("MONOCHROME1");
71    std::string d = "MONOCHROME1";
72
73    if( !gdcm::Util::DicomStringEqual(a,ref) ) 
74       return 1;
75    if( !gdcm::Util::DicomStringEqual(b,ref) ) 
76       return 1;
77    if( !gdcm::Util::DicomStringEqual(c,ref) ) 
78       return 1;
79    if(  gdcm::Util::DicomStringEqual(d,ref) ) 
80       return 1;
81
82 // ----------------------------------------------------------
83 // Let's test gdcm::Debug, now.
84     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag() <<std::endl;
85     gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo.txt");
86     std::cout << "We set a Debug file"   <<std::endl;
87     if ( !gdcm::Debug::GetDebugFlag() )
88     {
89        std::cout << "Debug Flag should be TRUE... " << std::endl;
90        return 1;
91     }
92     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
93     gdcm::Debug::SetDebugFlag ( false );
94     std::cout << "GetDebugFlag : " << gdcm::Debug::GetDebugFlag()<<std::endl;
95     gdcm::Debug::SetDebugFilename ("DummyFileNameToWriteTo2.txt");    
96
97    return 0;
98 }