]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3804] Fixed broken conversion of duration to text
authorMarcin Siodelski <marcin@isc.org>
Mon, 20 Apr 2015 14:53:02 +0000 (16:53 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 20 Apr 2015 14:53:02 +0000 (16:53 +0200)
src/lib/util/stopwatch_impl.cc
src/lib/util/tests/stopwatch_unittest.cc

index b124aea0f02026c18387b6d640ec43653d837b7b..79fc71ae237f3bd3e20f1c377730fb7983bbdf38 100644 (file)
@@ -13,6 +13,7 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <util/stopwatch_impl.h>
+#include <iomanip>
 #include <sstream>
 
 namespace isc {
@@ -87,7 +88,8 @@ std::string
 StopwatchImpl::logFormat(const boost::posix_time::time_duration& duration) {
     std::ostringstream s;
     s << duration.total_milliseconds() << ".";
-    s << (duration.total_microseconds() % 1000) << " ms";
+    s << std::setfill('0') << std::setw(3) << (duration.total_microseconds() % 1000)
+      << " ms";
     return (s.str());
 }
 
index 4a0fc53fa5155601ec76bfbc7855be7750b0e34c..973b71fe7d6f4642ddb37c1018f22831247977b6 100644 (file)
@@ -287,14 +287,14 @@ TEST_F(StopwatchTest, autostart) {
 
 // Make sure that the conversion to the loggable string works as expected.
 TEST_F(StopwatchTest, logFormat) {
-    time_duration duration = microseconds(223543);
-    EXPECT_EQ("223.543 ms", StopwatchImpl::logFormat(duration));
+    time_duration duration = microseconds(223043);
+    EXPECT_EQ("223.043 ms", StopwatchImpl::logFormat(duration));
 
     duration = microseconds(1234);
     EXPECT_EQ("1.234 ms", StopwatchImpl::logFormat(duration));
 
     duration = microseconds(2000);
-    EXPECT_EQ("2.0 ms", StopwatchImpl::logFormat(duration));
+    EXPECT_EQ("2.000 ms", StopwatchImpl::logFormat(duration));
 }
 
 } // end of anonymous namespace