changeset 7022:91b3be9a243a

fix unit test FuncStreamBuf.BasicTest
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2026 15:51:59 +0200
parents 27ad2332b84a
children cb751bdccb15
files OrthancFramework/Sources/Logging.cpp OrthancFramework/UnitTestsSources/LoggingTests.cpp
diffstat 2 files changed, 33 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Logging.cpp	Tue Jul 07 15:36:01 2026 +0200
+++ b/OrthancFramework/Sources/Logging.cpp	Tue Jul 07 15:51:59 2026 +0200
@@ -626,6 +626,24 @@
 
 static const size_t THREAD_NAME_MAX_SIZE = 16;   // Thread names are limited to 16 char + a space
 
+
+static std::string FormatThreadName(const std::string& name)
+{
+  if (name.size() < THREAD_NAME_MAX_SIZE)
+  {
+    return std::string(THREAD_NAME_MAX_SIZE - name.size(), ' ') + name;
+  }
+  else if (name.size() == THREAD_NAME_MAX_SIZE)
+  {
+    return name;
+  }
+  else
+  {
+    return name.substr(THREAD_NAME_MAX_SIZE);
+  }
+}
+
+
 namespace
 {
   class ThreadInformation : public boost::noncopyable
@@ -654,19 +672,7 @@
 #endif
 
       hasName_ = true;
-
-      if (name.size() < THREAD_NAME_MAX_SIZE)
-      {
-        name_ = std::string(THREAD_NAME_MAX_SIZE - name.size(), ' ') + name;
-      }
-      else if (name.size() == THREAD_NAME_MAX_SIZE)
-      {
-        name_ = name;
-      }
-      else
-      {
-        name_ = name.substr(THREAD_NAME_MAX_SIZE);
-      }
+      name_ = FormatThreadName(name);
 
       assert(name_.size() == THREAD_NAME_MAX_SIZE);
     }
@@ -786,7 +792,7 @@
         }
         else
         {
-          return boost::lexical_cast<std::string>(threadId_);
+          return FormatThreadName(boost::lexical_cast<std::string>(threadId_));
         }
       }
 
--- a/OrthancFramework/UnitTestsSources/LoggingTests.cpp	Tue Jul 07 15:36:01 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/LoggingTests.cpp	Tue Jul 07 15:51:59 2026 +0200
@@ -132,11 +132,24 @@
 
 
 #if ORTHANC_ENABLE_LOGGING_STDIO == 0
+namespace
+{
+  class BasicTestRestore : public boost::noncopyable
+  {
+  public:
+    ~BasicTestRestore()
+    {
+      Orthanc::Logging::EnableTraceLevel(false);  // Back to normal
+    }
+  };
+}
+
 TEST(FuncStreamBuf, BasicTest)
 {
   LoggingMementoScope loggingConfiguration;
 
   Orthanc::Logging::EnableTraceLevel(true);
+  BasicTestRestore restore;
 
   typedef void(*LoggingFunctionFunc)(const char*);
 
@@ -199,8 +212,6 @@
     ASSERT_TRUE(ok);
     ASSERT_STREQ(payload.c_str(), text);
   }
-
-  Orthanc::Logging::EnableTraceLevel(false);  // Back to normal
 }
 #endif