| 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, c++11, c++14 |
| 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> |
| 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 | namespace fs = std::filesystem; |
| 40 | |
| 41 | MultiStringType InStr = MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789" ); |
| 42 | MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"" ); |
| 43 | |
| 44 | template <class CharT> |
| 45 | void doIOTest() { |
| 46 | using namespace fs; |
| 47 | using Ptr = const CharT*; |
| 48 | using StrStream = std::basic_stringstream<CharT>; |
| 49 | const char* const InCStr = InStr; |
| 50 | const Ptr E = OutStr; |
| 51 | const path p((const char*)InStr); |
| 52 | StrStream ss; |
| 53 | { // test output |
| 54 | auto& ret = (ss << p); |
| 55 | assert(ss.str() == E); |
| 56 | assert(&ret == &ss); |
| 57 | } |
| 58 | { // test input |
| 59 | path p_in; |
| 60 | auto& ret = ss >> p_in; |
| 61 | assert(p_in.native() == (const char*)InStr); |
| 62 | assert(&ret == &ss); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | int main(int, char**) { |
| 68 | doIOTest<char16_t>(); |
| 69 | doIOTest<char32_t>(); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |