From 27bfaccf736fb995d1e97b78151c38c7a44d323f Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 11 Oct 2018 22:13:40 +0200 Subject: [PATCH] Enhance LOG emulation It is needed for baseapi_test and other unit tests. Signed-off-by: Stefan Weil --- unittest/log.h | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/unittest/log.h b/unittest/log.h index 3efb8585a2..9264993370 100644 --- a/unittest/log.h +++ b/unittest/log.h @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////// // File: log.h // Description: Include for custom log message for unittest for tesseract. -// based on -// //https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework +// based on +// https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,18 +14,42 @@ // See the License for the specific language governing permissions and // limitations under the License. /////////////////////////////////////////////////////////////////////// + #ifndef TESSERACT_UNITTEST_LOG_H_ #define TESSERACT_UNITTEST_LOG_H_ #include -static class LOG { - public: - LOG() {} - std::ostream& info() { - std::cout << "[ LOG MSG ] "; +enum LogLevel { + INFO, ERROR +}; + +static inline std::ostream& LOG(enum LogLevel level) +{ + switch (level) { +#if 0 + case DEBUG: + std::cout << "[DEBUG] "; + break; +#endif + case INFO: + std::cout << "[INFO] "; + break; + case ERROR: + std::cout << "[ERROR] "; + break; + } + return std::cout; +} + +// https://github.com/google/ion/blob/master/ion/base/logging.h +static inline std::ostream& QCHECK(bool condition) +{ + static std::ostream null_stream(nullptr); + if (condition) { return std::cout; } -} log; + return null_stream; +} #endif // TESSERACT_UNITTEST_LOG_H_