You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2015/10/01 19:17:06 UTC

[3/6] thrift git commit: THRIFT-3329: fix C++ tests incompatibility with boost-1.59

THRIFT-3329: fix C++ tests incompatibility with boost-1.59

Client: C++
Patch: James E. King, III <ji...@simplivity.com>

This closes #620


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/e9bdb411
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/e9bdb411
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/e9bdb411

Branch: refs/heads/0.9.3
Commit: e9bdb411fbf06aa51d25a6fd85a76327b2dc4ae4
Parents: 0621e1f
Author: Konrad Grochowski <hc...@apache.org>
Authored: Fri Sep 25 20:17:36 2015 +0200
Committer: Konrad Grochowski <hc...@apache.org>
Committed: Fri Sep 25 21:04:57 2015 +0200

----------------------------------------------------------------------
 lib/cpp/test/SecurityTest.cpp           | 64 ++++++++++++----------------
 lib/cpp/test/TMemoryBufferTest.cpp      |  2 +-
 lib/cpp/test/TServerIntegrationTest.cpp |  8 ++--
 lib/cpp/test/TransportTest.cpp          | 38 ++++++++++-------
 lib/cpp/test/ZlibTest.cpp               | 20 +++++++--
 5 files changed, 72 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/e9bdb411/lib/cpp/test/SecurityTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/SecurityTest.cpp b/lib/cpp/test/SecurityTest.cpp
index c22d79b..213efd4 100644
--- a/lib/cpp/test/SecurityTest.cpp
+++ b/lib/cpp/test/SecurityTest.cpp
@@ -18,7 +18,7 @@
  */
 
 #define BOOST_TEST_MODULE SecurityTest
-#include <boost/test/auto_unit_test.hpp>
+#include <boost/test/unit_test.hpp>
 #include <boost/bind.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/foreach.hpp>
@@ -55,53 +55,45 @@ struct GlobalFixture
     GlobalFixture()
     {
         using namespace boost::unit_test::framework;
-        try
-        {
-            for (int i = 0; i < master_test_suite().argc; ++i)
-            {
-                BOOST_MESSAGE(boost::format("argv[%1%] = \"%2%\"") % i % master_test_suite().argv[i]);
-            }
+		for (int i = 0; i < master_test_suite().argc; ++i)
+		{
+			BOOST_TEST_MESSAGE(boost::format("argv[%1%] = \"%2%\"") % i % master_test_suite().argv[i]);
+		}
 
     #ifdef linux
-            // OpenSSL calls send() without MSG_NOSIGPIPE so writing to a socket that has
-            // disconnected can cause a SIGPIPE signal...
-            signal(SIGPIPE, SIG_IGN);
+		// OpenSSL calls send() without MSG_NOSIGPIPE so writing to a socket that has
+		// disconnected can cause a SIGPIPE signal...
+		signal(SIGPIPE, SIG_IGN);
     #endif
 
-            TSSLSocketFactory::setManualOpenSSLInitialization(true);
-            apache::thrift::transport::initializeOpenSSL();
+		TSSLSocketFactory::setManualOpenSSLInitialization(true);
+		apache::thrift::transport::initializeOpenSSL();
 
-            keyDir = boost::filesystem::current_path().parent_path().parent_path().parent_path() / "test" / "keys";
-            if (!boost::filesystem::exists(certFile("server.crt")))
-            {
-                keyDir = boost::filesystem::path(master_test_suite().argv[master_test_suite().argc - 1]);
-                BOOST_REQUIRE_MESSAGE(boost::filesystem::exists(certFile("server.crt")),
-                                      "The last argument to this test must be the directory containing the test certificate(s).");
-            }
-        }
-        catch (std::exception& ex)
-        {
-            BOOST_FAIL(boost::format("%1%: %2%") % typeid(ex).name() % ex.what());
-        }
+		keyDir = boost::filesystem::current_path().parent_path().parent_path().parent_path() / "test" / "keys";
+		if (!boost::filesystem::exists(certFile("server.crt")))
+		{
+			keyDir = boost::filesystem::path(master_test_suite().argv[master_test_suite().argc - 1]);
+			if (!boost::filesystem::exists(certFile("server.crt")))
+			{
+				throw std::invalid_argument("The last argument to this test must be the directory containing the test certificate(s).");
+			}
+		}
     }
 
     virtual ~GlobalFixture()
     {
-        try
-        {
-            apache::thrift::transport::cleanupOpenSSL();
+		apache::thrift::transport::cleanupOpenSSL();
 #ifdef linux
-            signal(SIGPIPE, SIG_DFL);
+		signal(SIGPIPE, SIG_DFL);
 #endif
-        }
-        catch (std::exception& ex)
-        {
-            BOOST_MESSAGE(boost::format("%1%: %2%") % typeid(ex).name() % ex.what());
-        }
     }
 };
 
+#if (BOOST_VERSION >= 105900)
+BOOST_GLOBAL_FIXTURE(GlobalFixture);
+#else
 BOOST_GLOBAL_FIXTURE(GlobalFixture)
+#endif
 
 struct SecurityFixture : public TestPortFixture
 {
@@ -139,7 +131,7 @@ struct SecurityFixture : public TestPortFixture
             catch (apache::thrift::transport::TTransportException& ex)
             {
                 boost::mutex::scoped_lock lock(gMutex);
-                BOOST_MESSAGE(boost::format("SRV %1% Exception: %2%") % boost::this_thread::get_id() % ex.what());
+                BOOST_TEST_MESSAGE(boost::format("SRV %1% Exception: %2%") % boost::this_thread::get_id() % ex.what());
             }
 
             if (connectedClient)
@@ -184,7 +176,7 @@ struct SecurityFixture : public TestPortFixture
             catch (apache::thrift::transport::TTransportException& ex)
             {
                 boost::mutex::scoped_lock lock(gMutex);
-                BOOST_MESSAGE(boost::format("CLI %1% Exception: %2%") % boost::this_thread::get_id() % ex.what());
+                BOOST_TEST_MESSAGE(boost::format("CLI %1% Exception: %2%") % boost::this_thread::get_id() % ex.what());
             }
 
             if (pClientSocket)
@@ -249,7 +241,7 @@ BOOST_AUTO_TEST_CASE(ssl_security_matrix)
 
                 boost::mutex::scoped_lock lock(mMutex);
 
-                BOOST_MESSAGE(boost::format("TEST: Server = %1%, Client = %2%")
+                BOOST_TEST_MESSAGE(boost::format("TEST: Server = %1%, Client = %2%")
                     % protocol2str(si) % protocol2str(ci));
 
                 mConnected = false;

http://git-wip-us.apache.org/repos/asf/thrift/blob/e9bdb411/lib/cpp/test/TMemoryBufferTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TMemoryBufferTest.cpp b/lib/cpp/test/TMemoryBufferTest.cpp
index 492eead..84103e3 100644
--- a/lib/cpp/test/TMemoryBufferTest.cpp
+++ b/lib/cpp/test/TMemoryBufferTest.cpp
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(test_copy) {
   string* str2 = new string("plsreuse");
   bool obj_reuse = (str1 == str2);
   bool dat_reuse = (data1 == str2->data());
-  BOOST_MESSAGE("Object reuse: " << obj_reuse << "   Data reuse: " << dat_reuse
+  BOOST_TEST_MESSAGE("Object reuse: " << obj_reuse << "   Data reuse: " << dat_reuse
                 << ((obj_reuse && dat_reuse) ? "   YAY!" : ""));
   delete str2;
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/e9bdb411/lib/cpp/test/TServerIntegrationTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TServerIntegrationTest.cpp b/lib/cpp/test/TServerIntegrationTest.cpp
index 38cbc21..f530771 100644
--- a/lib/cpp/test/TServerIntegrationTest.cpp
+++ b/lib/cpp/test/TServerIntegrationTest.cpp
@@ -176,7 +176,7 @@ public:
       pEventHandler->wait();
     }
 
-    BOOST_MESSAGE("server is listening");
+    BOOST_TEST_MESSAGE("server is listening");
   }
 
   void blockUntilAccepted(uint64_t numAccepted) {
@@ -185,16 +185,16 @@ public:
       pEventHandler->wait();
     }
 
-    BOOST_MESSAGE(boost::format("server has accepted %1%") % numAccepted);
+    BOOST_TEST_MESSAGE(boost::format("server has accepted %1%") % numAccepted);
   }
 
   void stopServer() {
     if (pServerThread) {
       pServer->stop();
-      BOOST_MESSAGE("server stop completed");
+      BOOST_TEST_MESSAGE("server stop completed");
 
       pServerThread->join();
-      BOOST_MESSAGE("server thread joined");
+      BOOST_TEST_MESSAGE("server thread joined");
       pServerThread.reset();
     }
   }

http://git-wip-us.apache.org/repos/asf/thrift/blob/e9bdb411/lib/cpp/test/TransportTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TransportTest.cpp b/lib/cpp/test/TransportTest.cpp
index 7bd8aa0..c056a5d 100644
--- a/lib/cpp/test/TransportTest.cpp
+++ b/lib/cpp/test/TransportTest.cpp
@@ -33,6 +33,7 @@
 #include <boost/random.hpp>
 #include <boost/type_traits.hpp>
 #include <boost/test/unit_test.hpp>
+#include <boost/version.hpp>
 
 #include <thrift/transport/TBufferTransports.h>
 #include <thrift/transport/TFDTransport.h>
@@ -919,6 +920,12 @@ public:
                 rand4k);
   }
 
+#if (BOOST_VERSION >= 105900)
+#define MAKE_TEST_CASE(_FUNC, _NAME) boost::unit_test::make_test_case(_FUNC, _NAME, __FILE__, __LINE__)
+#else
+#define MAKE_TEST_CASE(_FUNC, _NAME) boost::unit_test::make_test_case(_FUNC, _NAME)
+#endif
+
 private:
   template <class CoupledTransports>
   void addTestRW(const char* transport_name,
@@ -937,7 +944,11 @@ private:
          << rSizeGen.describe() << ", " << wChunkSizeGen.describe() << ", "
          << rChunkSizeGen.describe() << ", " << maxOutstanding << ")";
 
+#if (BOOST_VERSION >= 105900)
+    boost::function<void ()> test_func
+#else
     boost::unit_test::callback0<> test_func
+#endif
         = apache::thrift::stdcxx::bind(test_rw<CoupledTransports>,
                                        totalSize,
                                        wSizeGen,
@@ -945,39 +956,30 @@ private:
                                        wChunkSizeGen,
                                        rChunkSizeGen,
                                        maxOutstanding);
-    boost::unit_test::test_case* tc = boost::unit_test::make_test_case(test_func, name.str());
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_func, name.str()), expectedFailures);
   }
 
   template <class CoupledTransports>
   void addTestBlocking(const char* transportName, uint32_t expectedFailures = 0) {
     char name[1024];
-    boost::unit_test::test_case* tc;
 
     THRIFT_SNPRINTF(name, sizeof(name), "%s::test_read_part_available()", transportName);
-    tc = boost::unit_test::make_test_case(test_read_part_available<CoupledTransports>, name);
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_read_part_available<CoupledTransports>, name), expectedFailures);
 
     THRIFT_SNPRINTF(name, sizeof(name), "%s::test_read_part_available_in_chunks()", transportName);
-    tc = boost::unit_test::make_test_case(test_read_part_available_in_chunks<CoupledTransports>,
-                                          name);
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_read_part_available_in_chunks<CoupledTransports>, name), expectedFailures);
 
     THRIFT_SNPRINTF(name, sizeof(name), "%s::test_read_partial_midframe()", transportName);
-    tc = boost::unit_test::make_test_case(test_read_partial_midframe<CoupledTransports>, name);
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_read_partial_midframe<CoupledTransports>, name), expectedFailures);
 
     THRIFT_SNPRINTF(name, sizeof(name), "%s::test_read_none_available()", transportName);
-    tc = boost::unit_test::make_test_case(test_read_none_available<CoupledTransports>, name);
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_read_none_available<CoupledTransports>, name), expectedFailures);
 
     THRIFT_SNPRINTF(name, sizeof(name), "%s::test_borrow_part_available()", transportName);
-    tc = boost::unit_test::make_test_case(test_borrow_part_available<CoupledTransports>, name);
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_borrow_part_available<CoupledTransports>, name), expectedFailures);
 
     THRIFT_SNPRINTF(name, sizeof(name), "%s::test_borrow_none_available()", transportName);
-    tc = boost::unit_test::make_test_case(test_borrow_none_available<CoupledTransports>, name);
-    suite_->add(tc, expectedFailures);
+    suite_->add(MAKE_TEST_CASE(test_borrow_none_available<CoupledTransports>, name), expectedFailures);
   }
 
   boost::unit_test::test_suite* suite_;
@@ -1016,7 +1018,11 @@ struct global_fixture {
   }
 };
 
+#if (BOOST_VERSION >= 105900)
+BOOST_GLOBAL_FIXTURE(global_fixture);
+#else
 BOOST_GLOBAL_FIXTURE(global_fixture)
+#endif
 
 boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
   THRIFT_UNUSED_VARIABLE(argc);

http://git-wip-us.apache.org/repos/asf/thrift/blob/e9bdb411/lib/cpp/test/ZlibTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/ZlibTest.cpp b/lib/cpp/test/ZlibTest.cpp
index cf628ed..fa237a2 100644
--- a/lib/cpp/test/ZlibTest.cpp
+++ b/lib/cpp/test/ZlibTest.cpp
@@ -32,9 +32,11 @@
 #include <iostream>
 #include <thrift/cxxfunctional.h>
 
+#include <boost/function.hpp>
 #include <boost/random.hpp>
 #include <boost/shared_array.hpp>
 #include <boost/test/unit_test.hpp>
+#include <boost/version.hpp>
 
 #include <thrift/transport/TBufferTransports.h>
 #include <thrift/transport/TZlibTransport.h>
@@ -328,16 +330,28 @@ void test_no_write() {
  * Initialization
  */
 
-#define ADD_TEST_CASE(suite, name, function, ...)                                                  \
+#if (BOOST_VERSION >= 105900)
+#define ADD_TEST_CASE(suite, name, _FUNC, ...)                                                     \
   do {                                                                                             \
     ::std::ostringstream name_ss;                                                                  \
-    name_ss << name << "-" << BOOST_STRINGIZE(function);                                           \
+    name_ss << name << "-" << BOOST_STRINGIZE(_FUNC);                                              \
+    boost::function<void ()> test_func = ::apache::thrift::stdcxx::bind(_FUNC, ##__VA_ARGS__);     \
     ::boost::unit_test::test_case* tc                                                              \
-        = ::boost::unit_test::make_test_case(::apache::thrift::stdcxx::bind(function,              \
+        = ::boost::unit_test::make_test_case(test_func, name_ss.str(), __FILE__, __LINE__);        \
+    (suite)->add(tc);                                                                              \
+  } while (0)
+#else
+#define ADD_TEST_CASE(suite, name, _FUNC, ...)                                                     \
+  do {                                                                                             \
+    ::std::ostringstream name_ss;                                                                  \
+    name_ss << name << "-" << BOOST_STRINGIZE(_FUNC);                                              \
+    ::boost::unit_test::test_case* tc                                                              \
+        = ::boost::unit_test::make_test_case(::apache::thrift::stdcxx::bind(_FUNC,                 \
                                                                             ##__VA_ARGS__),        \
                                              name_ss.str());                                       \
     (suite)->add(tc);                                                                              \
   } while (0)
+#endif
 
 void add_tests(boost::unit_test::test_suite* suite,
                const boost::shared_array<uint8_t>& buf,