Skip to content

Commit 27bfacc

Browse files
committed
Enhance LOG emulation
It is needed for baseapi_test and other unit tests. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent db07a69 commit 27bfacc

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

unittest/log.h

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
///////////////////////////////////////////////////////////////////////
22
// File: log.h
33
// Description: Include for custom log message for unittest for tesseract.
4-
// based on
5-
// //https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework
4+
// based on
5+
// https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -14,18 +14,42 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616
///////////////////////////////////////////////////////////////////////
17+
1718
#ifndef TESSERACT_UNITTEST_LOG_H_
1819
#define TESSERACT_UNITTEST_LOG_H_
1920

2021
#include <iostream>
2122

22-
static class LOG {
23-
public:
24-
LOG() {}
25-
std::ostream& info() {
26-
std::cout << "[ LOG MSG ] ";
23+
enum LogLevel {
24+
INFO, ERROR
25+
};
26+
27+
static inline std::ostream& LOG(enum LogLevel level)
28+
{
29+
switch (level) {
30+
#if 0
31+
case DEBUG:
32+
std::cout << "[DEBUG] ";
33+
break;
34+
#endif
35+
case INFO:
36+
std::cout << "[INFO] ";
37+
break;
38+
case ERROR:
39+
std::cout << "[ERROR] ";
40+
break;
41+
}
42+
return std::cout;
43+
}
44+
45+
// https://github.com/google/ion/blob/master/ion/base/logging.h
46+
static inline std::ostream& QCHECK(bool condition)
47+
{
48+
static std::ostream null_stream(nullptr);
49+
if (condition) {
2750
return std::cout;
2851
}
29-
} log;
52+
return null_stream;
53+
}
3054

3155
#endif // TESSERACT_UNITTEST_LOG_H_

0 commit comments

Comments
 (0)