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 // <experimental/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 <experimental/filesystem>
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 namespace fs = std::experimental::filesystem;
32
33 template <class CharT>
RunTestCase(MultiStringType const & MS)34 void RunTestCase(MultiStringType const& MS) {
35 using namespace fs;
36 const char* Expect = MS;
37 const CharT* TestPath = MS;
38 const CharT* TestPathEnd = StrEnd(TestPath);
39 const std::size_t Size = TestPathEnd - TestPath;
40 const std::size_t SSize = StrEnd(Expect) - Expect;
41 assert(Size == SSize);
42 // StringTypes
43 {
44 const std::basic_string<CharT> S(TestPath);
45 path p(S);
46 assert(p.native() == Expect);
47 assert(p.string<CharT>() == TestPath);
48 assert(p.string<CharT>() == S);
49 }
50 {
51 const std::basic_string_view<CharT> S(TestPath);
52 path p(S);
53 assert(p.native() == Expect);
54 assert(p.string<CharT>() == TestPath);
55 assert(p.string<CharT>() == S);
56 }
57 // Char* pointers
58 {
59 path p(TestPath);
60 assert(p.native() == Expect);
61 assert(p.string<CharT>() == TestPath);
62 }
63 {
64 path p(TestPath, TestPathEnd);
65 assert(p.native() == Expect);
66 assert(p.string<CharT>() == TestPath);
67 }
68 // Iterators
69 {
70 using It = input_iterator<const CharT*>;
71 path p(It{TestPath});
72 assert(p.native() == Expect);
73 assert(p.string<CharT>() == TestPath);
74 }
75 {
76 using It = input_iterator<const CharT*>;
77 path p(It{TestPath}, It{TestPathEnd});
78 assert(p.native() == Expect);
79 assert(p.string<CharT>() == TestPath);
80 }
81 }
82
test_sfinae()83 void test_sfinae() {
84 using namespace fs;
85 {
86 using It = const char* const;
87 static_assert(std::is_constructible<path, It>::value, "");
88 }
89 {
90 using It = input_iterator<const char*>;
91 static_assert(std::is_constructible<path, It>::value, "");
92 }
93 {
94 struct Traits {
95 using iterator_category = std::input_iterator_tag;
96 using value_type = const char;
97 using pointer = const char*;
98 using reference = const char&;
99 using difference_type = std::ptrdiff_t;
100 };
101 using It = input_iterator<const char*, Traits>;
102 static_assert(std::is_constructible<path, It>::value, "");
103 }
104 {
105 using It = output_iterator<const char*>;
106 static_assert(!std::is_constructible<path, It>::value, "");
107
108 }
109 {
110 static_assert(!std::is_constructible<path, int*>::value, "");
111 }
112 }
113
main()114 int main() {
115 for (auto const& MS : PathList) {
116 RunTestCase<char>(MS);
117 RunTestCase<wchar_t>(MS);
118 RunTestCase<char16_t>(MS);
119 RunTestCase<char32_t>(MS);
120 }
121 test_sfinae();
122 }
123