diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2016-08-18 22:41:16 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2016-08-18 22:41:16 +0300 |
commit | 4bc8c759d75336b2f59b5a1f30f9dc6871fd731d (patch) | |
tree | 9c725050188af86cf187d940ba7bc636a5de51ec /test | |
parent | 62a9655508ebd66fbc47aabfbc708837dfe685dd (diff) |
Added a proper unit test for the new section_handle, and in so doing found and fixed many bugs.
Diffstat (limited to 'test')
m--------- | test/kerneltest | 0 | ||||
-rw-r--r-- | test/tests/section_handle_create_close/kernel_section_handle.cpp.hpp | 2 | ||||
-rw-r--r-- | test/tests/section_handle_create_close/runner.cpp | 51 |
3 files changed, 42 insertions, 11 deletions
diff --git a/test/kerneltest b/test/kerneltest -Subproject a96c2e797c4cf2d4e292c46d2c2d3d37df9cb6e +Subproject d07a2d2198edf35d2f16b9d9894166e19004ddd diff --git a/test/tests/section_handle_create_close/kernel_section_handle.cpp.hpp b/test/tests/section_handle_create_close/kernel_section_handle.cpp.hpp index 3bf8c91b..50b4d70d 100644 --- a/test/tests/section_handle_create_close/kernel_section_handle.cpp.hpp +++ b/test/tests/section_handle_create_close/kernel_section_handle.cpp.hpp @@ -10,8 +10,6 @@ namespace section_handle_create_close BOOST_AFIO_TEST_KERNEL_DECL boost::outcome::result<boost::afio::section_handle> test_kernel_section_handle(boost::afio::file_handle &backing, boost::afio::section_handle::extent_type maximum_size, boost::afio::section_handle::flag m) { auto h = boost::afio::section_handle::section(backing, maximum_size, m); - if(h) - h.get().close(); return h; } } diff --git a/test/tests/section_handle_create_close/runner.cpp b/test/tests/section_handle_create_close/runner.cpp index dd9bfb33..94f047c6 100644 --- a/test/tests/section_handle_create_close/runner.cpp +++ b/test/tests/section_handle_create_close/runner.cpp @@ -12,25 +12,58 @@ template <class U> inline void section_handle_create_close_(U &&f) using namespace BOOST_AFIO_V2_NAMESPACE; // Create a temporary file and put some text into it - auto temph = file_handle::file("tempfile", file_handle::mode::write, file_handle::creation::if_needed).get(); - temph.write(0, "niall is not here", 17).get(); + file_handle temph; auto boundf = [&](auto... pars) { return f(temph, pars...); }; // clang-format off - static const auto permuter(mt_permute_parameters< + static const auto permuter(st_permute_parameters< result<void>, parameters< typename section_handle::extent_type, typename section_handle::flag >, - precondition::filesystem_setup_parameters + precondition::filesystem_setup_parameters, + postcondition::custom_parameters<bool> >( { - // Does the mode parameter have the expected side effects? - { make_ready_result<void>(), { 1, section_handle::flag::read }, { "_" } }, - }, - precondition::filesystem_setup() - )); + { make_ready_result<void>(),{ 1, section_handle::flag::none },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::read },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::cow },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::execute },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::nocommit },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::prefault },{ "_" },{ false } }, + //{ make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::executable },{ "_" },{ false } }, + + { make_ready_result<void>(),{ 1, section_handle::flag::none },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::read },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::cow },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::execute },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write | section_handle::flag::nocommit },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write | section_handle::flag::prefault },{ "_" },{ true } }, + //{ make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::executable },{ "_" },{ true } }, + }, + precondition::filesystem_setup(), + postcondition::custom( + [&](auto *, auto &testreturn, size_t, int use_file_backing) { + if (use_file_backing) + { + temph = file_handle::file("tempfile", file_handle::mode::write, file_handle::creation::if_needed).get(); + temph.write(0, "niall is not here", 17).get(); + } + else + temph = file_handle(); + return &testreturn; + }, + [&](auto *testreturn) { + // Need to close the section and any backing file as otherwise filesystem_setup won't be able to clear up the working dir + if (*testreturn) + testreturn->get().close(); + temph.close(); + }, + "check section") + )); // clang-format on auto results = permuter(boundf); |