diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index b91e4be582..5e78e760cf 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -240,6 +240,8 @@ + + @@ -1895,6 +1897,8 @@ + + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index cb63157e0f..36d25db9fd 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -543,6 +543,9 @@ extras\beast\unit_test\detail + + extras\beast\unit_test + extras\beast\unit_test @@ -2460,6 +2463,9 @@ ripple\beast\utility + + ripple\beast\utility + ripple\beast\utility\test diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index e56eb8b5e7..362d19f540 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include @@ -201,8 +201,8 @@ static int runUnitTests( std::string const& argument) { using namespace beast::unit_test; - beast::debug_ostream stream; - reporter r (stream); + beast::unit_test::dstream dlog; + reporter r(dlog); r.arg(argument); bool const failed (r.run_each_if ( global_suites(), match_auto (pattern))); diff --git a/src/ripple/beast/nudb/test/beast_nudb_callgrind_test.cpp b/src/ripple/beast/nudb/test/beast_nudb_callgrind_test.cpp index 2ef9c4cc35..0821cc1cb0 100644 --- a/src/ripple/beast/nudb/test/beast_nudb_callgrind_test.cpp +++ b/src/ripple/beast/nudb/test/beast_nudb_callgrind_test.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include #include #include #include @@ -96,9 +96,9 @@ public: N = 100000 }; - testcase (abort_on_fail); + testcase (beast::unit_test::abort_on_fail); - beast::detail::temp_dir tempDir; + beast::temp_dir tempDir; do_test (N, tempDir.path()); } }; diff --git a/src/ripple/beast/nudb/test/beast_nudb_recover_test.cpp b/src/ripple/beast/nudb/test/beast_nudb_recover_test.cpp index b9e7ea00b4..ffa1f3dc6e 100644 --- a/src/ripple/beast/nudb/test/beast_nudb_recover_test.cpp +++ b/src/ripple/beast/nudb/test/beast_nudb_recover_test.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -117,7 +117,7 @@ public: { testcase << count << " inserts"; - beast::detail::temp_dir tempDir; + beast::temp_dir tempDir; auto const path = tempDir.path(); for (std::size_t n = 1;;++n) diff --git a/src/ripple/beast/nudb/test/beast_nudb_store_test.cpp b/src/ripple/beast/nudb/test/beast_nudb_store_test.cpp index f226aed938..aba76fc468 100644 --- a/src/ripple/beast/nudb/test/beast_nudb_store_test.cpp +++ b/src/ripple/beast/nudb/test/beast_nudb_store_test.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include #include #include #include @@ -43,8 +43,8 @@ public: do_test (std::size_t N, std::size_t block_size, float load_factor) { - testcase (abort_on_fail); - beast::detail::temp_dir tempDir; + testcase (beast::unit_test::abort_on_fail); + beast::temp_dir tempDir; auto const dp = tempDir.file ("nudb.dat"); auto const kp = tempDir.file ("nudb.key"); diff --git a/src/ripple/beast/nudb/test/beast_nudb_verify_test.cpp b/src/ripple/beast/nudb/test/beast_nudb_verify_test.cpp index 3f72278d46..a93b3db63a 100644 --- a/src/ripple/beast/nudb/test/beast_nudb_verify_test.cpp +++ b/src/ripple/beast/nudb/test/beast_nudb_verify_test.cpp @@ -242,7 +242,7 @@ public: void run() override { - testcase(abort_on_fail) << "verify " << arg(); + testcase(beast::unit_test::abort_on_fail) << "verify " << arg(); if (arg().empty()) return fail("missing unit test argument"); do_verify(arg()); @@ -270,7 +270,7 @@ public: void run() override { - testcase(abort_on_fail) << "verify_fast " << arg(); + testcase(beast::unit_test::abort_on_fail) << "verify_fast " << arg(); if (arg().empty()) return fail("missing unit test argument"); do_verify(arg()); diff --git a/src/ripple/beast/nudb/test/common.h b/src/ripple/beast/nudb/test/common.h index ce0944df26..9c8ad53049 100644 --- a/src/ripple/beast/nudb/test/common.h +++ b/src/ripple/beast/nudb/test/common.h @@ -209,47 +209,43 @@ num (T t) return s2; } -template +inline void -print (Log log, +print(std::ostream& log, beast::nudb::verify_info const& info) { - log << "avg_fetch: " << std::fixed << std::setprecision(3) << - info.avg_fetch; - log << "waste: " << std::fixed << std::setprecision(3) << - info.waste * 100 << "%"; - log << "overhead: " << std::fixed << std::setprecision(1) << - info.overhead * 100 << "%"; - log << "actual_load: " << std::fixed << std::setprecision(0) << - info.actual_load * 100 << "%"; - log << "version: " << num(info.version); - log << "uid: " << std::showbase << std::hex << info.uid; - log << "appnum: " << info.appnum; - log << "key_size: " << num(info.key_size); - log << "salt: " << std::showbase << std::hex << info.salt; - log << "pepper: " << std::showbase << std::hex << info.pepper; - log << "block_size: " << num(info.block_size); - log << "bucket_size: " << num(info.bucket_size); - log << "load_factor: " << std::fixed << std::setprecision(0) << - info.load_factor * 100 << "%"; - log << "capacity: " << num(info.capacity); - log << "buckets: " << num(info.buckets); - log << "key_count: " << num(info.key_count); - log << "value_count: " << num(info.value_count); - log << "value_bytes: " << num(info.value_bytes); - log << "spill_count: " << num(info.spill_count); - log << "spill_count_tot: " << num(info.spill_count_tot); - log << "spill_bytes: " << num(info.spill_bytes); - log << "spill_bytes_tot: " << num(info.spill_bytes_tot); - log << "key_file_size: " << num(info.key_file_size); - log << "dat_file_size: " << num(info.dat_file_size); + log << + "avg_fetch: " << std::fixed << std::setprecision(3) << info.avg_fetch << '\n' << + "waste: " << std::fixed << std::setprecision(3) << info.waste * 100 << "%\n" << + "overhead: " << std::fixed << std::setprecision(1) << info.overhead * 100 << "%\n" << + "actual_load: " << std::fixed << std::setprecision(0) << info.actual_load * 100 << "%\n" << + "version: " << num(info.version) << '\n' << + "uid: " << std::showbase << std::hex << info.uid << '\n' << + "appnum: " << info.appnum << '\n' << + "key_size: " << num(info.key_size) << '\n' << + "salt: " << std::showbase << std::hex << info.salt << '\n' << + "pepper: " << std::showbase << std::hex << info.pepper << '\n' << + "block_size: " << num(info.block_size) << '\n' << + "bucket_size: " << num(info.bucket_size) << '\n' << + "load_factor: " << std::fixed << std::setprecision(0) << info.load_factor * 100 << "%\n" << + "capacity: " << num(info.capacity) << '\n' << + "buckets: " << num(info.buckets) << '\n' << + "key_count: " << num(info.key_count) << '\n' << + "value_count: " << num(info.value_count) << '\n' << + "value_bytes: " << num(info.value_bytes) << '\n' << + "spill_count: " << num(info.spill_count) << '\n' << + "spill_count_tot: " << num(info.spill_count_tot) << '\n' << + "spill_bytes: " << num(info.spill_bytes) << '\n' << + "spill_bytes_tot: " << num(info.spill_bytes_tot) << '\n' << + "key_file_size: " << num(info.key_file_size) << '\n' << + "dat_file_size: " << num(info.dat_file_size) << std::endl; std::string s; for (int i = 0; i < info.hist.size(); ++i) s += (i==0) ? std::to_string(info.hist[i]) : (", " + std::to_string(info.hist[i])); - log << "hist: " << s; + log << "hist: " << s << std::endl; } } // test diff --git a/src/ripple/beast/unit_test.h b/src/ripple/beast/unit_test.h index 06b02c9bba..099c3c0d84 100644 --- a/src/ripple/beast/unit_test.h +++ b/src/ripple/beast/unit_test.h @@ -21,7 +21,6 @@ #define BEAST_UNIT_TEST_H_INCLUDED #include -#include #include #include #include diff --git a/src/ripple/beast/utility/temp_dir.h b/src/ripple/beast/utility/temp_dir.h new file mode 100644 index 0000000000..2dfdf6aba6 --- /dev/null +++ b/src/ripple/beast/utility/temp_dir.h @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +/* + 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_UTILITY_TEMP_DIR_H_INCLUDED +#define BEAST_UTILITY_TEMP_DIR_H_INCLUDED + +#include +#include + +namespace beast { + +/** RAII temporary directory. + + The directory and all its contents are deleted when + the instance of `temp_dir` is destroyed. +*/ +class temp_dir +{ + boost::filesystem::path path_; + +public: +#if ! GENERATING_DOCS + temp_dir(const temp_dir&) = delete; + temp_dir& operator=(const temp_dir&) = delete; +#endif + + /// Construct a temporary directory. + temp_dir() + { + auto const dir = + boost::filesystem::temp_directory_path(); + do + { + path_ = + dir / boost::filesystem::unique_path(); + } + while(boost::filesystem::exists(path_)); + boost::filesystem::create_directory (path_); + } + + /// Destroy a temporary directory. + ~temp_dir() + { + boost::filesystem::remove_all (path_); + } + + /// Get the native path for the temporary directory + std::string + path() const + { + return path_.string(); + } + + /** Get the native path for the a file. + + The file does not need to exist. + */ + std::string + file(std::string const& name) const + { + return (path_ / name).string(); + } +}; + +} // beast + +#endif \ No newline at end of file diff --git a/src/ripple/nodestore/tests/Backend.test.cpp b/src/ripple/nodestore/tests/Backend.test.cpp index d639413c32..18c9763311 100644 --- a/src/ripple/nodestore/tests/Backend.test.cpp +++ b/src/ripple/nodestore/tests/Backend.test.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include namespace ripple { @@ -42,7 +42,7 @@ public: testcase ("Backend type=" + type); Section params; - beast::detail::temp_dir tempDir; + beast::temp_dir tempDir; params.set ("type", type); params.set ("path", tempDir.path()); diff --git a/src/ripple/nodestore/tests/Database.test.cpp b/src/ripple/nodestore/tests/Database.test.cpp index 7772814143..3fa14a9687 100644 --- a/src/ripple/nodestore/tests/Database.test.cpp +++ b/src/ripple/nodestore/tests/Database.test.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include namespace ripple { @@ -35,7 +35,7 @@ public: { DummyScheduler scheduler; - beast::detail::temp_dir node_db; + beast::temp_dir node_db; Section srcParams; srcParams.set ("type", srcBackendType); srcParams.set ("path", node_db.path()); @@ -61,7 +61,7 @@ public: "test", scheduler, j, 2, srcParams); // Set up the destination database - beast::detail::temp_dir dest_db; + beast::temp_dir dest_db; Section destParams; destParams.set ("type", destBackendType); destParams.set ("path", dest_db.path()); @@ -98,7 +98,7 @@ public: testcase (s); - beast::detail::temp_dir node_db; + beast::temp_dir node_db; Section nodeParams; nodeParams.set ("type", type); nodeParams.set ("path", node_db.path()); diff --git a/src/ripple/nodestore/tests/Timing.test.cpp b/src/ripple/nodestore/tests/Timing.test.cpp index d70a488bbd..76a8977144 100644 --- a/src/ripple/nodestore/tests/Timing.test.cpp +++ b/src/ripple/nodestore/tests/Timing.test.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -679,7 +679,7 @@ public: params.threads = threads; for (auto i = default_repeat; i--;) { - beast::detail::temp_dir tempDir; + beast::temp_dir tempDir; Section config = parse(config_string); config.set ("path", tempDir.path()); std::stringstream ss; @@ -697,7 +697,7 @@ public: void run() override { - testcase ("Timing", suite::abort_on_fail); + testcase ("Timing", beast::unit_test::abort_on_fail); /* Parameters: diff --git a/src/ripple/nodestore/tests/import_test.cpp b/src/ripple/nodestore/tests/import_test.cpp index 3ad1c1715d..a1a988bb1d 100644 --- a/src/ripple/nodestore/tests/import_test.cpp +++ b/src/ripple/nodestore/tests/import_test.cpp @@ -301,7 +301,7 @@ public: void run() override { - testcase(abort_on_fail) << arg(); + testcase(beast::unit_test::abort_on_fail) << arg(); using namespace beast::nudb; using namespace beast::nudb::detail; @@ -573,7 +573,7 @@ public: void run() override { - testcase(abort_on_fail) << arg(); + testcase(beast::unit_test::abort_on_fail) << arg(); using namespace beast::nudb; using namespace beast::nudb::detail;