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: 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 = cpp17_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 = cpp17_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 RunTestCaseImpl<CharT>(MS, fs::path::auto_format); 91 RunTestCaseImpl<CharT>(MS, fs::path::native_format); 92 RunTestCaseImpl<CharT>(MS, fs::path::generic_format); 93 } 94 95 void test_sfinae() { 96 using namespace fs; 97 { 98 using It = const char* const; 99 static_assert(std::is_constructible<path, It>::value, ""); 100 } 101 { 102 using It = cpp17_input_iterator<const char*>; 103 static_assert(std::is_constructible<path, It>::value, ""); 104 } 105 { 106 struct Traits { 107 using iterator_category = std::input_iterator_tag; 108 using value_type = const char; 109 using pointer = const char*; 110 using reference = const char&; 111 using difference_type = std::ptrdiff_t; 112 }; 113 using It = cpp17_input_iterator<const char*, Traits>; 114 static_assert(std::is_constructible<path, It>::value, ""); 115 } 116 { 117 using It = cpp17_output_iterator<const char*>; 118 static_assert(!std::is_constructible<path, It>::value, ""); 119 120 } 121 { 122 static_assert(!std::is_constructible<path, int*>::value, ""); 123 } 124 } 125 126 int main(int, char**) { 127 for (auto const& MS : PathList) { 128 RunTestCase<char>(MS); 129 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 130 RunTestCase<char8_t>(MS); 131 #endif 132 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 133 RunTestCase<wchar_t>(MS); 134 #endif 135 RunTestCase<char16_t>(MS); 136 RunTestCase<char32_t>(MS); 137 } 138 test_sfinae(); 139 140 return 0; 141 } 142