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