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 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 25 #include "filesystem_include.h" 26 #include <type_traits> 27 #include <cassert> 28 29 #include "../../path_helper.h" 30 #include "make_string.h" 31 #include "min_allocator.h" 32 #include "test_iterators.h" 33 #include "test_macros.h" 34 35 36 template <class CharT, class ...Args> 37 void RunTestCaseImpl(MultiStringType const& MS, Args... args) { 38 using namespace fs; 39 const fs::path::value_type* Expect = MS; 40 const CharT* TestPath = MS; 41 const CharT* TestPathEnd = StrEnd(TestPath); 42 const std::size_t Size = TestPathEnd - TestPath; 43 const std::size_t SSize = StrEnd(Expect) - Expect; 44 assert(Size == SSize); 45 // StringTypes 46 { 47 const std::basic_string<CharT> S(TestPath); 48 path p(S, args...); 49 assert(p.native() == Expect); 50 assert(p.string<CharT>() == TestPath); 51 assert(p.string<CharT>() == S); 52 } 53 { 54 const std::basic_string_view<CharT> S(TestPath); 55 path p(S, args...); 56 assert(p.native() == Expect); 57 assert(p.string<CharT>() == TestPath); 58 assert(p.string<CharT>() == S); 59 } 60 // Char* pointers 61 { 62 path p(TestPath, args...); 63 assert(p.native() == Expect); 64 assert(p.string<CharT>() == TestPath); 65 } 66 { 67 path p(TestPath, TestPathEnd, args...); 68 assert(p.native() == Expect); 69 assert(p.string<CharT>() == TestPath); 70 } 71 // Iterators 72 { 73 using It = cpp17_input_iterator<const CharT*>; 74 path p(It{TestPath}, args...); 75 assert(p.native() == Expect); 76 assert(p.string<CharT>() == TestPath); 77 } 78 { 79 using It = cpp17_input_iterator<const CharT*>; 80 path p(It{TestPath}, It{TestPathEnd}, args...); 81 assert(p.native() == Expect); 82 assert(p.string<CharT>() == TestPath); 83 } 84 } 85 86 template <class CharT, class ...Args> 87 void RunTestCase(MultiStringType const& MS) { 88 RunTestCaseImpl<CharT>(MS); 89 RunTestCaseImpl<CharT>(MS, fs::path::format::auto_format); 90 RunTestCaseImpl<CharT>(MS, fs::path::format::native_format); 91 RunTestCaseImpl<CharT>(MS, fs::path::format::generic_format); 92 RunTestCaseImpl<CharT>(MS, fs::path::auto_format); 93 RunTestCaseImpl<CharT>(MS, fs::path::native_format); 94 RunTestCaseImpl<CharT>(MS, fs::path::generic_format); 95 } 96 97 void test_sfinae() { 98 using namespace fs; 99 { 100 using It = const char* const; 101 static_assert(std::is_constructible<path, It>::value, ""); 102 } 103 { 104 using It = cpp17_input_iterator<const char*>; 105 static_assert(std::is_constructible<path, It>::value, ""); 106 } 107 { 108 struct Traits { 109 using iterator_category = std::input_iterator_tag; 110 using value_type = const char; 111 using pointer = const char*; 112 using reference = const char&; 113 using difference_type = std::ptrdiff_t; 114 }; 115 using It = cpp17_input_iterator<const char*, Traits>; 116 static_assert(std::is_constructible<path, It>::value, ""); 117 } 118 { 119 using It = cpp17_output_iterator<const char*>; 120 static_assert(!std::is_constructible<path, It>::value, ""); 121 122 } 123 { 124 static_assert(!std::is_constructible<path, int*>::value, ""); 125 } 126 } 127 128 int main(int, char**) { 129 for (auto const& MS : PathList) { 130 RunTestCase<char>(MS); 131 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 132 RunTestCase<char8_t>(MS); 133 #endif 134 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 135 RunTestCase<wchar_t>(MS); 136 #endif 137 RunTestCase<char16_t>(MS); 138 RunTestCase<char32_t>(MS); 139 } 140 test_sfinae(); 141 142 return 0; 143 } 144