directory_entry.mods.pass.cpp 3.1 KB

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