]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/filesystem/test/issues/recurse_dir_iter_5403.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / filesystem / test / issues / recurse_dir_iter_5403.cpp
CommitLineData
7c673cae
FG
1// Boost Filesystem recurse_dir_iter_test.cpp ----------------------------------------//
2
3// Copyright Beman Dawes 2014.
4
5// Distributed under the Boost Software License, Version 1.0.
6// See http://www.boost.org/LICENSE_1_0.txt
7
8// Library home page: http://www.boost.org/libs/filesystem
9
10#include <boost/config/warning_disable.hpp>
11
12// See deprecated_test for tests of deprecated features
92f5a8d4 13#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
7c673cae
FG
14# define BOOST_FILESYSTEM_NO_DEPRECATED
15#endif
92f5a8d4 16#ifndef BOOST_SYSTEM_NO_DEPRECATED
7c673cae
FG
17# define BOOST_SYSTEM_NO_DEPRECATED
18#endif
19
20#include <boost/filesystem/operations.hpp>
21
22#include <boost/config.hpp>
23# if defined( BOOST_NO_STD_WSTRING )
24# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
25# endif
26
27#include <boost/cerrno.hpp>
28#include <boost/detail/lightweight_test.hpp>
29#include <boost/detail/lightweight_main.hpp>
30
31namespace fs = boost::filesystem;
32using boost::system::error_code;
33using boost::system::system_category;
34using boost::system::system_error;
35
36#include <iostream>
37
38using std::cout;
39using std::endl;
40
41#ifdef BOOST_WINDOWS_API
42# include <windows.h>
43#endif
44namespace
45{
46 typedef int errno_t;
47 std::string platform(BOOST_PLATFORM);
48 bool report_throws = false;
49 bool cleanup = true;
50 bool skip_long_windows_tests = false;
51 unsigned short language_id; // 0 except for Windows
52
53} // unnamed namespace
54
55//------------------------------------------------------------------------------------//
56// //
57// main //
58// //
59//------------------------------------------------------------------------------------//
60
61int cpp_main(int argc, char* argv[])
62{
63 // document state of critical macros
64#ifdef BOOST_POSIX_API
65 cout << "BOOST_POSIX_API is defined\n";
66#endif
67#ifdef BOOST_WINDOWS_API
68 cout << "BOOST_WINDOWS_API is defined\n";
69#endif
70
71 for (; argc > 1; --argc, ++argv)
72 {
73 //if (*argv[1]=='-' && *(argv[1]+1)=='t')
74 // report_throws = true;
75 //else if (*argv[1]=='-' && *(argv[1]+1)=='x')
76 // cleanup = false;
77 //else if (*argv[1]=='-' && *(argv[1]+1)=='w')
78 // skip_long_windows_tests = true;
79 }
80
81 // The choice of platform to test is made at runtime rather than compile-time
82 // so that compile errors for all platforms will be detected even though
83 // only the current platform is runtime tested.
84# if defined(BOOST_POSIX_API)
85 platform = "POSIX";
86# elif defined(BOOST_WINDOWS_API)
87 platform = "Windows";
88# if !defined(__MINGW32__) && !defined(__CYGWIN__)
89 language_id = ::GetUserDefaultUILanguage();
90# else
91 language_id = 0x0409; // Assume US English
92# endif
93# else
94# error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
95# endif
96 cout << "API is " << platform << endl;
97 cout << "initial_path() is " << fs::initial_path() << endl;
98 fs::path ip = fs::initial_path();
99
100 for (fs::path::const_iterator it = ip.begin(); it != ip.end(); ++it)
101 {
102 if (it != ip.begin())
103 cout << ", ";
104 cout << *it;
105 }
106 cout << endl;
107
108 // From the root, walk the directory tree looking for a permissions error
109
110 fs::recursive_directory_iterator it("/");
111 fs::recursive_directory_iterator end_it;
112
113 // The increment function has an invarient that it always makes progress,
114 // so even if an error occurs this loop will eventually terminate.
115
116 while (it != end_it)
117 {
118 error_code ec;
119 fs::path init_path = it->path();
120 it.increment(ec);
121 if (ec)
122 {
123 cout << "initial path: " << init_path << endl;
124 cout << "error_code: " << ec.value() << " with msg: " << ec.message() << endl;
125 if (it != end_it)
126 cout << "post-increment path: " << it->path() << endl;
127 }
128 }
129
130 cout << "returning from main()" << endl;
131 return ::boost::report_errors();
132} // main