diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2017-08-27 02:16:07 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2017-08-27 02:16:07 +0300 |
commit | 5a8179a1f1ddf7c7a14a5f6836973505e8fa406f (patch) | |
tree | f4b9020b4daf48b273de62902d3d3441aeb63369 /test/tests/path_view.cpp | |
parent | 23e64e78da06177168db0a86539769fdfd2441dc (diff) |
Added unit test for path_view.
Diffstat (limited to 'test/tests/path_view.cpp')
-rw-r--r-- | test/tests/path_view.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/tests/path_view.cpp b/test/tests/path_view.cpp new file mode 100644 index 00000000..51120db8 --- /dev/null +++ b/test/tests/path_view.cpp @@ -0,0 +1,79 @@ +/* Integration test kernel for whether path views work +(C) 2017 Niall Douglas <http://www.nedproductions.biz/> (2 commits) +File Created: Aug 2017 + + +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 "../../include/afio/afio.hpp" +#include "kerneltest/include/kerneltest.hpp" + +static inline void TestPathView() +{ + namespace afio = AFIO_V2_NAMESPACE; + // path view has constexpr construction + constexpr afio::path_view a, b("hello"); + BOOST_CHECK(a.empty()); + BOOST_CHECK(!b.empty()); + BOOST_CHECK(b == "hello"); + // Globs + BOOST_CHECK(afio::path_view("niall*").contains_glob()); + // Splitting + constexpr const char p[] = "/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/0"; + afio::path_view e(p); + afio::path_view f(e.filename()); + e.remove_filename(); + BOOST_CHECK(e == "/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir"); + BOOST_CHECK(f == "0"); +#ifndef _WIN32 + // cstr + afio::path_view::c_str g(e); + BOOST_CHECK(g.buffer != p); + afio::path_view::c_str h(f); + BOOST_CHECK(g.buffer == p + 70); +#endif + +#ifdef _WIN32 + // On Windows, UTF-8 and UTF-16 paths are equivalent and backslash conversion happens + afio::path_view c("path/to"), d(L"path\\to"); + BOOST_CHECK(c == d); + // Globs + BOOST_CHECK(afio::path_view(L"niall*").contains_glob()); + BOOST_CHECK(afio::path_view("0123456789012345678901234567890123456789012345678901234567890123.deleted").is_afio_deleted()); + BOOST_CHECK(afio::path_view(L"0123456789012345678901234567890123456789012345678901234567890123.deleted").is_afio_deleted()); + BOOST_CHECK(!afio::path_view("0123456789012345678901234567890123456789g12345678901234567890123.deleted").is_afio_deleted()); + // Splitting + constexpr const wchar_t p2[] = L"\\mnt\\c\\Users\\ned\\Documents\\boostish\\afio\\programs\\build_posix\\testdir\\0"; + afio::path_view g(p2); + afio::path_view h(g.filename()); + g.remove_filename(); + BOOST_CHECK(g == "\\mnt\\c\\Users\\ned\\Documents\\boostish\\afio\\programs\\build_posix\\testdir"); + BOOST_CHECK(h == "0"); + // cstr + afio::path_view::c_str i(g, false); + BOOST_CHECK(i.buffer != p2); + afio::path_view::c_str j(g, true); + BOOST_CHECK(j.buffer == p2); + afio::path_view::c_str k(h, false); + BOOST_CHECK(k.buffer == p2 + 70); +#endif +} + +KERNELTEST_TEST_KERNEL(integration, afio, path_view, path_view, "Tests that afio::path_view() works as expected", TestPathView()) |