]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/operations/file_size.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / operations / file_size.cc
1 // Copyright (C) 2015-2020 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-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-filesystem-ts "" }
21
22 #include <filesystem>
23 #include <testsuite_hooks.h>
24 #include <testsuite_fs.h>
25
26 namespace fs = std::filesystem;
27
28 void
29 test01()
30 {
31 std::error_code ec;
32 size_t size = fs::file_size(".", ec);
33 VERIFY( ec == std::errc::is_a_directory );
34 VERIFY( size == -1 );
35
36 try {
37 size = fs::file_size(".");
38 ec.clear();
39 } catch (const fs::filesystem_error& e) {
40 ec = e.code();
41 }
42 VERIFY( ec == std::errc::is_a_directory );
43 VERIFY( size == -1 );
44 }
45
46 void
47 test02()
48 {
49 fs::path p = __gnu_test::nonexistent_path();
50
51 std::error_code ec;
52 size_t size = fs::file_size(p, ec);
53 VERIFY( ec );
54 VERIFY( size == -1 );
55
56 try {
57 size = fs::file_size(p);
58 ec.clear();
59 } catch (const fs::filesystem_error& e) {
60 ec = e.code();
61 }
62 VERIFY( ec );
63 VERIFY( size == -1 );
64 }
65
66 int
67 main()
68 {
69 test01();
70 test02();
71 }