| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
// UNSUPPORTED: availability-filesystem-missing |
| 11 |
|
| 12 |
// These tests require locale for non-char paths |
| 13 |
// UNSUPPORTED: no-localization |
| 14 |
|
| 15 |
// <filesystem> |
| 16 |
|
| 17 |
// class path |
| 18 |
|
| 19 |
// template <class Source> |
| 20 |
// path(const Source& source); |
| 21 |
// template <class InputIterator> |
| 22 |
// path(InputIterator first, InputIterator last); |
| 23 |
|
| 24 |
#include <filesystem> |
| 25 |
#include <type_traits> |
| 26 |
#include <cassert> |
| 27 |
|
| 28 |
#include "../../path_helper.h" |
| 29 |
#include "make_string.h" |
| 30 |
#include "min_allocator.h" |
| 31 |
#include "test_iterators.h" |
| 32 |
#include "test_macros.h" |
| 33 |
namespace fs = std::filesystem; |
| 34 |
|
| 35 |
template <class CharT, class ...Args> |
| 36 |
void RunTestCaseImpl(MultiStringType const& MS, Args... args) { |
| 37 |
using namespace fs; |
| 38 |
const fs::path::value_type* Expect = MS; |
| 39 |
const CharT* TestPath = MS; |
| 40 |
const CharT* TestPathEnd = StrEnd(TestPath); |
| 41 |
const std::size_t Size = TestPathEnd - TestPath; |
| 42 |
const std::size_t SSize = StrEnd(Expect) - Expect; |
| 43 |
assert(Size == SSize); |
| 44 |
// StringTypes |
| 45 |
{ |
| 46 |
const std::basic_string<CharT> S(TestPath); |
| 47 |
path p(S, args...); |
| 48 |
assert(p.native() == Expect); |
| 49 |
assert(p.string<CharT>() == TestPath); |
| 50 |
assert(p.string<CharT>() == S); |
| 51 |
} |
| 52 |
{ |
| 53 |
const std::basic_string_view<CharT> S(TestPath); |
| 54 |
path p(S, args...); |
| 55 |
assert(p.native() == Expect); |
| 56 |
assert(p.string<CharT>() == TestPath); |
| 57 |
assert(p.string<CharT>() == S); |
| 58 |
} |
| 59 |
// Char* pointers |
| 60 |
{ |
| 61 |
path p(TestPath, args...); |
| 62 |
assert(p.native() == Expect); |
| 63 |
assert(p.string<CharT>() == TestPath); |
| 64 |
} |
| 65 |
{ |
| 66 |
path p(TestPath, TestPathEnd, args...); |
| 67 |
assert(p.native() == Expect); |
| 68 |
assert(p.string<CharT>() == TestPath); |
| 69 |
} |
| 70 |
// Iterators |
| 71 |
{ |
| 72 |
using It = cpp17_input_iterator<const CharT*>; |
| 73 |
path p(It{TestPath}, args...); |
| 74 |
assert(p.native() == Expect); |
| 75 |
assert(p.string<CharT>() == TestPath); |
| 76 |
} |
| 77 |
{ |
| 78 |
using It = cpp17_input_iterator<const CharT*>; |
| 79 |
path p(It{TestPath}, It{TestPathEnd}, args...); |
| 80 |
assert(p.native() == Expect); |
| 81 |
assert(p.string<CharT>() == TestPath); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
template <class CharT, class ...Args> |
| 86 |
void RunTestCase(MultiStringType const& MS) { |
| 87 |
RunTestCaseImpl<CharT>(MS); |
| 88 |
RunTestCaseImpl<CharT>(MS, fs::path::format::auto_format); |
| 89 |
RunTestCaseImpl<CharT>(MS, fs::path::format::native_format); |
| 90 |
RunTestCaseImpl<CharT>(MS, fs::path::format::generic_format); |
| 91 |
RunTestCaseImpl<CharT>(MS, fs::path::auto_format); |
| 92 |
RunTestCaseImpl<CharT>(MS, fs::path::native_format); |
| 93 |
RunTestCaseImpl<CharT>(MS, fs::path::generic_format); |
| 94 |
} |
| 95 |
|
| 96 |
void test_sfinae() { |
| 97 |
using namespace fs; |
| 98 |
{ |
| 99 |
using It = const char* const; |
| 100 |
static_assert(std::is_constructible<path, It>::value, ""); |
| 101 |
} |
| 102 |
{ |
| 103 |
using It = cpp17_input_iterator<const char*>; |
| 104 |
static_assert(std::is_constructible<path, It>::value, ""); |
| 105 |
} |
| 106 |
{ |
| 107 |
struct Traits { |
| 108 |
using iterator_category = std::input_iterator_tag; |
| 109 |
using value_type = const char; |
| 110 |
using pointer = const char*; |
| 111 |
using reference = const char&; |
| 112 |
using difference_type = std::ptrdiff_t; |
| 113 |
}; |
| 114 |
using It = cpp17_input_iterator<const char*, Traits>; |
| 115 |
static_assert(std::is_constructible<path, It>::value, ""); |
| 116 |
} |
| 117 |
{ |
| 118 |
using It = cpp17_output_iterator<const char*>; |
| 119 |
static_assert(!std::is_constructible<path, It>::value, ""); |
| 120 |
|
| 121 |
} |
| 122 |
{ |
| 123 |
static_assert(!std::is_constructible<path, int*>::value, ""); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
int main(int, char**) { |
| 128 |
for (auto const& MS : PathList) { |
| 129 |
RunTestCase<char>(MS); |
| 130 |
#if TEST_STD_VER > 17 && defined(__cpp_char8_t) |
| 131 |
RunTestCase<char8_t>(MS); |
| 132 |
#endif |
| 133 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 134 |
RunTestCase<wchar_t>(MS); |
| 135 |
#endif |
| 136 |
RunTestCase<char16_t>(MS); |
| 137 |
RunTestCase<char32_t>(MS); |
| 138 |
} |
| 139 |
test_sfinae(); |
| 140 |
|
| 141 |
return 0; |
| 142 |
} |