Home | History | Annotate | Download | only in directory_entry.obs
      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_entry
     15 
     16 // bool operator==(directory_entry const&) const noexcept;
     17 // bool operator!=(directory_entry const&) const noexcept;
     18 // bool operator< (directory_entry const&) const noexcept;
     19 // bool operator<=(directory_entry const&) const noexcept;
     20 // bool operator> (directory_entry const&) const noexcept;
     21 // bool operator>=(directory_entry const&) const noexcept;
     22 
     23 
     24 #include <experimental/filesystem>
     25 #include <type_traits>
     26 #include <cassert>
     27 
     28 namespace fs = std::experimental::filesystem;
     29 
     30 #define CHECK_OP(Op) \
     31   static_assert(std::is_same<decltype(ce. operator Op (ce)), bool>::value, ""); \
     32   static_assert(noexcept(ce.operator Op (ce)), "Operation must be noexcept" )
     33 
     34 void test_comparison_signatures() {
     35   using namespace fs;
     36   path const p("foo/bar/baz");
     37   // Check that the operators are member functions with the correct signatures.
     38   {
     39     directory_entry const ce(p);
     40     CHECK_OP(==);
     41     CHECK_OP(!=);
     42     CHECK_OP(< );
     43     CHECK_OP(<=);
     44     CHECK_OP(> );
     45     CHECK_OP(>=);
     46   }
     47 }
     48 #undef CHECK_OP
     49 
     50 // The actual semantics of the comparisons are testing via paths operators.
     51 void test_comparisons_simple() {
     52   using namespace fs;
     53   typedef std::pair<path, path> TestType;
     54   TestType TestCases[] =
     55   {
     56       {"", ""},
     57       {"", "a"},
     58       {"a", "a"},
     59       {"a", "b"},
     60       {"foo/bar/baz", "foo/bar/baz/"}
     61   };
     62   auto TestFn = [](path const& LHS, const directory_entry& LHSE,
     63                    path const& RHS, const directory_entry& RHSE) {
     64     assert((LHS == RHS) == (LHSE == RHSE));
     65     assert((LHS != RHS) == (LHSE != RHSE));
     66     assert((LHS < RHS) ==  (LHSE < RHSE));
     67     assert((LHS <= RHS) == (LHSE <= RHSE));
     68     assert((LHS > RHS) ==  (LHSE > RHSE));
     69     assert((LHS >= RHS) == (LHSE >= RHSE));
     70   };
     71   for (auto const& TC : TestCases) {
     72     const directory_entry L(TC.first);
     73     const directory_entry R(TC.second);
     74     TestFn(TC.first,  L, TC.second, R);
     75     TestFn(TC.second, R, TC.first, L);
     76   }
     77 }
     78 
     79 int main() {
     80   test_comparison_signatures();
     81   test_comparisons_simple();
     82 }
     83