File: TestTrace.cxx

package info (click to toggle)
gdcm 3.0.24-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 27,560 kB
  • sloc: cpp: 203,722; ansic: 76,471; xml: 48,131; python: 3,473; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 97
file content (119 lines) | stat: -rw-r--r-- 3,043 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "gdcmTrace.h"

#include <iostream>

int TestTrace(int, char *[])
{
  gdcm::Trace t; //initializes all macros to 'off'

  gdcmDebugMacro( "DebugKO" );
  gdcmWarningMacro( "WarningKO" );
  gdcmErrorMacro( "ErrorKO" );

  // test the SetStream interface
  std::ostringstream useros;
  gdcm::Trace::SetStream( useros );

  gdcmDebugMacro( "DebugOK_OFF" );
  gdcmWarningMacro( "WarningOK_OFF" );
  gdcmErrorMacro( "ErrorOK_OFF" );

  gdcm::Trace::DebugOn();
  gdcm::Trace::WarningOn();
  gdcm::Trace::ErrorOn();

  gdcmDebugMacro( "DebugOK_ON" );
  gdcmWarningMacro( "WarningOK_ON" );
  gdcmErrorMacro( "ErrorOK_ON" );

  //in release mode, tracing just doesn't work any more, so this test isn't valid.
#ifndef NDEBUG
  std::string result = useros.str();
  if( result.find( "KO" ) != std::string::npos )
    {
    std::cerr << result << std::endl;
    return 1;
    }
  if( result.find( "OFF" ) != std::string::npos )
    {
    std::cerr << result << std::endl;
    return 1;
    }

  // opposite:
  if( result.find( "OK" ) == std::string::npos )
    {
    std::cerr << result << std::endl;
    return 1;
    }
  if( result.find( "ON" ) == std::string::npos )
    {
    std::cerr << result << std::endl;
    return 1;
    }
#endif

  // Test Debug/Warning/Error interface:
  std::ostringstream debug;
  std::ostringstream warning;
  std::ostringstream error;

  gdcm::Trace::SetDebugStream( debug );
  gdcm::Trace::SetWarningStream( warning );
  gdcm::Trace::SetErrorStream( error );

  gdcmDebugMacro( "Debug1234" );
  gdcmWarningMacro( "Warning1234" );
  gdcmErrorMacro( "Error1234" );

#ifndef NDEBUG
  std::string result1 = debug.str();
  std::string result2 = warning.str();
  std::string result3 = error.str();
  if( result1.find( "Debug1234" ) == std::string::npos )
    {
    std::cerr << result1 << std::endl;
    return 1;
    }
  if( result2.find( "Warning1234" ) == std::string::npos )
    {
    std::cerr << result2 << std::endl;
    return 1;
    }
  if( result3.find( "Error1234" ) == std::string::npos )
    {
    std::cerr << result3 << std::endl;
    return 1;
    }
  if( result1.find( "Warning1234" ) != std::string::npos )
    {
    std::cerr << result1 << std::endl;
    return 1;
    }
  if( result2.find( "Error1234" ) != std::string::npos )
    {
    std::cerr << result2 << std::endl;
    return 1;
    }
  if( result3.find( "Debug1234" ) != std::string::npos )
    {
    std::cerr << result3 << std::endl;
    return 1;
    }
#endif

  return 0;
}