diff options
author | Konrad Grochowski <hcorg@apache.org> | 2015-09-25 20:17:36 +0200 |
---|---|---|
committer | Konrad Grochowski <hcorg@apache.org> | 2015-09-25 21:04:57 +0200 |
commit | e9bdb411fbf06aa51d25a6fd85a76327b2dc4ae4 (patch) | |
tree | 59dfda9e5acfceb5e35ad19b4440fea295746a93 | |
parent | 0621e1fc949a7e67c418b465f7f10ee082ea4a93 (diff) | |
download | thrift-e9bdb411fbf06aa51d25a6fd85a76327b2dc4ae4.tar.gz |
THRIFT-3329: fix C++ tests incompatibility with boost-1.59
Client: C++
Patch: James E. King, III <jim.king@simplivity.com>
This closes #620
-rw-r--r-- | lib/cpp/test/SecurityTest.cpp | 64 | ||||
-rw-r--r-- | lib/cpp/test/TMemoryBufferTest.cpp | 2 | ||||
-rw-r--r-- | lib/cpp/test/TServerIntegrationTest.cpp | 8 | ||||
-rw-r--r-- | lib/cpp/test/TransportTest.cpp | 38 | ||||
-rw-r--r-- | lib/cpp/test/ZlibTest.cpp | 20 |
5 files changed, 72 insertions, 60 deletions
diff --git a/lib/cpp/test/SecurityTest.cpp b/lib/cpp/test/SecurityTest.cpp index c22d79b93..213efd449 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; diff --git a/lib/cpp/test/TMemoryBufferTest.cpp b/lib/cpp/test/TMemoryBufferTest.cpp index 492eead0b..84103e3f6 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; diff --git a/lib/cpp/test/TServerIntegrationTest.cpp b/lib/cpp/test/TServerIntegrationTest.cpp index 38cbc210b..f530771e6 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(); } } diff --git a/lib/cpp/test/TransportTest.cpp b/lib/cpp/test/TransportTest.cpp index 7bd8aa0fe..c056a5d0a 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); diff --git a/lib/cpp/test/ZlibTest.cpp b/lib/cpp/test/ZlibTest.cpp index cf628ed29..fa237a2e0 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, |