path.io.unicode_bug.pass.cpp 1.8 KB

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