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