diff options
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc')
-rw-r--r-- | libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc index 28b948f2b12..ffd97ce19d2 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc @@ -70,8 +70,79 @@ test01() remove_all(p, ec); } +void +test02() +{ + bool test __attribute__((unused)) = false; + + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + create_directory(p, fs::current_path(), ec); + create_directory_symlink(p, p / "l", ec); + VERIFY( !ec ); + + // Test post-increment (libstdc++/71005) + auto iter = fs::directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != fs::directory_iterator() ); + const auto entry1 = *iter; + const auto entry2 = *iter++; + VERIFY( entry1 == entry2 ); + VERIFY( entry1.path() == p/"l" ); + VERIFY( iter == fs::directory_iterator() ); + + remove_all(p, ec); +} + +void +test03() +{ + bool test __attribute__((unused)) = false; + + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + create_directories(p / "longer_than_small_string_buffer", ec); + VERIFY( !ec ); + + // Test for no reallocation on each dereference (this is a GNU extension) + auto iter = fs::directory_iterator(p, ec); + const auto* s1 = iter->path().c_str(); + const auto* s2 = iter->path().c_str(); + VERIFY( s1 == s2 ); + + remove_all(p, ec); +} + +void +test04() +{ + bool test __attribute__((unused)) = false; + + const fs::directory_iterator it; + VERIFY( it == fs::directory_iterator() ); +} + +void +test05() +{ + bool test __attribute__((unused)) = false; + + auto p = __gnu_test::nonexistent_path(); + create_directory(p); + create_directory_symlink(p, p / "l"); + fs::directory_iterator it(p), endit; + VERIFY( begin(it) == it ); + static_assert( noexcept(begin(it)), "begin is noexcept" ); + VERIFY( end(it) == endit ); + static_assert( noexcept(end(it)), "end is noexcept" ); +} + int main() { test01(); + test02(); + test03(); + test04(); + test05(); } |