DGtal  1.0.0
Functions
testTrace.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>
#include "DGtal/base/Config.h"
#include "DGtal/base/Common.h"
Include dependency graph for testTrace.cpp:

Go to the source code of this file.

Functions

void testSimple ()
 
void testIndent ()
 
void testFileStream ()
 
void testTimings ()
 
int main ()
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr )
Date
2009/12/13

This file is part of the DGtal library

Definition in file testTrace.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 166 of file testTrace.cpp.

167 {
168  testSimple();
169  testIndent();
170  testFileStream();
171  testTimings();
172  return 0;
173 }
void testFileStream()
Definition: testTrace.cpp:88
void testSimple()
Definition: testTrace.cpp:47
void testTimings()
Definition: testTrace.cpp:115
void testIndent()
Definition: testTrace.cpp:56

References testFileStream(), testIndent(), testSimple(), and testTimings().

◆ testFileStream()

void testFileStream ( )

We test the Trace class on file stream.

a file "example.txt" must have been created with the traces.

Definition at line 88 of file testTrace.cpp.

89 {
90  trace.beginBlock("testFileStream");
91  trace.info() << "Checking the filestream output.. Please check the 'example.txt' file"<<endl;
92 
93  ofstream myfile;
94  myfile.open ("example.txt");
95 
96  TraceWriterFile traceWriterFile(myfile);
97  Trace t2(traceWriterFile);
98 
99  t2.info()<< "This is an Info trace"<<endl;
100  t2.warning()<< "This is an warning trace"<<endl;
101 
102  t2.error()<< "This is an Error trace"<<endl;
103  t2.emphase()<< "This is an Emphased trace"<<endl;
104 
105  t2.beginBlock("FirstMethod");
106  t2.info()<< "This is an Info trace, level 1"<<endl;
107  t2.info()<< "This is an Info trace, level 1"<<endl;
108  t2.endBlock();
109 
110  myfile.close();
111 
112  trace.endBlock();
113 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
double endBlock()
implementation of basic methods to trace out messages with indentation levels.
Definition: Trace.h:73
std::ostream & info()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

◆ testIndent()

void testIndent ( )

Definition at line 56 of file testTrace.cpp.

57 {
58  long tmp=0;
59 
60  trace.info()<< "This is an Info trace, level 0"<<endl;
61  trace.beginBlock("FirstMethod");
62  trace.info()<< "This is an Info trace, level 1"<<endl;
63  trace.info()<< "This is an Info trace, level 1"<<endl;
64  trace.beginBlock("SecondMethod");
65  trace.warning()<< "This is an Warning trace, level 2"<<endl;
66  trace.warning()<< "This is an Warning trace, level 2"<<endl;
67  trace.info()<< "This is an Info trace, level 2"<<endl;
68  trace.error()<< "This is an Error trace, level 2 (followed by a loop)"<<endl;
69 
70  for (unsigned int i=0 ; i< 450; i++)
71  tmp = (long)cos((double)tmp+i);
72 
73  trace.endBlock();
74  trace.info()<< "This is an Info trace, level 1 (followed by another loop)"<<endl;
75 
76  for (unsigned int i=0 ; i< 430; i++)
77  tmp = (long)cos((double)tmp+i);
78 
79  trace.endBlock();
80  trace.info()<< "This is an Info trace, level 0"<<endl<<endl;
81 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
double endBlock()
std::ostream & warning()
std::ostream & info()
std::ostream & error()

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

◆ testSimple()

void testSimple ( )

Definition at line 47 of file testTrace.cpp.

48 {
49  trace.info()<< "This is an Info trace"<<endl;
50  trace.warning()<< "This is an warning trace"<<endl;
51  trace.error()<< "This is an Error trace"<<endl;
52  trace.emphase()<< "This is an Emphased trace"<<endl;
53  cerr<<endl;
54 }
Trace trace
Definition: Common.h:144
std::ostream & emphase()
std::ostream & warning()
std::ostream & info()
std::ostream & error()

References DGtal::Trace::emphase(), DGtal::Trace::error(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

◆ testTimings()

void testTimings ( )

Definition at line 115 of file testTrace.cpp.

116 {
117  size_t duration;
118 
119  trace.beginBlock("Level0");
120  double tmp=1.0;
121 
122  trace.beginBlock("Level1");
123  trace.info()<<"..."<<std::endl;
124  for (unsigned int i=0 ; i< 4350; i++)
125  tmp = (long)cos((double)tmp+i);
126  duration = trace.endBlock();
127 
128  trace.beginBlock("Level1B");
129  trace.info()<<"..."<<std::endl;
130  for (unsigned int i=0 ; i< 4350; i++)
131  tmp = (long)cos((double)tmp+i);
132 
133  trace.beginBlock("Level2");
134  trace.info()<<"..."<<std::endl;
135  for (unsigned int i=0 ; i< 4350; i++)
136  tmp = (long)cos((double)tmp+i);
137  duration += trace.endBlock();
138 
139  trace.beginBlock("Level2B");
140  trace.info()<<"..."<<std::endl;
141  for (unsigned int i=0 ; i< 4350; i++)
142  tmp = (long)cos((double)tmp+i);
143  duration += trace.endBlock();
144 
145  trace.beginBlock("Level2C");
146  trace.info()<<"..."<<std::endl;
147  for (unsigned int i=0 ; i< 4450; i++)
148  tmp = (long)cos((double)tmp+i);
149  duration += trace.endBlock();
150 
151  duration += trace.endBlock();
152 
153  trace.beginBlock("Level1C");
154  trace.info()<<"..."<<std::endl;
155  for (unsigned int i=0 ; i< 430; i++)
156  tmp = (long)cos((double)tmp+i);
157  duration += trace.endBlock();
158 
159  duration += trace.endBlock();
160  trace.info()<<"Duration="<<duration<<std::endl;
161 
162 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
double endBlock()
std::ostream & info()

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().