diff UnitTestsSources/LoggingTests.cpp @ 3359:815b81142ff7 emscripten-logging

Enable custom logging functions to redirect to emscripten specific logging calls in the ORTHANC_ENABLE_LOGGING_STDIO mode.
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 07 May 2019 11:23:11 +0200
parents 54cdad5a7228
children 1fdbe5885783
line wrap: on
line diff
--- a/UnitTestsSources/LoggingTests.cpp	Wed Apr 24 07:51:48 2019 +0200
+++ b/UnitTestsSources/LoggingTests.cpp	Tue May 07 11:23:11 2019 +0200
@@ -36,6 +36,7 @@
 #include <sstream>
 
 #include "../Core/Logging.h"
+#include "../Core/LoggingUtils.h"
 
 using namespace Orthanc::Logging;
 
@@ -66,11 +67,19 @@
 
 If the log line cannot be matched, the function returns false.
 */
+
+#ifdef WIN32
+# define EOLSTRING "\r\n"
+#else 
+# define EOLSTRING "\n"
+#endif
+
 static bool GetLogLinePayload(std::string& payload,
   const std::string& logLine)
 {
   const char* regexStr = "[A-Z][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} "
-    "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)\r\n$";
+    "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)" EOLSTRING "$";
+
   boost::regex regexObj(regexStr);
 
   //std::stringstream regexSStr;
@@ -109,7 +118,7 @@
 {
   LoggingMementoScope loggingConfiguration;
 
-  EnableTraceLevel(TRUE);
+  EnableTraceLevel(true);
 
   typedef void(*LoggingFunctionFunc)(const char*);
 
@@ -132,6 +141,7 @@
     testErrorStream.clear();
     std::string payload;
     bool ok = GetLogLinePayload(payload, logLine);
+    ASSERT_TRUE(ok);
     ASSERT_STREQ(payload.c_str(), text);
   }
 
@@ -144,6 +154,7 @@
     testErrorStream.clear();
     std::string payload;
     bool ok = GetLogLinePayload(payload, logLine);
+    ASSERT_TRUE(ok);
     ASSERT_STREQ(payload.c_str(), text);
   }
 
@@ -155,6 +166,7 @@
     testWarningStream.clear();
     std::string payload;
     bool ok = GetLogLinePayload(payload, logLine);
+    ASSERT_TRUE(ok);
     ASSERT_STREQ(payload.c_str(), text);
   }
 
@@ -166,6 +178,7 @@
     testInfoStream.clear();
     std::string payload;
     bool ok = GetLogLinePayload(payload, logLine);
+    ASSERT_TRUE(ok);
     ASSERT_STREQ(payload.c_str(), text);
   }
 }