directory_entry.mods.pass.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 directory_entry
  12. // directory_entry& operator=(directory_entry const&) = default;
  13. // directory_entry& operator=(directory_entry&&) noexcept = default;
  14. // void assign(path const&);
  15. // void replace_filename(path const&);
  16. #include "filesystem_include.hpp"
  17. #include <type_traits>
  18. #include <cassert>
  19. void test_copy_assign_operator()
  20. {
  21. using namespace fs;
  22. // Copy
  23. {
  24. static_assert(std::is_copy_assignable<directory_entry>::value,
  25. "directory_entry must be copy assignable");
  26. static_assert(!std::is_nothrow_copy_assignable<directory_entry>::value,
  27. "directory_entry's copy assignment cannot be noexcept");
  28. const path p("foo/bar/baz");
  29. const path p2("abc");
  30. const directory_entry e(p);
  31. directory_entry e2;
  32. assert(e.path() == p && e2.path() == path());
  33. e2 = e;
  34. assert(e.path() == p && e2.path() == p);
  35. directory_entry e3(p2);
  36. e2 = e3;
  37. assert(e2.path() == p2 && e3.path() == p2);
  38. }
  39. }
  40. void test_move_assign_operator()
  41. {
  42. using namespace fs;
  43. // Copy
  44. {
  45. static_assert(std::is_nothrow_move_assignable<directory_entry>::value,
  46. "directory_entry is noexcept move assignable");
  47. const path p("foo/bar/baz");
  48. const path p2("abc");
  49. directory_entry e(p);
  50. directory_entry e2(p2);
  51. assert(e.path() == p && e2.path() == p2);
  52. e2 = std::move(e);
  53. assert(e2.path() == p);
  54. assert(e.path() != p); // testing moved from state
  55. }
  56. }
  57. void test_path_assign_method()
  58. {
  59. using namespace fs;
  60. const path p("foo/bar/baz");
  61. const path p2("abc");
  62. directory_entry e(p);
  63. {
  64. static_assert(std::is_same<decltype(e.assign(p)), void>::value,
  65. "return type should be void");
  66. static_assert(noexcept(e.assign(p)) == false, "operation must not be noexcept");
  67. }
  68. {
  69. assert(e.path() == p);
  70. e.assign(p2);
  71. assert(e.path() == p2 && e.path() != p);
  72. e.assign(p);
  73. assert(e.path() == p && e.path() != p2);
  74. }
  75. }
  76. void test_replace_filename_method()
  77. {
  78. using namespace fs;
  79. const path p("/path/to/foo.exe");
  80. const path replace("bar.out");
  81. const path expect("/path/to/bar.out");
  82. directory_entry e(p);
  83. {
  84. static_assert(noexcept(e.replace_filename(replace)) == false,
  85. "operation cannot be noexcept");
  86. static_assert(std::is_same<decltype(e.replace_filename(replace)), void>::value,
  87. "operation must return void");
  88. }
  89. {
  90. assert(e.path() == p);
  91. e.replace_filename(replace);
  92. assert(e.path() == expect);
  93. }
  94. }
  95. int main() {
  96. test_copy_assign_operator();
  97. test_move_assign_operator();
  98. test_path_assign_method();
  99. test_replace_filename_method();
  100. }