]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
ops.cc (stat_type): Define alias for struct stat and use throughout the file.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / temp_directory_path.cc
CommitLineData
9caf7b27
JW
1// Copyright (C) 2015 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++11 -lstdc++fs" }
19// { dg-require-filesystem-ts "" }
20
21#include <experimental/filesystem>
22#include <stdlib.h>
23#include <testsuite_hooks.h>
24#include <testsuite_fs.h>
25
26void
27clean_env()
28{
29 ::unsetenv("TMPDIR");
30 ::unsetenv("TMP");
31 ::unsetenv("TEMPDIR");
32 ::unsetenv("TEMP");
33}
34
35namespace fs = std::experimental::filesystem;
36
37void
38test01()
39{
40 clean_env();
41
42 if (!fs::exists("/tmp"))
43 return; // just give up
44
45 std::error_code ec;
46 fs::path p1 = fs::temp_directory_path(ec);
47 VERIFY( exists(p1) );
48
49 fs::path p2 = fs::temp_directory_path();
50 VERIFY( p1 == p2 );
51}
52
53void
54test02()
55{
56 clean_env();
57
58 if (::setenv("TMPDIR", __gnu_test::nonexistent_path().string().c_str(), 1))
59 return; // just give up
60
61 std::error_code ec;
62 fs::path p = fs::temp_directory_path(ec);
63 VERIFY( ec );
64
65 std::error_code ec2;
66 try {
67 p = fs::temp_directory_path();
68 } catch (const fs::filesystem_error& e) {
69 ec2 = e.code();
70 }
71 VERIFY( ec2 == ec );
72}
73
74
75int
76main()
77{
78 test01();
79 test02();
80}