source.pass.cpp 3.4 KB

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