directory_entry.cons.pass.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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() noexcept = default;
  13. // directory_entry(const directory_entry&) = default;
  14. // directory_entry(directory_entry&&) noexcept = default;
  15. // explicit directory_entry(const path);
  16. #include <experimental/filesystem>
  17. #include <type_traits>
  18. #include <cassert>
  19. namespace fs = std::experimental::filesystem;
  20. void test_default_ctor()
  21. {
  22. using namespace fs;
  23. // Default
  24. {
  25. static_assert(std::is_nothrow_default_constructible<directory_entry>::value,
  26. "directory_entry must have a nothrow default constructor");
  27. directory_entry e;
  28. assert(e.path() == path());
  29. }
  30. }
  31. void test_copy_ctor()
  32. {
  33. using namespace fs;
  34. // Copy
  35. {
  36. static_assert(std::is_copy_constructible<directory_entry>::value,
  37. "directory_entry must be copy constructible");
  38. static_assert(!std::is_nothrow_copy_constructible<directory_entry>::value,
  39. "directory_entry's copy constructor cannot be noexcept");
  40. const path p("foo/bar/baz");
  41. const directory_entry e(p);
  42. assert(e.path() == p);
  43. directory_entry e2(e);
  44. assert(e.path() == p);
  45. assert(e2.path() == p);
  46. }
  47. }
  48. void test_move_ctor()
  49. {
  50. using namespace fs;
  51. // Move
  52. {
  53. static_assert(std::is_nothrow_move_constructible<directory_entry>::value,
  54. "directory_entry must be nothrow move constructible");
  55. const path p("foo/bar/baz");
  56. directory_entry e(p);
  57. assert(e.path() == p);
  58. directory_entry e2(std::move(e));
  59. assert(e2.path() == p);
  60. assert(e.path() != p); // Testing moved from state.
  61. }
  62. }
  63. void test_path_ctor() {
  64. using namespace fs;
  65. {
  66. static_assert(std::is_constructible<directory_entry, const path&>::value,
  67. "directory_entry must be constructible from path");
  68. static_assert(!std::is_nothrow_constructible<directory_entry, const path&>::value,
  69. "directory_entry constructor should not be noexcept");
  70. static_assert(!std::is_convertible<path const&, directory_entry>::value,
  71. "directory_entry constructor should be explicit");
  72. }
  73. {
  74. const path p("foo/bar/baz");
  75. const directory_entry e(p);
  76. assert(p == e.path());
  77. }
  78. }
  79. int main() {
  80. test_default_ctor();
  81. test_copy_ctor();
  82. test_move_ctor();
  83. test_path_ctor();
  84. }