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 // UNSUPPORTED: availability-filesystem-missing
11 
12 // <filesystem>
13 
14 // class path
15 
16 // template <class charT, class traits>
17 // basic_ostream<charT, traits>&
18 // operator<<(basic_ostream<charT, traits>& os, const path& p);
19 //
20 // template <class charT, class traits>
21 // basic_istream<charT, traits>&
22 // operator>>(basic_istream<charT, traits>& is, path& p)
23 //
24 
25 // TODO(EricWF) This test fails because "std::quoted" fails to compile
26 // for char16_t and char32_t types. Combine with path.io.pass.cpp when this
27 // passes.
28 // XFAIL: *
29 
30 #include "filesystem_include.h"
31 #include <type_traits>
32 #include <sstream>
33 #include <cassert>
34 
35 #include "test_macros.h"
36 #include "test_iterators.h"
37 #include "count_new.h"
38 #include "filesystem_test_helper.h"
39 
40 MultiStringType InStr =  MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789");
41 MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"");
42 
43 template <class CharT>
44 void doIOTest() {
45   using namespace fs;
46   using Ptr = const CharT*;
47   using StrStream = std::basic_stringstream<CharT>;
48   const char* const InCStr = InStr;
49   const Ptr E = OutStr;
50   const path p((const char*)InStr);
51   StrStream ss;
52   { // test output
53     auto& ret = (ss << p);
54     assert(ss.str() == E);
55     assert(&ret == &ss);
56   }
57   { // test input
58     path p_in;
59     auto& ret = ss >> p_in;
60     assert(p_in.native() == (const char*)InStr);
61     assert(&ret == &ss);
62   }
63 }
64 
65 
66 int main(int, char**) {
67   doIOTest<char16_t>();
68   doIOTest<char32_t>();
69 
70   return 0;
71 }
72