Home | History | Annotate | Download | only in directory_iterator.members
      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 directory_iterator
     15 
     16 // directory_iterator& operator=(directory_iterator const&);
     17 
     18 #include <experimental/filesystem>
     19 #include <type_traits>
     20 #include <set>
     21 #include <cassert>
     22 
     23 #include "test_macros.h"
     24 #include "rapid-cxx-test.hpp"
     25 #include "filesystem_test_helper.hpp"
     26 
     27 // The filesystem specification explicitly allows for self-move on
     28 // the directory iterators. Turn off this warning so we can test it.
     29 #if defined(__clang__)
     30 #pragma clang diagnostic ignored "-Wself-move"
     31 #endif
     32 
     33 using namespace std::experimental::filesystem;
     34 
     35 TEST_SUITE(directory_iterator_move_assign_tests)
     36 
     37 TEST_CASE(test_assignment_signature)
     38 {
     39     using D = directory_iterator;
     40     static_assert(std::is_nothrow_move_assignable<D>::value, "");
     41 }
     42 
     43 TEST_CASE(test_move_to_end_iterator)
     44 {
     45     const path testDir = StaticEnv::Dir;
     46 
     47     directory_iterator from(testDir);
     48     TEST_REQUIRE(from != directory_iterator{});
     49     const path entry = *from;
     50 
     51     directory_iterator to{};
     52     to = std::move(from);
     53     TEST_REQUIRE(to != directory_iterator{});
     54     TEST_CHECK(*to == entry);
     55 }
     56 
     57 
     58 TEST_CASE(test_move_from_end_iterator)
     59 {
     60     const path testDir = StaticEnv::Dir;
     61 
     62     directory_iterator from{};
     63 
     64     directory_iterator to(testDir);
     65     TEST_REQUIRE(to != from);
     66 
     67     to = std::move(from);
     68     TEST_REQUIRE(to == directory_iterator{});
     69     TEST_REQUIRE(from == directory_iterator{});
     70 }
     71 
     72 TEST_CASE(test_move_valid_iterator)
     73 {
     74     const path testDir = StaticEnv::Dir;
     75     const directory_iterator endIt{};
     76 
     77     directory_iterator it(testDir);
     78     TEST_REQUIRE(it != endIt);
     79     ++it;
     80     TEST_REQUIRE(it != endIt);
     81     const path entry = *it;
     82 
     83     directory_iterator it2(testDir);
     84     TEST_REQUIRE(it2 != it);
     85     const path entry2 = *it2;
     86     TEST_CHECK(entry2 != entry);
     87 
     88     it2 = std::move(it);
     89     TEST_REQUIRE(it2 != directory_iterator{});
     90     TEST_CHECK(*it2 == entry);
     91 }
     92 
     93 TEST_CASE(test_returns_reference_to_self)
     94 {
     95     directory_iterator it;
     96     directory_iterator it2;
     97     directory_iterator& ref = (it2 = it);
     98     TEST_CHECK(&ref == &it2);
     99 }
    100 
    101 
    102 TEST_CASE(test_self_move)
    103 {
    104     // Create two non-equal iterators that have exactly the same state.
    105     directory_iterator it(StaticEnv::Dir);
    106     directory_iterator it2(StaticEnv::Dir);
    107     ++it; ++it2;
    108     TEST_CHECK(it != it2);
    109     TEST_CHECK(*it2 == *it);
    110 
    111     it = std::move(it);
    112     TEST_CHECK(*it2 == *it);
    113 }
    114 
    115 
    116 TEST_SUITE_END()
    117