Welcome to mirror list, hosted at ThFree Co, Russian Federation.

path_view.cpp « tests « test - github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56307985927537327587da5f3cc2504100a0b364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* 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 "../test_kernel_decl.hpp"

static inline void TestPathView()
{
  namespace llfio = LLFIO_V2_NAMESPACE;
  // path view has constexpr construction
  constexpr llfio::path_view a, b("hello");
  BOOST_CHECK(a.empty());
  BOOST_CHECK(!b.empty());
  BOOST_CHECK(b == "hello");
  // Globs
  BOOST_CHECK(llfio::path_view("niall*").contains_glob());
  // Splitting
  constexpr const char p[] = "/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/0";
  llfio::path_view e(p);  // NOLINT
  llfio::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
  llfio::path_view::c_str g(e);
  BOOST_CHECK(g.buffer != p);  // NOLINT
  llfio::path_view::c_str h(f);
  BOOST_CHECK(h.buffer == p + 70);  // NOLINT
#endif

#ifdef _WIN32
  // On Windows, UTF-8 and UTF-16 paths are equivalent and backslash conversion happens
  llfio::path_view c("path/to"), d(L"path\\to");
  BOOST_CHECK(c == d);
  // Globs
  BOOST_CHECK(llfio::path_view(L"niall*").contains_glob());
  BOOST_CHECK(llfio::path_view("0123456789012345678901234567890123456789012345678901234567890123.deleted").is_llfio_deleted());
  BOOST_CHECK(llfio::path_view(L"0123456789012345678901234567890123456789012345678901234567890123.deleted").is_llfio_deleted());
  BOOST_CHECK(!llfio::path_view("0123456789012345678901234567890123456789g12345678901234567890123.deleted").is_llfio_deleted());
  // Splitting
  constexpr const wchar_t p2[] = L"\\mnt\\c\\Users\\ned\\Documents\\boostish\\afio\\programs\\build_posix\\testdir\\0";
  llfio::path_view g(p2);
  llfio::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
  llfio::path_view::c_str i(g, false);
  BOOST_CHECK(i.buffer != p2);
  llfio::path_view::c_str j(g, true);
  BOOST_CHECK(j.buffer == p2);
  llfio::path_view::c_str k(h, false);
  BOOST_CHECK(k.buffer == p2 + 70);
#endif
}

KERNELTEST_TEST_KERNEL(integration, llfio, path_view, path_view, "Tests that llfio::path_view() works as expected", TestPathView())