1 // Boost Filesystem recurse_dir_iter_test.cpp ----------------------------------------//
3 // Copyright Beman Dawes 2014.
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // Library home page: http://www.boost.org/libs/filesystem
10 #include <boost/config/warning_disable.hpp>
12 // See deprecated_test for tests of deprecated features
13 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
14 # define BOOST_FILESYSTEM_NO_DEPRECATED
16 #ifndef BOOST_SYSTEM_NO_DEPRECATED
17 # define BOOST_SYSTEM_NO_DEPRECATED
20 #include <boost/filesystem/operations.hpp>
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
27 #include <boost/cerrno.hpp>
28 #include <boost/detail/lightweight_test.hpp>
29 #include <boost/detail/lightweight_main.hpp>
31 namespace fs
= boost::filesystem
;
32 using boost::system::error_code
;
33 using boost::system::system_category
;
34 using boost::system::system_error
;
41 #ifdef BOOST_WINDOWS_API
47 std::string
platform(BOOST_PLATFORM
);
48 bool report_throws
= false;
50 bool skip_long_windows_tests
= false;
51 unsigned short language_id
; // 0 except for Windows
53 } // unnamed namespace
55 //------------------------------------------------------------------------------------//
59 //------------------------------------------------------------------------------------//
61 int cpp_main(int argc
, char* argv
[])
63 // document state of critical macros
64 #ifdef BOOST_POSIX_API
65 cout
<< "BOOST_POSIX_API is defined\n";
67 #ifdef BOOST_WINDOWS_API
68 cout
<< "BOOST_WINDOWS_API is defined\n";
71 for (; argc
> 1; --argc
, ++argv
)
73 //if (*argv[1]=='-' && *(argv[1]+1)=='t')
74 // report_throws = true;
75 //else if (*argv[1]=='-' && *(argv[1]+1)=='x')
77 //else if (*argv[1]=='-' && *(argv[1]+1)=='w')
78 // skip_long_windows_tests = true;
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)
86 # elif defined(BOOST_WINDOWS_API)
88 # if !defined(__MINGW32__) && !defined(__CYGWIN__)
89 language_id
= ::GetUserDefaultUILanguage();
91 language_id
= 0x0409; // Assume US English
94 # error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
96 cout
<< "API is " << platform
<< endl
;
97 cout
<< "initial_path() is " << fs::initial_path() << endl
;
98 fs::path ip
= fs::initial_path();
100 for (fs::path::const_iterator it
= ip
.begin(); it
!= ip
.end(); ++it
)
102 if (it
!= ip
.begin())
108 // From the root, walk the directory tree looking for a permissions error
110 fs::recursive_directory_iterator
it("/");
111 fs::recursive_directory_iterator end_it
;
113 // The increment function has an invarient that it always makes progress,
114 // so even if an error occurs this loop will eventually terminate.
119 fs::path init_path
= it
->path();
123 cout
<< "initial path: " << init_path
<< endl
;
124 cout
<< "error_code: " << ec
.value() << " with msg: " << ec
.message() << endl
;
126 cout
<< "post-increment path: " << it
->path() << endl
;
130 cout
<< "returning from main()" << endl
;
131 return ::boost::report_errors();