swap.pass.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // void swap(path& rhs) noexcept;
  13. #include "filesystem_include.hpp"
  14. #include <type_traits>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "test_iterators.h"
  18. #include "count_new.hpp"
  19. #include "filesystem_test_helper.hpp"
  20. struct SwapTestcase {
  21. const char* value1;
  22. const char* value2;
  23. };
  24. #define LONG_STR1 "_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG"
  25. #define LONG_STR2 "_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2"
  26. const SwapTestcase TestCases[] =
  27. {
  28. {"", ""}
  29. , {"shortstr", LONG_STR1}
  30. , {LONG_STR1, "shortstr"}
  31. , {LONG_STR1, LONG_STR2}
  32. };
  33. #undef LONG_STR1
  34. #undef LONG_STR2
  35. int main()
  36. {
  37. using namespace fs;
  38. {
  39. path p;
  40. ASSERT_NOEXCEPT(p.swap(p));
  41. ASSERT_SAME_TYPE(void, decltype(p.swap(p)));
  42. }
  43. for (auto const & TC : TestCases) {
  44. path p1(TC.value1);
  45. path p2(TC.value2);
  46. {
  47. DisableAllocationGuard g;
  48. p1.swap(p2);
  49. }
  50. assert(p1 == TC.value2);
  51. assert(p2 == TC.value1);
  52. {
  53. DisableAllocationGuard g;
  54. p1.swap(p2);
  55. }
  56. assert(p1 == TC.value1);
  57. assert(p2 == TC.value2);
  58. }
  59. // self-swap
  60. {
  61. const char* Val = "aoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeu";
  62. path p1(Val);
  63. assert(p1 == Val);
  64. {
  65. DisableAllocationGuard g;
  66. p1.swap(p1);
  67. }
  68. assert(p1 == Val);
  69. }
  70. }