DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testTrace.cpp
1 
34 #include <cstdio>
35 #include <cmath>
36 #include <iostream>
37 #include <fstream>
38 
39 #include "DGtal/base/Config.h"
40 #include "DGtal/base/Common.h"
41 
42 
43 using namespace DGtal;
44 using namespace std;
45 
46 
47 void testSimple()
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 }
55 
56 void testIndent()
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< 4334450; 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< 4334450; 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 }
82 
88 void testFileStream()
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 }
114 
115 void testTimings()
116 {
117  size_t duration,duration2;
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< 4334450; 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< 4334450; 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< 4334450; 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< 4334450; 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< 4334450; 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< 4334450; i++)
156  tmp = (long)cos((double)tmp+i);
157  duration += trace.endBlock();
158 
159  duration2 = trace.endBlock();
160 
161 }
162 
163 
164 
165 int main()
166 {
167  testSimple();
168  testIndent();
169  testFileStream();
170  testTimings();
171  return 0;
172 }
173