diff options
Diffstat (limited to 'test/tests')
6 files changed, 216 insertions, 0 deletions
diff --git a/test/tests/path_view.cpp b/test/tests/path_view.cpp index 56307985..5648e8e2 100644 --- a/test/tests/path_view.cpp +++ b/test/tests/path_view.cpp @@ -24,6 +24,32 @@ Distributed under the Boost Software License, Version 1.0. #include "../test_kernel_decl.hpp" +template <class U> inline void CheckPathView(const LLFIO_V2_NAMESPACE::filesystem::path &p, const char *desc, U &&c) +{ + using LLFIO_V2_NAMESPACE::filesystem::path; + using LLFIO_V2_NAMESPACE::path_view; + auto r1 = c(p); + auto r2 = c(path_view(p)); + BOOST_CHECK(r1 == r2); + if(r1 != r2) + { + std::cerr << "For " << desc << " with path " << p << "\n"; + std::cerr << " filesystem::path returned " << r1 << "\n"; + std::cerr << " path_view returned " << r2 << std::endl; + } +} + +static inline void CheckPathView(const LLFIO_V2_NAMESPACE::filesystem::path &path) +{ + CheckPathView(path, "root_directory()", [](const auto &p) { return p.root_directory(); }); + CheckPathView(path, "root_path()", [](const auto &p) { return p.root_path(); }); + CheckPathView(path, "relative_path()", [](const auto &p) { return p.relative_path(); }); + CheckPathView(path, "parent_path()", [](const auto &p) { return p.parent_path(); }); + CheckPathView(path, "filename()", [](const auto &p) { return p.filename(); }); + CheckPathView(path, "stem()", [](const auto &p) { return p.stem(); }); + CheckPathView(path, "extension()", [](const auto &p) { return p.extension(); }); +} + static inline void TestPathView() { namespace llfio = LLFIO_V2_NAMESPACE; @@ -48,6 +74,33 @@ static inline void TestPathView() llfio::path_view::c_str h(f); BOOST_CHECK(h.buffer == p + 70); // NOLINT #endif + CheckPathView("/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir"); +#if 0 + // I think we are standards conforming here, Dinkumware and libstdc++ are not + CheckPathView("/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/"); +#endif + CheckPathView("/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/0"); + CheckPathView("/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/0.txt"); + CheckPathView("boostish/afio/programs/build_posix/testdir"); +#if 0 + // I think we are standards conforming here, Dinkumware and libstdc++ are not + CheckPathView("boostish/afio/programs/build_posix/testdir/"); +#endif + CheckPathView("boostish/afio/programs/build_posix/testdir/0"); + CheckPathView("boostish/afio/programs/build_posix/testdir/0.txt"); + CheckPathView("0"); + CheckPathView("0.txt"); + CheckPathView("0.foo.txt"); + CheckPathView(".0.foo.txt"); +#if 0 + // I think we are standards conforming here, Dinkumware and libstdc++ are not + CheckPathView(".txt"); + CheckPathView("/"); + CheckPathView("//"); +#endif + CheckPathView(""); + CheckPathView("."); + CheckPathView(".."); #ifdef _WIN32 // On Windows, UTF-8 and UTF-16 paths are equivalent and backslash conversion happens @@ -72,6 +125,26 @@ static inline void TestPathView() BOOST_CHECK(j.buffer == p2); llfio::path_view::c_str k(h, false); BOOST_CHECK(k.buffer == p2 + 70); + + CheckPathView(L"\\mnt\\c\\Users\\ned\\Documents\\boostish\\afio\\programs\\build_posix\\testdir\\0"); + CheckPathView(L"C:\\Users\\ned\\Documents\\boostish\\afio\\programs\\build_posix\\testdir\\0"); + CheckPathView("C:/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/0.txt"); + // CheckPathView(L"\\\\niall\\douglas.txt"); + CheckPathView(L"\\!!\\niall\\douglas.txt"); + CheckPathView(L"\\??\\niall\\douglas.txt"); + CheckPathView(L"\\\\?\\niall\\douglas.txt"); + CheckPathView(L"\\\\.\\niall\\douglas.txt"); + + // Handle NT kernel paths correctly + BOOST_CHECK(llfio::path_view(L"\\\\niall").is_absolute()); + BOOST_CHECK(llfio::path_view(L"\\!!\\niall").is_absolute()); + BOOST_CHECK(llfio::path_view(L"\\??\\niall").is_absolute()); + BOOST_CHECK(llfio::path_view(L"\\\\?\\niall").is_absolute()); + BOOST_CHECK(llfio::path_view(L"\\\\.\\niall").is_absolute()); + // On Windows this is relative, on POSIX it is absolute + BOOST_CHECK(llfio::path_view("/niall").is_relative()); +#else + BOOST_CHECK(llfio::path_view("/niall").is_absolute()); #endif } diff --git a/test/tests/symlink_handle_create_close/existing0/testfile.txt b/test/tests/symlink_handle_create_close/existing0/testfile.txt new file mode 100644 index 00000000..e55f0f57 --- /dev/null +++ b/test/tests/symlink_handle_create_close/existing0/testfile.txt @@ -0,0 +1 @@ +niall
\ No newline at end of file diff --git a/test/tests/symlink_handle_create_close/existing1/testfile.txt b/test/tests/symlink_handle_create_close/existing1/testfile.txt new file mode 100644 index 00000000..e55f0f57 --- /dev/null +++ b/test/tests/symlink_handle_create_close/existing1/testfile.txt @@ -0,0 +1 @@ +niall
\ No newline at end of file diff --git a/test/tests/symlink_handle_create_close/existing1/testlink b/test/tests/symlink_handle_create_close/existing1/testlink new file mode 120000 index 00000000..62c74bcb --- /dev/null +++ b/test/tests/symlink_handle_create_close/existing1/testlink @@ -0,0 +1 @@ +testfile.txt
\ No newline at end of file diff --git a/test/tests/symlink_handle_create_close/kernel_symlink_handle.cpp.hpp b/test/tests/symlink_handle_create_close/kernel_symlink_handle.cpp.hpp new file mode 100644 index 00000000..04cb9098 --- /dev/null +++ b/test/tests/symlink_handle_create_close/kernel_symlink_handle.cpp.hpp @@ -0,0 +1,57 @@ +/* Test kernel for symlink_handle create and close +(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (5 commits) +File Created: Jul 2018 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include "../../test_kernel_decl.hpp" + +namespace symlink_handle_create_close +{ + LLFIO_TEST_KERNEL_DECL LLFIO_V2_NAMESPACE::result<LLFIO_V2_NAMESPACE::symlink_handle> test_kernel_symlink_handle_absolute(LLFIO_V2_NAMESPACE::symlink_handle::mode m, LLFIO_V2_NAMESPACE::symlink_handle::creation c, LLFIO_V2_NAMESPACE::symlink_handle::flag f) + { + auto h = LLFIO_V2_NAMESPACE::symlink_handle::symlink({}, "testlink", m, c, f); + if(h) + { + if(h.value().is_writable()) + { + h.value().write("testfile.txt").value(); + } + h.value().close().value(); + } + return h; + } + LLFIO_TEST_KERNEL_DECL LLFIO_V2_NAMESPACE::result<LLFIO_V2_NAMESPACE::symlink_handle> test_kernel_symlink_handle_relative(LLFIO_V2_NAMESPACE::symlink_handle::mode m, LLFIO_V2_NAMESPACE::symlink_handle::creation c, LLFIO_V2_NAMESPACE::symlink_handle::flag f) + { + OUTCOME_TRY(b, LLFIO_V2_NAMESPACE::path_handle::path(".")); + auto h = LLFIO_V2_NAMESPACE::symlink_handle::symlink(b, "testlink", m, c, f); + if(h) + { + if(h.value().is_writable()) + { + h.value().write("testfile.txt").value(); + } + h.value().close().value(); + } + b.close().value(); + return h; + } +} // namespace file_handle_create_close diff --git a/test/tests/symlink_handle_create_close/runner.cpp b/test/tests/symlink_handle_create_close/runner.cpp new file mode 100644 index 00000000..1e14f1a0 --- /dev/null +++ b/test/tests/symlink_handle_create_close/runner.cpp @@ -0,0 +1,83 @@ +/* Integration test kernel for symlink_handle create and close +(C) 2018 Niall Douglas <http://www.nedproductions.biz/> (22 commits) +File Created: Jul 2018 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include "kernel_symlink_handle.cpp.hpp" + +template <class U> inline void symlink_handle_create_close_creation(U &&f) +{ + using namespace KERNELTEST_V1_NAMESPACE; + using LLFIO_V2_NAMESPACE::result; + using symlink_handle = LLFIO_V2_NAMESPACE::symlink_handle; + static const result<void> no_such_file_or_directory = LLFIO_V2_NAMESPACE::errc::no_such_file_or_directory; + static const result<void> file_exists = LLFIO_V2_NAMESPACE::errc::file_exists; + static const result<void> function_not_supported = LLFIO_V2_NAMESPACE::errc::function_not_supported; + static const result<void> permission_denied = LLFIO_V2_NAMESPACE::errc::permission_denied; + + // clang-format off + static const auto permuter(mt_permute_parameters< + result<void>, + parameters< + typename symlink_handle::mode, + typename symlink_handle::creation, + typename symlink_handle::flag + >, + precondition::filesystem_setup_parameters, + postcondition::filesystem_comparison_structure_parameters + >( + { + + // Does the mode parameter have the expected side effects? + { success(), { symlink_handle::mode::none, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success(), { symlink_handle::mode::attr_read, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success(), { symlink_handle::mode::attr_write, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success(), { symlink_handle::mode::write, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing0" }, { "existing1" }}, + { success(), { symlink_handle::mode::write, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { function_not_supported, { symlink_handle::mode::append, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success(), { symlink_handle::mode::none, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing0" }, { "existing1" }}, + { success(), { symlink_handle::mode::attr_read, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing0" }, { "existing1" }}, + { success(), { symlink_handle::mode::attr_write, symlink_handle::creation::if_needed, symlink_handle::flag::none }, { "existing0" }, { "existing1" }}, + + // Does the creation parameter have the expected side effects? + { no_such_file_or_directory, { symlink_handle::mode::write, symlink_handle::creation::open_existing , symlink_handle::flag::none }, { "existing0" }, { "existing0" }}, + { success(), { symlink_handle::mode::write, symlink_handle::creation::open_existing , symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success(), { symlink_handle::mode::write, symlink_handle::creation::only_if_not_exist, symlink_handle::flag::none }, { "existing0" }, { "existing1" }}, + { file_exists, { symlink_handle::mode::write, symlink_handle::creation::only_if_not_exist, symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { success(), { symlink_handle::mode::write, symlink_handle::creation::if_needed , symlink_handle::flag::none }, { "existing0" }, { "existing1" }}, + { success(), { symlink_handle::mode::write, symlink_handle::creation::if_needed , symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + { function_not_supported, { symlink_handle::mode::write, symlink_handle::creation::truncate , symlink_handle::flag::none }, { "existing1" }, { "existing1" }}, + + // Does the flag parameter have the expected side effects? + { success(), { symlink_handle::mode::write, symlink_handle::creation::open_existing, symlink_handle::flag::unlink_on_first_close }, { "existing1" }, { "existing0" }} + }, + precondition::filesystem_setup(), + postcondition::filesystem_comparison_structure() + )); + // clang-format on + + auto results = permuter(std::forward<U>(f)); + check_results_with_boost_test(permuter, results); +} + +KERNELTEST_TEST_KERNEL(unit, llfio, symlink_handle_create_close, symlink_handle, "Tests that llfio::symlink_handle::symlink()'s parameters with absolute paths work as expected", symlink_handle_create_close_creation(symlink_handle_create_close::test_kernel_symlink_handle_absolute)) +KERNELTEST_TEST_KERNEL(unit, llfio, symlink_handle_create_close, symlink_handle, "Tests that llfio::symlink_handle::symlink()'s parameters with relative paths work as expected", symlink_handle_create_close_creation(symlink_handle_create_close::test_kernel_symlink_handle_relative)) |