From e8ad5a0e6bd03b0cde6b58bdbec7b103116f2107 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 9 Aug 2013 20:31:45 -0700 Subject: [PATCH] Tidy up beast_asio --- Builds/VisualStudio2012/beast.vcxproj | 77 ++++--- Builds/VisualStudio2012/beast.vcxproj.filters | 62 +++--- modules/beast_asio/beast_asio.cpp | 12 +- modules/beast_asio/beast_asio.h | 16 +- modules/beast_asio/tests/beast_PeerTest.cpp | 73 +++++++ modules/beast_asio/tests/beast_PeerTest.h | 205 ++++++++++++++++++ modules/beast_asio/tests/beast_TestPeer.h | 15 +- .../beast_asio/tests/beast_TestPeerBasics.cpp | 47 ++++ .../beast_asio/tests/beast_TestPeerBasics.h | 113 ++++------ .../beast_asio/tests/beast_TestPeerDetails.h | 2 +- .../{detail => }/beast_TestPeerDetailsTcp.h | 0 .../beast_asio/tests/beast_TestPeerLogic.cpp | 58 +++++ .../beast_asio/tests/beast_TestPeerLogic.h | 51 +---- .../beast_TestPeerLogicAsyncClient.cpp | 0 .../beast_TestPeerLogicAsyncClient.h | 0 .../beast_TestPeerLogicAsyncServer.cpp | 0 .../beast_TestPeerLogicAsyncServer.h | 0 .../beast_TestPeerLogicSyncClient.cpp | 0 .../beast_TestPeerLogicSyncClient.h | 0 .../beast_TestPeerLogicSyncServer.cpp | 0 .../beast_TestPeerLogicSyncServer.h | 0 modules/beast_asio/tests/beast_TestPeerTest.h | 128 ----------- .../tests/{detail => }/beast_TestPeerType.h | 0 ...rTests.cpp => beast_TestPeerUnitTests.cpp} | 10 +- .../tests/detail/beast_TestPeerTestType.h | 119 ---------- .../beast_core/diagnostic/beast_UnitTest.cpp | 2 - 26 files changed, 531 insertions(+), 459 deletions(-) create mode 100644 modules/beast_asio/tests/beast_PeerTest.cpp create mode 100644 modules/beast_asio/tests/beast_PeerTest.h rename modules/beast_asio/tests/{detail => }/beast_TestPeerDetailsTcp.h (100%) create mode 100644 modules/beast_asio/tests/beast_TestPeerLogic.cpp rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicAsyncClient.cpp (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicAsyncClient.h (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicAsyncServer.cpp (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicAsyncServer.h (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicSyncClient.cpp (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicSyncClient.h (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicSyncServer.cpp (100%) rename modules/beast_asio/tests/{detail => }/beast_TestPeerLogicSyncServer.h (100%) delete mode 100644 modules/beast_asio/tests/beast_TestPeerTest.h rename modules/beast_asio/tests/{detail => }/beast_TestPeerType.h (100%) rename modules/beast_asio/tests/{beast_TestPeerTests.cpp => beast_TestPeerUnitTests.cpp} (84%) delete mode 100644 modules/beast_asio/tests/detail/beast_TestPeerTestType.h diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index 422474a3a5..3894c35e84 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -81,15 +81,14 @@ + - - - - - - - - + + + + + + @@ -310,7 +309,43 @@ true true - + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + true true true @@ -322,30 +357,6 @@ true true - - true - true - true - true - - - true - true - true - true - - - true - true - true - true - - - true - true - true - true - true diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index f379219bac..c85fd8174c 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -152,9 +152,6 @@ {422da6a1-e57e-4a96-9fce-e5958c16026e} - - {5d8ed68a-e3b5-49f3-938b-fbe7365f6293} - @@ -785,35 +782,32 @@ beast_asio\sockets - - beast_asio\tests\detail - beast_asio\tests - - beast_asio\tests\detail - beast_asio\tests - + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests + + + beast_asio\tests @@ -1240,26 +1234,32 @@ beast_asio\tests - - beast_asio\tests - beast_asio\sockets beast_asio\sockets - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests - - beast_asio\tests\detail + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests diff --git a/modules/beast_asio/beast_asio.cpp b/modules/beast_asio/beast_asio.cpp index b77cf24606..b74854aa53 100644 --- a/modules/beast_asio/beast_asio.cpp +++ b/modules/beast_asio/beast_asio.cpp @@ -29,11 +29,13 @@ namespace beast #include "sockets/beast_SslContext.cpp" #include "tests/beast_TestPeerBasics.cpp" -#include "tests/beast_TestPeerTests.cpp" +#include "tests/beast_TestPeerLogic.cpp" +#include "tests/beast_TestPeerLogicSyncServer.cpp" +#include "tests/beast_TestPeerLogicSyncClient.cpp" +#include "tests/beast_TestPeerLogicAsyncServer.cpp" +#include "tests/beast_TestPeerLogicAsyncClient.cpp" -#include "tests/detail/beast_TestPeerLogicSyncServer.cpp" -#include "tests/detail/beast_TestPeerLogicSyncClient.cpp" -#include "tests/detail/beast_TestPeerLogicAsyncServer.cpp" -#include "tests/detail/beast_TestPeerLogicAsyncClient.cpp" +#include "tests/beast_PeerTest.cpp" +#include "tests/beast_TestPeerUnitTests.cpp" } diff --git a/modules/beast_asio/beast_asio.h b/modules/beast_asio/beast_asio.h index d537fe1caa..f4a42d6e13 100644 --- a/modules/beast_asio/beast_asio.h +++ b/modules/beast_asio/beast_asio.h @@ -60,15 +60,13 @@ namespace beast #include "tests/beast_TestPeer.h" #include "tests/beast_TestPeerDetails.h" #include "tests/beast_TestPeerLogic.h" -#include "tests/beast_TestPeerTest.h" - -#include "tests/detail/beast_TestPeerLogicSyncServer.h" -#include "tests/detail/beast_TestPeerLogicSyncClient.h" -#include "tests/detail/beast_TestPeerLogicAsyncServer.h" -#include "tests/detail/beast_TestPeerLogicAsyncClient.h" -#include "tests/detail/beast_TestPeerType.h" -#include "tests/detail/beast_TestPeerTestType.h" -#include "tests/detail/beast_TestPeerDetailsTcp.h" +#include "tests/beast_TestPeerLogicSyncServer.h" +#include "tests/beast_TestPeerLogicSyncClient.h" +#include "tests/beast_TestPeerLogicAsyncServer.h" +#include "tests/beast_TestPeerLogicAsyncClient.h" +#include "tests/beast_TestPeerType.h" +#include "tests/beast_TestPeerDetailsTcp.h" +#include "tests/beast_PeerTest.h" } diff --git a/modules/beast_asio/tests/beast_PeerTest.cpp b/modules/beast_asio/tests/beast_PeerTest.cpp new file mode 100644 index 0000000000..47cbebf627 --- /dev/null +++ b/modules/beast_asio/tests/beast_PeerTest.cpp @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +PeerTest::Result::Result () + : m_ec (TestPeerBasics::make_error (TestPeerBasics::errc::skipped)) + , m_message (m_ec.message ()) +{ +} + +PeerTest::Result::Result (boost::system::error_code const& ec, String const& prefix) + : m_ec (ec) + , m_message ((prefix == String::empty) ? ec.message () + : prefix + " " + ec.message ()) +{ +} + +bool PeerTest::Result::failed () const noexcept +{ + return TestPeerBasics::failure (m_ec); +} + +bool PeerTest::Result::timedout () const noexcept +{ + return m_ec == TestPeerBasics::make_error (TestPeerBasics::errc::timeout); +} + +String PeerTest::Result::message () const noexcept +{ + return m_message; +} + +bool PeerTest::Result::report (UnitTest& test, bool reportPassingTests) +{ + bool const success = test.unexpected (failed (), message ()); + if (reportPassingTests && success) + test.logMessage (String ("pass ") + message()); + return success; +} + +//------------------------------------------------------------------------------ + +PeerTest::Results::Results () + : name ("unknown") +{ +} + +bool PeerTest::Results::report (UnitTest& test, bool beginTestCase) +{ + if (beginTestCase) + test.beginTestCase (name); + bool success = true; + if (! client.report (test)) + success = false; + if (! server.report (test)) + success = false; + return success; +} diff --git a/modules/beast_asio/tests/beast_PeerTest.h b/modules/beast_asio/tests/beast_PeerTest.h new file mode 100644 index 0000000000..a07fa50e75 --- /dev/null +++ b/modules/beast_asio/tests/beast_PeerTest.h @@ -0,0 +1,205 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_PEERTEST_H_INCLUDED +#define RIPPLE_PEERTEST_H_INCLUDED + +/** Performs a test of two peers defined by template parameters. +*/ +class PeerTest +{ +public: + enum + { + /** How long to wait before aborting a peer and reporting a timeout. + + @note Aborting synchronous logics may cause undefined behavior. + */ + defaultTimeoutSeconds = 30 + }; + + //-------------------------------------------------------------------------- + + /** Holds the test results for one peer. + */ + class Result + { + public: + /** Default constructor indicates the test was skipped. + */ + Result (); + + /** Construct from an error code. + The prefix is prepended to the error message. + */ + explicit Result (boost::system::error_code const& ec, String const& prefix = ""); + + /** Returns true if the peer failed. + */ + bool failed () const noexcept; + + /** Convenience for determining if the peer timed out. + */ + bool timedout () const noexcept; + + /** Provides a descriptive message. + This is suitable to pass to UnitTest::fail. + */ + String message () const noexcept; + + /** Report the result to a UnitTest object. + A return value of true indicates success. + */ + bool report (UnitTest& test, bool reportPassingTests = false); + + private: + boost::system::error_code m_ec; + String m_message; + }; + + //-------------------------------------------------------------------------- + + /** Holds the results for both peers in a test. + */ + struct Results + { + String name; // A descriptive name for this test case. + Result client; + Result server; + + Results (); + + /** Report the results to a UnitTest object. + A return value of true indicates success. + @param beginTestCase `true` to call test.beginTestCase for you + */ + bool report (UnitTest& test, bool beginTestCase = true); + }; + + //-------------------------------------------------------------------------- + + /** Test two peers and return the results. + */ + template + static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds) + { + Results results; + + results.name = Details::getArgName (arg); + + try + { + TestPeerType server (arg); + + results.name << " / " << server.name (); + + try + { + TestPeerType client (arg); + + results.name << " / " << client.name (); + + try + { + server.start (); + + try + { + client.start (); + + boost::system::error_code const ec = + client.join (timeoutSeconds); + + results.client = Result (ec, client.name ()); + + try + { + boost::system::error_code const ec = + server.join (timeoutSeconds); + + results.server = Result (ec, server.name ()); + + } + catch (...) + { + results.server = Result (TestPeerBasics::make_error ( + TestPeerBasics::errc::exceptioned), server.name ()); + } + } + catch (...) + { + results.client = Result (TestPeerBasics::make_error ( + TestPeerBasics::errc::exceptioned), client.name ()); + } + } + catch (...) + { + results.server = Result (TestPeerBasics::make_error ( + TestPeerBasics::errc::exceptioned), server.name ()); + } + } + catch (...) + { + results.client = Result (TestPeerBasics::make_error ( + TestPeerBasics::errc::exceptioned), "client"); + } + } + catch (...) + { + results.server = Result (TestPeerBasics::make_error ( + TestPeerBasics::errc::exceptioned), "server"); + } + + return results; + } + + //-------------------------------------------------------------------------- + + /** Reports tests of Details for all known asynchronous logic combinations to a UnitTest. + */ + template + static void report_async (UnitTest& test, Arg const& arg, + int timeoutSeconds = defaultTimeoutSeconds, + bool beginTestCase = true) + { + run + (arg, timeoutSeconds).report (test, beginTestCase); + } + + /** Reports tests of Details against all known logic combinations to a UnitTest. + */ + template + static void report (UnitTest& test, Arg const& arg, + int timeoutSeconds = defaultTimeoutSeconds, + bool beginTestCase = true) + { + run + (arg, timeoutSeconds).report (test, beginTestCase); + + run + (arg, timeoutSeconds).report (test, beginTestCase); + + run + (arg, timeoutSeconds).report (test, beginTestCase); + + report_async
(test, arg, timeoutSeconds, beginTestCase); + } +}; + +#endif diff --git a/modules/beast_asio/tests/beast_TestPeer.h b/modules/beast_asio/tests/beast_TestPeer.h index c87647605a..6ffcc0b7b4 100644 --- a/modules/beast_asio/tests/beast_TestPeer.h +++ b/modules/beast_asio/tests/beast_TestPeer.h @@ -22,9 +22,7 @@ /** An abstract peer for unit tests. */ -class TestPeer - : public TestPeerBasics - , public Uncopyable +class TestPeer : public TestPeerBasics { public: virtual ~TestPeer () { } @@ -47,17 +45,6 @@ public: @return Any error code generated during the server operation. */ virtual boost::system::error_code join (int timeoutSeconds = -1) = 0; - - /** Runs a unit test on the specified pair of peers. - Returns true if the tests passed. - */ -#if 0 - static bool runTest (UnitTest& test, - TestPeer& server, - TestPeer& client, - int timeoutSeconds, - String const& name); -#endif }; #endif diff --git a/modules/beast_asio/tests/beast_TestPeerBasics.cpp b/modules/beast_asio/tests/beast_TestPeerBasics.cpp index d45a70de70..257ba0c562 100644 --- a/modules/beast_asio/tests/beast_TestPeerBasics.cpp +++ b/modules/beast_asio/tests/beast_TestPeerBasics.cpp @@ -17,6 +17,51 @@ */ //============================================================================== +TestPeerBasics::Role::Role (role_t role) + : m_role (role) +{ +} + +String TestPeerBasics::Role::name () const noexcept +{ + if (m_role == server) + return "server"; + return "client"; +} + +bool TestPeerBasics::Role::operator== (role_t role) const noexcept +{ + return m_role == role; +} + +TestPeerBasics::Role::operator Socket::handshake_type () const noexcept +{ + if (m_role == server) + return Socket::server; + return Socket::client; +} + +//------------------------------------------------------------------------------ + +TestPeerBasics::Model::Model (model_t model) + : m_model (model) +{ +} + +String TestPeerBasics::Model::name () const noexcept +{ + if (m_model == async) + return "async"; + return "sync"; +} + +bool TestPeerBasics::Model::operator== (model_t model) const noexcept +{ + return m_model == model; +} + +//------------------------------------------------------------------------------ + boost::system::error_category const& TestPeerBasics::test_category () noexcept { struct test_category_type : boost::system::error_category @@ -99,3 +144,5 @@ bool TestPeerBasics::unexpected (bool condition, boost::system::error_code& ec) return ! expected (condition, ec); } +//------------------------------------------------------------------------------ + diff --git a/modules/beast_asio/tests/beast_TestPeerBasics.h b/modules/beast_asio/tests/beast_TestPeerBasics.h index 8c57c18622..cf2c6f3f32 100644 --- a/modules/beast_asio/tests/beast_TestPeerBasics.h +++ b/modules/beast_asio/tests/beast_TestPeerBasics.h @@ -24,8 +24,48 @@ @see TestPeer */ -struct TestPeerBasics +class TestPeerBasics { +public: + /** Identifies if the peer is a client or a server. */ + struct Role + { + enum role_t + { + client, + server + }; + + Role (role_t role); + String name () const noexcept; + bool operator== (role_t role) const noexcept; + operator Socket::handshake_type () const noexcept; + + private: + role_t m_role; + }; + + //-------------------------------------------------------------------------- + + /** Selects between synchronous or asynchronous networking i/o usage. */ + struct Model + { + enum model_t + { + sync, + async + }; + + Model (model_t model); + String name () const noexcept; + bool operator== (model_t model) const noexcept; + + private: + model_t m_model; + }; + + //-------------------------------------------------------------------------- + // Custom error codes for distinguishing test conditions struct errc { @@ -67,77 +107,6 @@ struct TestPeerBasics /** Set the error based on a passed condition and return the success. */ static bool unexpected (bool condition, boost::system::error_code& ec) noexcept; - - //-------------------------------------------------------------------------- - - struct Role - { - enum role_t - { - client, - server - }; - - Role (role_t role) - : m_role (role) - { - } - - String name () const noexcept - { - if (m_role == server) - return "server"; - return "client"; - } - - bool operator== (role_t role) const noexcept - { - return m_role == role; - } - - operator Socket::handshake_type () const noexcept - { - if (m_role == server) - return Socket::server; - return Socket::client; - } - - private: - role_t m_role; - }; - - //-------------------------------------------------------------------------- - - struct Model - { - enum model_t - { - sync, - async - }; - - Model (model_t model) - : m_model (model) - { - } - - String name () const noexcept - { - if (m_model == async) - return "async"; - return "sync"; - } - - bool operator== (model_t model) const noexcept - { - return m_model == model; - } - - private: - model_t m_model; - }; - - //-------------------------------------------------------------------------- }; #endif diff --git a/modules/beast_asio/tests/beast_TestPeerDetails.h b/modules/beast_asio/tests/beast_TestPeerDetails.h index ec2a6b9887..c03f4bd2ba 100644 --- a/modules/beast_asio/tests/beast_TestPeerDetails.h +++ b/modules/beast_asio/tests/beast_TestPeerDetails.h @@ -22,7 +22,7 @@ /** Base class of all detail objects. */ -class TestPeerDetails : public Uncopyable +class TestPeerDetails { public: virtual ~TestPeerDetails () { } diff --git a/modules/beast_asio/tests/detail/beast_TestPeerDetailsTcp.h b/modules/beast_asio/tests/beast_TestPeerDetailsTcp.h similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerDetailsTcp.h rename to modules/beast_asio/tests/beast_TestPeerDetailsTcp.h diff --git a/modules/beast_asio/tests/beast_TestPeerLogic.cpp b/modules/beast_asio/tests/beast_TestPeerLogic.cpp new file mode 100644 index 0000000000..d2d8e1adb8 --- /dev/null +++ b/modules/beast_asio/tests/beast_TestPeerLogic.cpp @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +TestPeerLogic::TestPeerLogic (Socket& socket) + : m_socket (&socket) +{ +} + +TestPeerLogic::error_code& TestPeerLogic::error () noexcept +{ + return m_ec; +} + +TestPeerLogic::error_code const& TestPeerLogic::error () const noexcept +{ + return m_ec; +} + +TestPeerLogic::error_code const& TestPeerLogic::error (error_code const& ec) noexcept +{ + return m_ec = ec; +} + +Socket& TestPeerLogic::socket () noexcept +{ + return *m_socket; +} + +void TestPeerLogic::on_connect () +{ + pure_virtual (); +} + +void TestPeerLogic::on_connect_async (error_code const&) +{ + pure_virtual (); +} + +void TestPeerLogic::pure_virtual () +{ + fatal_error ("A TestPeerLogic function was called incorrectly"); +} diff --git a/modules/beast_asio/tests/beast_TestPeerLogic.h b/modules/beast_asio/tests/beast_TestPeerLogic.h index a0094a01ad..bdb47cf35f 100644 --- a/modules/beast_asio/tests/beast_TestPeerLogic.h +++ b/modules/beast_asio/tests/beast_TestPeerLogic.h @@ -22,62 +22,31 @@ /** Interface for implementing the logic part of a peer test. */ -class TestPeerLogic - : public TestPeerBasics - , public Uncopyable +class TestPeerLogic : public TestPeerBasics { public: typedef boost::system::error_code error_code; - explicit TestPeerLogic (Socket& socket) - : m_socket (socket) - { - } + explicit TestPeerLogic (Socket& socket); - error_code& error () noexcept - { - return m_ec; - } + error_code& error () noexcept; + error_code const& error () const noexcept; + error_code const& error (error_code const& ec) noexcept; // assigns to m_ec - error_code const& error () const noexcept - { - return m_ec; - } - - // also assigns, used for async handlers - error_code const& error (error_code const& ec) noexcept - { - return m_ec = ec; - } - - Socket& socket () noexcept - { - return m_socket; - } + Socket& socket () noexcept; virtual Role get_role () const noexcept = 0; - virtual Model get_model () const noexcept = 0; - virtual void on_connect () - { - pure_virtual (); - } - - virtual void on_connect_async (error_code const&) - { - pure_virtual (); - } + virtual void on_connect (); + virtual void on_connect_async (error_code const&); protected: - static void pure_virtual () - { - fatal_error ("A TestPeerLogic function was called incorrectly"); - } + static void pure_virtual (); private: error_code m_ec; - Socket& m_socket; + Socket* m_socket; }; #endif diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncClient.cpp b/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncClient.cpp rename to modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncClient.h b/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.h similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncClient.h rename to modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.h diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncServer.cpp b/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncServer.cpp rename to modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncServer.h b/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.h similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicAsyncServer.h rename to modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.h diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicSyncClient.cpp b/modules/beast_asio/tests/beast_TestPeerLogicSyncClient.cpp similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicSyncClient.cpp rename to modules/beast_asio/tests/beast_TestPeerLogicSyncClient.cpp diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicSyncClient.h b/modules/beast_asio/tests/beast_TestPeerLogicSyncClient.h similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicSyncClient.h rename to modules/beast_asio/tests/beast_TestPeerLogicSyncClient.h diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicSyncServer.cpp b/modules/beast_asio/tests/beast_TestPeerLogicSyncServer.cpp similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicSyncServer.cpp rename to modules/beast_asio/tests/beast_TestPeerLogicSyncServer.cpp diff --git a/modules/beast_asio/tests/detail/beast_TestPeerLogicSyncServer.h b/modules/beast_asio/tests/beast_TestPeerLogicSyncServer.h similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerLogicSyncServer.h rename to modules/beast_asio/tests/beast_TestPeerLogicSyncServer.h diff --git a/modules/beast_asio/tests/beast_TestPeerTest.h b/modules/beast_asio/tests/beast_TestPeerTest.h deleted file mode 100644 index 628359461a..0000000000 --- a/modules/beast_asio/tests/beast_TestPeerTest.h +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_TESTPEERTEST_H_INCLUDED -#define RIPPLE_TESTPEERTEST_H_INCLUDED - -/** Performs a test of two peers defined by template parameters. -*/ -struct TestPeerTest : protected TestPeerBasics -{ - enum - { - /** How long to wait before aborting a peer and reporting a timeout. - - @note Aborting synchronous logics may cause undefined behavior. - */ - defaultTimeoutSeconds = 30 - }; - - /** Holds the results for one peer. */ - class Result : protected TestPeerBasics - { - public: - /** Default constructor indicates the test was skipped. - */ - Result () - : m_ec (make_error (errc::skipped)) - , m_message (m_ec.message ()) - { - } - - /** Construct from an error code. - The prefix is prepended to the error message. - */ - explicit Result (boost::system::error_code const& ec, String const& prefix = "") - : m_ec (ec) - , m_message ((prefix == String::empty) ? ec.message () - : prefix + " " + ec.message ()) - { - } - - /** Returns true if the peer failed. - */ - bool failed () const noexcept - { - return failure (m_ec); - } - - /** Convenience for determining if the peer timed out. */ - bool timedout () const noexcept - { - return m_ec == make_error (errc::timeout); - } - - /** Provides a descriptive message. - This is suitable to pass to UnitTest::fail. - */ - String message () const noexcept - { - return m_message; - } - - /** Report the result to a UnitTest object. - A return value of true indicates success. - */ - bool report (UnitTest& test) - { - bool const success = test.unexpected (failed (), message ()); -#if 0 - // Option to report passing tests - if (success) - test.logMessage (String ("passed ") + message()); -#endif - return success; - } - - private: - boost::system::error_code m_ec; - String m_message; - }; - - //-------------------------------------------------------------------------- - - /** Holds the results for both peers. */ - struct Results - { - String name; // A descriptive name for this test case. - Result client; - Result server; - - Results () : name ("unknown") - { - } - - /** Report the results to a UnitTest object. - A return value of true indicates success. - */ - bool report (UnitTest& test, bool beginTestCase = true) - { - if (beginTestCase) - test.beginTestCase (name); - bool success = true; - if (! client.report (test)) - success = false; - if (! server.report (test)) - success = false; - return success; - } - }; -}; - -#endif diff --git a/modules/beast_asio/tests/detail/beast_TestPeerType.h b/modules/beast_asio/tests/beast_TestPeerType.h similarity index 100% rename from modules/beast_asio/tests/detail/beast_TestPeerType.h rename to modules/beast_asio/tests/beast_TestPeerType.h diff --git a/modules/beast_asio/tests/beast_TestPeerTests.cpp b/modules/beast_asio/tests/beast_TestPeerUnitTests.cpp similarity index 84% rename from modules/beast_asio/tests/beast_TestPeerTests.cpp rename to modules/beast_asio/tests/beast_TestPeerUnitTests.cpp index f67e7abe37..878216ac27 100644 --- a/modules/beast_asio/tests/beast_TestPeerTests.cpp +++ b/modules/beast_asio/tests/beast_TestPeerUnitTests.cpp @@ -17,7 +17,9 @@ */ //============================================================================== -class TestPeerTests : public UnitTest +/** UnitTest for the TestPeer family of objects. +*/ +class TestPeerUnitTests : public UnitTest { public: enum @@ -25,14 +27,14 @@ public: timeoutSeconds = 3 }; - TestPeerTests () : UnitTest ("TestPeer", "beast", runManual) + TestPeerUnitTests () : UnitTest ("TestPeer", "beast") { } template void testDetails (Arg const& arg = Arg ()) { - TestPeerTestType::test
(*this, arg, timeoutSeconds); + PeerTest::report
(*this, arg, timeoutSeconds); } void runTest () @@ -43,4 +45,4 @@ public: } }; -static TestPeerTests testPeerTests; +static TestPeerUnitTests testPeerUnitTests; diff --git a/modules/beast_asio/tests/detail/beast_TestPeerTestType.h b/modules/beast_asio/tests/detail/beast_TestPeerTestType.h deleted file mode 100644 index e7763b2d58..0000000000 --- a/modules/beast_asio/tests/detail/beast_TestPeerTestType.h +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_TESTPEERTESTTYPE_H_INCLUDED -#define RIPPLE_TESTPEERTESTTYPE_H_INCLUDED - -/** Performs a test of two peers defined by template parameters. -*/ -class TestPeerTestType : public TestPeerTest -{ -public: - /** Test two peers and return the results. - */ - template - static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds) - { - Results results; - - results.name = Details::getArgName (arg); - - try - { - TestPeerType server (arg); - - results.name << " / " << server.name (); - - try - { - TestPeerType client (arg); - - results.name << " / " << client.name (); - - try - { - server.start (); - - try - { - client.start (); - - boost::system::error_code const ec = - client.join (timeoutSeconds); - - results.client = Result (ec, client.name ()); - - try - { - boost::system::error_code const ec = - server.join (timeoutSeconds); - - results.server = Result (ec, server.name ()); - - } - catch (...) - { - results.server = Result (make_error ( - errc::exceptioned), server.name ()); - } - } - catch (...) - { - results.client = Result (make_error ( - errc::exceptioned), client.name ()); - } - } - catch (...) - { - results.server = Result (make_error ( - errc::exceptioned), server.name ()); - } - } - catch (...) - { - results.client = Result (make_error ( - errc::exceptioned), "client"); - } - } - catch (...) - { - results.server = Result (make_error ( - errc::exceptioned), "server"); - } - - return results; - } - - //-------------------------------------------------------------------------- - - /** Reports tests of Details against all known logic combinations to a UnitTest. - */ - template - static void test (UnitTest& test, Arg const& arg, - int timeoutSeconds = defaultTimeoutSeconds, - bool beginTestCase = true) - { - run (arg, timeoutSeconds).report (test, beginTestCase); - run (arg, timeoutSeconds).report (test, beginTestCase); - run (arg, timeoutSeconds).report (test, beginTestCase); - run (arg, timeoutSeconds).report (test, beginTestCase); - } -}; - -#endif diff --git a/modules/beast_core/diagnostic/beast_UnitTest.cpp b/modules/beast_core/diagnostic/beast_UnitTest.cpp index e9724d155b..82a10351e1 100644 --- a/modules/beast_core/diagnostic/beast_UnitTest.cpp +++ b/modules/beast_core/diagnostic/beast_UnitTest.cpp @@ -264,8 +264,6 @@ UnitTests::TestList UnitTests::selectTests ( // If no trailing slash on package, try tests if (list.size () == 0 && indexOfDot == -1) { - std::cout << "Trying package as test" << std::endl; - // Try "package" as a testname list = selectTest (package, tests); }