diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2017-04-08 13:05:12 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2017-04-08 13:05:12 +0300 |
commit | fb6fb35b40877816f063adca44c30d7ce161baa1 (patch) | |
tree | c36b05153e3e0b07dc74b6e9e359dfe40f6def71 /test/tests/file_handle_create_close | |
parent | 369493e64de37ae4d83447e9d705ee3c74c24d56 (diff) |
Test a solution to generic error conditions instead of hard coding errnos
Diffstat (limited to 'test/tests/file_handle_create_close')
-rw-r--r-- | test/tests/file_handle_create_close/runner.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/test/tests/file_handle_create_close/runner.cpp b/test/tests/file_handle_create_close/runner.cpp index ec8ccc83..92123cbc 100644 --- a/test/tests/file_handle_create_close/runner.cpp +++ b/test/tests/file_handle_create_close/runner.cpp @@ -11,6 +11,11 @@ template <class U> inline void file_handle_create_close_creation(U &&f) { using namespace BOOST_KERNELTEST_V1_NAMESPACE; using file_handle = BOOST_AFIO_V2_NAMESPACE::file_handle; + using BOOST_OUTCOME_V1_NAMESPACE::stl11::errc; + static const result<void> success = make_valued_result<void>(); + static const result<void> permission_denied = make_errored_result(errc::permission_denied); + static const result<void> no_such_file_or_directory = make_errored_result(errc::no_such_file_or_directory); + static const result<void> file_exists = make_errored_result(errc::file_exists); /* Set up a permuter which for every one of these parameter values listed, tests with the value using the input workspace which should produce outcome @@ -34,38 +39,38 @@ template <class U> inline void file_handle_create_close_creation(U &&f) { // Initialiser list of output value expected for the input parameters, plus any precondition/postcondition parameters // Does the mode parameter have the expected side effects? - { make_valued_result<void>(), { file_handle::mode::none, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, - { make_valued_result<void>(), { file_handle::mode::attr_read, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, - { make_valued_result<void>(), { file_handle::mode::attr_write, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, - { make_valued_result<void>(), { file_handle::mode::append, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::append, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success, { file_handle::mode::none, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success, { file_handle::mode::attr_read, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success, { file_handle::mode::attr_write, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success, { file_handle::mode::write, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { success, { file_handle::mode::write, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success, { file_handle::mode::append, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { success, { file_handle::mode::append, file_handle::creation::if_needed, file_handle::flag::none }, { "existing1" }, { "existing1" }}, #ifdef _WIN32 // Interestingly Windows lets you create a new file which has no access at all. Go figure. - { make_valued_result<void>(), { file_handle::mode::none, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::attr_read, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::attr_write, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { success, { file_handle::mode::none, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { success, { file_handle::mode::attr_read, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { success, { file_handle::mode::attr_write, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, #else - { make_errored_result<void>(EACCES), { file_handle::mode::none, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, - { make_errored_result<void>(EACCES), { file_handle::mode::attr_read, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, - { make_errored_result<void>(EACCES), { file_handle::mode::attr_write, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, + { permission_denied, { file_handle::mode::none, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, + { permission_denied, { file_handle::mode::attr_read, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, + { permission_denied, { file_handle::mode::attr_write, file_handle::creation::if_needed, file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, #endif // Does the creation parameter have the expected side effects? - { make_errored_result<void>(ENOENT), { file_handle::mode::write, file_handle::creation::open_existing , file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::open_existing , file_handle::flag::none }, { "existing0" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::open_existing , file_handle::flag::none }, { "existing1" }, { "existing1" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::only_if_not_exist, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, - { make_errored_result<void>(EEXIST), { file_handle::mode::write, file_handle::creation::only_if_not_exist, file_handle::flag::none }, { "existing0" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::if_needed , file_handle::flag::none }, { "non-existing" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::if_needed , file_handle::flag::none }, { "existing1" }, { "existing1" }}, - { make_errored_result<void>(ENOENT), { file_handle::mode::write, file_handle::creation::truncate , file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::truncate , file_handle::flag::none }, { "existing0" }, { "existing0" }}, - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::truncate , file_handle::flag::none }, { "existing1" }, { "existing0" }}, + { no_such_file_or_directory, { file_handle::mode::write, file_handle::creation::open_existing , file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, + { success, { file_handle::mode::write, file_handle::creation::open_existing , file_handle::flag::none }, { "existing0" }, { "existing0" }}, + { success, { file_handle::mode::write, file_handle::creation::open_existing , file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success, { file_handle::mode::write, file_handle::creation::only_if_not_exist, file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { file_exists, { file_handle::mode::write, file_handle::creation::only_if_not_exist, file_handle::flag::none }, { "existing0" }, { "existing0" }}, + { success, { file_handle::mode::write, file_handle::creation::if_needed , file_handle::flag::none }, { "non-existing" }, { "existing0" }}, + { success, { file_handle::mode::write, file_handle::creation::if_needed , file_handle::flag::none }, { "existing1" }, { "existing1" }}, + { no_such_file_or_directory, { file_handle::mode::write, file_handle::creation::truncate , file_handle::flag::none }, { "non-existing" }, { "non-existing" }}, + { success, { file_handle::mode::write, file_handle::creation::truncate , file_handle::flag::none }, { "existing0" }, { "existing0" }}, + { success, { file_handle::mode::write, file_handle::creation::truncate , file_handle::flag::none }, { "existing1" }, { "existing0" }}, // Does the flag parameter have the expected side effects? - { make_valued_result<void>(), { file_handle::mode::write, file_handle::creation::open_existing, file_handle::flag::unlink_on_close }, { "existing1" }, { "non-existing" }} + { success, { file_handle::mode::write, file_handle::creation::open_existing, file_handle::flag::unlink_on_close }, { "existing1" }, { "non-existing" }} }, // Any parameters from now on are called before each permutation and the object returned is // destroyed after each permutation. The callspec is (parameter_permuter<...> *parent, outcome<T> &testret, size_t, pars) |