summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/experimental/filesystem/class.directory_entry
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-06-17 19:46:40 +0000
committerEric Fiselier <eric@efcs.ca>2016-06-17 19:46:40 +0000
commitc79795874adef276115f8bcf0b46da4155d2d46d (patch)
tree3c58305df7b6b28f1626e65f704ca3aba480be3a /libcxx/test/std/experimental/filesystem/class.directory_entry
parent7a5813597dad665e4461372edbc3a6ea8e8cb8f0 (diff)
downloadbcm5719-llvm-c79795874adef276115f8bcf0b46da4155d2d46d.tar.gz
bcm5719-llvm-c79795874adef276115f8bcf0b46da4155d2d46d.zip
Add Filesystem TS -- Complete
Add the completed std::experimental::filesystem implementation and tests. The implementation supports C++11 or newer. The TS is built as part of 'libc++experimental.a'. Users of the TS need to manually link this library. Building and testing the TS can be disabled using the CMake option '-DLIBCXX_ENABLE_FILESYSTEM=OFF'. Currently 'libc++experimental.a' is not installed by default. To turn on the installation of the library use '-DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=ON'. llvm-svn: 273034
Diffstat (limited to 'libcxx/test/std/experimental/filesystem/class.directory_entry')
-rw-r--r--libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.cons.pass.cpp97
-rw-r--r--libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.mods.pass.cpp113
-rw-r--r--libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/comparisons.pass.cpp82
-rw-r--r--libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/path.pass.cpp89
-rw-r--r--libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/status.pass.cpp51
-rw-r--r--libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/symlink_status.pass.cpp50
6 files changed, 482 insertions, 0 deletions
diff --git a/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.cons.pass.cpp b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.cons.pass.cpp
new file mode 100644
index 00000000000..9a92f0698ba
--- /dev/null
+++ b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.cons.pass.cpp
@@ -0,0 +1,97 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class directory_entry
+
+// directory_entry() noexcept = default;
+// directory_entry(const directory_entry&) = default;
+// directory_entry(directory_entry&&) noexcept = default;
+// explicit directory_entry(const path);
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+namespace fs = std::experimental::filesystem;
+
+void test_default_ctor()
+{
+ using namespace fs;
+ // Default
+ {
+ static_assert(std::is_nothrow_default_constructible<directory_entry>::value,
+ "directory_entry must have a nothrow default constructor");
+ directory_entry e;
+ assert(e.path() == path());
+ }
+}
+
+
+void test_copy_ctor()
+{
+ using namespace fs;
+ // Copy
+ {
+ static_assert(std::is_copy_constructible<directory_entry>::value,
+ "directory_entry must be copy constructible");
+ static_assert(!std::is_nothrow_copy_constructible<directory_entry>::value,
+ "directory_entry's copy constructor cannot be noexcept");
+ const path p("foo/bar/baz");
+ const directory_entry e(p);
+ assert(e.path() == p);
+ directory_entry e2(e);
+ assert(e.path() == p);
+ assert(e2.path() == p);
+ }
+
+}
+
+void test_move_ctor()
+{
+ using namespace fs;
+ // Move
+ {
+ static_assert(std::is_nothrow_move_constructible<directory_entry>::value,
+ "directory_entry must be nothrow move constructible");
+ const path p("foo/bar/baz");
+ directory_entry e(p);
+ assert(e.path() == p);
+ directory_entry e2(std::move(e));
+ assert(e2.path() == p);
+ assert(e.path() != p); // Testing moved from state.
+ }
+}
+
+void test_path_ctor() {
+ using namespace fs;
+ {
+ static_assert(std::is_constructible<directory_entry, const path&>::value,
+ "directory_entry must be constructible from path");
+ static_assert(!std::is_nothrow_constructible<directory_entry, const path&>::value,
+ "directory_entry constructor should not be noexcept");
+ static_assert(!std::is_convertible<path const&, directory_entry>::value,
+ "directory_entry constructor should be explicit");
+ }
+ {
+ const path p("foo/bar/baz");
+ const directory_entry e(p);
+ assert(p == e.path());
+ }
+}
+
+int main() {
+ test_default_ctor();
+ test_copy_ctor();
+ test_move_ctor();
+ test_path_ctor();
+}
diff --git a/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.mods.pass.cpp b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.mods.pass.cpp
new file mode 100644
index 00000000000..97ecbefac42
--- /dev/null
+++ b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.mods.pass.cpp
@@ -0,0 +1,113 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class directory_entry
+
+// directory_entry& operator=(directory_entry const&) = default;
+// directory_entry& operator=(directory_entry&&) noexcept = default;
+// void assign(path const&);
+// void replace_filename(path const&);
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+namespace fs = std::experimental::filesystem;
+
+void test_copy_assign_operator()
+{
+ using namespace fs;
+ // Copy
+ {
+ static_assert(std::is_copy_assignable<directory_entry>::value,
+ "directory_entry must be copy assignable");
+ static_assert(!std::is_nothrow_copy_assignable<directory_entry>::value,
+ "directory_entry's copy assignment cannot be noexcept");
+ const path p("foo/bar/baz");
+ const path p2("abc");
+ const directory_entry e(p);
+ directory_entry e2;
+ assert(e.path() == p && e2.path() == path());
+ e2 = e;
+ assert(e.path() == p && e2.path() == p);
+ directory_entry e3(p2);
+ e2 = e3;
+ assert(e2.path() == p2 && e3.path() == p2);
+ }
+}
+
+
+void test_move_assign_operator()
+{
+ using namespace fs;
+ // Copy
+ {
+ static_assert(std::is_nothrow_move_assignable<directory_entry>::value,
+ "directory_entry is noexcept move assignable");
+ const path p("foo/bar/baz");
+ const path p2("abc");
+ directory_entry e(p);
+ directory_entry e2(p2);
+ assert(e.path() == p && e2.path() == p2);
+ e2 = std::move(e);
+ assert(e2.path() == p);
+ assert(e.path() != p); // testing moved from state
+ }
+}
+
+void test_path_assign_method()
+{
+ using namespace fs;
+ const path p("foo/bar/baz");
+ const path p2("abc");
+ directory_entry e(p);
+ {
+ static_assert(std::is_same<decltype(e.assign(p)), void>::value,
+ "return type should be void");
+ static_assert(noexcept(e.assign(p)) == false, "operation must not be noexcept");
+ }
+ {
+ assert(e.path() == p);
+ e.assign(p2);
+ assert(e.path() == p2 && e.path() != p);
+ e.assign(p);
+ assert(e.path() == p && e.path() != p2);
+ }
+}
+
+void test_replace_filename_method()
+{
+ using namespace fs;
+ const path p("/path/to/foo.exe");
+ const path replace("bar.out");
+ const path expect("/path/to/bar.out");
+ directory_entry e(p);
+ {
+ static_assert(noexcept(e.replace_filename(replace)) == false,
+ "operation cannot be noexcept");
+ static_assert(std::is_same<decltype(e.replace_filename(replace)), void>::value,
+ "operation must return void");
+ }
+ {
+ assert(e.path() == p);
+ e.replace_filename(replace);
+ assert(e.path() == expect);
+ }
+}
+
+int main() {
+ test_copy_assign_operator();
+ test_move_assign_operator();
+ test_path_assign_method();
+ test_replace_filename_method();
+}
diff --git a/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/comparisons.pass.cpp b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/comparisons.pass.cpp
new file mode 100644
index 00000000000..96e50930022
--- /dev/null
+++ b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/comparisons.pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class directory_entry
+
+// bool operator==(directory_entry const&) const noexcept;
+// bool operator!=(directory_entry const&) const noexcept;
+// bool operator< (directory_entry const&) const noexcept;
+// bool operator<=(directory_entry const&) const noexcept;
+// bool operator> (directory_entry const&) const noexcept;
+// bool operator>=(directory_entry const&) const noexcept;
+
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+namespace fs = std::experimental::filesystem;
+
+#define CHECK_OP(Op) \
+ static_assert(std::is_same<decltype(ce. operator Op (ce)), bool>::value, ""); \
+ static_assert(noexcept(ce.operator Op (ce)), "Operation must be noexcept" )
+
+void test_comparison_signatures() {
+ using namespace fs;
+ path const p("foo/bar/baz");
+ // Check that the operators are member functions with the correct signatures.
+ {
+ directory_entry const ce(p);
+ CHECK_OP(==);
+ CHECK_OP(!=);
+ CHECK_OP(< );
+ CHECK_OP(<=);
+ CHECK_OP(> );
+ CHECK_OP(>=);
+ }
+}
+#undef CHECK_OP
+
+// The actual semantics of the comparisons are testing via paths operators.
+void test_comparisons_simple() {
+ using namespace fs;
+ typedef std::pair<path, path> TestType;
+ TestType TestCases[] =
+ {
+ {"", ""},
+ {"", "a"},
+ {"a", "a"},
+ {"a", "b"},
+ {"foo/bar/baz", "foo/bar/baz/"}
+ };
+ auto TestFn = [](path const& LHS, const directory_entry& LHSE,
+ path const& RHS, const directory_entry& RHSE) {
+ assert((LHS == RHS) == (LHSE == RHSE));
+ assert((LHS != RHS) == (LHSE != RHSE));
+ assert((LHS < RHS) == (LHSE < RHSE));
+ assert((LHS <= RHS) == (LHSE <= RHSE));
+ assert((LHS > RHS) == (LHSE > RHSE));
+ assert((LHS >= RHS) == (LHSE >= RHSE));
+ };
+ for (auto const& TC : TestCases) {
+ const directory_entry L(TC.first);
+ const directory_entry R(TC.second);
+ TestFn(TC.first, L, TC.second, R);
+ TestFn(TC.second, R, TC.first, L);
+ }
+}
+
+int main() {
+ test_comparison_signatures();
+ test_comparisons_simple();
+}
diff --git a/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/path.pass.cpp b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/path.pass.cpp
new file mode 100644
index 00000000000..d228a3d9264
--- /dev/null
+++ b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/path.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class directory_entry
+
+// const path& path() const noexcept;
+// operator const path&() const noexcept;
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+namespace fs = std::experimental::filesystem;
+
+void test_path_method() {
+ using namespace fs;
+ const path p("foo/bar/baz.exe");
+ const path p2("abc");
+ {
+ directory_entry nce;
+ const directory_entry e("");
+ static_assert(std::is_same<decltype(e.path()), const path&>::value, "");
+ static_assert(std::is_same<decltype(nce.path()), const path&>::value, "");
+ static_assert(noexcept(e.path()) && noexcept(nce.path()), "");
+ }
+ {
+ directory_entry e(p);
+ path const& pref = e.path();
+ assert(pref == p);
+ assert(&pref == &e.path());
+ e.assign(p2);
+ assert(pref == p2);
+ assert(&pref == &e.path());
+ }
+}
+
+void test_path_conversion() {
+ using namespace fs;
+ const path p("foo/bar/baz.exe");
+ const path p2("abc");
+ {
+ directory_entry nce;
+ const directory_entry e("");
+ // Check conversions exist
+ static_assert(std::is_convertible<directory_entry&, path const&>::value, "");
+ static_assert(std::is_convertible<directory_entry const&, path const&>::value, "");
+ static_assert(std::is_convertible<directory_entry &&, path const&>::value, "");
+ static_assert(std::is_convertible<directory_entry const&&, path const&>::value, "");
+ // Not convertible to non-const
+ static_assert(!std::is_convertible<directory_entry&, path&>::value, "");
+ static_assert(!std::is_convertible<directory_entry const&, path&>::value, "");
+ static_assert(!std::is_convertible<directory_entry &&, path&>::value, "");
+ static_assert(!std::is_convertible<directory_entry const&&, path&>::value, "");
+ // conversions are noexcept
+ static_assert(noexcept(e.operator fs::path const&()) &&
+ noexcept(e.operator fs::path const&()), "");
+ }
+ // const
+ {
+ directory_entry const e(p);
+ path const& pref = e;
+ assert(&pref == &e.path());
+ }
+ // non-const
+ {
+ directory_entry e(p);
+ path const& pref = e;
+ assert(&pref == &e.path());
+
+ e.assign(p2);
+ assert(pref == p2);
+ assert(&pref == &e.path());
+ }
+}
+
+int main() {
+ test_path_method();
+ test_path_conversion();
+}
diff --git a/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/status.pass.cpp b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/status.pass.cpp
new file mode 100644
index 00000000000..54c5172ebce
--- /dev/null
+++ b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/status.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class directory_entry
+
+// file_status status() const;
+// file_status status(error_code const&) const noexcept;
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+#include "filesystem_test_helper.hpp"
+
+int main()
+{
+ using namespace fs;
+ {
+ const directory_entry e("foo");
+ std::error_code ec;
+ static_assert(std::is_same<decltype(e.status()), file_status>::value, "");
+ static_assert(std::is_same<decltype(e.status(ec)), file_status>::value, "");
+ static_assert(noexcept(e.status()) == false, "");
+ static_assert(noexcept(e.status(ec)) == true, "");
+ }
+ auto TestFn = [](path const& p) {
+ const directory_entry e(p);
+ std::error_code pec, eec;
+ file_status ps = fs::status(p, pec);
+ file_status es = e.status(eec);
+ assert(ps.type() == es.type());
+ assert(ps.permissions() == es.permissions());
+ assert(pec == eec);
+ };
+ {
+ TestFn(StaticEnv::File);
+ TestFn(StaticEnv::Dir);
+ TestFn(StaticEnv::SymlinkToFile);
+ TestFn(StaticEnv::DNE);
+ }
+}
diff --git a/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/symlink_status.pass.cpp b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/symlink_status.pass.cpp
new file mode 100644
index 00000000000..3a99eb671b4
--- /dev/null
+++ b/libcxx/test/std/experimental/filesystem/class.directory_entry/directory_entry.obs/symlink_status.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class directory_entry
+
+// file_status symlink_status() const;
+// file_status symlink_status(error_code&) const noexcept;
+
+#include <experimental/filesystem>
+#include <type_traits>
+#include <cassert>
+
+#include "filesystem_test_helper.hpp"
+
+int main() {
+ using namespace fs;
+ {
+ const directory_entry e("foo");
+ std::error_code ec;
+ static_assert(std::is_same<decltype(e.symlink_status()), file_status>::value, "");
+ static_assert(std::is_same<decltype(e.symlink_status(ec)), file_status>::value, "");
+ static_assert(noexcept(e.symlink_status()) == false, "");
+ static_assert(noexcept(e.symlink_status(ec)) == true, "");
+ }
+ auto TestFn = [](path const& p) {
+ const directory_entry e(p);
+ std::error_code pec, eec;
+ file_status ps = fs::symlink_status(p, pec);
+ file_status es = e.symlink_status(eec);
+ assert(ps.type() == es.type());
+ assert(ps.permissions() == es.permissions());
+ assert(pec == eec);
+ };
+ {
+ TestFn(StaticEnv::File);
+ TestFn(StaticEnv::Dir);
+ TestFn(StaticEnv::SymlinkToFile);
+ TestFn(StaticEnv::DNE);
+ }
+}
OpenPOWER on IntegriCloud