[asterisk-scf-commits] asterisk-scf/release/logger.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Feb 13 09:02:48 CST 2012


branch "master" has been updated
       via  fb00b2fd21f879b34dd658c9cd62e77dc12be184 (commit)
       via  14a58d5619810a239e5efe35052a5d558fd6576e (commit)
      from  5a430c1eeccead2e308d276f39c09b58072a8cbf (commit)

Summary of changes:
 client/src/LogFormatter.cpp  |   29 +++++++++++++++++++++++++----
 client/test/ExpectedLogOut.h |   11 ++++++-----
 client/test/Logger-test.cpp  |   14 +++++++++-----
 3 files changed, 40 insertions(+), 14 deletions(-)


- Log -----------------------------------------------------------------
commit fb00b2fd21f879b34dd658c9cd62e77dc12be184
Author: David M. Lee <dlee at digium.com>
Date:   Mon Feb 13 08:43:54 2012 -0600

    Adding support for older versions of Boost

diff --git a/client/src/LogFormatter.cpp b/client/src/LogFormatter.cpp
index dd0362f..a45112e 100644
--- a/client/src/LogFormatter.cpp
+++ b/client/src/LogFormatter.cpp
@@ -62,7 +62,28 @@ string AsteriskSCF::System::Logging::sourceInfoStr(const string& fmt, unsigned i
         if ((pos=s.find("$sf",0))!=string::npos)
         {
             boost::filesystem::path p(file);
-            s.replace(pos,3,p.filename().native());
+	    std::string basename;
+	    // According to http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v2/doc/index.htm:
+	    //
+	    // Boost 1.44 introduced Filesystem Library v3, with breaking API
+	    // changes.
+	    //
+	    // Boost 1.44 through 1.47 included both v2 and v3 API's.
+	    //
+	    // The default API was changed to v3 in 1.46.
+	    //
+	    // As such, code to support Boost 1.40 and the latest Boost is
+	    // sadly complicated.
+	    //
+	    // This code originally tried to use boost::lexical_cast to avoid
+	    // the #if, but it would sometimes quote the filename, which is
+	    // uncool.
+#if BOOST_FILESYSTEM_VERSION >= 3
+            basename = p.filename().native();
+#else
+	    basename = p.filename();
+#endif
+            s.replace(pos,3,basename);
             found = true;
         }
     }

commit 14a58d5619810a239e5efe35052a5d558fd6576e
Author: David M. Lee <dlee at digium.com>
Date:   Fri Feb 10 13:11:10 2012 -0600

    Several logger unit test fixes.
    
    * Lexically casting a path to string inconsistently put double quotes around
      the path. Use .native() instead
    * Client side time formatting was simply broken.
    * Rewrote ExpectedLogOut.check so the assertion message was actually useful.
    * Added note about the brittleness of the time sensitive tests.

diff --git a/client/src/LogFormatter.cpp b/client/src/LogFormatter.cpp
index 45787d3..dd0362f 100644
--- a/client/src/LogFormatter.cpp
+++ b/client/src/LogFormatter.cpp
@@ -62,7 +62,7 @@ string AsteriskSCF::System::Logging::sourceInfoStr(const string& fmt, unsigned i
         if ((pos=s.find("$sf",0))!=string::npos)
         {
             boost::filesystem::path p(file);
-            s.replace(pos,3,boost::lexical_cast<string>(p.leaf()));
+            s.replace(pos,3,p.filename().native());
             found = true;
         }
     }
@@ -121,13 +121,13 @@ string LogFormatter::formatMessage(const string& message, const string& name, Le
         {
             boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
 
-            size_t pos2 = outStr.find("}",pos+3);
+            size_t pos2 = outStr.find("}",pos + 3);
             if (pos2 != string::npos)
             {
-                string userTimeFormat = outStr.substr(pos+3,pos2-3);
+                string userTimeFormat = outStr.substr(pos + 3, pos2 - pos - 3);
                 string nowStr = getFormattedTime(now, userTimeFormat);
 
-                outStr.replace(pos,pos+pos2+1,nowStr);
+                outStr.replace(pos, pos2 - pos + 1, nowStr);
             }
         }
         catch (...)
diff --git a/client/test/ExpectedLogOut.h b/client/test/ExpectedLogOut.h
index 9ef96ac..0b8c702 100644
--- a/client/test/ExpectedLogOut.h
+++ b/client/test/ExpectedLogOut.h
@@ -32,18 +32,19 @@ public:
 
     void check()
     {
-        std::string actual = mActual.str();
-        BOOST_CHECK(0 == actual.compare(0, mExpected.length(), mExpected));
+        check(0);
     }
 
-    /** 
-     * @param less Shorten the length to compare by this amount. 
+    /**
+     * @param less Shorten the length to compare by this amount.
      * (Time strings won't match the last few digits.)
      */
     void check(int less)
     {
         std::string actual = mActual.str();
-        BOOST_CHECK(0 == actual.compare(0, (mExpected.length() - less), mExpected, 0, (mExpected.length() - less)));
+        BOOST_CHECK_EQUAL(
+            mExpected.substr(0, mExpected.size() - less),
+            actual.substr(0, actual.size() - less));
     }
 
     boost::shared_ptr<LogOut> operator()() 
diff --git a/client/test/Logger-test.cpp b/client/test/Logger-test.cpp
index 8200440..96d6f19 100644
--- a/client/test/Logger-test.cpp
+++ b/client/test/Logger-test.cpp
@@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(test_stream_format)
 
     std::string hostName = boost::asio::ip::host_name();
 
-    BOOST_REQUIRE(hostName.length() != 0); 
+    BOOST_REQUIRE(hostName.length() != 0);
     ExpectedLogOut out("Debug:src:" + hostName + ": debug f00d\n",
                        "$l:$n:$h: $m");
 
@@ -155,12 +155,16 @@ BOOST_AUTO_TEST_CASE(test_stream_timestamp)
     Ice::Long pid = (Ice::Long)boost::interprocess::ipcdetail::get_current_process_id();
     std::string nowStr = getFormattedTime(now);
 
-    ExpectedLogOut out(boost::lexical_cast<std::string>(pid) + ":src:Debug:TimeStamp test:Logger-test.cpp : " + nowStr,
+    ExpectedLogOut out(boost::lexical_cast<std::string>(pid) + ":src:Debug:TimeStamp test:Logger-test.cpp : " + nowStr + "\n",
         "$p:$n:$l:$m : $t");
     Logger uut("src", *out(), Debug);
 
     uut(Debug) << "TimeStamp test:" << SRCINFO("$sf") << '\n';
 
+    // TODO - This test is brittle b/c it assumes that time may only change in the least significant
+    // digits. But it's possible this test runs just as the second rolls over, causing this test to
+    // fail. Instead, the TimeFormatter should be provided with a TimeFactory test double that
+    // provides a stable value for the current time.
     out.check(6);
 }
 
@@ -170,12 +174,12 @@ BOOST_AUTO_TEST_CASE(test_stream_timestamp_formatted)
 
     std::string nowStr = getFormattedTime(now, "%x %H:%M:%S%p");
 
-    ExpectedLogOut out("src:Debug:TimeStamp format test " + nowStr,
-                       "$n:$l:$m $t{%x %H:%M:%S%p}");
+    ExpectedLogOut out("src:Debug:TimeStamp format test (" + nowStr + ")\n",
+                       "$n:$l:$m ($t{%x %H:%M:%S%p})");
     Logger uut("src", *out(), Debug);
 
     uut(Debug) << "TimeStamp format test" << '\n';
-    out.check(6);
+    out.check();
 }
 
 

-----------------------------------------------------------------------


-- 
asterisk-scf/release/logger.git



More information about the asterisk-scf-commits mailing list