diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 5ed815b435..64c135d19c 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -22,12 +22,6 @@ - - true - true - true - true - true true @@ -1024,7 +1018,7 @@ true true - + true true true @@ -1712,6 +1706,12 @@ true true + + true + true + true + true + true true @@ -2238,7 +2238,6 @@ - @@ -2509,7 +2508,6 @@ - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 503928fdf6..b2c9bd29d6 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -750,9 +750,6 @@ [2] Old Ripple\ripple_app\consensus - - [2] Old Ripple\ripple_app\main - [2] Old Ripple\ripple_app\websocket @@ -1356,9 +1353,6 @@ [1] Ripple\radmap\impl - - [1] Ripple\common\impl - [1] Ripple\common\impl @@ -1497,6 +1491,12 @@ [1] Ripple\sslutil\impl + + [2] Old Ripple\ripple_data\protocol + + + [2] Old Ripple\ripple_app\main + @@ -1982,9 +1982,6 @@ [2] Old Ripple\ripple_app\consensus - - [2] Old Ripple\ripple_app\main - [2] Old Ripple\ripple_app\websocket @@ -2834,9 +2831,6 @@ [1] Ripple\radmap\api - - [1] Ripple\common - [1] Ripple\common diff --git a/src/BeastConfig.h b/src/BeastConfig.h index 36210f93f0..a9184bbac9 100644 --- a/src/BeastConfig.h +++ b/src/BeastConfig.h @@ -27,6 +27,21 @@ @file BeastConfig.h */ +//------------------------------------------------------------------------------ +// +// Unit Tests +// +//------------------------------------------------------------------------------ + +/** Config: BEAST_NO_UNIT_TEST_INLINE + Prevents unit test definitions from being inserted into a global table. + The default is to include inline unit test definitions. +*/ + +#ifndef BEAST_NO_UNIT_TEST_INLINE +//#define BEAST_NO_UNIT_TEST_INLINE 1 +#endif + //------------------------------------------------------------------------------ // // Diagnostics diff --git a/src/beast/BeastConfig.h b/src/beast/BeastConfig.h index 40d2da93f9..0765cc3b77 100644 --- a/src/beast/BeastConfig.h +++ b/src/beast/BeastConfig.h @@ -27,6 +27,19 @@ @file BeastConfig.h */ +//------------------------------------------------------------------------------ +// +// Unit Tests +// +//------------------------------------------------------------------------------ + +/** Config: BEAST_NO_UNIT_TEST_INLINE + Prevents unit test definitions from being inserted into a global table. +*/ +#ifndef BEAST_NO_UNIT_TEST_INLINE +#define BEAST_NO_UNIT_TEST_INLINE 0 +#endif + //------------------------------------------------------------------------------ // // Diagnostics diff --git a/src/beast/Builds/VisualStudio2013/beast.vcxproj b/src/beast/Builds/VisualStudio2013/beast.vcxproj index 1df00296c4..9dbccaa521 100644 --- a/src/beast/Builds/VisualStudio2013/beast.vcxproj +++ b/src/beast/Builds/VisualStudio2013/beast.vcxproj @@ -93,6 +93,7 @@ + @@ -224,6 +225,24 @@ + + + + true + true + true + true + + + + + + + + + + + @@ -284,7 +303,6 @@ - @@ -300,7 +318,6 @@ - @@ -380,7 +397,7 @@ true true - + true true true @@ -392,13 +409,13 @@ true true - + true true true true - + true true true @@ -406,38 +423,32 @@ - - 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 true true @@ -450,12 +461,6 @@ true - - true - true - true - true - true true @@ -492,6 +497,18 @@ true true + + true + true + true + true + + + true + true + true + true + true @@ -548,6 +565,12 @@ true true + + true + true + true + true + true true @@ -597,12 +620,6 @@ true true - - true - true - true - true - true true @@ -622,8 +639,19 @@ true - + + true + true + true + true + + + true + true + true + true + true true @@ -637,12 +665,6 @@ true - - true - true - true - true - true true @@ -673,13 +695,19 @@ true true - - + true true true true + + true + true + true + true + + true true @@ -716,6 +744,12 @@ true true + + true + true + true + true + true true @@ -800,12 +834,6 @@ true true - - true - true - true - true - true true @@ -871,12 +899,6 @@ true true - - true - true - true - true - true true @@ -943,12 +965,6 @@ true true - - true - true - true - true - true true @@ -1285,7 +1301,7 @@ Disabled WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - $(ProjectDir);%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) false true diff --git a/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters b/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters index e2c6b8d5bc..eb91f1d7cc 100644 --- a/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters +++ b/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters @@ -264,9 +264,6 @@ {48c7ee12-704c-42cb-99ea-9a486bb4b57e} - - {e30eda19-95b4-4831-b86a-ee5fae88abd2} - {a4dca8cc-7d1f-4353-b7e1-15eab33e8bd4} @@ -291,6 +288,27 @@ {3c58ba5e-1855-4865-8a9f-c0afd5014e74} + + {09aa885d-9607-4f8c-80d2-43673e541fd0} + + + {afec071b-bc2c-4d32-a5e3-e99273a81a1c} + + + {3e1fc57f-e3c0-4889-a1d8-25145aa535a1} + + + {1e86eefc-51b3-4270-b472-dd3f323e9875} + + + {a8c4a672-6264-45a5-8c22-e3ce2391300e} + + + {94cc3672-688a-46e4-8df0-c3523a521c43} + + + {63c495fa-b6b2-42ed-8ae3-9f3582e76bf5} + @@ -416,9 +434,6 @@ beast_core\diagnostic - - beast_core\diagnostic - beast_core\files @@ -656,9 +671,6 @@ beast_core\time - - beast_core\misc - beast_core\diagnostic @@ -749,9 +761,6 @@ beast - - beast - beast @@ -1170,6 +1179,54 @@ beast\streams + + beast\unit_test + + + beast\unit_test + + + beast\unit_test + + + beast\unit_test + + + beast\unit_test + + + beast + + + beast\unit_test + + + beast + + + beast\unit_test + + + beast\container + + + beast\unit_test + + + beast\unit_test + + + beast\unit_test + + + beast\unit_test + + + beast\chrono + + + beast\unit_test + @@ -1274,9 +1331,6 @@ beast_core\native - - beast_core\diagnostic - beast_core\files @@ -1355,9 +1409,6 @@ beast_asio\basics - - beast_asio\system - beast_asio\tests @@ -1418,9 +1469,6 @@ beast_core\time - - beast_core\misc - beast_core\diagnostic @@ -1499,15 +1547,6 @@ beast_asio\http - - beast\chrono\impl - - - beast\smart_ptr - - - beast\threads\impl - beast\threads\impl @@ -1565,15 +1604,6 @@ beast\insight\impl - - beast\chrono\impl - - - beast\chrono\impl - - - beast\crypto\impl - beast\crypto\impl @@ -1583,9 +1613,6 @@ beast\insight\impl - - beast\net\impl - beast\net\impl @@ -1595,21 +1622,12 @@ beast\net\impl - - beast\utility\impl - beast\chrono - - beast\chrono\impl - beast\container - - beast\container\impl - beast\container\tests @@ -1622,15 +1640,6 @@ beast\asio - - beast\asio\tests - - - beast\asio\tests - - - beast\asio\tests - beast\asio\tests @@ -1640,11 +1649,56 @@ beast\http\impl + + beast\utility\tests + + + beast\container\tests + + + beast\asio\tests + + + beast\asio\tests + + + beast\asio\tests + + + beast\chrono\tests + + + beast\crypto\tests + + + beast\crypto\tests + + + beast\utility\tests + + + beast\threads\tests + + + beast\chrono\tests + + + beast\chrono\impl + + + beast\http\tests + + + beast\net\tests + + + beast\streams\tests + beast\streams - - beast\utility\tests + + beast\threads\tests diff --git a/src/beast/beast/asio/Asio.cpp b/src/beast/beast/asio/Asio.cpp index fb60b4fd36..4f964be9ba 100644 --- a/src/beast/beast/asio/Asio.cpp +++ b/src/beast/beast/asio/Asio.cpp @@ -23,10 +23,10 @@ #include "impl/IPAddressConversion.cpp" -#include "tests/wrap_handler_tests.cpp" -#include "tests/bind_handler_tests.cpp" +#include "tests/wrap_handler.test.cpp" +#include "tests/bind_handler.test.cpp" #include "tests/enable_wait_for_async.test.cpp" -#include "tests/shared_handler_tests.cpp" +#include "tests/shared_handler.test.cpp" #include "abstract_socket.cpp" // TEMPORARY! diff --git a/src/beast/beast/asio/tests/bind_handler_tests.cpp b/src/beast/beast/asio/tests/bind_handler.test.cpp similarity index 78% rename from src/beast/beast/asio/tests/bind_handler_tests.cpp rename to src/beast/beast/asio/tests/bind_handler.test.cpp index 7992e1f106..c9e8d5a7c7 100644 --- a/src/beast/beast/asio/tests/bind_handler_tests.cpp +++ b/src/beast/beast/asio/tests/bind_handler.test.cpp @@ -21,7 +21,7 @@ #include "../../../BeastConfig.h" #endif -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" #include "../bind_handler.h" @@ -30,31 +30,24 @@ namespace beast { namespace asio { -class bind_handler_Tests : public UnitTest +class bind_handler_test : public unit_test::suite { public: static void foo (int) { } - void runTest() + void run() { - beginTestCase ("call"); - - auto f (bind_handler (std::bind (&foo, std::placeholders::_1), + auto f (bind_handler ( + std::bind (&foo, std::placeholders::_1), 42)); - f(); - pass(); } - - bind_handler_Tests() : UnitTest ("bind_handler", "beast", runManual) - { - } }; -static bind_handler_Tests bind_handler_tests; +BEAST_DEFINE_TESTSUITE(bind_handler,asio,beast); } } diff --git a/src/beast/beast/asio/tests/enable_wait_for_async.test.cpp b/src/beast/beast/asio/tests/enable_wait_for_async.test.cpp index 191cbb4b7d..f09f53e442 100644 --- a/src/beast/beast/asio/tests/enable_wait_for_async.test.cpp +++ b/src/beast/beast/asio/tests/enable_wait_for_async.test.cpp @@ -21,7 +21,7 @@ #include "../../../BeastConfig.h" #endif -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" #include "../bind_handler.h" #include "../enable_wait_for_async.h" @@ -30,7 +30,7 @@ namespace beast { -class enable_wait_for_async_Tests : public UnitTest +class enable_wait_for_async_test : public unit_test::suite { public: typedef boost::system::error_code error_code; @@ -89,22 +89,17 @@ public: } }; - beginTestCase ("wait_for_async"); owner o; o(); expect (o.notified); } - void runTest() + void run() { test(); } - - enable_wait_for_async_Tests() : UnitTest ("enable_wait_for_async", "beast") - { - } }; -static enable_wait_for_async_Tests enable_wait_for_async_tests; +BEAST_DEFINE_TESTSUITE(enable_wait_for_async,asio,beast); } diff --git a/src/beast/beast/asio/tests/shared_handler_tests.cpp b/src/beast/beast/asio/tests/shared_handler.test.cpp similarity index 95% rename from src/beast/beast/asio/tests/shared_handler_tests.cpp rename to src/beast/beast/asio/tests/shared_handler.test.cpp index 358ff798bc..686c0f08a9 100644 --- a/src/beast/beast/asio/tests/shared_handler_tests.cpp +++ b/src/beast/beast/asio/tests/shared_handler.test.cpp @@ -21,7 +21,7 @@ #include "../../../BeastConfig.h" #endif -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" #include "../shared_handler.h" @@ -37,7 +37,7 @@ namespace beast { -class shared_handler_Tests : public UnitTest +class shared_handler_test : public unit_test::suite { public: struct test_results @@ -139,10 +139,8 @@ public: async_op (handler); } - void runTest() + void run() { - beginTestCase ("hooks"); - #if ! BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE static_assert (! std::is_constructible < std::function , int&&>::value, @@ -230,12 +228,8 @@ public: expect (r.cont); } } - - shared_handler_Tests() : UnitTest ("shared_handler", "beast") - { - } }; -static shared_handler_Tests shared_handler_tests; +BEAST_DEFINE_TESTSUITE(shared_handler,asio,beast); } diff --git a/src/beast/beast/asio/tests/wrap_handler_tests.cpp b/src/beast/beast/asio/tests/wrap_handler.test.cpp similarity index 90% rename from src/beast/beast/asio/tests/wrap_handler_tests.cpp rename to src/beast/beast/asio/tests/wrap_handler.test.cpp index de368f74f3..be72dbb02c 100644 --- a/src/beast/beast/asio/tests/wrap_handler_tests.cpp +++ b/src/beast/beast/asio/tests/wrap_handler.test.cpp @@ -21,7 +21,7 @@ #include "../../../BeastConfig.h" #endif -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" #include "../wrap_handler.h" @@ -38,7 +38,7 @@ namespace asio { // Displays the order of destruction of parameters in the bind wrapper // -class boost_bind_Tests : public UnitTest +class boost_bind_test : public unit_test::suite { public: struct Result @@ -84,10 +84,8 @@ public: { } - void runTest() + void run() { - beginTestCase ("order"); - { Result r; { @@ -96,7 +94,8 @@ public: Arg (r, "two"), Arg (r, "three")); } - logMessage (std::string ("boost::bind (") + r.text + ")"); + log << + std::string ("boost::bind (") + r.text + ")"; } { @@ -107,22 +106,20 @@ public: Arg (r, "two"), Arg (r, "three")); } - logMessage (std::string ("std::bind (") + r.text + ")"); + + log << + std::string ("std::bind (") + r.text + ")"; } pass(); } - - boost_bind_Tests() : UnitTest ("bind", "beast", runManual) - { - } }; -static boost_bind_Tests boost_bind_tests; +BEAST_DEFINE_TESTSUITE(boost_bind,asio,beast); //------------------------------------------------------------------------------ -class wrap_handler_handler_Tests : public UnitTest +class wrap_handler_test : public unit_test::suite { public: struct test_results @@ -218,10 +215,8 @@ public: return boost_asio_handler_cont_helpers::is_continuation (handler); } - void runTest() + void run() { - beginTestCase ("hooks"); - // Hooks called when using the raw handler { test_results r; @@ -276,13 +271,9 @@ public: expect (f.call); } } - - wrap_handler_handler_Tests() : UnitTest ("wrap_handler", "beast") - { - } }; -static wrap_handler_handler_Tests wrap_handler_handler_tests; +BEAST_DEFINE_TESTSUITE(wrap_handler,asio,beast); } } diff --git a/src/beast/beast/chrono/Chrono.cpp b/src/beast/beast/chrono/Chrono.cpp index 2dae119718..4306d7e800 100644 --- a/src/beast/beast/chrono/Chrono.cpp +++ b/src/beast/beast/chrono/Chrono.cpp @@ -22,10 +22,9 @@ #endif #include "../Config.h" -#include "../../modules/beast_core/beast_core.h" // for UnitTest -#include "impl/abstract_clock.cpp" #include "impl/chrono_io.cpp" -#include "impl/basic_seconds_clock.cpp" - #include "impl/RelativeTime.cpp" + +#include "tests/abstract_clock.test.cpp" +#include "tests/basic_seconds_clock.test.cpp" diff --git a/src/beast/beast/chrono/abstract_clock.h b/src/beast/beast/chrono/abstract_clock.h index 54c19444ca..d085825c5d 100644 --- a/src/beast/beast/chrono/abstract_clock.h +++ b/src/beast/beast/chrono/abstract_clock.h @@ -20,8 +20,6 @@ #ifndef BEAST_CHRONO_ABSTRACT_CLOCK_H_INCLUDED #define BEAST_CHRONO_ABSTRACT_CLOCK_H_INCLUDED -#include "chrono_io.h" - #include #include @@ -75,9 +73,10 @@ public: /** Returns the current time. */ virtual time_point now () const = 0; +#if 0 /** Convert the specified time point to a string. */ /** @{ */ - virtual std::string to_string (time_point const& tp) const = 0; + //virtual std::string to_string (time_point const& tp) const = 0; template std::string to_string ( @@ -87,6 +86,7 @@ public: std::chrono::time_point_cast (tp)); } /** @} */ +#endif /** Returning elapsed ticks since the epoch. */ rep elapsed () const @@ -123,6 +123,7 @@ struct abstract_clock_wrapper : public basic_abstract_clock_wrapper { // generic conversion displays the duration + /* std::string to_string (typename basic_abstract_clock_wrapper < TrivialClock, Duration>::time_point const& tp) const { @@ -130,6 +131,7 @@ struct abstract_clock_wrapper ss << tp.time_since_epoch(); return ss.str (); } + */ }; /* diff --git a/src/beast/beast/chrono/impl/basic_seconds_clock.cpp b/src/beast/beast/chrono/abstract_clock_io.h similarity index 69% rename from src/beast/beast/chrono/impl/basic_seconds_clock.cpp rename to src/beast/beast/chrono/abstract_clock_io.h index 6c12ac1956..bd2ad9931e 100644 --- a/src/beast/beast/chrono/impl/basic_seconds_clock.cpp +++ b/src/beast/beast/chrono/abstract_clock_io.h @@ -17,30 +17,21 @@ */ //============================================================================== -#include "../basic_seconds_clock.h" +#ifndef BEAST_CHRONO_ABSTRACT_CLOCK_IO_H_INCLUDED +#define BEAST_CHRONO_ABSTRACT_CLOCK_IO_H_INCLUDED -#include "../../Config.h" -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "chrono_io.h" namespace beast { -class basic_seconds_clock_Tests : public UnitTest +template +std::basic_ostream & +operator<< (std::basic_ostream & os, + std::chrono::time_point , Duration> const& tp) { -public: - void runTest () - { - beginTestCase ("now"); - - basic_seconds_clock ::now (); - - pass (); - } - - basic_seconds_clock_Tests() : UnitTest("basic_seconds_clock", "beast") - { - } -}; - -static basic_seconds_clock_Tests basic_seconds_clock_tests; + return os << tp.time_since_epoch() << " since epoch"; +} } + +#endif diff --git a/src/beast/beast/chrono/manual_clock.h b/src/beast/beast/chrono/manual_clock.h index ad373725c9..8342c7d4f0 100644 --- a/src/beast/beast/chrono/manual_clock.h +++ b/src/beast/beast/chrono/manual_clock.h @@ -53,12 +53,14 @@ public: return m_now; } +#if 0 std::string to_string (time_point const& tp) const { std::stringstream ss; ss << tp.time_since_epoch() << " from start"; return ss.str (); } +#endif /** Set the current time of the manual clock. Precondition: diff --git a/src/beast/beast/chrono/impl/abstract_clock.cpp b/src/beast/beast/chrono/tests/abstract_clock.test.cpp similarity index 74% rename from src/beast/beast/chrono/impl/abstract_clock.cpp rename to src/beast/beast/chrono/tests/abstract_clock.test.cpp index 11cc561412..7cf098d1b0 100644 --- a/src/beast/beast/chrono/impl/abstract_clock.cpp +++ b/src/beast/beast/chrono/tests/abstract_clock.test.cpp @@ -18,16 +18,18 @@ //============================================================================== #include "../abstract_clock.h" +#include "../abstract_clock_io.h" #include "../manual_clock.h" -#include +#include "../../unit_test/suite.h" -#include #include +#include +#include namespace beast { -class abstract_clock_tests : public UnitTest +class abstract_clock_test : public unit_test::suite { public: void test (abstract_clock & c) @@ -40,10 +42,10 @@ public: std::stringstream ss; ss << - "t1= " << c.to_string (t1) << - ", t2= " << c.to_string (t2) << + "t1= " << t1.time_since_epoch() << + ", t2= " << t2.time_since_epoch() << ", elapsed= " << (t2 - t1); - logMessage (ss.str()); + log << ss.str(); } } @@ -54,45 +56,38 @@ public: std::stringstream ss; - ss << "now() = " << c.to_string (c.now ()) << std::endl; + ss << "now() = " << c.now () << std::endl; c.set (clock_type::time_point (std::chrono::seconds (1))); - ss << "now() = " << c.to_string (c.now ()) << std::endl; + ss << "now() = " << c.now () << std::endl; c.set (clock_type::time_point (std::chrono::seconds (2))); - ss << "now() = " << c.to_string (c.now ()) << std::endl; + ss << "now() = " << c.now () << std::endl; - logMessage (ss.str()); + log << ss.str(); } - void runTest () + void run () { - beginTestCase ("Syntax"); - - logMessage ("steady_clock"); + log << "steady_clock"; test (get_abstract_clock ()); - logMessage ("system_clock"); + log << "system_clock"; test (get_abstract_clock ()); - logMessage ("high_resolution_clock"); + log << "high_resolution_clock"; test (get_abstract_clock ()); - logMessage ("manual_clock"); + log << "manual_clock"; test_manual (); pass (); } - - abstract_clock_tests () - : UnitTest ("abstract_clock", "beast", runManual) - { - } }; -static abstract_clock_tests abstract_clock_tests_; +BEAST_DEFINE_TESTSUITE(abstract_clock,chrono,beast); } diff --git a/src/beast/beast/smart_ptr/SmartPtr.cpp b/src/beast/beast/chrono/tests/basic_seconds_clock.test.cpp similarity index 75% rename from src/beast/beast/smart_ptr/SmartPtr.cpp rename to src/beast/beast/chrono/tests/basic_seconds_clock.test.cpp index f7f123567e..e8e9c58df8 100644 --- a/src/beast/beast/smart_ptr/SmartPtr.cpp +++ b/src/beast/beast/chrono/tests/basic_seconds_clock.test.cpp @@ -17,15 +17,24 @@ */ //============================================================================== -#if BEAST_INCLUDE_BEASTCONFIG -#include "../../BeastConfig.h" -#endif +#include "../../unit_test/suite.h" -#include "../Config.h" +#include "../basic_seconds_clock.h" -#include "ContainerDeletePolicy.h" -#include "ScopedPointer.h" -#include "SharedObject.h" -#include "SharedPtr.h" +namespace beast { -#include "../../modules/beast_core/beast_core.h" // for UnitTest +class basic_seconds_clock_test : public unit_test::suite +{ +public: + void + run() + { + basic_seconds_clock < + std::chrono::steady_clock>::now (); + pass (); + } +}; + +BEAST_DEFINE_TESTSUITE(basic_seconds_clock,chrono,beast); + +} diff --git a/src/beast/beast/container/Container.cpp b/src/beast/beast/container/Container.cpp index 1cf70c77f2..c11ccfa882 100644 --- a/src/beast/beast/container/Container.cpp +++ b/src/beast/beast/container/Container.cpp @@ -21,7 +21,5 @@ #include "../../BeastConfig.h" #endif -#include "impl/aged_associative_container.cpp" - +#include "tests/aged_associative_container.test.cpp" #include "tests/buffer_view.test.cpp" - diff --git a/src/beast/beast/container/buffer_view.h b/src/beast/beast/container/buffer_view.h index f9e2ddeef0..1336b69e3c 100644 --- a/src/beast/beast/container/buffer_view.h +++ b/src/beast/beast/container/buffer_view.h @@ -22,6 +22,7 @@ #include "../Config.h" +#include #include "../cxx14/algorithm.h" // #include #include diff --git a/src/beast/beast/container/detail/aged_ordered_container.h b/src/beast/beast/container/detail/aged_ordered_container.h index dd151b317a..dd77b28e7d 100644 --- a/src/beast/beast/container/detail/aged_ordered_container.h +++ b/src/beast/beast/container/detail/aged_ordered_container.h @@ -23,9 +23,6 @@ #include "aged_container_iterator.h" #include "aged_associative_container.h" -#include "../../cxx14/algorithm.h" -#include "../../cxx14/type_traits.h" - #include "../aged_container.h" #include "../../chrono/abstract_clock.h" @@ -34,10 +31,12 @@ #include #include +#include "../../cxx14/algorithm.h" // #include #include #include #include +#include "../../cxx14/type_traits.h" // #include namespace beast { diff --git a/src/beast/beast/container/detail/aged_unordered_container.h b/src/beast/beast/container/detail/aged_unordered_container.h index 2eac2783ad..5a1054fecc 100644 --- a/src/beast/beast/container/detail/aged_unordered_container.h +++ b/src/beast/beast/container/detail/aged_unordered_container.h @@ -31,12 +31,12 @@ #include #include -#include "../../cxx14/algorithm.h" -#include "../../cxx14/type_traits.h" +#include "../../cxx14/algorithm.h" // #include #include #include #include +#include "../../cxx14/type_traits.h" // #include /* diff --git a/src/beast/beast/container/impl/aged_associative_container.cpp b/src/beast/beast/container/tests/aged_associative_container.test.cpp similarity index 86% rename from src/beast/beast/container/impl/aged_associative_container.cpp rename to src/beast/beast/container/tests/aged_associative_container.test.cpp index c1671ba7f0..7c410fcf8a 100644 --- a/src/beast/beast/container/impl/aged_associative_container.cpp +++ b/src/beast/beast/container/tests/aged_associative_container.test.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -#include "../../../modules/beast_core/beast_core.h" // for UnitTest #include "../../chrono/manual_clock.h" +#include "../../unit_test/suite.h" + #include "../aged_set.h" #include "../aged_map.h" #include "../aged_multiset.h" @@ -28,6 +29,9 @@ #include "../aged_unordered_multiset.h" #include "../aged_unordered_multimap.h" +#include +#include + #ifndef BEAST_AGED_UNORDERED_NO_ALLOC_DEFAULTCTOR # ifdef _MSC_VER # define BEAST_AGED_UNORDERED_NO_ALLOC_DEFAULTCTOR 0 @@ -46,7 +50,7 @@ namespace beast { -class aged_associative_container_TestsBase : public UnitTest +class aged_associative_container_test_base : public unit_test::suite { public: template @@ -392,56 +396,6 @@ public: //-------------------------------------------------------------------------- - // Compile time checks - // - void checkAliases () - { - typedef std::string Key; - typedef int T; - - static_assert (std::is_same < - aged_set , - detail::aged_ordered_container >::value, - "bad alias: aged_set"); - - static_assert (std::is_same < - aged_multiset , - detail::aged_ordered_container >::value, - "bad alias: aged_multiset"); - - static_assert (std::is_same < - aged_map , - detail::aged_ordered_container >::value, - "bad alias: aged_map"); - - static_assert (std::is_same < - aged_multimap , - detail::aged_ordered_container >::value, - "bad alias: aged_multimap"); - - static_assert (std::is_same < - aged_unordered_set , - detail::aged_unordered_container >::value, - "bad alias: aged_unordered_set"); - - static_assert (std::is_same < - aged_unordered_multiset , - detail::aged_unordered_container >::value, - "bad alias: aged_unordered_multiset"); - - static_assert (std::is_same < - aged_unordered_map , - detail::aged_unordered_container >::value, - "bad alias: aged_unordered_map"); - - static_assert (std::is_same < - aged_unordered_multimap , - detail::aged_unordered_container >::value, - "bad alias: aged_unordered_multimap"); - } - - //-------------------------------------------------------------------------- - template < class Container, class Values @@ -603,11 +557,6 @@ public: template void testMaybeUnordered(); - - aged_associative_container_TestsBase () : UnitTest ( - "aged_associative_container", "beast") - { - } }; //------------------------------------------------------------------------------ @@ -620,7 +569,7 @@ template < > typename std::enable_if < Container::is_map::value && ! Container::is_multi::value>::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkMapContents (Container& c, Values const& v) { if (v.empty()) @@ -651,7 +600,7 @@ template < > typename std::enable_if < std::remove_reference ::type::is_unordered::value>::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkUnorderedContentsRefRef (C&& c, Values const& v) { typedef typename std::remove_reference ::type Cont; @@ -685,7 +634,7 @@ checkUnorderedContentsRefRef (C&& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkContentsRefRef (C&& c, Values const& v) { typedef typename std::remove_reference ::type Cont; @@ -715,7 +664,7 @@ checkContentsRefRef (C&& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkContents (Cont& c, Values const& v) { checkContentsRefRef (c, v); @@ -725,7 +674,7 @@ checkContents (Cont& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkContents (Cont& c) { typedef TestTraits < @@ -746,7 +695,7 @@ checkContents (Cont& c) // ordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testConstructEmpty () { typedef TestTraits Traits; @@ -760,7 +709,8 @@ testConstructEmpty () typedef typename Traits::MyAlloc MyAlloc; typename Traits::Clock clock; - beginTestCase (Traits::name() + " empty"); + //testcase (Traits::name() + " empty"); + testcase ("empty"); { typename Traits::template Cont c ( @@ -790,7 +740,7 @@ testConstructEmpty () // unordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testConstructEmpty () { typedef TestTraits Traits; @@ -806,8 +756,8 @@ testConstructEmpty () typedef typename Traits::MyAlloc MyAlloc; typename Traits::Clock clock; - beginTestCase (Traits::name() + " empty"); - + //testcase (Traits::name() + " empty"); + testcase ("empty"); { typename Traits::template Cont c ( clock); @@ -860,7 +810,7 @@ testConstructEmpty () // ordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testConstructRange () { typedef TestTraits Traits; @@ -875,7 +825,8 @@ testConstructRange () typename Traits::Clock clock; auto const v (Traits::values()); - beginTestCase (Traits::name() + " range"); + //testcase (Traits::name() + " range"); + testcase ("range"); { typename Traits::template Cont c ( @@ -922,7 +873,7 @@ testConstructRange () // unordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testConstructRange () { typedef TestTraits Traits; @@ -939,7 +890,8 @@ testConstructRange () typename Traits::Clock clock; auto const v (Traits::values()); - beginTestCase (Traits::name() + " range"); + //testcase (Traits::name() + " range"); + testcase ("range"); { typename Traits::template Cont c ( @@ -1001,7 +953,7 @@ testConstructRange () // ordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testConstructInitList () { typedef TestTraits Traits; @@ -1015,7 +967,8 @@ testConstructInitList () typedef typename Traits::MyAlloc MyAlloc; typename Traits::Clock clock; - beginTestCase (Traits::name() + " init-list"); + //testcase (Traits::name() + " init-list"); + testcase ("init-list"); // VFALCO TODO @@ -1025,7 +978,7 @@ testConstructInitList () // unordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testConstructInitList () { typedef TestTraits Traits; @@ -1041,7 +994,9 @@ testConstructInitList () typedef typename Traits::MyAlloc MyAlloc; typename Traits::Clock clock; - beginTestCase (Traits::name() + " init-list"); + //testcase (Traits::name() + " init-list"); + testcase ("init-list"); + // VFALCO TODO pass(); } @@ -1054,7 +1009,7 @@ testConstructInitList () template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testCopyMove () { typedef TestTraits Traits; @@ -1063,7 +1018,8 @@ testCopyMove () typename Traits::Clock clock; auto const v (Traits::values()); - beginTestCase (Traits::name() + " copy/move"); + //testcase (Traits::name() + " copy/move"); + testcase ("copy/move"); // copy @@ -1136,7 +1092,7 @@ testCopyMove () template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkInsertCopy (Container& c, Values const& v) { for (auto const& e : v) @@ -1146,7 +1102,7 @@ checkInsertCopy (Container& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkInsertMove (Container& c, Values const& v) { Values v2 (v); @@ -1157,7 +1113,7 @@ checkInsertMove (Container& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkInsertHintCopy (Container& c, Values const& v) { for (auto const& e : v) @@ -1167,7 +1123,7 @@ checkInsertHintCopy (Container& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkInsertHintMove (Container& c, Values const& v) { Values v2 (v); @@ -1178,7 +1134,7 @@ checkInsertHintMove (Container& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkEmplace (Container& c, Values const& v) { for (auto const& e : v) @@ -1188,7 +1144,7 @@ checkEmplace (Container& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: checkEmplaceHint (Container& c, Values const& v) { for (auto const& e : v) @@ -1198,7 +1154,7 @@ checkEmplaceHint (Container& c, Values const& v) template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testModifiers() { typedef TestTraits Traits; @@ -1206,7 +1162,8 @@ testModifiers() auto const v (Traits::values()); auto const l (make_list (v)); - beginTestCase (Traits::name() + " modify"); + //testcase (Traits::name() + " modify"); + testcase ("modify"); { typename Traits::template Cont <> c (clock); @@ -1257,7 +1214,7 @@ testModifiers() template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testChronological () { typedef TestTraits Traits; @@ -1265,7 +1222,8 @@ testChronological () typename Traits::Clock clock; auto const v (Traits::values()); - beginTestCase (Traits::name() + " chronological"); + //testcase (Traits::name() + " chronological"); + testcase ("chronological"); typename Traits::template Cont <> c ( v.begin(), v.end(), clock); @@ -1297,14 +1255,15 @@ testChronological () // map, unordered_map template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testArrayCreate() { typedef TestTraits Traits; typename Traits::Clock clock; auto v (Traits::values()); - beginTestCase (Traits::name() + " array create"); + //testcase (Traits::name() + " array create"); + testcase ("array create"); { // Copy construct key @@ -1332,7 +1291,7 @@ testArrayCreate() // ordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testCompare () { typedef TestTraits Traits; @@ -1340,7 +1299,8 @@ testCompare () typename Traits::Clock clock; auto const v (Traits::values()); - beginTestCase (Traits::name() + " array create"); + //testcase (Traits::name() + " array create"); + testcase ("array create"); typename Traits::template Cont <> c1 ( v.begin(), v.end(), clock); @@ -1366,13 +1326,14 @@ testCompare () // ordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testObservers() { typedef TestTraits Traits; typename Traits::Clock clock; - beginTestCase (Traits::name() + " observers"); + //testcase (Traits::name() + " observers"); + testcase ("observers"); typename Traits::template Cont <> c (clock); c.key_comp(); @@ -1384,13 +1345,14 @@ testObservers() // unordered template typename std::enable_if ::type -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testObservers() { typedef TestTraits Traits; typename Traits::Clock clock; - beginTestCase (Traits::name() + " observers"); + //testcase (Traits::name() + " observers"); + testcase ("observers"); typename Traits::template Cont <> c (clock); c.hash_function(); @@ -1407,7 +1369,7 @@ testObservers() template void -aged_associative_container_TestsBase:: +aged_associative_container_test_base:: testMaybeUnorderedMultiMap () { typedef TestTraits Traits; @@ -1423,38 +1385,133 @@ testMaybeUnorderedMultiMap () testObservers (); } -template -void -aged_associative_container_TestsBase:: -testMaybeUnorderedMulti() -{ - testMaybeUnorderedMultiMap (); - testMaybeUnorderedMultiMap (); -} - -template -void -aged_associative_container_TestsBase:: -testMaybeUnordered() -{ - testMaybeUnorderedMulti (); - testMaybeUnorderedMulti (); -} - //------------------------------------------------------------------------------ -class aged_associative_container_Tests : - public aged_associative_container_TestsBase +class aged_set_test : public aged_associative_container_test_base { public: - void runTest () + // Compile time checks + + typedef std::string Key; + typedef int T; + + static_assert (std::is_same < + aged_set , + detail::aged_ordered_container >::value, + "bad alias: aged_set"); + + static_assert (std::is_same < + aged_multiset , + detail::aged_ordered_container >::value, + "bad alias: aged_multiset"); + + static_assert (std::is_same < + aged_map , + detail::aged_ordered_container >::value, + "bad alias: aged_map"); + + static_assert (std::is_same < + aged_multimap , + detail::aged_ordered_container >::value, + "bad alias: aged_multimap"); + + static_assert (std::is_same < + aged_unordered_set , + detail::aged_unordered_container >::value, + "bad alias: aged_unordered_set"); + + static_assert (std::is_same < + aged_unordered_multiset , + detail::aged_unordered_container >::value, + "bad alias: aged_unordered_multiset"); + + static_assert (std::is_same < + aged_unordered_map , + detail::aged_unordered_container >::value, + "bad alias: aged_unordered_map"); + + static_assert (std::is_same < + aged_unordered_multimap , + detail::aged_unordered_container >::value, + "bad alias: aged_unordered_multimap"); + + void run () { - checkAliases (); - testMaybeUnordered (); - testMaybeUnordered (); + testMaybeUnorderedMultiMap (); } }; -static aged_associative_container_Tests aged_associative_container_tests; +class aged_map_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + +class aged_multiset_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + +class aged_multimap_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + + +class aged_unordered_set_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + +class aged_unordered_map_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + +class aged_unordered_multiset_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + +class aged_unordered_multimap_test : public aged_associative_container_test_base +{ +public: + void run () + { + testMaybeUnorderedMultiMap (); + } +}; + +BEAST_DEFINE_TESTSUITE(aged_set,container,beast); +BEAST_DEFINE_TESTSUITE(aged_map,container,beast); +BEAST_DEFINE_TESTSUITE(aged_multiset,container,beast); +BEAST_DEFINE_TESTSUITE(aged_multimap,container,beast); +BEAST_DEFINE_TESTSUITE(aged_unordered_set,container,beast); +BEAST_DEFINE_TESTSUITE(aged_unordered_map,container,beast); +BEAST_DEFINE_TESTSUITE(aged_unordered_multiset,container,beast); +BEAST_DEFINE_TESTSUITE(aged_unordered_multimap,container,beast); } diff --git a/src/beast/beast/container/tests/buffer_view.test.cpp b/src/beast/beast/container/tests/buffer_view.test.cpp index 3bc2172834..743430cb4c 100644 --- a/src/beast/beast/container/tests/buffer_view.test.cpp +++ b/src/beast/beast/container/tests/buffer_view.test.cpp @@ -17,14 +17,15 @@ */ //============================================================================== -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" + #include "../buffer_view.h" #include "../../cxx14/algorithm.h" // namespace beast { -class buffer_view_Tests : public UnitTest +class buffer_view_test : public unit_test::suite { public: // Returns `true` if the iterator distance matches the size @@ -153,7 +154,7 @@ public: // Test empty containers void testEmpty() { - beginTestCase ("empty"); + testcase ("empty"); buffer_view v1; checkEmpty (v1); @@ -239,11 +240,11 @@ public: void testConstruct() { - beginTestCase ("std::vector "); + testcase ("std::vector "); testConstruct ( std::vector ({'h', 'e', 'l', 'l', 'o'})); - beginTestCase ("std::string "); + testcase ("std::string "); testConstruct ( std::basic_string ("hello")); } @@ -252,7 +253,7 @@ public: void testCoerce() { - beginTestCase ("coerce"); + testcase ("coerce"); std::string const s ("hello"); const_buffer_view v (s); @@ -264,7 +265,7 @@ public: void testAssign() { - beginTestCase ("testAssign"); + testcase ("testAssign"); std::vector v1({1, 2, 3}); buffer_view r1(v1); std::vector v2({4, 5, 6, 7}); @@ -305,19 +306,15 @@ public: static_assert (std::is_nothrow_move_assignable < buffer_view >::value, ""); - void runTest() + void run() { testEmpty(); testConstruct(); testCoerce(); testAssign(); } - - buffer_view_Tests() : UnitTest ("buffer_view", "beast") - { - } }; -static buffer_view_Tests buffer_view_tests; +BEAST_DEFINE_TESTSUITE(buffer_view,container,beast); } diff --git a/src/beast/beast/crypto/Crypto.cpp b/src/beast/beast/crypto/Crypto.cpp index f4c1eb1cbb..327df57d50 100644 --- a/src/beast/beast/crypto/Crypto.cpp +++ b/src/beast/beast/crypto/Crypto.cpp @@ -21,9 +21,9 @@ #include "../../BeastConfig.h" #endif -#include "../../modules/beast_core/beast_core.h" // for UnitTest - -#include "impl/BinaryEncoding.cpp" #include "impl/MurmurHash.cpp" #include "impl/Sha256.cpp" #include "impl/UnsignedInteger.cpp" + +#include "tests/BinaryEncoding.test.cpp" +#include "tests/UnsignedInteger.test.cpp" diff --git a/src/beast/beast/crypto/UnsignedInteger.h b/src/beast/beast/crypto/UnsignedInteger.h index b276e12868..a810b60b3a 100644 --- a/src/beast/beast/crypto/UnsignedInteger.h +++ b/src/beast/beast/crypto/UnsignedInteger.h @@ -23,6 +23,8 @@ #include "UnsignedIntegerCalc.h" #include "MurmurHash.h" +#include "../../modules/beast_core/beast_core.h" // FIX ASAP + #include #include diff --git a/src/beast/beast/crypto/UnsignedIntegerCalc.h b/src/beast/beast/crypto/UnsignedIntegerCalc.h index ef1d48120f..2f48049317 100644 --- a/src/beast/beast/crypto/UnsignedIntegerCalc.h +++ b/src/beast/beast/crypto/UnsignedIntegerCalc.h @@ -20,6 +20,7 @@ #ifndef BEAST_CRYPTO_UNSIGNEDINTEGERCALC_H_INCLUDED #define BEAST_CRYPTO_UNSIGNEDINTEGERCALC_H_INCLUDED +#include #include namespace beast { @@ -155,7 +156,7 @@ public: */ UnsignedIntegerCalc& operator= (UnsignedIntegerCalc const& other) { - bassert (other.size() <= size()); + assert (other.size() <= size()); size_type n (size()); UInt* dest (m_values + size()); for (; n-- > other.size();) @@ -335,7 +336,7 @@ public: } *lhs++ = UInt (part); } - bassert (carry == 0); // overflow + assert (carry == 0); // overflow return *this; } @@ -359,7 +360,7 @@ public: carry = part >> numBits; *lhs = UInt (part & maxUInt); } - bassert (carry == 0); // overflow + assert (carry == 0); // overflow return *this; } diff --git a/src/beast/beast/crypto/impl/UnsignedInteger.cpp b/src/beast/beast/crypto/impl/UnsignedInteger.cpp index 2cd246257c..a35bb2d5f0 100644 --- a/src/beast/beast/crypto/impl/UnsignedInteger.cpp +++ b/src/beast/beast/crypto/impl/UnsignedInteger.cpp @@ -5,8 +5,7 @@ Portions are Copyright (c) 2013 the authors listed at the following URL, and/or the authors of referenced articles or incorporated external code: - http://en.literateprograms.org/Arbitrary-precision_integer_arithmetic_(C)?action=history&offset=20100923155004 - + http://en.literateprograms.org/Arbitrary-precision_integer_arithmetic_(C) 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. @@ -23,6 +22,8 @@ #include "../UnsignedInteger.h" +#include "../../unit_test/suite.h" + namespace beast { namespace multiprecsion { @@ -31,7 +32,7 @@ namespace multiprecsion { /* Copyright (c) 2013 the authors listed at the following URL, and/or the authors of referenced articles or incorporated external code: - http://en.literateprograms.org/Arbitrary-precision_integer_arithmetic_(C)?action=history&offset=20100923155004 + http://en.literateprograms.org/Arbitrary-precision_integer_arithmetic_(C) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -342,63 +343,4 @@ char* integer_to_string(integer x) { } -//------------------------------------------------------------------------------ - -class UnsignedIntegerTests : public UnitTest -{ -public: - UnsignedIntegerTests () : UnitTest ("UnsignedInteger", "beast") - { - } - - template - void runTest () - { - typedef UnsignedInteger UInt; - - String s; - - s << "Bytes=" << String(Bytes); - - beginTestCase (s); - - UInt zero; - zero.fill (0); - expect (zero.isZero (), "should be zero"); - expect (! zero.isNotZero (), "sould not be non-zero"); - - UInt one (UInt::createFromInteger (1U)); - expect (one == UInt::createFromInteger (1U), "should be equal"); - - expect (! one.isZero (), "should not be zero"); - expect (one.isNotZero (), "sould be non-zero"); - - expect (zero < one, "should be less"); - expect (one > zero, "should be greater"); - expect (zero >= zero, "should be less than or equal"); - expect (one <= one, "should be less than or equal"); - - expect (zero == zero, "should be equal"); - expect (zero != one, "should not be equal"); - - expect (zero == UInt::createFromInteger (0U), "should be zero"); - expect (one == UInt::createFromInteger (1U), "should be one"); - expect (one != UInt::createFromInteger (2U), "should not be two"); - - UInt largest = UInt::createFilled (0xff); - - expect (largest > zero && largest > one, "should be greater"); - } - - void runTest() - { - runTest <16> (); - runTest <33> (); - } - -private: -}; - -static UnsignedIntegerTests unsignedIntegerTests; - } diff --git a/src/beast/beast/crypto/impl/BinaryEncoding.cpp b/src/beast/beast/crypto/tests/BinaryEncoding.test.cpp similarity index 93% rename from src/beast/beast/crypto/impl/BinaryEncoding.cpp rename to src/beast/beast/crypto/tests/BinaryEncoding.test.cpp index dfdca1bcd6..f66185f589 100644 --- a/src/beast/beast/crypto/impl/BinaryEncoding.cpp +++ b/src/beast/beast/crypto/tests/BinaryEncoding.test.cpp @@ -20,6 +20,8 @@ #include "../BinaryEncoding.h" #include "../UnsignedInteger.h" +#include "../../unit_test/suite.h" + #include #include @@ -276,19 +278,20 @@ public: //------------------------------------------------------------------------------ -class BinaryEncodingTests : public UnitTest +class BinaryEncoding_test : public unit_test::suite { public: // This is a baseline for the other tests template void testBase16 () { - beginTestCase ("base16"); + Random r; + testcase ("base16"); for (int i = 0; i < 50; ++i) { typedef UnsignedInteger UInt; UInt v0; - random().fillBitsRandomly (v0.begin(), UInt::size); + r.fillBitsRandomly (v0.begin(), UInt::size); std::string const good (HexEncoding::encode (v0)); UInt v1; @@ -299,8 +302,8 @@ public: Base16Conversion c; std::string const check (BinaryEncoding::encode (v0, c)); - if (! expect (good == check)) - logMessage (String ("expected ") + good + " but got " + check); + expect (good == check, + std::string ("expected ") + good + " but got " + check); } } } @@ -313,7 +316,8 @@ public: typedef UnsignedInteger UInt; UInt v1 (vin.c_str()); std::string const s1 (BinaryEncoding::encode (v1, c)); - logMessage (vout + " to " + s1); + log << + vout + " to " + s1; expect (vout == s1); UInt v2; @@ -321,14 +325,14 @@ public: if (expect (success)) { std::string const s2 (BinaryEncoding::encode (v2, c)); - logMessage (vin + " to " + s2); - //expect (vin == v2); + log << + vin + " to " + s2; } } void testBase64 () { - beginTestCase ("Base64"); + testcase ("Base64"); // input (uint) std::string const vin [] = { @@ -354,12 +358,16 @@ public: { typedef UnsignedInteger UInt; - beginTestCase (String (c.name()) + " <" + String::fromNumber (Bytes) + ">"); + std::stringstream ss; + ss << + c.name() << " <" << Bytes << ">"; + testcase (ss.str()); + Random r; for (int i = 0; i < 50; ++i) { UInt v1; - random().fillBitsRandomly (v1.begin(), UInt::size); + r.fillBitsRandomly (v1.begin(), UInt::size); std::string const s1 (BinaryEncoding::encode (v1, c)); UInt v2; @@ -369,7 +377,7 @@ public: } } - void runTest () + void run () { testBase16 <10> (); @@ -394,12 +402,8 @@ public: testEncode (); #endif } - - BinaryEncodingTests () : UnitTest ("BinaryEncoding", "beast", runManual) - { - } }; -static BinaryEncodingTests BinaryEncodingTests; +BEAST_DEFINE_TESTSUITE_MANUAL(BinaryEncoding,crypto,beast); } diff --git a/src/beast/beast/crypto/tests/UnsignedInteger.test.cpp b/src/beast/beast/crypto/tests/UnsignedInteger.test.cpp new file mode 100644 index 0000000000..2263e61e94 --- /dev/null +++ b/src/beast/beast/crypto/tests/UnsignedInteger.test.cpp @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Portions are Copyright (c) 2013 the authors listed at the following URL, + and/or the authors of referenced articles or incorporated external code: + http://en.literateprograms.org/Arbitrary-precision_integer_arithmetic_(C) + 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. +*/ +//============================================================================== + +#include "../UnsignedInteger.h" + +#include "../../unit_test/suite.h" + +namespace beast { + +class UnsignedInteger_test : public unit_test::suite +{ +public: + template + void test () + { + typedef UnsignedInteger UInt; + + std::stringstream ss; + ss << + "bytes=" << Bytes; + testcase (ss.str()); + + UInt zero; + zero.fill (0); + expect (zero.isZero (), "should be zero"); + expect (! zero.isNotZero (), "sould not be non-zero"); + + UInt one (UInt::createFromInteger (1U)); + expect (one == UInt::createFromInteger (1U), "should be equal"); + + expect (! one.isZero (), "should not be zero"); + expect (one.isNotZero (), "sould be non-zero"); + + expect (zero < one, "should be less"); + expect (one > zero, "should be greater"); + expect (zero >= zero, "should be less than or equal"); + expect (one <= one, "should be less than or equal"); + + expect (zero == zero, "should be equal"); + expect (zero != one, "should not be equal"); + + expect (zero == UInt::createFromInteger (0U), "should be zero"); + expect (one == UInt::createFromInteger (1U), "should be one"); + expect (one != UInt::createFromInteger (2U), "should not be two"); + + UInt largest = UInt::createFilled (0xff); + + expect (largest > zero && largest > one, "should be greater"); + } + + void run() + { + test <16> (); + test <33> (); + } + +private: +}; + +BEAST_DEFINE_TESTSUITE(UnsignedInteger,crypto,beast); + +} diff --git a/src/beast/beast/cxx14/tests/integer_sequence.test.cpp b/src/beast/beast/cxx14/tests/integer_sequence.test.cpp index 5846cfe6a7..f7360baa28 100644 --- a/src/beast/beast/cxx14/tests/integer_sequence.test.cpp +++ b/src/beast/beast/cxx14/tests/integer_sequence.test.cpp @@ -23,12 +23,12 @@ #include "../utility.h" -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" namespace beast { namespace asio { -class integer_sequence_Tests : public UnitTest +class integer_sequence_test : public unit_test::suite { public: template @@ -41,10 +41,8 @@ public: return std::make_tuple (std::get (t)...); } - void runTest() + void run() { - beginTestCase ("call"); - // Code from // http://llvm.org/svn/llvm-project/libcxx/trunk/test/utilities/intseq/intseq.general/integer_seq.pass.cpp @@ -103,13 +101,9 @@ public: expect ( tsizemix == std::make_tuple ( 11, 11, 12, 13, 15 )); pass(); } - - integer_sequence_Tests() : UnitTest ("integer_sequence", "beast") - { - } }; -static integer_sequence_Tests integer_sequence_tests; +BEAST_DEFINE_TESTSUITE(integer_sequence,cxx14,beast); } } diff --git a/src/beast/beast/http/HTTP.cpp b/src/beast/beast/http/HTTP.cpp index 25a2286475..c8c010e94c 100644 --- a/src/beast/beast/http/HTTP.cpp +++ b/src/beast/beast/http/HTTP.cpp @@ -25,3 +25,5 @@ #include "impl/ParsedURL.cpp" #include "impl/joyent_parser.cpp" #include "impl/raw_parser.cpp" + +#include "tests/ParsedURL.test.cpp" diff --git a/src/beast/beast/http/impl/ParsedURL.cpp b/src/beast/beast/http/impl/ParsedURL.cpp index d1b97dd1e6..f889f39830 100644 --- a/src/beast/beast/http/impl/ParsedURL.cpp +++ b/src/beast/beast/http/impl/ParsedURL.cpp @@ -18,11 +18,12 @@ //============================================================================== #include "../ParsedURL.h" - -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../strings/String.h" #include "joyent_parser.h" +#include + namespace beast { ParsedURL::ParsedURL () @@ -146,35 +147,4 @@ URL ParsedURL::url () const return m_url; } -//------------------------------------------------------------------------------ - -class ParsedURLTests : public UnitTest -{ -public: - void checkURL (String const& url) - { - ParsedURL result (url); - expect (result.error () == 0); - expect (result.url ().toString () == url); - } - - void testURL () - { - beginTestCase ("parse URL"); - - checkURL ("http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference.html"); - } - - void runTest () - { - testURL (); - } - - ParsedURLTests () : UnitTest ("ParsedURL", "beast", runManual) - { - } -}; - -static ParsedURLTests parsedURLTests; - } diff --git a/src/beast/beast/http/tests/ParsedURL.test.cpp b/src/beast/beast/http/tests/ParsedURL.test.cpp new file mode 100644 index 0000000000..ca236210de --- /dev/null +++ b/src/beast/beast/http/tests/ParsedURL.test.cpp @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +/* + 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. +*/ +//============================================================================== + +#include "../ParsedURL.h" + +#include "../../unit_test/suite.h" + +#include "../impl/joyent_parser.h" + +namespace beast { + +class ParsedURL_test : public unit_test::suite +{ +public: + void checkURL (String const& url) + { + ParsedURL result (url); + expect (result.error () == 0); + expect (result.url ().toString () == url); + } + + void testURL () + { + checkURL ("http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference.html"); + } + + void run () + { + testURL (); + } +}; + +BEAST_DEFINE_TESTSUITE(ParsedURL,http,beast); + +} diff --git a/src/beast/beast/insight/BaseImpl.h b/src/beast/beast/insight/BaseImpl.h index 86953efe0d..6c3d7821d3 100644 --- a/src/beast/beast/insight/BaseImpl.h +++ b/src/beast/beast/insight/BaseImpl.h @@ -20,6 +20,9 @@ #ifndef BEAST_INSIGHT_BASEIMPL_H_INCLUDED #define BEAST_INSIGHT_BASEIMPL_H_INCLUDED +#include +#include +#include #include namespace beast { diff --git a/src/beast/beast/insight/Collector.h b/src/beast/beast/insight/Collector.h index 74bb8998a9..6325ad37b5 100644 --- a/src/beast/beast/insight/Collector.h +++ b/src/beast/beast/insight/Collector.h @@ -20,14 +20,14 @@ #ifndef BEAST_INSIGHT_COLLECTOR_H_INCLUDED #define BEAST_INSIGHT_COLLECTOR_H_INCLUDED -#include - #include "Counter.h" #include "Event.h" #include "Gauge.h" #include "Hook.h" #include "Meter.h" +#include + namespace beast { namespace insight { diff --git a/src/beast/beast/insight/Counter.h b/src/beast/beast/insight/Counter.h index 9f27128b66..2da422261f 100644 --- a/src/beast/beast/insight/Counter.h +++ b/src/beast/beast/insight/Counter.h @@ -20,11 +20,11 @@ #ifndef BEAST_INSIGHT_COUNTER_H_INCLUDED #define BEAST_INSIGHT_COUNTER_H_INCLUDED -#include - #include "Base.h" #include "CounterImpl.h" +#include + namespace beast { namespace insight { @@ -60,32 +60,58 @@ public: /** Increment the counter. */ /** @{ */ - void increment (value_type amount) const + void + increment (value_type amount) const { if (m_impl) m_impl->increment (amount); } - Counter const& operator+= (value_type amount) const - { increment (amount); return *this; } + Counter const& + operator+= (value_type amount) const + { + increment (amount); + return *this; + } - Counter const& operator-= (value_type amount) const - { increment (-amount); return *this; } + Counter const& + operator-= (value_type amount) const + { + increment (-amount); + return *this; + } - Counter const& operator++ () const - { increment (1); return *this; } + Counter const& + operator++ () const + { + increment (1); + return *this; + } - Counter const& operator++ (int) const - { increment (1); return *this; } + Counter const& + operator++ (int) const + { + increment (1); + return *this; + } - Counter const& operator-- () const - { increment (-1); return *this; } + Counter const& + operator-- () const + { + increment (-1); + return *this; + } - Counter const& operator-- (int) const - { increment (-1); return *this; } + Counter const& + operator-- (int) const + { + increment (-1); + return *this; + } /** @} */ - std::shared_ptr const& impl () const + std::shared_ptr const& + impl () const { return m_impl; } diff --git a/src/beast/beast/insight/CounterImpl.h b/src/beast/beast/insight/CounterImpl.h index c1a0254be3..61f150509d 100644 --- a/src/beast/beast/insight/CounterImpl.h +++ b/src/beast/beast/insight/CounterImpl.h @@ -20,8 +20,6 @@ #ifndef BEAST_INSIGHT_COUNTERIMPL_H_INCLUDED #define BEAST_INSIGHT_COUNTERIMPL_H_INCLUDED -#include - #include "BaseImpl.h" namespace beast { @@ -34,7 +32,7 @@ class CounterImpl , public BaseImpl { public: - typedef int64 value_type; + typedef std::int64_t value_type; virtual ~CounterImpl () = 0; virtual void increment (value_type amount) = 0; diff --git a/src/beast/beast/insight/Event.h b/src/beast/beast/insight/Event.h index 0bcf6df590..52189a505b 100644 --- a/src/beast/beast/insight/Event.h +++ b/src/beast/beast/insight/Event.h @@ -20,14 +20,14 @@ #ifndef BEAST_INSIGHT_EVENT_H_INCLUDED #define BEAST_INSIGHT_EVENT_H_INCLUDED -#include -#include - #include "Base.h" #include "EventImpl.h" #include "../chrono/chrono_util.h" +#include +#include + namespace beast { namespace insight { @@ -62,7 +62,8 @@ public: /** Push an event notification. */ template - void notify (std::chrono::duration const& value) const + void + notify (std::chrono::duration const& value) const { if (m_impl) m_impl->notify (ceil (value)); diff --git a/src/beast/beast/insight/EventImpl.h b/src/beast/beast/insight/EventImpl.h index d2d684e555..4113d59daf 100644 --- a/src/beast/beast/insight/EventImpl.h +++ b/src/beast/beast/insight/EventImpl.h @@ -20,8 +20,6 @@ #ifndef BEAST_INSIGHT_EVENTIMPL_H_INCLUDED #define BEAST_INSIGHT_EVENTIMPL_H_INCLUDED -#include - #include "BaseImpl.h" namespace beast { diff --git a/src/beast/beast/insight/Gauge.h b/src/beast/beast/insight/Gauge.h index 22875214f9..d02a68d345 100644 --- a/src/beast/beast/insight/Gauge.h +++ b/src/beast/beast/insight/Gauge.h @@ -20,11 +20,11 @@ #ifndef BEAST_INSIGHT_GAUGE_H_INCLUDED #define BEAST_INSIGHT_GAUGE_H_INCLUDED -#include - #include "Base.h" #include "GaugeImpl.h" +#include + namespace beast { namespace insight { @@ -40,7 +40,7 @@ namespace insight { class Gauge : public Base { public: - typedef GaugeImpl::value_type value_type; + typedef GaugeImpl::value_type value_type; typedef GaugeImpl::difference_type difference_type; /** Create a null metric. @@ -84,26 +84,51 @@ public: m_impl->increment (amount); } - Gauge const& operator+= (difference_type amount) const - { increment (amount); return *this; } + Gauge const& + operator+= (difference_type amount) const + { + increment (amount); + return *this; + } - Gauge const& operator-= (difference_type amount) const - { increment (-amount); return *this; } + Gauge const& + operator-= (difference_type amount) const + { + increment (-amount); + return *this; + } - Gauge const& operator++ () const - { increment (1); return *this; } + Gauge const& + operator++ () const + { + increment (1); + return *this; + } - Gauge const& operator++ (int) const - { increment (1); return *this; } + Gauge const& + operator++ (int) const + { + increment (1); + return *this; + } - Gauge const& operator-- () const - { increment (-1); return *this; } + Gauge const& + operator-- () const + { + increment (-1); + return *this; + } - Gauge const& operator-- (int) const - { increment (-1); return *this; } + Gauge const& + operator-- (int) const + { + increment (-1); + return *this; + } /** @} */ - std::shared_ptr const& impl () const + std::shared_ptr const& + impl () const { return m_impl; } diff --git a/src/beast/beast/insight/GaugeImpl.h b/src/beast/beast/insight/GaugeImpl.h index 1f5794e958..081c534b3b 100644 --- a/src/beast/beast/insight/GaugeImpl.h +++ b/src/beast/beast/insight/GaugeImpl.h @@ -20,8 +20,6 @@ #ifndef BEAST_INSIGHT_GAUGEIMPL_H_INCLUDED #define BEAST_INSIGHT_GAUGEIMPL_H_INCLUDED -#include - #include "BaseImpl.h" namespace beast { @@ -34,8 +32,8 @@ class GaugeImpl , public BaseImpl { public: - typedef uint64 value_type; - typedef int64 difference_type; + typedef std::uint64_t value_type; + typedef std::int64_t difference_type; virtual ~GaugeImpl () = 0; virtual void set (value_type value) = 0; diff --git a/src/beast/beast/insight/Group.h b/src/beast/beast/insight/Group.h index 273472914e..f47c72a226 100644 --- a/src/beast/beast/insight/Group.h +++ b/src/beast/beast/insight/Group.h @@ -20,10 +20,11 @@ #ifndef BEAST_INSIGHT_GROUP_H_INCLUDED #define BEAST_INSIGHT_GROUP_H_INCLUDED -#include - #include "Collector.h" +#include +#include + namespace beast { namespace insight { diff --git a/src/beast/beast/insight/Groups.h b/src/beast/beast/insight/Groups.h index 6138938205..be4f297606 100644 --- a/src/beast/beast/insight/Groups.h +++ b/src/beast/beast/insight/Groups.h @@ -20,12 +20,12 @@ #ifndef BEAST_INSIGHT_GROUPS_H_INCLUDED #define BEAST_INSIGHT_GROUPS_H_INCLUDED -#include -#include - #include "Collector.h" #include "Group.h" +#include +#include + namespace beast { namespace insight { @@ -37,9 +37,12 @@ public: /** Find or create a new collector with a given name. */ /** @{ */ - virtual Group::ptr const& get (std::string const& name) = 0; + virtual + Group::ptr const& + get (std::string const& name) = 0; - Group::ptr const& operator[] (std::string const& name) + Group::ptr const& + operator[] (std::string const& name) { return get (name); } diff --git a/src/beast/beast/insight/Hook.h b/src/beast/beast/insight/Hook.h index 783477a4e7..696fe6815a 100644 --- a/src/beast/beast/insight/Hook.h +++ b/src/beast/beast/insight/Hook.h @@ -20,11 +20,11 @@ #ifndef BEAST_INSIGHT_HOOK_H_INCLUDED #define BEAST_INSIGHT_HOOK_H_INCLUDED -#include - #include "Base.h" #include "HookImpl.h" +#include + namespace beast { namespace insight { diff --git a/src/beast/beast/insight/HookImpl.h b/src/beast/beast/insight/HookImpl.h index 84b2b3e7f2..78ecb0e4ea 100644 --- a/src/beast/beast/insight/HookImpl.h +++ b/src/beast/beast/insight/HookImpl.h @@ -20,9 +20,6 @@ #ifndef BEAST_INSIGHT_HOOKIMPL_H_INCLUDED #define BEAST_INSIGHT_HOOKIMPL_H_INCLUDED -#include -#include - #include "BaseImpl.h" namespace beast { diff --git a/src/beast/beast/insight/Insight.cpp b/src/beast/beast/insight/Insight.cpp index 209364788a..5ab9a4df6b 100644 --- a/src/beast/beast/insight/Insight.cpp +++ b/src/beast/beast/insight/Insight.cpp @@ -23,8 +23,6 @@ #include "../Config.h" -#include "../../modules/beast_core/beast_core.h" // for UnitTest - #include "../Insight.h" #include "impl/Collector.cpp" diff --git a/src/beast/beast/insight/MeterImpl.h b/src/beast/beast/insight/MeterImpl.h index 21dae58a0c..301f86e638 100644 --- a/src/beast/beast/insight/MeterImpl.h +++ b/src/beast/beast/insight/MeterImpl.h @@ -20,8 +20,6 @@ #ifndef BEAST_INSIGHT_METERIMPL_H_INCLUDED #define BEAST_INSIGHT_METERIMPL_H_INCLUDED -#include - #include "BaseImpl.h" namespace beast { @@ -34,7 +32,7 @@ class MeterImpl , public BaseImpl { public: - typedef uint64 value_type; + typedef std::uint64_t value_type; virtual ~MeterImpl () = 0; virtual void increment (value_type amount) = 0; diff --git a/src/beast/beast/insight/StatsDCollector.h b/src/beast/beast/insight/StatsDCollector.h index b5efbbc813..ea5bf61ee5 100644 --- a/src/beast/beast/insight/StatsDCollector.h +++ b/src/beast/beast/insight/StatsDCollector.h @@ -22,6 +22,7 @@ #include "Collector.h" +#include "../utility/Journal.h" #include "../net/IPEndpoint.h" namespace beast { @@ -39,7 +40,9 @@ public: @param prefix A string pre-pended before each metric name. @param journal Destination for logging output. */ - static std::shared_ptr New (IP::Endpoint const& address, + static + std::shared_ptr + New (IP::Endpoint const& address, std::string const& prefix, Journal journal); }; diff --git a/src/beast/beast/insight/impl/StatsDCollector.cpp b/src/beast/beast/insight/impl/StatsDCollector.cpp index 85271097c4..cc54769337 100644 --- a/src/beast/beast/insight/impl/StatsDCollector.cpp +++ b/src/beast/beast/insight/impl/StatsDCollector.cpp @@ -18,19 +18,21 @@ //============================================================================== #include "../../asio/IPAddressConversion.h" +#include "../../intrusive/List.h" #include "../../threads/SharedData.h" -#include -#include -#include -#include -#include - -#include +#include #include #include #include +#include +#include +#include +#include +#include +#include + #ifndef BEAST_STATSDCOLLECTOR_TRACING_ENABLED #define BEAST_STATSDCOLLECTOR_TRACING_ENABLED 0 #endif @@ -364,7 +366,7 @@ public: { std::string const& buffer (*iter); std::size_t const length (buffer.size ()); - check_precondition (! buffer.empty ()); + assert (! buffer.empty ()); if (! buffers.empty () && (size + length) > max_packet_size) { #if BEAST_STATSDCOLLECTOR_TRACING_ENABLED diff --git a/src/beast/beast/net/Net.cpp b/src/beast/beast/net/Net.cpp index 6180dfa1ab..d65e14aa68 100644 --- a/src/beast/beast/net/Net.cpp +++ b/src/beast/beast/net/Net.cpp @@ -17,18 +17,11 @@ */ //============================================================================== -#if BEAST_INCLUDE_BEASTCONFIG -#include "../../BeastConfig.h" -#endif - #include "../Config.h" -#include "../../modules/beast_core/beast_core.h" // for UnitTest - #include "impl/DynamicBuffer.cpp" -#include "impl/IPAddress.cpp" #include "impl/IPAddressV4.cpp" #include "impl/IPAddressV6.cpp" #include "impl/IPEndpoint.cpp" - +#include "tests/IPEndpoint.test.cpp" diff --git a/src/beast/beast/net/impl/DynamicBuffer.cpp b/src/beast/beast/net/impl/DynamicBuffer.cpp index 4dec2d5dfb..459c2231d3 100644 --- a/src/beast/beast/net/impl/DynamicBuffer.cpp +++ b/src/beast/beast/net/impl/DynamicBuffer.cpp @@ -17,10 +17,15 @@ */ //============================================================================== -#include +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif #include "../DynamicBuffer.h" +#include +#include + namespace beast { DynamicBuffer::DynamicBuffer (size_type blocksize) diff --git a/src/beast/beast/net/impl/IPAddressV4.cpp b/src/beast/beast/net/impl/IPAddressV4.cpp index a74daacffb..37af00ef2e 100644 --- a/src/beast/beast/net/impl/IPAddressV4.cpp +++ b/src/beast/beast/net/impl/IPAddressV4.cpp @@ -17,7 +17,14 @@ */ //============================================================================== +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif + #include "../IPAddressV4.h" +#include "../detail/Parse.h" + +#include namespace beast { namespace IP { diff --git a/src/beast/beast/net/impl/IPAddressV6.cpp b/src/beast/beast/net/impl/IPAddressV6.cpp index 4c9baa31d4..3086228281 100644 --- a/src/beast/beast/net/impl/IPAddressV6.cpp +++ b/src/beast/beast/net/impl/IPAddressV6.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif + #include "../IPAddressV6.h" namespace beast { diff --git a/src/beast/beast/net/impl/IPEndpoint.cpp b/src/beast/beast/net/impl/IPEndpoint.cpp index 0f6f232534..f401c3159d 100644 --- a/src/beast/beast/net/impl/IPEndpoint.cpp +++ b/src/beast/beast/net/impl/IPEndpoint.cpp @@ -17,6 +17,11 @@ */ //============================================================================== +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif + +#include "../IPEndpoint.h" #include "../detail/Parse.h" namespace beast { diff --git a/src/beast/beast/net/impl/IPAddress.cpp b/src/beast/beast/net/tests/IPEndpoint.test.cpp similarity index 94% rename from src/beast/beast/net/impl/IPAddress.cpp rename to src/beast/beast/net/tests/IPEndpoint.test.cpp index 61c3b707a8..ccbee18cce 100644 --- a/src/beast/beast/net/impl/IPAddress.cpp +++ b/src/beast/beast/net/tests/IPEndpoint.test.cpp @@ -17,17 +17,23 @@ */ //============================================================================== -#include +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif #include "../IPEndpoint.h" #include "../detail/Parse.h" +#include "../../unit_test/suite.h" + +#include + namespace beast { namespace IP { //------------------------------------------------------------------------------ -class IPAddressTests : public UnitTest +class IPEndpoint_test : public unit_test::suite { public: void shouldParseV4 (std::string const& s, uint32 value) @@ -51,7 +57,7 @@ public: void testAddressV4 () { - beginTestCase ("AddressV4"); + testcase ("AddressV4"); expect (AddressV4().value == 0); expect (is_unspecified (AddressV4())); @@ -100,7 +106,7 @@ public: void testAddressV4Proxy () { - beginTestCase ("AddressV4::Proxy"); + testcase ("AddressV4::Proxy"); AddressV4 v4 (10, 0, 0, 1); expect (v4[0]==10); @@ -122,7 +128,7 @@ public: void testAddress () { - beginTestCase ("Address"); + testcase ("Address"); std::pair result ( Address::from_string ("1.2.3.4")); @@ -135,7 +141,7 @@ public: void testEndpoint () { - beginTestCase ("Endpoint"); + testcase ("Endpoint"); { std::pair result ( @@ -220,7 +226,7 @@ public: template void testParse (char const* name) { - beginTestCase (name); + testcase (name); shouldPass ("0.0.0.0"); shouldPass ("192.168.0.1"); @@ -235,7 +241,7 @@ public: shouldFail ("1.2.3:80"); } - void runTest () + void run () { testAddressV4 (); testAddressV4Proxy(); @@ -244,13 +250,9 @@ public: testParse ("Parse Endpoint"); } - - IPAddressTests () : UnitTest ("IP::Endpoint", "beast") - { - } }; -static IPAddressTests ipEndpointTests; +BEAST_DEFINE_TESTSUITE(IPEndpoint,net,beast); } } diff --git a/src/beast/beast/streams/basic_scoped_ostream.h b/src/beast/beast/streams/basic_scoped_ostream.h index 71f97bb307..d1a001ada5 100644 --- a/src/beast/beast/streams/basic_scoped_ostream.h +++ b/src/beast/beast/streams/basic_scoped_ostream.h @@ -21,6 +21,7 @@ #define BEAST_STREAMS_BASIC_SCOPED_OSTREAM_H_INCLUDED #include "../cxx14/memory.h" // + #include #include #include diff --git a/src/beast/beast/streams/streams.cpp b/src/beast/beast/streams/streams.cpp index a38a0f11d8..a957415919 100644 --- a/src/beast/beast/streams/streams.cpp +++ b/src/beast/beast/streams/streams.cpp @@ -17,54 +17,4 @@ */ //============================================================================== -#if BEAST_INCLUDE_BEASTCONFIG -#include "../../BeastConfig.h" -#endif - -#include "../../modules/beast_core/beast_core.h" - -#include "basic_abstract_ostream.h" - -namespace beast { - -class streams_Tests : public UnitTest -{ -public: - class test_stream : public basic_abstract_ostream - { - public: - explicit test_stream (UnitTest& test) - : m_test (test) - { - } - - void write (string_type const& s) override - { - m_test.logMessage (s); - } - - test_stream& operator= (test_stream const&) = delete; - - private: - UnitTest& m_test; - }; - - void runTest() - { - beginTestCase ("stream"); - - test_stream ts (*this); - - ts << "Hello"; - - pass(); - } - - streams_Tests() : UnitTest ("streams", "beast") - { - } -}; - -static streams_Tests streams_tests; - -} +#include "tests/basic_abstract_ostream.test.cpp" diff --git a/src/beast/beast/streams/tests/basic_abstract_ostream.test.cpp b/src/beast/beast/streams/tests/basic_abstract_ostream.test.cpp new file mode 100644 index 0000000000..1ef7687a92 --- /dev/null +++ b/src/beast/beast/streams/tests/basic_abstract_ostream.test.cpp @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +/* + 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. +*/ +//============================================================================== + +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif + +#include "../basic_abstract_ostream.h" + +#include "../../unit_test/suite.h" + +namespace beast { + +class basic_abstract_ostream_test : public unit_test::suite +{ +public: + class test_stream : public basic_abstract_ostream + { + public: + test_stream& + operator= (test_stream const&) = delete; + + explicit + test_stream (unit_test::suite& suite_) + : m_suite (suite_) + { + } + + void write (string_type const& s) override + { + m_suite.log << s; + } + + private: + unit_test::suite& m_suite; + }; + + void run() + { + test_stream ts (*this); + + ts << "Hello"; + + pass(); + } +}; + +BEAST_DEFINE_TESTSUITE(basic_abstract_ostream,streams,beast); + +} diff --git a/src/beast/beast/strings/Strings.cpp b/src/beast/beast/strings/Strings.cpp index 09b32a3470..15f2ddad1c 100644 --- a/src/beast/beast/strings/Strings.cpp +++ b/src/beast/beast/strings/Strings.cpp @@ -17,9 +17,5 @@ */ //============================================================================== -#if BEAST_INCLUDE_BEASTCONFIG -#include "../../BeastConfig.h" -#endif - #include "impl/CharacterFunctions.cpp" #include "impl/String.cpp" diff --git a/src/beast/beast/strings/impl/CharacterFunctions.cpp b/src/beast/beast/strings/impl/CharacterFunctions.cpp index 6158f70ae9..5121056973 100644 --- a/src/beast/beast/strings/impl/CharacterFunctions.cpp +++ b/src/beast/beast/strings/impl/CharacterFunctions.cpp @@ -21,6 +21,10 @@ */ //============================================================================== +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif + #include "../CharacterFunctions.h" #include diff --git a/src/beast/beast/strings/impl/String.cpp b/src/beast/beast/strings/impl/String.cpp index b12f397a9d..8a52c1ecca 100644 --- a/src/beast/beast/strings/impl/String.cpp +++ b/src/beast/beast/strings/impl/String.cpp @@ -21,7 +21,9 @@ */ //============================================================================== -#include +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif #include "../String.h" #include "../NewLine.h" @@ -32,7 +34,7 @@ #include "../../Arithmetic.h" #include "../../HeapBlock.h" -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include namespace beast { @@ -1976,364 +1978,4 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) #pragma warning (pop) #endif -//============================================================================== -//============================================================================== - -#ifdef BEAST_UNITTEST_H_INCLUDED - -class StringTests : public UnitTest -{ -public: - StringTests() : UnitTest ("String", "beast") - { - } - - template - struct TestUTFConversion - { - static void test (UnitTest& test) - { - String s (createRandomWideCharString()); - - typename CharPointerType::CharType buffer [300]; - - memset (buffer, 0xff, sizeof (buffer)); - CharPointerType (buffer).writeAll (s.toUTF32()); - test.expectEquals (String (CharPointerType (buffer)), s); - - memset (buffer, 0xff, sizeof (buffer)); - CharPointerType (buffer).writeAll (s.toUTF16()); - test.expectEquals (String (CharPointerType (buffer)), s); - - memset (buffer, 0xff, sizeof (buffer)); - CharPointerType (buffer).writeAll (s.toUTF8()); - test.expectEquals (String (CharPointerType (buffer)), s); - - test.expect (CharPointerType::isValidString (buffer, (int) strlen ((const char*) buffer))); - } - }; - - static String createRandomWideCharString() - { - beast_wchar buffer[50] = { 0 }; - Random r; - - for (int i = 0; i < numElementsInArray (buffer) - 1; ++i) - { - if (r.nextBool()) - { - do - { - buffer[i] = (beast_wchar) (1 + r.nextInt (0x10ffff - 1)); - } - while (! CharPointer_UTF16::canRepresent (buffer[i])); - } - else - buffer[i] = (beast_wchar) (1 + r.nextInt (0xff)); - } - - return CharPointer_UTF32 (buffer); - } - - void runTest() - { - { - beginTestCase ("Basics"); - - expect (String().length() == 0); - expect (String() == String::empty); - String s1, s2 ("abcd"); - expect (s1.isEmpty() && ! s1.isNotEmpty()); - expect (s2.isNotEmpty() && ! s2.isEmpty()); - expect (s2.length() == 4); - s1 = "abcd"; - expect (s2 == s1 && s1 == s2); - expect (s1 == "abcd" && s1 == L"abcd"); - expect (String ("abcd") == String (L"abcd")); - expect (String ("abcdefg", 4) == L"abcd"); - expect (String ("abcdefg", 4) == String (L"abcdefg", 4)); - expect (String::charToString ('x') == "x"); - expect (String::charToString (0) == String::empty); - expect (s2 + "e" == "abcde" && s2 + 'e' == "abcde"); - expect (s2 + L'e' == "abcde" && s2 + L"e" == "abcde"); - expect (s1.equalsIgnoreCase ("abcD") && s1 < "abce" && s1 > "abbb"); - expect (s1.startsWith ("ab") && s1.startsWith ("abcd") && ! s1.startsWith ("abcde")); - expect (s1.startsWithIgnoreCase ("aB") && s1.endsWithIgnoreCase ("CD")); - expect (s1.endsWith ("bcd") && ! s1.endsWith ("aabcd")); - expectEquals (s1.indexOf (String::empty), 0); - expectEquals (s1.indexOfIgnoreCase (String::empty), 0); - expect (s1.startsWith (String::empty) && s1.endsWith (String::empty) && s1.contains (String::empty)); - expect (s1.contains ("cd") && s1.contains ("ab") && s1.contains ("abcd")); - expect (s1.containsChar ('a')); - expect (! s1.containsChar ('x')); - expect (! s1.containsChar (0)); - expect (String ("abc foo bar").containsWholeWord ("abc") && String ("abc foo bar").containsWholeWord ("abc")); - } - - { - beginTestCase ("Operations"); - - String s ("012345678"); - expect (s.hashCode() != 0); - expect (s.hashCode64() != 0); - expect (s.hashCode() != (s + s).hashCode()); - expect (s.hashCode64() != (s + s).hashCode64()); - expect (s.compare (String ("012345678")) == 0); - expect (s.compare (String ("012345679")) < 0); - expect (s.compare (String ("012345676")) > 0); - expect (s.substring (2, 3) == String::charToString (s[2])); - expect (s.substring (0, 1) == String::charToString (s[0])); - expect (s.getLastCharacter() == s [s.length() - 1]); - expect (String::charToString (s.getLastCharacter()) == s.getLastCharacters (1)); - expect (s.substring (0, 3) == L"012"); - expect (s.substring (0, 100) == s); - expect (s.substring (-1, 100) == s); - expect (s.substring (3) == "345678"); - expect (s.indexOf (L"45") == 4); - expect (String ("444445").indexOf ("45") == 4); - expect (String ("444445").lastIndexOfChar ('4') == 4); - expect (String ("45454545x").lastIndexOf (L"45") == 6); - expect (String ("45454545x").lastIndexOfAnyOf ("456") == 7); - expect (String ("45454545x").lastIndexOfAnyOf (L"456x") == 8); - expect (String ("abABaBaBa").lastIndexOfIgnoreCase ("aB") == 6); - expect (s.indexOfChar (L'4') == 4); - expect (s + s == "012345678012345678"); - expect (s.startsWith (s)); - expect (s.startsWith (s.substring (0, 4))); - expect (s.startsWith (s.dropLastCharacters (4))); - expect (s.endsWith (s.substring (5))); - expect (s.endsWith (s)); - expect (s.contains (s.substring (3, 6))); - expect (s.contains (s.substring (3))); - expect (s.startsWithChar (s[0])); - expect (s.endsWithChar (s.getLastCharacter())); - expect (s [s.length()] == 0); - expect (String ("abcdEFGH").toLowerCase() == String ("abcdefgh")); - expect (String ("abcdEFGH").toUpperCase() == String ("ABCDEFGH")); - - String s2 ("123"); - s2 << ((int) 4) << ((short) 5) << "678" << L"9" << '0'; - s2 += "xyz"; - expect (s2 == "1234567890xyz"); - - beginTestCase ("Numeric conversions"); - expect (String::empty.getIntValue() == 0); - expect (String::empty.getDoubleValue() == 0.0); - expect (String::empty.getFloatValue() == 0.0f); - expect (s.getIntValue() == 12345678); - expect (s.getLargeIntValue() == (int64) 12345678); - expect (s.getDoubleValue() == 12345678.0); - expect (s.getFloatValue() == 12345678.0f); - expect (String (-1234).getIntValue() == -1234); - expect (String ((int64) -1234).getLargeIntValue() == -1234); - expect (String (-1234.56).getDoubleValue() == -1234.56); - expect (String (-1234.56f).getFloatValue() == -1234.56f); - expect (String (std::numeric_limits::max()).getIntValue() == std::numeric_limits::max()); - expect (String (std::numeric_limits::min()).getIntValue() == std::numeric_limits::min()); - expect (String (std::numeric_limits::max()).getLargeIntValue() == std::numeric_limits::max()); - expect (String (std::numeric_limits::min()).getLargeIntValue() == std::numeric_limits::min()); - expect (("xyz" + s).getTrailingIntValue() == s.getIntValue()); - expect (s.getHexValue32() == 0x12345678); - expect (s.getHexValue64() == (int64) 0x12345678); - expect (String::toHexString (0x1234abcd).equalsIgnoreCase ("1234abcd")); - expect (String::toHexString ((int64) 0x1234abcd).equalsIgnoreCase ("1234abcd")); - expect (String::toHexString ((short) 0x12ab).equalsIgnoreCase ("12ab")); - - expectEquals (String (int (0)), "0"); - expectEquals (String (short (0)), "0"); - expectEquals (String (int64 (0)), "0"); - expectEquals (String ((unsigned int) 0), "0"); - expectEquals (String ((unsigned short) 0), "0"); - expectEquals (String (uint64 (0)), "0"); - - expectEquals (String (int (-1)), "-1"); - expectEquals (String (short (-1)), "-1"); - expectEquals (String (int64 (-1)), "-1"); - - expectEquals (String (int (1)), "1"); - expectEquals (String (short (1)), "1"); - expectEquals (String (int64 (1)), "1"); - expectEquals (String ((unsigned int) 1), "1"); - expectEquals (String ((unsigned short) 1), "1"); - expectEquals (String (uint64 (1)), "1"); - - unsigned char data[] = { 1, 2, 3, 4, 0xa, 0xb, 0xc, 0xd }; - expect (String::toHexString (data, 8, 0).equalsIgnoreCase ("010203040a0b0c0d")); - expect (String::toHexString (data, 8, 1).equalsIgnoreCase ("01 02 03 04 0a 0b 0c 0d")); - expect (String::toHexString (data, 8, 2).equalsIgnoreCase ("0102 0304 0a0b 0c0d")); - - beginTestCase ("Subsections"); - String s3; - s3 = "abcdeFGHIJ"; - expect (s3.equalsIgnoreCase ("ABCdeFGhiJ")); - expect (s3.compareIgnoreCase (L"ABCdeFGhiJ") == 0); - expect (s3.containsIgnoreCase (s3.substring (3))); - expect (s3.indexOfAnyOf ("xyzf", 2, true) == 5); - expect (s3.indexOfAnyOf (L"xyzf", 2, false) == -1); - expect (s3.indexOfAnyOf ("xyzF", 2, false) == 5); - expect (s3.containsAnyOf (L"zzzFs")); - expect (s3.startsWith ("abcd")); - expect (s3.startsWithIgnoreCase (L"abCD")); - expect (s3.startsWith (String::empty)); - expect (s3.startsWithChar ('a')); - expect (s3.endsWith (String ("HIJ"))); - expect (s3.endsWithIgnoreCase (L"Hij")); - expect (s3.endsWith (String::empty)); - expect (s3.endsWithChar (L'J')); - expect (s3.indexOf ("HIJ") == 7); - expect (s3.indexOf (L"HIJK") == -1); - expect (s3.indexOfIgnoreCase ("hij") == 7); - expect (s3.indexOfIgnoreCase (L"hijk") == -1); - expect (s3.toStdString() == s3.toRawUTF8()); - - String s4 (s3); - s4.append (String ("xyz123"), 3); - expect (s4 == s3 + "xyz"); - - expect (String (1234) < String (1235)); - expect (String (1235) > String (1234)); - expect (String (1234) >= String (1234)); - expect (String (1234) <= String (1234)); - expect (String (1235) >= String (1234)); - expect (String (1234) <= String (1235)); - - String s5 ("word word2 word3"); - expect (s5.containsWholeWord (String ("word2"))); - expect (s5.indexOfWholeWord ("word2") == 5); - expect (s5.containsWholeWord (L"word")); - expect (s5.containsWholeWord ("word3")); - expect (s5.containsWholeWord (s5)); - expect (s5.containsWholeWordIgnoreCase (L"Word2")); - expect (s5.indexOfWholeWordIgnoreCase ("Word2") == 5); - expect (s5.containsWholeWordIgnoreCase (L"Word")); - expect (s5.containsWholeWordIgnoreCase ("Word3")); - expect (! s5.containsWholeWordIgnoreCase (L"Wordx")); - expect (! s5.containsWholeWordIgnoreCase ("xWord2")); - expect (s5.containsNonWhitespaceChars()); - expect (s5.containsOnly ("ordw23 ")); - expect (! String (" \n\r\t").containsNonWhitespaceChars()); - - expect (s5.matchesWildcard (L"wor*", false)); - expect (s5.matchesWildcard ("wOr*", true)); - expect (s5.matchesWildcard (L"*word3", true)); - expect (s5.matchesWildcard ("*word?", true)); - expect (s5.matchesWildcard (L"Word*3", true)); - expect (! s5.matchesWildcard (L"*34", true)); - expect (String ("xx**y").matchesWildcard ("*y", true)); - expect (String ("xx**y").matchesWildcard ("x*y", true)); - expect (String ("xx**y").matchesWildcard ("xx*y", true)); - expect (String ("xx**y").matchesWildcard ("xx*", true)); - expect (String ("xx?y").matchesWildcard ("x??y", true)); - expect (String ("xx?y").matchesWildcard ("xx?y", true)); - expect (! String ("xx?y").matchesWildcard ("xx?y?", true)); - expect (String ("xx?y").matchesWildcard ("xx??", true)); - - expectEquals (s5.fromFirstOccurrenceOf (String::empty, true, false), s5); - expectEquals (s5.fromFirstOccurrenceOf ("xword2", true, false), s5.substring (100)); - expectEquals (s5.fromFirstOccurrenceOf (L"word2", true, false), s5.substring (5)); - expectEquals (s5.fromFirstOccurrenceOf ("Word2", true, true), s5.substring (5)); - expectEquals (s5.fromFirstOccurrenceOf ("word2", false, false), s5.getLastCharacters (6)); - expectEquals (s5.fromFirstOccurrenceOf (L"Word2", false, true), s5.getLastCharacters (6)); - - expectEquals (s5.fromLastOccurrenceOf (String::empty, true, false), s5); - expectEquals (s5.fromLastOccurrenceOf (L"wordx", true, false), s5); - expectEquals (s5.fromLastOccurrenceOf ("word", true, false), s5.getLastCharacters (5)); - expectEquals (s5.fromLastOccurrenceOf (L"worD", true, true), s5.getLastCharacters (5)); - expectEquals (s5.fromLastOccurrenceOf ("word", false, false), s5.getLastCharacters (1)); - expectEquals (s5.fromLastOccurrenceOf (L"worD", false, true), s5.getLastCharacters (1)); - - expect (s5.upToFirstOccurrenceOf (String::empty, true, false).isEmpty()); - expectEquals (s5.upToFirstOccurrenceOf ("word4", true, false), s5); - expectEquals (s5.upToFirstOccurrenceOf (L"word2", true, false), s5.substring (0, 10)); - expectEquals (s5.upToFirstOccurrenceOf ("Word2", true, true), s5.substring (0, 10)); - expectEquals (s5.upToFirstOccurrenceOf (L"word2", false, false), s5.substring (0, 5)); - expectEquals (s5.upToFirstOccurrenceOf ("Word2", false, true), s5.substring (0, 5)); - - expectEquals (s5.upToLastOccurrenceOf (String::empty, true, false), s5); - expectEquals (s5.upToLastOccurrenceOf ("zword", true, false), s5); - expectEquals (s5.upToLastOccurrenceOf ("word", true, false), s5.dropLastCharacters (1)); - expectEquals (s5.dropLastCharacters(1).upToLastOccurrenceOf ("word", true, false), s5.dropLastCharacters (1)); - expectEquals (s5.upToLastOccurrenceOf ("Word", true, true), s5.dropLastCharacters (1)); - expectEquals (s5.upToLastOccurrenceOf ("word", false, false), s5.dropLastCharacters (5)); - expectEquals (s5.upToLastOccurrenceOf ("Word", false, true), s5.dropLastCharacters (5)); - - expectEquals (s5.replace ("word", L"xyz", false), String ("xyz xyz2 xyz3")); - expect (s5.replace (L"Word", "xyz", true) == "xyz xyz2 xyz3"); - expect (s5.dropLastCharacters (1).replace ("Word", String ("xyz"), true) == L"xyz xyz2 xyz"); - expect (s5.replace ("Word", "", true) == " 2 3"); - expectEquals (s5.replace ("Word2", L"xyz", true), String ("word xyz word3")); - expect (s5.replaceCharacter (L'w', 'x') != s5); - expectEquals (s5.replaceCharacter ('w', L'x').replaceCharacter ('x', 'w'), s5); - expect (s5.replaceCharacters ("wo", "xy") != s5); - expectEquals (s5.replaceCharacters ("wo", "xy").replaceCharacters ("xy", L"wo"), s5); - expectEquals (s5.retainCharacters ("1wordxya"), String ("wordwordword")); - expect (s5.retainCharacters (String::empty).isEmpty()); - expect (s5.removeCharacters ("1wordxya") == " 2 3"); - expectEquals (s5.removeCharacters (String::empty), s5); - expect (s5.initialSectionContainingOnly ("word") == L"word"); - expect (String ("word").initialSectionContainingOnly ("word") == L"word"); - expectEquals (s5.initialSectionNotContaining (String ("xyz ")), String ("word")); - expectEquals (s5.initialSectionNotContaining (String (";[:'/")), s5); - expect (! s5.isQuotedString()); - expect (s5.quoted().isQuotedString()); - expect (! s5.quoted().unquoted().isQuotedString()); - expect (! String ("x'").isQuotedString()); - expect (String ("'x").isQuotedString()); - - String s6 (" \t xyz \t\r\n"); - expectEquals (s6.trim(), String ("xyz")); - expect (s6.trim().trim() == "xyz"); - expectEquals (s5.trim(), s5); - expectEquals (s6.trimStart().trimEnd(), s6.trim()); - expectEquals (s6.trimStart().trimEnd(), s6.trimEnd().trimStart()); - expectEquals (s6.trimStart().trimStart().trimEnd().trimEnd(), s6.trimEnd().trimStart()); - expect (s6.trimStart() != s6.trimEnd()); - expectEquals (("\t\r\n " + s6 + "\t\n \r").trim(), s6.trim()); - expect (String::repeatedString ("xyz", 3) == L"xyzxyzxyz"); - } - - { - beginTestCase ("UTF conversions"); - - TestUTFConversion ::test (*this); - TestUTFConversion ::test (*this); - TestUTFConversion ::test (*this); - } - - { - beginTestCase ("StringArray"); - - StringArray s; - s.addTokens ("4,3,2,1,0", ";,", "x"); - expectEquals (s.size(), 5); - - expectEquals (s.joinIntoString ("-"), String ("4-3-2-1-0")); - s.remove (2); - expectEquals (s.joinIntoString ("--"), String ("4--3--1--0")); - expectEquals (s.joinIntoString (String::empty), String ("4310")); - s.clear(); - expectEquals (s.joinIntoString ("x"), String::empty); - - StringArray toks; - toks.addTokens ("x,,", ";,", ""); - expectEquals (toks.size(), 3); - expectEquals (toks.joinIntoString ("-"), String ("x--")); - toks.clear(); - - toks.addTokens (",x,", ";,", ""); - expectEquals (toks.size(), 3); - expectEquals (toks.joinIntoString ("-"), String ("-x-")); - toks.clear(); - - toks.addTokens ("x,'y,z',", ";,", "'"); - expectEquals (toks.size(), 3); - expectEquals (toks.joinIntoString ("-"), String ("x-'y,z'-")); - } - } -}; - -static StringTests stringUnitTests; - -#endif - } diff --git a/src/beast/beast/threads/Thread.h b/src/beast/beast/threads/Thread.h index 1ea34f7c14..4a89fe4657 100644 --- a/src/beast/beast/threads/Thread.h +++ b/src/beast/beast/threads/Thread.h @@ -24,6 +24,7 @@ #ifndef BEAST_THREADS_THREAD_H_INCLUDED #define BEAST_THREADS_THREAD_H_INCLUDED +#include "../strings/String.h" #include "../utility/LeakChecked.h" #include "RecursiveMutex.h" #include "WaitableEvent.h" diff --git a/src/beast/beast/threads/Threads.cpp b/src/beast/beast/threads/Threads.cpp index a2e9491651..283e0811e4 100644 --- a/src/beast/beast/threads/Threads.cpp +++ b/src/beast/beast/threads/Threads.cpp @@ -21,9 +21,11 @@ #include "../../BeastConfig.h" #endif -#include "impl/Atomic.cpp" #include "impl/RecursiveMutex.cpp" #include "impl/ServiceQueue.cpp" #include "impl/Stoppable.cpp" #include "impl/Thread.cpp" #include "impl/WaitableEvent.cpp" + +#include "tests/Atomic.test.cpp" +#include "tests/ServiceQueue.test.cpp" diff --git a/src/beast/beast/threads/impl/ServiceQueue.cpp b/src/beast/beast/threads/impl/ServiceQueue.cpp index 317d7a6144..0b284e3551 100644 --- a/src/beast/beast/threads/impl/ServiceQueue.cpp +++ b/src/beast/beast/threads/impl/ServiceQueue.cpp @@ -19,8 +19,6 @@ #include "../ServiceQueue.h" -#include "../../../modules/beast_core/beast_core.h" // for UnitTest - namespace beast { class ServiceQueueBase::ScopedServiceThread : public List ::Node @@ -185,275 +183,4 @@ bool ServiceQueueBase::empty() // ThreadLocalValue ServiceQueueBase::s_service; -//------------------------------------------------------------------------------ - -namespace detail { - -//------------------------------------------------------------------------------ - -class ServiceQueueTimingTests - : public UnitTest -{ -public: - class Stopwatch - { - public: - Stopwatch () { start(); } - void start () { m_startTime = Time::getHighResolutionTicks (); } - double getElapsed () - { - int64 const now = Time::getHighResolutionTicks(); - return Time::highResolutionTicksToSeconds (now - m_startTime); - } - private: - int64 m_startTime; - }; - - static int const callsPerThread = 50000; - - //-------------------------------------------------------------------------- - - template - struct Consumer : Thread - { - ServiceType& m_service; - Random m_random; - String m_string; - - Consumer (int id, int64 seedValue, ServiceType& service) - : Thread ("C#" + String::fromNumber (id)) - , m_service (service) - , m_random (seedValue) - { startThread(); } - - ~Consumer () - { stopThread(); } - - static Consumer*& thread() - { - static ThreadLocalValue local; - return local.get(); - } - - static void stop_one () - { thread()->signalThreadShouldExit(); } - - static void handler () - { thread()->do_handler(); } - - void do_handler() - { - String const s (String::fromNumber (m_random.nextInt())); - m_string += s; - if (m_string.length() > 100) - m_string = String::empty; - } - - void run () - { - thread() = this; - while (! threadShouldExit()) - m_service.run_one(); - } - }; - - //-------------------------------------------------------------------------- - - template - struct Producer : Thread - { - ServiceType& m_service; - Random m_random; - String m_string; - - Producer (int id, int64 seedValue, ServiceType& service) - : Thread ("P#" + String::fromNumber (id)) - , m_service (service) - , m_random (seedValue) - { } - - ~Producer () - { stopThread(); } - - void run () - { - for (std::size_t i = 0; i < callsPerThread; ++i) - { - String const s (String::fromNumber (m_random.nextInt())); - m_string += s; - if (m_string.length() > 100) - m_string = String::empty; - m_service.dispatch (bind (&Consumer::handler)); - } - } - }; - - //-------------------------------------------------------------------------- - - template - void testThreads (std::size_t nConsumers, std::size_t nProducers) - { - beginTestCase (String::fromNumber (nConsumers) + " consumers, " + - String::fromNumber (nProducers) + " producers, " + - "Allocator = " + std::string(typeid(Allocator).name())); - - typedef ServiceQueueType ServiceType; - - ServiceType service (nConsumers); - std::vector > > consumers; - std::vector > > producers; - consumers.reserve (nConsumers); - producers.reserve (nProducers); - - for (std::size_t i = 0; i < nConsumers; ++i) - consumers.push_back (new Consumer (i + 1, - random().nextInt64(), service)); - - for (std::size_t i = 0; i < nProducers; ++i) - producers.push_back (new Producer (i + 1, - random().nextInt64(), service)); - - Stopwatch t; - - for (std::size_t i = 0; i < producers.size(); ++i) - producers[i]->startThread(); - - for (std::size_t i = 0; i < producers.size(); ++i) - producers[i]->waitForThreadToExit(); - - for (std::size_t i = 0; i < consumers.size(); ++i) - service.dispatch (bind (&Consumer ::stop_one)); - - for (std::size_t i = 0; i < consumers.size(); ++i) - consumers[i]->waitForThreadToExit(); - - double const seconds (t.getElapsed()); - logMessage (String (seconds, 2) + " seconds"); - - pass(); - } - - void runTest() - { -#if 1 - testThreads > (1, 1); - testThreads > (1, 4); - testThreads > (1, 16); - testThreads > (4, 1); - testThreads > (8, 16); -#endif - -#if 0 - testThreads > (1, 1); - testThreads > (1, 4); - testThreads > (1, 16); - testThreads > (4, 1); - testThreads > (8, 16); -#endif - } - - ServiceQueueTimingTests () : UnitTest ("ServiceQueueTiming", "beast", runManual) - { - } -}; - -static ServiceQueueTimingTests serviceQueueTimingTests; - -//------------------------------------------------------------------------------ - -class ServiceQueueTests - : public UnitTest -{ -public: - struct ServiceThread : Thread - { - Random m_random; - ServiceQueue& m_service; - String m_string; - - ServiceThread (int id, int64 seedValue, - ServiceQueue& service) - : Thread ("#" + String::fromNumber (id)) - , m_random (seedValue) - , m_service (service) - { - startThread(); - } - - ~ServiceThread () - { - stopThread(); - } - - static ServiceThread*& thread() - { - static ThreadLocalValue local; - return local.get(); - } - - static void stop_one () - { - thread()->signalThreadShouldExit(); - } - - static void handler () - { - thread()->do_handler(); - } - - void do_handler() - { -#if 1 - String const s (String::fromNumber (m_random.nextInt())); - m_string += s; - if (m_string.length() > 100) - m_string = String::empty; -#endif - } - - void run () - { - thread() = this; - while (! threadShouldExit()) - m_service.run_one(); - } - }; - - static std::size_t const totalCalls = 10000; - - void testThreads (std::size_t n) - { - std::size_t const callsPerThread (totalCalls / n); - beginTestCase (String::fromNumber (n) + " threads"); - ServiceQueue service (n); - std::vector > threads; - threads.reserve (n); - for (std::size_t i = 0; i < n; ++i) - threads.push_back (new ServiceThread (i + 1, - random().nextInt64(), service)); - for (std::size_t i = n * callsPerThread; i; --i) - service.dispatch (bind (&ServiceThread::handler)); - for (std::size_t i = 0; i < threads.size(); ++i) - service.dispatch (bind (&ServiceThread::stop_one)); - for (std::size_t i = 0; i < threads.size(); ++i) - threads[i]->waitForThreadToExit(); - pass(); - } - - void runTest() - { - testThreads (1); - testThreads (4); - testThreads (16); - } - - ServiceQueueTests () : UnitTest ("ServiceQueue", "beast") - { - } -}; - -static ServiceQueueTests serviceQueueTests; - -} - } diff --git a/src/beast/beast/threads/impl/Thread.cpp b/src/beast/beast/threads/impl/Thread.cpp index f04782d9b0..34c2b71fca 100644 --- a/src/beast/beast/threads/impl/Thread.cpp +++ b/src/beast/beast/threads/impl/Thread.cpp @@ -22,6 +22,11 @@ //============================================================================== #include "../Thread.h" +#include "../../smart_ptr/SharedObject.h" +#include "../../smart_ptr/SharedPtr.h" +#include "../../../modules/beast_core/time/Time.h" + +#include namespace beast { @@ -44,7 +49,7 @@ Thread::~Thread() To avoid this type of nastiness, always make sure you call stopThread() before or during your subclass's destructor. */ - check_precondition (! isThreadRunning()); + assert (! isThreadRunning()); stopThread (); } diff --git a/src/beast/beast/threads/impl/Atomic.cpp b/src/beast/beast/threads/tests/Atomic.test.cpp similarity index 84% rename from src/beast/beast/threads/impl/Atomic.cpp rename to src/beast/beast/threads/tests/Atomic.test.cpp index 5f1790fd48..a348c435c6 100644 --- a/src/beast/beast/threads/impl/Atomic.cpp +++ b/src/beast/beast/threads/tests/Atomic.test.cpp @@ -21,15 +21,21 @@ */ //============================================================================== -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#if BEAST_INCLUDE_BEASTCONFIG +#include "../../BeastConfig.h" +#endif + +#include "../../Atomic.h" +#include "../../Arithmetic.h" +#include "../../ByteOrder.h" + +#include "../../unit_test/suite.h" namespace beast { -class AtomicTests : public UnitTest +class Atomic_test : public unit_test::suite { public: - AtomicTests() : UnitTest ("Atomic", "beast") {} - template void testFloat () { @@ -78,9 +84,9 @@ public: testFloat (); } - void runTest() + void run() { - beginTestCase ("Misc"); + testcase ("Misc"); char a1[7]; expect (numElementsInArray(a1) == 7); @@ -91,43 +97,43 @@ public: expect (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211); expect (ByteOrder::swap ((uint64) literal64bit (0x1122334455667788)) == literal64bit (0x8877665544332211)); - beginTestCase ("int"); + testcase ("int"); testInteger (); - beginTestCase ("unsigned int"); + testcase ("unsigned int"); testInteger (); - beginTestCase ("int32"); + testcase ("int32"); testInteger (); - beginTestCase ("uint32"); + testcase ("uint32"); testInteger (); - beginTestCase ("long"); + testcase ("long"); testInteger (); - beginTestCase ("void*"); + testcase ("void*"); testInteger (); - beginTestCase ("int*"); + testcase ("int*"); testInteger (); - beginTestCase ("float"); + testcase ("float"); testFloat (); #if ! BEAST_64BIT_ATOMICS_UNAVAILABLE // 64-bit intrinsics aren't available on some old platforms - beginTestCase ("int64"); + testcase ("int64"); testInteger (); - beginTestCase ("uint64"); + testcase ("uint64"); testInteger (); - beginTestCase ("double"); + testcase ("double"); testFloat (); #endif } }; -static AtomicTests atomicTests; +BEAST_DEFINE_TESTSUITE(Atomic,thread,beast); } diff --git a/src/beast/beast/threads/tests/ServiceQueue.test.cpp b/src/beast/beast/threads/tests/ServiceQueue.test.cpp new file mode 100644 index 0000000000..f079d57421 --- /dev/null +++ b/src/beast/beast/threads/tests/ServiceQueue.test.cpp @@ -0,0 +1,295 @@ +//------------------------------------------------------------------------------ +/* + 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. +*/ +//============================================================================== + +#include "../ServiceQueue.h" + +#include "../../unit_test/suite.h" + +#include "../../../modules/beast_core/time/Time.h" +#include "../../../modules/beast_core/maths/Random.h" + +#include +#include + +namespace beast { + +class ServiceQueue_timing_test : public unit_test::suite +{ +public: + class Stopwatch + { + public: + Stopwatch () { start(); } + void start () { m_startTime = Time::getHighResolutionTicks (); } + double getElapsed () + { + int64 const now = Time::getHighResolutionTicks(); + return Time::highResolutionTicksToSeconds (now - m_startTime); + } + private: + int64 m_startTime; + }; + + static int const callsPerThread = 50000; + + //-------------------------------------------------------------------------- + + template + struct Consumer : Thread + { + ServiceType& m_service; + Random m_random; + String m_string; + + Consumer (int id, int64 seedValue, ServiceType& service) + : Thread ("C#" + String::fromNumber (id)) + , m_service (service) + , m_random (seedValue) + { startThread(); } + + ~Consumer () + { stopThread(); } + + static Consumer*& thread() + { + static ThreadLocalValue local; + return local.get(); + } + + static void stop_one () + { thread()->signalThreadShouldExit(); } + + static void handler () + { thread()->do_handler(); } + + void do_handler() + { + String const s (String::fromNumber (m_random.nextInt())); + m_string += s; + if (m_string.length() > 100) + m_string = String::empty; + } + + void run () + { + thread() = this; + while (! threadShouldExit()) + m_service.run_one(); + } + }; + + //-------------------------------------------------------------------------- + + template + struct Producer : Thread + { + ServiceType& m_service; + Random m_random; + String m_string; + + Producer (int id, int64 seedValue, ServiceType& service) + : Thread ("P#" + String::fromNumber (id)) + , m_service (service) + , m_random (seedValue) + { } + + ~Producer () + { stopThread(); } + + void run () + { + for (std::size_t i = 0; i < callsPerThread; ++i) + { + String const s (String::fromNumber (m_random.nextInt())); + m_string += s; + if (m_string.length() > 100) + m_string = String::empty; + m_service.dispatch (std::bind (&Consumer::handler)); + } + } + }; + + //-------------------------------------------------------------------------- + + template + void testThreads (std::size_t nConsumers, std::size_t nProducers) + { + std::stringstream ss; + ss << + nConsumers << " consumers, " << + nProducers << " producers, Allocator = " << + typeid(Allocator).name(); + testcase (ss.str()); + + typedef ServiceQueueType ServiceType; + + ServiceType service (nConsumers); + std::vector > > consumers; + std::vector > > producers; + consumers.reserve (nConsumers); + producers.reserve (nProducers); + + Random r; + + for (std::size_t i = 0; i < nConsumers; ++i) + consumers.emplace_back (new Consumer (i + 1, + r.nextInt64(), service)); + + for (std::size_t i = 0; i < nProducers; ++i) + producers.emplace_back (new Producer (i + 1, + r.nextInt64(), service)); + + Stopwatch t; + + for (std::size_t i = 0; i < producers.size(); ++i) + producers[i]->startThread(); + + for (std::size_t i = 0; i < producers.size(); ++i) + producers[i]->waitForThreadToExit(); + + for (std::size_t i = 0; i < consumers.size(); ++i) + service.dispatch (std::bind (&Consumer ::stop_one)); + + for (std::size_t i = 0; i < consumers.size(); ++i) + consumers[i]->waitForThreadToExit(); + + double const seconds (t.getElapsed()); + log << seconds << " seconds"; + + pass(); + } + + void run() + { +#if 1 + testThreads > (1, 1); + testThreads > (1, 4); + testThreads > (1, 16); + testThreads > (4, 1); + testThreads > (8, 16); +#endif + +#if 0 + testThreads > (1, 1); + testThreads > (1, 4); + testThreads > (1, 16); + testThreads > (4, 1); + testThreads > (8, 16); +#endif + } +}; + +BEAST_DEFINE_TESTSUITE_MANUAL(ServiceQueue_timing,threads,beast); + +//------------------------------------------------------------------------------ + +class ServiceQueue_test : public unit_test::suite +{ +public: + struct ServiceThread : Thread + { + Random m_random; + ServiceQueue& m_service; + String m_string; + + ServiceThread (int id, int64 seedValue, + ServiceQueue& service) + : Thread ("#" + String::fromNumber (id)) + , m_random (seedValue) + , m_service (service) + { + startThread(); + } + + ~ServiceThread () + { + stopThread(); + } + + static ServiceThread*& thread() + { + static ThreadLocalValue local; + return local.get(); + } + + static void stop_one () + { + thread()->signalThreadShouldExit(); + } + + static void handler () + { + thread()->do_handler(); + } + + void do_handler() + { +#if 1 + String const s (String::fromNumber (m_random.nextInt())); + m_string += s; + if (m_string.length() > 100) + m_string = String::empty; +#endif + } + + void run () + { + thread() = this; + while (! threadShouldExit()) + m_service.run_one(); + } + }; + + static std::size_t const totalCalls = 10000; + + void testThreads (std::size_t n) + { + std::stringstream ss; + ss << n << " threads"; + testcase (ss.str()); + + Random r; + std::size_t const callsPerThread (totalCalls / n); + + ServiceQueue service (n); + std::vector > threads; + threads.reserve (n); + for (std::size_t i = 0; i < n; ++i) + threads.emplace_back (new ServiceThread (i + 1, + r.nextInt64(), service)); + for (std::size_t i = n * callsPerThread; i; --i) + service.dispatch (std::bind (&ServiceThread::handler)); + for (std::size_t i = 0; i < threads.size(); ++i) + service.dispatch (std::bind (&ServiceThread::stop_one)); + for (std::size_t i = 0; i < threads.size(); ++i) + threads[i]->waitForThreadToExit(); + pass(); + } + + void run() + { + testThreads (1); + testThreads (4); + testThreads (16); + } +}; + +BEAST_DEFINE_TESTSUITE(ServiceQueue,threads,beast); + +} diff --git a/src/beast/beast/unit_test.h b/src/beast/beast/unit_test.h new file mode 100644 index 0000000000..81764936e8 --- /dev/null +++ b/src/beast/beast/unit_test.h @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_H_INCLUDED +#define BEAST_UNIT_TEST_H_INCLUDED + +#include "./unit_test/amount.h" +#include "./unit_test/print.h" +#include "./unit_test/global_suites.h" +#include "./unit_test/match.h" +#include "./unit_test/recorder.h" +#include "./unit_test/reporter.h" +#include "./unit_test/results.h" +#include "./unit_test/runner.h" +#include "./unit_test/suite.h" +#include "./unit_test/suite_info.h" +#include "./unit_test/suite_list.h" + +#endif diff --git a/src/beast/beast/unit_test/README.md b/src/beast/beast/unit_test/README.md new file mode 100644 index 0000000000..0382e28270 --- /dev/null +++ b/src/beast/beast/unit_test/README.md @@ -0,0 +1,3 @@ +# beast.unit_test + +This provides a framework for defining and running unit tests. diff --git a/src/beast/beast/unit_test/amount.h b/src/beast/beast/unit_test/amount.h new file mode 100644 index 0000000000..ef95014045 --- /dev/null +++ b/src/beast/beast/unit_test/amount.h @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_AMOUNT_H_INLCUDED +#define BEAST_UNIT_TEST_AMOUNT_H_INLCUDED + +#include +#include +#include + +namespace beast { +namespace unit_test { + +/** Utility for producing nicely composed output of amounts with units. */ +class amount +{ +private: + std::size_t n; + std::string const& what; + +public: + amount (amount const&) = default; + amount& operator= (amount const&) = delete; + + amount (std::size_t n_, std::string const& what_) + : n (n_) + , what (what_) + { + } + + friend + std::ostream& + operator<< (std::ostream& s, amount const& t) + { + s << t.n << " " << t.what << ((t.n != 1) ? "s" : ""); + return s; + } +}; + +} // unit_test +} // beast + +#endif diff --git a/src/beast/modules/beast_vflib/threads/GuiServiceQueue.h b/src/beast/beast/unit_test/define_print.cpp similarity index 51% rename from src/beast/modules/beast_vflib/threads/GuiServiceQueue.h rename to src/beast/beast/unit_test/define_print.cpp index 2f8d8750bb..4777010951 100644 --- a/src/beast/modules/beast_vflib/threads/GuiServiceQueue.h +++ b/src/beast/beast/unit_test/define_print.cpp @@ -2,7 +2,6 @@ /* This file is part of Beast: https://github.com/vinniefalco/Beast Copyright 2013, Vinnie Falco - Copyright Patrick Dehne (www.sonicweb-radio.de) Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -15,58 +14,64 @@ 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 BEAST_VFLIB_GUISERVICEQUEUE_H_INCLUDED -#define BEAST_VFLIB_GUISERVICEQUEUE_H_INCLUDED +#include "amount.h" +#include "global_suites.h" +#include "suite.h" -#include "AppConfig.h" -#include "modules/juce_core/juce_core.h" -#include "modules/juce_events/juce_events.h" - -#include "CallQueue.h" +// Include this .cpp in your project to gain access to the printing suite namespace beast { +namespace unit_test { -class GuiServiceQueue -: public CallQueue -, private juce::AsyncUpdater -, private ThreadWithServiceQueue::EntryPoints +namespace detail { + +/** A suite that prints the list of globally defined suites. */ +class print_test : public suite { public: - explicit GuiServiceQueue (const String& name) - : CallQueue(name) - , m_thread(name) + static + std::string + prefix (suite_info const& s) { - bassert (juce::MessageManager::getInstance()->isThisTheMessageThread()); - - m_thread.start (this); + if (s.manual()) + return "|M| "; + return " "; } - - void close () + + void + print (suite_list &c) { - m_thread.stop (true); - - CallQueue::close (); + std::size_t manual (0); + for (auto const& s : c) + { + log << + prefix (s) << + s.full_name(); + if (s.manual()) + ++manual; + } + log << + amount (c.size(), "suite") << " total, " << + amount (manual, "manual suite") + ; } - - void enqueue (ServiceQueueBase::Item* item) + + void + run() { - CallQueue::enqueue (item); - - m_thread.call (&juce::AsyncUpdater::triggerAsyncUpdate, (AsyncUpdater*)this); + log << "------------------------------------------"; + print (global_suites()); + log << "------------------------------------------"; + pass(); } - - void handleAsyncUpdate() - { - poll(); - } - -private: - ThreadWithServiceQueue m_thread; }; +BEAST_DEFINE_TESTSUITE_MANUAL(print,unit_test,beast); + } -#endif +} +} diff --git a/src/beast/beast/unit_test/global_suites.h b/src/beast/beast/unit_test/global_suites.h new file mode 100644 index 0000000000..8fd39d5df5 --- /dev/null +++ b/src/beast/beast/unit_test/global_suites.h @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_GLOBAL_SUITES_H_INCLUDED +#define BEAST_UNIT_TEST_GLOBAL_SUITES_H_INCLUDED + +#include "suite_list.h" + +namespace beast { +namespace unit_test { + +namespace detail { + +// Non const container is a detail, users are not allowed to modify! +inline +suite_list& +global_suites() +{ + static suite_list s; + return s; +} + +// Used to insert suites during static initialization +template +struct global_suite_instance +{ + global_suite_instance (char const* name, char const* module, + char const* library, bool manual) + { + global_suites().insert ( + name, module, library, manual); + } +}; + +} // detail + +/** Holds suites registered during static initialization. */ +inline +suite_list const& +global_suites() +{ + return detail::global_suites(); +} + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/match.h b/src/beast/beast/unit_test/match.h new file mode 100644 index 0000000000..ad0d1f07cb --- /dev/null +++ b/src/beast/beast/unit_test/match.h @@ -0,0 +1,173 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_MATCH_H_INLCUDED +#define BEAST_UNIT_TEST_MATCH_H_INLCUDED + +#include "suite_info.h" + +namespace beast { +namespace unit_test { + +// Predicate for implementing matches +class selector +{ +public: + enum mode_t + { + // Run all tests except manual ones + all, + + // Run tests that match in any field + automatch, + + // Match on suite + suite, + + // Match on library + library, + + // Match on module (used internally) + module, + + // Match nothing (used internally) + none + }; + +private: + mode_t m_mode; + std::string m_pat; + std::string m_library; + +public: + explicit + selector (mode_t mode, std::string const& pattern = "") + : m_mode (mode) + , m_pat (pattern) + { + if (m_mode == automatch && pattern.empty()) + m_mode = all; + } + + bool + operator() (suite_info const& s) + { + switch (m_mode) + { + case automatch: + // check suite + if (m_pat == s.name()) + { + m_mode = none; + return true; + } + + // check module + if (m_pat == s.module()) + { + m_mode = module; + m_library = s.library(); + return ! s.manual(); + } + + // check library + if (m_pat == s.library()) + { + m_mode = library; + return ! s.manual(); + } + + return false; + + case suite: + return m_pat == s.name(); + + case module: + return m_pat == s.module() && ! s.manual(); + + case library: + return m_pat == s.library() && ! s.manual(); + + case none: + return false; + + case all: + default: + // fall through + break; + }; + + return ! s.manual(); + } +}; + +//------------------------------------------------------------------------------ + +// Utility functions for producing predicates to select suites. + +/** Returns a predicate that implements a smart matching rule. + The predicate checks the suite, module, and library fields of the + suite_info in that order. When it finds a match, it changes modes + depending on what was found: + + If a suite is matched first, then only the suite is selected. The + suite may be marked manual. + + If a module is matched first, then only suites from that module + and library not marked manual are selected from then on. + + If a library is matched first, then only suites from that library + not marked manual are selected from then on. + +*/ +inline +selector +match_auto (std::string const& name) +{ + return selector (selector::automatch, name); +} + +/** Return a predicate that matches all suites not marked manual. */ +inline +selector +match_all() +{ + return selector (selector::all); +} + +/** Returns a predicate that matches a specific suite. */ +inline +selector +match_suite (std::string const& name) +{ + return selector (selector::suite, name); +} + +/** Returns a predicate that matches all suites in a library. */ +inline +selector +match_library (std::string const& name) +{ + return selector (selector::library, name); +} + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/print.h b/src/beast/beast/unit_test/print.h new file mode 100644 index 0000000000..b4cd355e55 --- /dev/null +++ b/src/beast/beast/unit_test/print.h @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_PRINT_H_INLCUDED +#define BEAST_UNIT_TEST_PRINT_H_INLCUDED + +#include "amount.h" +#include "results.h" + +#include "../streams/abstract_ostream.h" +#include "../streams/basic_std_ostream.h" + +#include +#include + +namespace beast { +namespace unit_test { + +/** Write test results to the specified output stream. */ +/** @{ */ +inline +void +print (results const& r, abstract_ostream& stream) +{ + for (auto const& s : r) + { + for (auto const& c : s) + { + stream << + s.name() << + (c.name().empty() ? "" : ("." + c.name())); + + std::size_t i (1); + for (auto const& t : c.tests) + { + if (! t.pass) + stream << + "#" << i << + " failed: " << t.reason; + ++i; + } + } + } + + stream << + amount (r.size(), "suite") << ", " << + amount (r.cases(), "case") << ", " << + amount (r.total(), "test") << " total, " << + amount (r.failed(), "failure") + ; +} + +inline +void +print (results const& r, std::ostream& stream = std::cout) +{ + auto s (make_std_ostream (stream)); + print (r, s); +} + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/recorder.h b/src/beast/beast/unit_test/recorder.h new file mode 100644 index 0000000000..565167e750 --- /dev/null +++ b/src/beast/beast/unit_test/recorder.h @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_RECORDER_H_INLCUDED +#define BEAST_UNIT_TEST_RECORDER_H_INLCUDED + +#include "results.h" +#include "runner.h" + +namespace beast { +namespace unit_test { + +/** A test runner that stores the results. */ +class recorder : public runner +{ +private: + results m_results; + suite_results m_suite; + case_results m_case; + +public: + recorder (recorder const&) = default; + recorder& operator= (recorder const&) = default; + + recorder() + { + } + + /** Returns a report with the results of all completed suites. */ + results const& report() const + { + return m_results; + } + +private: + virtual + void + on_suite_begin (suite_info const& info) override + { + m_suite = suite_results (info.full_name()); + } + + virtual + void + on_suite_end() override + { + m_results.insert (std::move (m_suite)); + } + + virtual + void + on_case_begin (std::string const& name) override + { + m_case = case_results (name); + } + + virtual + void + on_case_end() override + { + if (m_case.tests.size() > 0) + m_suite.insert (std::move (m_case)); + } + + virtual + void + on_pass() override + { + m_case.tests.pass(); + } + + virtual + void + on_fail (std::string const& reason) override + { + m_case.tests.fail (reason); + } + + virtual + void + on_log (std::string const& s) override + { + m_case.log.insert (s); + } +}; + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/reporter.h b/src/beast/beast/unit_test/reporter.h new file mode 100644 index 0000000000..ac2937ee23 --- /dev/null +++ b/src/beast/beast/unit_test/reporter.h @@ -0,0 +1,207 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_REPORTER_H_INLCUDED +#define BEAST_UNIT_TEST_REPORTER_H_INLCUDED + +#include "amount.h" +#include "recorder.h" + +#include "../streams/abstract_ostream.h" +#include "../streams/basic_std_ostream.h" + +#include +#include + +#include +#include + +namespace beast { +namespace unit_test { + +/** A simple test runner that writes everything to a stream in real time. + The totals are output when the object is destroyed. +*/ +class reporter : public runner +{ +private: + struct case_results + { + std::string name; + std::size_t total; + std::size_t failed; + + case_results (std::string const& name_ = "") + : name (name_) + , total (0) + , failed (0) + { + } + }; + + struct suite_results + { + std::string name; + std::size_t cases; + std::size_t total; + std::size_t failed; + + explicit + suite_results (std::string const& name_ = "") + : name (name_) + , cases (0) + , total (0) + , failed (0) + { + } + + void + add (case_results const& r) + { + ++cases; + total += r.total; + failed += r.failed; + } + }; + + struct results + { + std::size_t suites; + std::size_t cases; + std::size_t total; + std::size_t failed; + + results() + : suites (0) + , cases (0) + , total (0) + , failed (0) + { + } + + void + add (suite_results const& r) + { + ++suites; + total += r.total; + cases += r.cases; + failed += r.failed; + } + }; + + boost::optional m_std_ostream; + std::reference_wrapper m_stream; + results m_results; + suite_results m_suite; + case_results m_case; + +public: + reporter (reporter const&) = delete; + reporter& operator= (reporter const&) = delete; + + explicit reporter (std::ostream& stream = std::cout) + : m_std_ostream (boost::ref (stream)) + , m_stream (*m_std_ostream) + { + } + + ~reporter() + { + m_stream.get() << + amount (m_results.suites, "suite") << ", " << + amount (m_results.cases, "case") << ", " << + amount (m_results.total, "test") << " total, " << + amount (m_results.failed, "failure") + ; + } + + explicit reporter (abstract_ostream& stream) + : m_stream (stream) + { + } + +private: + virtual + void + on_suite_begin (suite_info const& info) override + { + m_suite = suite_results (info.full_name()); + } + + virtual + void + on_suite_end() override + { + m_results.add (m_suite); + } + + virtual + void + on_case_begin (std::string const& name) override + { + m_case = case_results (name); + + m_stream.get() << + m_suite.name << + (m_case.name.empty() ? + "" : (" " + m_case.name)) + ; + } + + virtual + void + on_case_end() override + { + m_suite.add (m_case); + } + + virtual + void + on_pass() override + { + ++m_case.total; + } + + virtual + void + on_fail (std::string const& reason) override + { + ++m_case.failed; + ++m_case.total; + + m_stream.get() << + "#" << m_case.total << + " failed" << + (reason.empty() ? "" : ": ") << reason + ; + } + + virtual + void + on_log (std::string const& s) override + { + m_stream.get() << + s; + } +}; + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/results.h b/src/beast/beast/unit_test/results.h new file mode 100644 index 0000000000..6dcecd84dc --- /dev/null +++ b/src/beast/beast/unit_test/results.h @@ -0,0 +1,256 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_RESULTS_H_INLCUDED +#define BEAST_UNIT_TEST_RESULTS_H_INLCUDED + +#include "../container/const_container.h" + +#include +#include + +namespace beast { +namespace unit_test { + +/** Holds a set of test condition outcomes in a testcase. */ +class case_results +{ +public: + /** Holds the result of evaluating one test condition. */ + struct test + { + explicit test (bool pass_) + : pass (pass_) + { + } + + test (bool pass_, std::string const& reason_) + : pass (pass_) + , reason (reason_) + { + } + + bool pass; + std::string reason; + }; + +private: + class tests_t + : public const_container > + { + private: + std::size_t m_failed; + + public: + tests_t () + : m_failed (0) + { + } + + /** Returns the total number of test conditions. */ + std::size_t + total() const + { + return cont().size(); + } + + /** Returns the number of failed test conditions. */ + std::size_t + failed() const + { + return m_failed; + } + + /** Register a successful test condition. */ + void + pass() + { + cont().emplace_back (true); + } + + /** Register a failed test condition. */ + void + fail (std::string const& reason = "") + { + ++m_failed; + cont().emplace_back (false, reason); + } + }; + + class log_t + : public const_container > + { + public: + /** Insert a string into the log. */ + void + insert (std::string const& s) + { + cont().push_back (s); + } + }; + + std::string m_name; + +public: + explicit case_results (std::string const& name = "") + : m_name (name) + { + } + + /** Returns the name of this testcase. */ + std::string const& + name() const + { + return m_name; + } + + /** Memberspace for a container of test condition outcomes. */ + tests_t tests; + + /** Memberspace for a container of testcase log messages. */ + log_t log; +}; + +//-------------------------------------------------------------------------- + +/** Holds the set of testcase results in a suite. */ +class suite_results + : public const_container > +{ +private: + std::string m_name; + std::size_t m_total; + std::size_t m_failed; + +public: + explicit suite_results (std::string const& name = "") + : m_name (name) + , m_total (0) + , m_failed (0) + { + } + + /** Returns the name of this suite. */ + std::string const& + name() const + { + return m_name; + } + + /** Returns the total number of test conditions. */ + std::size_t + total() const + { + return m_total; + } + + /** Returns the number of failures. */ + std::size_t + failed() const + { + return m_failed; + } + + /** Insert a set of testcase results. */ + /** @{ */ + void + insert (case_results&& r) + { + cont().emplace_back (std::move (r)); + m_total += r.tests.total(); + m_failed += r.tests.failed(); + } + + void + insert (case_results const& r) + { + cont().push_back (r); + m_total += r.tests.total(); + m_failed += r.tests.failed(); + } + /** @} */ +}; + +//------------------------------------------------------------------------------ + +// VFALCO TODO Make this a template class using scoped allocators +/** Holds the results of running a set of testsuites. */ +class results + : public const_container > +{ +private: + std::size_t m_cases; + std::size_t m_total; + std::size_t m_failed; + +public: + results() + : m_cases (0) + , m_total (0) + , m_failed (0) + { + } + + /** Returns the total number of test cases. */ + std::size_t + cases() const + { + return m_cases; + } + + /** Returns the total number of test conditions. */ + std::size_t + total() const + { + return m_total; + } + + /** Returns the number of failures. */ + std::size_t + failed() const + { + return m_failed; + } + + /** Insert a set of suite results. */ + /** @{ */ + void + insert (suite_results&& r) + { + m_cases += r.size(); + m_total += r.total(); + m_failed += r.failed(); + cont().emplace_back (std::move (r)); + } + + void + insert (suite_results const& r) + { + m_cases += r.size(); + m_total += r.total(); + m_failed += r.failed(); + cont().push_back (r); + } + /** @} */ +}; + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/runner.h b/src/beast/beast/unit_test/runner.h new file mode 100644 index 0000000000..d2b55e7521 --- /dev/null +++ b/src/beast/beast/unit_test/runner.h @@ -0,0 +1,272 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_RUNNER_H_INCLUDED +#define BEAST_UNIT_TEST_RUNNER_H_INCLUDED + +#include "suite_info.h" + +#include "../streams/abstract_ostream.h" + +#include +#include + +namespace beast { +namespace unit_test { + +/** Unit test runner interface. + Derived classes can customize the reporting behavior. This interface is + injected into the unit_test class to receive the results of the tests. +*/ +class runner +{ +private: + // Reroutes log output to the runner + class stream_t : public abstract_ostream + { + private: + runner& m_owner; + + public: + stream_t() = delete; + stream_t& operator= (stream_t const&) = delete; + + stream_t (runner& owner) + : m_owner (owner) + { + } + + void + write (string_type const& s) + { + m_owner.log (s); + } + }; + + stream_t m_stream; + bool m_default; + bool m_failed; + bool m_cond; + +public: + virtual ~runner() = default; + runner (runner const&) = default; + runner& operator= (runner const&) = default; + + runner() + : m_stream (*this) + , m_default (false) + , m_failed (false) + , m_cond (false) + { + } + + /** Run the specified suite. + @return `true` if any conditions failed. + */ + bool + run (suite_info const& s) + { + // Enable 'default' testcase + m_default = true; + m_failed = false; + on_suite_begin (s); + s.run (*this); + // Forgot to call pass or fail. + assert (m_cond); + on_case_end(); + on_suite_end(); + return m_failed; + } + + /** Run a sequence of suites. + The expression + `FwdIter::value_type` + must be convertible to `suite_info`. + @return `true` if any conditions failed. + */ + template + bool + run (FwdIter first, FwdIter last) + { + bool failed (false); + for (;first != last; ++first) + failed = run (*first) || failed; + return failed; + } + + /** Conditionally run a sequence of suites. + pred will be called as: + @code + bool pred (suite_info const&); + @endcode + @return `true` if any conditions failed. + */ + template + bool + run_if (FwdIter first, FwdIter last, Pred pred = Pred()) + { + bool failed (false); + for (;first != last; ++first) + if (pred (*first)) + failed = run (*first) || failed; + return failed; + } + + /** Run all suites in a container. + @return `true` if any conditions failed. + */ + template + bool + run_each (SequenceContainer const& c) + { + bool failed (false); + for (auto const& s : c) + failed = run (s) || failed; + return failed; + } + + /** Conditionally run suites in a container. + pred will be called as: + @code + bool pred (suite_info const&); + @endcode + @return `true` if any conditions failed. + */ + template + bool + run_each_if (SequenceContainer const& c, Pred pred = Pred()) + { + bool failed (false); + for (auto const& s : c) + if (pred (s)) + failed = run (s) || failed; + return failed; + } + +private: + // + // Overrides + // + + /** Called when a new suite starts. */ + virtual + void + on_suite_begin (suite_info const&) + { + } + + /** Called when a suite ends. */ + virtual + void + on_suite_end() + { + } + + /** Called when a new case starts. */ + virtual + void + on_case_begin (std::string const&) + { + } + + /** Called when a new case ends. */ + virtual + void + on_case_end() + { + } + + /** Called for each passing condition. */ + virtual + void + on_pass () + { + } + + /** Called for each failing condition. */ + virtual + void + on_fail (std::string const&) + { + } + + /** Called when a test logs output. */ + virtual + void + on_log (std::string const&) + { + } + +private: + friend class suite; + + abstract_ostream& + stream() + { + return m_stream; + } + + // Start a new testcase. + void + testcase (std::string const& name) + { + // Name may not be empty + assert (m_default || ! name.empty()); + // Forgot to call pass or fail + assert (m_default || m_cond); + if (! m_default) + on_case_end(); + m_default = false; + m_cond = false; + on_case_begin (name); + } + + void + pass() + { + if (m_default) + testcase (""); + on_pass(); + m_cond = true; + } + + void + fail (std::string const& reason) + { + if (m_default) + testcase (""); + on_fail (reason); + m_failed = true; + m_cond = true; + } + + void + log (std::string const& s) + { + if (m_default) + testcase (""); + on_log (s); + } +}; + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/suite.h b/src/beast/beast/unit_test/suite.h new file mode 100644 index 0000000000..1bd157be1a --- /dev/null +++ b/src/beast/beast/unit_test/suite.h @@ -0,0 +1,289 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_SUITE_H_INCLUDED +#define BEAST_UNIT_TEST_SUITE_H_INCLUDED + +#include "runner.h" + +#include "../utility/noexcept.h" +#include + +namespace beast { +namespace unit_test { + +/** A testsuite class. + Derived classes execute a series of testcases, where each testcase is + a series of pass/fail tests. To provide a unit test using this class, + derive from it and use the BEAST_DEFINE_UNIT_TEST macro in a + translation unit. +*/ +class suite +{ +private: + // This exception is thrown internally to stop the current suite + // in the event of a failure, if the option to stop is set. + struct abort_exception : public std::exception + { + char const* + what() const noexcept override + { + return "suite aborted on failed condition"; + } + }; + + // Memberspace + class log_t + { + private: + friend class suite; + runner* m_runner; + + runner* + operator-> () + { + return m_runner; + } + + public: + log_t () + : m_runner (nullptr) + { + } + + template + abstract_ostream::scoped_stream_type + operator<< (T const& t) + { + return m_runner->stream() << t; + } + + /** Returns the raw stream used for output. */ + abstract_ostream& + stream() + { + return m_runner->stream(); + } + }; + + bool m_abort = false; + +public: + /** Type for scoped stream logging. + To use this type, declare a local variable of the type + on the stack in derived class member function and construct + it from log.stream(); + + @code + + scoped_stream ss (log.stream(); + + ss << "Hello" << std::endl; + ss << "world" << std::endl; + + @endcode + + Streams constructed in this fashion will not have the line + ending automatically appended. + + Thread safety: + + The scoped_stream may only be used by one thread. + Multiline output sent to the stream will be atomically + written to the underlying abstract_Ostream + */ + typedef abstract_ostream::scoped_stream_type scoped_stream; + + /** Memberspace for logging. */ + log_t log; + + /** Invokes the test using the specified runner. + Data members are set up here instead of the constructor as a + convenience to writing the derived class to avoid repetition of + forwarded constructor arguments to the base. + Normally this is called by the framework for you. + */ + void + operator() (runner& r) + { + log.m_runner = &r; + + try + { + run(); + } + catch (abort_exception const&) + { + // ends the suite + } + catch (std::exception const& e) + { + fail (std::string ("unhandled exception: ") + + std::string (e.what())); + } + catch (...) + { + fail ("unhandled exception"); + } + } + + enum abort_t + { + no_abort_on_fail, + abort_on_fail + }; + + /** Open a new testcase. + A testcase is a series of evaluated test conditions. A test suite + may have multiple test cases. A test is associated with the last + opened testcase. When the test first runs, a default unnamed + case is opened. Tests with only one case may omit the call + to testcase. + @param abort If `true`, the suite will be stopped on first failure. + */ + void + testcase (std::string const& name, + abort_t abort = no_abort_on_fail) + { + m_abort = abort == abort_on_fail; + log->testcase (name); + } + + /** Evaluate a test condition. + The condition is passed as a template argument instead of `bool` so + that implicit conversion is not required. The `reason` argument is + logged if the condition is false. + @return `true` if the test condition indicates success. + */ + template + bool + expect (Condition shouldBeTrue, std::string const& reason = "") + { + if (shouldBeTrue) + pass(); + else + fail (reason); + return shouldBeTrue; + } + + // DEPRECATED + // @return `true` if the test condition indicates success (a false value) + template + bool + unexpected (Condition shouldBeFalse, std::string const& reason = "") + { + if (! shouldBeFalse) + pass(); + else + fail (reason); + return ! shouldBeFalse; + } + + /** Record a successful test condition. */ + void + pass() + { + log->pass(); + } + + /** Record a failure. */ + void + fail (std::string const& reason= "") + { + log->fail (reason); + if (m_abort) + throw abort_exception(); + } + +private: + /** Runs the suite. */ + virtual + void + run() = 0; +}; + +} // unit_test +} // beast + +//------------------------------------------------------------------------------ + +// detail: +// This inserts the suite with the given manual flag +#define BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,manual) \ + static beast::unit_test::detail::global_suite_instance \ + Library ## Module ## Class ## _test_instance ( \ + #Class, #Module, #Library, manual); + +//------------------------------------------------------------------------------ + +// Preprocessor directives for controlling unit test definitions. + +// If this is already defined, don't redefine it. This allows +// programs to provide custom behavior for testsuite definitions +// +#ifndef BEAST_DEFINE_TESTSUITE + +/** Enables insertion of test suites into the global container. + The default is to insert all test suite definitions into the global + container. If BEAST_DEFINE_TESTSUITE is user defined, this macro + has no effect. +*/ +#ifndef BEAST_NO_UNIT_TEST_INLINE +#define BEAST_NO_UNIT_TEST_INLINE 0 +#endif + +/** Define a unit test suite. + + Class The type representing the class being tested. + Module Identifies the module. + Library Identifies the library. + + The declaration for the class implementing the test should be the same + as Class ## _test. For example, if Class is aged_ordered_container, the + test class must be declared as: + + @code + + struct aged_ordered_container_test : beast::unit_test::suite + { + //... + }; + + @endcode + + The macro invocation must appear in the same namespace as the test class. +*/ + +#if BEAST_NO_UNIT_TEST_INLINE +#define BEAST_DEFINE_TESTSUITE(Class,Module,Library) + +#else +#include "global_suites.h" +#define BEAST_DEFINE_TESTSUITE(Class,Module,Library) \ + BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,false) +#define BEAST_DEFINE_TESTSUITE_MANUAL(Class,Module,Library) \ + BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,true) + +#endif + +#endif + +//------------------------------------------------------------------------------ + +#endif diff --git a/src/beast/beast/unit_test/suite_info.h b/src/beast/beast/unit_test/suite_info.h new file mode 100644 index 0000000000..ca86236f77 --- /dev/null +++ b/src/beast/beast/unit_test/suite_info.h @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_SUITE_INFO_H_INCLUDED +#define BEAST_UNIT_TEST_SUITE_INFO_H_INCLUDED + +#include +#include +#include + +namespace beast { +namespace unit_test { + +class runner; + +/** Associates a unit test type with metadata. */ +class suite_info +{ +private: + typedef std::function run_type; + + char const* m_name; + char const* m_module; + char const* m_library; + bool m_manual; + run_type m_run; + +public: + suite_info ( + char const* name, + char const* module, + char const* library, + bool manual, + run_type run) + : m_name (name) + , m_module (module) + , m_library (library) + , m_manual (manual) + , m_run (std::move (run)) + { + } + + char const* + name() const + { + return m_name; + } + + char const* + module() const + { + return m_module; + } + + char const* + library() const + { + return m_library; + } + + /** Returns `true` if this suite only runs manually. */ + bool + manual() const + { + return m_manual; + } + + /** Return the canonical suite name as a string. */ + std::string + full_name() const + { + return + std::string (m_library) + "." + + std::string (m_module) + "." + + std::string (m_name); + } + + /** Run a new instance of the associated test suite. */ + void + run (runner& r) const + { + m_run (r); + } +}; + +inline +bool +operator< (suite_info const& lhs, suite_info const& rhs) +{ + return lhs.full_name() < rhs.full_name(); +} + +/** Convenience for producing suite_info for a given test type. */ +template +suite_info make_suite_info (char const* name, char const* module, + char const* library, bool manual) +{ + return suite_info (name, module, library, manual, + [](runner& r) + { + Suite test; + return test (r); + }); +} + +} // unit_test +} // beast + +#endif diff --git a/src/beast/beast/unit_test/suite_list.h b/src/beast/beast/unit_test/suite_list.h new file mode 100644 index 0000000000..3cc534fcdf --- /dev/null +++ b/src/beast/beast/unit_test/suite_list.h @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +/* + 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 BEAST_UNIT_TEST_SUITE_LIST_H_INCLUDED +#define BEAST_UNIT_TEST_SUITE_LIST_H_INCLUDED + +#include "suite_info.h" + +#include "../container/const_container.h" + +#include +//#include +#include +#include +#include + +namespace beast { +namespace unit_test { + +/** A container of test suites. */ +class suite_list + : public const_container < + std::set + //std::list + > +{ +private: +#ifndef NDEBUG + std::unordered_set m_names; + std::unordered_set m_classes; +#endif + +public: + /** Insert a suite into the set. + The suite must not already exist. + */ + template + void + insert (char const* name, + char const* module, char const* library, + bool manual) + { + #ifndef NDEBUG + { + auto const result (m_names.insert (name)); + assert (result.second); // Duplicate name + } + + { + auto const result (m_classes.insert ( + std::type_index (typeid(Suite)))); + assert (result.second); // Duplicate type + } + #endif + + cont().emplace (std::move (make_suite_info ( + name, module, library, manual))); + } +}; + +} // unit_test +} // beast + +#endif + diff --git a/src/beast/beast/utility/Utility.cpp b/src/beast/beast/utility/Utility.cpp index 48175d75bd..9b42c0733c 100644 --- a/src/beast/beast/utility/Utility.cpp +++ b/src/beast/beast/utility/Utility.cpp @@ -26,10 +26,11 @@ // For Journal and Debug #include "../../modules/beast_core/beast_core.h" -#include "impl/Assert.cpp" #include "impl/Debug.cpp" #include "impl/Journal.cpp" #include "impl/LeakChecked.cpp" #include "impl/StaticObject.cpp" #include "impl/PropertyStream.cpp" + +#include "tests/bassert.test.cpp" #include "tests/empty_base_optimization.test.cpp" diff --git a/src/beast/beast/utility/impl/Debug.cpp b/src/beast/beast/utility/impl/Debug.cpp index d3a26e0aad..8448e1888e 100644 --- a/src/beast/beast/utility/impl/Debug.cpp +++ b/src/beast/beast/utility/impl/Debug.cpp @@ -17,6 +17,9 @@ */ //============================================================================== +#include "../Debug.h" +#include "../../unit_test/suite.h" + namespace beast { namespace Debug { @@ -299,7 +302,7 @@ String commandLineToString (const String& commandLine) // A simple unit test to determine the diagnostic settings in a build. // -class DebugTests : public UnitTest +class Debug_test : public unit_test::suite { public: static int envDebug () @@ -329,25 +332,34 @@ public: #endif } - void runTest () + void run () { - beginTestCase ("diagnostics"); + log << + "operatingSystemName = '" << + SystemStats::getOperatingSystemName () << "'"; + + log << + "_DEBUG = " << + String::fromNumber (envDebug ()); + + log << + "BEAST_DEBUG = " << + String::fromNumber (beastDebug ()); + + log << + "BEAST_FORCE_DEBUG = " << + String::fromNumber (beastForceDebug ()); + + log << + "sizeof(std::size_t) = " << + String::fromNumber (sizeof(std::size_t)); - logMessage ("operatingSystemName = '" + SystemStats::getOperatingSystemName () + "'"); - logMessage ("_DEBUG = " + String::fromNumber (envDebug ())); - logMessage ("BEAST_DEBUG = " + String::fromNumber (beastDebug ())); - logMessage ("BEAST_FORCE_DEBUG = " + String::fromNumber (beastForceDebug ())); - logMessage ("sizeof(std::size_t) = " + String::fromNumber (sizeof(std::size_t))); bassertfalse; fail (); } - - DebugTests () : UnitTest ("Debug", "beast", runManual) - { - } }; -static DebugTests debugTests; +BEAST_DEFINE_TESTSUITE_MANUAL(Debug,utility,beast); } diff --git a/src/beast/beast/utility/impl/PropertyStream.cpp b/src/beast/beast/utility/impl/PropertyStream.cpp index f3b6e7509d..7ea88bb388 100644 --- a/src/beast/beast/utility/impl/PropertyStream.cpp +++ b/src/beast/beast/utility/impl/PropertyStream.cpp @@ -18,6 +18,7 @@ //============================================================================== #include "../PropertyStream.h" +#include "../../unit_test/suite.h" #include #include @@ -606,7 +607,7 @@ void PropertyStream::add (long double value) //------------------------------------------------------------------------------ -class PropertyStreamTests : public UnitTest +class PropertyStream_test : public unit_test::suite { public: typedef PropertyStream::Source Source; @@ -622,8 +623,8 @@ public: } catch (...) { - failException (); - } + fail ("unhandled exception");; + } } void test_peel_leading_slash (std::string s, std::string const& expected, @@ -637,7 +638,7 @@ public: } catch(...) { - failException (); + fail ("unhandled exception");; } } @@ -652,7 +653,7 @@ public: } catch (...) { - failException (); + fail ("unhandled exception");; } } @@ -665,7 +666,7 @@ public: } catch (...) { - failException (); + fail ("unhandled exception");; } } @@ -679,7 +680,7 @@ public: } catch (...) { - failException (); + fail ("unhandled exception");; } } @@ -693,7 +694,7 @@ public: } catch(...) { - failException (); + fail ("unhandled exception");; } } @@ -708,11 +709,11 @@ public: } catch (...) { - failException (); + fail ("unhandled exception");; } } - void runTest() + void run() { Source a ("a"); Source b ("b"); @@ -733,19 +734,19 @@ public: b.add ( e ); d.add ( f ); - beginTestCase ("peel_name"); + testcase ("peel_name"); test_peel_name ("a", "a", ""); test_peel_name ("foo/bar", "foo", "bar"); test_peel_name ("foo/goo/bar", "foo", "goo/bar"); test_peel_name ("", "", ""); - beginTestCase ("peel_leading_slash"); + testcase ("peel_leading_slash"); test_peel_leading_slash ("foo/", "foo/", false); test_peel_leading_slash ("foo", "foo", false); test_peel_leading_slash ("/foo/", "foo/", true); test_peel_leading_slash ("/foo", "foo", true); - beginTestCase ("peel_trailing_slashstar"); + testcase ("peel_trailing_slashstar"); test_peel_trailing_slashstar ("/foo/goo/*", "/foo/goo", true); test_peel_trailing_slashstar ("foo/goo/*", "foo/goo", true); test_peel_trailing_slashstar ("/foo/goo/", "/foo/goo", false); @@ -757,13 +758,13 @@ public: test_peel_trailing_slashstar ("**", "*", true); test_peel_trailing_slashstar ("*/", "*", false); - beginTestCase ("find_one"); + testcase ("find_one"); test_find_one (a, &b, "b"); test_find_one (a, nullptr, "d"); test_find_one (b, &e, "e"); test_find_one (d, &f, "f"); - beginTestCase ("find_path"); + testcase ("find_path"); test_find_path (a, "a", nullptr); test_find_path (a, "e", nullptr); test_find_path (a, "a/b", nullptr); @@ -774,14 +775,14 @@ public: test_find_path (a, "b/e", &e); test_find_path (a, "b/d/f", &f); - beginTestCase ("find_one_deep"); + testcase ("find_one_deep"); test_find_one_deep (a, "z", nullptr); test_find_one_deep (a, "g", &g); test_find_one_deep (a, "b", &b); test_find_one_deep (a, "d", &d); test_find_one_deep (a, "f", &f); - beginTestCase ("find"); + testcase ("find"); test_find (a, "", &a, false); test_find (a, "*", &a, true); test_find (a, "/b", &b, false); @@ -798,14 +799,9 @@ public: test_find (a, "/d*", nullptr, true); test_find (a, "/d/*", nullptr, true); } - - PropertyStreamTests () - : UnitTest ("PropertyStream", "beast") - { - } }; -static PropertyStreamTests propertyStreamTests; +BEAST_DEFINE_TESTSUITE(PropertyStream,utility,beast); } diff --git a/src/beast/beast/utility/impl/Assert.cpp b/src/beast/beast/utility/tests/bassert.test.cpp similarity index 78% rename from src/beast/beast/utility/impl/Assert.cpp rename to src/beast/beast/utility/tests/bassert.test.cpp index d7503cc21f..2da5c702aa 100644 --- a/src/beast/beast/utility/impl/Assert.cpp +++ b/src/beast/beast/utility/tests/bassert.test.cpp @@ -17,21 +17,23 @@ */ //============================================================================== -namespace beast { +#include "../../Config.h" -class BassertUnitTests : public UnitTest +#include "../../unit_test/suite.h" + +namespace beast { + +// This demonstrates what happens when a bassert condition fails +class bassert_test : public unit_test::suite { public: - void runTest () + void run () { - beginTestCase ("bassert"); bassert (false); + pass(); } - - BassertUnitTests () : UnitTest ("bassert", "beast", runManual) { } }; -//------------------------------------------------------------------------------ +BEAST_DEFINE_TESTSUITE_MANUAL(bassert,utility,beast); -static BassertUnitTests bassertUnitTests; -} +} // beast diff --git a/src/beast/beast/utility/tests/empty_base_optimization.test.cpp b/src/beast/beast/utility/tests/empty_base_optimization.test.cpp index 54c9674148..57c57287aa 100644 --- a/src/beast/beast/utility/tests/empty_base_optimization.test.cpp +++ b/src/beast/beast/utility/tests/empty_base_optimization.test.cpp @@ -23,12 +23,12 @@ #include "../empty_base_optimization.h" -#include "../../../modules/beast_core/beast_core.h" // for UnitTest +#include "../../unit_test/suite.h" namespace beast { -class empty_base_optimization_Tests - : public UnitTest +class empty_base_optimization_test + : public unit_test::suite { public: template @@ -94,20 +94,14 @@ public: } void - runTest () + run () { - beginTestCase ("empty_base_optimization"); expect (test_one()); expect (test_two()); pass (); } - - empty_base_optimization_Tests() - : UnitTest ("empty_base_optimization", "beast") - { - } }; -static empty_base_optimization_Tests empty_base_optimization_tests; +BEAST_DEFINE_TESTSUITE(empty_base_optimization,utility,beast); -} // beast +} // beast diff --git a/src/beast/modules/beast_asio/beast_asio.cpp b/src/beast/modules/beast_asio/beast_asio.cpp index 7e21a743aa..6c95da660e 100644 --- a/src/beast/modules/beast_asio/beast_asio.cpp +++ b/src/beast/modules/beast_asio/beast_asio.cpp @@ -51,8 +51,6 @@ #include "tests/TestPeerLogicAsyncClient.cpp" #include "tests/TestPeerUnitTests.cpp" -#include "system/BoostUnitTests.cpp" - #include "http/HTTPParser.cpp" #include "http/HTTPRequestParser.cpp" #include "http/HTTPResponseParser.cpp" diff --git a/src/beast/modules/beast_asio/http/HTTPClientType.cpp b/src/beast/modules/beast_asio/http/HTTPClientType.cpp index 2cb043ccc8..dae2052d5e 100644 --- a/src/beast/modules/beast_asio/http/HTTPClientType.cpp +++ b/src/beast/modules/beast_asio/http/HTTPClientType.cpp @@ -19,6 +19,7 @@ #include "../../../beast/asio/wrap_handler.h" #include "../../../beast/asio/placeholders.h" +#include "../../../beast/unit_test/suite.h" namespace beast { namespace asio { @@ -545,7 +546,7 @@ HTTPClientBase* HTTPClientBase::New (Journal journal, //------------------------------------------------------------------------------ -class HTTPClientTests : public UnitTest +class HTTPClient_test : public unit_test::suite { public: typedef boost::system::error_code error_code; @@ -592,35 +593,38 @@ public: //-------------------------------------------------------------------------- - void log (HTTPMessage const& m) + void print (HTTPMessage const& m) { for (std::size_t i = 0; i < m.headers().size(); ++i) { HTTPField const f (m.headers()[i]); - String s; - s = "[ '" + f.name() + - "' , '" + f.value() + "' ]"; - logMessage (s); + std::stringstream ss; + log << + "[ '" << f.name() << + "' , '" << f.value() + "' ]"; } } - void log (HTTPClientBase::error_type error, HTTPClientBase::value_type const& response) + void print (HTTPClientBase::error_type error, + HTTPClientBase::value_type const& response) { if (error != 0) { - logMessage (String ( - "HTTPClient error: '" + error.message() + "'")); + log << + "HTTPClient error: '" + error.message() << "'"; } else if (! response.empty ()) { - logMessage (String ("Status: ") + - String::fromNumber (response->status())); + log << + "Status: " << + String::fromNumber (response->status()).toStdString(); - log (*response); + print (*response); } else { - logMessage ("HTTPClient: no response"); + log << + "HTTPClient: no response"; } } @@ -628,7 +632,7 @@ public: void handle_get (HTTPClientBase::result_type result) { - log (result.first, result.second); + print (result.first, result.second); } void testSync (String const& s, double timeoutSeconds) @@ -639,7 +643,7 @@ public: HTTPClientBase::result_type const& result ( client->get (ParsedURL (s).url ())); - log (result.first, result.second); + print (result.first, result.second); } void testAsync (String const& s, double timeoutSeconds) @@ -649,7 +653,7 @@ public: HTTPClientBase::New (Journal(), timeoutSeconds)); client->async_get (t.get_io_service (), ParsedURL (s).url (), - beast::bind (&HTTPClientTests::handle_get, this, + beast::bind (&HTTPClient_test::handle_get, this, beast::_1)); t.start (); @@ -658,10 +662,8 @@ public: //-------------------------------------------------------------------------- - void runTest () + void run () { - beginTestCase ("HTTPClient::get"); - testSync ( "http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference.html", 5); @@ -676,13 +678,9 @@ public: pass (); } - - HTTPClientTests () : UnitTest ("HttpClient", "beast", runManual) - { - } }; -static HTTPClientTests httpClientTests; +BEAST_DEFINE_TESTSUITE_MANUAL(HTTPClient,beast_asio,beast); } } diff --git a/src/beast/modules/beast_asio/system/BoostIncludes.h b/src/beast/modules/beast_asio/system/BoostIncludes.h index 1a5c45df83..609041cb87 100644 --- a/src/beast/modules/beast_asio/system/BoostIncludes.h +++ b/src/beast/modules/beast_asio/system/BoostIncludes.h @@ -52,33 +52,9 @@ #include #include #include +#include // work-around for broken #include "../../../beast/boost/get_pointer.h" -// Continuation hooks added in 1.54.0 -#ifndef BEAST_ASIO_HAS_CONTINUATION_HOOKS -# if BOOST_VERSION >= 105400 -# define BEAST_ASIO_HAS_CONTINUATION_HOOKS 1 -# else -# define BEAST_ASIO_HAS_CONTINUATION_HOOKS 0 -# endif -#endif -#if BEAST_ASIO_HAS_CONTINUATION_HOOKS -# include -#endif - -//------------------------------------------------------------------------------ - -// Configure some options based on the version of boost -#if BOOST_VERSION >= 105400 -# ifndef BEAST_ASIO_HAS_BUFFEREDHANDSHAKE -# define BEAST_ASIO_HAS_BUFFEREDHANDSHAKE 1 -# endif -#else -# ifndef BEAST_ASIO_HAS_BUFFEREDHANDSHAKE -# define BEAST_ASIO_HAS_BUFFEREDHANDSHAKE 0 -# endif -#endif - #endif diff --git a/src/beast/modules/beast_asio/system/BoostUnitTests.cpp b/src/beast/modules/beast_asio/system/BoostUnitTests.cpp deleted file mode 100644 index 8995e564d6..0000000000 --- a/src/beast/modules/beast_asio/system/BoostUnitTests.cpp +++ /dev/null @@ -1,86 +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. -*/ -//============================================================================== - -namespace beast { - -/** Test for showing information about the build of boost. -*/ -class BoostUnitTests : public UnitTest -{ -public: - struct BoostVersion - { - explicit BoostVersion (int value) - : vmajor (value / 100000) - , vminor ((value / 100) % 100) - , vpatch (value % 100) - { - } - - String toString () const noexcept - { - return String (vmajor) + "." + - String (vminor).paddedLeft ('0', 2) + "." + - String (vpatch).paddedLeft ('0', 2); - } - - int vmajor; - int vminor; - int vpatch; - }; - - enum - { - minimumVersion = 104700 - }; - - // To prevent constant conditional expression warning - static int getMinimumVersion () - { - return minimumVersion; - } - - void runTest () - { - beginTestCase ("version"); - - BoostVersion version (BOOST_VERSION); - - logMessage (String ("BOOST_VERSION = " + version.toString ())); - logMessage (String ("BOOST_LIB_VERSION = '") + BOOST_LIB_VERSION + "'"); - - if (BOOST_VERSION >= getMinimumVersion ()) - { - pass (); - } - else - { - fail (String ("Boost version is below ") + - BoostVersion (minimumVersion).toString ()); - } - } - - BoostUnitTests () : UnitTest ("boost", "beast") - { - } -}; - -static BoostUnitTests boostUnitTests; - -} diff --git a/src/beast/modules/beast_asio/tests/PeerTest.cpp b/src/beast/modules/beast_asio/tests/PeerTest.cpp index 2666a92436..54bc467c5c 100644 --- a/src/beast/modules/beast_asio/tests/PeerTest.cpp +++ b/src/beast/modules/beast_asio/tests/PeerTest.cpp @@ -65,11 +65,14 @@ String PeerTest::Result::message () const noexcept return m_message; } -bool PeerTest::Result::report (UnitTest& test, bool reportPassingTests) const +bool PeerTest::Result::report (unit_test::suite& suite, + bool reportPassingTests) const { - bool const success = test.unexpected (failed (), message ()); + bool const success = suite.expect (! failed (), + message ().toStdString()); if (reportPassingTests && success) - test.logMessage (String ("pass ") + message()); + suite.log << + "pass " + message().toStdString(); return success; } @@ -90,14 +93,15 @@ bool PeerTest::Results::operator!= (Results const& other) const noexcept return (client != other.client) || (server != other.server); } -bool PeerTest::Results::report (UnitTest& test, bool beginTestCase) const +bool PeerTest::Results::report (unit_test::suite& suite, + bool beginTestCase) const { if (beginTestCase) - test.beginTestCase (name); + suite.testcase (name.toStdString()); bool success = true; - if (! client.report (test)) + if (! client.report (suite)) success = false; - if (! server.report (test)) + if (! server.report (suite)) success = false; return success; } diff --git a/src/beast/modules/beast_asio/tests/PeerTest.h b/src/beast/modules/beast_asio/tests/PeerTest.h index 7f1f5f9ff1..6020db5d65 100644 --- a/src/beast/modules/beast_asio/tests/PeerTest.h +++ b/src/beast/modules/beast_asio/tests/PeerTest.h @@ -20,6 +20,8 @@ #ifndef BEAST_ASIO_TESTS_PEERTEST_H_INCLUDED #define BEAST_ASIO_TESTS_PEERTEST_H_INCLUDED +#include "../../../beast/unit_test/suite.h" + namespace beast { namespace asio { @@ -67,14 +69,15 @@ public: bool timedout () const noexcept; /** Provides a descriptive message. - This is suitable to pass to UnitTest::fail. + This is suitable to pass to suite::fail. */ String message () const noexcept; - /** Report the result to a UnitTest object. + /** Report the result to a testsuite. A return value of true indicates success. */ - bool report (UnitTest& test, bool reportPassingTests = false) const; + bool report (unit_test::suite& suite, + bool reportPassingTests = false) const; private: boost::system::error_code m_ec; @@ -97,19 +100,21 @@ public: bool operator== (Results const& other) const noexcept; bool operator!= (Results const& other) const noexcept; - /** Report the results to a UnitTest object. + /** Report the results to a suite object. A return value of true indicates success. @param beginTestCase `true` to call test.beginTestCase for you */ - bool report (UnitTest& test, bool beginTestCase = true) const; + bool report (unit_test::suite& suite, bool beginTestCase = true) const; }; //-------------------------------------------------------------------------- /** Test two peers and return the results. */ - template - static Results run (ClientArg const& clientArg, ServerArg const& serverArg, int timeoutSeconds = defaultTimeoutSeconds) + template + static Results run (ClientArg const& clientArg, ServerArg const& serverArg, + int timeoutSeconds = defaultTimeoutSeconds) { Results results; @@ -199,42 +204,40 @@ public: return results; } - template + template static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds) { - return run (arg, arg, timeoutSeconds); + return run ( + arg, arg, timeoutSeconds); } //-------------------------------------------------------------------------- - /** Reports tests of Details for all known asynchronous logic combinations to a UnitTest. - */ - template - static void report_async (UnitTest& test, Arg const& arg, + template + static void report_async (unit_test::suite& suite, Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds, bool beginTestCase = true) { run - (arg, timeoutSeconds).report (test, beginTestCase); + (arg, timeoutSeconds).report (suite, 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) + template + static + void + report (unit_test::suite& suite, Arg const& arg, + int timeoutSeconds = defaultTimeoutSeconds, bool beginTestCase = true) { run - (arg, timeoutSeconds).report (test, beginTestCase); + (arg, timeoutSeconds).report (suite, beginTestCase); run - (arg, timeoutSeconds).report (test, beginTestCase); + (arg, timeoutSeconds).report (suite, beginTestCase); run - (arg, timeoutSeconds).report (test, beginTestCase); + (arg, timeoutSeconds).report (suite, beginTestCase); - report_async
(test, arg, timeoutSeconds, beginTestCase); + report_async
(suite, arg, timeoutSeconds, beginTestCase); } }; diff --git a/src/beast/modules/beast_asio/tests/TestPeerUnitTests.cpp b/src/beast/modules/beast_asio/tests/TestPeerUnitTests.cpp index fa600a82a7..22dfc77278 100644 --- a/src/beast/modules/beast_asio/tests/TestPeerUnitTests.cpp +++ b/src/beast/modules/beast_asio/tests/TestPeerUnitTests.cpp @@ -17,11 +17,13 @@ */ //============================================================================== +#include "../../../beast/unit_test/suite.h" + namespace beast { namespace asio { -/** UnitTest for the TestPeer family of objects. */ -class TestPeerUnitTests : public UnitTest +/** Test suite for the TestPeer family of objects. */ +class TestPeer_test : public unit_test::suite { public: @@ -31,7 +33,7 @@ public: PeerTest::report
(*this, arg, timeoutSeconds); } - void runTest () + void run () { typedef boost::asio::ip::tcp protocol; testDetails (protocol::v4 ()); @@ -44,13 +46,9 @@ public: { timeoutSeconds = 10 }; - - TestPeerUnitTests () : UnitTest ("TestPeer", "beast") - { - } }; -static TestPeerUnitTests testPeerUnitTests; +BEAST_DEFINE_TESTSUITE(TestPeer,beast_asio,beast); } } diff --git a/src/beast/modules/beast_core/beast_core.cpp b/src/beast/modules/beast_core/beast_core.cpp index 87a4670110..07f0e1ded3 100644 --- a/src/beast/modules/beast_core/beast_core.cpp +++ b/src/beast/modules/beast_core/beast_core.cpp @@ -128,7 +128,6 @@ #include "diagnostic/FatalError.cpp" #include "diagnostic/SemanticVersion.cpp" -#include "diagnostic/UnitTest.cpp" #include "diagnostic/UnitTestUtilities.cpp" #include "files/DirectoryIterator.cpp" @@ -145,7 +144,6 @@ #include "memory/MemoryBlock.cpp" -#include "misc/Main.cpp" #include "misc/Result.cpp" #include "streams/FileInputSource.cpp" diff --git a/src/beast/modules/beast_core/beast_core.h b/src/beast/modules/beast_core/beast_core.h index 5a23a33aac..26776e882d 100644 --- a/src/beast/modules/beast_core/beast_core.h +++ b/src/beast/modules/beast_core/beast_core.h @@ -166,7 +166,6 @@ class FileOutputStream; #include "files/TemporaryFile.h" #include "logging/Logger.h" #include "memory/SharedSingleton.h" -#include "misc/Main.h" #include "misc/WindowsRegistry.h" #include "streams/MemoryOutputStream.h" @@ -177,7 +176,6 @@ class FileOutputStream; #include "threads/HighResolutionTimer.h" #include "threads/InterProcessLock.h" #include "threads/Process.h" -#include "diagnostic/UnitTest.h" #include "xml/XmlDocument.h" #include "xml/XmlElement.h" #include "diagnostic/UnitTestUtilities.h" diff --git a/src/beast/modules/beast_core/diagnostic/FatalError.cpp b/src/beast/modules/beast_core/diagnostic/FatalError.cpp index 295c44ceb3..4585f62337 100644 --- a/src/beast/modules/beast_core/diagnostic/FatalError.cpp +++ b/src/beast/modules/beast_core/diagnostic/FatalError.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { // // FatalError::Reporter @@ -112,26 +113,16 @@ FatalError::FatalError (char const* message, char const* fileName, int lineNumbe //------------------------------------------------------------------------------ -// Yes even this class can have a unit test. It's manually triggered though. -// -class FatalErrorTests : public UnitTest +class FatalError_test : public unit_test::suite { public: - FatalErrorTests () : UnitTest ("FatalError", "beast", runManual) + void run () { - } - - void runTest () - { - beginTestCase ("raise"); - - // We don't really expect the program to run after this - // but the unit test is here so you can manually test it. int shouldBeZero (1); check_invariant (shouldBeZero == 0); } }; -static FatalErrorTests fatalErrorTests; +BEAST_DEFINE_TESTSUITE_MANUAL(FatalError,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/diagnostic/SemanticVersion.cpp b/src/beast/modules/beast_core/diagnostic/SemanticVersion.cpp index 56ffd366d7..732b74c78a 100644 --- a/src/beast/modules/beast_core/diagnostic/SemanticVersion.cpp +++ b/src/beast/modules/beast_core/diagnostic/SemanticVersion.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { SemanticVersion::SemanticVersion () : majorVersion (0) @@ -288,13 +289,9 @@ bool SemanticVersion::chopIdentifiers (StringArray* value, bool allowLeadingZero //------------------------------------------------------------------------------ -class SemanticVersionTests : public UnitTest +class SemanticVersion_test: public unit_test::suite { public: - SemanticVersionTests () : UnitTest ("SemanticVersion", "beast") - { - } - void checkPass (String const& input, bool shouldPass = true) { SemanticVersion v; @@ -377,7 +374,7 @@ public: void testParse () { - beginTestCase ("parse"); + testcase ("parse"); check ("0.0.0"); check ("1.2.3"); @@ -511,7 +508,7 @@ public: checkLess ("0.9.9", "1.0.0"); } - void runTest () + void run () { testParse (); testValues (); @@ -519,6 +516,6 @@ public: } }; -static SemanticVersionTests semanticVersionTests; +BEAST_DEFINE_TESTSUITE(SemanticVersion,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/diagnostic/UnitTest.cpp b/src/beast/modules/beast_core/diagnostic/UnitTest.cpp deleted file mode 100644 index c14a5c16b8..0000000000 --- a/src/beast/modules/beast_core/diagnostic/UnitTest.cpp +++ /dev/null @@ -1,484 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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. -*/ -//============================================================================== - -namespace beast -{ - -UnitTest::UnitTest (String const& className, - String const& packageName, - When when) - : m_className (className.removeCharacters (" ")) - , m_packageName (packageName.removeCharacters (" ")) - , m_when (when) - , m_runner (nullptr) -{ - getAllTests().add (this); -} - -UnitTest::~UnitTest() -{ - getAllTests().removeFirstMatchingValue (this); -} - -String UnitTest::getTestName() const noexcept -{ - String s; - s << m_packageName << "." << m_className; - return s; -} - -String const& UnitTest::getClassName() const noexcept -{ - return m_className; -} - -String const& UnitTest::getPackageName() const noexcept -{ - return m_packageName; -} - -Journal UnitTest::journal () const -{ - bassert (m_runner != nullptr); - return m_runner->journal(); -} - -UnitTest::TestList& UnitTest::getAllTests() -{ - static TestList s_tests; - - return s_tests; -} - -void UnitTest::initialise() -{ -} - -void UnitTest::shutdown() -{ -} - -ScopedPointer & UnitTest::run ( - UnitTests* const runner) -{ - bassert (runner != nullptr); - m_runner = runner; - m_random = m_runner->m_random; - - m_suite = new Suite (m_className, m_packageName); - - initialise(); - -#if 0 - try - { - runTest(); - } - catch (...) - { - failException (); - } -#else - runTest (); -#endif - - shutdown(); - - finishCase (); - - m_suite->secondsElapsed = RelativeTime ( - Time::getCurrentTime () - m_suite->whenStarted).inSeconds (); - - return m_suite; -} - -void UnitTest::logMessage (String const& message) -{ - m_runner->logMessage (message); -} - -void UnitTest::logReport (StringArray const& report) -{ - m_runner->logReport (report); -} - -void UnitTest::beginTestCase (String const& name) -{ - finishCase (); - - String s; - s << getTestName () << " : " << name; - logMessage (s); - - m_case = new Case (name, m_className); -} - -bool UnitTest::expect_bool (bool trueCondition, String const& failureMessage) -{ - if (trueCondition) - { - pass (); - } - else - { - fail (failureMessage); - } - - return trueCondition; -} - -bool UnitTest::unexpected_bool (bool falseCondition, String const& failureMessage) -{ - return expect (! falseCondition, failureMessage); -} - -void UnitTest::pass () -{ - // If this goes off it means you forgot to call beginTestCase()! - bassert (m_case != nullptr); - - m_case->items.add (Item (true)); -} - -void UnitTest::fail (String const& failureMessage) -{ - // If this goes off it means you forgot to call beginTestCase()! - bassert (m_case != nullptr); - - Item item (false, failureMessage); - - m_case->failures++; - int const caseNumber = m_case->items.add (Item (false, failureMessage)); - - String s; - s << "#" << String (caseNumber) << " failed: " << failureMessage; - logMessage (s); - - m_runner->onFailure (); -} - -void UnitTest::failException () -{ - Item item (false, "An exception was thrown"); - - if (m_case != nullptr) - { - m_case->failures++; - } - else - { - // This hack gives us a test case, to handle the condition where an - // exception was thrown before beginTestCase() was called. - // - beginTestCase ("Exception outside test case"); - } - - int const caseNumber = m_case->items.add (item); - - String s; - s << "#" << String (caseNumber) << " threw an exception "; - logMessage (s); - - m_runner->onFailure (); -} - -Random& UnitTest::random() -{ - // This method's only valid while the test is being run! - bassert (m_runner != nullptr); - - return m_random; -} - -//------------------------------------------------------------------------------ - -void UnitTest::finishCase () -{ - if (m_case != nullptr) - { - // If this goes off it means you forgot to - // report any passing test case items! - // - bassert (m_case->items.size () > 0); - - m_case->secondsElapsed = RelativeTime ( - Time::getCurrentTime () - m_case->whenStarted).inSeconds (); - - m_suite->tests += m_case->items.size (); - m_suite->failures += m_case->failures; - - m_suite->cases.add (m_case.release ()); - } -} - -//============================================================================== - -UnitTests::JournalSink::JournalSink (UnitTests& tests) - : m_tests (tests) -{ -} - -void UnitTests::JournalSink::write (Journal::Severity, std::string const& text) -{ - m_tests.logMessage (text); -} - -//============================================================================== - -UnitTests::UnitTests() - : m_assertOnFailure (false) - , m_sink (*this) -{ -} - -UnitTests::~UnitTests() -{ -} - -void UnitTests::setAssertOnFailure (bool shouldAssert) noexcept -{ - m_assertOnFailure = shouldAssert; -} - -UnitTests::Results const& UnitTests::getResults () const noexcept -{ - return *m_results; -} - -bool UnitTests::anyTestsFailed () const noexcept -{ - return m_results->failures > 0; -} - -UnitTests::TestList UnitTests::selectTests ( - String const& match, TestList const& tests) const noexcept -{ - TestList list; - list.ensureStorageAllocated (tests.size ()); - - int const indexOfDot = match.indexOfChar ('.'); - String const package = (indexOfDot == -1) ? match : match.substring (0, indexOfDot); - String const testname = (indexOfDot == -1) ? "" - : match.substring (indexOfDot + 1, match.length () + 1); - - if (package != String::empty) - { - if (testname != String::empty) - { - // "package.testname" : First test which matches - for (int i = 0; i < tests.size(); ++i) - { - UnitTest* const test = tests [i]; - if (package.equalsIgnoreCase (test->getPackageName ()) && - testname.equalsIgnoreCase (test->getClassName ())) - { - list.add (test); - break; - } - } - } - else - { - // Get all tests in the package - list = selectPackage (package, tests); - - // If no trailing slash on package, try tests - if (list.size () == 0 && indexOfDot == -1) - { - // Try "package" as a testname - list = selectTest (package, tests); - } - } - } - else if (testname != String::empty) - { - list = selectTest (testname, tests); - } - else - { - // All non manual tests - for (int i = 0; i < tests.size(); ++i) - { - UnitTest* const test = tests [i]; - if (test->getWhen () != UnitTest::runManual) - list.add (test); - } - } - - return list; -} - -UnitTests::TestList UnitTests::selectPackage ( - String const& package, TestList const& tests) const noexcept -{ - TestList list; - list.ensureStorageAllocated (tests.size ()); - for (int i = 0; i < tests.size(); ++i) - { - UnitTest* const test = tests [i]; - if (package.equalsIgnoreCase (test->getPackageName ()) && - test->getWhen () != UnitTest::runManual) - list.add (test); - } - return list; -} - -UnitTests::TestList UnitTests::selectTest ( - String const& testname, TestList const& tests) const noexcept -{ - TestList list; - for (int i = 0; i < tests.size(); ++i) - { - UnitTest* const test = tests [i]; - if (testname.equalsIgnoreCase (test->getClassName ())) - { - list.add (test); - break; - } - } - return list; -} - -UnitTests::TestList UnitTests::selectStartupTests (TestList const& tests) const noexcept -{ - TestList list; - for (int i = 0; i < tests.size(); ++i) - { - UnitTest* const test = tests [i]; - if (test->getWhen () == UnitTest::runStartup) - list.add (test); - } - return list; -} - -void UnitTests::runSelectedTests (String const& match, TestList const& tests, int64 randomSeed) -{ - runTests (selectTests (match, tests), randomSeed); -} - -void UnitTests::runTests (TestList const& tests, int64 randomSeed) -{ - if (randomSeed == 0) - randomSeed = Random().nextInt (0x7fffffff); - m_random = Random (randomSeed); - - m_results = new Results; - for (int i = 0; i < tests.size (); ++i) - { - if (shouldAbortTests()) - break; - runTest (*tests [i]); - } - m_results->secondsElapsed = RelativeTime ( - Time::getCurrentTime () - m_results->whenStarted).inSeconds (); -} - -void UnitTests::onFailure () -{ - // A failure occurred and the setting to assert on failures is turned on. - bassert (! m_assertOnFailure); -} - -bool UnitTests::shouldAbortTests() -{ - return false; -} - -void UnitTests::logMessage (const String& message) -{ - Logger::writeToLog (message); -} - -void UnitTests::logReport (StringArray const& report) -{ - for (int i = 0; i < report.size (); ++i) - logMessage (report [i]); -} - -void UnitTests::runTest (UnitTest& test) -{ -#if 0 - try - { -#endif - ScopedPointer suite (test.run (this).release ()); - - m_results->cases += suite->cases.size (); - m_results->tests += suite->tests; - m_results->failures += suite->failures; - - m_results->suites.add (suite.release ()); -#if 0 - } - catch (...) - { - // Should never get here. - Throw (std::runtime_error ("unhandled exception during unit tests")); - } -#endif -} - -//------------------------------------------------------------------------------ - -/** A UnitTest that prints the list of available unit tests. - Not an actual test (it always passes) but if you run it manually it - will print a list of the names of all available unit tests in the program. -*/ -class UnitTestsPrinter : public UnitTest -{ -public: - UnitTestsPrinter () : UnitTest ("print", "print", runManual) - { - } - - void runTest () - { - beginTestCase ("List available unit tests"); - - TestList const& list (UnitTest::getAllTests ()); - - for (int i = 0; i < list.size (); ++i) - { - UnitTest const& test (*list [i]); - - String s; - switch (test.getWhen ()) - { - default: - case UnitTest::runNormal: s << " "; break; - case UnitTest::runManual: s << "[manual] "; break; - case UnitTest::runStartup: s << "[FORCED] "; break; - }; - - s << test.getTestName (); - - logMessage (s); - } - - pass (); - } -}; - -static UnitTestsPrinter unitTestsPrinter; - -} // namespace beast diff --git a/src/beast/modules/beast_core/diagnostic/UnitTest.h b/src/beast/modules/beast_core/diagnostic/UnitTest.h deleted file mode 100644 index d28bf7a695..0000000000 --- a/src/beast/modules/beast_core/diagnostic/UnitTest.h +++ /dev/null @@ -1,555 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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 BEAST_UNITTEST_H_INCLUDED -#define BEAST_UNITTEST_H_INCLUDED - -namespace beast -{ - -class UnitTests; - -/** This is a base class for classes that perform a unit test. - - To write a test using this class, your code should look something like this: - - @code - - class MyTest : public UnitTest - { - public: - MyTest() : UnitTest ("Foobar testing", "packageName") { } - - void runTest() - { - beginTestCase ("Part 1"); - - expect (myFoobar.doesSomething()); - expect (myFoobar.doesSomethingElse()); - - beginTestCase ("Part 2"); - - expect (myOtherFoobar.doesSomething()); - expect (myOtherFoobar.doesSomethingElse()); - - //... - } - }; - - // This makes the unit test available in the global list - // It doesn't have to be static. - // - static MyTest myTest; - - @endcode - - To run one or more unit tests, use the UnitTests class. - - @see UnitTests -*/ -class BEAST_API UnitTest : public Uncopyable -{ -public: - /** When the test should be run. */ - enum When - { - /** Test will be run when @ref runAllTests is called. - @see runAllTests - */ - runNormal, - - /** Test will excluded from @ref runAllTests. - The test can be manually run from @ref runTestsByName. - @see runAllTests, runTestsByName - */ - runManual, - - /** Test will be additionlly forced to run on every launch. - If any failures occur, FatalError is called. The tests will - also be run from @ref runAllTests or @ref runTestsByName if - explicitly invoked. - - @see FatalError - */ - runStartup - }; - - /** Describes a single test item. - - An item created for each call to the test functions, such as @ref expect - or @expectEquals. - */ - struct Item - { - explicit Item (bool passed_, String failureMessage_ = "") - : passed (passed_) - , failureMessage (failureMessage_) - { - } - - bool passed; - String failureMessage; - }; - - /** Describes a test case. - A test case represents a group of Item objects. - */ - struct Case - { - explicit Case (String const& name_, String const& className_) - : name (name_) - , className (className_) - , whenStarted (Time::getCurrentTime ()) - , secondsElapsed (0) - , failures (0) - { - } - - String name; - String className; - - Time whenStarted; - double secondsElapsed; - - int failures; - - Array items; - }; - - /** Contains the results of a test. - - One of these objects is instantiated each time UnitTest::beginTestCase() is called, and - it contains details of the number of subsequent UnitTest::expect() calls that are - made. - */ - struct Suite - { - String className; - String packageName; - Time whenStarted; - double secondsElapsed; - int tests; - int failures; - OwnedArray cases; - - //---- - - Suite (String const& className_, String const& packageName_) - : className (className_) - , packageName (packageName_) - , whenStarted (Time::getCurrentTime ()) // hack for now - , secondsElapsed (0) - , tests (0) - , failures (0) - { - } - - // for convenience - String getSuiteName () const noexcept - { - String s; - s << packageName << "::" << className; - return s; - } - }; - - /** The type of a list of tests. */ - typedef Array TestList; - - //-------------------------------------------------------------------------- - - /** Creates a test with the given name, group, and run option. - - The group is used when you want to run all tests in a particular group - instead of all tests in general. The run option allows you to write some - tests that are only available manually. For examplem, a performance unit - test that takes a long time which you might not want to run every time - you run all tests. - */ - /* - suiteName: A name - className: The name of the class that the unit test exercises - packageName: A real or pseudo "namespace" describing the general area of - functionality to which the specified class belongs. - Examples: "network", "core", "ui" - A package name can appear in multiple testsuite instances. - */ - explicit UnitTest (String const& name, - String const& group = "", - When when = runNormal); - - /** Destructor. */ - virtual ~UnitTest(); - - /** Returns the fully qualified test name in the form . */ - String getTestName() const noexcept; - - /** Returns the class name of the test. */ - const String& getClassName() const noexcept; - - /** Returns the package name of the test. */ - String const& getPackageName () const noexcept; - - /** Returns the run option of the test. */ - When getWhen () const noexcept { return m_when; } - - /** Returns a Journal that logs to the UnitTests. */ - Journal journal () const; - - /** Runs the test, using the specified UnitTests. - You shouldn't need to call this method directly - use - UnitTests::runTests() instead. - */ - ScopedPointer & run (UnitTests* runner); - - /** Returns the set of all UnitTest objects that currently exist. */ - static TestList& getAllTests(); - - //-------------------------------------------------------------------------- - - /** You can optionally implement this method to set up your test. - This method will be called before runTest(). - */ - virtual void initialise(); - - /** You can optionally implement this method to clear up after your test has been run. - This method will be called after runTest() has returned. - */ - virtual void shutdown(); - - /** Implement this method in your subclass to actually run your tests. - - The content of your implementation should call beginTestCase() and expect() - to perform the tests. - */ - virtual void runTest() = 0; - - /** Tells the system that a new subsection of tests is beginning. - This should be called from your runTest() method, and may be called - as many times as you like, to demarcate different sets of tests. - */ - void beginTestCase (String const& name); - - // beginTestCase () - - /** Checks that the result of a test is true, and logs this result. - - In your runTest() method, you should call this method for each condition that - you want to check, e.g. - - @code - void runTest() - { - beginTestCase ("basic tests"); - expect (x + y == 2); - expect (getThing() == someThing); - ...etc... - } - @endcode - - If Suite is true, a pass is logged; if it's false, a failure is logged. - If the failure message is specified, it will be written to the log if the test fails. - - Requirements: - Condition must be explicitly convertible to bool - */ - template - bool expect (Condition trueCondition, String const& failureMessage = String::empty) - { - return expect_bool (!!trueCondition, failureMessage); - } - - bool expect_bool (bool trueCondition, String const& failureMessage); - - /** Checks that the result of a test is false, and logs this result. - - This is basically the opposite of expect(). - - @see expect - - Requirements: - Condition must be explicitly convertible to bool - */ - template - bool unexpected (Condition falseCondition, String const& failureMessage = String::empty) - { - return unexpected_bool (!!falseCondition, failureMessage); - } - - bool unexpected_bool (bool falseCondition, String const& failureMessage); - - /** Compares two values, and if they don't match, prints out a message containing the - expected and actual result values. - */ - template - bool expectEquals (ActualType actual, ExpectedType expected, String failureMessage = String::empty) - { - const bool result = (actual == expected); - - if (! result) - { - if (failureMessage.isNotEmpty()) - failureMessage << " -- "; - - failureMessage << "Expected value: " << expected << ", Actual value: " << actual; - } - - return expect (result, failureMessage); - } - - /** Causes the test item to pass. */ - void pass (); - - /** Causes the test item to fail. */ - void fail (String const& failureMessage = String::empty); - - /** Records an exception in the test item. */ - void failException (); - - //============================================================================== - /** Writes a message to the test log. - This can only be called during your runTest() method. - */ - void logMessage (const String& message); - - void logReport (StringArray const& report); - - /** Returns a shared RNG that all unit tests should use. */ - Random& random(); - -private: - void finishCase (); - -private: - //============================================================================== - String const m_className; - String const m_packageName; - When const m_when; - UnitTests* m_runner; - ScopedPointer m_suite; - ScopedPointer m_case; - Random m_random; -}; - -//============================================================================== -/** - Runs a set of unit tests. - - You can instantiate one of these objects and use it to invoke tests on a set of - UnitTest objects. - - By using a subclass of UnitTests, you can intercept logging messages and - perform custom behaviour when each test completes. - - @see UnitTest -*/ -class BEAST_API UnitTests : public Uncopyable -{ -public: - typedef UnitTest::TestList TestList; - - struct Results - { - Results () - : whenStarted (Time::getCurrentTime ()) - , cases (0) - , tests (0) - , failures (0) - { - } - - Time whenStarted; - double secondsElapsed; - int cases; - int tests; - int failures; - - OwnedArray suites; - }; - - /** */ - UnitTests(); - - /** Destructor. */ - virtual ~UnitTests(); - - /** Sets a flag to indicate whether an assertion should be triggered if a test fails. - This is true by default. - */ - void setAssertOnFailure (bool shouldAssert) noexcept; - - /** Retrieve the information on all the suites that were run. - This is overwritten every time new tests are run. - */ - Results const& getResults () const noexcept; - - /** Returns `true` if any test failed. */ - bool anyTestsFailed () const noexcept; - - //-------------------------------------------------------------------------- - - /** Selects zero or more tests from specified packages or test names. - - The name can be in these formats: - "" - - "." - "." - "." - - "" - An empty string will match all tests objects which are not - marked to be run manually. - - - Selects all tests which belong to that package, excluding those - which must be run manually. If no package with that name exists, - then this will select the first test from any package which matches - the name. If the test is a manual test, it will be selected. - - "." - Selects all tests which belong to that package, excluding those - which must be run manually. If no package with that name exists, - then no tests will be selected. - - "." - Selects only the first test that matches the given testname and - package, regardless of the manual run setting. If no test with a - matching package and test name is found, then no test is selected. - - "." - Selects the first test which matches the testname, even if it - is a manual test. - - Some examples of names: - - "beast" All unit tests in beast - "beast.File" Just the File beast unit test - ".Random" The first test with the name Random - - @note Matching is not case-sensitive. - - @param match The string used to match tests - @param tests An optional parameter containing a list of tests to match. - */ - TestList selectTests (String const& match = "", - TestList const& tests = UnitTest::getAllTests ()) const noexcept; - - /** Selects all tests which match the specified package. - - Tests marked to be run manually are not included. - - @note Matching is not case-sensitive. - - @param match The string used to match tests - @param tests An optional parameter containing a list of tests to match. - */ - TestList selectPackage (String const& package, - TestList const& tests = UnitTest::getAllTests ()) const noexcept; - - /** Selects the first test whose name matches, from any package. - - This can include tests marked to be run manually. - - @note Matching is not case-sensitive. - - @param match The name of the test to match. - @param tests An optional parameter containing a list of tests to match. - */ - TestList selectTest (String const& testname, - TestList const& tests = UnitTest::getAllTests ()) const noexcept; - - /** Selects the startup tests. - A test marked as runStartup will be forced to run on launch. - Typically these are lightweight tests that ensure the system - environment will not cause the program to exhibit undefined behavior. - - @param tests An optional parameter containing a list of tests to match. - */ - TestList selectStartupTests (TestList const& tests = UnitTest::getAllTests ()) const noexcept; - - /** Run a list of matching tests. - This first calls selectTests and then runTeests on the resulting list. - @param match The string used for matching. - @param tests An optional parameter containing a list of tests to match. - */ - void runSelectedTests (String const& match = "", - TestList const& tests = UnitTest::getAllTests (), - int64 randomSeed = 0); - - /** Runs the specified list of tests. - @note The tests are run regardless of the run settings. - @param tests The list of tests to run. - */ - void runTests (TestList const& tests, int64 randomSeed = 0); - - Journal journal () - { - return Journal (m_sink); - } - -protected: - friend class UnitTest; - - /** Called on a failure. */ - void onFailure (); - - /** This can be overridden to let the runner know that it should abort the tests - as soon as possible, e.g. because the thread needs to stop. - */ - virtual bool shouldAbortTests (); - - /** Logs a message about the current test progress. - By default this just writes the message to the Logger class, but you could override - this to do something else with the data. - */ - virtual void logMessage (String const& message); - - /** Logs a report about the current test progress. - This calls logMessage for each String. - */ - virtual void logReport (StringArray const& report); - -private: - void runTest (UnitTest& test); - -private: - class JournalSink : public Journal::Sink, public Uncopyable - { - public: - explicit JournalSink (UnitTests& tests); - void write (Journal::Severity severity, std::string const& text); - - private: - UnitTests& m_tests; - }; - - bool m_assertOnFailure; - ScopedPointer m_results; - Random m_random; - JournalSink m_sink; -}; - -} // namespace beast - -#endif diff --git a/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.cpp b/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.cpp index 7875d0da7a..f40a382f13 100644 --- a/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.cpp +++ b/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.cpp @@ -17,188 +17,8 @@ */ //============================================================================== -namespace beast -{ +namespace beast { +namespace UnitTestUtilities { -namespace UnitTestUtilities -{ - -JUnitXMLFormatter::JUnitXMLFormatter (UnitTests const& tests) - : m_tests (tests) - , m_currentTime (timeToString (Time::getCurrentTime ())) - , m_hostName (SystemStats::getComputerName ()) -{ -} - -// This is the closest thing to documentation on JUnit XML I could find: -// -// http://junitpdfreport.sourceforge.net/managedcontent/PdfTranslation -// -String JUnitXMLFormatter::createDocumentString () -{ - UnitTests::Results const& results (m_tests.getResults ()); - - ScopedPointer testsuites (new XmlElement ("testsuites")); - testsuites->setAttribute ("tests", String (results.tests)); - if (results.failures != 0) - testsuites->setAttribute ("failures", String (results.failures)); - testsuites->setAttribute ("time", secondsToString (results.secondsElapsed)); - - for (int i = 0; i < results.suites.size (); ++i) - { - UnitTest::Suite const& suite (*results.suites [i]); - - XmlElement* testsuite (new XmlElement ("testsuite"));; - testsuite->setAttribute ("name", suite.className); - testsuite->setAttribute ("tests", String (suite.tests)); - if (suite.failures != 0) - testsuite->setAttribute ("failures", String (suite.failures)); - testsuite->setAttribute ("time", secondsToString (suite.secondsElapsed)); - testsuite->setAttribute ("timestamp", timeToString (suite.whenStarted)); - testsuite->setAttribute ("hostname", m_hostName); - testsuite->setAttribute ("package", suite.packageName); - - testsuites->addChildElement (testsuite); - - for (int i = 0; i < suite.cases.size (); ++i) - { - UnitTest::Case const& testCase (*suite.cases [i]); - - XmlElement* testcase (new XmlElement ("testcase")); - testcase->setAttribute ("name", testCase.name); - testcase->setAttribute ("time", secondsToString (testCase.secondsElapsed)); - testcase->setAttribute ("classname", suite.className); - - testsuite->addChildElement (testcase); - - for (int i = 0; i < testCase.items.size (); ++i) - { - UnitTest::Item const& item (testCase.items.getUnchecked (i)); - - if (!item.passed) - { - XmlElement* failure (new XmlElement ("failure")); - - String s; - s << "#" << String (i+1) << " " << item.failureMessage; - failure->setAttribute ("message", s); - - testcase->addChildElement (failure); - } - } - } - } - - return testsuites->createDocument ( - //"https://svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4.xsd", - "", - false, - true, - "UTF-8", - 999); -}; - -String JUnitXMLFormatter::timeToString (Time const& time) -{ - return time.toString (true, true, false, true); -} - -String JUnitXMLFormatter::secondsToString (double seconds) -{ - if (seconds < .01) - return String (seconds, 4); - else if (seconds < 1) - return String (seconds, 2); - else if (seconds < 10) - return String (seconds, 1); - else - return String (int (seconds)); -} - -//------------------------------------------------------------------------------ - -/** A unit test that always passes. - This can be useful to diagnose continuous integration systems. -*/ -class PassUnitTest : public UnitTest -{ -public: - PassUnitTest () : UnitTest ("Pass", "beast", runManual) - { - } - - void runTest () - { - beginTestCase ("pass"); - - pass (); - } -}; - -static PassUnitTest passUnitTest; - -//------------------------------------------------------------------------------ - -/** A unit test that always fails. - This can be useful to diagnose continuous integration systems. -*/ -class FailUnitTest : public UnitTest -{ -public: - FailUnitTest () : UnitTest ("Fail", "beast", runManual) - { - } - - void runTest () - { - beginTestCase ("fail"); - - fail ("Intentional failure"); - } -}; - -static FailUnitTest failUnitTest; - -} - -//------------------------------------------------------------------------------ - -class UnitTestUtilitiesTests : public UnitTest -{ -public: - UnitTestUtilitiesTests () : UnitTest ("UnitTestUtilities", "beast") - { - } - - void testPayload () - { - using namespace UnitTestUtilities; - - int const maxBufferSize = 4000; - int const minimumBytes = 1; - int const numberOfItems = 100; - int64 const seedValue = 50; - - beginTestCase ("Payload"); - - Payload p1 (maxBufferSize); - Payload p2 (maxBufferSize); - - for (int i = 0; i < numberOfItems; ++i) - { - p1.repeatableRandomFill (minimumBytes, maxBufferSize, seedValue); - p2.repeatableRandomFill (minimumBytes, maxBufferSize, seedValue); - - expect (p1 == p2, "Should be equal"); - } - } - - void runTest () - { - testPayload (); - } -}; - -static UnitTestUtilitiesTests unitTestUtilitiesTests; - -} // namespace beast +} // UnitTestUtilities +} // beast diff --git a/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.h b/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.h index c42b431666..1f226dce84 100644 --- a/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.h +++ b/src/beast/modules/beast_core/diagnostic/UnitTestUtilities.h @@ -20,11 +20,8 @@ #ifndef BEAST_UNITTESTUTILITIES_H_INCLUDED #define BEAST_UNITTESTUTILITIES_H_INCLUDED -namespace beast -{ - -namespace UnitTestUtilities -{ +namespace beast { +namespace UnitTestUtilities { /** Fairly shuffle an array pseudo-randomly. */ @@ -102,39 +99,7 @@ public: HeapBlock data; }; -//------------------------------------------------------------------------------ - -/** Format unit test results in JUnit XML format. - - The output can be used directly with the Jenkins CI server with - the appropriate JUnit plugin. - - JUnit FAQ: http://junit.sourceforge.net/doc/faq/faq.htm - - Jenkins Home: http://jenkins-ci.org/ - - @see UnitTest, UnitTests -*/ - -class JUnitXMLFormatter : public Uncopyable -{ -public: - JUnitXMLFormatter (UnitTests const& tests); - - String createDocumentString (); - -private: - static String timeToString (Time const& time); - static String secondsToString (double seconds); - -private: - UnitTests const& m_tests; - String const m_currentTime; - String const m_hostName; -}; - -} - -} // namespace beast +} // UnitTestUtilities +} // beast #endif diff --git a/src/beast/modules/beast_core/files/File.cpp b/src/beast/modules/beast_core/files/File.cpp index 35b0c16345..d06beba707 100644 --- a/src/beast/modules/beast_core/files/File.cpp +++ b/src/beast/modules/beast_core/files/File.cpp @@ -21,8 +21,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { // We need to make a shared singleton or else there are // issues with the leak detector and order of detruction. @@ -904,14 +905,19 @@ File File::createTempFile (const String& fileNameEnding) //============================================================================== -class FileTests : public UnitTest +class File_test : public unit_test::suite { public: - FileTests() : UnitTest ("File", "beast") {} - - void runTest() + template + bool + expectEquals (T1 const& t1, T2 const& t2) { - beginTestCase ("Reading"); + return expect (t1 == t2); + } + + void run() + { + testcase ("Reading"); const File home (File::getSpecialLocation (File::userHomeDirectory)); const File temp (File::getSpecialLocation (File::tempDirectory)); @@ -950,7 +956,7 @@ public: expect (numRootsExisting > 0); } - beginTestCase ("Writing"); + testcase ("Writing"); File demoFolder (temp.getChildFile ("Beast UnitTests Temp Folder.folder")); expect (demoFolder.deleteRecursively()); @@ -991,7 +997,7 @@ public: expect (tempFile.exists()); expect (tempFile.getSize() == 10); expect (std::abs ((int) (tempFile.getLastModificationTime().toMilliseconds() - Time::getCurrentTime().toMilliseconds())) < 3000); - expectEquals (tempFile.loadFileAsString(), String ("0123456789")); + expect (tempFile.loadFileAsString() == String ("0123456789")); expect (! demoFolder.containsSubDirectories()); expectEquals (tempFile.getRelativePathFrom (demoFolder.getParentDirectory()), demoFolder.getFileName() + File::separatorString + tempFile.getFileName()); @@ -1036,7 +1042,7 @@ public: expect (tempFile.getSize() == 10); } - beginTestCase ("More writing"); + testcase ("More writing"); expect (tempFile.appendData ("abcdefghij", 10)); expect (tempFile.getSize() == 20); @@ -1058,6 +1064,6 @@ public: } }; -static FileTests fileTests; +BEAST_DEFINE_TESTSUITE (File,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/files/RandomAccessFile.cpp b/src/beast/modules/beast_core/files/RandomAccessFile.cpp index a20270ca1a..2376079cf0 100644 --- a/src/beast/modules/beast_core/files/RandomAccessFile.cpp +++ b/src/beast/modules/beast_core/files/RandomAccessFile.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { RandomAccessFile::RandomAccessFile () noexcept : fileHandle (nullptr) @@ -101,13 +102,9 @@ Result RandomAccessFile::flush () //------------------------------------------------------------------------------ -class RandomAccessFileTests : public UnitTest +class RandomAccessFile_test : public unit_test::suite { public: - RandomAccessFileTests () : UnitTest ("RandomAccessFile", "beast") - { - } - enum { maxPayload = 8192 @@ -221,7 +218,9 @@ public: int const seedValue = 50; - beginTestCase (String ("numRecords=") + String (numRecords)); + std::stringstream ss; + ss << numRecords << " records"; + testcase (ss.str()); // Calculate the path File const path (File::createTempFile ("RandomAccessFile")); @@ -264,14 +263,12 @@ public: } } - void runTest () + void run () { testFile (10000); } - -private: }; -static RandomAccessFileTests randomAccessFileTests; +BEAST_DEFINE_TESTSUITE(RandomAccessFile,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/maths/Random.cpp b/src/beast/modules/beast_core/maths/Random.cpp index 2cea764975..67c9b9fb24 100644 --- a/src/beast/modules/beast_core/maths/Random.cpp +++ b/src/beast/modules/beast_core/maths/Random.cpp @@ -21,8 +21,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { Random::Random (const int64 seedValue) noexcept : seed (seedValue) @@ -122,15 +123,11 @@ void Random::fillBitsRandomly (void* const buffer, size_t bytes) //============================================================================== -class RandomTests : public UnitTest +class Random_test : public unit_test::suite { public: - RandomTests() : UnitTest ("Random", "beast") {} - - void runTest() + void run() { - beginTestCase ("Random"); - for (int j = 10; --j >= 0;) { Random r; @@ -153,6 +150,6 @@ public: } }; -static RandomTests randomTests; +BEAST_DEFINE_TESTSUITE(Random,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/misc/Main.cpp b/src/beast/modules/beast_core/misc/Main.cpp deleted file mode 100644 index 1f04b0ecf5..0000000000 --- a/src/beast/modules/beast_core/misc/Main.cpp +++ /dev/null @@ -1,131 +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. -*/ -//============================================================================== - -namespace beast -{ - -Main* Main::s_instance; - -Main::Main () -{ - // If this happens it means there are two instances of Main! - check_precondition (s_instance == nullptr); - - s_instance = this; - -} - -Main::~Main () -{ - s_instance = nullptr; -} - -Main& Main::getInstance () -{ - bassert (s_instance != nullptr); - - return *s_instance; -} - -int Main::runStartupUnitTests () -{ - int exitCode = EXIT_SUCCESS; - - struct StartupUnitTests : UnitTests - { - void logMessage (String const&) - { - // Intentionally do nothing, we don't want - // to see the extra output for startup tests. - } - - void log (String const& message) - { -#if BEAST_MSVC - if (beast_isRunningUnderDebugger ()) - Logger::outputDebugString (message); -#endif - - std::cerr << message.toStdString () << std::endl; - } - - void reportCase (String const& suiteName, UnitTest::Case const& testcase) - { - String s; - s << suiteName << " (" << testcase.name << ") produced " << - String (testcase.failures) << - ((testcase.failures == 1) ? " failure." : " failures."); - log (s); - } - - void reportSuite (UnitTest::Suite const& suite) - { - if (suite.failures > 0) - { - String const suiteName = suite.getSuiteName (); - - for (int i = 0; i < suite.cases.size (); ++i) - { - UnitTest::Case const& testcase (*suite.cases [i]); - - if (testcase.failures > 0) - reportCase (suiteName, testcase); - } - } - } - - void reportSuites (UnitTests::Results const& results) - { - for (int i = 0; i < results.suites.size (); ++i) - reportSuite (*results.suites [i]); - } - - void reportResults () - { - reportSuites (getResults ()); - } - }; - - StartupUnitTests tests; - - tests.runTests (tests.selectStartupTests ()); - - if (tests.anyTestsFailed ()) - { - tests.reportResults (); - - tests.log ("Terminating with an error due to failed startup tests."); - - exitCode = EXIT_FAILURE; - } - - return exitCode; -} - -int Main::runFromMain (int argc, char const* const* argv) -{ - int exitCode (runStartupUnitTests ()); - - if (exitCode == EXIT_SUCCESS) - exitCode = run (argc, argv); - - return exitCode; -} - -} // namespace beast diff --git a/src/beast/modules/beast_core/misc/Main.h b/src/beast/modules/beast_core/misc/Main.h deleted file mode 100644 index 25158476d8..0000000000 --- a/src/beast/modules/beast_core/misc/Main.h +++ /dev/null @@ -1,84 +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 BEAST_CORE_MAIN_H_INCLUDED -#define BEAST_CORE_MAIN_H_INCLUDED - -namespace beast -{ - -/** Represents a command line program's entry point - To use this, derive your class from @ref Main and implement the - function run (); -*/ -class Main : public Uncopyable -{ -public: - Main (); - - virtual ~Main (); - - /** Run the program. - - You should call this from your @ref main function. Don't put - anything else in there. Instead, do it in your class derived - from Main. For example: - - @code - - struct MyProgram : Main - { - int run (int argc, char const* const* argv) - { - std::cout << "Hello, world!" << std::endl; - return 0; - } - }; - - int main (int argc, char const* const* argv) - { - MyProgram program; - - return program.runFromMain (argc, argv); - } - - @endcode - */ - int runFromMain (int argc, char const* const* argv); - - /** Retrieve the instance of the program. */ - static Main& getInstance (); - -protected: - /** Entry point for running the program. - Subclasses provide the implementation. - */ - virtual int run (int argc, char const* const* argv) = 0; - -private: - int runStartupUnitTests (); - -private: - static Main* s_instance; -}; - -} // namespace beast - -#endif - diff --git a/src/beast/modules/beast_core/text/LexicalCast.cpp b/src/beast/modules/beast_core/text/LexicalCast.cpp index a074d7712e..cc5d1d703c 100644 --- a/src/beast/modules/beast_core/text/LexicalCast.cpp +++ b/src/beast/modules/beast_core/text/LexicalCast.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { unsigned char const LexicalCastUtilities::s_digitTable [256] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xFF - 0x07 @@ -57,13 +58,9 @@ unsigned char const LexicalCastUtilities::s_digitTable [256] = { //------------------------------------------------------------------------------ -class LexicalCastTests : public UnitTest +class LexicalCast_test : public unit_test::suite { public: - LexicalCastTests () : UnitTest ("LexicalCast", "beast") - { - } - template static IntType nextRandomInt (Random& r) { @@ -74,7 +71,7 @@ public: void testInteger (IntType in) { String s; - IntType out; + IntType out (in+1); expect (lexicalCastChecked (s, in)); expect (lexicalCastChecked (out, s)); @@ -85,9 +82,10 @@ public: void testIntegers (Random& r) { { - String s; - s << "random " << typeid (IntType).name (); - beginTestCase (s); + std::stringstream ss; + ss << + "random " << typeid (IntType).name (); + testcase (ss.str()); for (int i = 0; i < 1000; ++i) { @@ -97,16 +95,17 @@ public: } { - String s; - s << "numeric_limits <" << typeid (IntType).name () << ">"; - beginTestCase (s); + std::stringstream ss; + ss << + "numeric_limits <" << typeid (IntType).name () << ">"; + testcase (ss.str()); testInteger (std::numeric_limits ::min ()); testInteger (std::numeric_limits ::max ()); } } - void runTest () + void run() { int64 const seedValue = 50; @@ -123,6 +122,6 @@ public: } }; -static LexicalCastTests lexicalCastTests; +BEAST_DEFINE_TESTSUITE(LexicalCast,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/thread/Workers.cpp b/src/beast/modules/beast_core/thread/Workers.cpp index 2edc3202a7..2c72f9becb 100644 --- a/src/beast/modules/beast_core/thread/Workers.cpp +++ b/src/beast/modules/beast_core/thread/Workers.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -namespace beast -{ +#include "../../../beast/unit_test/suite.h" + +namespace beast { Workers::Workers (Callback& callback, String const& threadNames, int numberOfThreads) : m_callback (callback) @@ -222,12 +223,9 @@ void Workers::Worker::run () //------------------------------------------------------------------------------ -class WorkersTests : public UnitTest +class Workers_test : public unit_test::suite { public: - WorkersTests () : UnitTest ("Workers", "beast") - { - } struct TestCallback : Workers::Callback { @@ -247,11 +245,19 @@ public: Atomic count; }; + template + bool + expectEquals (T1 const& t1, T2 const& t2) + { + return expect (t1 == t2); + } + void testThreads (int const threadCount) { - String s; - s << "threadCount = " << String (threadCount); - beginTestCase (s); + std::stringstream ss; + ss << + "threadCount = " << threadCount; + testcase (ss.str()); TestCallback cb (threadCount); @@ -277,7 +283,7 @@ public: expectEquals (count, 0); } - void runTest () + void run () { testThreads (0); testThreads (1); @@ -288,6 +294,6 @@ public: } }; -static WorkersTests workersTests; +BEAST_DEFINE_TESTSUITE(Workers,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/thread/impl/TrackedMutex.cpp b/src/beast/modules/beast_core/thread/impl/TrackedMutex.cpp index 502476556f..59245d94ca 100644 --- a/src/beast/modules/beast_core/thread/impl/TrackedMutex.cpp +++ b/src/beast/modules/beast_core/thread/impl/TrackedMutex.cpp @@ -17,11 +17,8 @@ */ //============================================================================== -namespace beast -{ - -namespace detail -{ +namespace beast { +namespace detail { // Example: // @@ -74,7 +71,7 @@ TrackedMutexBasics::Lists& TrackedMutexBasics::getLists () //------------------------------------------------------------------------------ -} // namespace detail +} // detail //============================================================================== @@ -478,88 +475,4 @@ String TrackedMutex::makeSourceLocation (char const* fileName, int lineNumber) n return sourceLocation; } -//============================================================================== - -namespace detail -{ - -class TrackedMutexUnitTests : public UnitTest -{ -public: - typedef TrackedMutexType Mutex; - - struct LockingThread : public Thread - { - Mutex& m_m1; - Mutex& m_m2; - WaitableEvent m_start; - - explicit LockingThread (String name, Mutex& m1, Mutex& m2) - : Thread (name) - , m_m1 (m1) - , m_m2 (m2) - { - startThread (); - } - - void waitForStart () - { - m_start.wait (); - } - - void run () - { - Mutex::ScopedLockType l2 (m_m2, __FILE__, __LINE__); - { - Mutex::ScopedLockType l1 (m_m1, __FILE__, __LINE__); - m_start.signal (); - { - Mutex::ScopedUnlockType ul1 (m_m1, __FILE__, __LINE__); - this->wait (); - } - } - } - }; - - //-------------------------------------------------------------------------- - - void report (String name) - { - beginTestCase (name); - StringArray report; - TrackedMutex::generateGlobalBlockedReport (report); - logReport (report); - pass (); - } - - void runTest () - { - Mutex m1 ("M1", __FILE__, __LINE__); - Mutex m2 ("M2", __FILE__, __LINE__); - - { - Mutex::ScopedLockType l1 (m1, __FILE__, __LINE__); - LockingThread t1 ("T1", m1, m2); - { - Mutex::ScopedUnlockType ul1 (m1, __FILE__, __LINE__); - t1.waitForStart (); - } - report ("#1"); - { - t1.notify (); - Mutex::ScopedUnlockType ul1 (m1, __FILE__, __LINE__); - t1.waitForThreadToExit (); - } - } - } - - TrackedMutexUnitTests () : UnitTest ("TrackedMutex", "beast", runManual) - { - } -}; - -static TrackedMutexUnitTests trackedMutexUnitTests; - -} // namespace detail - -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_core/threads/ChildProcess.cpp b/src/beast/modules/beast_core/threads/ChildProcess.cpp index a7a68fe709..46f465e10e 100644 --- a/src/beast/modules/beast_core/threads/ChildProcess.cpp +++ b/src/beast/modules/beast_core/threads/ChildProcess.cpp @@ -61,13 +61,11 @@ String ChildProcess::readAllProcessOutput() //============================================================================== -class ChildProcessTests : public UnitTest +class ChildProcess_test : public unit_test::suite { public: - void runTest() + void run() { - beginTestCase ("Child Processes"); - #if BEAST_WINDOWS || BEAST_MAC || BEAST_LINUX ChildProcess p; @@ -87,17 +85,13 @@ public: //expect (output.isNotEmpty()); #endif } - - // VFALCO NOTE I had to disable this test because it was leaving - // behind a zombie process and making other unit tests fail. - // It doesnt happen with a debugger attached, or if the - // unit test is run individually. - // - ChildProcessTests() : UnitTest ("ChildProcess", "beast", runManual) - { - } }; -static ChildProcessTests childProcessTests; +// VFALCO NOTE I had to disable this test because it was leaving +// behind a zombie process and making other unit tests fail. +// It doesnt happen with a debugger attached, or if the +// unit test is run individually. +// +BEAST_DEFINE_TESTSUITE_MANUAL(ChildProcess,beast_core,beast); -} // namespace beast +} // beast diff --git a/src/beast/modules/beast_vflib/beast_vflib.cpp b/src/beast/modules/beast_vflib/beast_vflib.cpp deleted file mode 100644 index 355f19d5d6..0000000000 --- a/src/beast/modules/beast_vflib/beast_vflib.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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. -*/ -//============================================================================== - -#include "beast_vflib.h" - -#include "threads/ThreadWithServiceQueue.cpp" - -/** Unit tests for header only classes -*/ - -static beast::detail::CallQueueTests callQueueTests; -static beast::detail::ManualServiceQueueTests manualServiceQueueTests; diff --git a/src/beast/modules/beast_vflib/beast_vflib.h b/src/beast/modules/beast_vflib/beast_vflib.h deleted file mode 100644 index 50e2d76a80..0000000000 --- a/src/beast/modules/beast_vflib/beast_vflib.h +++ /dev/null @@ -1,29 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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 BEAST_VFLIB_H_INCLUDED -#define BEAST_VFLIB_H_INCLUDED - -#include "functor/BindHelper.h" -#include "threads/CallQueue.h" -#include "threads/ThreadWithServiceQueue.h" -#include "threads/ManualServiceQueue.h" -#include "threads/GuiServiceQueue.h" - -#endif diff --git a/src/beast/modules/beast_vflib/functor/BindHelper.h b/src/beast/modules/beast_vflib/functor/BindHelper.h deleted file mode 100644 index b148fd081a..0000000000 --- a/src/beast/modules/beast_vflib/functor/BindHelper.h +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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 BEAST_VFLIB_BINDHELPER_H_INCLUDED -#define BEAST_VFLIB_BINDHELPER_H_INCLUDED - -namespace beast { - -/** Calls bind() for you. - The UnaryFunction will be called with this signature: - @code - template - void operator() (Functor const& f); - @endcode - Where Functor is the result of the bind. - */ -template -class BindHelper -{ -private: - // Gets called with the bind - UnaryFunction m_f; - -public: -#if BEAST_VARIADIC_MAX >= 1 - template - explicit BindHelper (Arg& arg) - : m_f (arg) - { } - - template - explicit BindHelper (Arg const& arg) - : m_f (arg) - { } - - template - void operator() (F const& f) const - { m_f (f); } -#endif - -#if BEAST_VARIADIC_MAX >= 2 - template - void operator() (F const& f, P1 const& p1) const - { m_f (bind (f, p1)); } -#endif - -#if BEAST_VARIADIC_MAX >= 3 - template - void operator() (F const& f, P1 const& p1, P2 const& p2) const - { m_f (bind (f, p1, p2)); } -#endif - -#if BEAST_VARIADIC_MAX >= 4 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3) const - { m_f (bind (f, p1, p2, p3)); } -#endif - -#if BEAST_VARIADIC_MAX >= 5 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4) const - { m_f (bind (f, p1, p2, p3, p4)); } -#endif - -#if BEAST_VARIADIC_MAX >= 6 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5) const - { m_f (bind (f, p1, p2, p3, p4, p5)); } -#endif - -#if BEAST_VARIADIC_MAX >= 7 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5, P6 const& p6) const - { m_f (bind (f, p1, p2, p3, p4, p5, p6)); } -#endif - -#if BEAST_VARIADIC_MAX >= 8 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5, P6 const& p6, P7 const& p7) const - { m_f (bind (f, p1, p2, p3, p4, p5, p6, p7)); } -#endif - -#if BEAST_VARIADIC_MAX >= 9 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5, P6 const& p6, P7 const& p7, P8 const& p8) const - { m_f (bind (f, p1, p2, p3, p4, p5, p6, p7, p8)); } -#endif - -#if BEAST_VARIADIC_MAX >= 10 - template - void operator() (F const& f, P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5, P6 const& p6, P7 const& p7, P8 const& p8, P9 const& p9) const - { m_f (bind (f, p1, p2, p3, p4, p5, p6, p7, p8, p9)); } -#endif -}; - -} - -#endif diff --git a/src/beast/modules/beast_vflib/threads/CallQueue.h b/src/beast/modules/beast_vflib/threads/CallQueue.h deleted file mode 100644 index 352977de20..0000000000 --- a/src/beast/modules/beast_vflib/threads/CallQueue.h +++ /dev/null @@ -1,382 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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 BEAST_VFLIB_CALLQUEUE_H_INCLUDED -#define BEAST_VFLIB_CALLQUEUE_H_INCLUDED - -#include "beast/Threads.h" -#include "../functor/BindHelper.h" - -namespace beast { - -template > -class CallQueueType -: public ServiceQueueType -{ -public: - explicit CallQueueType (const String& name, - int expectedConcurrency = 1, - Allocator alloc = Allocator()) - : ServiceQueueType(expectedConcurrency, alloc) - , m_name (name) - , queue(*this) - , call(*this) - { - } - - ~CallQueueType () - { - // Someone forget to close the queue. - bassert (m_closed.isSignaled ()); - - // Can't destroy queue with unprocessed calls. - bassert (ServiceQueueBase::empty ()); - } - - void enqueue (ServiceQueueBase::Item* item) - { - // If this goes off someone added calls - // after the queue has been closed. - bassert (!m_closed.isSignaled ()); - - ServiceQueueType ::enqueue (item); - } - - /** Close the queue. - - Functors may not be added after this routine is called. This is used for - diagnostics, to track down spurious calls during application shutdown - or exit. Derived classes may call this if the appropriate time is known. - - The queue is synchronized after it is closed. - Can still have pending calls, just can't put new ones in. - */ - virtual void close () - { - m_closed.signal (); - - ServiceQueueType ::stop (); - } - - struct BindHelperPost - { - CallQueueType& m_queue; - explicit BindHelperPost (CallQueueType& queue) - : m_queue (queue) - { } - template - void operator() (F const& f) const - { m_queue.post ( F (f) ); } - }; - - struct BindHelperDispatch - { - CallQueueType& m_queue; - explicit BindHelperDispatch (CallQueueType& queue) - : m_queue (queue) - { } - template - void operator() (F const& f) const - { m_queue.dispatch ( F (f) ); } - }; - - BindHelper const queue; - BindHelper const call; - -private: - String m_name; - AtomicFlag m_closed; -}; - -typedef CallQueueType > CallQueue; - -namespace detail -{ - -//------------------------------------------------------------------------------ - -class CallQueueTests -: public UnitTest -{ -public: - struct CallTracker - { - CallQueueTests *unitTest; - int c0, c1, c2, c3, c4, c5, c6, c7, c8; - int q0, q1, q2, q3, q4, q5, q6, q7, q8; - - CallTracker(CallQueueTests *parent) - : unitTest(parent) - , c0(0), c1(0), c2(0), c3(0), c4(0), c5(0), c6(0), c7(0), c8(0) - , q0(0), q1(0), q2(0), q3(0), q4(0), q5(0), q6(0), q7(0), q8(0) - { - } - - void doQ0() { q0++; } - - void doQ1(const String& p1) - { - unitTest->expect(p1 == "p1"); - q1++; - } - - void doQ2(const String& p1, const String& p2) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - q2++; - } - - void doQ3(const String& p1, const String& p2, const String& p3) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - q3++; - } - - void doQ4(const String& p1, const String& p2, const String& p3, const String& p4) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - q4++; - } - - void doQ5(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - q5++; - } - - void doQ6(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5, const String& p6) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - unitTest->expect(p6 == "p6"); - q6++; - } - - void doQ7(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5, const String& p6, const String& p7) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - unitTest->expect(p6 == "p6"); - unitTest->expect(p7 == "p7"); - q7++; - } - - void doQ8(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5, const String& p6, const String& p7, const String& p8) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - unitTest->expect(p6 == "p6"); - unitTest->expect(p7 == "p7"); - unitTest->expect(p8 == "p8"); - q8++; - } - - void doC0() { c0++; } - - void doC1(const String& p1) - { - unitTest->expect(p1 == "p1"); - c1++; - } - - void doC2(const String& p1, const String& p2) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - c2++; - } - - void doC3(const String& p1, const String& p2, const String& p3) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - c3++; - } - - void doC4(const String& p1, const String& p2, const String& p3, const String& p4) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - c4++; - } - - void doC5(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - c5++; - } - - void doC6(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5, const String& p6) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - unitTest->expect(p6 == "p6"); - c6++; - } - - void doC7(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5, const String& p6, const String& p7) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - unitTest->expect(p6 == "p6"); - unitTest->expect(p7 == "p7"); - c7++; - } - - void doC8(const String& p1, const String& p2, const String& p3, const String& p4, const String& p5, const String& p6, const String& p7, const String& p8) - { - unitTest->expect(p1 == "p1"); - unitTest->expect(p2 == "p2"); - unitTest->expect(p3 == "p3"); - unitTest->expect(p4 == "p4"); - unitTest->expect(p5 == "p5"); - unitTest->expect(p6 == "p6"); - unitTest->expect(p7 == "p7"); - unitTest->expect(p8 == "p8"); - c8++; - } - }; - - CallTracker m_callTracker; - - void testArities () - { - beginTestCase("Arities"); - - int calls = 0; - -#if BEAST_VARIADIC_MAX >= 2 - m_queue.queue(&CallTracker::doQ0, &m_callTracker); calls++; - m_queue.queue(&CallTracker::doC0, &m_callTracker); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 3 - m_queue.queue(&CallTracker::doQ1, &m_callTracker, "p1"); calls++; - m_queue.queue(&CallTracker::doC1, &m_callTracker, "p1"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 4 - m_queue.queue(&CallTracker::doQ2, &m_callTracker, "p1", "p2"); calls++; - m_queue.queue(&CallTracker::doC2, &m_callTracker, "p1", "p2"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 5 - m_queue.queue(&CallTracker::doQ3, &m_callTracker, "p1", "p2", "p3"); calls++; - m_queue.queue(&CallTracker::doC3, &m_callTracker, "p1", "p2", "p3"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 6 - m_queue.queue(&CallTracker::doQ4, &m_callTracker, "p1", "p2", "p3", "p4"); calls++; - m_queue.queue(&CallTracker::doC4, &m_callTracker, "p1", "p2", "p3", "p4"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 7 - m_queue.queue(&CallTracker::doQ5, &m_callTracker, "p1", "p2", "p3", "p4", "p5"); calls++; - m_queue.queue(&CallTracker::doC5, &m_callTracker, "p1", "p2", "p3", "p4", "p5"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 8 - m_queue.queue(&CallTracker::doQ6, &m_callTracker, "p1", "p2", "p3", "p4", "p5", "p6"); calls++; - m_queue.queue(&CallTracker::doC6, &m_callTracker, "p1", "p2", "p3", "p4", "p5", "p6"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 9 - m_queue.queue(&CallTracker::doQ7, &m_callTracker, "p1", "p2", "p3", "p4", "p5", "p6", "p7"); calls++; - m_queue.queue(&CallTracker::doC7, &m_callTracker, "p1", "p2", "p3", "p4", "p5", "p6", "p7"); calls++; -#endif - -#if BEAST_VARIADIC_MAX >= 10 - m_queue.queue(&CallTracker::doQ8, &m_callTracker, "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"); calls++; - m_queue.queue(&CallTracker::doC8, &m_callTracker, "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"); calls++; -#endif - - std::size_t performedCalls = m_queue.poll(); - - m_queue.close(); - - expect (performedCalls == calls); - - expect (m_callTracker.c0 == 1); - expect (m_callTracker.c1 == 1); - expect (m_callTracker.c2 == 1); - expect (m_callTracker.c3 == 1); - expect (m_callTracker.c4 == 1); - expect (m_callTracker.c5 == 1); - - expect (m_callTracker.q0 == 1); - expect (m_callTracker.q1 == 1); - expect (m_callTracker.q2 == 1); - expect (m_callTracker.q3 == 1); - expect (m_callTracker.q4 == 1); - expect (m_callTracker.q5 == 1); - } - - void runTest() - { - testArities(); - } - - CallQueueTests () - : UnitTest ("CallQueue", "beast") - , m_queue("CallQueue Test Queue") - , m_callTracker(this) - { - } - - CallQueue m_queue; -}; - -} - -} - -#endif diff --git a/src/beast/modules/beast_vflib/threads/ManualServiceQueue.h b/src/beast/modules/beast_vflib/threads/ManualServiceQueue.h deleted file mode 100644 index 3ab220e7f0..0000000000 --- a/src/beast/modules/beast_vflib/threads/ManualServiceQueue.h +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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 BEAST_VFLIB_MANUALSERVICEQUEUE_H_INCLUDED -#define BEAST_VFLIB_MANUALSERVICEQUEUE_H_INCLUDED - -#include "CallQueue.h" - -namespace beast { - -class ManualServiceQueue -: public CallQueue -{ -public: - explicit ManualServiceQueue (const String& name) - : CallQueue(name) - { - } - - /** Calls all functors in the queue. Returns if there are no - more functors available to run - */ - bool synchronize () - { - if(poll() > 0) - return true; - - return false; - } -}; - -//------------------------------------------------------------------------------ - -namespace detail -{ - -//------------------------------------------------------------------------------ - -class ManualServiceQueueTests -: public UnitTest -{ -public: - struct CallTracker - { - ManualServiceQueueTests *unitTest; - int c0, c1; - int q0, q1; - - CallTracker(ManualServiceQueueTests *parent) - : unitTest(parent) - , c0(0), c1(0) - , q0(0), q1(0) - { - } - - void doQ0() { q0++; } - - void doQ1(const String& p1) - { - unitTest->expect(p1 == "p1"); - q1++; - } - - void doC0() { c0++; } - - void doC1(const String& p1) - { - unitTest->expect(p1 == "p1"); - c1++; - } - }; - - void performEmptyQueue() - { - beginTestCase("Empty queue"); - - ManualServiceQueue queue("ManualServiceQueueTests"); - - bool doneSomething = queue.synchronize(); - expect(!doneSomething); - - queue.close(); - } - - void performCalls() - { - beginTestCase("Calls"); - - Random r; - r.setSeedRandomly(); - - ManualServiceQueue queue("ManualServiceQueueTests"); - - static int const batches = 1000; - - for(std::size_t i=0; i 0) - { - for(std::size_t y=0; y - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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. - */ -//============================================================================== - -#include "ThreadWithServiceQueue.h" - -namespace beast { - -ThreadWithServiceQueue::ThreadWithServiceQueue (const String& name) -: CallQueue(name) -, m_thread(name, this) -, m_entryPoints(nullptr) -, m_calledStart(false) -, m_calledStop(false) -{ -} - -ThreadWithServiceQueue::~ThreadWithServiceQueue () -{ - stop(true); -} - -void ThreadWithServiceQueue::start (EntryPoints* const entryPoints) -{ - // start() MUST be called. - bassert (!m_calledStart); - m_calledStart = true; - - m_entryPoints = entryPoints; - - m_thread.startThread (); -} - -void ThreadWithServiceQueue::stop (bool const wait) -{ - // start() MUST be called. - bassert (m_calledStart); - - if (!m_calledStop) - { - m_calledStop = true; - - m_thread.signalThreadShouldExit(); - - // something could slip in here - - close (); - } - - if (wait) - m_thread.waitForThreadToExit (); -} - -void ThreadWithServiceQueue::runThread () -{ - m_entryPoints->threadInit (); - - while (! m_thread.threadShouldExit ()) - run (); - - // Perform the remaining calls in the queue - - reset (); - poll (); - - m_entryPoints->threadExit(); -} - -//------------------------------------------------------------------------------ - -namespace detail -{ - -//------------------------------------------------------------------------------ - -class ThreadWithServiceQueueTests -: public UnitTest -{ -public: - - struct ThreadWithServiceQueueRunner - : public ThreadWithServiceQueue::EntryPoints - { - ThreadWithServiceQueue m_worker; - int cCallCount, c1CallCount; - int qCallCount, q1CallCount; - int initCalled, exitCalled; - - ThreadWithServiceQueueRunner() - : m_worker("ThreadWithServiceQueueRunner") - , cCallCount(0) - , c1CallCount(0) - , qCallCount(0) - , q1CallCount(0) - , initCalled(0) - , exitCalled(0) - { - } - - void start() - { - m_worker.start(this); - } - - void stop() - { - m_worker.stop(true); - } - - void c() - { - m_worker.call(&ThreadWithServiceQueueRunner::cImpl, this); - } - - void cImpl() - { - cCallCount++; - } - - void c1(int p1) - { - m_worker.call(&ThreadWithServiceQueueRunner::c1Impl, this, p1); - } - - void c1Impl(int p1) - { - c1CallCount++; - } - - void q() - { - m_worker.queue(&ThreadWithServiceQueueRunner::qImpl, this); - } - - void qImpl() - { - qCallCount++; - } - - void q1(int p1) - { - m_worker.queue(&ThreadWithServiceQueueRunner::q1Impl, this, p1); - } - - void q1Impl(int p1) - { - q1CallCount++; - } - - void threadInit () - { - initCalled++; - } - - void threadExit () - { - exitCalled++; - } - }; - - static int const calls = 1000; - - void performCalls() - { - Random r; - r.setSeedRandomly(); - - ThreadWithServiceQueueRunner runner; - - runner.start(); - - for(std::size_t i=0; i - Copyright Patrick Dehne (www.sonicweb-radio.de) - - 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 BEAST_VFLIB_THREADWITHSERVICEQUEUE_H_INCLUDED -#define BEAST_VFLIB_THREADWITHSERVICEQUEUE_H_INCLUDED - -#include "CallQueue.h" - -namespace beast { - -class ThreadWithServiceQueue -: public CallQueue -{ -public: - /** Entry points for a ThreadWithCallQueue. - */ - class EntryPoints - { - public: - virtual ~EntryPoints () { } - - virtual void threadInit () { } - - virtual void threadExit () { } - }; - - explicit ThreadWithServiceQueue (const String& name); - - ~ThreadWithServiceQueue(); - - void start (EntryPoints* const entryPoints); - - void stop (bool const wait); - - /** Calls all functors in the queue. Blocks if there are no - functors available to run until more functors become - available or the queue is stopped - - */ - bool synchronize (); - - /** Helper class to work around ThreadWithServiceQueue and Thread both - having a run member - */ - class Worker - : public Thread - { - public: - Worker(const String& name, ThreadWithServiceQueue *parent) - : Thread(name) - , m_parent(parent) - { - } - - void run() - { - m_parent->runThread(); - } - - private: - ThreadWithServiceQueue *m_parent; - }; - - void runThread (); - -private: - EntryPoints* m_entryPoints; - bool m_calledStart; - bool m_calledStop; - Worker m_thread; -}; - -} - -#endif diff --git a/src/ripple/beast/ripple_beast.cpp b/src/ripple/beast/ripple_beast.cpp index d50e1854d7..fc79ac0dd0 100644 --- a/src/ripple/beast/ripple_beast.cpp +++ b/src/ripple/beast/ripple_beast.cpp @@ -40,10 +40,11 @@ #include "../beast/beast/http/HTTP.cpp" #include "../beast/beast/insight/Insight.cpp" #include "../beast/beast/net/Net.cpp" -#include "../beast/beast/smart_ptr/SmartPtr.cpp" #include "../beast/beast/streams/streams.cpp" #include "../beast/beast/strings/Strings.cpp" #include "../beast/beast/threads/Threads.cpp" #include "../beast/beast/utility/Utility.cpp" #include "../beast/beast/cxx14/cxx14.cpp" + +#include "../beast/beast/unit_test/define_print.cpp" diff --git a/src/ripple/common/KeyCache.h b/src/ripple/common/KeyCache.h index 28e006cf08..a2ebe4c847 100644 --- a/src/ripple/common/KeyCache.h +++ b/src/ripple/common/KeyCache.h @@ -26,6 +26,7 @@ #include #include "../../beast/beast/chrono/abstract_clock.h" +#include "../../beast/beast/chrono/chrono_io.h" #include "../../beast/beast/Insight.h" namespace ripple { diff --git a/src/ripple/common/TaggedCache.h b/src/ripple/common/TaggedCache.h index 882e617ce7..f78c831255 100644 --- a/src/ripple/common/TaggedCache.h +++ b/src/ripple/common/TaggedCache.h @@ -21,10 +21,12 @@ #define RIPPLE_TAGGEDCACHE_H_INCLUDED #include "../../beast/beast/chrono/abstract_clock.h" +#include "../../beast/beast/chrono/chrono_io.h" #include "../../beast/beast/Insight.h" #include +#include #include #include @@ -390,7 +392,8 @@ public: */ bool insert (key_type const& key, T const& value) { - mapped_ptr p (boost::make_shared (boost::cref (value))); + mapped_ptr p (boost::make_shared ( + std::cref (value))); return canonicalize (key, p); } diff --git a/src/ripple/common/counted_bind.h b/src/ripple/common/counted_bind.h deleted file mode 100644 index 9dd6b881d9..0000000000 --- a/src/ripple/common/counted_bind.h +++ /dev/null @@ -1,241 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - 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_COUNTED_BIND_H_INCLUDED -#define RIPPLE_COUNTED_BIND_H_INCLUDED - -#include -#include -#include - -namespace ripple { - -namespace detail { - -// Wrapper for managing the handler count -template -class counted_bind_wrapper -{ -public: - template - counted_bind_wrapper (H&& h, Counter& c) - : m_handler (std::forward (h)) - , m_counter (c) - { - ++m_counter; - } - - counted_bind_wrapper (counted_bind_wrapper&& w) - : m_handler (std::move (w.m_handler)) - , m_counter (w.m_counter) - { - ++m_counter; - } - - counted_bind_wrapper (counted_bind_wrapper const& w) - : m_handler (w.m_handler) - , m_counter (w.m_counter) - { - ++m_counter; - } - - ~counted_bind_wrapper () - { - --m_counter; - } - - //counted_bind_wrapper& operator= (counted_bind_wrapper const&) = delete; - -#if 0 - // When variadic template arguments are supported - template - void operator () (Args&& ...args) const - { - m_handler (std::forward (args)...); - } - -#else - void operator() () - { - m_handler (); - } - - void operator() () const - { - m_handler (); - } - - template - void operator() (P1 const& p1) - { - m_handler (p1); - } - - template - void operator() (P1 const& p1) const - { - m_handler (p1); - } - - template - void operator() (P1 const& p1, P2 const& p2) - { - m_handler (p1, p2); - } - - template - void operator() (P1 const& p1, P2 const& p2) const - { - m_handler (p1, p2); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3) - { - m_handler (p1, p2, p3); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3) const - { - m_handler (p1, p2, p3); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4) - { - m_handler (p1, p2, p3, p4); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4) const - { - m_handler (p1, p2, p3, p4); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5) - { - m_handler (p1, p2, p3, p4, p5); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5) const - { - m_handler (p1, p2, p3, p4, p5); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5, P6 const& p6) - { - m_handler (p1, p2, p3, p4, p5, p6); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5, P6 const& p6) const - { - m_handler (p1, p2, p3, p4, p5, p6); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5, P6 const& p6, P7 const& p7) - { - m_handler (p1, p2, p3, p4, p5, p6, p7); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5, P6 const& p6, P7 const& p7) const - { - m_handler (p1, p2, p3, p4, p5, p6, p7); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5, P6 const& p6, P7 const& p7, P8 const& p8) - { - m_handler (p1, p2, p3, p4, p5, p6, p7, p8); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, - P5 const& p5, P6 const& p6, P7 const& p7, P8 const& p8) const - { - m_handler (p1, p2, p3, p4, p5, p6, p7, p8); - } - -#endif - -private: - Handler m_handler; - Counter& m_counter; -}; - -} - -//------------------------------------------------------------------------------ - -/** Provides a counted_bind replacement for bind which counts pending I/Os. - Derive your class from this class and then call the bind member - function instead. -*/ -class enable_counted_bind -{ -public: - typedef std::size_t size_type; - -private: - typedef std::atomic counter_type; - -public: - enable_counted_bind () - : m_count (0) - { - } - - /** Return the number of binds pending completion. */ - size_type bind_count () const - { - return m_count.load (); - } - - /** Returns a wrapper that calls the handler and manages the counter. */ - template - detail::counted_bind_wrapper wrap (Handler&& h) - { - return detail::counted_bind_wrapper ( - std::forward (h), m_count); - } - -private: - counter_type m_count; -}; - -} - -#endif diff --git a/src/ripple/common/impl/KeyCache.cpp b/src/ripple/common/impl/KeyCache.cpp index 0f0d829edc..eadadc0339 100644 --- a/src/ripple/common/impl/KeyCache.cpp +++ b/src/ripple/common/impl/KeyCache.cpp @@ -19,17 +19,16 @@ #include "../KeyCache.h" +#include "../../beast/beast/unit_test/suite.h" #include "../../beast/beast/chrono/manual_clock.h" namespace ripple { -class KeyCacheTests : public beast::UnitTest +class KeyCache_test : public beast::unit_test::suite { public: - void runTest () + void run () { - beginTestCase ("Insert"); - beast::manual_clock clock; clock.set (0); @@ -90,13 +89,8 @@ public: expect (c.size () < 3); } } - - KeyCacheTests () : UnitTest ( - "KeyCache", "ripple") - { - } }; -static KeyCacheTests keyCacheTests; +BEAST_DEFINE_TESTSUITE(KeyCache,common,ripple); } diff --git a/src/ripple/common/impl/MultiSocket.cpp b/src/ripple/common/impl/MultiSocket.cpp index 2951e06db0..963ea294f5 100644 --- a/src/ripple/common/impl/MultiSocket.cpp +++ b/src/ripple/common/impl/MultiSocket.cpp @@ -21,6 +21,8 @@ #include "../RippleSSLContext.h" +#include "../../beast/beast/unit_test/suite.h" + namespace ripple { MultiSocket* MultiSocket::New ( @@ -45,7 +47,7 @@ MultiSocket* MultiSocket::New ( //------------------------------------------------------------------------------ -class MultiSocketTests : public beast::UnitTest +class MultiSocket_test : public beast::unit_test::suite { public: class MultiSocketDetails : public beast::asio::TestPeerDetails @@ -232,7 +234,8 @@ public: template void testProxyFlags (int extraClientFlags, int extraServerFlags) { - check_precondition (! MultiSocket::Flag (extraClientFlags).any_set (MultiSocket::Flag::client_role | MultiSocket::Flag::server_role)); + check_precondition (! MultiSocket::Flag (extraClientFlags).any_set ( + MultiSocket::Flag::client_role | MultiSocket::Flag::server_role)); runProxy (MultiSocket::Flag::client_role | extraClientFlags, MultiSocket::Flag::server_role | extraServerFlags); @@ -243,7 +246,8 @@ public: template void testFlags (int extraClientFlags, int extraServerFlags) { - check_precondition (! MultiSocket::Flag (extraClientFlags).any_set (MultiSocket::Flag::client_role | MultiSocket::Flag::server_role)); + check_precondition (! MultiSocket::Flag (extraClientFlags).any_set ( + MultiSocket::Flag::client_role | MultiSocket::Flag::server_role)); run (MultiSocket::Flag::client_role | extraClientFlags, MultiSocket::Flag::server_role | extraServerFlags); @@ -288,7 +292,7 @@ public: MultiSocket::Flag::proxy | MultiSocket::Flag::ssl); } - void runTest () + void run () { testProtocol (); } @@ -299,12 +303,8 @@ public: { timeoutSeconds = 10 }; - - MultiSocketTests () : UnitTest ("MultiSocket", "ripple") - { - } }; -static MultiSocketTests multiSocketTests; +BEAST_DEFINE_TESTSUITE(MultiSocket,common,ripple); } diff --git a/src/ripple/common/impl/ResolverAsio.cpp b/src/ripple/common/impl/ResolverAsio.cpp index 960612cbf8..6a62d7dea1 100644 --- a/src/ripple/common/impl/ResolverAsio.cpp +++ b/src/ripple/common/impl/ResolverAsio.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "boost/asio.hpp" @@ -195,7 +196,7 @@ public: { // Attempt to find the first and last non-whitespace auto const find_whitespace = std::bind ( - std::isspace , + &std::isspace , std::placeholders::_1, std::locale ()); diff --git a/src/ripple/common/impl/TaggedCache.cpp b/src/ripple/common/impl/TaggedCache.cpp index b5a4a01cb6..74871139ed 100644 --- a/src/ripple/common/impl/TaggedCache.cpp +++ b/src/ripple/common/impl/TaggedCache.cpp @@ -19,6 +19,7 @@ #include "../TaggedCache.h" +#include "../../beast/beast/unit_test/suite.h" #include "../../beast/beast/chrono/manual_clock.h" namespace ripple { @@ -33,16 +34,13 @@ then canonicalize a new object with the same key, make sure you get the original object. */ -class TaggedCacheTests : public beast::UnitTest +class TaggedCache_test : public beast::unit_test::suite { public: - void runTest () + void run () { - //Journal const j (journal()); beast::Journal const j; - beginTestCase ("Insert"); - beast::manual_clock clock; clock.set (0); @@ -146,13 +144,8 @@ public: expect (c.getTrackSize() == 0); } } - - TaggedCacheTests () : UnitTest ( - "TaggedCache", "ripple") - { - } }; -static TaggedCacheTests taggedCacheTests; +BEAST_DEFINE_TESTSUITE(TaggedCache,common,ripple); } diff --git a/src/ripple/common/impl/counted_bind.cpp b/src/ripple/common/impl/counted_bind.cpp deleted file mode 100644 index 37a4e3f303..0000000000 --- a/src/ripple/common/impl/counted_bind.cpp +++ /dev/null @@ -1,174 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - 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. -*/ -//============================================================================== - -#include "../counted_bind.h" - -namespace ripple { - -class TrackedHandler -{ -public: - explicit TrackedHandler (beast::Journal journal) - : m_journal (journal) - { - m_journal.info << "Constructor"; - } - - TrackedHandler (TrackedHandler const& h) - : m_journal (h.m_journal) - { - m_journal.info << "Copy Constructor"; - } - - TrackedHandler (TrackedHandler&& h) - : m_journal (std::move (h.m_journal)) - { - m_journal.info << "Move Constructor"; - } - - // VFALCO NOTE What the heck does this do? - TrackedHandler (TrackedHandler const&& h) - : m_journal (h.m_journal) - { - m_journal.info << "Move Constructor (const)"; - } - - ~TrackedHandler () - { - m_journal.info << "Destructor"; - } - - void operator () () const - { - m_journal.info << "Function call"; - } - -private: - beast::Journal m_journal; -}; - -//------------------------------------------------------------------------------ - -template -struct HandlerWrapper -{ -#if 1 - // Universal constructor - template - HandlerWrapper (H&& h, std::nullptr_t) // dummy arg - : m_handler (std::forward (h)) - { - } - -#else - // move construct - HandlerWrapper (Handler&& h, nullptr_t) - : m_handler (std::move (h)) - { - } - - // copy construct - HandlerWrapper (Handler const& h, nullptr_t) - : m_handler (h) - { - } -#endif - -#if 0 - template - void operator () (Args&& ...args) - { - m_handler (std::forward (args)...); - } - -#else - void operator() () const - { - m_handler (); - } - -#endif - - Handler const m_handler; -}; - -template -HandlerWrapper < - typename std::remove_reference ::type> make_handler (Handler&& h) -{ - typedef typename std::remove_reference ::type handler_type; - return HandlerWrapper ( - std::forward (h), nullptr); -} - -//------------------------------------------------------------------------------ - -class CountedBindTests : public beast::UnitTest -{ -public: - void runTest () - { - beginTestCase ("Move"); - - beast::Journal const j (journal()); - - { - j.info << "w1"; - TrackedHandler h (j); - HandlerWrapper w1 (std::move (h), nullptr); - w1 (); - } - - { - j.info << "w2"; - HandlerWrapper w2 ((TrackedHandler (j)), nullptr); - w2 (); - } - - { - j.info << "w3"; - TrackedHandler const h (j); - HandlerWrapper w3 (h, nullptr); - w3 (); - } - - { - j.info << "w4"; - auto w4 (make_handler (TrackedHandler (j))); - w4 (); - } - - { - j.info << "w5"; - TrackedHandler const h (j); - auto w5 (make_handler (h)); - w5 (); - } - - pass (); - } - - CountedBindTests () : UnitTest ("counted_bind", "ripple", runManual) - { - } -}; - -static CountedBindTests countedBindTests; - -} diff --git a/src/ripple/common/ripple_common.cpp b/src/ripple/common/ripple_common.cpp index fee71b3f2e..632ffb9ed0 100644 --- a/src/ripple/common/ripple_common.cpp +++ b/src/ripple/common/ripple_common.cpp @@ -19,9 +19,6 @@ #include "../../BeastConfig.h" -#include "../../beast/modules/beast_core/beast_core.h" // for UnitTest - -#include "impl/counted_bind.cpp" #include "impl/KeyCache.cpp" #include "impl/TaggedCache.cpp" #include "impl/ResolverAsio.cpp" diff --git a/src/ripple/json/impl/Tests.cpp b/src/ripple/json/impl/Tests.cpp index 343aabc86e..db64abe59f 100644 --- a/src/ripple/json/impl/Tests.cpp +++ b/src/ripple/json/impl/Tests.cpp @@ -17,15 +17,15 @@ */ //============================================================================== +#include "../../../beast/beast/unit_test/suite.h" + namespace ripple { -class JsonCppTests : public beast::UnitTest +class JsonCpp_test : public beast::unit_test::suite { public: void testBadJson () { - beginTestCase ("bad input"); - char const* s ( "{\"method\":\"ledger\",\"params\":[{\"ledger_index\":1e300}]}" ); @@ -37,16 +37,12 @@ public: pass (); } - void runTest () + void run () { testBadJson (); } - - JsonCppTests () : UnitTest ("JsonCpp", "ripple") - { - } }; -static JsonCppTests jsonCppTests; +BEAST_DEFINE_TESTSUITE(JsonCpp,json,ripple); -} // namespace ripple +} // ripple diff --git a/src/ripple/peerfinder/impl/Livecache.cpp b/src/ripple/peerfinder/impl/Livecache.cpp index 7af9a9c744..e804f579b1 100644 --- a/src/ripple/peerfinder/impl/Livecache.cpp +++ b/src/ripple/peerfinder/impl/Livecache.cpp @@ -17,12 +17,13 @@ */ //============================================================================== -#include "../.././beast/beast/chrono/manual_clock.h" +#include "../../../beast/beast/unit_test/suite.h" +#include "../../../beast/beast/chrono/manual_clock.h" namespace ripple { namespace PeerFinder { -class LivecacheTests : public beast::UnitTest +class Livecache_test : public beast::unit_test::suite { public: beast::manual_clock m_clock; @@ -40,8 +41,6 @@ public: void testFetch () { - beginTestCase ("fetch"); - Livecache <> c (m_clock, beast::Journal()); add (1, 1, c); @@ -60,17 +59,13 @@ public: pass(); } - void runTest () + void run () { testFetch (); } - - LivecacheTests () : UnitTest ("PeerFinder:Livecache", "ripple") - { - } }; -static LivecacheTests livecacheTests; +BEAST_DEFINE_TESTSUITE(Livecache,peerfinder,ripple); } } diff --git a/src/ripple/peerfinder/ripple_peerfinder.cpp b/src/ripple/peerfinder/ripple_peerfinder.cpp index ebee802393..a82bb0d25d 100644 --- a/src/ripple/peerfinder/ripple_peerfinder.cpp +++ b/src/ripple/peerfinder/ripple_peerfinder.cpp @@ -41,6 +41,7 @@ #include "../beast/modules/beast_asio/beast_asio.h" #include "../beast/beast/boost/ErrorCode.h" +#include "../beast/beast/chrono/chrono_io.h" #include "impl/iosformat.h" // VFALCO NOTE move to beast diff --git a/src/ripple/resource/impl/Tests.cpp b/src/ripple/resource/impl/Tests.cpp index 000c434cd4..3a75f8784d 100644 --- a/src/ripple/resource/impl/Tests.cpp +++ b/src/ripple/resource/impl/Tests.cpp @@ -17,12 +17,13 @@ */ //============================================================================== -#include "../.././beast/beast/chrono/manual_clock.h" +#include "../../../beast/beast/unit_test/suite.h" +#include "../../../beast/beast/chrono/manual_clock.h" namespace ripple { namespace Resource { -class Tests : public beast::UnitTest +class Manager_test : public beast::unit_test::suite { public: class TestLogic @@ -55,13 +56,14 @@ public: void createGossip (Gossip& gossip) { - int const v (10 + random().nextInt (10)); - int const n (10 + random().nextInt (10)); + beast::Random r; + int const v (10 + r.nextInt (10)); + int const n (10 + r.nextInt (10)); gossip.items.reserve (n); for (int i = 0; i < n; ++i) { Gossip::Item item; - item.balance = 100 + random().nextInt (500); + item.balance = 100 + r.nextInt (500); item.address = beast::IP::Endpoint ( beast::IP::AddressV4 (207, 127, 82, v + i)); gossip.items.push_back (item); @@ -77,9 +79,9 @@ public: void testDrop (beast::Journal j) { - beginTestCase ("Warn/drop"); + testcase ("Warn/drop"); - Tests::TestLogic logic (j); + TestLogic logic (j); Charge const fee (dropThreshold + 1); beast::IP::Endpoint const addr ( @@ -148,7 +150,7 @@ public: void testImports (beast::Journal j) { - beginTestCase ("Imports"); + testcase ("Imports"); TestLogic logic (j); @@ -165,7 +167,7 @@ public: void testImport (beast::Journal j) { - beginTestCase ("Import"); + testcase ("Import"); TestLogic logic (j); @@ -183,7 +185,7 @@ public: void testCharges (beast::Journal j) { - beginTestCase ("Charge"); + testcase ("Charge"); TestLogic logic (j); @@ -222,9 +224,8 @@ public: pass(); } - void runTest () + void run() { - //Journal j (journal()); beast::Journal j; testDrop (j); @@ -232,13 +233,9 @@ public: testImports (j); testImport (j); } - - Tests () : UnitTest ("ResourceManager", "ripple") - { - } }; -static Tests tests; +BEAST_DEFINE_TESTSUITE(Manager,resource,ripple); } } diff --git a/src/ripple/resource/ripple_resource.cpp b/src/ripple/resource/ripple_resource.cpp index df882139d6..2d8733ada0 100644 --- a/src/ripple/resource/ripple_resource.cpp +++ b/src/ripple/resource/ripple_resource.cpp @@ -30,6 +30,7 @@ #include "../beast/beast/Insight.h" #include "../beast/beast/cxx14/memory.h" +#include "../beast/beast/chrono/chrono_io.h" #include "impl/Fees.cpp" # include "impl/Kind.h" diff --git a/src/ripple/sitefiles/TODO.md b/src/ripple/sitefiles/TODO.md index 64904f9475..604537b2d1 100644 --- a/src/ripple/sitefiles/TODO.md +++ b/src/ripple/sitefiles/TODO.md @@ -1,7 +1,5 @@ # SiteFiles TODO -- UnitTest - - Use it in more places - Process the local file diff --git a/src/ripple/sslutil/impl/ECDSACanonical.cpp b/src/ripple/sslutil/impl/ECDSACanonical.cpp index 9714a7b9c6..9baab4fd32 100644 --- a/src/ripple/sslutil/impl/ECDSACanonical.cpp +++ b/src/ripple/sslutil/impl/ECDSACanonical.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include "../../../beast/beast/unit_test/suite.h" + namespace ripple { namespace detail { @@ -196,13 +198,9 @@ void hex_to_binary (FwdIter first, FwdIter last, Container& out) } } -class ECDSACanonicalTests : public beast::UnitTest +class ECDSACanonical_test : public beast::unit_test::suite { public: - ECDSACanonicalTests () : UnitTest ("ECDSACanonical", "ripple") - { - } - bool isCanonical (std::string const& hex) { Blob j; @@ -210,10 +208,8 @@ public: return isCanonicalECDSASig (&j[0], j.size(), ECDSA::not_strict); } - void runTest () + void run () { - beginTestCase ("canonicalSignatures"); - expect (isCanonical("304402203932c892e2e550f3af8ee4ce9c215a87f9bb" "831dcac87b2838e2c2eaa891df0c022030b61dd36543125d56b9f9f3a1f" "53189e5af33cdda8d77a5209aec03978fa001"), "canonical signature"); @@ -294,6 +290,6 @@ public: } }; -static ECDSACanonicalTests ECDSACTests; +BEAST_DEFINE_TESTSUITE(ECDSACanonical,sslutil,ripple); } diff --git a/src/ripple/testoverlay/impl/TestOverlay.cpp b/src/ripple/testoverlay/impl/TestOverlay.cpp index 6a2b282859..8fe7a6cda3 100644 --- a/src/ripple/testoverlay/impl/TestOverlay.cpp +++ b/src/ripple/testoverlay/impl/TestOverlay.cpp @@ -17,9 +17,17 @@ */ //============================================================================== +#include "../../../beast/beast/unit_test/suite.h" + +#include +#include +#include +#include + +namespace ripple { namespace TestOverlay { -class Tests : public beast::UnitTest +class Network1_test : public beast::unit_test::suite { public: template @@ -108,8 +116,6 @@ public: void testCreation () { - beginTestCase ("create"); - Network network; Results result; @@ -121,28 +127,23 @@ public: network.steps()) + " "; result += network.step (); s << result.toString (); - logMessage (s); + log << s.toStdString(); } int const seen (network.state().seen()); beast::String s = "Seen = " + beast::String::fromNumber (seen); - logMessage (s); + log << + s.toStdString(); pass (); } - void runTest () + void run () { testCreation (); } - - Tests () : UnitTest ("TestOverlay", "ripple", runManual) - { - } }; -static Tests tests; - //------------------------------------------------------------------------------ // // @@ -430,7 +431,7 @@ private: //------------------------------------------------------------------------------ -class Tests2 : public beast::UnitTest +class Network2_test : public beast::unit_test::suite { public: class Message : public BasicMessage @@ -523,32 +524,28 @@ public: void test1 () { - beginTestCase ("network"); - int count (0); std::vector peers; make_peers (peers, 10000, &count); - make_connections (peers, 3, random()); + make_connections (peers, 3, beast::Random()); peers[0].send (Message ()); for (int i = 0; i < 10; ++i) { iterate (peers); - journal().info << "count = " << count; + log << + "count = " << count; } pass(); } - void runTest () + void run () { test1 (); } - - Tests2 () - : UnitTest ("TestOverlay2", "ripple", runManual) - { - } }; -static Tests2 tests2; +BEAST_DEFINE_TESTSUITE_MANUAL(Network1,overlay,ripple); +BEAST_DEFINE_TESTSUITE_MANUAL(Network2,overlay,ripple); } +} diff --git a/src/ripple/testoverlay/ripple_testoverlay.cpp b/src/ripple/testoverlay/ripple_testoverlay.cpp index 4cfddfd25c..753bc544f0 100644 --- a/src/ripple/testoverlay/ripple_testoverlay.cpp +++ b/src/ripple/testoverlay/ripple_testoverlay.cpp @@ -21,13 +21,4 @@ #include "ripple_testoverlay.h" -#include -#include -#include -#include - -namespace ripple { - #include "impl/TestOverlay.cpp" - -} diff --git a/src/ripple/types/impl/RippleAssets.cpp b/src/ripple/types/impl/RippleAssets.cpp index dd34451ab7..aa20f8eeae 100644 --- a/src/ripple/types/impl/RippleAssets.cpp +++ b/src/ripple/types/impl/RippleAssets.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include "../../../beast/beast/unit_test/suite.h" + #include #include #include @@ -36,11 +38,9 @@ # endif #endif - - namespace ripple { -class RippleAssetTests : public beast::UnitTest +class RippleAsset_test : public beast::unit_test::suite { public: // Comparison, hash tests for uint60 (via base_uint) @@ -205,46 +205,46 @@ public: void testAssetSets () { - beginTestCase ("std::set "); + testcase ("std::set "); testAssetSet > (); - beginTestCase ("std::set "); + testcase ("std::set "); testAssetSet > (); #if RIPPLE_ASSETS_ENABLE_STD_HASH - beginTestCase ("std::unordered_set "); + testcase ("std::unordered_set "); testAssetSet > (); - beginTestCase ("std::unordered_set "); + testcase ("std::unordered_set "); testAssetSet > (); #endif - beginTestCase ("boost::unordered_set "); + testcase ("boost::unordered_set "); testAssetSet > (); - beginTestCase ("boost::unordered_set "); + testcase ("boost::unordered_set "); testAssetSet > (); } void testAssetMaps () { - beginTestCase ("std::map "); + testcase ("std::map "); testAssetMap > (); - beginTestCase ("std::map "); + testcase ("std::map "); testAssetMap > (); #if RIPPLE_ASSETS_ENABLE_STD_HASH - beginTestCase ("std::unordered_map "); + testcase ("std::unordered_map "); testAssetMap > (); - beginTestCase ("std::unordered_map "); + testcase ("std::unordered_map "); testAssetMap > (); - beginTestCase ("boost::unordered_map "); + testcase ("boost::unordered_map "); testAssetMap > (); - beginTestCase ("boost::unordered_map "); + testcase ("boost::unordered_map "); testAssetMap > (); #endif @@ -390,66 +390,66 @@ public: void testBookSets () { - beginTestCase ("std::set "); + testcase ("std::set "); testBookSet > (); - beginTestCase ("std::set "); + testcase ("std::set "); testBookSet > (); #if RIPPLE_ASSETS_ENABLE_STD_HASH - beginTestCase ("std::unordered_set "); + testcase ("std::unordered_set "); testBookSet > (); - beginTestCase ("std::unordered_set "); + testcase ("std::unordered_set "); testBookSet > (); #endif - beginTestCase ("boost::unordered_set "); + testcase ("boost::unordered_set "); testBookSet > (); - beginTestCase ("boost::unordered_set "); + testcase ("boost::unordered_set "); testBookSet > (); } void testBookMaps () { - beginTestCase ("std::map "); + testcase ("std::map "); testBookMap > (); - beginTestCase ("std::map "); + testcase ("std::map "); testBookMap > (); #if RIPPLE_ASSETS_ENABLE_STD_HASH - beginTestCase ("std::unordered_map "); + testcase ("std::unordered_map "); testBookMap > (); - beginTestCase ("std::unordered_map "); + testcase ("std::unordered_map "); testBookMap > (); - beginTestCase ("boost::unordered_map "); + testcase ("boost::unordered_map "); testBookMap > (); - beginTestCase ("boost::unordered_map "); + testcase ("boost::unordered_map "); testBookMap > (); #endif } //-------------------------------------------------------------------------- - void runTest () + void run() { - beginTestCase ("RippleCurrency"); + testcase ("RippleCurrency"); testUnsigned (); - beginTestCase ("RippleIssuer"); + testcase ("RippleIssuer"); testUnsigned (); // --- - beginTestCase ("RippleAsset"); + testcase ("RippleAsset"); testAssetType (); - beginTestCase ("RippleAssetRef"); + testcase ("RippleAssetRef"); testAssetType (); testAssetSets (); @@ -457,21 +457,17 @@ public: // --- - beginTestCase ("RippleBook"); + testcase ("RippleBook"); testBook (); - beginTestCase ("RippleBookRef"); + testcase ("RippleBookRef"); testBook (); testBookSets (); testBookMaps (); } - - RippleAssetTests () : UnitTest ("RippleAsset", "ripple") - { - } }; -static RippleAssetTests rippleAssetTests; +BEAST_DEFINE_TESTSUITE(RippleAsset,types,ripple); } diff --git a/src/ripple/validators/impl/Tests.cpp b/src/ripple/validators/impl/Tests.cpp index b68ce9e851..1a2ef98ca1 100644 --- a/src/ripple/validators/impl/Tests.cpp +++ b/src/ripple/validators/impl/Tests.cpp @@ -17,13 +17,15 @@ */ //============================================================================== +#include "../../../beast/beast/unit_test/suite.h" + namespace ripple { namespace Validators { -class Tests : public beast::UnitTest +class Logic_test : public beast::unit_test::suite { public: - enum + enum { numberOfTestValidators = 1000, numberofTestSources = 50 @@ -172,19 +174,18 @@ public: void addSources (Logic& logic) { + beast::Random r; for (int i = 1; i <= numberofTestSources; ++i) { beast::String const name (beast::String::fromNumber (i)); - beast::uint32 const start = random().nextInt (numberOfTestValidators); - beast::uint32 const end = start + random().nextInt (numberOfTestValidators); + beast::uint32 const start = r.nextInt (numberOfTestValidators); + beast::uint32 const end = start + r.nextInt (numberOfTestValidators); logic.add (new TestSource (name, start, end)); } } void testLogic () { - beginTestCase ("logic"); - //TestStore store; StoreSqdb storage; @@ -196,7 +197,7 @@ public: // Can't call this 'error' because of ADL and Journal::error beast::Error err (storage.open (file)); - unexpected (err, err.what()); + expect (! err, err.what()); Logic logic (storage, beast::Journal ()); logic.load (); @@ -210,23 +211,14 @@ public: pass (); } - void runTest () + void + run () { - // We need to use the same seed so we create the - // same IDs for the set of TestSource objects. - // - beast::int64 const seedValue = 10; - random().setSeed (seedValue); - testLogic (); } - - Tests () : UnitTest ("Validators", "ripple", runManual) - { - } }; -static Tests tests; +BEAST_DEFINE_TESTSUITE(Logic,validators,ripple); } } diff --git a/src/ripple_app/consensus/DisputedTx.cpp b/src/ripple_app/consensus/DisputedTx.cpp index 00ce2acc0c..da5ca2c0c4 100644 --- a/src/ripple_app/consensus/DisputedTx.cpp +++ b/src/ripple_app/consensus/DisputedTx.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // #define TRUST_NETWORK // Track a peer's yes/no vote on a particular disputed transaction @@ -148,3 +150,5 @@ Json::Value DisputedTx::getJson () return ret; } +} // ripple + diff --git a/src/ripple_app/consensus/DisputedTx.h b/src/ripple_app/consensus/DisputedTx.h index 9d01d6d041..715bbeb4a5 100644 --- a/src/ripple_app/consensus/DisputedTx.h +++ b/src/ripple_app/consensus/DisputedTx.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_DISPUTEDTX_H #define RIPPLE_DISPUTEDTX_H +namespace ripple { + /** A transaction discovered to be in dispute during conensus. During consensus, a @ref DisputedTx is created when a transaction @@ -85,4 +87,6 @@ typedef std::map::value_type u160_prop_pair; #define LEDGER_TOTAL_PASSES 8 #define LEDGER_RETRY_PASSES 5 +} // ripple + #endif diff --git a/src/ripple_app/consensus/LedgerConsensus.cpp b/src/ripple_app/consensus/LedgerConsensus.cpp index 399b67db31..a2302067c9 100644 --- a/src/ripple_app/consensus/LedgerConsensus.cpp +++ b/src/ripple_app/consensus/LedgerConsensus.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (LedgerConsensus) // #define TRUST_NETWORK @@ -1922,3 +1924,5 @@ boost::shared_ptr LedgerConsensus::New (clock_type& clock, return boost::make_shared ( clock, prevLCLHash, previousLedger,closeTime); } + +} // ripple diff --git a/src/ripple_app/consensus/LedgerConsensus.h b/src/ripple_app/consensus/LedgerConsensus.h index d826d18729..56135fb78a 100644 --- a/src/ripple_app/consensus/LedgerConsensus.h +++ b/src/ripple_app/consensus/LedgerConsensus.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERCONSENSUS_H #define RIPPLE_LEDGERCONSENSUS_H +namespace ripple { + /** Manager for achieving consensus on the next ledger. This object is created when the consensus process starts, and @@ -82,5 +84,6 @@ public: virtual void simulate () = 0; }; +} // ripple #endif diff --git a/src/ripple_app/contracts/Contract.cpp b/src/ripple_app/contracts/Contract.cpp index 66f448c17f..782a291d88 100644 --- a/src/ripple_app/contracts/Contract.cpp +++ b/src/ripple_app/contracts/Contract.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + Contract::Contract () { @@ -43,4 +45,4 @@ void Contract::executeAccept () //interpreter.interpret(this,code); } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/contracts/Contract.h b/src/ripple_app/contracts/Contract.h index fba16f5665..ae27d44569 100644 --- a/src/ripple_app/contracts/Contract.h +++ b/src/ripple_app/contracts/Contract.h @@ -20,9 +20,7 @@ #ifndef CONTRACT_H #define CONTRACT_H -/* - Encapsulates the SLE for a Contract -*/ +namespace ripple { class Contract { @@ -43,6 +41,6 @@ public: void executeAccept (); }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/contracts/Interpreter.cpp b/src/ripple_app/contracts/Interpreter.cpp index bbd3db2df3..bdbd06474c 100644 --- a/src/ripple_app/contracts/Interpreter.cpp +++ b/src/ripple_app/contracts/Interpreter.cpp @@ -17,10 +17,7 @@ */ //============================================================================== -/* -We also need to charge for each op - -*/ +namespace ripple { namespace Script { @@ -226,7 +223,6 @@ bool Interpreter::canSign (const uint160& signer) return (true); } +} - - -} // end namespace +} // ripple diff --git a/src/ripple_app/contracts/Interpreter.h b/src/ripple_app/contracts/Interpreter.h index 642c0aa401..5c9dc7b8a4 100644 --- a/src/ripple_app/contracts/Interpreter.h +++ b/src/ripple_app/contracts/Interpreter.h @@ -20,8 +20,9 @@ #ifndef INTERPRETER_H #define INTERPRETER_H -namespace Script -{ +namespace ripple { + +namespace Script { class Operation; // Contracts are non typed have variable data types @@ -96,4 +97,6 @@ public: } // end namespace +} // ripple + #endif diff --git a/src/ripple_app/contracts/Operation.cpp b/src/ripple_app/contracts/Operation.cpp index 9de8274cb2..8614e80291 100644 --- a/src/ripple_app/contracts/Operation.cpp +++ b/src/ripple_app/contracts/Operation.cpp @@ -22,6 +22,8 @@ We also need to charge for each op */ +namespace ripple { + namespace Script { @@ -31,4 +33,6 @@ int Operation::getFee () return (getConfig ().FEE_CONTRACT_OPERATION); } -} \ No newline at end of file +} + +} // ripple diff --git a/src/ripple_app/contracts/Operation.h b/src/ripple_app/contracts/Operation.h index 3363f3ab20..6bb1f96e92 100644 --- a/src/ripple_app/contracts/Operation.h +++ b/src/ripple_app/contracts/Operation.h @@ -20,8 +20,9 @@ #ifndef OPERATION_H #define OPERATION_H -namespace Script -{ +namespace ripple { + +namespace Script { // Contracts are non typed have variable data types @@ -374,7 +375,6 @@ public: } +} // ripple + #endif - -// vim:ts=4 - diff --git a/src/ripple_app/contracts/ScriptData.cpp b/src/ripple_app/contracts/ScriptData.cpp index 398cc19215..5f37c43da7 100644 --- a/src/ripple_app/contracts/ScriptData.cpp +++ b/src/ripple_app/contracts/ScriptData.cpp @@ -17,3 +17,6 @@ */ //============================================================================== +namespace ripple { + +} // ripple diff --git a/src/ripple_app/contracts/ScriptData.h b/src/ripple_app/contracts/ScriptData.h index b8939463ec..9f87f973d5 100644 --- a/src/ripple_app/contracts/ScriptData.h +++ b/src/ripple_app/contracts/ScriptData.h @@ -20,6 +20,8 @@ #ifndef SCRIPT_DATA_H #define SCRIPT_DATA_H +namespace ripple { + namespace Script { class Data @@ -179,6 +181,6 @@ public: } -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/data/DBInit.cpp b/src/ripple_app/data/DBInit.cpp index 608d0361b4..49277b4cfc 100644 --- a/src/ripple_app/data/DBInit.cpp +++ b/src/ripple_app/data/DBInit.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // Transaction database holds transactions and public keys const char* TxnDBInit[] = { @@ -332,3 +334,4 @@ const char* PathFindDBInit[] = int PathFindDBCount = NUMBER (PathFindDBInit); */ +} // ripple diff --git a/src/ripple_app/data/DBInit.h b/src/ripple_app/data/DBInit.h index f0c4b8c489..36dfaa7732 100644 --- a/src/ripple_app/data/DBInit.h +++ b/src/ripple_app/data/DBInit.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_DBINIT_H_INCLUDED #define RIPPLE_DBINIT_H_INCLUDED +namespace ripple { + // VFALCO TODO Tidy these up into a class with functions and return types. extern const char* RpcDBInit[]; extern const char* TxnDBInit[]; @@ -32,4 +34,6 @@ extern int TxnDBCount; extern int LedgerDBCount; extern int WalletDBCount; +} // ripple + #endif diff --git a/src/ripple_app/data/Database.cpp b/src/ripple_app/data/Database.cpp index 0512b479b8..fadb149fc6 100644 --- a/src/ripple_app/data/Database.cpp +++ b/src/ripple_app/data/Database.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + Database::Database (const char* host) : mNumCol (0) { @@ -203,4 +205,4 @@ char* Database::getSingleDBValueStr (const char* sql, std::string& retStr) } #endif -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/data/Database.h b/src/ripple_app/data/Database.h index 158ae1815e..28844d6508 100644 --- a/src/ripple_app/data/Database.h +++ b/src/ripple_app/data/Database.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_DATABASE_H_INCLUDED #define RIPPLE_DATABASE_H_INCLUDED +namespace ripple { + // VFALCO Get rid of these macros // #define SQL_FOREACH(_db, _strQuery) \ @@ -116,6 +118,6 @@ protected: std::vector mColNameTable; }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/data/DatabaseCon.cpp b/src/ripple_app/data/DatabaseCon.cpp index b7bef72048..5d03b0d283 100644 --- a/src/ripple_app/data/DatabaseCon.cpp +++ b/src/ripple_app/data/DatabaseCon.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + DatabaseCon::DatabaseCon (const std::string& strName, const char* initStrings[], int initCount) { // VFALCO TODO remove this dependency on the config by making it the caller's @@ -40,3 +42,5 @@ DatabaseCon::~DatabaseCon () mDatabase->disconnect (); delete mDatabase; } + +} // ripple diff --git a/src/ripple_app/data/DatabaseCon.h b/src/ripple_app/data/DatabaseCon.h index abd18a9586..c60834c4dd 100644 --- a/src/ripple_app/data/DatabaseCon.h +++ b/src/ripple_app/data/DatabaseCon.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_DATABASECON_H #define RIPPLE_DATABASECON_H +namespace ripple { + // VFALCO NOTE This looks like a pointless class. Figure out // what purpose it is really trying to serve and do it better. class DatabaseCon : beast::LeakChecked @@ -42,5 +44,7 @@ private: DeprecatedRecursiveMutex mLock; }; +} // ripple + #endif diff --git a/src/ripple_app/data/SqliteDatabase.cpp b/src/ripple_app/data/SqliteDatabase.cpp index 0565c5a268..f9d5e921a4 100644 --- a/src/ripple_app/data/SqliteDatabase.cpp +++ b/src/ripple_app/data/SqliteDatabase.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (SqliteDatabase) SqliteStatement::SqliteStatement (SqliteDatabase* db, const char* sql, bool aux) @@ -483,4 +485,4 @@ std::string SqliteStatement::getError (int j) return sqlite3_errstr (j); } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/data/SqliteDatabase.h b/src/ripple_app/data/SqliteDatabase.h index cc8ffa023a..7c82dee935 100644 --- a/src/ripple_app/data/SqliteDatabase.h +++ b/src/ripple_app/data/SqliteDatabase.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SQLITEDATABASE_H_INCLUDED #define RIPPLE_SQLITEDATABASE_H_INCLUDED +namespace ripple { + class SqliteDatabase : public Database , private beast::Thread @@ -144,6 +146,6 @@ public: std::string getError (int); }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/ledger/AcceptedLedger.cpp b/src/ripple_app/ledger/AcceptedLedger.cpp index 99b52c1136..51563383dc 100644 --- a/src/ripple_app/ledger/AcceptedLedger.cpp +++ b/src/ripple_app/ledger/AcceptedLedger.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO TODO Remove this global and make it a member of the App // Use a dependency injection to give AcceptedLedger access. // @@ -62,3 +64,5 @@ AcceptedLedgerTx::pointer AcceptedLedger::getTxn (int i) const return it->second; } + +} // ripple diff --git a/src/ripple_app/ledger/AcceptedLedger.h b/src/ripple_app/ledger/AcceptedLedger.h index 2db1703781..ac526ea0d1 100644 --- a/src/ripple_app/ledger/AcceptedLedger.h +++ b/src/ripple_app/ledger/AcceptedLedger.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_ACCEPTEDLEDGER_H #define RIPPLE_ACCEPTEDLEDGER_H +namespace ripple { + /** A ledger that has become irrevocable. An accepted ledger is a ledger that has a sufficient number of @@ -89,4 +91,6 @@ private: map_t mMap; }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/AcceptedLedgerTx.cpp b/src/ripple_app/ledger/AcceptedLedgerTx.cpp index 0fdf6ac229..f12870a776 100644 --- a/src/ripple_app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple_app/ledger/AcceptedLedgerTx.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + AcceptedLedgerTx::AcceptedLedgerTx (beast::uint32 seq, SerializerIterator& sit) { Serializer txnSer (sit.getVL ()); @@ -72,3 +74,4 @@ void AcceptedLedgerTx::buildJson () } } +} // ripple diff --git a/src/ripple_app/ledger/AcceptedLedgerTx.h b/src/ripple_app/ledger/AcceptedLedgerTx.h index e16d5e32c9..fbf28e4534 100644 --- a/src/ripple_app/ledger/AcceptedLedgerTx.h +++ b/src/ripple_app/ledger/AcceptedLedgerTx.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_ACCEPTEDLEDGERTX_H #define RIPPLE_ACCEPTEDLEDGERTX_H -//------------------------------------------------------------------------------ +namespace ripple { /** A transaction that is in a closed ledger. @@ -107,4 +107,6 @@ private: void buildJson (); }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/DirectoryEntryIterator.cpp b/src/ripple_app/ledger/DirectoryEntryIterator.cpp index c0a071f78c..1cd5b57132 100644 --- a/src/ripple_app/ledger/DirectoryEntryIterator.cpp +++ b/src/ripple_app/ledger/DirectoryEntryIterator.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -/** Get the current ledger entry -*/ +namespace ripple { + +/** Get the current ledger entry */ SLE::pointer DirectoryEntryIterator::getEntry (LedgerEntrySet& les, LedgerEntryType type) { return les.entryCache (type, mEntryIndex); @@ -107,4 +108,4 @@ bool DirectoryEntryIterator::setJson (Json::Value const& j, LedgerEntrySet& les) return true; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/ledger/DirectoryEntryIterator.h b/src/ripple_app/ledger/DirectoryEntryIterator.h index aca609ef9c..d8e965ce49 100644 --- a/src/ripple_app/ledger/DirectoryEntryIterator.h +++ b/src/ripple_app/ledger/DirectoryEntryIterator.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_DIRECTORYENTRYITERATOR_H_INCLUDED #define RIPPLE_DIRECTORYENTRYITERATOR_H_INCLUDED -/** An iterator that walks the ledger entries in a single directory -*/ +namespace ripple { + +/** An iterator that walks the ledger entries in a single directory */ class DirectoryEntryIterator { @@ -80,6 +81,6 @@ private: SLE::pointer mDirNode; // SLE for the entry we are on }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/ledger/InboundLedger.cpp b/src/ripple_app/ledger/InboundLedger.cpp index de4083e7a9..5bc0c8b668 100644 --- a/src/ripple_app/ledger/InboundLedger.cpp +++ b/src/ripple_app/ledger/InboundLedger.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + //SETUP_LOG (InboundLedger) template <> char const* LogPartition::getPartitionName () { return "InLedger"; } @@ -1265,3 +1267,5 @@ Json::Value InboundLedger::getJson (int) return ret; } + +} // ripple diff --git a/src/ripple_app/ledger/InboundLedger.h b/src/ripple_app/ledger/InboundLedger.h index 43d32c064a..b23663429a 100644 --- a/src/ripple_app/ledger/InboundLedger.h +++ b/src/ripple_app/ledger/InboundLedger.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_INBOUNDLEDGER_H #define RIPPLE_INBOUNDLEDGER_H +namespace ripple { + // VFALCO TODO Rename to InboundLedger // A ledger we are trying to acquire class InboundLedger @@ -149,4 +151,6 @@ private: std::vector > mOnComplete; }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/InboundLedgers.cpp b/src/ripple_app/ledger/InboundLedgers.cpp index b0f1e7a166..2ec562ee97 100644 --- a/src/ripple_app/ledger/InboundLedgers.cpp +++ b/src/ripple_app/ledger/InboundLedgers.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +namespace ripple { class InboundLedgersImp : public InboundLedgers @@ -401,23 +402,4 @@ InboundLedgers* InboundLedgers::New (clock_type& clock, beast::Stoppable& parent return new InboundLedgersImp (clock, parent, collector); } - - - - - - - - - - - - - - - - - - - - +} // ripple diff --git a/src/ripple_app/ledger/InboundLedgers.h b/src/ripple_app/ledger/InboundLedgers.h index 5a4ff5b345..dd022587e5 100644 --- a/src/ripple_app/ledger/InboundLedgers.h +++ b/src/ripple_app/ledger/InboundLedgers.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_INBOUNDLEDGERS_H #define RIPPLE_INBOUNDLEDGERS_H +namespace ripple { + /** Manages the lifetime of inbound ledgers. @see InboundLedger @@ -77,4 +79,6 @@ public: virtual void onStop() = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/Ledger.cpp b/src/ripple_app/ledger/Ledger.cpp index 24cff81eb2..446f0af9e2 100644 --- a/src/ripple_app/ledger/Ledger.cpp +++ b/src/ripple_app/ledger/Ledger.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + SETUP_LOG (Ledger) LedgerBase::LedgerBase () @@ -2042,17 +2046,11 @@ std::vector Ledger::getNeededAccountStateHashes (int max, SHAMapSyncFil //------------------------------------------------------------------------------ -class LedgerTests : public beast::UnitTest +class Ledger_test : public beast::unit_test::suite { public: - LedgerTests () : UnitTest ("Ledger", "ripple") + void run () { - } - - void runTest () - { - beginTestCase ("uint256"); - uint256 uBig ("D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000"); // VFALCO NOTE This fails in the original version as well. @@ -2060,7 +2058,9 @@ public: } }; -static LedgerTests ledgerTests; +BEAST_DEFINE_TESTSUITE(Ledger,ripple_app,ripple); Ledger::StaticLockType Ledger::sPendingSaveLock ("LedgerStatic", __FILE__, __LINE__); std::set Ledger::sPendingSaves; + +} // ripple diff --git a/src/ripple_app/ledger/Ledger.h b/src/ripple_app/ledger/Ledger.h index fdb69a9546..6c09c1eef3 100644 --- a/src/ripple_app/ledger/Ledger.h +++ b/src/ripple_app/ledger/Ledger.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGER_H #define RIPPLE_LEDGER_H +namespace ripple { + class Job; enum LedgerStateParms @@ -524,4 +526,6 @@ inline LedgerStateParms operator& (const LedgerStateParms& l1, const LedgerState return static_cast (static_cast (l1) & static_cast (l2)); } +} // ripple + #endif diff --git a/src/ripple_app/ledger/LedgerCleaner.cpp b/src/ripple_app/ledger/LedgerCleaner.cpp index dc9e9a7a5e..e8a9fbdac4 100644 --- a/src/ripple_app/ledger/LedgerCleaner.cpp +++ b/src/ripple_app/ledger/LedgerCleaner.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + /* LedgerCleaner @@ -442,3 +444,5 @@ LedgerCleaner* LedgerCleaner::New ( { return new LedgerCleanerImp (parent, journal); } + +} // ripple diff --git a/src/ripple_app/ledger/LedgerCleaner.h b/src/ripple_app/ledger/LedgerCleaner.h index 14f07f6d51..26c9a33ef6 100644 --- a/src/ripple_app/ledger/LedgerCleaner.h +++ b/src/ripple_app/ledger/LedgerCleaner.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERCLEANER_H_INCLUDED #define RIPPLE_LEDGERCLEANER_H_INCLUDED +namespace ripple { + /** Check the ledger/transaction databases to make sure they have continuity */ class LedgerCleaner : public beast::Stoppable @@ -52,4 +54,6 @@ public: virtual void doClean (Json::Value const& parameters) = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/LedgerEntrySet.cpp b/src/ripple_app/ledger/LedgerEntrySet.cpp index 62d1148a14..edb9f679b8 100644 --- a/src/ripple_app/ledger/LedgerEntrySet.cpp +++ b/src/ripple_app/ledger/LedgerEntrySet.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (LedgerEntrySet) // #define META_DEBUG @@ -1680,4 +1682,5 @@ TER LedgerEntrySet::accountSend (const uint160& uSenderID, const uint160& uRecei return terResult; } -// vim:ts=4 +} // ripple + diff --git a/src/ripple_app/ledger/LedgerEntrySet.h b/src/ripple_app/ledger/LedgerEntrySet.h index cfc6251923..ec53c74515 100644 --- a/src/ripple_app/ledger/LedgerEntrySet.h +++ b/src/ripple_app/ledger/LedgerEntrySet.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERENTRYSET_H #define RIPPLE_LEDGERENTRYSET_H +namespace ripple { + enum TransactionEngineParams { tapNONE = 0x00, @@ -287,4 +289,6 @@ inline LedgerEntrySet::iterator range_end (LedgerEntrySet& x) return x.end (); } +} // ripple + #endif diff --git a/src/ripple_app/ledger/LedgerHistory.cpp b/src/ripple_app/ledger/LedgerHistory.cpp index 4cbac2e276..a3de203ff4 100644 --- a/src/ripple_app/ledger/LedgerHistory.cpp +++ b/src/ripple_app/ledger/LedgerHistory.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO TODO replace macros #ifndef CACHED_LEDGER_NUM @@ -185,3 +187,5 @@ void LedgerHistory::tune (int size, int age) m_ledgers_by_hash.setTargetSize (size); m_ledgers_by_hash.setTargetAge (age); } + +} // ripple diff --git a/src/ripple_app/ledger/LedgerHistory.h b/src/ripple_app/ledger/LedgerHistory.h index c522cd5092..f86934cf4a 100644 --- a/src/ripple_app/ledger/LedgerHistory.h +++ b/src/ripple_app/ledger/LedgerHistory.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERHISTORY_H #define RIPPLE_LEDGERHISTORY_H +namespace ripple { + // VFALCO TODO Rename to OldLedgers ? class LedgerHistory : beast::LeakChecked { @@ -67,4 +69,6 @@ private: std::map mLedgersByIndex; // validated ledgers }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/LedgerHolder.h b/src/ripple_app/ledger/LedgerHolder.h index 8b912f28bc..2420f6e79b 100644 --- a/src/ripple_app/ledger/LedgerHolder.h +++ b/src/ripple_app/ledger/LedgerHolder.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERHOLDER_H #define RIPPLE_LEDGERHOLDER_H +namespace ripple { + // Can std::atomic> make this lock free? /** Hold a ledger in a thread-safe way. @@ -74,4 +76,6 @@ private: }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/LedgerMaster.cpp b/src/ripple_app/ledger/LedgerMaster.cpp index 24cd3d3643..037bca2b7f 100644 --- a/src/ripple_app/ledger/LedgerMaster.cpp +++ b/src/ripple_app/ledger/LedgerMaster.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + #define MIN_VALIDATION_RATIO 150 // 150/256ths of validations of previous ledger #define MAX_LEDGER_GAP 100 // Don't catch up more than 100 ledgers (cannot exceed 256) @@ -1328,3 +1330,5 @@ LedgerMaster* LedgerMaster::New (Stoppable& parent, beast::Journal journal) { return new LedgerMasterImp (parent, journal); } + +} // ripple diff --git a/src/ripple_app/ledger/LedgerMaster.h b/src/ripple_app/ledger/LedgerMaster.h index 478a0422fc..3cf3d9a358 100644 --- a/src/ripple_app/ledger/LedgerMaster.h +++ b/src/ripple_app/ledger/LedgerMaster.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERMASTER_H_INCLUDED #define RIPPLE_LEDGERMASTER_H_INCLUDED +namespace ripple { + // Tracks the current ledger and any ledgers in the process of closing // Tracks ledger history // Tracks held transactions @@ -140,4 +142,6 @@ public: beast::uint32 ledgerHistory, beast::uint32 targetLedger); }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/LedgerProposal.cpp b/src/ripple_app/ledger/LedgerProposal.cpp index c70a87d197..63cd3854ec 100644 --- a/src/ripple_app/ledger/LedgerProposal.cpp +++ b/src/ripple_app/ledger/LedgerProposal.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + LedgerProposal::LedgerProposal (uint256 const& pLgr, beast::uint32 seq, uint256 const& tx, beast::uint32 closeTime, const RippleAddress& naPeerPublic, uint256 const& suppression) : @@ -140,4 +142,4 @@ Json::Value LedgerProposal::getJson () const return ret; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/ledger/LedgerProposal.h b/src/ripple_app/ledger/LedgerProposal.h index 6897ef9540..75682d202e 100644 --- a/src/ripple_app/ledger/LedgerProposal.h +++ b/src/ripple_app/ledger/LedgerProposal.h @@ -20,6 +20,8 @@ #ifndef __PROPOSELEDGER__ #define __PROPOSELEDGER__ +namespace ripple { + class LedgerProposal : public CountedObject { @@ -141,6 +143,6 @@ private: boost::posix_time::ptime mTime; }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/ledger/LedgerTiming.cpp b/src/ripple_app/ledger/LedgerTiming.cpp index 4e378e5b65..616caa933e 100644 --- a/src/ripple_app/ledger/LedgerTiming.cpp +++ b/src/ripple_app/ledger/LedgerTiming.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO Should rename ContinuousLedgerTiming to LedgerTiming struct LedgerTiming; // for Log @@ -167,3 +169,5 @@ int ContinuousLedgerTiming::getNextLedgerTimeResolution (int previousResolution, return previousResolution; } + +} // ripple diff --git a/src/ripple_app/ledger/LedgerTiming.h b/src/ripple_app/ledger/LedgerTiming.h index 7039cc3b23..e4b8678314 100644 --- a/src/ripple_app/ledger/LedgerTiming.h +++ b/src/ripple_app/ledger/LedgerTiming.h @@ -20,6 +20,8 @@ #ifndef __LEDGERTIMING__ #define __LEDGERTIMING__ +namespace ripple { + // The number of seconds a ledger may remain idle before closing # define LEDGER_IDLE_INTERVAL 15 @@ -97,4 +99,6 @@ public: static int getNextLedgerTimeResolution (int previousResolution, bool previousAgree, int ledgerSeq); }; +} // ripple + #endif diff --git a/src/ripple_app/ledger/OrderBookDB.cpp b/src/ripple_app/ledger/OrderBookDB.cpp index c99e977265..da3008152f 100644 --- a/src/ripple_app/ledger/OrderBookDB.cpp +++ b/src/ripple_app/ledger/OrderBookDB.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (OrderBookDB) OrderBookDB::OrderBookDB (Stoppable& parent) @@ -337,4 +339,4 @@ void BookListeners::publish (Json::Value const& jvObj) } } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/ledger/OrderBookDB.h b/src/ripple_app/ledger/OrderBookDB.h index d4f87df10d..9d78a3a800 100644 --- a/src/ripple_app/ledger/OrderBookDB.h +++ b/src/ripple_app/ledger/OrderBookDB.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_ORDERBOOKDB_H_INCLUDED #define RIPPLE_ORDERBOOKDB_H_INCLUDED +namespace ripple { + // VFALCO TODO Add Javadoc comment explaining what this class does class BookListeners { @@ -99,6 +101,6 @@ private: }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/ledger/OrderBookIterator.cpp b/src/ripple_app/ledger/OrderBookIterator.cpp index 5d0297ed2b..3c260134bf 100644 --- a/src/ripple_app/ledger/OrderBookIterator.cpp +++ b/src/ripple_app/ledger/OrderBookIterator.cpp @@ -17,8 +17,9 @@ */ //============================================================================== -/** Iterate through the directories in an order book -*/ +namespace ripple { + +/** Iterate through the directories in an order book */ BookDirIterator::BookDirIterator(uint160 const& uInCurrency, uint160 const& uInIssuer, uint160 const& uOutCurrency, uint160 const& uOutIssuer) { @@ -223,4 +224,4 @@ bool OrderBookIterator::nextOfferInDir () return mOfferIterator.nextEntry (mEntrySet); } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/ledger/OrderBookIterator.h b/src/ripple_app/ledger/OrderBookIterator.h index a11aa15384..a4d814da14 100644 --- a/src/ripple_app/ledger/OrderBookIterator.h +++ b/src/ripple_app/ledger/OrderBookIterator.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_ORDERBOOKITERATOR_H_INCLUDED #define RIPPLE_ORDERBOOKITERATOR_H_INCLUDED -/** An iterator that walks the directories in a book -*/ +namespace ripple { + +/** An iterator that walks the directories in a book */ class BookDirIterator { @@ -198,6 +199,6 @@ private: DirectoryEntryIterator mOfferIterator; }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/ledger/SerializedValidation.cpp b/src/ripple_app/ledger/SerializedValidation.cpp index 1222920d82..2ce1d596d6 100644 --- a/src/ripple_app/ledger/SerializedValidation.cpp +++ b/src/ripple_app/ledger/SerializedValidation.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SerializedValidation::SerializedValidation (SerializerIterator& sit, bool checkSignature) : STObject (getFormat (), sit, sfValidation) , mTrusted (false) @@ -157,4 +159,4 @@ SOTemplate const& SerializedValidation::getFormat () return holder.format; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/ledger/SerializedValidation.h b/src/ripple_app/ledger/SerializedValidation.h index 5290cff2f4..96600fbd1b 100644 --- a/src/ripple_app/ledger/SerializedValidation.h +++ b/src/ripple_app/ledger/SerializedValidation.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SERIALIZEDVALIDATION_H #define RIPPLE_SERIALIZEDVALIDATION_H +namespace ripple { + // Validation flags const beast::uint32 vfFullyCanonicalSig = 0x80000000; // signature is fully canonical @@ -95,5 +97,6 @@ private: bool mTrusted; }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/main/FatalErrorReporter.cpp b/src/ripple_app/main/FatalErrorReporter.cpp index 90abe124b5..9a6464fb05 100644 --- a/src/ripple_app/main/FatalErrorReporter.cpp +++ b/src/ripple_app/main/FatalErrorReporter.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + FatalErrorReporter::FatalErrorReporter () { m_savedReporter = beast::FatalError::setReporter (this); @@ -34,17 +38,11 @@ void FatalErrorReporter::reportMessage (beast::String& formattedMessage) //------------------------------------------------------------------------------ -class FatalErrorReporterTests : public beast::UnitTest +class FatalErrorReporter_test : public beast::unit_test::suite { public: - FatalErrorReporterTests () : beast::UnitTest ("FatalErrorReporter", "ripple", runManual) + void run () { - } - - void runTest () - { - beginTestCase ("report"); - FatalErrorReporter reporter; // We don't really expect the program to run after this @@ -54,4 +52,6 @@ public: } }; -static FatalErrorReporterTests fatalErrorReporterTests; +BEAST_DEFINE_TESTSUITE_MANUAL(FatalErrorReporter,ripple_app,ripple); + +} // ripple diff --git a/src/ripple_app/main/FatalErrorReporter.h b/src/ripple_app/main/FatalErrorReporter.h index 1e8e0ac4f5..567c4f6412 100644 --- a/src/ripple_app/main/FatalErrorReporter.h +++ b/src/ripple_app/main/FatalErrorReporter.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_FATALERRORREPORTER_H_INCLUDED #define RIPPLE_FATALERRORREPORTER_H_INCLUDED +namespace ripple { + /** FatalError reporter. This writes the details to standard error and the log. The reporter is @@ -43,4 +45,6 @@ private: beast::FatalError::Reporter* m_savedReporter; }; +} // ripple + #endif diff --git a/src/ripple_app/main/IoServicePool.cpp b/src/ripple_app/main/IoServicePool.cpp index 0fb1601960..74d7577016 100644 --- a/src/ripple_app/main/IoServicePool.cpp +++ b/src/ripple_app/main/IoServicePool.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class IoServicePool::ServiceThread : private beast::Thread { public: @@ -126,3 +128,5 @@ void IoServicePool::onThreadExit() stopped (); } } + +} // ripple diff --git a/src/ripple_app/main/IoServicePool.h b/src/ripple_app/main/IoServicePool.h index 172f909ab8..6410155e62 100644 --- a/src/ripple_app/main/IoServicePool.h +++ b/src/ripple_app/main/IoServicePool.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_APP_IOSERVICEPOOL_H_INCLUDED #define RIPPLE_APP_IOSERVICEPOOL_H_INCLUDED +namespace ripple { + /** An io_service with an associated group of threads. */ class IoServicePool : public beast::Stoppable { @@ -47,4 +49,6 @@ private: beast::Atomic m_threadsRunning; }; +} // ripple + #endif diff --git a/src/ripple_app/main/LoadManager.cpp b/src/ripple_app/main/LoadManager.cpp index 570b0bf351..a9224fbc20 100644 --- a/src/ripple_app/main/LoadManager.cpp +++ b/src/ripple_app/main/LoadManager.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class LoadManagerImp : public LoadManager , public beast::Thread @@ -259,3 +261,5 @@ LoadManager* LoadManager::New (Stoppable& parent, beast::Journal journal) { return new LoadManagerImp (parent, journal); } + +} // ripple diff --git a/src/ripple_app/main/LoadManager.h b/src/ripple_app/main/LoadManager.h index 4e75b7d57a..84ce224b60 100644 --- a/src/ripple_app/main/LoadManager.h +++ b/src/ripple_app/main/LoadManager.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LOADMANAGER_H_INCLUDED #define RIPPLE_LOADMANAGER_H_INCLUDED +namespace ripple { + /** Manages load sources. This object creates an associated thread to maintain a clock. @@ -74,4 +76,6 @@ public: virtual void resetDeadlockDetector () = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/main/LocalCredentials.cpp b/src/ripple_app/main/LocalCredentials.cpp index 190b2ea4db..fc6835191e 100644 --- a/src/ripple_app/main/LocalCredentials.cpp +++ b/src/ripple_app/main/LocalCredentials.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + LocalCredentials::LocalCredentials () : mLedger (0) { @@ -166,4 +168,4 @@ bool LocalCredentials::dataStore (const std::string& strKey, const std::string& return bSuccess; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/main/LocalCredentials.h b/src/ripple_app/main/LocalCredentials.h index c7c6b02b8d..2e00d7edce 100644 --- a/src/ripple_app/main/LocalCredentials.h +++ b/src/ripple_app/main/LocalCredentials.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_LOCALCREDENTIALS_H #define RIPPLE_LOCALCREDENTIALS_H -/** Holds the cryptographic credentials identifying this instance of the server. -*/ +namespace ripple { + +/** Holds the cryptographic credentials identifying this instance of the server. */ class LocalCredentials : public beast::Uncopyable { public: @@ -64,5 +65,6 @@ private: LedgerIndex mLedger; // ledger we last synched to }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/main/RippleMain.cpp b/src/ripple_app/main/Main.cpp similarity index 82% rename from src/ripple_app/main/RippleMain.cpp rename to src/ripple_app/main/Main.cpp index 08183fd13f..d8f5d29bab 100644 --- a/src/ripple_app/main/RippleMain.cpp +++ b/src/ripple_app/main/Main.cpp @@ -17,15 +17,12 @@ */ //============================================================================== +#include "../../beast/beast/unit_test.h" +#include "../../beast/beast/streams/debug_ostream.h" + namespace po = boost::program_options; -RippleMain::RippleMain() -{ -} - -RippleMain::~RippleMain() -{ -} +namespace ripple { void setupServer () { @@ -140,108 +137,36 @@ void printHelp (const po::options_description& desc) //------------------------------------------------------------------------------ -// OUr custom unit test runner -// -class RippleUnitTests : public beast::UnitTests +static +void +setupConfigForUnitTests (Config* config) { -public: - explicit RippleUnitTests (bool shouldLog) - : m_shouldLog (shouldLog) - { - setupConfigForUnitTests (&getConfig ()); + config->nodeDatabase = parseDelimitedKeyValueString ("type=memory"); + config->ephemeralNodeDatabase = beast::StringPairArray (); + config->importNodeDatabase = beast::StringPairArray (); +} - // VFALCO NOTE It sucks that we have to do this but some - // code demands the Application object exists. - // - // TODO To find out who, just comment the next line out - m_app = make_Application(); - - setAssertOnFailure (false); - } - - ~RippleUnitTests () - { - m_app = nullptr; - } - - void logMessage (beast::String const& message) - { - if (m_shouldLog) - { -#if BEAST_MSVC - if (beast::beast_isRunningUnderDebugger ()) - { - beast::Logger::outputDebugString (message); - } - else - { - std::cout << message.toStdString () << std::endl; - } - -#else - std::cout << message.toStdString () << std::endl; - -#endif - } - } - -private: - void setupConfigForUnitTests (Config* config) - { - config->nodeDatabase = parseDelimitedKeyValueString ("type=memory"); - config->ephemeralNodeDatabase = beast::StringPairArray (); - config->importNodeDatabase = beast::StringPairArray (); - } - -private: - bool const m_shouldLog; - std::unique_ptr m_app; -}; - -static int runUnitTests (beast::String const& match, beast::String const& format) +static +int +runUnitTests (std::string pattern, std::string format) { - bool const shouldLog = format != "junit"; - - if (format != "junit" && format != "text" && format != "") - { - beast::String s; - s << "Warning, unknown unittest-format='" << format << "'"; - Log::out () << s.toStdString (); - } - - RippleUnitTests tr (shouldLog); - - tr.runSelectedTests (match); - - if (format == "junit") - { - beast::UnitTestUtilities::JUnitXMLFormatter f (tr); - - beast::String const s = f.createDocumentString (); - - std::cout << s.toStdString (); - } - else - { - beast::UnitTests::Results const& r (tr.getResults ()); - - beast::String s; - - s << "Summary: " << - beast::String (r.suites.size ()) << " suites, " << - beast::String (r.cases) << " cases, " << - beast::String (r.tests) << " tests, " << - beast::String (r.failures) << " failure" << ((r.failures != 1) ? "s" : "") << "."; - - tr.logMessage (s); - } - - return tr.anyTestsFailed () ? EXIT_FAILURE : EXIT_SUCCESS; + // Config needs to be set up before creating Application + setupConfigForUnitTests (&getConfig ()); + // VFALCO TODO Remove dependence on constructing Application object + auto app (make_Application()); + using namespace beast::unit_test; + beast::debug_ostream stream; + reporter r (stream); + bool const failed (r.run_each_if ( + global_suites(), match_auto (pattern))); + if (failed) + return EXIT_FAILURE; + return EXIT_SUCCESS; } //------------------------------------------------------------------------------ -int RippleMain::run (int argc, char const* const* argv) +int run (int argc, char** argv) { FatalErrorReporter reporter; @@ -368,7 +293,7 @@ int RippleMain::run (int argc, char const* const* argv) // if (vm.count ("unittest")) { - beast::String format; + std::string format; if (vm.count ("unittest-format")) format = vm ["unittest-format"].as (); @@ -463,4 +388,4 @@ int RippleMain::run (int argc, char const* const* argv) return iResult; } - +} diff --git a/src/ripple_app/main/NodeStoreScheduler.cpp b/src/ripple_app/main/NodeStoreScheduler.cpp index 49ec6b32c8..b7c5336b50 100644 --- a/src/ripple_app/main/NodeStoreScheduler.cpp +++ b/src/ripple_app/main/NodeStoreScheduler.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + NodeStoreScheduler::NodeStoreScheduler (Stoppable& parent) : Stoppable ("NodeStoreScheduler", parent) , m_jobQueue (nullptr) @@ -55,3 +57,5 @@ void NodeStoreScheduler::doTask (NodeStore::Task& task, Job&) if ((--m_taskCount == 0) && isStopping()) stopped(); } + +} // ripple diff --git a/src/ripple_app/main/NodeStoreScheduler.h b/src/ripple_app/main/NodeStoreScheduler.h index 5dc6e1a02e..48389abc8e 100644 --- a/src/ripple_app/main/NodeStoreScheduler.h +++ b/src/ripple_app/main/NodeStoreScheduler.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_APP_NODESTORESCHEDULER_H_INCLUDED #define RIPPLE_APP_NODESTORESCHEDULER_H_INCLUDED +namespace ripple { + /** A NodeStore::Scheduler which uses the JobQueue and implements the Stoppable API. */ class NodeStoreScheduler : public NodeStore::Scheduler @@ -44,5 +46,6 @@ private: std::atomic m_taskCount; }; +} // ripple #endif diff --git a/src/ripple_app/main/ParameterTable.cpp b/src/ripple_app/main/ParameterTable.cpp index cde7c0ac31..8fccb5232d 100644 --- a/src/ripple_app/main/ParameterTable.cpp +++ b/src/ripple_app/main/ParameterTable.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + bool ParameterNode::setValue (const std::string& name, const Json::Value& value, Json::Value& error) { if (name.empty ()) // this node @@ -189,3 +191,5 @@ bool ParameterInt::setValue (const Json::Value& value, Json::Value& error) error["value"] = value; return false; } + +} // ripple diff --git a/src/ripple_app/main/ParameterTable.h b/src/ripple_app/main/ParameterTable.h index d297a0f8d6..d5de9fc545 100644 --- a/src/ripple_app/main/ParameterTable.h +++ b/src/ripple_app/main/ParameterTable.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PARAMETERTABLE_H #define RIPPLE_PARAMETERTABLE_H +namespace ripple { + class Parameter : public boost::enable_shared_from_this { // abstract base class parameters are derived from @@ -96,4 +98,6 @@ private: int mValue; }; +} // ripple + #endif diff --git a/src/ripple_app/main/RippleMain.h b/src/ripple_app/main/RippleMain.h deleted file mode 100644 index 58f4427ccf..0000000000 --- a/src/ripple_app/main/RippleMain.h +++ /dev/null @@ -1,32 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - 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_RIPPLEMAIN_H_INCLUDED -#define RIPPLE_RIPPLEMAIN_H_INCLUDED - -class RippleMain : public beast::Main -{ -public: - RippleMain (); - ~RippleMain (); - - int run (int argc, char const* const* argv); -}; - -#endif diff --git a/src/ripple_app/misc/AccountItem.cpp b/src/ripple_app/misc/AccountItem.cpp index 728486f38d..e450ef4e8c 100644 --- a/src/ripple_app/misc/AccountItem.cpp +++ b/src/ripple_app/misc/AccountItem.cpp @@ -17,8 +17,12 @@ */ //============================================================================== +namespace ripple { + AccountItem::AccountItem (SerializedLedgerEntry::ref ledger) : mLedgerEntry (ledger) { } + +} // ripple diff --git a/src/ripple_app/misc/AccountItem.h b/src/ripple_app/misc/AccountItem.h index 886d9b8625..7e8adafff0 100644 --- a/src/ripple_app/misc/AccountItem.h +++ b/src/ripple_app/misc/AccountItem.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_ACCOUNTITEM_H #define RIPPLE_ACCOUNTITEM_H +namespace ripple { + // // Fetch ledger entries from an account's owner dir. // @@ -84,4 +86,6 @@ protected: SerializedLedgerEntry::pointer mLedgerEntry; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/AccountItems.cpp b/src/ripple_app/misc/AccountItems.cpp index 8f6c213124..22fabd2995 100644 --- a/src/ripple_app/misc/AccountItems.cpp +++ b/src/ripple_app/misc/AccountItems.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + AccountItems::AccountItems (uint160 const& accountID, Ledger::ref ledger, AccountItem::pointer ofType) @@ -87,4 +89,5 @@ Json::Value AccountItems::getJson (int v) return ret; } -// vim:ts=4 +} // ripple + diff --git a/src/ripple_app/misc/AccountItems.h b/src/ripple_app/misc/AccountItems.h index 09b63b1acb..4f5b183da8 100644 --- a/src/ripple_app/misc/AccountItems.h +++ b/src/ripple_app/misc/AccountItems.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_ACCOUNTITEMS_H #define RIPPLE_ACCOUNTITEMS_H -/** A set of AccountItem objects. -*/ +namespace ripple { + +/** A set of AccountItem objects. */ class AccountItems : beast::LeakChecked { public: @@ -55,4 +56,6 @@ private: Container mItems; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/AccountState.cpp b/src/ripple_app/misc/AccountState.cpp index 85e96fa889..d0b46b529c 100644 --- a/src/ripple_app/misc/AccountState.cpp +++ b/src/ripple_app/misc/AccountState.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + AccountState::AccountState (RippleAddress const& naAccountID) : mAccountID (naAccountID) , mValid (false) @@ -79,4 +81,4 @@ void AccountState::dump () Log (lsINFO) << j; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/misc/AccountState.h b/src/ripple_app/misc/AccountState.h index 8f67637aaa..337909b399 100644 --- a/src/ripple_app/misc/AccountState.h +++ b/src/ripple_app/misc/AccountState.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_ACCOUNTSTATE_H #define RIPPLE_ACCOUNTSTATE_H +namespace ripple { + // // Provide abstract access to an account's state, such that access to the serialized format is hidden. // @@ -87,4 +89,6 @@ private: bool mValid; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/CanonicalTXSet.cpp b/src/ripple_app/misc/CanonicalTXSet.cpp index c6b5ffcbcf..1494c0f6eb 100644 --- a/src/ripple_app/misc/CanonicalTXSet.cpp +++ b/src/ripple_app/misc/CanonicalTXSet.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + bool CanonicalTXSet::Key::operator< (Key const& rhs) const { if (mAccount < rhs.mAccount) return true; @@ -88,4 +90,4 @@ CanonicalTXSet::iterator CanonicalTXSet::erase (iterator const& it) return tmp; } - +} // ripple diff --git a/src/ripple_app/misc/CanonicalTXSet.h b/src/ripple_app/misc/CanonicalTXSet.h index 2b17e3f6d2..295af63e32 100644 --- a/src/ripple_app/misc/CanonicalTXSet.h +++ b/src/ripple_app/misc/CanonicalTXSet.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_CANONICALTXSET_H #define RIPPLE_CANONICALTXSET_H +namespace ripple { + /** Holds transactions which were deferred to the next pass of consensus. "Canonical" refers to the order in which transactions are applied. @@ -119,4 +121,6 @@ private: std::map mMap; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/Features.cpp b/src/ripple_app/misc/Features.cpp index c5dd8df714..be8ff2e1e3 100644 --- a/src/ripple_app/misc/Features.cpp +++ b/src/ripple_app/misc/Features.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class Features; SETUP_LOG (Features) @@ -503,4 +505,4 @@ IFeatures* IFeatures::New (beast::uint32 majorityTime, int majorityFraction) return new Features (majorityTime, majorityFraction); } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/misc/FeeVote.cpp b/src/ripple_app/misc/FeeVote.cpp index d582399ca9..a773ac9340 100644 --- a/src/ripple_app/misc/FeeVote.cpp +++ b/src/ripple_app/misc/FeeVote.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -class Features; +namespace ripple { -//------------------------------------------------------------------------------ +class Features; class FeeVote : public IFeeVote { @@ -210,4 +210,4 @@ IFeeVote* IFeeVote::New (beast::uint64 targetBaseFee, return new FeeVote (targetBaseFee, targetReserveBase, targetReserveIncrement); } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/misc/HashRouter.cpp b/src/ripple_app/misc/HashRouter.cpp index ea501f6ea5..ec1400744b 100644 --- a/src/ripple_app/misc/HashRouter.cpp +++ b/src/ripple_app/misc/HashRouter.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO TODO Inline the function definitions class HashRouter : public IHashRouter { @@ -240,3 +242,6 @@ IHashRouter* IHashRouter::New (int holdTime) { return new HashRouter (holdTime); } + +} // ripple + diff --git a/src/ripple_app/misc/IFeatures.h b/src/ripple_app/misc/IFeatures.h index 376518437f..b8eb963cc4 100644 --- a/src/ripple_app/misc/IFeatures.h +++ b/src/ripple_app/misc/IFeatures.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_IFEATURES_H #define RIPPLE_IFEATURES_H +namespace ripple { + class FeatureSet { // the status of all features requested in a given window @@ -140,4 +142,6 @@ public: }; +} // ripple + #endif diff --git a/src/ripple_app/misc/IFeeVote.h b/src/ripple_app/misc/IFeeVote.h index 9f1e85ee7a..c2b4e9b27e 100644 --- a/src/ripple_app/misc/IFeeVote.h +++ b/src/ripple_app/misc/IFeeVote.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_IFEEVOTE_H #define RIPPLE_IFEEVOTE_H -/** Manager to process fee votes. -*/ +namespace ripple { + +/** Manager to process fee votes. */ class IFeeVote { public: @@ -54,4 +55,6 @@ public: SHAMap::ref initialPosition) = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/IHashRouter.h b/src/ripple_app/misc/IHashRouter.h index 9eb8f7cac9..d3aabb5d78 100644 --- a/src/ripple_app/misc/IHashRouter.h +++ b/src/ripple_app/misc/IHashRouter.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_HASHROUTER_H_INCLUDED #define RIPPLE_HASHROUTER_H_INCLUDED +namespace ripple { + // VFALCO NOTE Are these the flags?? Why aren't we using a packed struct? // VFALCO TODO convert these macros to int constants #define SF_RELAYED 0x01 // Has already been relayed to other nodes @@ -80,5 +82,6 @@ public: // virtual Entry getEntry (uint256 const&) = 0; }; +} // ripple #endif diff --git a/src/ripple_app/misc/NetworkOPs.cpp b/src/ripple_app/misc/NetworkOPs.cpp index 3b2a8252d9..fa7f66d260 100644 --- a/src/ripple_app/misc/NetworkOPs.cpp +++ b/src/ripple_app/misc/NetworkOPs.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class NetworkOPsImp : public NetworkOPs , public beast::DeadlineTimer::Listener @@ -3277,3 +3279,5 @@ NetworkOPs* NetworkOPs::New (clock_type& clock, LedgerMaster& ledgerMaster, { return new NetworkOPsImp (clock, ledgerMaster, parent, journal); } + +} // ripple diff --git a/src/ripple_app/misc/NetworkOPs.h b/src/ripple_app/misc/NetworkOPs.h index 3d82ecd87b..0386c2bd62 100644 --- a/src/ripple_app/misc/NetworkOPs.h +++ b/src/ripple_app/misc/NetworkOPs.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NETWORKOPS_H #define RIPPLE_NETWORKOPS_H +namespace ripple { + // Operations that clients may wish to perform against the network // Master operational handler, server sequencer, network tracker @@ -309,4 +311,6 @@ public: SerializedTransaction::ref stTxn, TER terResult) = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/NicknameState.cpp b/src/ripple_app/misc/NicknameState.cpp index 104c0ba345..0f15448f54 100644 --- a/src/ripple_app/misc/NicknameState.cpp +++ b/src/ripple_app/misc/NicknameState.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + NicknameState::NicknameState (SerializedLedgerEntry::pointer ledgerEntry) : mLedgerEntry (ledgerEntry) { @@ -44,3 +46,5 @@ void NicknameState::addJson (Json::Value& val) { val = mLedgerEntry->getJson (0); } + +} // ripple diff --git a/src/ripple_app/misc/NicknameState.h b/src/ripple_app/misc/NicknameState.h index ec59874796..e61311556c 100644 --- a/src/ripple_app/misc/NicknameState.h +++ b/src/ripple_app/misc/NicknameState.h @@ -17,10 +17,11 @@ */ //============================================================================== - #ifndef RIPPLE_NICKNAMESTATE_H #define RIPPLE_NICKNAMESTATE_H +namespace ripple { + // // State of a nickname node. // - Isolate ledger entry format. @@ -58,5 +59,6 @@ private: SerializedLedgerEntry::pointer mLedgerEntry; }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/misc/Offer.cpp b/src/ripple_app/misc/Offer.cpp index 4baee5d543..2c0162b931 100644 --- a/src/ripple_app/misc/Offer.cpp +++ b/src/ripple_app/misc/Offer.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + AccountItem::pointer Offer::makeItem (const uint160& , SerializedLedgerEntry::ref ledgerEntry) { if (!ledgerEntry || ledgerEntry->getType () != ltOFFER) return (AccountItem::pointer ()); @@ -43,4 +45,4 @@ Json::Value Offer::getJson (int) return ret; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/misc/Offer.h b/src/ripple_app/misc/Offer.h index 3906b1aa2c..9e373f6d0c 100644 --- a/src/ripple_app/misc/Offer.h +++ b/src/ripple_app/misc/Offer.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_OFFER_H #define RIPPLE_OFFER_H +namespace ripple { + class Offer : public AccountItem { public: @@ -63,6 +65,6 @@ private: int mSeq; }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/misc/OrderBook.cpp b/src/ripple_app/misc/OrderBook.cpp index e99036ce35..6433876353 100644 --- a/src/ripple_app/misc/OrderBook.cpp +++ b/src/ripple_app/misc/OrderBook.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +namespace ripple { OrderBook::OrderBook (uint256 const& index, uint160 const& currencyIn, @@ -30,3 +31,5 @@ OrderBook::OrderBook (uint256 const& index, , mIssuerOut (issuerOut) { } + +} // ripple diff --git a/src/ripple_app/misc/OrderBook.h b/src/ripple_app/misc/OrderBook.h index efabf03ae3..b4d475d733 100644 --- a/src/ripple_app/misc/OrderBook.h +++ b/src/ripple_app/misc/OrderBook.h @@ -17,12 +17,12 @@ */ //============================================================================== - #ifndef RIPPLE_ORDERBOOK_H #define RIPPLE_ORDERBOOK_H -/** Describes a serialized ledger entry for an order book. -*/ +namespace ripple { + +/** Describes a serialized ledger entry for an order book. */ class OrderBook : beast::LeakChecked { public: @@ -40,8 +40,7 @@ public: @param issuerOut The destination issuer. */ // VFALCO NOTE what is the meaning of the index parameter? - // VFALCO TODO group the issuer and currency parameters together. - // VFALCO TODO give typedef names to uint256 / uint160 params + // VFALCO TODO Replace with RippleAsset OrderBook (uint256 const& index, uint160 const& currencyIn, uint160 const& currencyOut, @@ -75,6 +74,7 @@ public: private: + // VFALCO TODO Replace these with RippleAsset uint256 const mBookBase; uint160 const mCurrencyIn; uint160 const mCurrencyOut; @@ -82,4 +82,6 @@ private: uint160 const mIssuerOut; }; +} // ripple + #endif diff --git a/src/ripple_app/misc/ProofOfWork.cpp b/src/ripple_app/misc/ProofOfWork.cpp index 1cbd473fe5..046152861e 100644 --- a/src/ripple_app/misc/ProofOfWork.cpp +++ b/src/ripple_app/misc/ProofOfWork.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (ProofOfWork) // VFALCO TODO Move these to a header @@ -190,3 +192,4 @@ bool ProofOfWork::calcResultInfo (PowResult powCode, std::string& strToken, std: return iIndex >= 0; } +} // ripple diff --git a/src/ripple_app/misc/ProofOfWorkFactory.cpp b/src/ripple_app/misc/ProofOfWorkFactory.cpp index 5cea975463..7b20a56679 100644 --- a/src/ripple_app/misc/ProofOfWorkFactory.cpp +++ b/src/ripple_app/misc/ProofOfWorkFactory.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + class ProofOfWorkFactoryImp : public ProofOfWorkFactory , public beast::LeakChecked @@ -354,14 +358,10 @@ ProofOfWorkFactory* ProofOfWorkFactory::New () //------------------------------------------------------------------------------ -class ProofOfWorkTests : public beast::UnitTest +class ProofOfWork_test : public beast::unit_test::suite { public: - ProofOfWorkTests () : beast::UnitTest ("ProofOfWork", "ripple", runManual) - { - } - - void runTest () + void run () { using namespace ripple; @@ -371,7 +371,6 @@ public: beast::String s; s << "solve difficulty " << beast::String (pow.getDifficulty ()); - beginTestCase ("solve"); uint256 solution = pow.solve (16777216); @@ -420,4 +419,6 @@ public: } }; -static ProofOfWorkTests proofOfWorkTests; +BEAST_DEFINE_TESTSUITE_MANUAL(ProofOfWork,ripple_app,ripple); + +} // ripple diff --git a/src/ripple_app/misc/SerializedLedger.cpp b/src/ripple_app/misc/SerializedLedger.cpp index 45659e3094..2c33967280 100644 --- a/src/ripple_app/misc/SerializedLedger.cpp +++ b/src/ripple_app/misc/SerializedLedger.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + struct SerializedLedgerLog; // for Log SETUP_LOGN (SerializedLedgerLog,"SerializedLedger") @@ -215,4 +217,4 @@ std::vector SerializedLedgerEntry::getOwners () return owners; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/misc/SerializedLedger.h b/src/ripple_app/misc/SerializedLedger.h index 9da2729918..5a4ad925b1 100644 --- a/src/ripple_app/misc/SerializedLedger.h +++ b/src/ripple_app/misc/SerializedLedger.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SERIALIZEDLEDGER_H #define RIPPLE_SERIALIZEDLEDGER_H +namespace ripple { + // VFALCO NOTE // // This looks like a central class for Ripple. Almost everything that @@ -118,5 +120,7 @@ private: typedef SerializedLedgerEntry SLE; +} // ripple + #endif -// vim:ts=4 + diff --git a/src/ripple_app/misc/SerializedTransaction.cpp b/src/ripple_app/misc/SerializedTransaction.cpp index 922b47d745..d3bee9cd0a 100644 --- a/src/ripple_app/misc/SerializedTransaction.cpp +++ b/src/ripple_app/misc/SerializedTransaction.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + SETUP_LOG (SerializedTransaction) SerializedTransaction::SerializedTransaction (TxType type) @@ -325,17 +329,11 @@ bool isMemoOkay (STObject const& st) //------------------------------------------------------------------------------ -class SerializedTransactionTests : public beast::UnitTest +class SerializedTransaction_test : public beast::unit_test::suite { public: - SerializedTransactionTests () : beast::UnitTest ("SerializedTransaction", "ripple") + void run() { - } - - void runTest () - { - beginTestCase ("tx"); - RippleAddress seed; seed.setSeedRandom (); RippleAddress generator = RippleAddress::createGeneratorPublic (seed); @@ -357,8 +355,8 @@ public: if (copy != j) { - Log (lsFATAL) << j.getJson (0); - Log (lsFATAL) << copy.getJson (0); + log << j.getJson (0); + log << copy.getJson (0); fail ("Transaction fails serialize/deserialize test"); } else @@ -374,8 +372,8 @@ public: if (STObject (j) != *new_obj) { - Log (lsINFO) << "ORIG: " << j.getJson (0); - Log (lsINFO) << "BUILT " << new_obj->getJson (0); + log << "ORIG: " << j.getJson (0); + log << "BUILT " << new_obj->getJson (0); fail ("Built a different transaction"); } else @@ -385,4 +383,6 @@ public: } }; -static SerializedTransactionTests serializedTransactionTests; +BEAST_DEFINE_TESTSUITE(SerializedTransaction,ripple_app,ripple); + +} // ripple diff --git a/src/ripple_app/misc/SerializedTransaction.h b/src/ripple_app/misc/SerializedTransaction.h index 373108a455..2e54d2bbc7 100644 --- a/src/ripple_app/misc/SerializedTransaction.h +++ b/src/ripple_app/misc/SerializedTransaction.h @@ -20,7 +20,9 @@ #ifndef RIPPLE_SERIALIZEDTRANSACTION_H #define RIPPLE_SERIALIZEDTRANSACTION_H -// VFALCO TODO eliminate these macros +namespace ripple { + +// VFALCO TODO replace these macros with language constants #define TXN_SQL_NEW 'N' #define TXN_SQL_CONFLICT 'C' @@ -153,5 +155,6 @@ private: bool isMemoOkay (STObject const& st); +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/misc/Validations.cpp b/src/ripple_app/misc/Validations.cpp index dee7403c65..5baf8505f6 100644 --- a/src/ripple_app/misc/Validations.cpp +++ b/src/ripple_app/misc/Validations.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class ValidationsImp; SETUP_LOG (Validations) @@ -463,4 +465,4 @@ Validations* Validations::New () return new ValidationsImp; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/misc/Validations.h b/src/ripple_app/misc/Validations.h index ea49e57fe1..75f4294d34 100644 --- a/src/ripple_app/misc/Validations.h +++ b/src/ripple_app/misc/Validations.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_VALIDATIONS_H_INCLUDED #define RIPPLE_VALIDATIONS_H_INCLUDED +namespace ripple { + // VFALCO TODO rename and move these typedefs into the Validations interface typedef boost::unordered_map ValidationSet; typedef std::pair currentValidationCount; // nodes validating and highest node ID validating @@ -58,4 +60,6 @@ public: virtual void sweep () = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/paths/PathRequest.cpp b/src/ripple_app/paths/PathRequest.cpp index 064d87d77d..cdbafd6d05 100644 --- a/src/ripple_app/paths/PathRequest.cpp +++ b/src/ripple_app/paths/PathRequest.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (PathRequest) PathRequest::PathRequest ( @@ -475,3 +477,4 @@ InfoSub::pointer PathRequest::getSubscriber () return wpSubscriber.lock (); } +} // ripple diff --git a/src/ripple_app/paths/PathRequest.h b/src/ripple_app/paths/PathRequest.h index 929bbe2eb8..d6f9128fad 100644 --- a/src/ripple_app/paths/PathRequest.h +++ b/src/ripple_app/paths/PathRequest.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PATHREQUEST_H #define RIPPLE_PATHREQUEST_H +namespace ripple { + // A pathfinding request submitted by a client // The request issuer must maintain a strong pointer @@ -104,4 +106,6 @@ private: }; +} // ripple + #endif diff --git a/src/ripple_app/paths/PathRequests.cpp b/src/ripple_app/paths/PathRequests.cpp index 7ef7b366bc..31f3bc0077 100644 --- a/src/ripple_app/paths/PathRequests.cpp +++ b/src/ripple_app/paths/PathRequests.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + /** Get the current RippleLineCache, updating it if necessary. Get the correct ledger to use. */ @@ -196,6 +198,5 @@ Json::Value PathRequests::makePathRequest( } return result; } - -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/paths/PathRequests.h b/src/ripple_app/paths/PathRequests.h index 8497d1eaee..589168b1e1 100644 --- a/src/ripple_app/paths/PathRequests.h +++ b/src/ripple_app/paths/PathRequests.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PATHREQUESTS_H #define RIPPLE_PATHREQUESTS_H +namespace ripple { + class PathRequests { public: @@ -71,4 +73,6 @@ private: }; +} // ripple + #endif diff --git a/src/ripple_app/paths/PathState.cpp b/src/ripple_app/paths/PathState.cpp index 192d42d15d..65828c6c2f 100644 --- a/src/ripple_app/paths/PathState.cpp +++ b/src/ripple_app/paths/PathState.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // TODO: // - Do automatic bridging via XRP. // @@ -932,3 +934,4 @@ Json::Value PathState::getJson () const return jvPathState; } +} // ripple diff --git a/src/ripple_app/paths/PathState.h b/src/ripple_app/paths/PathState.h index 5a93e65e19..52d12ac06d 100644 --- a/src/ripple_app/paths/PathState.h +++ b/src/ripple_app/paths/PathState.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PATHSTATE_H #define RIPPLE_PATHSTATE_H +namespace ripple { + // account id, currency id, issuer id :: node typedef boost::tuple aciSource; typedef boost::unordered_map curIssuerNode; // Map of currency, issuer to node index. @@ -181,4 +183,6 @@ private: TER pushImply (const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID); }; +} // ripple + #endif diff --git a/src/ripple_app/paths/Pathfinder.cpp b/src/ripple_app/paths/Pathfinder.cpp index f808e2e8bf..e330e49b58 100644 --- a/src/ripple_app/paths/Pathfinder.cpp +++ b/src/ripple_app/paths/Pathfinder.cpp @@ -18,6 +18,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (Pathfinder) /* @@ -926,4 +928,4 @@ void Pathfinder::initPathTable() } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/paths/Pathfinder.h b/src/ripple_app/paths/Pathfinder.h index 8a9404771f..2c43dc3afc 100644 --- a/src/ripple_app/paths/Pathfinder.h +++ b/src/ripple_app/paths/Pathfinder.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PATHFINDER_H #define RIPPLE_PATHFINDER_H +namespace ripple { + // VFALCO TODO Remove this unused stuff? #if 0 // @@ -146,4 +148,6 @@ boost::unordered_set usAccountSourceCurrencies RippleLineCache::ref lrLedger, bool includeXRP); +} // ripple + #endif diff --git a/src/ripple_app/paths/RippleCalc.cpp b/src/ripple_app/paths/RippleCalc.cpp index a6192cc3b8..1411ae1d40 100644 --- a/src/ripple_app/paths/RippleCalc.cpp +++ b/src/ripple_app/paths/RippleCalc.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // TODO: // - Do automatic bridging via XRP. // @@ -2723,4 +2725,4 @@ void TransactionEngine::calcNodeOffer ( } #endif -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/paths/RippleCalc.h b/src/ripple_app/paths/RippleCalc.h index 1c9d90cbf6..a988449c17 100644 --- a/src/ripple_app/paths/RippleCalc.h +++ b/src/ripple_app/paths/RippleCalc.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_RIPPLECALC_H #define RIPPLE_RIPPLECALC_H +namespace ripple { + /** Calculate the quality of a payment path. The quality is a synonym for price. Specifically, the amount of @@ -97,5 +99,6 @@ protected: bool mOpenLedger; }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/paths/RippleLineCache.cpp b/src/ripple_app/paths/RippleLineCache.cpp index ca99a8c200..5e507e9c52 100644 --- a/src/ripple_app/paths/RippleLineCache.cpp +++ b/src/ripple_app/paths/RippleLineCache.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + RippleLineCache::RippleLineCache (Ledger::ref l) : mLock (this, "RippleLineCache", __FILE__, __LINE__) , mLedger (l) @@ -35,3 +37,5 @@ AccountItems& RippleLineCache::getRippleLines (const uint160& accountID) return *it->second; } + +} // ripple diff --git a/src/ripple_app/paths/RippleLineCache.h b/src/ripple_app/paths/RippleLineCache.h index ba72451e22..9bdf54d699 100644 --- a/src/ripple_app/paths/RippleLineCache.h +++ b/src/ripple_app/paths/RippleLineCache.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_RIPPLELINECACHE_H #define RIPPLE_RIPPLELINECACHE_H +namespace ripple { + // Used by Pathfinder class RippleLineCache { @@ -46,4 +48,6 @@ private: boost::unordered_map mRLMap; }; +} // ripple + #endif diff --git a/src/ripple_app/paths/RippleState.cpp b/src/ripple_app/paths/RippleState.cpp index 8e484e83a1..54ea344177 100644 --- a/src/ripple_app/paths/RippleState.cpp +++ b/src/ripple_app/paths/RippleState.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + AccountItem::pointer RippleState::makeItem (const uint160& accountID, SerializedLedgerEntry::ref ledgerEntry) { if (!ledgerEntry || ledgerEntry->getType () != ltRIPPLE_STATE) @@ -70,4 +72,4 @@ Json::Value RippleState::getJson (int) return ret; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/paths/RippleState.h b/src/ripple_app/paths/RippleState.h index 78f75cfcec..ce56e31a1d 100644 --- a/src/ripple_app/paths/RippleState.h +++ b/src/ripple_app/paths/RippleState.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_RIPPLESTATE_H #define RIPPLE_RIPPLESTATE_H +namespace ripple { + // // A ripple line's state. // - Isolate ledger entry format. @@ -141,5 +143,7 @@ private: STAmount mBalance; }; + +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/peers/ClusterNodeStatus.h b/src/ripple_app/peers/ClusterNodeStatus.h index 1e22e6611f..92cfa76e1e 100644 --- a/src/ripple_app/peers/ClusterNodeStatus.h +++ b/src/ripple_app/peers/ClusterNodeStatus.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_CLUSTERNODESTATUS_H_INCLUDED #define RIPPLE_CLUSTERNODESTATUS_H_INCLUDED +namespace ripple { + class ClusterNodeStatus { public: @@ -68,4 +70,6 @@ private: beast::uint32 mReportTime; }; +} // ripple + #endif diff --git a/src/ripple_app/peers/PeerSet.cpp b/src/ripple_app/peers/PeerSet.cpp index 7b3ddaab28..42e3789498 100644 --- a/src/ripple_app/peers/PeerSet.cpp +++ b/src/ripple_app/peers/PeerSet.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class InboundLedger; // VFALCO NOTE The txnData constructor parameter is a code smell. @@ -194,3 +196,4 @@ std::size_t PeerSet::getPeerCount () const return ret; } +} // ripple diff --git a/src/ripple_app/peers/PeerSet.h b/src/ripple_app/peers/PeerSet.h index 715acf0b70..c12d3b9afb 100644 --- a/src/ripple_app/peers/PeerSet.h +++ b/src/ripple_app/peers/PeerSet.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PEERSET_H #define RIPPLE_PEERSET_H +namespace ripple { + /** A set of peers used to acquire data. A peer set is used to acquire a ledger or a transaction set. @@ -156,4 +158,6 @@ protected: PeerSetMap mPeers; }; +} // ripple + #endif diff --git a/src/ripple_app/peers/UniqueNodeList.cpp b/src/ripple_app/peers/UniqueNodeList.cpp index cedae04929..5937c5b844 100644 --- a/src/ripple_app/peers/UniqueNodeList.cpp +++ b/src/ripple_app/peers/UniqueNodeList.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // XXX Dynamically limit fetching by distance. // XXX Want a limit of 2000 validators. @@ -2042,3 +2044,5 @@ UniqueNodeList* UniqueNodeList::New (Stoppable& parent) { return new UniqueNodeListImp (parent); } + +} // ripple diff --git a/src/ripple_app/peers/UniqueNodeList.h b/src/ripple_app/peers/UniqueNodeList.h index 4097126472..27180919a4 100644 --- a/src/ripple_app/peers/UniqueNodeList.h +++ b/src/ripple_app/peers/UniqueNodeList.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_UNIQUENODELIST_H_INCLUDED #define RIPPLE_UNIQUENODELIST_H_INCLUDED +namespace ripple { + class UniqueNodeList : public beast::Stoppable { protected: @@ -75,6 +77,6 @@ public: virtual int iSourceScore (ValidatorSource vsWhy) = 0; }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/ripple_app.cpp b/src/ripple_app/ripple_app.cpp index 52e7c2f6a6..157a6d48cd 100644 --- a/src/ripple_app/ripple_app.cpp +++ b/src/ripple_app/ripple_app.cpp @@ -50,7 +50,6 @@ #include "misc/ProofOfWorkFactory.h" -namespace ripple { # include "main/NodeStoreScheduler.h" #include "main/NodeStoreScheduler.cpp" @@ -61,12 +60,10 @@ namespace ripple { #include "main/FatalErrorReporter.cpp" # include "rpc/RPCHandler.h" -} # include "rpc/RPCServerHandler.h" # include "main/RPCHTTPServer.h" #include "main/RPCHTTPServer.cpp" #include "rpc/RPCServerHandler.cpp" -namespace ripple { #include "rpc/RPCHandler.cpp" #include "websocket/WSConnection.h" @@ -81,9 +78,6 @@ namespace ripple { #include "websocket/WSConnection.cpp" # include "websocket/WSDoor.h" #include "websocket/WSDoor.cpp" -} - - #include "../ripple/common/ResolverAsio.h" @@ -92,15 +86,14 @@ namespace ripple { #include "main/Application.cpp" - - -namespace ripple { -# include "main/RippleMain.h" -#include "main/RippleMain.cpp" -} +#include "main/Main.cpp" //------------------------------------------------------------------------------ +namespace ripple { +int run (int argc, char** argv); +} + struct ProtobufLibrary { ~ProtobufLibrary () @@ -152,12 +145,5 @@ int main (int argc, char** argv) beast::SharedSingleton ::get (); - int result (0); - - ripple::RippleMain rippled; - - result = rippled.runFromMain (argc, argv); - - return result; + return ripple::run (argc, argv); } - diff --git a/src/ripple_app/ripple_app.h b/src/ripple_app/ripple_app.h index 8b3aba6014..5e2d454d3e 100644 --- a/src/ripple_app/ripple_app.h +++ b/src/ripple_app/ripple_app.h @@ -24,9 +24,6 @@ #include #endif - -//------------------------------------------------------------------------------ - // VFALCO TODO Reduce these boost dependencies. Make more interfaces // purely abstract and move implementation into .cpp files. // @@ -67,24 +64,17 @@ #include "../../ripple_overlay/ripple_overlay.h" -namespace ripple { #include "data/Database.h" #include "data/DatabaseCon.h" #include "data/SqliteDatabase.h" #include "data/DBInit.h" #include "shamap/SHAMapItem.h" -} - -// VFALCO NOTE Have to step outside the ripple namespace to -// get the specialization for std::hash, et. al. #include "shamap/SHAMapNode.h" #include "shamap/SHAMapTreeNode.h" #include "shamap/SHAMapMissingNode.h" #include "shamap/SHAMapSyncFilter.h" #include "shamap/SHAMapAddNode.h" #include "shamap/SHAMap.h" - -namespace ripple { #include "misc/SerializedTransaction.h" #include "misc/SerializedLedger.h" #include "tx/TransactionMeta.h" @@ -122,9 +112,7 @@ namespace ripple { #include "misc/NetworkOPs.h" #include "tx/TransactionMaster.h" #include "main/LocalCredentials.h" -} // escape the namespace #include "main/Application.h" -namespace ripple { #include "ledger/OrderBookDB.h" #include "tx/TransactionAcquire.h" #include "consensus/DisputedTx.h" @@ -145,6 +133,5 @@ namespace ripple { #include "contracts/Contract.h" #include "contracts/Interpreter.h" #include "contracts/Operation.h" -} #endif diff --git a/src/ripple_app/ripple_app_pt1.cpp b/src/ripple_app/ripple_app_pt1.cpp index 71deff1018..f9a8c6bf90 100644 --- a/src/ripple_app/ripple_app_pt1.cpp +++ b/src/ripple_app/ripple_app_pt1.cpp @@ -32,8 +32,6 @@ #include "misc/ProofOfWorkFactory.h" -namespace ripple { - #include "peers/PeerSet.cpp" #include "misc/OrderBook.cpp" #include "misc/ProofOfWorkFactory.cpp" @@ -47,5 +45,3 @@ namespace ripple { # include "ledger/LedgerCleaner.h" #include "ledger/LedgerCleaner.cpp" #include "ledger/LedgerMaster.cpp" - -} diff --git a/src/ripple_app/ripple_app_pt2.cpp b/src/ripple_app/ripple_app_pt2.cpp index 3cfab90114..e70acf6fae 100644 --- a/src/ripple_app/ripple_app_pt2.cpp +++ b/src/ripple_app/ripple_app_pt2.cpp @@ -23,8 +23,6 @@ #include "../ripple/common/seconds_clock.h" -namespace ripple { - #include "shamap/SHAMap.cpp" // Uses theApp #include "shamap/SHAMapItem.cpp" #include "shamap/SHAMapSync.cpp" @@ -42,8 +40,6 @@ namespace ripple { #include "data/SqliteDatabase.cpp" #include "data/DBInit.cpp" -} - # include "shamap/RadixMapTest.h" #include "shamap/RadixMapTest.cpp" #include "shamap/FetchPackTests.cpp" diff --git a/src/ripple_app/ripple_app_pt3.cpp b/src/ripple_app/ripple_app_pt3.cpp index aa7b7e761b..a242251f25 100644 --- a/src/ripple_app/ripple_app_pt3.cpp +++ b/src/ripple_app/ripple_app_pt3.cpp @@ -21,9 +21,6 @@ #include "ripple_app.h" -namespace ripple -{ - #include "ledger/Ledger.cpp" #include "shamap/SHAMapDelta.cpp" #include "shamap/SHAMapNode.cpp" @@ -34,5 +31,3 @@ namespace ripple #include "contracts/Operation.cpp" #include "contracts/ScriptData.cpp" #include "contracts/Interpreter.cpp" - -} diff --git a/src/ripple_app/ripple_app_pt4.cpp b/src/ripple_app/ripple_app_pt4.cpp index 2496ae1dd1..5b1eaa8397 100644 --- a/src/ripple_app/ripple_app_pt4.cpp +++ b/src/ripple_app/ripple_app_pt4.cpp @@ -29,18 +29,11 @@ #include "transactors/Transactor.h" -namespace ripple { - #include "paths/RippleState.cpp" - #include "peers/UniqueNodeList.cpp" - #include "ledger/InboundLedger.cpp" - #include "tx/TransactionCheck.cpp" #include "tx/TransactionMaster.cpp" #include "tx/Transaction.cpp" #include "tx/TransactionEngine.cpp" #include "tx/TransactionMeta.cpp" - -} diff --git a/src/ripple_app/ripple_app_pt5.cpp b/src/ripple_app/ripple_app_pt5.cpp index d68ea21dd6..22ea695871 100644 --- a/src/ripple_app/ripple_app_pt5.cpp +++ b/src/ripple_app/ripple_app_pt5.cpp @@ -32,11 +32,8 @@ #include "misc/ProofOfWork.h" -namespace ripple { - #include "ledger/LedgerTiming.cpp" #include "ledger/AcceptedLedgerTx.cpp" #include "main/LocalCredentials.cpp" #include "misc/Validations.cpp" #include "misc/FeeVote.cpp" -} diff --git a/src/ripple_app/ripple_app_pt6.cpp b/src/ripple_app/ripple_app_pt6.cpp index 6726925276..755c30bc18 100644 --- a/src/ripple_app/ripple_app_pt6.cpp +++ b/src/ripple_app/ripple_app_pt6.cpp @@ -23,8 +23,6 @@ #include "../ripple/common/seconds_clock.h" -namespace ripple { - #include "ledger/LedgerEntrySet.cpp" #include "ledger/AcceptedLedger.cpp" #include "ledger/DirectoryEntryIterator.cpp" @@ -34,5 +32,3 @@ namespace ripple { #include "misc/Offer.cpp" #include "paths/Pathfinder.cpp" #include "misc/Features.cpp" - -} diff --git a/src/ripple_app/ripple_app_pt7.cpp b/src/ripple_app/ripple_app_pt7.cpp index d0dfd513e4..cd0fd10ae7 100644 --- a/src/ripple_app/ripple_app_pt7.cpp +++ b/src/ripple_app/ripple_app_pt7.cpp @@ -25,9 +25,6 @@ #include "../ripple/common/seconds_clock.h" -namespace ripple -{ - #include "ledger/InboundLedgers.cpp" #include "ledger/LedgerHistory.cpp" #include "misc/SerializedLedger.cpp" @@ -36,5 +33,3 @@ namespace ripple # include "tx/TxQueueEntry.h" # include "tx/TxQueue.h" #include "misc/NetworkOPs.cpp" - -} diff --git a/src/ripple_app/ripple_app_pt8.cpp b/src/ripple_app/ripple_app_pt8.cpp index 003fa2157a..89f05a4e73 100644 --- a/src/ripple_app/ripple_app_pt8.cpp +++ b/src/ripple_app/ripple_app_pt8.cpp @@ -28,9 +28,6 @@ #include "../ripple_rpc/api/ErrorCodes.h" -namespace ripple -{ - #include "paths/PathRequest.cpp" #include "paths/PathRequests.cpp" #include "paths/RippleCalc.cpp" @@ -40,8 +37,6 @@ namespace ripple #include "paths/RippleLineCache.cpp" #include "ledger/SerializedValidation.cpp" -} - #ifdef _MSC_VER #pragma warning (pop) #endif diff --git a/src/ripple_app/rpc/RPCHandler.cpp b/src/ripple_app/rpc/RPCHandler.cpp index a4534d6d75..3ea233a59a 100644 --- a/src/ripple_app/rpc/RPCHandler.cpp +++ b/src/ripple_app/rpc/RPCHandler.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + // // Carries out the RPC. // @@ -4467,13 +4471,11 @@ Json::Value RPCInternalHandler::runHandler (const std::string& name, const Json: //------------------------------------------------------------------------------ -class JSONRPCTests : public beast::UnitTest +class JSONRPC_test : public beast::unit_test::suite { public: void testAutoFillFees () { - beginTestCase ("autofill_fee"); - RippleAddress rootSeedMaster = RippleAddress::createSeedGeneric ("masterpassphrase"); RippleAddress rootGeneratorMaster = RippleAddress::createGeneratorPublic (rootSeedMaster); RippleAddress rootAddress = RippleAddress::createAccountPublic (rootGeneratorMaster, 0); @@ -4504,14 +4506,12 @@ public: } } - void runTest () + void run () { testAutoFillFees (); } - - JSONRPCTests () : UnitTest ("ripple", "JSONRPC") - { - } }; -static JSONRPCTests jsonRPCTests; +BEAST_DEFINE_TESTSUITE(JSONRPC,ripple_app,ripple); + +} // ripple diff --git a/src/ripple_app/rpc/RPCHandler.h b/src/ripple_app/rpc/RPCHandler.h index a4b78ee226..c343271ee0 100644 --- a/src/ripple_app/rpc/RPCHandler.h +++ b/src/ripple_app/rpc/RPCHandler.h @@ -20,6 +20,10 @@ #ifndef __RPCHANDLER__ #define __RPCHANDLER__ +namespace ripple { + +// VFALCO Why are these magic macros in here instead of some ledger header? +// VFALCO TODO Replace with language constants. #define LEDGER_CURRENT -1 #define LEDGER_CLOSED -2 #define LEDGER_VALIDATED -3 @@ -196,4 +200,6 @@ private: handler_t mHandler; }; +} // ripple + #endif diff --git a/src/ripple_app/shamap/FetchPackTests.cpp b/src/ripple_app/shamap/FetchPackTests.cpp index 7e4159e77e..bc4a085ce8 100644 --- a/src/ripple_app/shamap/FetchPackTests.cpp +++ b/src/ripple_app/shamap/FetchPackTests.cpp @@ -17,9 +17,11 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + namespace ripple { -class FetchPackTests : public beast::UnitTest +class FetchPack_test : public beast::unit_test::suite { public: enum @@ -67,35 +69,34 @@ public: map.emplace (hash, blob); } - void runTest () + void run () { using namespace RadixMap; - beginTestCase ("Build"); - FullBelowCache fullBelowCache ("test.full_below", get_seconds_clock ()); boost::shared_ptr t1 (boost::make_shared
( smtFREE, fullBelowCache)); - add_random_items (tableItems, *t1, random()); + beast::Random r; + add_random_items (tableItems, *t1, r); boost::shared_ptr
t2 (t1->snapShot (true)); - add_random_items (tableItemsExtra, *t1, random ()); - add_random_items (tableItemsExtra, *t2, random ()); + add_random_items (tableItemsExtra, *t1, r); + add_random_items (tableItemsExtra, *t2, r); // turn t1 into t2 Map map; t2->getFetchPack (t1.get(), true, 1000000, boost::bind ( - &FetchPackTests::on_fetch, this, boost::ref (map), beast::_1, beast::_2)); + &FetchPack_test::on_fetch, this, boost::ref (map), beast::_1, beast::_2)); t1->getFetchPack (nullptr, true, 1000000, boost::bind ( - &FetchPackTests::on_fetch, this, boost::ref (map), beast::_1, beast::_2)); + &FetchPack_test::on_fetch, this, boost::ref (map), beast::_1, beast::_2)); // try to rebuild t2 from the fetch pack boost::shared_ptr
t3; try { - TestFilter filter (map, journal ()); + TestFilter filter (map, beast::Journal()); t3 = boost::make_shared
(smtFREE, t2->getHash (), fullBelowCache); @@ -105,23 +106,17 @@ public: // everything should be in the pack, no hashes should be needed std::vector hashes = t3->getNeededHashes(1, &filter); expect (hashes.empty(), "missing hashes"); + + expect (t3->getHash () == t2->getHash (), "root hashes do not match"); + expect (t3->deepCompare (*t2), "failed compare"); } catch (...) { - failException (); + fail ("unhandled exception"); } - - expect (t3->getHash () == t2->getHash (), "root hashes do not match"); - expect (t3->deepCompare (*t2), "failed compare"); - - pass (); - } - - FetchPackTests () : UnitTest ("FetchPack", "ripple") - { } }; -static FetchPackTests fetchPackTests; +BEAST_DEFINE_TESTSUITE(FetchPack,ripple_app,ripple); } diff --git a/src/ripple_app/shamap/SHAMap.cpp b/src/ripple_app/shamap/SHAMap.cpp index 7b0541a7e3..a4a81718f3 100644 --- a/src/ripple_app/shamap/SHAMap.cpp +++ b/src/ripple_app/shamap/SHAMap.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + SETUP_LOG (SHAMap) void SHAMap::DefaultMissingNodeHandler::operator() (beast::uint32 refNUm) @@ -1292,13 +1296,9 @@ void SHAMap::canonicalize (uint256 const& hash, SHAMapTreeNode::pointer& node) //------------------------------------------------------------------------------ -class SHAMapTests : public beast::UnitTest +class SHAMap_test : public beast::unit_test::suite { public: - SHAMapTests () : UnitTest ("SHAMap", "ripple") - { - } - // VFALCO TODO Rename this to createFilledVector and pass an unsigned char, tidy up // static Blob IntToVUC (int v) @@ -1311,9 +1311,9 @@ public: return vuc; } - void runTest () + void run () { - beginTestCase ("add/traverse"); + testcase ("add/traverse"); FullBelowCache fullBelowCache ("test.full_below", get_seconds_clock ()); @@ -1369,7 +1369,7 @@ public: - beginTestCase ("snapshot"); + testcase ("snapshot"); uint256 mapHash = sMap.getHash (); SHAMap::pointer map2 = sMap.snapShot (false); @@ -1386,4 +1386,6 @@ public: } }; -static SHAMapTests shaMapTests; +BEAST_DEFINE_TESTSUITE(SHAMap,ripple_app,ripple); + +} // ripple diff --git a/src/ripple_app/shamap/SHAMap.h b/src/ripple_app/shamap/SHAMap.h index 11126e6410..48e0f66b7b 100644 --- a/src/ripple_app/shamap/SHAMap.h +++ b/src/ripple_app/shamap/SHAMap.h @@ -23,17 +23,6 @@ #include "../ripple/radmap/ripple_radmap.h" #include "../main/FullBelowCache.h" -enum SHAMapState -{ - smsModifying = 0, // Objects can be added and removed (like an open ledger) - smsImmutable = 1, // Map cannot be changed (like a closed ledger) - smsSynching = 2, // Map's hash is locked in, valid nodes can be added (like a peer's closing ledger) - smsFloating = 3, // Map is free to change hash (like a synching open ledger) - smsInvalid = 4, // Map is known not to be valid (usually synching a corrupt ledger) -}; - -//------------------------------------------------------------------------------ - namespace std { template <> @@ -62,6 +51,15 @@ struct hash : std::hash namespace ripple { +enum SHAMapState +{ + smsModifying = 0, // Objects can be added and removed (like an open ledger) + smsImmutable = 1, // Map cannot be changed (like a closed ledger) + smsSynching = 2, // Map's hash is locked in, valid nodes can be added (like a peer's closing ledger) + smsFloating = 3, // Map is free to change hash (like a synching open ledger) + smsInvalid = 4, // Map is known not to be valid (usually synching a corrupt ledger) +}; + class SHAMap : public CountedObject { diff --git a/src/ripple_app/shamap/SHAMapDelta.cpp b/src/ripple_app/shamap/SHAMapDelta.cpp index 72c624e91d..b8821e13c9 100644 --- a/src/ripple_app/shamap/SHAMapDelta.cpp +++ b/src/ripple_app/shamap/SHAMapDelta.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // This code is used to compare another node's transaction tree // to our own. It returns a map containing all items that are different // between two SHA maps. It is optimized not to descend down tree @@ -268,3 +270,5 @@ void SHAMap::walkMap (std::vector& missingNodes, int maxMissi } } } + +} // ripple diff --git a/src/ripple_app/shamap/SHAMapItem.cpp b/src/ripple_app/shamap/SHAMapItem.cpp index 565bee571b..2c7feb5e33 100644 --- a/src/ripple_app/shamap/SHAMapItem.cpp +++ b/src/ripple_app/shamap/SHAMapItem.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class SHAMap; SHAMapItem::SHAMapItem (uint256 const& tag, Blob const& data) @@ -30,3 +32,5 @@ SHAMapItem::SHAMapItem (uint256 const& tag, const Serializer& data) , mData (data.peekData ()) { } + +} // ripple diff --git a/src/ripple_app/shamap/SHAMapItem.h b/src/ripple_app/shamap/SHAMapItem.h index 2704f61048..56adfc23fa 100644 --- a/src/ripple_app/shamap/SHAMapItem.h +++ b/src/ripple_app/shamap/SHAMapItem.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SHAMAPITEM_H #define RIPPLE_SHAMAPITEM_H +namespace ripple { + // an item stored in a SHAMap class SHAMapItem : public CountedObject @@ -122,4 +124,6 @@ private: Serializer mData; }; +} // ripple + #endif diff --git a/src/ripple_app/shamap/SHAMapMissingNode.cpp b/src/ripple_app/shamap/SHAMapMissingNode.cpp index 128358bb58..4a7c30bbc0 100644 --- a/src/ripple_app/shamap/SHAMapMissingNode.cpp +++ b/src/ripple_app/shamap/SHAMapMissingNode.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + std::ostream& operator<< (std::ostream& out, const SHAMapMissingNode& mn) { switch (mn.getMapType ()) @@ -37,3 +39,5 @@ std::ostream& operator<< (std::ostream& out, const SHAMapMissingNode& mn) return out; } + +} // ripple diff --git a/src/ripple_app/shamap/SHAMapMissingNode.h b/src/ripple_app/shamap/SHAMapMissingNode.h index cf0612aba0..284fed1c6a 100644 --- a/src/ripple_app/shamap/SHAMapMissingNode.h +++ b/src/ripple_app/shamap/SHAMapMissingNode.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SHAMAPMISSINGNODE_H #define RIPPLE_SHAMAPMISSINGNODE_H +namespace ripple { + enum SHAMapType { smtTRANSACTION = 1, // A tree of transactions @@ -27,8 +29,6 @@ enum SHAMapType smtFREE = 3, // A tree not part of a ledger }; -namespace ripple { - class SHAMapMissingNode : public std::runtime_error { public: @@ -97,6 +97,6 @@ private: extern std::ostream& operator<< (std::ostream&, SHAMapMissingNode const&); -} +} // ripple #endif diff --git a/src/ripple_app/shamap/SHAMapNode.cpp b/src/ripple_app/shamap/SHAMapNode.cpp index 8a81513e2f..e034b90b90 100644 --- a/src/ripple_app/shamap/SHAMapNode.cpp +++ b/src/ripple_app/shamap/SHAMapNode.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (SHAMapNode) // canonicalize the hash to a node ID for this depth @@ -175,3 +177,5 @@ void SHAMapNode::dump () const { WriteLog (lsDEBUG, SHAMapNode) << getString (); } + +} // ripple diff --git a/src/ripple_app/shamap/SHAMapSync.cpp b/src/ripple_app/shamap/SHAMapSync.cpp index 91defa4f88..77ffd6338c 100644 --- a/src/ripple_app/shamap/SHAMapSync.cpp +++ b/src/ripple_app/shamap/SHAMapSync.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + // VFALCO TODO tidy up this global static const uint256 uZero; @@ -731,13 +735,9 @@ std::list SHAMap::getTrustedPath (uint256 const& index) //#define SMS_DEBUG #endif -class SHAMapSyncTests : public beast::UnitTest +class SHAMapSync_test : public beast::unit_test::suite { public: - SHAMapSyncTests () : beast::UnitTest ("SHAMapSync", "ripple") - { - } - static SHAMapItem::pointer makeRandomAS () { Serializer s; @@ -762,7 +762,7 @@ public: if (!map.addItem (*item, false, false)) { - journal().fatal << + log << "Unable to add item to map"; return false; } @@ -772,7 +772,7 @@ public: { if (!map.delItem (*it)) { - journal().fatal << + log << "Unable to remove item from map"; return false; } @@ -780,7 +780,7 @@ public: if (beforeHash != map.getHash ()) { - journal().fatal << + log << "Hashes do not match"; return false; } @@ -788,7 +788,7 @@ public: return true; } - void runTest () + void run () { unsigned int seed; @@ -806,8 +806,6 @@ public: for (int i = 0; i < items; ++i) source.addItem (*makeRandomAS (), false, false); - beginTestCase ("add/remove"); - unexpected (!confuseMap (source, 500), "ConfuseMap"); source.setImmutable (); @@ -922,4 +920,6 @@ public: } }; -static SHAMapSyncTests shaMapSyncTests; +BEAST_DEFINE_TESTSUITE(SHAMapSync,ripple_app,ripple); + +} // ripple diff --git a/src/ripple_app/shamap/SHAMapSyncFilter.h b/src/ripple_app/shamap/SHAMapSyncFilter.h index 87fdc0ff3b..99d92761bb 100644 --- a/src/ripple_app/shamap/SHAMapSyncFilter.h +++ b/src/ripple_app/shamap/SHAMapSyncFilter.h @@ -20,8 +20,7 @@ #ifndef RIPPLE_SHAMAPSYNCFILTER_H #define RIPPLE_SHAMAPSYNCFILTER_H -/** Callback for filtering SHAMap during sync. -*/ +/** Callback for filtering SHAMap during sync. */ namespace ripple { class SHAMapSyncFilter diff --git a/src/ripple_app/shamap/SHAMapSyncFilters.cpp b/src/ripple_app/shamap/SHAMapSyncFilters.cpp index e9796651bd..3d1506c56f 100644 --- a/src/ripple_app/shamap/SHAMapSyncFilters.cpp +++ b/src/ripple_app/shamap/SHAMapSyncFilters.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + ConsensusTransSetSF::ConsensusTransSetSF (NodeCache& nodeCache) : m_nodeCache (nodeCache) { @@ -124,3 +126,5 @@ bool TransactionStateSF::haveNode (SHAMapNode const& id, { return getApp().getOPs ().getFetchPack (nodeHash, nodeData); } + +} // ripple diff --git a/src/ripple_app/shamap/SHAMapSyncFilters.h b/src/ripple_app/shamap/SHAMapSyncFilters.h index 9fcc021590..8e5dc91d65 100644 --- a/src/ripple_app/shamap/SHAMapSyncFilters.h +++ b/src/ripple_app/shamap/SHAMapSyncFilters.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SHAMAPSYNCFILTERS_H #define RIPPLE_SHAMAPSYNCFILTERS_H +namespace ripple { + // Sync filters allow low-level SHAMapSync code to interact correctly with // higher-level structures such as caches and transaction stores @@ -92,4 +94,6 @@ private: beast::uint32 mLedgerSeq; }; +} // ripple + #endif diff --git a/src/ripple_app/shamap/SHAMapTreeNode.cpp b/src/ripple_app/shamap/SHAMapTreeNode.cpp index 8b36c5c1fe..f30f857253 100644 --- a/src/ripple_app/shamap/SHAMapTreeNode.cpp +++ b/src/ripple_app/shamap/SHAMapTreeNode.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SHAMapTreeNode::SHAMapTreeNode (beast::uint32 seq, const SHAMapNode& nodeID) : SHAMapNode (nodeID) , mHash (beast::uint64(0)) @@ -475,3 +477,4 @@ bool SHAMapTreeNode::setChildHash (int m, uint256 const& hash) return updateHash (); } +} // ripple diff --git a/src/ripple_app/shamap/SHAMapTreeNode.h b/src/ripple_app/shamap/SHAMapTreeNode.h index c9c598a108..7a89110c3c 100644 --- a/src/ripple_app/shamap/SHAMapTreeNode.h +++ b/src/ripple_app/shamap/SHAMapTreeNode.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SHAMAPTREENODE_H #define RIPPLE_SHAMAPTREENODE_H +namespace ripple { + class SHAMap; enum SHANodeFormat @@ -29,8 +31,6 @@ enum SHANodeFormat snfHASH = 3, // just the hash }; -namespace ripple { - class SHAMapTreeNode : public SHAMapNode , public CountedObject @@ -186,6 +186,6 @@ private: bool updateHash (); }; -} +} // ripple #endif diff --git a/src/ripple_app/tx/Transaction.cpp b/src/ripple_app/tx/Transaction.cpp index a576149a31..7feb6c1c80 100644 --- a/src/ripple_app/tx/Transaction.cpp +++ b/src/ripple_app/tx/Transaction.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + Transaction::Transaction (SerializedTransaction::ref sit, bool bValidate) : mInLedger (0), mStatus (INVALID), mResult (temUNCERTAIN), mTransaction (sit) { @@ -364,3 +366,4 @@ bool Transaction::isHexTxID (const std::string& txid) return (ret == txid.end ()); } +} // ripple diff --git a/src/ripple_app/tx/Transaction.h b/src/ripple_app/tx/Transaction.h index 55fd182595..79d6340b26 100644 --- a/src/ripple_app/tx/Transaction.h +++ b/src/ripple_app/tx/Transaction.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TRANSACTION_H #define RIPPLE_TRANSACTION_H +namespace ripple { + // // Transactions should be constructed in JSON with. Use STObject::parseJson to obtain a binary version. // @@ -185,5 +187,6 @@ private: SerializedTransaction::pointer mTransaction; }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/tx/TransactionAcquire.cpp b/src/ripple_app/tx/TransactionAcquire.cpp index 1dabb6765f..1bec2a14b4 100644 --- a/src/ripple_app/tx/TransactionAcquire.cpp +++ b/src/ripple_app/tx/TransactionAcquire.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + //SETUP_LOG (TransactionAcquire) template <> char const* LogPartition::getPartitionName () { return "TxAcquire"; } @@ -250,3 +252,5 @@ SHAMapAddNode TransactionAcquire::takeNodes (const std::list& nodeID return SHAMapAddNode::invalid (); } } + +} // ripple diff --git a/src/ripple_app/tx/TransactionAcquire.h b/src/ripple_app/tx/TransactionAcquire.h index a44a398a46..148ada1314 100644 --- a/src/ripple_app/tx/TransactionAcquire.h +++ b/src/ripple_app/tx/TransactionAcquire.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TRANSACTIONACQUIRE_H #define RIPPLE_TRANSACTIONACQUIRE_H +namespace ripple { + // VFALCO TODO rename to PeerTxRequest // A transaction set we are trying to acquire class TransactionAcquire @@ -59,4 +61,6 @@ private: boost::weak_ptr pmDowncast (); }; +} // ripple + #endif diff --git a/src/ripple_app/tx/TransactionCheck.cpp b/src/ripple_app/tx/TransactionCheck.cpp index 3fcfa84521..ee9387c66b 100644 --- a/src/ripple_app/tx/TransactionCheck.cpp +++ b/src/ripple_app/tx/TransactionCheck.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +namespace ripple { // VFALCO TODO move this into TransactionEngine.cpp @@ -104,3 +105,5 @@ bool TransactionEngine::checkInvariants (TER result, const SerializedTransaction return true; } + +} // ripple diff --git a/src/ripple_app/tx/TransactionEngine.cpp b/src/ripple_app/tx/TransactionEngine.cpp index dbd566d95e..2ebfdf2807 100644 --- a/src/ripple_app/tx/TransactionEngine.cpp +++ b/src/ripple_app/tx/TransactionEngine.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // // XXX Make sure all fields are recognized in transactions. // @@ -222,4 +224,4 @@ TER TransactionEngine::applyTransaction (const SerializedTransaction& txn, Trans return terResult; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/tx/TransactionEngine.h b/src/ripple_app/tx/TransactionEngine.h index 782b97f0ee..825b5af41d 100644 --- a/src/ripple_app/tx/TransactionEngine.h +++ b/src/ripple_app/tx/TransactionEngine.h @@ -20,6 +20,8 @@ #ifndef __TRANSACTIONENGINE__ #define __TRANSACTIONENGINE__ +namespace ripple { + // A TransactionEngine applies serialized transactions to a ledger // It can also, verify signatures, verify fees, and give rejection reasons @@ -113,5 +115,6 @@ inline TransactionEngineParams operator& (const TransactionEngineParams& l1, con return static_cast (static_cast (l1) & static_cast (l2)); } +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/tx/TransactionMaster.cpp b/src/ripple_app/tx/TransactionMaster.cpp index 0b2d1f5222..97a067b046 100644 --- a/src/ripple_app/tx/TransactionMaster.cpp +++ b/src/ripple_app/tx/TransactionMaster.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + TransactionMaster::TransactionMaster () : mCache ("TransactionCache", 65536, 1800, get_seconds_clock (), LogPartition::getJournal ()) @@ -112,3 +114,5 @@ void TransactionMaster::sweep (void) { mCache.sweep (); } + +} // ripple diff --git a/src/ripple_app/tx/TransactionMaster.h b/src/ripple_app/tx/TransactionMaster.h index fa8429d82e..c4c0446edb 100644 --- a/src/ripple_app/tx/TransactionMaster.h +++ b/src/ripple_app/tx/TransactionMaster.h @@ -20,6 +20,8 @@ #ifndef __TRANSACTIONMASTER__ #define __TRANSACTIONMASTER__ +namespace ripple { + // Tracks all transactions in memory class TransactionMaster : beast::LeakChecked @@ -40,5 +42,6 @@ private: TaggedCache mCache; }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_app/tx/TransactionMeta.cpp b/src/ripple_app/tx/TransactionMeta.cpp index c6b035dffe..e94e0a0328 100644 --- a/src/ripple_app/tx/TransactionMeta.cpp +++ b/src/ripple_app/tx/TransactionMeta.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO TODO rename class to TransactionMeta SETUP_LOG (TransactionMetaSet) @@ -233,4 +235,4 @@ void TransactionMetaSet::addRaw (Serializer& s, TER result, beast::uint32 index) getAsObject ().add (s); } -// vim:ts=4 +} // ripple diff --git a/src/ripple_app/tx/TransactionMeta.h b/src/ripple_app/tx/TransactionMeta.h index 224f27715e..a9ce096dd2 100644 --- a/src/ripple_app/tx/TransactionMeta.h +++ b/src/ripple_app/tx/TransactionMeta.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TRANSACTIONMETA_H #define RIPPLE_TRANSACTIONMETA_H +namespace ripple { + class TransactionMetaSet : beast::LeakChecked { public: @@ -121,6 +123,6 @@ private: STArray mNodes; }; -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_app/tx/TxQueue.cpp b/src/ripple_app/tx/TxQueue.cpp index 9e6d529df7..f1ac02774e 100644 --- a/src/ripple_app/tx/TxQueue.cpp +++ b/src/ripple_app/tx/TxQueue.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class TxQueueImp : public TxQueue , public beast::LeakChecked @@ -141,3 +143,5 @@ TxQueue* TxQueue::New () { return new TxQueueImp; } + +} // ripple diff --git a/src/ripple_app/tx/TxQueue.h b/src/ripple_app/tx/TxQueue.h index fcecbe2719..ef79ed638d 100644 --- a/src/ripple_app/tx/TxQueue.h +++ b/src/ripple_app/tx/TxQueue.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TXQUEUE_H_INCLUDED #define RIPPLE_TXQUEUE_H_INCLUDED +namespace ripple { + class TxQueue : beast::LeakChecked { public: @@ -41,4 +43,6 @@ public: virtual bool stopProcessing (TxQueueEntry::ref finishedJob) = 0; }; +} // ripple + #endif diff --git a/src/ripple_app/tx/TxQueueEntry.cpp b/src/ripple_app/tx/TxQueueEntry.cpp index 68664fd32a..40a19eb9da 100644 --- a/src/ripple_app/tx/TxQueueEntry.cpp +++ b/src/ripple_app/tx/TxQueueEntry.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + void TxQueueEntry::addCallbacks (const TxQueueEntry& otherEntry) { BOOST_FOREACH (const stCallback & callback, otherEntry.mCallbacks) @@ -29,3 +31,4 @@ void TxQueueEntry::doCallbacks (TER result) callback (mTxn, result); } +} // ripple diff --git a/src/ripple_app/tx/TxQueueEntry.h b/src/ripple_app/tx/TxQueueEntry.h index 86f6973fc3..20b8569247 100644 --- a/src/ripple_app/tx/TxQueueEntry.h +++ b/src/ripple_app/tx/TxQueueEntry.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TXQUEUEENTRY_H_INCLUDED #define RIPPLE_TXQUEUEENTRY_H_INCLUDED +namespace ripple { + // Allow transactions to be signature checked out of sequence but retired in sequence class TxQueueEntry { @@ -64,4 +66,6 @@ private: std::list mCallbacks; }; +} // ripple + #endif diff --git a/src/ripple_app/websocket/WSConnection.cpp b/src/ripple_app/websocket/WSConnection.cpp index 9675393514..14d86a3428 100644 --- a/src/ripple_app/websocket/WSConnection.cpp +++ b/src/ripple_app/websocket/WSConnection.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOGN (WSConnection, "WSConnection") //------------------------------------------------------------------------------ @@ -200,3 +202,5 @@ Json::Value WSConnection::invokeCommand (Json::Value& jvRequest) return jvResult; } + +} // ripple diff --git a/src/ripple_app/websocket/WSConnection.h b/src/ripple_app/websocket/WSConnection.h index ce341982b4..d1625f8b19 100644 --- a/src/ripple_app/websocket/WSConnection.h +++ b/src/ripple_app/websocket/WSConnection.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_WSCONNECTION_H #define RIPPLE_WSCONNECTION_H -//------------------------------------------------------------------------------ +namespace ripple { /** A Ripple WebSocket connection handler. This handles everything that is independent of the endpint_type. @@ -203,4 +203,6 @@ private: weak_connection_ptr m_connection; }; +} // ripple + #endif diff --git a/src/ripple_app/websocket/WSDoor.cpp b/src/ripple_app/websocket/WSDoor.cpp index 6c3fbd04dd..3d305162e8 100644 --- a/src/ripple_app/websocket/WSDoor.cpp +++ b/src/ripple_app/websocket/WSDoor.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (WSDoor) // @@ -178,3 +180,5 @@ WSDoor* WSDoor::New (Resource::Manager& resourceManager, return door.release (); } + +} // ripple diff --git a/src/ripple_app/websocket/WSDoor.h b/src/ripple_app/websocket/WSDoor.h index 115d9a66bd..9e61b59f5a 100644 --- a/src/ripple_app/websocket/WSDoor.h +++ b/src/ripple_app/websocket/WSDoor.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_WSDOOR_H_INCLUDED #define RIPPLE_WSDOOR_H_INCLUDED +namespace ripple { + /** Handles accepting incoming WebSocket connections. */ class WSDoor : public beast::Stoppable { @@ -34,4 +36,6 @@ public: int iPort, bool bPublic, bool bProxy, boost::asio::ssl::context& ssl_context); }; +} // ripple + #endif diff --git a/src/ripple_app/websocket/WSServerHandler.cpp b/src/ripple_app/websocket/WSServerHandler.cpp index 51633f623d..740accd7f5 100644 --- a/src/ripple_app/websocket/WSServerHandler.cpp +++ b/src/ripple_app/websocket/WSServerHandler.cpp @@ -17,4 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOGN (WSServerHandlerLog,"WSServerHandler") + +} // ripple diff --git a/src/ripple_app/websocket/WSServerHandler.h b/src/ripple_app/websocket/WSServerHandler.h index e7ffb61045..39386c64fa 100644 --- a/src/ripple_app/websocket/WSServerHandler.h +++ b/src/ripple_app/websocket/WSServerHandler.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_WSSERVERHANDLER_H_INCLUDED #define RIPPLE_WSSERVERHANDLER_H_INCLUDED +namespace ripple { + extern bool serverOkay (std::string& reason); template @@ -424,4 +426,6 @@ public: } }; +} // ripple + #endif diff --git a/src/ripple_basics/containers/RangeSet.cpp b/src/ripple_basics/containers/RangeSet.cpp index 79e33add92..147d7183a0 100644 --- a/src/ripple_basics/containers/RangeSet.cpp +++ b/src/ripple_basics/containers/RangeSet.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + SETUP_LOG (RangeSet) // VFALCO NOTE std::min and std::max not good enough? @@ -257,13 +261,9 @@ void RangeSet::checkInternalConsistency () const noexcept //------------------------------------------------------------------------------ -class RangeSetTests : public beast::UnitTest +class RangeSet_test : public beast::unit_test::suite { public: - RangeSetTests () : UnitTest ("RangeSet", "ripple") - { - } - RangeSet createPredefinedSet () { RangeSet set; @@ -282,7 +282,7 @@ public: void testMembership () { - beginTestCase ("membership"); + testcase ("membership"); RangeSet r1, r2; @@ -301,7 +301,7 @@ public: void testPrevMissing () { - beginTestCase ("prevMissing"); + testcase ("prevMissing"); RangeSet const set = createPredefinedSet (); @@ -316,7 +316,7 @@ public: } } - void runTest () + void run () { testMembership (); @@ -326,5 +326,7 @@ public: } }; -static RangeSetTests rangeSetTests; +BEAST_DEFINE_TESTSUITE(RangeSet,ripple_basics,ripple); + +} // ripple diff --git a/src/ripple_basics/containers/RangeSet.h b/src/ripple_basics/containers/RangeSet.h index d6ebb5005c..a6a7b03ef2 100644 --- a/src/ripple_basics/containers/RangeSet.h +++ b/src/ripple_basics/containers/RangeSet.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_RANGESET_H_INCLUDED #define RIPPLE_RANGESET_H_INCLUDED -/** A sparse set of integers. -*/ +namespace ripple { + +/** A sparse set of integers. */ // VFALCO TODO Replace with juce::SparseSet class RangeSet { @@ -77,4 +78,6 @@ private: Map mRanges; }; +} // ripple + #endif diff --git a/src/ripple_basics/containers/SyncUnorderedMap.h b/src/ripple_basics/containers/SyncUnorderedMap.h index f33855022b..086ab90d1a 100644 --- a/src/ripple_basics/containers/SyncUnorderedMap.h +++ b/src/ripple_basics/containers/SyncUnorderedMap.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SYNC_UNORDERED_MAP_H #define RIPPLE_SYNC_UNORDERED_MAP_H +namespace ripple { + // Common base class SyncUnorderedMap { @@ -162,5 +164,8 @@ struct Destroyer > } }; -} +} // detail + +} // ripple + #endif diff --git a/src/ripple_basics/log/Log.cpp b/src/ripple_basics/log/Log.cpp index fba8c493e5..7043ffda88 100644 --- a/src/ripple_basics/log/Log.cpp +++ b/src/ripple_basics/log/Log.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + Log::Log (LogSeverity s) : m_level (s) , m_partition (nullptr) @@ -125,3 +127,4 @@ LogSeverity Log::stringToSeverity (const std::string& s) return lsINVALID; } +} // ripple diff --git a/src/ripple_basics/log/Log.h b/src/ripple_basics/log/Log.h index f1b6de299c..3c1bc08f2d 100644 --- a/src/ripple_basics/log/Log.h +++ b/src/ripple_basics/log/Log.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BASICS_LOG_H_INCLUDED #define RIPPLE_BASICS_LOG_H_INCLUDED +namespace ripple { + /** RAII helper for writing to the LogSink. */ class Log : public beast::Uncopyable { @@ -76,4 +78,6 @@ private: // #define CondLog(c, s, k) if (!ShouldLog (s, k) || !(c)) do {} while(0); else Log(s, LogPartition::get ()) +} // ripple + #endif diff --git a/src/ripple_basics/log/LogFile.cpp b/src/ripple_basics/log/LogFile.cpp index 2cef1364dd..bd072de168 100644 --- a/src/ripple_basics/log/LogFile.cpp +++ b/src/ripple_basics/log/LogFile.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + LogFile::LogFile () : m_stream (nullptr) { @@ -80,3 +82,4 @@ void LogFile::writeln (char const* text) } } +} // ripple diff --git a/src/ripple_basics/log/LogFile.h b/src/ripple_basics/log/LogFile.h index 7acd2ae536..195edf82a3 100644 --- a/src/ripple_basics/log/LogFile.h +++ b/src/ripple_basics/log/LogFile.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BASICS_LOGFILE_H_INCLUDED #define RIPPLE_BASICS_LOGFILE_H_INCLUDED +namespace ripple { + /** Manages a system file containing logged output. The system file remains open during program execution. Interfaces @@ -103,4 +105,6 @@ private: boost::filesystem::path m_path; }; +} // ripple + #endif diff --git a/src/ripple_basics/log/LogPartition.cpp b/src/ripple_basics/log/LogPartition.cpp index b9e9a4cfe0..ef4f6dc2a7 100644 --- a/src/ripple_basics/log/LogPartition.cpp +++ b/src/ripple_basics/log/LogPartition.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + void LogPartition::write (beast::Journal::Severity level, std::string const& text) { std::string output; @@ -173,3 +175,5 @@ beast::Journal::Severity LogPartition::convertLogSeverity (LogSeverity level) return Journal::kFatal; } + +} // ripple diff --git a/src/ripple_basics/log/LogPartition.h b/src/ripple_basics/log/LogPartition.h index 70a9d01ca0..fc96ba2f8c 100644 --- a/src/ripple_basics/log/LogPartition.h +++ b/src/ripple_basics/log/LogPartition.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BASICS_LOGPARTITION_H_INCLUDED #define RIPPLE_BASICS_LOGPARTITION_H_INCLUDED +namespace ripple { + class LogPartition : public beast::Journal::Sink { public: @@ -133,4 +135,7 @@ LogPartition& LogPartition::get () struct Class##Instantiator { Class##Instantiator () { LogPartition::get (); } }; \ static Class##Instantiator Class##Instantiator_instance; +} // ripple + #endif + diff --git a/src/ripple_basics/log/LogSeverity.h b/src/ripple_basics/log/LogSeverity.h index 5aed510fbd..7cc1440ee0 100644 --- a/src/ripple_basics/log/LogSeverity.h +++ b/src/ripple_basics/log/LogSeverity.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BASICS_LOGSEVERITY_H_INCLUDED #define RIPPLE_BASICS_LOGSEVERITY_H_INCLUDED +namespace ripple { + enum LogSeverity { lsINVALID = -1, // used to indicate an invalid severity @@ -31,4 +33,6 @@ enum LogSeverity lsFATAL = 5 // A severe condition that indicates a server problem }; +} // ripple + #endif diff --git a/src/ripple_basics/log/LogSink.cpp b/src/ripple_basics/log/LogSink.cpp index 0e9cc5ae7e..aa378aa7ef 100644 --- a/src/ripple_basics/log/LogSink.cpp +++ b/src/ripple_basics/log/LogSink.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + LogSink::LogSink () : m_mutex ("Log", __FILE__, __LINE__) , m_minSeverity (lsINFO) @@ -184,3 +186,4 @@ LogSink::Ptr LogSink::get () return beast::SharedSingleton ::getInstance (); } +} // ripple diff --git a/src/ripple_basics/log/LogSink.h b/src/ripple_basics/log/LogSink.h index b08dfa5f90..929e4d4b16 100644 --- a/src/ripple_basics/log/LogSink.h +++ b/src/ripple_basics/log/LogSink.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BASICS_LOGSINK_H_INCLUDED #define RIPPLE_BASICS_LOGSINK_H_INCLUDED +namespace ripple { + /** An endpoint for all logging messages. */ class LogSink { @@ -94,4 +96,7 @@ private: LogFile m_logFile; LogSeverity m_minSeverity; }; + +} // ripple + #endif diff --git a/src/ripple_basics/log/LoggedTimings.h b/src/ripple_basics/log/LoggedTimings.h index df33b7bed9..41ea13d5a2 100644 --- a/src/ripple_basics/log/LoggedTimings.h +++ b/src/ripple_basics/log/LoggedTimings.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_BASICS_LOGGEDTIMINGS_H_INCLUDED #define RIPPLE_BASICS_LOGGEDTIMINGS_H_INCLUDED -namespace detail -{ +namespace ripple { + +namespace detail { /** Template class that performs destruction of an object. Default implementation simply calls delete @@ -66,7 +67,7 @@ inline double cleanElapsed (double seconds) noexcept return static_cast ((seconds * 10 + 0.5) / 10); } -} +} // detail //------------------------------------------------------------------------------ @@ -125,4 +126,6 @@ void logTimedCall (beast::Journal::Stream stream, } } +} // ripple + #endif diff --git a/src/ripple_basics/ripple_basics.cpp b/src/ripple_basics/ripple_basics.cpp index c5b9aa46b7..0711a8945d 100644 --- a/src/ripple_basics/ripple_basics.cpp +++ b/src/ripple_basics/ripple_basics.cpp @@ -43,8 +43,6 @@ //------------------------------------------------------------------------------ -namespace ripple { - #include "containers/RangeSet.cpp" #include "log/Log.cpp" @@ -59,5 +57,3 @@ namespace ripple { #include "utility/ThreadName.cpp" #include "utility/Time.cpp" #include "utility/UptimeTimer.cpp" - -} diff --git a/src/ripple_basics/ripple_basics.h b/src/ripple_basics/ripple_basics.h index 2733908c62..7dd1b4cf2a 100644 --- a/src/ripple_basics/ripple_basics.h +++ b/src/ripple_basics/ripple_basics.h @@ -37,8 +37,6 @@ #include "../ripple/types/ripple_types.h" -namespace ripple { - #include "types/BasicTypes.h" # include "log/LogSeverity.h" @@ -60,6 +58,4 @@ namespace ripple { #include "containers/RangeSet.h" #include "containers/SyncUnorderedMap.h" -} - #endif diff --git a/src/ripple_basics/types/BasicTypes.h b/src/ripple_basics/types/BasicTypes.h index 5e26744835..521d17b115 100644 --- a/src/ripple_basics/types/BasicTypes.h +++ b/src/ripple_basics/types/BasicTypes.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BASICTYPES_H #define RIPPLE_BASICTYPES_H +namespace ripple { + /** Synchronization primitives. This lets us switch between tracked and untracked mutexes. */ @@ -39,4 +41,6 @@ typedef DeprecatedRecursiveMutex::scoped_lock DeprecatedScopedLock; /** A callback used to check for canceling an operation. */ typedef std::function CancelCallback; +} // ripple + #endif diff --git a/src/ripple_basics/utility/CountedObject.cpp b/src/ripple_basics/utility/CountedObject.cpp index bc86cbccba..d2a120e95e 100644 --- a/src/ripple_basics/utility/CountedObject.cpp +++ b/src/ripple_basics/utility/CountedObject.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + CountedObjects& CountedObjects::getInstance () { static CountedObjects instance; @@ -90,3 +92,5 @@ CountedObjects::CounterBase::~CounterBase () // undefined behavior will result if the singleton's member // functions are called. } + +} // ripple diff --git a/src/ripple_basics/utility/CountedObject.h b/src/ripple_basics/utility/CountedObject.h index bbb6b96695..99cc8af711 100644 --- a/src/ripple_basics/utility/CountedObject.h +++ b/src/ripple_basics/utility/CountedObject.h @@ -20,10 +20,9 @@ #ifndef RIPPLE_COUNTEDOBJECT_H_INCLUDED #define RIPPLE_COUNTEDOBJECT_H_INCLUDED -//------------------------------------------------------------------------------ +namespace ripple { -/** Manages all counted object types. -*/ +/** Manages all counted object types. */ class CountedObjects { public: @@ -134,4 +133,6 @@ private: } }; +} // ripple + #endif diff --git a/src/ripple_basics/utility/IniFile.cpp b/src/ripple_basics/utility/IniFile.cpp index 63cfce7c0a..41fa99d3c8 100644 --- a/src/ripple_basics/utility/IniFile.cpp +++ b/src/ripple_basics/utility/IniFile.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + #define SECTION_DEFAULT_NAME "" struct ParseSectionLog; // for Log @@ -174,3 +176,4 @@ parseKeyValueSection (Section& secSource, beast::String const& strSection) return result; } +} // ripple diff --git a/src/ripple_basics/utility/IniFile.h b/src/ripple_basics/utility/IniFile.h index 4f02dc259b..3e975e9593 100644 --- a/src/ripple_basics/utility/IniFile.h +++ b/src/ripple_basics/utility/IniFile.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_INIFILE_H_INCLUDED #define RIPPLE_INIFILE_H_INCLUDED +namespace ripple { + // VFALCO TODO Rename to IniFile and clean up typedef std::map > Section; @@ -41,4 +43,6 @@ Section::mapped_type* SectionEntries (Section& secSource, const std::string& str beast::StringPairArray parseKeyValueSection (Section& secSource, beast::String const& strSection); +} // ripple + #endif diff --git a/src/ripple_basics/utility/PlatformMacros.h b/src/ripple_basics/utility/PlatformMacros.h index 8750be3733..9ac7055fd3 100644 --- a/src/ripple_basics/utility/PlatformMacros.h +++ b/src/ripple_basics/utility/PlatformMacros.h @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + #ifndef RIPPLE_PLATFORMMACROS_H #define RIPPLE_PLATFORMMACROS_H @@ -32,4 +34,6 @@ #define NUMBER(x) (sizeof(x)/sizeof((x)[0])) #define isSetBit(x,y) (!!((x) & (y))) +} // ripple + #endif diff --git a/src/ripple_basics/utility/StringUtilities.cpp b/src/ripple_basics/utility/StringUtilities.cpp index 9a8e15005c..a477461719 100644 --- a/src/ripple_basics/utility/StringUtilities.cpp +++ b/src/ripple_basics/utility/StringUtilities.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + // VFALCO TODO Replace these with something more robust and without macros. // #if ! BEAST_MSVC @@ -224,6 +228,8 @@ bool parseIpPort (const std::string& strSource, std::string& strIP, int& iPort) return bValid; } +// VFALCO TODO Callers should be using beast::URL and beast::ParsedURL, not this home-brew. +// bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath) { // scheme://username:password@hostname:port/rest @@ -313,7 +319,7 @@ beast::StringPairArray parseDelimitedKeyValueString (beast::String parameters, //------------------------------------------------------------------------------ -class StringUtilitiesTests : public beast::UnitTest +class StringUtilities_test : public beast::unit_test::suite { public: void testUnHexSuccess (std::string strIn, std::string strExpected) @@ -340,7 +346,7 @@ public: void testUnHex () { - beginTestCase ("strUnHex"); + testcase ("strUnHex"); testUnHexSuccess ("526970706c6544", "RippleD"); testUnHexSuccess ("A", "\n"); @@ -358,7 +364,7 @@ public: void testParseUrl () { - beginTestCase ("parseUrl"); + testcase ("parseUrl"); std::string strScheme; std::string strDomain; @@ -402,16 +408,14 @@ public: "parseUrl: Mixed://domain/path path failed"); } - void runTest () + void run () { testParseUrl (); testUnHex (); } - - StringUtilitiesTests () : UnitTest ("StringUtilities", "ripple") - { - } }; -static StringUtilitiesTests stringUtilitiesTests; +BEAST_DEFINE_TESTSUITE(StringUtilities,ripple_basics,ripple); + +} // ripple diff --git a/src/ripple_basics/utility/StringUtilities.h b/src/ripple_basics/utility/StringUtilities.h index 635a255cd5..12ce53ccbf 100644 --- a/src/ripple_basics/utility/StringUtilities.h +++ b/src/ripple_basics/utility/StringUtilities.h @@ -20,10 +20,9 @@ #ifndef RIPPLE_STRINGUTILITIES_H #define RIPPLE_STRINGUTILITIES_H -/** String utility functions. -*/ +namespace ripple { -//------------------------------------------------------------------------------ +// String utility functions. // Ripple specific constant used for parsing qualities and other things // @@ -132,4 +131,6 @@ bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& s extern beast::StringPairArray parseDelimitedKeyValueString (beast::String s, beast::beast_wchar delimiter='|'); +} // ripple + #endif diff --git a/src/ripple_basics/utility/Sustain.cpp b/src/ripple_basics/utility/Sustain.cpp index 60696697ff..3042c08c29 100644 --- a/src/ripple_basics/utility/Sustain.cpp +++ b/src/ripple_basics/utility/Sustain.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + #ifdef __unix__ static pid_t pManager = static_cast (0); @@ -108,3 +110,5 @@ std::string StopSustain () } #endif + +} // ripple diff --git a/src/ripple_basics/utility/Sustain.h b/src/ripple_basics/utility/Sustain.h index d7d04569b9..8c9a45b039 100644 --- a/src/ripple_basics/utility/Sustain.h +++ b/src/ripple_basics/utility/Sustain.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SUSTAIN_H #define RIPPLE_SUSTAIN_H +namespace ripple { + // "Sustain" is a system for a buddy process that monitors the main process // and relaunches it on a fault. // @@ -30,4 +32,6 @@ extern bool HaveSustain (); extern std::string StopSustain (); extern std::string DoSustain (std::string logFile); +} // ripple + #endif diff --git a/src/ripple_basics/utility/ThreadName.cpp b/src/ripple_basics/utility/ThreadName.cpp index 6931830f84..a46e6ee30c 100644 --- a/src/ripple_basics/utility/ThreadName.cpp +++ b/src/ripple_basics/utility/ThreadName.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO TODO use beast::Thread::setCurrentThreadName() or something similar. #if _MSC_VER @@ -91,3 +93,5 @@ extern void setCallingThreadName (const char*) } #endif #endif + +} // ripple diff --git a/src/ripple_basics/utility/ThreadName.h b/src/ripple_basics/utility/ThreadName.h index 070e54ef63..418789a918 100644 --- a/src/ripple_basics/utility/ThreadName.h +++ b/src/ripple_basics/utility/ThreadName.h @@ -20,6 +20,10 @@ #ifndef RIPPLE_THREADNAME_H #define RIPPLE_THREADNAME_H +namespace ripple { + extern void setCallingThreadName (char const*); +} // ripple + #endif diff --git a/src/ripple_basics/utility/Time.cpp b/src/ripple_basics/utility/Time.cpp index e08460be27..e59b3dcb1e 100644 --- a/src/ripple_basics/utility/Time.cpp +++ b/src/ripple_basics/utility/Time.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // VFALCO TODO Tidy this up into a RippleTime object // @@ -55,3 +57,5 @@ uint64_t utFromSeconds (int iSeconds) return tdDelta.total_seconds (); } + +} // ripple diff --git a/src/ripple_basics/utility/Time.h b/src/ripple_basics/utility/Time.h index 77c3c0f2bb..a05e9f1ffe 100644 --- a/src/ripple_basics/utility/Time.h +++ b/src/ripple_basics/utility/Time.h @@ -20,9 +20,13 @@ #ifndef RIPPLE_TIME_H #define RIPPLE_TIME_H +namespace ripple { + boost::posix_time::ptime ptEpoch (); int iToSeconds (boost::posix_time::ptime ptWhen); boost::posix_time::ptime ptFromSeconds (int iSeconds); uint64_t utFromSeconds (int iSeconds); +} // ripple + #endif diff --git a/src/ripple_basics/utility/UptimeTimer.cpp b/src/ripple_basics/utility/UptimeTimer.cpp index e3a8495920..8adca4797a 100644 --- a/src/ripple_basics/utility/UptimeTimer.cpp +++ b/src/ripple_basics/utility/UptimeTimer.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + UptimeTimer::UptimeTimer () : m_elapsedTime (0) , m_startTime (::time (0)) @@ -72,3 +74,5 @@ UptimeTimer& UptimeTimer::getInstance () return instance; } + +} // ripple diff --git a/src/ripple_basics/utility/UptimeTimer.h b/src/ripple_basics/utility/UptimeTimer.h index 3beaf7d758..a1fc777cca 100644 --- a/src/ripple_basics/utility/UptimeTimer.h +++ b/src/ripple_basics/utility/UptimeTimer.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_UPTIMETIMER_H #define RIPPLE_UPTIMETIMER_H +namespace ripple { + /** Tracks program uptime. The timer can be switched to a manual system of updating, to reduce @@ -51,4 +53,6 @@ private: bool m_isUpdatingManually; }; +} // ripple + #endif diff --git a/src/ripple_core/functional/Config.cpp b/src/ripple_core/functional/Config.cpp index 80d2150702..21219f8c42 100644 --- a/src/ripple_core/functional/Config.cpp +++ b/src/ripple_core/functional/Config.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // // TODO: Check permissions on config file before using it. // @@ -779,3 +781,6 @@ beast::File const& Config::getModuleDatabasePath () // // //------------------------------------------------------------------------------ + +} // ripple + diff --git a/src/ripple_core/functional/Config.h b/src/ripple_core/functional/Config.h index 3ff3e358e0..72851d7024 100644 --- a/src/ripple_core/functional/Config.h +++ b/src/ripple_core/functional/Config.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_CORE_CONFIG_H_INCLUDED #define RIPPLE_CORE_CONFIG_H_INCLUDED +namespace ripple { + // VFALCO TODO Replace these with beast "unsigned long long" generators // VFALCO NOTE Apparently these are used elsewhere. Make them constants in the config // or in the Application @@ -491,6 +493,6 @@ public: extern Config& getConfig (); -#endif +} // ripple -// vim:ts=4 +#endif diff --git a/src/ripple_core/functional/ConfigSections.h b/src/ripple_core/functional/ConfigSections.h index 59ed90ede9..e3ada3e0c3 100644 --- a/src/ripple_core/functional/ConfigSections.h +++ b/src/ripple_core/functional/ConfigSections.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_CONFIGSECTIONS_H_INCLUDED #define RIPPLE_CONFIGSECTIONS_H_INCLUDED +namespace ripple { + // VFALCO NOTE // // Please use this style for all new sections @@ -108,4 +110,6 @@ struct ConfigSection #define SECTION_VALIDATORS "validators" #define SECTION_VALIDATORS_SITE "validators_site" +} // ripple + #endif diff --git a/src/ripple_core/functional/LoadEvent.cpp b/src/ripple_core/functional/LoadEvent.cpp index 6bedb919c4..92f6a37452 100644 --- a/src/ripple_core/functional/LoadEvent.cpp +++ b/src/ripple_core/functional/LoadEvent.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + LoadEvent::LoadEvent (LoadMonitor& monitor, const std::string& name, bool shouldStart) : m_loadMonitor (monitor) , m_isRunning (false) @@ -88,3 +90,5 @@ void LoadEvent::stop () m_isRunning = false; m_loadMonitor.addLoadSample (*this); } + +} // ripple diff --git a/src/ripple_core/functional/LoadEvent.h b/src/ripple_core/functional/LoadEvent.h index 01918652aa..944f69b02d 100644 --- a/src/ripple_core/functional/LoadEvent.h +++ b/src/ripple_core/functional/LoadEvent.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LOADEVENT_H #define RIPPLE_LOADEVENT_H +namespace ripple { + class LoadMonitor; // VFALCO NOTE What is the difference between a LoadEvent and a LoadMonitor? @@ -76,4 +78,6 @@ private: double m_secondsRunning; }; +} // ripple + #endif diff --git a/src/ripple_core/functional/LoadFeeTrack.h b/src/ripple_core/functional/LoadFeeTrack.h index bed002d46a..1ad3fe3c39 100644 --- a/src/ripple_core/functional/LoadFeeTrack.h +++ b/src/ripple_core/functional/LoadFeeTrack.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LOADFEETRACK_H_INCLUDED #define RIPPLE_LOADFEETRACK_H_INCLUDED +namespace ripple { + /** Manages the current fee schedule. The "base" fee is the cost to send a reference transaction under no load, @@ -66,4 +68,6 @@ public: virtual bool isLoadedCluster () = 0; }; +} // ripple + #endif diff --git a/src/ripple_core/functional/LoadFeeTrackImp.cpp b/src/ripple_core/functional/LoadFeeTrackImp.cpp index ef6ebca5ba..026f0624b2 100644 --- a/src/ripple_core/functional/LoadFeeTrackImp.cpp +++ b/src/ripple_core/functional/LoadFeeTrackImp.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + LoadFeeTrack* LoadFeeTrack::New (beast::Journal journal) { return new LoadFeeTrackImp (journal); @@ -24,20 +28,14 @@ LoadFeeTrack* LoadFeeTrack::New (beast::Journal journal) //------------------------------------------------------------------------------ -class LoadFeeTrackTests : public beast::UnitTest +class LoadFeeTrack_test : public beast::unit_test::suite { public: - LoadFeeTrackTests () : UnitTest ("LoadFeeTrack", "ripple") - { - } - - void runTest () + void run () { Config d; // get a default configuration object LoadFeeTrackImp l; - beginTestCase ("fee scaling"); - expect (l.scaleFeeBase (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10000); expect (l.scaleFeeLoad (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false) == 10000); expect (l.scaleFeeBase (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1); @@ -53,5 +51,6 @@ public: } }; +BEAST_DEFINE_TESTSUITE(LoadFeeTrack,ripple_core,ripple); -static LoadFeeTrackTests loadFeeTrackTests; +} // ripple diff --git a/src/ripple_core/functional/LoadFeeTrackImp.h b/src/ripple_core/functional/LoadFeeTrackImp.h index 081cf6936a..deddf24156 100644 --- a/src/ripple_core/functional/LoadFeeTrackImp.h +++ b/src/ripple_core/functional/LoadFeeTrackImp.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LOADFEETRACKIMP_H_INCLUDED #define RIPPLE_LOADFEETRACKIMP_H_INCLUDED +namespace ripple { + class LoadFeeTrackImp : public LoadFeeTrack { public: @@ -228,4 +230,6 @@ private: int raiseCount; }; +} // ripple + #endif diff --git a/src/ripple_core/functional/LoadMonitor.cpp b/src/ripple_core/functional/LoadMonitor.cpp index 21f4aca45e..e81161587a 100644 --- a/src/ripple_core/functional/LoadMonitor.cpp +++ b/src/ripple_core/functional/LoadMonitor.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + /* TODO @@ -216,3 +218,5 @@ LoadMonitor::Stats LoadMonitor::getStats () return stats; } + +} // ripple diff --git a/src/ripple_core/functional/LoadMonitor.h b/src/ripple_core/functional/LoadMonitor.h index 8fe318b4db..c339e5e78f 100644 --- a/src/ripple_core/functional/LoadMonitor.h +++ b/src/ripple_core/functional/LoadMonitor.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LOADMONITOR_H_INCLUDED #define RIPPLE_LOADMONITOR_H_INCLUDED +namespace ripple { + // Monitors load levels and response times // VFALCO TODO Rename this. Having both LoadManager and LoadMonitor is confusing. @@ -72,4 +74,6 @@ private: int mLastUpdate; }; +} // ripple + #endif diff --git a/src/ripple_core/nodestore/tests/BackendTests.cpp b/src/ripple_core/nodestore/tests/BackendTests.cpp index 1e62bc9489..caef6363dc 100644 --- a/src/ripple_core/nodestore/tests/BackendTests.cpp +++ b/src/ripple_core/nodestore/tests/BackendTests.cpp @@ -22,7 +22,7 @@ namespace NodeStore { // Tests the Backend interface // -class BackendTests : public TestBase +class Backend_test : public TestBase { public: void testBackend (beast::String type, beast::int64 const seedValue, @@ -32,7 +32,7 @@ public: DummyScheduler scheduler; - beginTestCase (beast::String ("Backend type=") + type); + testcase ((beast::String ("Backend type=") + type).toStdString()); beast::StringPairArray params; beast::File const path (beast::File::createTempFile ("node_db")); @@ -43,7 +43,7 @@ public: Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); - beast::Journal j ((journal ())); + beast::Journal j; { // Open the backend @@ -86,7 +86,7 @@ public: //-------------------------------------------------------------------------- - void runTest () + void run () { int const seedValue = 50; @@ -104,13 +104,9 @@ public: testBackend ("rocksdb", seedValue); #endif } - - BackendTests () : TestBase ("NodeStoreBackend") - { - } }; -static BackendTests backendTests; +BEAST_DEFINE_TESTSUITE(Backend,ripple_core,ripple); } } diff --git a/src/ripple_core/nodestore/tests/BasicTests.cpp b/src/ripple_core/nodestore/tests/BasicTests.cpp index d6c3394a25..421890d9b5 100644 --- a/src/ripple_core/nodestore/tests/BasicTests.cpp +++ b/src/ripple_core/nodestore/tests/BasicTests.cpp @@ -22,17 +22,13 @@ namespace NodeStore { // Tests predictable batches, and NodeObject blob encoding // -class BasicTests : public TestBase +class NodeStoreBasic_test : public TestBase { public: - BasicTests () : TestBase ("NodeStoreBasics") - { - } - // Make sure predictable object generation works! void testBatches (beast::int64 const seedValue) { - beginTestCase ("batch"); + testcase ("batch"); Batch batch1; createPredictableBatch (batch1, 0, numObjectsToTest, seedValue); @@ -51,7 +47,7 @@ public: // Checks encoding/decoding blobs void testBlobs (beast::int64 const seedValue) { - beginTestCase ("encoding"); + testcase ("encoding"); Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); @@ -74,7 +70,7 @@ public: } } - void runTest () + void run () { beast::int64 const seedValue = 50; @@ -84,7 +80,7 @@ public: } }; -static BasicTests basicTests; +BEAST_DEFINE_TESTSUITE(NodeStoreBasic,ripple_core,ripple); } } diff --git a/src/ripple_core/nodestore/tests/DatabaseTests.cpp b/src/ripple_core/nodestore/tests/DatabaseTests.cpp index 2de3bbdd70..55b42f07bb 100644 --- a/src/ripple_core/nodestore/tests/DatabaseTests.cpp +++ b/src/ripple_core/nodestore/tests/DatabaseTests.cpp @@ -20,20 +20,9 @@ namespace ripple { namespace NodeStore { -class DatabaseTests : public TestBase +class NodeStoreDatabase_test : public TestBase { public: - DatabaseTests () - : TestBase ("NodeStore") - { - } - - ~DatabaseTests () - { - } - - //-------------------------------------------------------------------------- - void testImport (beast::String destBackendType, beast::String srcBackendType, beast::int64 seedValue) { std::unique_ptr manager (make_Manager ()); @@ -49,7 +38,7 @@ public: Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); - beast::Journal j ((journal ())); + beast::Journal j; // Write to source db { @@ -74,7 +63,7 @@ public: std::unique_ptr dest (manager->make_Database ( "test", scheduler, j, 2, destParams)); - beginTestCase (beast::String ("import into '") + destBackendType + "' from '" + srcBackendType + "'"); + testcase ((beast::String ("import into '") + destBackendType + "' from '" + srcBackendType + "'").toStdString()); // Do the import dest->import (*src); @@ -106,7 +95,7 @@ public: if (useEphemeralDatabase) s << " (with ephemeral database)"; - beginTestCase (s); + testcase (s.toStdString()); beast::File const node_db (beast::File::createTempFile ("node_db")); beast::StringPairArray nodeParams; @@ -125,7 +114,7 @@ public: Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); - beast::Journal j ((journal ())); + beast::Journal j; { // Open the database @@ -226,7 +215,7 @@ public: //-------------------------------------------------------------------------- - void runTest () + void run () { beast::int64 const seedValue = 50; @@ -240,7 +229,7 @@ public: } }; -static DatabaseTests databaseTests; +BEAST_DEFINE_TESTSUITE(NodeStoreDatabase,ripple_core,ripple); } } diff --git a/src/ripple_core/nodestore/tests/TestBase.h b/src/ripple_core/nodestore/tests/TestBase.h index 14e61ad1d5..4173b724e8 100644 --- a/src/ripple_core/nodestore/tests/TestBase.h +++ b/src/ripple_core/nodestore/tests/TestBase.h @@ -20,12 +20,14 @@ #ifndef RIPPLE_NODESTORE_TESTBASE_H_INCLUDED #define RIPPLE_NODESTORE_TESTBASE_H_INCLUDED +#include "../../../beast/beast/unit_test/suite.h" + namespace ripple { namespace NodeStore { // Some common code for the unit tests // -class TestBase : public beast::UnitTest +class TestBase : public beast::unit_test::suite { public: // Tunable parameters @@ -181,11 +183,6 @@ public: pCopy->push_back (object); } } - - TestBase (beast::String name, beast::UnitTest::When when = beast::UnitTest::runNormal) - : beast::UnitTest (name, "ripple", when) - { - } }; } diff --git a/src/ripple_core/nodestore/tests/TimingTests.cpp b/src/ripple_core/nodestore/tests/TimingTests.cpp index 634b768be8..321e3b3ff7 100644 --- a/src/ripple_core/nodestore/tests/TimingTests.cpp +++ b/src/ripple_core/nodestore/tests/TimingTests.cpp @@ -20,7 +20,7 @@ namespace ripple { namespace NodeStore { -class TimingTests : public TestBase +class NodeStoreTiming_test : public TestBase { public: enum @@ -28,11 +28,6 @@ public: numObjectsToTest = 10000 }; - TimingTests () - : TestBase ("NodeStoreTiming", UnitTest::runManual) - { - } - class Stopwatch { public: @@ -66,7 +61,7 @@ public: beast::String s; s << "Testing backend '" << type << "' performance"; - beginTestCase (s); + testcase (s.toStdString()); beast::StringPairArray params; beast::File const path (beast::File::createTempFile ("node_db")); @@ -79,7 +74,7 @@ public: NodeStore::Batch batch2; createPredictableBatch (batch2, 0, numObjectsToTest, seedValue); - beast::Journal j ((journal ())); + beast::Journal j; // Open the backend std::unique_ptr backend (manager->make_Backend ( @@ -92,14 +87,14 @@ public: storeBatch (*backend, batch1); s = ""; s << " Single write: " << beast::String (t.getElapsed (), 2) << " seconds"; - logMessage (s); + log << s.toStdString(); // Bulk write batch test t.start (); backend->storeBatch (batch2); s = ""; s << " Batch write: " << beast::String (t.getElapsed (), 2) << " seconds"; - logMessage (s); + log << s.toStdString(); // Read test Batch copy; @@ -108,12 +103,12 @@ public: fetchCopyOfBatch (*backend, ©, batch2); s = ""; s << " Batch read: " << beast::String (t.getElapsed (), 2) << " seconds"; - logMessage (s); + log << s.toStdString(); } //-------------------------------------------------------------------------- - void runTest () + void run () { int const seedValue = 50; @@ -133,7 +128,7 @@ public: } }; -static TimingTests timingTests; +BEAST_DEFINE_TESTSUITE(NodeStoreTiming,ripple_core,ripple); } } diff --git a/src/ripple_core/ripple_core.cpp b/src/ripple_core/ripple_core.cpp index 95fc3d81e0..a954c91663 100644 --- a/src/ripple_core/ripple_core.cpp +++ b/src/ripple_core/ripple_core.cpp @@ -33,13 +33,11 @@ #include "../beast/beast/http/ParsedURL.h" #include "../ripple_net/ripple_net.h" // for HTTPClient -namespace ripple { #include "functional/Config.cpp" # include "functional/LoadFeeTrackImp.h" // private #include "functional/LoadFeeTrackImp.cpp" #include "functional/LoadEvent.cpp" #include "functional/LoadMonitor.cpp" -} #include "functional/Job.cpp" #include "functional/JobQueue.cpp" diff --git a/src/ripple_core/ripple_core.h b/src/ripple_core/ripple_core.h index e4988a3713..b8f6f89fd0 100644 --- a/src/ripple_core/ripple_core.h +++ b/src/ripple_core/ripple_core.h @@ -30,14 +30,11 @@ #include "nodestore/NodeStore.h" -namespace ripple { -// Order matters # include "functional/ConfigSections.h" #include "functional/Config.h" #include "functional/LoadFeeTrack.h" # include "functional/LoadEvent.h" # include "functional/LoadMonitor.h" -} # include "functional/Job.h" #include "functional/JobQueue.h" diff --git a/src/ripple_data/crypto/Base58Data.cpp b/src/ripple_data/crypto/Base58Data.cpp index e8afe2d440..78ef421524 100644 --- a/src/ripple_data/crypto/Base58Data.cpp +++ b/src/ripple_data/crypto/Base58Data.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2011 The Bitcoin Developers // Distributed under the MIT/X11 software license, see the accompanying @@ -145,4 +147,4 @@ std::size_t hash_value (const CBase58Data& b58) return seed; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_data/crypto/Base58Data.h b/src/ripple_data/crypto/Base58Data.h index bd39626ce4..0743a6aefc 100644 --- a/src/ripple_data/crypto/Base58Data.h +++ b/src/ripple_data/crypto/Base58Data.h @@ -32,6 +32,8 @@ #ifndef RIPPLE_BASE58DATA_H #define RIPPLE_BASE58DATA_H +namespace ripple { + class CBase58Data { protected: @@ -64,5 +66,6 @@ public: extern std::size_t hash_value (const CBase58Data& b58); +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_data/crypto/CKey.cpp b/src/ripple_data/crypto/CKey.cpp index 4e2ad62873..da3fca5029 100644 --- a/src/ripple_data/crypto/CKey.cpp +++ b/src/ripple_data/crypto/CKey.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2011 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying @@ -25,17 +29,12 @@ // VFALCO TODO move inlined stuff from CKey into here -class CKeyTests : public beast::UnitTest +class CKey_test : public beast::unit_test::suite { public: - CKeyTests () : UnitTest ("CKey", "ripple") + void + run () { - } - - void runTest () - { - beginTestCase ("determinism"); - uint128 seed1, seed2; seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26"); seed2.SetHex ("CF0C3BE4485961858C4198515AE5B965"); @@ -62,4 +61,7 @@ public: } }; -static CKeyTests cKeyTests; +BEAST_DEFINE_TESTSUITE(CKey,ripple_data,ripple); + +} // ripple + diff --git a/src/ripple_data/crypto/CKey.h b/src/ripple_data/crypto/CKey.h index 93a5888e43..6e18841af1 100644 --- a/src/ripple_data/crypto/CKey.h +++ b/src/ripple_data/crypto/CKey.h @@ -21,9 +21,12 @@ // Copyright (c) 2011 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. + #ifndef RIPPLE_CKEY_H #define RIPPLE_CKEY_H +namespace ripple { + // secp256k1: // const unsigned int PRIVATE_KEY_SIZE = 279; // const unsigned int PUBLIC_KEY_SIZE = 65; // but we don't use full keys @@ -315,5 +318,6 @@ public: Blob decryptECIES (CKey& otherKey, Blob const& ciphertext); }; +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_data/crypto/CKeyDeterministic.cpp b/src/ripple_data/crypto/CKeyDeterministic.cpp index 4043535c95..0253b88152 100644 --- a/src/ripple_data/crypto/CKeyDeterministic.cpp +++ b/src/ripple_data/crypto/CKeyDeterministic.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // #define EC_DEBUG // Functions to add CKey support for deterministic EC keys @@ -359,3 +361,5 @@ EC_KEY* CKey::GeneratePrivateDeterministicKey (const RippleAddress& pubGen, cons return pkey; } + +} // ripple diff --git a/src/ripple_data/crypto/CKeyECIES.cpp b/src/ripple_data/crypto/CKeyECIES.cpp index 588864cd22..a3dc24c4de 100644 --- a/src/ripple_data/crypto/CKeyECIES.cpp +++ b/src/ripple_data/crypto/CKeyECIES.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // ECIES uses elliptic curve keys to send an encrypted message. // A shared secret is generated from one public key and one private key. @@ -326,4 +328,4 @@ bool checkECIES (void) return true; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_data/crypto/RFC1751.cpp b/src/ripple_data/crypto/RFC1751.cpp index 72200d7e7a..b762b901e5 100644 --- a/src/ripple_data/crypto/RFC1751.cpp +++ b/src/ripple_data/crypto/RFC1751.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // // RFC 1751 code converted to C++/Boost. // @@ -492,3 +494,4 @@ beast::String RFC1751::getWordFromBlob (void const* data, size_t bytes) return s_dictionary [hash % (sizeof (s_dictionary) / sizeof (s_dictionary [0]))]; } +} // ripple diff --git a/src/ripple_data/crypto/RFC1751.h b/src/ripple_data/crypto/RFC1751.h index cb235bb898..60c09534c8 100644 --- a/src/ripple_data/crypto/RFC1751.h +++ b/src/ripple_data/crypto/RFC1751.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_RFC1751_H #define RIPPLE_RFC1751_H +namespace ripple { + class RFC1751 { public: @@ -47,4 +49,6 @@ private: static char const* s_dictionary []; }; +} // ripple + #endif diff --git a/src/ripple_data/protocol/BuildInfo.cpp b/src/ripple_data/protocol/BuildInfo.cpp index 44f08d6775..f57e9dd199 100644 --- a/src/ripple_data/protocol/BuildInfo.cpp +++ b/src/ripple_data/protocol/BuildInfo.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + char const* BuildInfo::getRawVersionString () { static char const* const rawText = @@ -158,16 +162,12 @@ std::string BuildInfo::Protocol::toStdString () const noexcept //------------------------------------------------------------------------------ -class BuildInfoTests : public beast::UnitTest +class BuildInfo_test : public beast::unit_test::suite { public: - BuildInfoTests () : beast::UnitTest ("BuildInfo", "ripple", runStartup) - { - } - void testVersion () { - beginTestCase ("version"); + testcase ("version"); beast::SemanticVersion v; @@ -185,7 +185,7 @@ public: { typedef BuildInfo::Protocol P; - beginTestCase ("protocol"); + testcase ("protocol"); expect (P (0, 0).toPacked () == 0); expect (P (0, 1).toPacked () == 1); @@ -202,7 +202,7 @@ public: void testValues () { - beginTestCase ("comparison"); + testcase ("comparison"); typedef BuildInfo::Protocol P; @@ -217,14 +217,18 @@ public: expect (BuildInfo::getCurrentProtocol () >= BuildInfo::getMinimumProtocol ()); } - void runTest () + void run () { testVersion (); testProtocol (); testValues (); - logMessage ("Ripple version: " + BuildInfo::getVersionString()); + log << + " Ripple version: " << + BuildInfo::getVersionString().toStdString(); } }; -static BuildInfoTests buildInfoTests; +BEAST_DEFINE_TESTSUITE(BuildInfo,ripple_data,ripple); + +} // ripple diff --git a/src/ripple_data/protocol/BuildInfo.h b/src/ripple_data/protocol/BuildInfo.h index caaf97a9f1..c20ce34a27 100644 --- a/src/ripple_data/protocol/BuildInfo.h +++ b/src/ripple_data/protocol/BuildInfo.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_BUILDINFO_H_INCLUDED #define RIPPLE_BUILDINFO_H_INCLUDED +namespace ripple { + /** Versioning information for this build. */ struct BuildInfo { @@ -77,10 +79,9 @@ struct BuildInfo /** The oldest protocol version we will accept. */ static Protocol const& getMinimumProtocol (); -private: - friend class BuildInfoTests; - static char const* getRawVersionString (); }; +} // ripple + #endif diff --git a/src/ripple_data/protocol/FieldNames.cpp b/src/ripple_data/protocol/FieldNames.cpp index 6b5cde066c..4fd90705ca 100644 --- a/src/ripple_data/protocol/FieldNames.cpp +++ b/src/ripple_data/protocol/FieldNames.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // These must stay at the top of this file std::map SField::codeToField; int SField::num = 0; @@ -155,4 +157,5 @@ SField::~SField () codeToField.erase (it); } -// vim:ts=4 +} // ripple + diff --git a/src/ripple_data/protocol/FieldNames.h b/src/ripple_data/protocol/FieldNames.h index f0b3f6ccf2..5e78249f0f 100644 --- a/src/ripple_data/protocol/FieldNames.h +++ b/src/ripple_data/protocol/FieldNames.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_FIELDNAMES_H #define RIPPLE_FIELDNAMES_H +namespace ripple { + // VFALCO TODO lose the macro. #define FIELD_CODE(type, index) ((static_cast(type) << 16) | index) @@ -229,4 +231,6 @@ extern SField sfInvalid, sfGeneric, sfLedgerEntry, sfTransaction, sfValidation; #undef FIELD #undef TYPE +} // ripple + #endif diff --git a/src/ripple_data/protocol/HashPrefix.cpp b/src/ripple_data/protocol/HashPrefix.cpp index c37a3167e7..01076ea536 100644 --- a/src/ripple_data/protocol/HashPrefix.cpp +++ b/src/ripple_data/protocol/HashPrefix.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // The prefix codes are part of the Ripple protocol and existing codes cannot be // arbitrarily changed. @@ -29,3 +31,4 @@ HashPrefix const HashPrefix::txSign ('S', 'T', 'X'); HashPrefix const HashPrefix::validation ('V', 'A', 'L'); HashPrefix const HashPrefix::proposal ('P', 'R', 'P'); +} // ripple diff --git a/src/ripple_data/protocol/HashPrefix.h b/src/ripple_data/protocol/HashPrefix.h index 22e30bf852..6e16f3080f 100644 --- a/src/ripple_data/protocol/HashPrefix.h +++ b/src/ripple_data/protocol/HashPrefix.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_HASHPREFIX_H #define RIPPLE_HASHPREFIX_H +namespace ripple { + /** Prefix for hashing functions. These prefixes are inserted before the source material used to generate @@ -84,4 +86,6 @@ public: static HashPrefix const proposal; }; +} // ripple + #endif diff --git a/src/ripple_data/protocol/KnownFormats.h b/src/ripple_data/protocol/KnownFormats.h index 6259304de3..e0990f258e 100644 --- a/src/ripple_data/protocol/KnownFormats.h +++ b/src/ripple_data/protocol/KnownFormats.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_KNOWNFORMATS_H_INCLUDED #define RIPPLE_KNOWNFORMATS_H_INCLUDED +namespace ripple { + /** Manages a list of known formats. Each format has a name, an associated KeyType (typically an enumeration), @@ -182,4 +184,6 @@ private: TypeMap m_types; }; +} // ripple + #endif diff --git a/src/ripple_data/protocol/LedgerFormats.cpp b/src/ripple_data/protocol/LedgerFormats.cpp index 55b6918d05..dadcb6e475 100644 --- a/src/ripple_data/protocol/LedgerFormats.cpp +++ b/src/ripple_data/protocol/LedgerFormats.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + LedgerFormats::LedgerFormats () { add ("AccountRoot", ltACCOUNT_ROOT) @@ -131,3 +133,5 @@ LedgerFormats* LedgerFormats::getInstance () { return beast::SharedSingleton ::getInstance (); } + +} // ripple diff --git a/src/ripple_data/protocol/LedgerFormats.h b/src/ripple_data/protocol/LedgerFormats.h index 629572c64f..0bca7a0a04 100644 --- a/src/ripple_data/protocol/LedgerFormats.h +++ b/src/ripple_data/protocol/LedgerFormats.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERFORMATS_H_INCLUDED #define RIPPLE_LEDGERFORMATS_H_INCLUDED +namespace ripple { + /** Ledger entry types. These are stored in serialized data. @@ -129,5 +131,6 @@ private: void addCommonFields (Item& item); }; -#endif +} // ripple +#endif diff --git a/src/ripple_data/protocol/Protocol.h b/src/ripple_data/protocol/Protocol.h index de2cbfd017..ea4816ba67 100644 --- a/src/ripple_data/protocol/Protocol.h +++ b/src/ripple_data/protocol/Protocol.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_PROTOCOL_H #define RIPPLE_PROTOCOL_H +namespace ripple { + /** Protocol specific constants, types, and data. This information is part of the Ripple protocol. Specifically, @@ -64,4 +66,6 @@ typedef beast::uint32 TxSeq; // VFALCO NOTE Should read TxIndex or TxNum //typedef uint160 AccountHash; //typedef uint260 ValidatorID; +} // ripple + #endif diff --git a/src/ripple_data/protocol/RippleAddress.cpp b/src/ripple_data/protocol/RippleAddress.cpp index 1be6602b73..a267c93f12 100644 --- a/src/ripple_data/protocol/RippleAddress.cpp +++ b/src/ripple_data/protocol/RippleAddress.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + SETUP_LOG (RippleAddress) RippleAddress::RippleAddress () @@ -892,26 +896,20 @@ RippleAddress RippleAddress::createSeedGeneric (const std::string& strText) //------------------------------------------------------------------------------ -class RippleAddressTests : public beast::UnitTest +class RippleAddress_test : public beast::unit_test::suite { public: - RippleAddressTests () : UnitTest ("RippleAddress", "ripple") + void run() { - } - - void runTest () - { - beginTestCase ("public/private"); - // Construct a seed. - RippleAddress naSeed; + RippleAddress naSeed; expect (naSeed.setSeedGeneric ("masterpassphrase")); expect (naSeed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", naSeed.humanSeed ()); // Create node public/private key pair - RippleAddress naNodePublic = RippleAddress::createNodePublic (naSeed); - RippleAddress naNodePrivate = RippleAddress::createNodePrivate (naSeed); + RippleAddress naNodePublic = RippleAddress::createNodePublic (naSeed); + RippleAddress naNodePrivate = RippleAddress::createNodePrivate (naSeed); expect (naNodePublic.humanNodePublic () == "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9", naNodePublic.humanNodePublic ()); expect (naNodePrivate.humanNodePrivate () == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", naNodePrivate.humanNodePrivate ()); @@ -966,21 +964,19 @@ public: } }; -static RippleAddressTests rippleAddressTests; - //------------------------------------------------------------------------------ -class RippleIdentifierTests : public beast::UnitTest +class RippleIdentifier_test : public beast::unit_test::suite { public: - void runTest () + void run () { - beginTestCase ("Seed"); + testcase ("Seed"); RippleAddress seed; expect (seed.setSeedGeneric ("masterpassphrase")); expect (seed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", seed.humanSeed ()); - beginTestCase ("RipplePublicKey"); + testcase ("RipplePublicKey"); RippleAddress deprecatedPublicKey (RippleAddress::createNodePublic (seed)); expect (deprecatedPublicKey.humanNodePublic () == "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9", @@ -989,7 +985,7 @@ public: expect (publicKey.to_string() == deprecatedPublicKey.humanNodePublic(), publicKey.to_string()); - beginTestCase ("RipplePrivateKey"); + testcase ("RipplePrivateKey"); RippleAddress deprecatedPrivateKey (RippleAddress::createNodePrivate (seed)); expect (deprecatedPrivateKey.humanNodePrivate () == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", @@ -998,13 +994,13 @@ public: expect (privateKey.to_string() == deprecatedPrivateKey.humanNodePrivate(), privateKey.to_string()); - beginTestCase ("Generator"); + testcase ("Generator"); RippleAddress generator (RippleAddress::createGeneratorPublic (seed)); expect (generator.humanGenerator () == "fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt", generator.humanGenerator ()); - beginTestCase ("RippleAccountID"); + testcase ("RippleAccountID"); RippleAddress deprecatedAccountPublicKey ( RippleAddress::createAccountPublic (generator, 0)); expect (deprecatedAccountPublicKey.humanAccountID () == @@ -1015,12 +1011,12 @@ public: deprecatedAccountPublicKey.humanAccountID(), accountID.to_string()); - beginTestCase ("RippleAccountPublicKey"); + testcase ("RippleAccountPublicKey"); expect (deprecatedAccountPublicKey.humanAccountPublic () == "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw", deprecatedAccountPublicKey.humanAccountPublic ()); - beginTestCase ("RippleAccountPrivateKey"); + testcase ("RippleAccountPrivateKey"); RippleAddress deprecatedAccountPrivateKey ( RippleAddress::createAccountPrivate (generator, seed, 0)); expect (deprecatedAccountPrivateKey.humanAccountPrivate () == @@ -1031,10 +1027,9 @@ public: deprecatedAccountPrivateKey.humanAccountPrivate(), privateKey.to_string()); } - - RippleIdentifierTests () : beast::UnitTest ("RippleIdentifier", "ripple") - { - } }; -static RippleIdentifierTests rippleIdentifierTests; +BEAST_DEFINE_TESTSUITE(RippleAddress,ripple_data,ripple); +BEAST_DEFINE_TESTSUITE(RippleIdentifier,ripple_data,ripple); + +} // ripple diff --git a/src/ripple_data/protocol/RippleAddress.h b/src/ripple_data/protocol/RippleAddress.h index 7a9822e9e3..33187b239b 100644 --- a/src/ripple_data/protocol/RippleAddress.h +++ b/src/ripple_data/protocol/RippleAddress.h @@ -22,6 +22,8 @@ #include "../ripple/sslutil/api/ECDSACanonical.h" +namespace ripple { + // // Used to hold addresses and parse and produce human formats. // @@ -287,4 +289,6 @@ struct RippleAccountPrivateKeyTraits::assign } }; +} // ripple + #endif diff --git a/src/ripple_data/protocol/RippleSystem.h b/src/ripple_data/protocol/RippleSystem.h index 9b415fac52..78585b6f49 100644 --- a/src/ripple_data/protocol/RippleSystem.h +++ b/src/ripple_data/protocol/RippleSystem.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_RIPPLESYSTEM_H #define RIPPLE_RIPPLESYSTEM_H -/** Protocol specific constant globals. -*/ +namespace ripple { + +/** Protocol specific constant globals. */ // VFALCO NOTE use these from now on instead of the macros!! class RippleSystem { @@ -57,4 +58,6 @@ public: #define SYSTEM_CURRENCY_PRECISION 6 #define SYSTEM_CURRENCY_CODE_RIPPLE "XRR" +} // ripple + #endif diff --git a/src/ripple_data/protocol/STAmount.cpp b/src/ripple_data/protocol/STAmount.cpp index 9dca339c4d..2b9d062635 100644 --- a/src/ripple_data/protocol/STAmount.cpp +++ b/src/ripple_data/protocol/STAmount.cpp @@ -17,9 +17,11 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (STAmount) -beast::uint64 STAmount::uRateOne = STAmount::getRate (STAmount (1), STAmount (1)); +beast::uint64 STAmount::uRateOne = STAmount::getRate (STAmount (1), STAmount (1)); bool STAmount::issuerFromString (uint160& uDstIssuer, const std::string& sIssuer) { @@ -1318,13 +1320,9 @@ Json::Value STAmount::getJson (int) const //------------------------------------------------------------------------------ -class STAmountTests : public beast::UnitTest +class STAmount_test : public beast::unit_test::suite { public: - STAmountTests () : beast::UnitTest ("STAmount", "ripple") - { - } - static STAmount serializeAndDeserialize (const STAmount& s) { Serializer ser; @@ -1415,7 +1413,7 @@ public: void testSetValue () { - beginTestCase ("set value"); + testcase ("set value"); STAmount saTmp; @@ -1440,7 +1438,7 @@ public: void testNativeCurrency () { - beginTestCase ("native currency"); + testcase ("native currency"); STAmount zero, one (1), hundred (100); @@ -1590,7 +1588,7 @@ public: void testCustomCurrency () { - beginTestCase ("custom currency"); + testcase ("custom currency"); STAmount zero (CURRENCY_ONE, ACCOUNT_ONE), one (CURRENCY_ONE, ACCOUNT_ONE, 1), hundred (CURRENCY_ONE, ACCOUNT_ONE, 100); @@ -1776,7 +1774,7 @@ public: void testArithmetic () { - beginTestCase ("arithmetic"); + testcase ("arithmetic"); CBigNum b; @@ -1838,9 +1836,23 @@ public: //-------------------------------------------------------------------------- + template + bool + expect (Cond cond, beast::String const& s) + { + return suite::expect (cond, s.toStdString()); + } + + template + bool + expect (Cond cond) + { + return suite::expect (cond); + } + void testUnderflow () { - beginTestCase ("underflow"); + testcase ("underflow"); STAmount bigNative (STAmount::cMaxNative / 2); STAmount bigValue (CURRENCY_ONE, ACCOUNT_ONE, @@ -1937,7 +1949,7 @@ public: //-------------------------------------------------------------------------- - void runTest () + void run () { testSetValue (); testNativeCurrency (); @@ -1948,4 +1960,6 @@ public: } }; -static STAmountTests stAmountTests; +BEAST_DEFINE_TESTSUITE(STAmount,ripple_data,ripple); + +} // ripple diff --git a/src/ripple_data/protocol/STAmountRound.cpp b/src/ripple_data/protocol/STAmountRound.cpp index 751eee17d5..68d15bf6ab 100644 --- a/src/ripple_data/protocol/STAmountRound.cpp +++ b/src/ripple_data/protocol/STAmountRound.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + void STAmount::canonicalizeRound (bool isNative, beast::uint64& value, int& offset, bool roundUp) { if (!roundUp) // canonicalize already rounds down @@ -311,3 +313,4 @@ STAmount STAmount::divRound (const STAmount& num, const STAmount& den, return STAmount (uCurrencyID, uIssuerID, amount, offset, resultNegative); } +} // ripple diff --git a/src/ripple_data/protocol/STParsedJSON.cpp b/src/ripple_data/protocol/STParsedJSON.cpp index a96fb41598..0987c94273 100644 --- a/src/ripple_data/protocol/STParsedJSON.cpp +++ b/src/ripple_data/protocol/STParsedJSON.cpp @@ -725,4 +725,4 @@ bool STParsedJSON::parse (std::string const& json_name, return true; } -} +} // ripple diff --git a/src/ripple_data/protocol/STParsedJSON.h b/src/ripple_data/protocol/STParsedJSON.h index 218cede18a..0873677184 100644 --- a/src/ripple_data/protocol/STParsedJSON.h +++ b/src/ripple_data/protocol/STParsedJSON.h @@ -79,6 +79,6 @@ private: SField::ref inName, int depth, std::unique_ptr & sub_object); }; -} +} // ripple #endif diff --git a/src/ripple_data/protocol/SerializedObject.cpp b/src/ripple_data/protocol/SerializedObject.cpp index f90f516689..4814d5ebba 100644 --- a/src/ripple_data/protocol/SerializedObject.cpp +++ b/src/ripple_data/protocol/SerializedObject.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (STObject) std::unique_ptr STObject::makeDefaultObject (SerializedTypeID id, SField::ref name) @@ -1253,14 +1255,10 @@ void STArray::sort (bool (*compare) (const STObject&, const STObject&)) //------------------------------------------------------------------------------ -class SerializedObjectTests : public beast::UnitTest +class SerializedObject_test : public beast::unit_test::suite { public: - SerializedObjectTests () : beast::UnitTest ("SerializedObject", "ripple") - { - } - - void runTest () + void run() { testSerialization(); testParseJSONArray(); @@ -1277,7 +1275,7 @@ public: void testParseJSONArrayWithInvalidChildrenObjects () { - beginTestCase ("parse json array invalid children"); + testcase ("parse json array invalid children"); try { /* @@ -1315,7 +1313,7 @@ public: void testParseJSONArray () { - beginTestCase ("parse json array"); + testcase ("parse json array"); std::string const json ("{\"Template\":[{\"ModifiedNode\":{\"Sequence\":1}}]}\n"); Json::Value jsonObject; @@ -1336,7 +1334,7 @@ public: void testSerialization () { - beginTestCase ("serialization"); + testcase ("serialization"); unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful"); @@ -1415,4 +1413,6 @@ public: } }; -static SerializedObjectTests serializedObjectTests; +BEAST_DEFINE_TESTSUITE(SerializedObject,ripple_data,ripple); + +} // ripple diff --git a/src/ripple_data/protocol/SerializedObject.h b/src/ripple_data/protocol/SerializedObject.h index eb904420c7..5a8a29443e 100644 --- a/src/ripple_data/protocol/SerializedObject.h +++ b/src/ripple_data/protocol/SerializedObject.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SERIALIZEDOBJECT_H #define RIPPLE_SERIALIZEDOBJECT_H +namespace ripple { + class STArray; class STObject @@ -518,4 +520,6 @@ inline STArray::iterator range_end (STArray& x) return x.end (); } +} // ripple + #endif diff --git a/src/ripple_data/protocol/SerializedObjectTemplate.cpp b/src/ripple_data/protocol/SerializedObjectTemplate.cpp index 9ee719763d..c5d0fccecf 100644 --- a/src/ripple_data/protocol/SerializedObjectTemplate.cpp +++ b/src/ripple_data/protocol/SerializedObjectTemplate.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SOTemplate::SOTemplate () { } @@ -58,3 +60,5 @@ int SOTemplate::getIndex (SField::ref f) const return mIndex[f.getNum ()]; } + +} // ripple diff --git a/src/ripple_data/protocol/SerializedObjectTemplate.h b/src/ripple_data/protocol/SerializedObjectTemplate.h index 54a645b0c5..aa332c2969 100644 --- a/src/ripple_data/protocol/SerializedObjectTemplate.h +++ b/src/ripple_data/protocol/SerializedObjectTemplate.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_SERIALIZEDOBJECTTEMPLATE_H #define RIPPLE_SERIALIZEDOBJECTTEMPLATE_H -//------------------------------------------------------------------------------ +namespace ripple { /** Flags for elements in a SerializedObjectTemplate. */ @@ -89,4 +89,6 @@ private: std::vector mIndex; // field num -> index }; +} // ripple + #endif diff --git a/src/ripple_data/protocol/SerializedTypes.cpp b/src/ripple_data/protocol/SerializedTypes.cpp index 840ca2cf63..8280bc264b 100644 --- a/src/ripple_data/protocol/SerializedTypes.cpp +++ b/src/ripple_data/protocol/SerializedTypes.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (SerializedType) const STAmount saZero (CURRENCY_ONE, ACCOUNT_ONE, 0); @@ -619,4 +621,5 @@ void STPathSet::add (Serializer& s) const } s.add8 (STPathElement::typeEnd); } -// vim:ts=4 + +} // ripple diff --git a/src/ripple_data/protocol/SerializedTypes.h b/src/ripple_data/protocol/SerializedTypes.h index d0609f5107..4314caae7e 100644 --- a/src/ripple_data/protocol/SerializedTypes.h +++ b/src/ripple_data/protocol/SerializedTypes.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_SERIALIZEDTYPES_H #define RIPPLE_SERIALIZEDTYPES_H +namespace ripple { + // VFALCO TODO fix this restriction on copy assignment. // // CAUTION: Do not create a vector (or similar container) of any object derived from @@ -1656,4 +1658,6 @@ private: static STVector256* construct (SerializerIterator&, SField::ref); }; -#endif +} // ripple + +#endif \ No newline at end of file diff --git a/src/ripple_data/protocol/Serializer.cpp b/src/ripple_data/protocol/Serializer.cpp index 514f4572d1..93f6fc9913 100644 --- a/src/ripple_data/protocol/Serializer.cpp +++ b/src/ripple_data/protocol/Serializer.cpp @@ -17,6 +17,10 @@ */ //============================================================================== +#include "../../beast/beast/unit_test/suite.h" + +namespace ripple { + SETUP_LOG (Serializer) int Serializer::addZeros (size_t uBytes) @@ -684,17 +688,11 @@ Blob SerializerIterator::getRaw (int iLength) //------------------------------------------------------------------------------ -class SerializerTests : public beast::UnitTest +class Serializer_test : public beast::unit_test::suite { public: - SerializerTests () : beast::UnitTest ("Serializer", "ripple") + void run () { - } - - void runTest () - { - beginTestCase ("hash"); - Serializer s1; s1.add32 (3); s1.add256 (uint256 ()); @@ -707,6 +705,6 @@ public: } }; -static SerializerTests serializerTests; - +BEAST_DEFINE_TESTSUITE(Serializer,ripple_data,ripple); +} // ripple diff --git a/src/ripple_data/protocol/Serializer.h b/src/ripple_data/protocol/Serializer.h index 2c02ed771d..23eb9e51e2 100644 --- a/src/ripple_data/protocol/Serializer.h +++ b/src/ripple_data/protocol/Serializer.h @@ -298,7 +298,7 @@ public: Blob getVL (); }; -} +} // ripple #endif diff --git a/src/ripple_data/protocol/TER.cpp b/src/ripple_data/protocol/TER.cpp index e080b6ba8d..1e80220ca6 100644 --- a/src/ripple_data/protocol/TER.cpp +++ b/src/ripple_data/protocol/TER.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + bool transResultInfo (TER terCode, std::string& strToken, std::string& strHuman) { static struct @@ -151,4 +153,4 @@ std::string transHuman (TER terCode) return transResultInfo (terCode, strToken, strHuman) ? strHuman : "-"; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_data/protocol/TER.h b/src/ripple_data/protocol/TER.h index b3fd9fb808..aeb670fbf5 100644 --- a/src/ripple_data/protocol/TER.h +++ b/src/ripple_data/protocol/TER.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TER_H #define RIPPLE_TER_H +namespace ripple { + // VFALCO TODO do not use auto-incrementing. Explicitly assign each // constant so there is no possibility of someone coming in // and screwing it up. @@ -184,5 +186,6 @@ extern bool transResultInfo (TER terCode, std::string& strToken, std::string& st extern std::string transToken (TER terCode); extern std::string transHuman (TER terCode); +} // ripple + #endif -// vim:ts=4 diff --git a/src/ripple_data/protocol/TxFlags.h b/src/ripple_data/protocol/TxFlags.h index d53540b9ae..d9c5713d16 100644 --- a/src/ripple_data/protocol/TxFlags.h +++ b/src/ripple_data/protocol/TxFlags.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TXFLAGS_H #define RIPPLE_TXFLAGS_H +namespace ripple { + // // Transaction flags. // @@ -81,4 +83,6 @@ const beast::uint32 tfSetNoRipple = 0x00020000; const beast::uint32 tfClearNoRipple = 0x00040000; const beast::uint32 tfTrustSetMask = ~ (tfUniversal | tfSetfAuth | tfSetNoRipple | tfClearNoRipple); +} // ripple + #endif diff --git a/src/ripple_data/protocol/TxFormats.cpp b/src/ripple_data/protocol/TxFormats.cpp index 920d1b57c6..b6f26ba65e 100644 --- a/src/ripple_data/protocol/TxFormats.cpp +++ b/src/ripple_data/protocol/TxFormats.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + TxFormats::TxFormats () { add ("AccountSet", ttACCOUNT_SET) @@ -112,3 +114,5 @@ TxFormats* TxFormats::getInstance () //return SharedSingleton ::getInstance (); return &instance; } + +} // ripple diff --git a/src/ripple_data/protocol/TxFormats.h b/src/ripple_data/protocol/TxFormats.h index fdf89d3831..1ea8d1d0c6 100644 --- a/src/ripple_data/protocol/TxFormats.h +++ b/src/ripple_data/protocol/TxFormats.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_TXFORMATS_H_INCLUDED #define RIPPLE_TXFORMATS_H_INCLUDED +namespace ripple { + /** Transaction type identifiers. These are part of the binary message format. @@ -64,4 +66,6 @@ public: static TxFormats* getInstance (); }; +} // ripple + #endif diff --git a/src/ripple_data/ripple_data.cpp b/src/ripple_data/ripple_data.cpp index dc52bbb28e..1e69345213 100644 --- a/src/ripple_data/ripple_data.cpp +++ b/src/ripple_data/ripple_data.cpp @@ -58,9 +58,6 @@ #include "protocol/STParsedJSON.cpp" -namespace ripple -{ - #include "crypto/CKey.h" // needs RippleAddress VFALCO TODO remove this dependency cycle #include "crypto/RFC1751.h" @@ -90,8 +87,6 @@ static const beast::uint64 tenTo17m1 = tenTo17 - 1; #include "protocol/STAmount.cpp" #include "protocol/STAmountRound.cpp" -} - #if BEAST_MSVC #pragma warning (pop) #endif diff --git a/src/ripple_data/ripple_data.h b/src/ripple_data/ripple_data.h index a4b9f4de98..34e55623f0 100644 --- a/src/ripple_data/ripple_data.h +++ b/src/ripple_data/ripple_data.h @@ -27,7 +27,6 @@ struct bignum_st; typedef struct bignum_st BIGNUM; -namespace ripple { #include "crypto/Base58Data.h" #include "crypto/RFC1751.h" #include "protocol/BuildInfo.h" @@ -36,9 +35,7 @@ namespace ripple { #include "protocol/Protocol.h" #include "protocol/RippleAddress.h" #include "protocol/RippleSystem.h" -} #include "protocol/Serializer.h" // needs CKey -namespace ripple { #include "protocol/TER.h" #include "protocol/SerializedTypes.h" // needs Serializer, TER #include "protocol/SerializedObjectTemplate.h" @@ -50,8 +47,6 @@ namespace ripple { #include "utility/UptimeTimerAdapter.h" -} - #include "protocol/STParsedJSON.h" //------------------------------------------------------------------------------ diff --git a/src/ripple_data/utility/UptimeTimerAdapter.h b/src/ripple_data/utility/UptimeTimerAdapter.h index d9ae29a401..738b1bb410 100644 --- a/src/ripple_data/utility/UptimeTimerAdapter.h +++ b/src/ripple_data/utility/UptimeTimerAdapter.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_UPTIMETIMERADAPTER_H #define RIPPLE_UPTIMETIMERADAPTER_H -/** Adapter providing uptime measurements for template classes. -*/ +namespace ripple { + +/** Adapter providing uptime measurements for template classes. */ struct UptimeTimerAdapter { inline static int getElapsedSeconds () @@ -30,4 +31,6 @@ struct UptimeTimerAdapter } }; +} // ripple + #endif diff --git a/src/ripple_net/basics/HTTPClient.cpp b/src/ripple_net/basics/HTTPClient.cpp index f58d1a6003..722700f41b 100644 --- a/src/ripple_net/basics/HTTPClient.cpp +++ b/src/ripple_net/basics/HTTPClient.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // // Fetch a web page via http or https. // @@ -611,3 +613,5 @@ void HTTPClient::sendSMS (boost::asio::io_service& io_service, const std::string } } +} // ripple + diff --git a/src/ripple_net/basics/HTTPClient.h b/src/ripple_net/basics/HTTPClient.h index d9b6ccc1dd..9f056a1c26 100644 --- a/src/ripple_net/basics/HTTPClient.h +++ b/src/ripple_net/basics/HTTPClient.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_BASICS_HTTPCLIENT_H_INCLUDED #define RIPPLE_NET_BASICS_HTTPCLIENT_H_INCLUDED +namespace ripple { + /** Provides an asynchronous HTTP client implementation with optional SSL. */ class HTTPClient @@ -70,4 +72,6 @@ public: static void sendSMS (boost::asio::io_service& io_service, const std::string& strText); }; +} // ripple + #endif diff --git a/src/ripple_net/basics/HTTPRequest.cpp b/src/ripple_net/basics/HTTPRequest.cpp index 36181e8bd5..5c9481dee4 100644 --- a/src/ripple_net/basics/HTTPRequest.cpp +++ b/src/ripple_net/basics/HTTPRequest.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (HTTPRequest) // Logic to handle incoming HTTP reqests @@ -124,4 +126,4 @@ HTTPRequest::Action HTTPRequest::consume (boost::asio::streambuf& buf) return haERROR; } -// vim:ts=4 +} // ripple diff --git a/src/ripple_net/basics/HTTPRequest.h b/src/ripple_net/basics/HTTPRequest.h index 80e8195c28..0feda74239 100644 --- a/src/ripple_net/basics/HTTPRequest.h +++ b/src/ripple_net/basics/HTTPRequest.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_NET_BASICS_HTTPREQUEST_H_INCLUDED #define RIPPLE_NET_BASICS_HTTPREQUEST_H_INCLUDED -/** An HTTP request we are handling from a client. -*/ +namespace ripple { + +/** An HTTP request we are handling from a client. */ class HTTPRequest { public: @@ -100,4 +101,6 @@ private: bool bShouldClose; }; +} + #endif diff --git a/src/ripple_net/basics/RPCDoor.h b/src/ripple_net/basics/RPCDoor.h index e7425e257c..736426653f 100644 --- a/src/ripple_net/basics/RPCDoor.h +++ b/src/ripple_net/basics/RPCDoor.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_BASICS_RPCDOOR_H_INCLUDED #define RIPPLE_NET_BASICS_RPCDOOR_H_INCLUDED +namespace ripple { + /** Listening socket for RPC requests. */ class RPCDoor @@ -30,4 +32,6 @@ public: virtual ~RPCDoor () { } }; +} // ripple + #endif diff --git a/src/ripple_net/basics/RPCServer.h b/src/ripple_net/basics/RPCServer.h index 2557f2c2fe..4e5da3ba43 100644 --- a/src/ripple_net/basics/RPCServer.h +++ b/src/ripple_net/basics/RPCServer.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_BASICS_RPCSERVER_H_INCLUDED #define RIPPLE_NET_BASICS_RPCSERVER_H_INCLUDED +namespace ripple { + /** Provides RPC services to a client. Each client has a separate instance of this object. */ @@ -61,4 +63,6 @@ public: virtual boost::asio::ip::tcp::socket::endpoint_type& getRemoteEndpoint () = 0; }; +} // ripple + #endif diff --git a/src/ripple_net/basics/SNTPClient.cpp b/src/ripple_net/basics/SNTPClient.cpp index ffb1d3fbea..efe9854aa0 100644 --- a/src/ripple_net/basics/SNTPClient.cpp +++ b/src/ripple_net/basics/SNTPClient.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (SNTPClient) // #define SNTP_DEBUG @@ -372,3 +374,5 @@ SNTPClient* SNTPClient::New (Stoppable& parent) { return new SNTPClientImp (parent); } + +} // ripple diff --git a/src/ripple_net/basics/SNTPClient.h b/src/ripple_net/basics/SNTPClient.h index 0794d29b93..451cbf4652 100644 --- a/src/ripple_net/basics/SNTPClient.h +++ b/src/ripple_net/basics/SNTPClient.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_BASICS_SNTPCLIENT_H_INCLUDED #define RIPPLE_NET_BASICS_SNTPCLIENT_H_INCLUDED +namespace ripple { + class SNTPClient : public beast::Stoppable { protected: @@ -34,4 +36,6 @@ public: virtual bool getOffset (int& offset) = 0; }; +} // ripple + #endif diff --git a/src/ripple_net/basics/impl/RPCServerImp.h b/src/ripple_net/basics/impl/RPCServerImp.h index 06c43625d1..1a914c5b39 100644 --- a/src/ripple_net/basics/impl/RPCServerImp.h +++ b/src/ripple_net/basics/impl/RPCServerImp.h @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (RPCServer) class RPCServerImp @@ -256,3 +258,5 @@ private: HTTPRequest mHTTPRequest; }; + +} // ripple diff --git a/src/ripple_net/ripple_net.cpp b/src/ripple_net/ripple_net.cpp index 1750b62424..6c10e40429 100644 --- a/src/ripple_net/ripple_net.cpp +++ b/src/ripple_net/ripple_net.cpp @@ -48,7 +48,6 @@ // #include "../ripple_rpc/api/ErrorCodes.h" -namespace ripple { #include "basics/HTTPRequest.cpp" #include "basics/HTTPClient.cpp" # include "basics/impl/RPCServerImp.h" @@ -58,6 +57,5 @@ namespace ripple { #include "rpc/RPCSub.cpp" #include "rpc/RPCUtil.cpp" #include "rpc/InfoSub.cpp" -} #include "basics/RPCDoor.cpp" diff --git a/src/ripple_net/ripple_net.h b/src/ripple_net/ripple_net.h index 2dccb45364..244eeb2e45 100644 --- a/src/ripple_net/ripple_net.h +++ b/src/ripple_net/ripple_net.h @@ -33,8 +33,6 @@ #include "../ripple_data/ripple_data.h" #include "../ripple_websocket/autosocket/AutoSocket.h" -namespace ripple { - #include "basics/HTTPRequest.h" #include "basics/HTTPClient.h" #include "basics/RPCServer.h" @@ -47,6 +45,4 @@ namespace ripple { # include "rpc/InfoSub.h" #include "rpc/RPCSub.h" -} - #endif diff --git a/src/ripple_net/rpc/InfoSub.cpp b/src/ripple_net/rpc/InfoSub.cpp index 075c97de67..5ada86e2de 100644 --- a/src/ripple_net/rpc/InfoSub.cpp +++ b/src/ripple_net/rpc/InfoSub.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // This is the primary interface into the "client" portion of the program. // Code that wants to do normal operations on the network such as // creating and monitoring accounts, creating transactions, and so on @@ -96,3 +98,5 @@ const boost::shared_ptr& InfoSub::getPathRequest () { return mPathRequest; } + +} // ripple diff --git a/src/ripple_net/rpc/InfoSub.h b/src/ripple_net/rpc/InfoSub.h index ec7886e04a..3602759574 100644 --- a/src/ripple_net/rpc/InfoSub.h +++ b/src/ripple_net/rpc/InfoSub.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_RPC_INFOSUB_H_INCLUDED #define RIPPLE_NET_RPC_INFOSUB_H_INCLUDED +namespace ripple { + // Operations that clients may wish to perform against the network // Master operational handler, server sequencer, network tracker @@ -135,4 +137,6 @@ private: beast::uint64 mSeq; }; +} // ripple + #endif diff --git a/src/ripple_net/rpc/RPCCall.cpp b/src/ripple_net/rpc/RPCCall.cpp index ec2822739d..945c6be623 100644 --- a/src/ripple_net/rpc/RPCCall.cpp +++ b/src/ripple_net/rpc/RPCCall.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + class RPCParser; SETUP_LOG (RPCParser) @@ -1169,3 +1171,5 @@ void RPCCall::fromNetwork ( boost::posix_time::seconds (RPC_NOTIFY_SECONDS), BIND_TYPE (&RPCCallImp::onResponse, callbackFuncP, P_1, P_2, P_3)); } + +} // ripple diff --git a/src/ripple_net/rpc/RPCCall.h b/src/ripple_net/rpc/RPCCall.h index 979e55ca93..3a58eae877 100644 --- a/src/ripple_net/rpc/RPCCall.h +++ b/src/ripple_net/rpc/RPCCall.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_RPC_RPCCALL_H_INCLUDED #define RIPPLE_NET_RPC_RPCCALL_H_INCLUDED +namespace ripple { + // // This a trusted interface, the user is expected to provide valid input to perform valid requests. // Error catching and reporting is not a requirement of this command line interface. @@ -44,4 +46,6 @@ public: std::function callbackFuncP = std::function ()); }; +} // ripple + #endif diff --git a/src/ripple_net/rpc/RPCErr.cpp b/src/ripple_net/rpc/RPCErr.cpp index fa01f544df..910277a6cc 100644 --- a/src/ripple_net/rpc/RPCErr.cpp +++ b/src/ripple_net/rpc/RPCErr.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + struct RPCErr; SETUP_LOG (RPCErr) @@ -46,3 +48,5 @@ Json::Value const& logRPCError (Json::Value const& json) return json; } +} // ripple + diff --git a/src/ripple_net/rpc/RPCErr.h b/src/ripple_net/rpc/RPCErr.h index 59d6c4a87d..ce887b5244 100644 --- a/src/ripple_net/rpc/RPCErr.h +++ b/src/ripple_net/rpc/RPCErr.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_RPC_RPCERR_H_INCLUDED #define RIPPLE_NET_RPC_RPCERR_H_INCLUDED +namespace ripple { + Json::Value const& logRPCError (Json::Value const& json); // VFALCO NOTE these are deprecated @@ -27,4 +29,6 @@ bool isRpcError (Json::Value jvResult); Json::Value rpcError (int iError, Json::Value jvResult = Json::Value (Json::objectValue)); +} // ripple + #endif diff --git a/src/ripple_net/rpc/RPCSub.cpp b/src/ripple_net/rpc/RPCSub.cpp index 4cb2ad221b..6bf198f8dd 100644 --- a/src/ripple_net/rpc/RPCSub.cpp +++ b/src/ripple_net/rpc/RPCSub.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + SETUP_LOG (RPCSub) // Subscription object for JSON-RPC @@ -206,4 +208,6 @@ RPCSub::pointer RPCSub::New (InfoSub::Source& source, return boost::make_shared (boost::ref (source), boost::ref (io_service), boost::ref (jobQueue), strUrl, strUsername, strPassword); -} \ No newline at end of file +} + +} // ripple diff --git a/src/ripple_net/rpc/RPCSub.h b/src/ripple_net/rpc/RPCSub.h index 6cfe49c14c..4690bdee05 100644 --- a/src/ripple_net/rpc/RPCSub.h +++ b/src/ripple_net/rpc/RPCSub.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_RPC_RPCSUB_H_INCLUDED #define RIPPLE_NET_RPC_RPCSUB_H_INCLUDED +namespace ripple { + /** Subscription object for JSON RPC. */ class RPCSub : public InfoSub { @@ -39,4 +41,6 @@ protected: explicit RPCSub (InfoSub::Source& source); }; +} // ripple + #endif diff --git a/src/ripple_net/rpc/RPCUtil.cpp b/src/ripple_net/rpc/RPCUtil.cpp index f037711336..5154546b1b 100644 --- a/src/ripple_net/rpc/RPCUtil.cpp +++ b/src/ripple_net/rpc/RPCUtil.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace ripple { + // Used for logging struct RPCLog; @@ -292,4 +294,5 @@ void ErrorReply (std::ostream& stream, const Json::Value& objError, const Json:: stream << HTTPReply (nStatus, strReply) << std::flush; } -// vim:ts=4 +} // ripple + diff --git a/src/ripple_net/rpc/RPCUtil.h b/src/ripple_net/rpc/RPCUtil.h index 299cfcccb7..b59252ddd2 100644 --- a/src/ripple_net/rpc/RPCUtil.h +++ b/src/ripple_net/rpc/RPCUtil.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_NET_RPC_RPCUTIL_H_INCLUDED #define RIPPLE_NET_RPC_RPCUTIL_H_INCLUDED +namespace ripple { + // VFALCO TODO Wrap these up into a class. It looks like they just do some // convenience packaging of JSON data from the pieces. It looks // Ripple client protocol-specific. @@ -46,4 +48,6 @@ extern int ReadHTTP (std::basic_istream& stream, std::map& mapHeadersRet, std::string& strMessageRet); +} // ripple + #endif diff --git a/src/ripple_rpc/ripple_rpc.cpp b/src/ripple_rpc/ripple_rpc.cpp index 8a511bb6c1..400531faa7 100644 --- a/src/ripple_rpc/ripple_rpc.cpp +++ b/src/ripple_rpc/ripple_rpc.cpp @@ -21,8 +21,6 @@ #include "ripple_rpc.h" -#include "../beast/modules/beast_core/beast_core.h" // for UnitTest - // Unfortunate but necessary since RPC handlers can literally do anything #include "../ripple_app/ripple_app.h"