]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / temp_directory_path.cc
CommitLineData
f1717362 1// Copyright (C) 2015-2016 Free Software Foundation, Inc.
5fe4dbdc 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{
fc466aaf 40 bool test __attribute__((unused)) = false;
41
5fe4dbdc 42 clean_env();
43
44 if (!fs::exists("/tmp"))
45 return; // just give up
46
47 std::error_code ec;
48 fs::path p1 = fs::temp_directory_path(ec);
49 VERIFY( exists(p1) );
50
51 fs::path p2 = fs::temp_directory_path();
52 VERIFY( p1 == p2 );
53}
54
55void
56test02()
57{
fc466aaf 58 bool test __attribute__((unused)) = false;
59
5fe4dbdc 60 clean_env();
61
62 if (::setenv("TMPDIR", __gnu_test::nonexistent_path().string().c_str(), 1))
63 return; // just give up
64
65 std::error_code ec;
66 fs::path p = fs::temp_directory_path(ec);
67 VERIFY( ec );
68
69 std::error_code ec2;
70 try {
71 p = fs::temp_directory_path();
72 } catch (const fs::filesystem_error& e) {
73 ec2 = e.code();
74 }
75 VERIFY( ec2 == ec );
76}
77
78
79int
80main()
81{
82 test01();
83 test02();
84}