]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/operations/file_size.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / file_size.cc
CommitLineData
99dee823 1// Copyright (C) 2015-2021 Free Software Foundation, Inc.
9caf7b27
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
ef0e80d2 18// { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
52066eae 19// { dg-do run { target c++11 } }
9caf7b27
JW
20// { dg-require-filesystem-ts "" }
21
22#include <experimental/filesystem>
23#include <testsuite_hooks.h>
24#include <testsuite_fs.h>
25
26namespace fs = std::experimental::filesystem;
27
28void
29test01()
30{
31 std::error_code ec;
9412b35a 32 auto size = fs::file_size(".", ec);
9caf7b27 33 VERIFY( ec == std::errc::is_a_directory );
9412b35a 34 VERIFY( size == (std::uintmax_t)-1 );
9caf7b27
JW
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 );
9412b35a 43 VERIFY( size == (std::uintmax_t)-1 );
9caf7b27
JW
44}
45
46void
47test02()
48{
49 fs::path p = __gnu_test::nonexistent_path();
50
51 std::error_code ec;
9412b35a 52 auto size = fs::file_size(p, ec);
9caf7b27 53 VERIFY( ec );
9412b35a 54 VERIFY( size == (std::uintmax_t)-1 );
9caf7b27
JW
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 );
9412b35a 63 VERIFY( size == (std::uintmax_t)-1 );
9caf7b27
JW
64}
65
66int
67main()
68{
69 test01();
70 test02();
71}