Debian Codegraph @

libstdc++-v3/testsuite/27_io/filesystem/operations/file_size.cc

raw
1 // Copyright (C) 2015-2025 Free Software Foundation, Inc.
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-do run { target c++17 } }
19 // { dg-require-filesystem-ts "" }
20
21 #include <filesystem>
22 #include <testsuite_hooks.h>
23 #include <testsuite_fs.h>
24
25 namespace fs = std::filesystem;
26
27 void
28 test01()
29 {
30 std::error_code ec;
31 auto size = fs::file_size(".", ec);
32 VERIFY( ec == std::errc::is_a_directory );
33 VERIFY( size == (std::uintmax_t)-1 );
34
35 try {
36 size = fs::file_size(".");
37 ec.clear();
38 } catch (const fs::filesystem_error& e) {
39 ec = e.code();
40 }
41 VERIFY( ec == std::errc::is_a_directory );
42 VERIFY( size == (std::uintmax_t)-1 );
43 }
44
45 void
46 test02()
47 {
48 fs::path p = __gnu_test::nonexistent_path();
49
50 std::error_code ec;
51 auto size = fs::file_size(p, ec);
52 VERIFY( ec );
53 VERIFY( size == (std::uintmax_t)-1 );
54
55 try {
56 size = fs::file_size(p);
57 ec.clear();
58 } catch (const fs::filesystem_error& e) {
59 ec = e.code();
60 }
61 VERIFY( ec );
62 VERIFY( size == (std::uintmax_t)-1 );
63 }
64
65 int
66 main()
67 {
68 test01();
69 test02();
70 }