-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
341 lines (308 loc) · 12 KB
/
main.cpp
File metadata and controls
341 lines (308 loc) · 12 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#define BOOST_TEST_DYN_LINK
// either Suits or Fitxtures
#define BOOST_TEST_MODULE Suites
//#define BOOST_TEST_MODULE Fixtures
#include <boost/test/unit_test.hpp>
#include "structuredLogger.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <csignal>
#include "msgFormatVerify.h"
#include "stackdumptest.h"
// define all the regular expressions for readability
#define DATEREG "(\\d+ \\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d+)"
#define SEVREG "(<[^>]+>)"
#define MEDREG "(\\[[^\\]]+\\])"
#define THREADREG "(\\[[\\dabcdefx]+\\])"
//#define NORMREG DATEREG SEVEREG
//#define DEBUGREG NORMREG MEDREG THREADREG
//
// BOOST_WARN_EQUAL, BOOST_CHECK_EQUAL, BOOST_REQUIRE_EQUAL
//
// BOOST_<level>
// BOOST_<level>_BITWISE_EQUAL
// BOOST_<level>_CLOSE
// BOOST_<level>_CLOSE_FRACTION
// BOOST_<level>_EQUAL
// BOOST_<level>_EQUAL_COLLECTION
// BOOST_<level>_EXCEPTION
// BOOST_<level>_GE
// BOOST_<level>_GT
// BOOST_<level>_LE
// BOOST_<level>_LT
// BOOST_<level>_MESSAGE
// BOOST_<level>_NE
// BOOST_<level>_NO_THROW
// BOOST_<level>_PREDICATE
// BOOST_<level>_SMALL
// BOOST_<level>_THROW
// BOOST_ERROR
// BOOST_FAIL
// BOOST_IS_DEFINED
//
////
//class setup
//{
// int m;
//
// setup() : m(2)
// {
// BOOST_TEST_MESSAGE("setup mass");
// }
//
// ~setup()m0r3.23x
// {
// BOOST_TEST_MESSAGE("teardown mass");
// }
//};
// either Fixture for setup/tear down or
// Suite for non- tera down
//BOOST_FIXTURE_TEST_SUITE(Physics, Massive)
// The functions contained in this file are pretty dummy
// and are included only as a placeholder. Nevertheless,
// they *will* get included in the shared library if you
// don't remove them :)
//
// Obviously, you 'll have to write yourself the super-duper
// functions to include in the resulting library...
// Also, it's not necessary to write every function in this file.
// Feel free to add more files in this project. They will be
// included in the resulting library.
// highjack the main and make it the unitTest module
class setup {
public:
setup() ;
static void signalCatch(int);
protected:
};
setup::setup (){
signal(SIGSEGV,&setup::signalCatch);
}
void setup::signalCatch(int sigNum) {
///t_spSL elog = structuredLogger::getInstance(ELOGNAME,(t_loggingStyle) (allInfoFile| tokenMsg | sepErrorFile | sepDebugFile));
///elog->stack_trace("crash & burn");
///elog.reset();
std::cout << stackTrace().str() ;
}
extern "C"
{
BOOST_AUTO_TEST_SUITE(s_StructruedLogging)
BOOST_AUTO_TEST_CASE(general_logging)
{
setup s;
t_spSL elog = structuredLogger::getInstanceByName("logAllPlus",(t_loggingStyle) (allInfoFile| tokenMsg | sepErrorFile | sepDebugFile));
elog->generalL(normal,"message 1 GEN","test_case::msg");
elog->generalL(normal,"msg normal 2 GEN");
elog->generalL(warning,"msg warning GEN");
elog->generalL(notification,"msg info GEN",__PRETTY_FUNCTION__);
elog->generalL(critical,"msg fata/critial GEN","getLogger::general_logging");
elog->generalL(debug,"msg debug GEN");
elog->generalL(error,"msg error GEN");
elog->generalL(warning,"warning GEN");
elog->generalL(error,"error GEN",__PRETTY_FUNCTION__);
std::string normreg(DATEREG);
normreg.append(" ");
normreg.append(SEVREG);
normreg.append("(.*)");
std::string xname (elog->getFname());
xname.append(".log");
msgFormatVerify msgFV(xname.c_str(),normreg.c_str());
std::vector<std::string> results;
BOOST_CHECK(msgFV.compare_syntax(results));
std::ofstream severityCheckFile("normalSyntax.dat");
severityCheckFile << normreg << std::endl << "<normal>" << std::endl << "<normal>" << std::endl << "<warning>" << std::endl << "<notification>" <<std::endl;
severityCheckFile << "<critical>" << std::endl << "<debug>" << std::endl << "<error>" << std::endl << "<warning>" << std::endl << "<warning>" << std::endl;
severityCheckFile << "<error>" << std::endl;
severityCheckFile.close();
msgFormatVerify msgFV1(xname.c_str(),"normalSyntax.dat");
BOOST_CHECK(msgFV1.compare_syntax_severity(results));
elog.reset();
}
BOOST_AUTO_TEST_CASE(tokenLogging)
{
// token logging goes to the error file
// since token is the method capture
//
setup s;
t_spSL elog = structuredLogger::getInstanceByName("logall",(t_loggingStyle)(allInfoFile | tokenMsg));
elog->tokenL(normal,"message 1 TOKEN","test_case::msg");
elog->tokenL(normal,"msg normal 2 TOKEN");
elog->tokenL(warning,"msg warning TOKEN" );
elog->tokenL(notification,"msg info TOKEN",__PRETTY_FUNCTION__);
elog->tokenL(critical,"msg fatal/critical TOKEN ",__PRETTY_FUNCTION__);
elog->tokenL(debug,"msg debug TOKEN");
elog->tokenL(error,"msg error TOKEN","structuredLogger::junk(foo.bar)");
elog->tokenL(warning,"warning TOKEN");
elog->tokenL(error,"error TOKEN",__PRETTY_FUNCTION__);
std::ostringstream tokenreg;
tokenreg << DATEREG << " " << SEVREG << ".*?" << MEDREG << "(.*)";
std::string r = tokenreg.str();
std::string xname (elog->getFname());
xname.append(".log");
msgFormatVerify msgFV(xname.c_str(),r.c_str());
std::vector<std::string> results;
BOOST_CHECK(msgFV.compare_syntax(results));
std::ofstream severityCheckFile("tokenSyntax.dat");
severityCheckFile << r << std::endl << "<critical>" << std::endl << "<debug>" << std::endl << "error";
severityCheckFile << std::endl << "<error>" << std::endl;
severityCheckFile << std::endl << "<critical>" << std::endl << "<debug>" << std::endl << "error";
severityCheckFile << std::endl << "<error>" << std::endl;
severityCheckFile << std::endl << "<critical>" << std::endl << "<debug>" << std::endl << "error";
severityCheckFile << std::endl << "<error>" << std::endl;
severityCheckFile << std::endl << "<critical>" << std::endl << "<debug>" << std::endl << "error";
severityCheckFile << std::endl << "<error>" << std::endl;
severityCheckFile.close();
xname =elog->getFname();
xname.append(".error");
msgFormatVerify msgFV1(xname.c_str(),"tokenSyntax.dat");
BOOST_CHECK(msgFV1.compare_syntax_severity(results));
elog.reset();
}
BOOST_AUTO_TEST_CASE(debugLogging)
{
setup s;
t_spSL elog = structuredLogger::getInstanceByName("logdebug",sepDebugFile);
elog->debugL(normal,"message 1 DEBUG","test_case::msg");
elog->debugL(normal,"msg normal 2 DEBUG");
elog->debugL(warning,"msg warning DEBUG");
elog->debugL(notification,"msg info DEBUG",__PRETTY_FUNCTION__);
elog->debugL(critical,"msg fatal/critical DEBUG ",__PRETTY_FUNCTION__);
elog->debugL(debug,"msg debug DEBUG",__PRETTY_FUNCTION__);
elog->debugL(error,"msg error DEBUG","structuredLogger::junk(foo.bar)");
elog->debugL(warning,"warning DEBUG");
elog->debugL(error,"error DEBUG",__PRETTY_FUNCTION__);
std::ostringstream tokenreg;
tokenreg << DATEREG << " " << SEVREG << ".*?" << MEDREG <<".*?" << THREADREG <<"(.*)";
std::string r=tokenreg.str();
std::string xname (elog->getFname());
xname.append(".debug");
msgFormatVerify msgFV(xname.c_str(),r.c_str());
std::vector<std::string> results;
bool bcheck = msgFV.compare_syntax(results);
BOOST_CHECK(bcheck);
if (! bcheck){
std::cerr << "failed to match the following lines with regex" << r << std::endl;
for (std::vector<std::string>::iterator it = results.begin(); it != results.end(); ++it){
std::cerr << *it << std::endl;
}
}
std::ofstream severityCheckFile("debugSyntax.dat");
severityCheckFile << r << std::endl << "<debug>" << std::endl << "<debug>" << std::endl << "<debug>";
severityCheckFile << std::endl << "<debug>" << std::endl;
severityCheckFile.close();
msgFormatVerify msgFV1(xname.c_str(),"debugSyntax.dat");
BOOST_CHECK(msgFV1.compare_syntax_severity(results));
elog->stack_trace("testing stack_trace dump ","xxx");
elog.reset();
}
BOOST_AUTO_TEST_CASE(errorLogging)
{
setup s;
t_spSL elog = structuredLogger::getInstanceByName("logerror",sepErrorFile);
elog->errorL(normal,"message 1 ER","test_case::msg");
elog->errorL(normal,"msg normal 2 ER");
elog->errorL(warning,"msg warning ER");
elog->errorL(notification,"msg info ER",__PRETTY_FUNCTION__);
elog->errorL(critical,"msg fatal/critical ER",__PRETTY_FUNCTION__);
elog->errorL(debug,"msg debug ER");
elog->errorL(error,"msg error ER","structuredLogger::junk(foo.bar)");
elog->errorL(warning,"const char* warning ER");
elog->errorL(error,"const char* error ER",__PRETTY_FUNCTION__);
elog->errorL(error,"const char* error ER",__FILE__);
std::ostringstream tokenreg;
tokenreg << DATEREG << " " << SEVREG << ".*" << MEDREG << "(.*)";
std::string r = tokenreg.str();
std::string xname (elog->getFname());
xname.append(".error");
msgFormatVerify msgFV(xname.c_str(),r.c_str());
std::vector<std::string> results;
BOOST_CHECK(msgFV.compare_syntax(results));
std::ofstream severityCheckFile("errorSyntax.dat");
severityCheckFile << r << std::endl << "<critical>" << std::endl << "<debug>" << std::endl << "error";
severityCheckFile << std::endl << "<error>" << std::endl;
severityCheckFile.close();
msgFormatVerify msgFV1(xname.c_str(),"errorSyntax.dat");
BOOST_CHECK(msgFV1.compare_syntax_severity(results));
stackdumptest sdt(elog,1);
sdt.levelN(2);
sdt.levelN(3);
sdt.levelN(4);
elog.reset();
}
BOOST_AUTO_TEST_CASE(timer)
{
setup s;
t_spSL elog = structuredLogger::getInstance("logtimer");
elog->timed_Start("timing call start",debug);
elog->timed_Stop("timing call stop",debug);
elog.reset();
}
BOOST_AUTO_TEST_CASE(scope)
{
setup s;
std::string method(__FUNCTION__);
t_spSL elog = structuredLogger::getInstanceByName("logscope");
elog->named_scopeL(normal,"test normal",method);
elog->named_scopeL(warning,"test warning");
elog->named_scopeL(notification,"test info");
elog->named_scopeL(critical,"test fatal");
elog->named_scopeL(debug,"test debug");
elog->named_scopeL(error,"test error");
elog.reset();
}
BOOST_AUTO_TEST_CASE(default_test)
{
setup s;
t_spSL elog = structuredLogger::getInstance("logdefault");
elog.reset();
}
BOOST_AUTO_TEST_CASE(singleFile_test)
{
setup s;
t_spSL elog = structuredLogger::getInstanceByName("logsingleFile",singleFile);
elog->generalL(normal,"msg normal 2 GEN");
elog->generalL(warning,"msg warning GEN");
elog->generalL(notification,"msg info GEN",__PRETTY_FUNCTION__);
elog->generalL(critical,"msg fata/critial GEN","getLogger::general_logging");
elog->generalL(debug,"msg debug GEN");
elog->generalL(error,"msg error GEN");
elog->errorL(normal,"msg normal 2 ER");
elog->errorL(warning,"msg warning ER");
elog->errorL(notification,"msg info ER",__PRETTY_FUNCTION__);
elog->errorL(critical,"msg fatal/critical ER",__PRETTY_FUNCTION__);
elog->errorL(debug,"msg debug ER");
elog->errorL(error,"msg error ER","structuredLogger::junk(foo.bar)");
elog->debugL(normal,"msg normal 2 DEBUG");
elog->debugL(warning,"msg warning DEBUG");
elog->debugL(notification,"msg info DEBUG",__PRETTY_FUNCTION__);
elog->debugL(critical,"msg fatal/critical DEBUG ",__PRETTY_FUNCTION__);
elog->debugL(debug,"msg debug DEBUG",__PRETTY_FUNCTION__);
elog->debugL(error,"msg error DEBUG","structuredLogger::junk(foo.bar)");
elog.reset();
}
BOOST_AUTO_TEST_CASE(badfiletype_test)
{
setup s;
try {
t_spSL elog = structuredLogger::getInstanceByName("logsingleFileBad",sepSocket);
BOOST_CHECK(elog.get() == nullptr);
BOOST_CHECK(elog.get() != nullptr);
}catch (std::exception &e){
std::cout << e.what() << std::endl;
}
}
/*
BOOST_AUTO_TEST_CASE(tag)
{
t_spSL elog = structuredLogger::getInstance("structLogUtest.2");
elog->taggedL("tagA",normal,"test normal");
elog->taggedL("tagB",warning,"test warning");
elog->taggedL("tagC",notification,"test info");
elog->taggedL("tagD",critical,"test fatal");
elog->taggedL("tagE",debug,"test debug");
elog->taggedL("tagF",error,"test error");
}
*/
BOOST_AUTO_TEST_SUITE_END()
}