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