81 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <filesystem>12 13// class path14 15// void swap(path& rhs) noexcept;16 17#include <filesystem>18#include <cassert>19#include <type_traits>20 21#include "assert_macros.h"22#include "count_new.h"23#include "test_iterators.h"24namespace fs = std::filesystem;25 26struct SwapTestcase {27 const char* value1;28 const char* value2;29};30 31#define LONG_STR1 "_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG"32#define LONG_STR2 "_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2_THIS_IS_LONG2"33const SwapTestcase TestCases[] =34 {35 {"", ""}36 , {"shortstr", LONG_STR1}37 , {LONG_STR1, "shortstr"}38 , {LONG_STR1, LONG_STR2}39 };40#undef LONG_STR141#undef LONG_STR242 43int main(int, char**)44{45 using namespace fs;46 {47 path p;48 ASSERT_NOEXCEPT(p.swap(p));49 ASSERT_SAME_TYPE(void, decltype(p.swap(p)));50 }51 for (auto const & TC : TestCases) {52 path p1(TC.value1);53 path p2(TC.value2);54 {55 DisableAllocationGuard g;56 p1.swap(p2);57 }58 assert(p1 == TC.value2);59 assert(p2 == TC.value1);60 {61 DisableAllocationGuard g;62 p1.swap(p2);63 }64 assert(p1 == TC.value1);65 assert(p2 == TC.value2);66 }67 // self-swap68 {69 const char* Val = "aoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeu";70 path p1(Val);71 assert(p1 == Val);72 {73 DisableAllocationGuard g;74 p1.swap(p1);75 }76 assert(p1 == Val);77 }78 79 return 0;80}81