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 // const path& path() const noexcept;
     17 // operator const path&() const noexcept;
     18 
     19 #include <experimental/filesystem>
     20 #include <type_traits>
     21 #include <cassert>
     22 
     23 namespace fs = std::experimental::filesystem;
     24 
     25 void test_path_method() {
     26   using namespace fs;
     27   const path p("foo/bar/baz.exe");
     28   const path p2("abc");
     29   {
     30     directory_entry nce;
     31     const directory_entry e("");
     32     static_assert(std::is_same<decltype(e.path()),  const path&>::value, "");
     33     static_assert(std::is_same<decltype(nce.path()), const path&>::value, "");
     34     static_assert(noexcept(e.path()) && noexcept(nce.path()), "");
     35   }
     36   {
     37     directory_entry e(p);
     38     path const& pref = e.path();
     39     assert(pref == p);
     40     assert(&pref == &e.path());
     41     e.assign(p2);
     42     assert(pref == p2);
     43     assert(&pref == &e.path());
     44   }
     45 }
     46 
     47 void test_path_conversion() {
     48   using namespace fs;
     49   const path p("foo/bar/baz.exe");
     50   const path p2("abc");
     51   {
     52     directory_entry nce;
     53     const directory_entry e("");
     54     // Check conversions exist
     55     static_assert(std::is_convertible<directory_entry&,        path const&>::value, "");
     56     static_assert(std::is_convertible<directory_entry const&,  path const&>::value, "");
     57     static_assert(std::is_convertible<directory_entry &&,      path const&>::value, "");
     58     static_assert(std::is_convertible<directory_entry const&&, path const&>::value, "");
     59     // Not convertible to non-const
     60     static_assert(!std::is_convertible<directory_entry&,        path&>::value, "");
     61     static_assert(!std::is_convertible<directory_entry const&,  path&>::value, "");
     62     static_assert(!std::is_convertible<directory_entry &&,      path&>::value, "");
     63     static_assert(!std::is_convertible<directory_entry const&&, path&>::value, "");
     64     // conversions are noexcept
     65     static_assert(noexcept(e.operator fs::path const&()) &&
     66                   noexcept(e.operator fs::path const&()), "");
     67   }
     68   // const
     69   {
     70     directory_entry const e(p);
     71     path const& pref = e;
     72     assert(&pref == &e.path());
     73   }
     74   // non-const
     75   {
     76     directory_entry e(p);
     77     path const& pref = e;
     78     assert(&pref == &e.path());
     79 
     80     e.assign(p2);
     81     assert(pref == p2);
     82     assert(&pref == &e.path());
     83   }
     84 }
     85 
     86 int main() {
     87   test_path_method();
     88   test_path_conversion();
     89 }
     90