source.pass.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <experimental/filesystem>
  11. // class path
  12. // template <class Source>
  13. // path& operator=(Source const&);
  14. // template <class Source>
  15. // path& assign(Source const&);
  16. // template <class InputIterator>
  17. // path& assign(InputIterator first, InputIterator last);
  18. #include <experimental/filesystem>
  19. #include <type_traits>
  20. #include <cassert>
  21. #include "test_macros.h"
  22. #include "test_iterators.h"
  23. #include "count_new.hpp"
  24. #include "filesystem_test_helper.hpp"
  25. #include <iostream>
  26. namespace fs = std::experimental::filesystem;
  27. template <class CharT>
  28. void RunTestCase(MultiStringType const& MS) {
  29. using namespace fs;
  30. const char* Expect = MS;
  31. const CharT* TestPath = MS;
  32. const CharT* TestPathEnd = StrEnd(TestPath);
  33. const std::size_t Size = TestPathEnd - TestPath;
  34. const std::size_t SSize = StrEnd(Expect) - Expect;
  35. assert(Size == SSize);
  36. //////////////////////////////////////////////////////////////////////////////
  37. // basic_string<Char, Traits, Alloc>
  38. {
  39. const std::basic_string<CharT> S(TestPath);
  40. path p; PathReserve(p, S.length() + 1);
  41. {
  42. // string provides a contigious iterator. No allocation needed.
  43. DisableAllocationGuard g;
  44. path& pref = (p = S);
  45. assert(&pref == &p);
  46. }
  47. assert(p.native() == Expect);
  48. assert(p.string<CharT>() == TestPath);
  49. assert(p.string<CharT>() == S);
  50. }
  51. {
  52. const std::basic_string<CharT> S(TestPath);
  53. path p; PathReserve(p, S.length() + 1);
  54. {
  55. DisableAllocationGuard g;
  56. path& pref = p.assign(S);
  57. assert(&pref == &p);
  58. }
  59. assert(p.native() == Expect);
  60. assert(p.string<CharT>() == TestPath);
  61. assert(p.string<CharT>() == S);
  62. }
  63. //////////////////////////////////////////////////////////////////////////////
  64. // Char* pointers
  65. {
  66. path p; PathReserve(p, Size + 1);
  67. {
  68. // char* pointers are contigious and can be used with code_cvt directly.
  69. // no allocations needed.
  70. DisableAllocationGuard g;
  71. path& pref = (p = TestPath);
  72. assert(&pref == &p);
  73. }
  74. assert(p.native() == Expect);
  75. assert(p.string<CharT>() == TestPath);
  76. }
  77. {
  78. path p; PathReserve(p, Size + 1);
  79. {
  80. DisableAllocationGuard g;
  81. path& pref = p.assign(TestPath);
  82. assert(&pref == &p);
  83. }
  84. assert(p.native() == Expect);
  85. assert(p.string<CharT>() == TestPath);
  86. }
  87. {
  88. path p; PathReserve(p, Size + 1);
  89. {
  90. DisableAllocationGuard g;
  91. path& pref = p.assign(TestPath, TestPathEnd);
  92. assert(&pref == &p);
  93. }
  94. assert(p.native() == Expect);
  95. assert(p.string<CharT>() == TestPath);
  96. }
  97. //////////////////////////////////////////////////////////////////////////////
  98. // Iterators
  99. {
  100. using It = input_iterator<const CharT*>;
  101. path p; PathReserve(p, Size + 1);
  102. It it(TestPath);
  103. {
  104. // Iterators cannot be used with code_cvt directly. This assignment
  105. // may allocate if it's larger than a "short-string".
  106. path& pref = (p = it);
  107. assert(&pref == &p);
  108. }
  109. assert(p.native() == Expect);
  110. assert(p.string<CharT>() == TestPath);
  111. }
  112. {
  113. using It = input_iterator<const CharT*>;
  114. path p; PathReserve(p, Size + 1);
  115. It it(TestPath);
  116. {
  117. path& pref = p.assign(it);
  118. assert(&pref == &p);
  119. }
  120. assert(p.native() == Expect);
  121. assert(p.string<CharT>() == TestPath);
  122. }
  123. {
  124. using It = input_iterator<const CharT*>;
  125. path p; PathReserve(p, Size + 1);
  126. It it(TestPath);
  127. It e(TestPathEnd);
  128. {
  129. path& pref = p.assign(it, e);
  130. assert(&pref == &p);
  131. }
  132. assert(p.native() == Expect);
  133. assert(p.string<CharT>() == TestPath);
  134. }
  135. }
  136. int main() {
  137. for (auto const& MS : PathList) {
  138. RunTestCase<char>(MS);
  139. RunTestCase<wchar_t>(MS);
  140. RunTestCase<char16_t>(MS);
  141. RunTestCase<char32_t>(MS);
  142. }
  143. }