directory_entry.cons.pass.cpp 2.6 KB

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