# HG changeset patch # User Sebastien Jodogne # Date 1783432319 -7200 # Node ID 91b3be9a243a8fa77aeda9e2192fb6354ec463cf # Parent 27ad2332b84a448d8eafc99f4d623769db575cd5 fix unit test FuncStreamBuf.BasicTest diff -r 27ad2332b84a -r 91b3be9a243a OrthancFramework/Sources/Logging.cpp --- 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(threadId_); + return FormatThreadName(boost::lexical_cast(threadId_)); } } diff -r 27ad2332b84a -r 91b3be9a243a OrthancFramework/UnitTestsSources/LoggingTests.cpp --- 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