1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03
11
12 // <filesystem>
13
14 // class path
15
16 // template <class Source>
17 // path(const Source& source);
18 // template <class InputIterator>
19 // path(InputIterator first, InputIterator last);
20
21
22 #include "filesystem_include.hpp"
23 #include <type_traits>
24 #include <cassert>
25
26 #include "test_macros.h"
27 #include "test_iterators.h"
28 #include "min_allocator.h"
29 #include "filesystem_test_helper.hpp"
30
31
32 template <class CharT, class ...Args>
RunTestCaseImpl(MultiStringType const & MS,Args...args)33 void RunTestCaseImpl(MultiStringType const& MS, Args... args) {
34 using namespace fs;
35 const char* Expect = MS;
36 const CharT* TestPath = MS;
37 const CharT* TestPathEnd = StrEnd(TestPath);
38 const std::size_t Size = TestPathEnd - TestPath;
39 const std::size_t SSize = StrEnd(Expect) - Expect;
40 assert(Size == SSize);
41 // StringTypes
42 {
43 const std::basic_string<CharT> S(TestPath);
44 path p(S, args...);
45 assert(p.native() == Expect);
46 assert(p.string<CharT>() == TestPath);
47 assert(p.string<CharT>() == S);
48 }
49 {
50 const std::basic_string_view<CharT> S(TestPath);
51 path p(S, args...);
52 assert(p.native() == Expect);
53 assert(p.string<CharT>() == TestPath);
54 assert(p.string<CharT>() == S);
55 }
56 // Char* pointers
57 {
58 path p(TestPath, args...);
59 assert(p.native() == Expect);
60 assert(p.string<CharT>() == TestPath);
61 }
62 {
63 path p(TestPath, TestPathEnd, args...);
64 assert(p.native() == Expect);
65 assert(p.string<CharT>() == TestPath);
66 }
67 // Iterators
68 {
69 using It = input_iterator<const CharT*>;
70 path p(It{TestPath}, args...);
71 assert(p.native() == Expect);
72 assert(p.string<CharT>() == TestPath);
73 }
74 {
75 using It = input_iterator<const CharT*>;
76 path p(It{TestPath}, It{TestPathEnd}, args...);
77 assert(p.native() == Expect);
78 assert(p.string<CharT>() == TestPath);
79 }
80 }
81
82 template <class CharT, class ...Args>
RunTestCase(MultiStringType const & MS)83 void RunTestCase(MultiStringType const& MS) {
84 RunTestCaseImpl<CharT>(MS);
85 RunTestCaseImpl<CharT>(MS, fs::path::format::auto_format);
86 RunTestCaseImpl<CharT>(MS, fs::path::format::native_format);
87 RunTestCaseImpl<CharT>(MS, fs::path::format::generic_format);
88 }
89
test_sfinae()90 void test_sfinae() {
91 using namespace fs;
92 {
93 using It = const char* const;
94 static_assert(std::is_constructible<path, It>::value, "");
95 }
96 {
97 using It = input_iterator<const char*>;
98 static_assert(std::is_constructible<path, It>::value, "");
99 }
100 {
101 struct Traits {
102 using iterator_category = std::input_iterator_tag;
103 using value_type = const char;
104 using pointer = const char*;
105 using reference = const char&;
106 using difference_type = std::ptrdiff_t;
107 };
108 using It = input_iterator<const char*, Traits>;
109 static_assert(std::is_constructible<path, It>::value, "");
110 }
111 {
112 using It = output_iterator<const char*>;
113 static_assert(!std::is_constructible<path, It>::value, "");
114
115 }
116 {
117 static_assert(!std::is_constructible<path, int*>::value, "");
118 }
119 }
120
main()121 int main() {
122 for (auto const& MS : PathList) {
123 RunTestCase<char>(MS);
124 RunTestCase<wchar_t>(MS);
125 RunTestCase<char16_t>(MS);
126 RunTestCase<char32_t>(MS);
127 }
128 test_sfinae();
129 }
130