Browse Source

Merge branch 'error-log'

* error-log:
  Use "gatekeeper" variable AddingEntry in ctkErrorLogModel::AddEntry
  Extend ctkErrorLogModelTest3 to include ctkErrorLogStreamMessageHandler
Jean-Christophe Fillion-Robin 14 years ago
parent
commit
89409baedf

+ 1 - 1
Libs/Core/Testing/Cpp/CMakeLists.txt

@@ -116,7 +116,7 @@ SIMPLE_TEST( ctkErrorLogModelTest1 )
 SIMPLE_TEST( ctkErrorLogModelTest2 )
 SIMPLE_TEST( ctkErrorLogModelTest3 )
 SET_TESTS_PROPERTIES(ctkErrorLogModelTest3 PROPERTIES PASS_REGULAR_EXPRESSION
-"This is a qDebug message\nThis is a qWarning message\nThis is a qCritical message\n")
+"This is a qDebug message\nThis is a std::cerr message\nThis is a qWarning message\nThis is a std::cout message\nThis is a qCritical message\n")
 SIMPLE_TEST( ctkModelTesterTest1 )
 SIMPLE_TEST( ctkPimplTest1 )
 SIMPLE_TEST( ctkSingletonTest1 )

+ 23 - 13
Libs/Core/Testing/Cpp/ctkErrorLogModelTest3.cpp

@@ -26,6 +26,7 @@
 // CTK includes
 #include "ctkErrorLogModel.h"
 #include "ctkErrorLogQtMessageHandler.h"
+#include "ctkErrorLogStreamMessageHandler.h"
 #include "ctkModelTester.h"
 
 // STL includes
@@ -138,26 +139,35 @@ int ctkErrorLogModelTest3(int argc, char * argv [])
     {
     modelTester.setModel(&model);
 
-    // --------------------------------------------------------------------------
     // Monitor Qt messages
     model.registerMsgHandler(new ctkErrorLogQtMessageHandler);
     model.setMsgHandlerEnabled(ctkErrorLogQtMessageHandler::HandlerName, true);
 
-    QString qtMessage0("This is a qDebug message");
-    qDebug().nospace() << qPrintable(qtMessage0);
+    // Monitor Stream messages
+    model.registerMsgHandler(new ctkErrorLogStreamMessageHandler);
+    model.setMsgHandlerEnabled(ctkErrorLogStreamMessageHandler::HandlerName, true);
 
-    QString qtMessage1("This is a qWarning message");
-    qWarning().nospace() << qPrintable(qtMessage1);
+    QString message0("This is a qDebug message");
+    qDebug().nospace() << qPrintable(message0);
 
-    QString qtMessage2("This is a qCritical message");
-    qCritical().nospace() << qPrintable(qtMessage2);
+    QString message1("This is a std::cerr message");
+    std::cerr << qPrintable(message1) << std::endl;
 
-    QStringList expectedQtMessages;
-    expectedQtMessages << qtMessage0
-                       << qtMessage1
-                       << qtMessage2;
+    QString message2("This is a qWarning message");
+    qWarning().nospace() << qPrintable(message2);
 
-    errorMsg = checkRowCount(__LINE__, model.rowCount(), /* expected = */ expectedQtMessages.count());
+    QString message3("This is a std::cout message");
+    std::cout << qPrintable(message3) << std::endl;
+
+    QString message4("This is a qCritical message");
+    qCritical().nospace() << qPrintable(message4);
+
+    QStringList expectedMessages;
+    expectedMessages << message0 << message1
+                     << message2 << message3
+                     << message4;
+
+    errorMsg = checkRowCount(__LINE__, model.rowCount(), /* expected = */ expectedMessages.count());
     if (!errorMsg.isEmpty())
       {
       model.disableAllMsgHandler();
@@ -166,7 +176,7 @@ int ctkErrorLogModelTest3(int argc, char * argv [])
       return EXIT_FAILURE;
       }
 
-    errorMsg = checkTextMessages(__LINE__, model, expectedQtMessages);
+    errorMsg = checkTextMessages(__LINE__, model, expectedMessages);
     if (!errorMsg.isEmpty())
       {
       model.disableAllMsgHandler();

+ 21 - 0
Libs/Core/ctkErrorLogModel.cpp

@@ -119,6 +119,8 @@ public:
 
   bool LogEntryGrouping;
 
+  bool AddingEntry;
+
   int TerminalOutputEnabled;
 
 };
@@ -130,6 +132,7 @@ public:
 ctkErrorLogModelPrivate::ctkErrorLogModelPrivate(ctkErrorLogModel& object)
   : q_ptr(&object)
 {
+  this->AddingEntry = false;
   this->TerminalOutputEnabled = false;
 }
 
@@ -299,6 +302,21 @@ void ctkErrorLogModel::addEntry(ctkErrorLogModel::LogLevel logLevel,
 {
   Q_D(ctkErrorLogModel);
 
+  if (d->AddingEntry)
+    {
+//    QFile f("/tmp/ctkErrorLogModel-AddingEntry-true.txt");
+//    f.open(QFile::Append);
+//    QTextStream s(&f);
+//    s << "text=>" << text << "\n";
+//    s << "\tlogLevel:" << qPrintable(this->logLevelAsString(logLevel)) << "\n";
+//    s << "\torigin:" << qPrintable(origin) << "\n";
+//    s << "\ttext:" << text << "\n";
+//    f.close();
+    return;
+    }
+
+  d->AddingEntry = true;
+
   QString timeFormat("dd.MM.yyyy hh:mm:ss");
   QDateTime currentDateTime = QDateTime::currentDateTime();
 
@@ -381,6 +399,7 @@ void ctkErrorLogModel::addEntry(ctkErrorLogModel::LogLevel logLevel,
   if (d->TerminalOutputEnabled)
     {
     QStringList savedMsgHandlerEnabled = this->msgHandlerEnabled();
+
     this->disableAllMsgHandler();
     if (logLevel <= ctkErrorLogModel::Info)
       {
@@ -392,6 +411,8 @@ void ctkErrorLogModel::addEntry(ctkErrorLogModel::LogLevel logLevel,
       }
     this->setMsgHandlerEnabled(savedMsgHandlerEnabled);
     }
+
+  d->AddingEntry = false;
 }
 
 //------------------------------------------------------------------------------