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: aa92b0c88e8dd51afb69a71e9fedb44eddc35928 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* 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"

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;
  // path view has constexpr construction
  constexpr llfio::path_view a, b("hello");
  BOOST_CHECK(a.empty());
  BOOST_CHECK(!b.empty());
  BOOST_CHECK(0 == b.compare<>("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 = e.remove_filename();
  BOOST_CHECK(0 == e.compare<>("/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir"));
  BOOST_CHECK(0 == f.compare<>("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
  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
  llfio::path_view c("path/to"), d(L"path\\to");
  BOOST_CHECK(0 == c.compare<>(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 = g.remove_filename();
  BOOST_CHECK(0 == g.compare<>("\\mnt\\c\\Users\\ned\\Documents\\boostish\\afio\\programs\\build_posix\\testdir"));
  BOOST_CHECK(0 == h.compare<>("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);

  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
}

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