]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/filesystem/iterators/caching.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / iterators / caching.cc
CommitLineData
99dee823 1// Copyright (C) 2019-2021 Free Software Foundation, Inc.
5ed5c0da
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++17" }
19// { dg-do run { target c++17 } }
66d8ee9c 20// { dg-require-filesystem-ts "" }
5ed5c0da
JW
21
22#include <filesystem>
23#include <testsuite_fs.h>
24#include <testsuite_hooks.h>
25
26namespace fs = std::filesystem;
27
28__gnu_test::scoped_file
29create_dir(fs::path dir = __gnu_test::nonexistent_path())
30{
31 fs::create_directory(dir);
32 return { dir, __gnu_test::scoped_file::adopt_file };
33}
34
35void
36test01()
37{
38 auto testdir = create_dir();
39 __gnu_test::scoped_file file1(testdir.path/"file1");
40 __gnu_test::scoped_file file2(testdir.path/"file2");
41
42 fs::directory_iterator it(testdir.path);
43 VERIFY( it->is_regular_file() );
44 ++it;
45 VERIFY( it->is_regular_file() );
46 ++it;
47 VERIFY( it == fs::directory_iterator{} );
48}
49
50void
51test02()
52{
53 auto testdir = create_dir();
54 const auto sub1 = create_dir(testdir.path/"sub1");
55 __gnu_test::scoped_file file1(sub1.path / "file");
56 const auto sub2 = create_dir(testdir.path/"sub2");
57 __gnu_test::scoped_file file2(sub2.path / "file");
58
59 fs::recursive_directory_iterator it(testdir.path);
60 VERIFY( it->is_directory() );
61 ++it;
62 VERIFY( it->is_regular_file() );
63 ++it;
64 VERIFY( it->is_directory() );
65 ++it;
66 VERIFY( it->is_regular_file() );
67 ++it;
68 VERIFY( it == fs::recursive_directory_iterator{} );
69}
70
71int
72main()
73{
74 test01();
75 test02();
76}