early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,109 @@
# Boost Filesystem Library test Jamfile
# (C) Copyright Beman Dawes 2002-2006
# (C) Copyright Andrey Semashev 2020
# Distributed under the Boost Software License, Version 1.0.
# See www.boost.org/LICENSE_1_0.txt
import testing ;
import os ;
# The rule checks we're running on Windows that supports mklink command (Vista and later)
rule check-mklink ( properties * )
{
local result ;
if <target-os>windows in $(properties)
{
# mklink is a builtin shell command, so we can't check if an executable exists.
# Testing the exit status of the mklink command (in the hope that it will be different
# when the command is not supported) is inconclusive as for some reason Windows 8.1 shell
# always returns exit code of 1. We have to match the output of the command. :(
# Note that the output may be localized, so pick some part that is likely to be stable regardless
# of localization.
local output = [ SHELL "mklink /?" : exit-status ] ;
if [ MATCH (MKLINK) : $(output[1]) ]
{
result = <define>BOOST_FILESYSTEM_HAS_MKLINK ;
if ! $(.annouced-mklink)
{
ECHO " - Boost.Filesystem: mklink found" ;
.annouced-mklink = 1 ;
}
}
else
{
if ! $(.annouced-mklink)
{
ECHO " - Boost.Filesystem: mklink not found" ;
.annouced-mklink = 1 ;
}
}
}
#ECHO Result: $(result) ;
return $(result) ;
}
project
: requirements
<target-os>windows:<define>_SCL_SECURE_NO_WARNINGS
<target-os>windows:<define>_SCL_SECURE_NO_DEPRECATE
<target-os>windows:<define>_CRT_SECURE_NO_WARNINGS
<target-os>windows:<define>_CRT_SECURE_NO_DEPRECATE
<library>/boost/filesystem//boost_filesystem
<conditional>@check-mklink
;
# Some tests are run both statically and as shared libraries since Filesystem
# has a history of bugs that appear only in one type of build or the other.
path-constant HERE : . ;
local VIS ;
if [ os.environ UBSAN ]
{
VIS = <visibility>global
-<library>/boost/filesystem//boost_filesystem
<library>/boost/filesystem//boost_filesystem/<visibility>global ;
}
run config_info.cpp : : : <link>shared <test-info>always_show_run_output ;
run config_info.cpp : : : <link>static <test-info>always_show_run_output : config_info_static ;
run convenience_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
compile macro_default_test.cpp ;
run odr1_test.cpp odr2_test.cpp ;
run deprecated_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=3 ;
run fstream_test.cpp : : : $(VIS) <define>BOOST_FILESYSTEM_VERSION=4 ;
run large_file_support_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run locale_info.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 <test-info>always_show_run_output ;
run operations_test.cpp : : : <link>shared <define>BOOST_FILESYSTEM_VERSION=4 <test-info>always_show_run_output ;
run operations_test.cpp : : : <link>static <define>BOOST_FILESYSTEM_VERSION=4 : operations_test_static ;
run operations_unit_test.cpp : $(HERE) : : <link>shared <define>BOOST_FILESYSTEM_VERSION=4 <test-info>always_show_run_output ;
run copy_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run path_test.cpp : : : <link>shared <define>BOOST_FILESYSTEM_VERSION=4 ;
run path_test.cpp : : : <link>static <define>BOOST_FILESYSTEM_VERSION=4 : path_test_static ;
run path_test.cpp : : : <link>shared <define>BOOST_FILESYSTEM_VERSION=3 : path_test_v3 ;
run path_unit_test.cpp : : : <link>shared $(VIS) <define>BOOST_FILESYSTEM_VERSION=4 ;
run path_unit_test.cpp : : : <link>static $(VIS) <define>BOOST_FILESYSTEM_VERSION=4 : path_unit_test_static ;
run path_unit_test.cpp : : : <link>shared $(VIS) <define>BOOST_FILESYSTEM_VERSION=3 : path_unit_test_v3 ;
run relative_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run ../example/simple_ls.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run ../example/file_status.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run foreach_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
# `quick` target (for CI)
run quick.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
# Tests for specific issues
run issues/70-71-copy.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run issues/99_canonical_with_junction_point.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
run issues/reparse_tag_file_placeholder.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
if [ os.environ BOOST_FILESYSTEM_TEST_WITH_EXAMPLES ]
{
build-project ../example ;
}

View File

@@ -0,0 +1,50 @@
// boost/libs/filesystem/test/config_info.cpp ----------------------------------------//
// Copyright Beman Dawes 2017
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
#include <boost/filesystem.hpp>
#include <boost/filesystem/detail/macro_value.hpp>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Verify macro reporting works correctly\n";
cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl;
#define SUCHAMACRO
cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << endl;
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl;
cout << "Report macro values that may be useful in debugging various test programs\n";
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl;
cout << " BOOST_FILESYSTEM_VERSION: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_VERSION) << endl;
cout << " BOOST_FILESYSTEM_DEPRECATED: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DEPRECATED) << endl;
cout << " BOOST_FILESYSTEM_SOURCE: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_SOURCE) << endl;
cout << " BOOST_FILESYSTEM_DYN_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DYN_LINK) << endl;
cout << " BOOST_FILESYSTEM_STATIC_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_STATIC_LINK) << endl;
cout << " BOOST_ALL_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_ALL_NO_LIB) << endl;
cout << " BOOST_FILESYSTEM_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_NO_LIB) << endl;
cout << " BOOST_LIB_NAME: " << BOOST_MACRO_VALUE(BOOST_LIB_NAME) << endl;
cout << " BOOST_POSIX_API: " << BOOST_MACRO_VALUE(BOOST_POSIX_API) << endl;
cout << " BOOST_WINDOWS_API: " << BOOST_MACRO_VALUE(BOOST_WINDOWS_API) << endl;
cout << " _MSC_VER: " << BOOST_MACRO_VALUE(_MSC_VER) << endl;
cout << " __MINGW32__: " << BOOST_MACRO_VALUE(__MINGW32__) << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
return 0;
}

View File

@@ -0,0 +1,178 @@
// libs/filesystem/test/convenience_test.cpp -----------------------------------------//
// Copyright Beman Dawes, 2002
// Copyright Vladimir Prus, 2002
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See library home page at http://www.boost.org/libs/filesystem
#include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/directory.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <boost/bind/bind.hpp>
#include <fstream>
#include <iostream>
namespace fs = boost::filesystem;
using fs::path;
namespace sys = boost::system;
namespace {
template< typename F >
bool throws_fs_error(F func)
{
try
{
func();
}
catch (const fs::filesystem_error&)
{
return true;
}
return false;
}
void create_recursive_iterator(const fs::path& ph)
{
fs::recursive_directory_iterator it(ph);
}
} // namespace
// ------------------------------------------------------------------------------------//
int cpp_main(int, char*[])
{
// create_directories() tests --------------------------------------------------------//
BOOST_TEST(!fs::create_directories("/")); // should be harmless
path unique_dir = fs::unique_path(); // unique name in case tests running in parallel
path unique_yy = unique_dir / "yy";
path unique_yya = unique_dir / "yya";
path unique_yy_zz = unique_dir / "yy" / "zz";
fs::remove_all(unique_dir); // make sure slate is blank
BOOST_TEST(!fs::exists(unique_dir)); // reality check
BOOST_TEST(fs::create_directories(unique_dir));
BOOST_TEST(fs::exists(unique_dir));
BOOST_TEST(fs::is_directory(unique_dir));
BOOST_TEST(fs::create_directories(unique_yy_zz));
BOOST_TEST(fs::exists(unique_dir));
BOOST_TEST(fs::exists(unique_yy));
BOOST_TEST(fs::exists(unique_yy_zz));
BOOST_TEST(fs::is_directory(unique_dir));
BOOST_TEST(fs::is_directory(unique_yy));
BOOST_TEST(fs::is_directory(unique_yy_zz));
path is_a_file(unique_dir / "uu");
{
std::ofstream f(is_a_file.string().c_str());
BOOST_TEST(!!f);
}
BOOST_TEST(throws_fs_error(
boost::bind(fs::create_directories, is_a_file)));
BOOST_TEST(throws_fs_error(
boost::bind(fs::create_directories, is_a_file / "aa")));
// recursive_directory_iterator tests ----------------------------------------//
sys::error_code ec;
fs::recursive_directory_iterator it("/no-such-path", ec);
BOOST_TEST(ec);
BOOST_TEST(throws_fs_error(
boost::bind(create_recursive_iterator, "/no-such-path")));
fs::remove(unique_dir / "uu");
#ifdef BOOST_WINDOWS_API
// These tests depends on ordering of directory entries, and that's guaranteed
// on Windows but not necessarily on other operating systems
{
std::ofstream f(unique_yya.string().c_str());
BOOST_TEST(!!f);
}
for (it = fs::recursive_directory_iterator(unique_dir);
it != fs::recursive_directory_iterator(); ++it)
{
std::cout << it->path() << '\n';
}
it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy);
BOOST_TEST(it.depth() == 0);
++it;
BOOST_TEST(it->path() == unique_yy_zz);
BOOST_TEST(it.depth() == 1);
it.pop();
BOOST_TEST(it->path() == unique_yya);
BOOST_TEST(it.depth() == 0);
it++;
BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy);
it.disable_recursion_pending();
++it;
BOOST_TEST(it->path() == unique_yya);
++it;
BOOST_TEST(it == fs::recursive_directory_iterator());
fs::remove(unique_yya);
#endif
it = fs::recursive_directory_iterator(unique_yy_zz);
BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy);
BOOST_TEST(it.depth() == 0);
++it;
BOOST_TEST(it->path() == unique_yy_zz);
BOOST_TEST(it.depth() == 1);
it++;
BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy);
it.disable_recursion_pending();
++it;
BOOST_TEST(it == fs::recursive_directory_iterator());
it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy);
++it;
it.pop();
BOOST_TEST(it == fs::recursive_directory_iterator());
ec.clear();
BOOST_TEST(!ec);
// check that two argument failed constructor creates the end iterator
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) == fs::recursive_directory_iterator());
BOOST_TEST(ec);
fs::remove_all(unique_dir); // clean up behind ourselves
return ::boost::report_errors();
}

View File

@@ -0,0 +1,340 @@
// Copyright Andrey Semashev 2020.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
// This test verifies copy operation behavior.
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/directory.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/fstream.hpp> // for BOOST_FILESYSTEM_C_STR
#include <boost/system/error_code.hpp>
#include <set>
#include <string>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <boost/throw_exception.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/core/lightweight_test.hpp>
namespace fs = boost::filesystem;
namespace {
void create_file(fs::path const& ph, std::string const& contents = std::string())
{
std::ofstream f(BOOST_FILESYSTEM_C_STR(ph), std::ios_base::out | std::ios_base::trunc);
if (!f)
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create file: " + ph.string()));
if (!contents.empty())
f << contents;
}
void verify_file(fs::path const& ph, std::string const& expected)
{
std::ifstream f(BOOST_FILESYSTEM_C_STR(ph));
if (!f)
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to open file: " + ph.string()));
std::string contents;
f >> contents;
BOOST_TEST_EQ(contents, expected);
if (contents != expected)
{
BOOST_THROW_EXCEPTION(std::runtime_error("verify_file failed: contents \"" + contents + "\" != \"" + expected + "\" in " + ph.string()));
}
}
fs::path create_tree()
{
fs::path root_dir = fs::unique_path();
fs::create_directory(root_dir);
create_file(root_dir / "f1", "f1");
create_file(root_dir / "f2", "f2");
fs::create_directory(root_dir / "d1");
create_file(root_dir / "d1/f1", "d1f1");
fs::create_directory(root_dir / "d1/d1");
create_file(root_dir / "d1/d1/f1", "d1d1f1");
fs::create_directory(root_dir / "d1/d2");
fs::create_directory(root_dir / "d2");
create_file(root_dir / "d2/f1", "d2f1");
return root_dir;
}
typedef std::set< fs::path > directory_tree;
directory_tree collect_directory_tree(fs::path const& root_dir)
{
std::cout << "Collecting directory tree in: " << root_dir << '\n';
directory_tree tree;
fs::recursive_directory_iterator it(root_dir, fs::directory_options::skip_permission_denied |
fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks);
fs::recursive_directory_iterator end;
while (it != end)
{
fs::path p = fs::relative(it->path(), root_dir);
std::cout << p << '\n';
tree.insert(p);
++it;
}
std::cout << "done." << std::endl;
return tree;
}
void test_copy_file_default(fs::path const& root_dir)
{
std::cout << "test_copy_file_default" << std::endl;
fs::path target_dir = fs::unique_path();
fs::create_directory(target_dir);
fs::copy(root_dir / "f1", target_dir);
fs::copy(root_dir / "f2", target_dir / "f3");
directory_tree tree = collect_directory_tree(target_dir);
BOOST_TEST_EQ(tree.size(), 2u);
BOOST_TEST(tree.find("f1") != tree.end());
BOOST_TEST(tree.find("f3") != tree.end());
verify_file(target_dir / "f1", "f1");
verify_file(target_dir / "f3", "f2");
fs::remove_all(target_dir);
}
void test_copy_dir_default(fs::path const& root_dir, bool with_symlinks)
{
std::cout << "test_copy_dir_default" << std::endl;
fs::path target_dir = fs::unique_path();
fs::copy(root_dir, target_dir);
directory_tree tree = collect_directory_tree(target_dir);
BOOST_TEST_EQ(tree.size(), 4u + with_symlinks);
BOOST_TEST(tree.find("f1") != tree.end());
BOOST_TEST(tree.find("f2") != tree.end());
BOOST_TEST(tree.find("d1") != tree.end());
BOOST_TEST(tree.find("d2") != tree.end());
if (with_symlinks)
{
BOOST_TEST(tree.find("s1") != tree.end());
}
verify_file(target_dir / "f1", "f1");
verify_file(target_dir / "f2", "f2");
fs::remove_all(target_dir);
}
void test_copy_dir_default_ec(fs::path const& root_dir, bool with_symlinks)
{
// This test is similar to test_copy_dir_default, but uses an error_code overload of the operation.
// Tests for https://github.com/boostorg/filesystem/issues/152 fix.
std::cout << "test_copy_dir_default_ec" << std::endl;
fs::path target_dir = fs::unique_path();
boost::system::error_code ec;
fs::copy(root_dir, target_dir, ec);
BOOST_TEST(!ec);
directory_tree tree = collect_directory_tree(target_dir);
BOOST_TEST_EQ(tree.size(), 4u + with_symlinks);
BOOST_TEST(tree.find("f1") != tree.end());
BOOST_TEST(tree.find("f2") != tree.end());
BOOST_TEST(tree.find("d1") != tree.end());
BOOST_TEST(tree.find("d2") != tree.end());
if (with_symlinks)
{
BOOST_TEST(tree.find("s1") != tree.end());
}
verify_file(target_dir / "f1", "f1");
verify_file(target_dir / "f2", "f2");
fs::remove_all(target_dir);
}
void test_copy_dir_recursive(fs::path const& root_dir)
{
std::cout << "test_copy_dir_recursive" << std::endl;
fs::path target_dir = fs::unique_path();
fs::copy(root_dir, target_dir, fs::copy_options::recursive);
directory_tree tree = collect_directory_tree(target_dir);
BOOST_TEST_EQ(tree.size(), 9u);
BOOST_TEST(tree.find("f1") != tree.end());
BOOST_TEST(tree.find("f2") != tree.end());
BOOST_TEST(tree.find("d1") != tree.end());
BOOST_TEST(tree.find(fs::path("d1") / "f1") != tree.end());
BOOST_TEST(tree.find(fs::path("d1") / "d1") != tree.end());
BOOST_TEST(tree.find(fs::path("d1") / "d1" / "f1") != tree.end());
BOOST_TEST(tree.find(fs::path("d1") / "d2") != tree.end());
BOOST_TEST(tree.find("d2") != tree.end());
BOOST_TEST(tree.find(fs::path("d2") / "f1") != tree.end());
verify_file(target_dir / "f1", "f1");
verify_file(target_dir / "f2", "f2");
verify_file(target_dir / "d1/f1", "d1f1");
verify_file(target_dir / "d1/d1/f1", "d1d1f1");
verify_file(target_dir / "d2/f1", "d2f1");
fs::remove_all(target_dir);
}
void test_copy_dir_recursive_tree(fs::path const& root_dir)
{
std::cout << "test_copy_dir_recursive_tree" << std::endl;
fs::path target_dir = fs::unique_path();
fs::copy(root_dir, target_dir, fs::copy_options::recursive | fs::copy_options::directories_only);
directory_tree tree = collect_directory_tree(target_dir);
BOOST_TEST_EQ(tree.size(), 4u);
BOOST_TEST(tree.find("d1") != tree.end());
BOOST_TEST(tree.find(fs::path("d1") / "d1") != tree.end());
BOOST_TEST(tree.find(fs::path("d1") / "d2") != tree.end());
BOOST_TEST(tree.find("d2") != tree.end());
fs::remove_all(target_dir);
}
void test_copy_file_symlinks(fs::path const& root_dir)
{
std::cout << "test_copy_file_symlinks" << std::endl;
fs::path target_dir = fs::unique_path();
fs::create_directory(target_dir);
fs::copy(root_dir / "f1", target_dir);
fs::path prev_cur_dir = fs::current_path();
fs::current_path(target_dir);
fs::copy(".." / root_dir / "f2", "f2", fs::copy_options::create_symlinks);
fs::current_path(prev_cur_dir);
// Copying from a relative path with copy_options::create_symlinks to a directory other than current directory is a non-standard extension
fs::copy(target_dir / "f1", target_dir / "f3", fs::copy_options::create_symlinks);
verify_file(target_dir / "f1", "f1");
fs::path link_target = fs::read_symlink(target_dir / "f2");
if (link_target != (".." / root_dir / "f2"))
{
BOOST_ERROR("Incorrect f2 symlink in test_copy_file_symlinks");
std::cout << (target_dir / "f2") << " => " << link_target << std::endl;
}
link_target = fs::read_symlink(target_dir / "f3");
if (link_target != "f1" && link_target != (fs::path(".") / "f1"))
{
BOOST_ERROR("Incorrect f3 symlink in test_copy_file_symlinks");
std::cout << (target_dir / "f3") << " => " << link_target << std::endl;
}
fs::remove_all(target_dir);
}
void test_copy_errors(fs::path const& root_dir, bool symlinks_supported)
{
std::cout << "test_copy_errors" << std::endl;
fs::path target_dir = fs::unique_path();
fs::create_directory(target_dir);
BOOST_TEST_THROWS(fs::copy(root_dir / "non-existing", target_dir), fs::filesystem_error);
create_file(target_dir / "f1");
BOOST_TEST_THROWS(fs::copy(root_dir / "f1", target_dir), fs::filesystem_error);
BOOST_TEST_THROWS(fs::copy(root_dir / "f1", target_dir / "f1"), fs::filesystem_error);
BOOST_TEST_THROWS(fs::copy(root_dir / "d1", target_dir / "f1"), fs::filesystem_error);
BOOST_TEST_THROWS(fs::copy(target_dir, target_dir), fs::filesystem_error);
BOOST_TEST_THROWS(fs::copy(target_dir / "f1", target_dir / "f1"), fs::filesystem_error);
if (symlinks_supported)
{
// Should fail with is_a_directory error code
BOOST_TEST_THROWS(fs::copy(root_dir, target_dir, fs::copy_options::create_symlinks), fs::filesystem_error);
}
fs::remove_all(target_dir);
}
} // namespace
int main()
{
try
{
fs::path root_dir = create_tree();
test_copy_file_default(root_dir);
test_copy_dir_default(root_dir, false);
test_copy_dir_default_ec(root_dir, false);
test_copy_dir_recursive(root_dir);
test_copy_dir_recursive_tree(root_dir);
bool symlinks_supported = false;
try
{
fs::create_symlink("f1", root_dir / "s1");
symlinks_supported = true;
std::cout << " *** For information only ***\n"
" create_symlink() attempt succeeded"
<< std::endl;
}
catch (fs::filesystem_error& e)
{
std::cout << " *** For information only ***\n"
" create_symlink() attempt failed\n"
" filesystem_error.what() reports: "
<< e.what() << "\n"
" create_symlink() may not be supported on this operating system or file system"
<< std::endl;
}
if (symlinks_supported)
{
test_copy_dir_default(root_dir, true);
test_copy_file_symlinks(root_dir);
}
test_copy_errors(root_dir, symlinks_supported);
fs::remove_all(root_dir);
return boost::report_errors();
}
catch (std::exception& e)
{
std::cout << "FAIL, exception caught: " << boost::diagnostic_information(e) << std::endl;
return 1;
}
}

View File

@@ -0,0 +1,268 @@
// deprecated_test program --------------------------------------------------//
// Copyright Beman Dawes 2002
// Copyright Vladimir Prus 2002
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
// This test verifies that various deprecated names still work. This is
// important to preserve existing code that uses the old names.
#define BOOST_FILESYSTEM_DEPRECATED
#include <boost/filesystem.hpp>
#include <boost/filesystem/string_file.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace fs = boost::filesystem;
using boost::filesystem::path;
#define PATH_CHECK(a, b) check(a, b, __LINE__)
namespace {
std::string platform(BOOST_PLATFORM);
void check(const fs::path& source, const std::string& expected, int line)
{
if (source.generic_string() == expected)
return;
++::boost::detail::test_errors();
std::cout << '(' << line << ") source.string(): \"" << source.string()
<< "\" != expected: \"" << expected
<< "\"" << std::endl;
}
void normalize_test()
{
PATH_CHECK(path("").normalize(), "");
PATH_CHECK(path("/").normalize(), "/");
PATH_CHECK(path("//").normalize(), "//");
PATH_CHECK(path("///").normalize(), "/");
PATH_CHECK(path("f").normalize(), "f");
PATH_CHECK(path("foo").normalize(), "foo");
PATH_CHECK(path("foo/").normalize(), "foo/.");
PATH_CHECK(path("f/").normalize(), "f/.");
PATH_CHECK(path("/foo").normalize(), "/foo");
PATH_CHECK(path("foo/bar").normalize(), "foo/bar");
PATH_CHECK(path("..").normalize(), "..");
PATH_CHECK(path("../..").normalize(), "../..");
PATH_CHECK(path("/..").normalize(), "/..");
PATH_CHECK(path("/../..").normalize(), "/../..");
PATH_CHECK(path("../foo").normalize(), "../foo");
PATH_CHECK(path("foo/..").normalize(), ".");
PATH_CHECK(path("foo/../").normalize(), ".");
PATH_CHECK((path("foo") / "..").normalize(), ".");
PATH_CHECK(path("foo/...").normalize(), "foo/...");
PATH_CHECK(path("foo/.../").normalize(), "foo/.../.");
PATH_CHECK(path("foo/..bar").normalize(), "foo/..bar");
PATH_CHECK(path("../f").normalize(), "../f");
PATH_CHECK(path("/../f").normalize(), "/../f");
PATH_CHECK(path("f/..").normalize(), ".");
PATH_CHECK((path("f") / "..").normalize(), ".");
PATH_CHECK(path("foo/../..").normalize(), "..");
PATH_CHECK(path("foo/../../").normalize(), "../.");
PATH_CHECK(path("foo/../../..").normalize(), "../..");
PATH_CHECK(path("foo/../../../").normalize(), "../../.");
PATH_CHECK(path("foo/../bar").normalize(), "bar");
PATH_CHECK(path("foo/../bar/").normalize(), "bar/.");
PATH_CHECK(path("foo/bar/..").normalize(), "foo");
PATH_CHECK(path("foo/bar/../").normalize(), "foo/.");
PATH_CHECK(path("foo/bar/../..").normalize(), ".");
PATH_CHECK(path("foo/bar/../../").normalize(), ".");
PATH_CHECK(path("foo/bar/../blah").normalize(), "foo/blah");
PATH_CHECK(path("f/../b").normalize(), "b");
PATH_CHECK(path("f/b/..").normalize(), "f");
PATH_CHECK(path("f/b/../").normalize(), "f/.");
PATH_CHECK(path("f/b/../a").normalize(), "f/a");
PATH_CHECK(path("foo/bar/blah/../..").normalize(), "foo");
PATH_CHECK(path("foo/bar/blah/../../bletch").normalize(), "foo/bletch");
PATH_CHECK(path("//net").normalize(), "//net");
PATH_CHECK(path("//net/").normalize(), "//net/");
PATH_CHECK(path("//..net").normalize(), "//..net");
PATH_CHECK(path("//net/..").normalize(), "//net/..");
PATH_CHECK(path("//net/foo").normalize(), "//net/foo");
PATH_CHECK(path("//net/foo/").normalize(), "//net/foo/.");
PATH_CHECK(path("//net/foo/..").normalize(), "//net/");
PATH_CHECK(path("//net/foo/../").normalize(), "//net/.");
PATH_CHECK(path("/net/foo/bar").normalize(), "/net/foo/bar");
PATH_CHECK(path("/net/foo/bar/").normalize(), "/net/foo/bar/.");
PATH_CHECK(path("/net/foo/..").normalize(), "/net");
PATH_CHECK(path("/net/foo/../").normalize(), "/net/.");
PATH_CHECK(path("//net//foo//bar").normalize(), "//net/foo/bar");
PATH_CHECK(path("//net//foo//bar//").normalize(), "//net/foo/bar/.");
PATH_CHECK(path("//net//foo//..").normalize(), "//net/");
PATH_CHECK(path("//net//foo//..//").normalize(), "//net/.");
PATH_CHECK(path("///net///foo///bar").normalize(), "/net/foo/bar");
PATH_CHECK(path("///net///foo///bar///").normalize(), "/net/foo/bar/.");
PATH_CHECK(path("///net///foo///..").normalize(), "/net");
PATH_CHECK(path("///net///foo///..///").normalize(), "/net/.");
if (platform == "Windows")
{
PATH_CHECK(path("c:..").normalize(), "c:..");
PATH_CHECK(path("c:foo/..").normalize(), "c:");
PATH_CHECK(path("c:foo/../").normalize(), "c:.");
PATH_CHECK(path("c:/foo/..").normalize(), "c:/");
PATH_CHECK(path("c:/foo/../").normalize(), "c:/.");
PATH_CHECK(path("c:/..").normalize(), "c:/..");
PATH_CHECK(path("c:/../").normalize(), "c:/../.");
PATH_CHECK(path("c:/../..").normalize(), "c:/../..");
PATH_CHECK(path("c:/../../").normalize(), "c:/../../.");
PATH_CHECK(path("c:/../foo").normalize(), "c:/../foo");
PATH_CHECK(path("c:/../foo/").normalize(), "c:/../foo/.");
PATH_CHECK(path("c:/../../foo").normalize(), "c:/../../foo");
PATH_CHECK(path("c:/../../foo/").normalize(), "c:/../../foo/.");
PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo");
}
else // POSIX
{
PATH_CHECK(path("c:..").normalize(), "c:..");
PATH_CHECK(path("c:foo/..").normalize(), ".");
PATH_CHECK(path("c:foo/../").normalize(), ".");
PATH_CHECK(path("c:/foo/..").normalize(), "c:");
PATH_CHECK(path("c:/foo/../").normalize(), "c:/.");
PATH_CHECK(path("c:/..").normalize(), ".");
PATH_CHECK(path("c:/../").normalize(), ".");
PATH_CHECK(path("c:/../..").normalize(), "..");
PATH_CHECK(path("c:/../../").normalize(), "../.");
PATH_CHECK(path("c:/../foo").normalize(), "foo");
PATH_CHECK(path("c:/../foo/").normalize(), "foo/.");
PATH_CHECK(path("c:/../../foo").normalize(), "../foo");
PATH_CHECK(path("c:/../../foo/").normalize(), "../foo/.");
PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo");
}
}
// misc_test ------------------------------------------------------------------------//
void misc_test()
{
fs::path p;
fs::initial_path< fs::path >();
fs::initial_path< fs::wpath >();
p.file_string();
p.directory_string();
}
// path_rename_test -----------------------------------------------------------------//
void path_rename_test()
{
fs::path p("foo/bar/blah");
BOOST_TEST_EQ(path("foo/bar/blah").remove_leaf(), "foo/bar");
BOOST_TEST_EQ(p.leaf(), "blah");
BOOST_TEST_EQ(p.branch_path(), "foo/bar");
BOOST_TEST(p.has_leaf());
BOOST_TEST(p.has_branch_path());
BOOST_TEST(!p.is_complete());
if (platform == "Windows")
{
BOOST_TEST_EQ(path("foo\\bar\\blah").remove_leaf(), "foo\\bar");
p = "foo\\bar\\blah";
BOOST_TEST_EQ(p.branch_path(), "foo\\bar");
}
}
// string_file_tests ---------------------------------------------------------------//
void string_file_tests(const fs::path& temp_dir)
{
std::cout << "string_file_tests..." << std::endl;
std::string contents("0123456789");
fs::path p(temp_dir / "string_file");
save_string_file(p, contents);
save_string_file(p, contents);
BOOST_TEST_EQ(file_size(p), 10u);
std::string round_trip;
load_string_file(p, round_trip);
BOOST_TEST_EQ(contents, round_trip);
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
int cpp_main(int /*argc*/, char* /*argv*/[])
{
// The choice of platform is make at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
std::cout << "Platform is " << platform << '\n';
BOOST_TEST(fs::initial_path() == fs::current_path());
//path::default_name_check(fs::no_check);
fs::directory_entry de("foo/bar");
de.replace_leaf("", fs::file_status(), fs::file_status());
//de.leaf();
//de.string();
fs::path ng(" no-way, Jose");
BOOST_TEST(!fs::is_regular(ng)); // verify deprecated name still works
BOOST_TEST(!fs::symbolic_link_exists("nosuchfileordirectory"));
const fs::path temp_dir(fs::current_path() / ".." / fs::unique_path("deprecated_test-%%%%-%%%%-%%%%"));
std::cout << "temp_dir is " << temp_dir.string() << std::endl;
fs::create_directory(temp_dir);
misc_test();
path_rename_test();
normalize_test();
string_file_tests(temp_dir);
BOOST_TEST(fs::path("foo/bar").generic() == fs::path("foo/bar"));
// extension() tests ---------------------------------------------------------//
BOOST_TEST(fs::extension("a/b") == "");
BOOST_TEST(fs::extension("a/b.txt") == ".txt");
BOOST_TEST(fs::extension("a/b.") == ".");
BOOST_TEST(fs::extension("a.b.c") == ".c");
BOOST_TEST(fs::extension("a.b.c.") == ".");
BOOST_TEST(fs::extension("") == "");
BOOST_TEST(fs::extension("a/") == "");
// basename() tests ----------------------------------------------------------//
BOOST_TEST(fs::basename("b") == "b");
BOOST_TEST(fs::basename("a/b.txt") == "b");
BOOST_TEST(fs::basename("a/b.") == "b");
BOOST_TEST(fs::basename("a.b.c") == "a.b");
BOOST_TEST(fs::basename("a.b.c.") == "a.b.c");
BOOST_TEST(fs::basename("") == "");
// change_extension tests ---------------------------------------------------//
BOOST_TEST(fs::change_extension("a.txt", ".tex").string() == "a.tex");
BOOST_TEST(fs::change_extension("a.", ".tex").string() == "a.tex");
BOOST_TEST(fs::change_extension("a", ".txt").string() == "a.txt");
BOOST_TEST(fs::change_extension("a.b.txt", ".tex").string() == "a.b.tex");
// see the rationale in html docs for explanation why this works
BOOST_TEST(fs::change_extension("", ".png").string() == ".png");
std::cout << "post-test removal of " << temp_dir << std::endl;
BOOST_TEST(fs::remove_all(temp_dir) != 0);
return ::boost::report_errors();
}

View File

@@ -0,0 +1,81 @@
#include <string>
#include <iostream>
// Minimal class path
class path
{
public:
path(const char*)
{
std::cout << "path( const char * )\n";
}
path(const std::string&)
{
std::cout << "path( std::string & )\n";
}
// for maximum efficiency, either signature must work
#ifdef BY_VALUE
operator const std::string() const
#else
operator const std::string&() const
#endif
{
std::cout << "operator string\n";
return m_path;
}
#ifdef NAMED_CONVERSION
std::string string() const
{
std::cout << "std::string string() const\n";
return m_path;
}
#endif
private:
std::string m_path;
};
bool operator==(const path&, const path&)
{
std::cout << "operator==( const path &, const path & )\n";
return true;
}
// These are the critical use cases. If any of these don't compile, usability
// is unacceptably degraded.
void f(const path&)
{
std::cout << "f( const path & )\n";
}
int main()
{
f("foo");
f(std::string("foo"));
f(path("foo"));
std::cout << '\n';
std::string s1(path("foo"));
std::string s2 = path("foo");
s2 = path("foo");
#ifdef NAMED_CONVERSION
s2 = path("foo").string();
#endif
std::cout << '\n';
// these must call bool path( const path &, const path & );
path("foo") == path("foo");
path("foo") == "foo";
path("foo") == std::string("foo");
"foo" == path("foo");
std::string("foo") == path("foo");
return 0;
}

View File

@@ -0,0 +1,39 @@
// equivalent program -------------------------------------------------------//
// Copyright (c) 2004 Beman Dawes
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
// at http://www.boost.org/LICENSE_1_0.txt)
// See library home page at http://www.boost.org/libs/filesystem
//----------------------------------------------------------------------------//
#include <boost/filesystem/operations.hpp>
#include <iostream>
#include <exception>
int main(int argc, char* argv[])
{
boost::filesystem::path::default_name_check(boost::filesystem::native);
if (argc != 3)
{
std::cout << "Usage: equivalent path1 path2\n";
return 2;
}
bool eq;
try
{
eq = boost::filesystem::equivalent(argv[1], argv[2]);
}
catch (const std::exception& ex)
{
std::cout << ex.what() << "\n";
return 3;
}
std::cout << (eq ? "Paths are equivalent\n" : "Paths are not equivalent\n");
return !eq;
}

View File

@@ -0,0 +1,62 @@
// Copyright 2018 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/filesystem
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/config.hpp>
namespace fs = boost::filesystem;
int main()
{
{
fs::directory_iterator const it;
BOOST_FOREACH(fs::path const& p, it)
{
p.string();
}
}
#if !defined(BOOST_NO_CXX11_RANGE_BASED_FOR)
{
fs::directory_iterator const it;
for (fs::path const& p : it)
{
p.string();
}
}
#endif
{
fs::recursive_directory_iterator it;
BOOST_FOREACH(fs::path const& p, it)
{
p.string();
}
}
#if !defined(BOOST_NO_CXX11_RANGE_BASED_FOR)
{
fs::recursive_directory_iterator const it;
for (fs::path const& p : it)
{
p.string();
}
}
#endif
}

View File

@@ -0,0 +1,164 @@
// fstream_test.cpp ------------------------------------------------------------------//
// Copyright Beman Dawes 2002
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
#include <string>
#include <iostream>
#include <cstdio> // for std::remove
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
namespace fs = boost::filesystem;
#include <boost/config.hpp>
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std {
using ::remove;
}
#endif
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace {
bool cleanup = true;
void test(const fs::path& p)
{
fs::remove(p);
{
std::cout << " in test 1\n";
fs::filebuf fb1;
fb1.open(p, std::ios_base::out);
BOOST_TEST(fb1.is_open());
}
{
std::cout << " in test 2\n";
fs::filebuf fb2;
fb2.open(p, std::ios_base::in);
BOOST_TEST(fb2.is_open());
}
{
std::cout << " in test 3\n";
fs::ifstream tfs(p);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 4\n";
fs::ifstream tfs(p / p.filename()); // should fail
BOOST_TEST(!tfs.is_open());
}
{
std::cout << " in test 5\n";
fs::ifstream tfs(p, std::ios_base::in);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 6\n";
fs::ifstream tfs;
tfs.open(p);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 7\n";
fs::ifstream tfs;
tfs.open(p, std::ios_base::in);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 8\n";
fs::ofstream tfs(p);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 9\n";
fs::ofstream tfs(p, std::ios_base::out);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 10\n";
fs::ofstream tfs;
tfs.open(p);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 11\n";
fs::ofstream tfs;
tfs.open(p, std::ios_base::out);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 12\n";
fs::fstream tfs(p);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 13\n";
fs::fstream tfs(p, std::ios_base::in | std::ios_base::out);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 14\n";
fs::fstream tfs;
tfs.open(p);
BOOST_TEST(tfs.is_open());
}
{
std::cout << " in test 15\n";
fs::fstream tfs;
tfs.open(p, std::ios_base::in | std::ios_base::out);
BOOST_TEST(tfs.is_open());
}
if (cleanup)
fs::remove(p);
} // test
} // unnamed namespace
int cpp_main(int argc, char*[])
{
if (argc > 1)
cleanup = false;
std::cout << "BOOST_FILESYSTEM_C_STR(p) defined as \""
<< BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR(p)) << "\"\n";
// test narrow characters
std::cout << "narrow character tests:\n";
test("narrow_fstream_test");
// So that tests are run with known encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet());
fs::path::imbue(loc);
// test with some wide characters
// \u2780 is circled 1 against white background == e2 9e 80 in UTF-8
// \u2781 is circled 2 against white background == e2 9e 81 in UTF-8
// \u263A is a white smiling face
std::cout << "\nwide character tests:\n";
std::wstring ws(L"wide_fstream_test_");
ws.push_back(static_cast< wchar_t >(0x2780));
ws.push_back(static_cast< wchar_t >(0x263A));
test(ws);
return ::boost::report_errors();
}

View File

@@ -0,0 +1,7 @@
#include <boost/filesystem.hpp>
int main(void)
{
boost::filesystem::copy_file("a", "b");
return 0;
}

View File

@@ -0,0 +1,17 @@
// Linux test; before running: export LANG=foo
#include <locale>
#include <iostream>
#include <string>
#include <boost/filesystem/path.hpp>
int main()
{
std::string pathname = "/some/filesystem/path/%%%%";
boost::filesystem::path path(pathname);
std::wcout << path.wstring() << std::endl;
return 0;
}

View File

@@ -0,0 +1,14 @@
// Copyright iamvfx@gmail.com 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include <stdio.h>
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path dir("/");
for (char c : dir.filename().string())
printf("%c\n", c);
}

View File

@@ -0,0 +1,22 @@
#include <iostream>
#include <boost/filesystem/path.hpp>
using namespace std;
namespace fs = boost::filesystem;
int main(int argc, char** argv)
{
try
{
fs::path my_path("test/test.txt");
cout << "current path is " << my_path << endl;
cout << "parent path is " << my_path.parent_path() << endl;
}
catch (std::exception& e)
{
cerr << endl
<< "Error during execution: " << e.what() << endl
<< endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,40 @@
#include <boost/filesystem.hpp>
#include <boost/thread.hpp>
#include <fstream>
boost::condition_variable cond;
boost::mutex mut;
#define FNAME ("remove-test")
void remover()
{
while (1)
{
boost::filesystem::remove(FNAME);
}
}
void creater()
{
for (int i = 0; i < 100000; i++)
std::fstream(FNAME, std::fstream::out);
}
int main()
{
boost::filesystem::remove(FNAME);
boost::filesystem::remove(FNAME);
std::cout << "If you got this far, it's OK to remove a file that doesn't exist\n"
"Now trying with one creator thread and two remover threads.\n"
"This is likely to crash after just a few seconds at most."
<< std::endl;
boost::thread c(creater), r1(remover), r2(remover);
c.join();
r1.interrupt();
r1.join();
r2.interrupt();
r2.join();
}

View File

@@ -0,0 +1,24 @@
#include <boost/filesystem.hpp>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <vector>
#include <iostream>
namespace fs = boost::filesystem;
using namespace boost::adaptors;
int main()
{
fs::recursive_directory_iterator beg("."), end;
auto fileFilter = [](fs::path const& path) {
return is_regular_file(path);
};
std::vector< fs::path > paths;
copy(boost::make_iterator_range(beg, end) | filtered(fileFilter), std::back_inserter(paths));
for (auto& p : paths)
std::cout << p << "\n";
}

View File

@@ -0,0 +1,37 @@
#include <boost/filesystem.hpp>
#include <cvt/cp950>
#include <iostream>
#include <string>
#include <locale>
namespace fs = boost::filesystem;
int main(void)
{
std::locale global_loc = std::locale();
std::locale loc(global_loc, new stdext::cvt::codecvt_cp950< wchar_t >);
fs::path::imbue(loc);
std::cout << "HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n"
"WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n"
"EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW."
<< std::endl;
fs::recursive_directory_iterator end;
fs::recursive_directory_iterator iter("C:/boost/test-files/utf-8");
while (iter != end)
{
if (fs::is_directory(*iter))
{
std::cout << "[directory] " << iter->path().generic_string() << std::endl;
}
else if (fs::is_regular(*iter))
{
std::cout << " [file] " << iter->path().generic_string() << std::endl;
}
++iter;
}
return 0;
}

View File

@@ -0,0 +1,18 @@
#include <iostream>
#include <boost/filesystem.hpp>
using boost::filesystem::path;
int main()
{
std::cout << path("a").stem() << std::endl;
std::cout << path("a/").stem() << std::endl;
std::cout << path("a/b").stem() << std::endl;
std::cout << path("a/b/").stem() << std::endl;
std::cout << path("a/b/c").stem() << std::endl;
std::cout << path("a/b/c/").stem() << std::endl;
std::cout << path("a/b/c/d").stem() << std::endl;
std::cout << path("a/b/c/d/").stem() << std::endl;
std::cout << path("a/b/c/d/e").stem() << std::endl;
std::cout << path("a/b/c/d/e/").stem() << std::endl;
return 0;
}

View File

@@ -0,0 +1,36 @@
#include <boost/filesystem.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <string>
using namespace boost::filesystem;
// The original bug report was that this broke:
// path p(L"C:\\TEMP\\");
// path r(p / "narrow");
// That code now works, but ...
// Nils Gladitz has provided this example ...
class Test
{
public:
~Test()
{
path p(L"C:\\TEMP\\");
path r(p / "narrow");
}
};
// path p("narrow");
// fails if static linked and Test object is global variable, but does not fail if
// path p("narrow") line above is not commented out, and also does not fail if the
// Test test2 line below is commented out.
Test test1;
Test test2;
int cpp_main(int, char*[])
{
return 0;
}

View File

@@ -0,0 +1,20 @@
// Copyright 2018 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/filesystem
#include <boost/filesystem.hpp>
#include <boost/core/lightweight_test.hpp>
namespace fs = boost::filesystem;
int main()
{
BOOST_TEST_THROWS(fs::copy("/tmp/non-existent-a", "/tmp/non-existent-b"), std::exception);
return boost::report_errors();
}

View File

@@ -0,0 +1,7 @@
// Before running this test: export LANG=foo
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path("/abc").root_directory();
}

View File

@@ -0,0 +1,9 @@
#include "boost/filesystem.hpp"
static const boost::filesystem::path::codecvt_type& dummy =
boost::filesystem::path::codecvt();
int main()
{
return 0;
}

View File

@@ -0,0 +1,40 @@
// Boost 9219.cpp --------------------------------------------------------------------//
// Copyright Beman Dawes 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// //
// In researching filesystem issues it is convenient to have a program that can be //
// quickly modified to test reported problems. That's the purpose of this file and //
// its associated Visual Studio and Boost.Build infrastructure. //
// //
//--------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
using std::cout;
using std::endl;
namespace fs = boost::filesystem;
//------------------------------------ cpp_main --------------------------------------//
int cpp_main(int argc, char* argv[])
{
cout << "Hello, 9219" << endl;
cout << "This is a test for non-Windows systems" << endl;
BOOST_TEST(fs::exists(const_cast< char* >(".")));
return ::boost::report_errors();
} // cpp_main

View File

@@ -0,0 +1,85 @@
// Boost operations_test.cpp ---------------------------------------------------------//
// Copyright Alexander Grund 2020
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#if defined(BOOST_FILESYSTEM_HAS_MKLINK)
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdlib>
#include <vector>
namespace fs = boost::filesystem;
struct TmpDir
{
fs::path path;
TmpDir(const fs::path& base) :
path(fs::absolute(base) / fs::unique_path())
{
fs::create_directories(path);
}
~TmpDir()
{
boost::system::error_code ec;
fs::remove_all(path, ec);
}
};
// Test fs::canonical for various path in a Windows directory junction point
// This failed before due to broken handling of absolute paths and ignored ReparseTag
int main()
{
const fs::path cwd = fs::current_path();
const TmpDir tmp(cwd);
const fs::path junction = tmp.path / "junction";
const fs::path real = tmp.path / "real";
const fs::path subDir = "sub";
fs::create_directories(real / subDir);
fs::current_path(tmp.path);
BOOST_TEST(std::system("mklink /J junction real") == 0);
BOOST_TEST(fs::exists(junction));
// Due to a bug there was a dependency on the current path so try the below for all:
std::vector< fs::path > paths;
paths.push_back(cwd);
paths.push_back(junction);
paths.push_back(real);
paths.push_back(junction / subDir);
paths.push_back(real / subDir);
for (std::vector< fs::path >::iterator it = paths.begin(); it != paths.end(); ++it)
{
std::cout << "Testing in " << *it << std::endl;
fs::current_path(*it);
// Used by canonical, must work too
BOOST_TEST(fs::read_symlink(junction) == real);
BOOST_TEST(fs::canonical(junction) == real);
BOOST_TEST(fs::canonical(junction / subDir) == real / subDir);
}
// Restore the original current directory so that temp directory can be removed
fs::current_path(cwd);
return boost::report_errors();
}
#else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
int main()
{
std::cout << "Skipping test as the target system does not support mklink." << std::endl;
return 0;
}
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)

View File

@@ -0,0 +1,38 @@
# Boost Filesystem test/issues Jamfile
# Copyright Beman Dawes 2014
# Distributed under the Boost Software License, Version 1.0.
# See www.boost.org/LICENSE_1_0.txt
# Library home page: http://www.boost.org/libs/filesystem
project
: requirements
<library>/boost/filesystem//boost_filesystem
<link>static
;
test-suite "filesystem-issues" :
# [ run 9054_static_const_codecvt_segfault_pre_main.cpp
# : : : <link>shared : 9054_shared ]
# [ run 9054_static_const_codecvt_segfault_pre_main.cpp
# : : : <link>static : 9054_static ]
# [ run hello_filesystem.cpp
# : : : <link>shared : hello_shared ]
# [ run hello_filesystem.cpp
# : : : <link>static : hello_static ]
# [ run 9219.cpp
# : : : <link>shared : 9219_shared ]
# [ run 9219.cpp
# : : : <link>static : 9219_static ]
# [ run 10485.cpp
# : : : <link>shared <test-info>always_show_run_output ]
# [ run copy_file-compilation-error-2015-05-04.cpp ]
[ run 6638-convert_aux-fails-init-global.cpp
: : : <link>shared : 6638_shared ]
[ run 6638-convert_aux-fails-init-global.cpp
: : : <link>static : 6638_static ]
;

View File

@@ -0,0 +1,14 @@
// Rob Conde <rob.conde@ai-solutions.com> reports this fails
// to compile for Boost 1.58 with g++ 4.4.7 but is OK with FC++ 2013
#include "boost/filesystem/operations.hpp"
void myFunc()
{
using namespace boost::filesystem;
copy_options opt(copy_options::overwrite_existing);
copy_file(path("p1"), path("p2"), copy_options::overwrite_existing);
// copy_file(path("p1"),path("p2"),opt);
}

View File

@@ -0,0 +1,41 @@
// Test program to demonstrate that Linux does not support AT_SYMLINK_NOFOLLOW
// Copyright Duncan Exon Smith 2012
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Test this by running:
//
// rm -rf data && mkdir data && g++ -otest-fchmodat fchmodat_AT_SYMLINK_NOFOLLOW_6659.cpp && (cd data && ../test-fchmodat)
//
// If no assertions go off, then it looks like fchmodat is supported,
// but AT_SYMLINK_NOFOLLOW is not supported.
#include <fstream>
#include <cassert>
#include <fcntl.h>
#include <sys/stat.h>
#include <cerrno>
#ifdef NDEBUG
#error This program depends on assert() so makes no sense if NDEBUG is defined
#endif
int main(int argc, char* argv[])
{
{
std::ofstream file("out");
file << "contents";
}
assert(!::symlink("out", "sym"));
assert(!::fchmodat(AT_FDCWD, "out", S_IRUSR | S_IWUSR | S_IXUSR, 0));
assert(!::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, 0));
assert(::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, AT_SYMLINK_NOFOLLOW) == -1);
assert(errno == ENOTSUP);
return 0;
}

View File

@@ -0,0 +1,39 @@
// Boost hello_filesystem.cpp --------------------------------------------------------//
// Copyright Beman Dawes 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// //
// In researching filesystem issues it is convenient to have a program that can be //
// quickly modified to test reported problems. That's the purpose of this file and //
// its associated Visual Studio and Boost.Build infrastructure. //
// //
//--------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
using std::cout;
using std::endl;
namespace fs = boost::filesystem;
//------------------------------------ cpp_main --------------------------------------//
int cpp_main(int argc, char* argv[])
{
cout << "Hello, filesystem world" << endl;
BOOST_TEST(fs::exists("."));
return ::boost::report_errors();
} // cpp_main

View File

@@ -0,0 +1,9 @@
This directory contains tests related to specific issues.
The names are intended to indicate both the function or condition being tested
and the issue number.
-----
Copyright Beman Dawes 2012
Distributed under the Boost Software License, Version 1.0.
See http://www.boost.org/LICENSE_1_0.txt

View File

@@ -0,0 +1,116 @@
// Boost Filesystem recurse_dir_iter_test.cpp ----------------------------------------//
// Copyright Beman Dawes 2014.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/operations.hpp>
#include <boost/cerrno.hpp>
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace fs = boost::filesystem;
using boost::system::error_code;
#include <iostream>
using std::cout;
using std::endl;
namespace {
typedef int errno_t;
std::string platform(BOOST_PLATFORM);
bool report_throws = false;
bool cleanup = true;
bool skip_long_windows_tests = false;
} // unnamed namespace
//------------------------------------------------------------------------------------//
// //
// main //
// //
//------------------------------------------------------------------------------------//
int cpp_main(int argc, char* argv[])
{
// document state of critical macros
#ifdef BOOST_POSIX_API
cout << "BOOST_POSIX_API is defined\n";
#endif
#ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API is defined\n";
#endif
for (; argc > 1; --argc, ++argv)
{
//if (*argv[1]=='-' && *(argv[1]+1)=='t')
// report_throws = true;
//else if (*argv[1]=='-' && *(argv[1]+1)=='x')
// cleanup = false;
//else if (*argv[1]=='-' && *(argv[1]+1)=='w')
// skip_long_windows_tests = true;
}
// The choice of platform to test is made at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
#if defined(BOOST_POSIX_API)
platform = "POSIX";
#elif defined(BOOST_WINDOWS_API)
platform = "Windows";
#else
#error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
#endif
cout << "API is " << platform << endl;
cout << "initial_path() is " << fs::initial_path() << endl;
fs::path ip = fs::initial_path();
for (fs::path::const_iterator it = ip.begin(); it != ip.end(); ++it)
{
if (it != ip.begin())
cout << ", ";
cout << *it;
}
cout << endl;
// From the root, walk the directory tree looking for a permissions error
fs::recursive_directory_iterator it("/");
fs::recursive_directory_iterator end_it;
// The increment function has an invarient that it always makes progress,
// so even if an error occurs this loop will eventually terminate.
while (it != end_it)
{
error_code ec;
fs::path init_path = it->path();
it.increment(ec);
if (ec)
{
cout << "initial path: " << init_path << endl;
cout << "error_code: " << ec.value() << " with msg: " << ec.message() << endl;
if (it != end_it)
cout << "post-increment path: " << it->path() << endl;
}
}
cout << "returning from main()" << endl;
return ::boost::report_errors();
}

View File

@@ -0,0 +1,169 @@
// Boost reparse_tag_file_placeholder.cpp ---------------------------------------------------------//
// Copyright Roman Savchenko 2020
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#if defined(BOOST_FILESYSTEM_HAS_MKLINK)
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstddef>
#include <exception>
#include <windows.h>
#include <winnt.h>
#ifdef _MSC_VER
#pragma comment(lib, "Advapi32.lib")
#endif
// Test correct boost::filesystem::status when reparse point ReparseTag set to IO_REPARSE_TAG_FILE_PLACEHOLDER
// https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN
#if !defined(__MINGW32__) || defined(__MINGW64__)
typedef struct _REPARSE_DATA_BUFFER
{
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union
{
struct
{
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
ULONG Flags;
WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer;
struct
{
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
} MountPointReparseBuffer;
struct
{
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
#endif
#ifndef IO_REPARSE_TAG_FILE_PLACEHOLDER
#define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L)
#endif
#ifndef FSCTL_SET_REPARSE_POINT
#define FSCTL_SET_REPARSE_POINT (0x000900a4)
#endif
#ifndef REPARSE_DATA_BUFFER_HEADER_SIZE
#define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
#endif
bool obtain_restore_privilege()
{
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
DWORD err = GetLastError();
std::cout << "OpenProcessToken() failed with: " << err << std::endl;
return false;
}
TOKEN_PRIVILEGES tp;
if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tp.Privileges[0].Luid))
{
DWORD err = GetLastError();
CloseHandle(hToken);
std::cout << "LookupPrivilegeValue() failed with: " << err << std::endl;
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{
DWORD err = GetLastError();
CloseHandle(hToken);
std::cout << "AdjustTokenPrivileges() failed with: " << err << std::endl;
return false;
}
CloseHandle(hToken);
return true;
}
bool create_io_reparse_file_placeholder(const wchar_t* name)
{
if (!obtain_restore_privilege())
{
return false;
}
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT, 0);
if (hHandle == INVALID_HANDLE_VALUE)
{
DWORD err = GetLastError();
std::cout << "CreateFile() failed with: " << err << std::endl;
return false;
}
PREPARSE_DATA_BUFFER pReparse = reinterpret_cast< PREPARSE_DATA_BUFFER >(GlobalAlloc(GPTR, MAXIMUM_REPARSE_DATA_BUFFER_SIZE));
if (!pReparse)
{
DWORD err = GetLastError();
CloseHandle(hHandle);
std::cout << "GlobalAlloc() failed with: " << err << std::endl;
return false;
}
//note: IO_REPARSE_TAG_FILE_PLACEHOLDER - just to show that reparse point could be not only symlink or junction
pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER;
DWORD dwLen;
bool ret = !!DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE, NULL, 0, &dwLen, NULL);
if (!ret)
{
DWORD err = GetLastError();
std::cout << "DeviceIoControl() failed with: " << err << std::endl;
}
CloseHandle(hHandle);
GlobalFree(pReparse);
return ret;
}
int main()
{
boost::filesystem::path rpt = boost::filesystem::temp_directory_path() / "reparse_point_test.txt";
BOOST_TEST(create_io_reparse_file_placeholder(rpt.native().c_str()));
std::cout << "Created file placeholder reparse point: " << rpt.string() << std::endl;
BOOST_TEST_NO_THROW(BOOST_TEST(boost::filesystem::status(rpt).type() == boost::filesystem::reparse_file));
BOOST_TEST_NO_THROW(BOOST_TEST(boost::filesystem::remove(rpt)));
return boost::report_errors();
}
#else // defined(BOOST_FILESYSTEM_HAS_MKLINK)
int main()
{
std::cout << "Skipping test as the target system does not support mklink." << std::endl;
return 0;
}
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)

View File

@@ -0,0 +1,36 @@
// Boost large_file_support_test.cpp ---------------------------------------//
// Copyright Beman Dawes 2004.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See library home page at http://www.boost.org/libs/filesystem
// See deprecated_test for tests of deprecated features
#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/filesystem/operations.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main()
{
if (fs::detail::possible_large_file_size_support())
{
std::cout << "It appears that file sizes greater that 2 gigabytes are possible\n"
"for this configuration on this platform since the operating system\n"
"does use a large enough integer type to report large file sizes.\n\n"
"Whether or not such support is actually present depends on the OS\n";
return 0;
}
std::cout << "The operating system is using an integer type to report file sizes\n"
"that can not represent file sizes greater that 2 gigabytes (31-bits).\n"
"Thus the Filesystem Library will not correctly deal with such large\n"
"files. If you think that this operatiing system should be able to\n"
"support large files, please report the problem to the Boost developers\n"
"mailing list.\n";
return 1;
}

View File

@@ -0,0 +1,85 @@
// locale_info.cpp ---------------------------------------------------------//
// Copyright Beman Dawes 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include <locale>
#include <iostream>
#include <exception>
#include <cstdlib>
using namespace std;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe
#endif
namespace {
void facet_info(const locale& loc, const char* msg)
{
cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >("
<< msg << ") is "
<< (has_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc) ? "true\n" : "false\n");
}
void default_info()
{
try
{
locale loc;
cout << "\nlocale default construction OK" << endl;
facet_info(loc, "locale()");
}
catch (const exception& ex)
{
cout << "\nlocale default construction threw: " << ex.what() << endl;
}
}
void null_string_info()
{
try
{
locale loc("");
cout << "\nlocale(\"\") construction OK" << endl;
facet_info(loc, "locale(\"\")");
}
catch (const exception& ex)
{
cout << "\nlocale(\"\") construction threw: " << ex.what() << endl;
}
}
void classic_info()
{
try
{
locale loc(locale::classic());
cout << "\nlocale(locale::classic()) copy construction OK" << endl;
facet_info(loc, "locale::classic()");
}
catch (const exception& ex)
{
cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
}
}
} // namespace
int main()
{
const char* lang = getenv("LANG");
cout << "\nLANG environmental variable is "
<< (lang ? lang : "not present") << endl;
default_info();
null_string_info();
classic_info();
return 0;
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif

View File

@@ -0,0 +1,57 @@
// long_path_test.cpp ----------------------------------------------------------------//
// Copyright Beman Dawes 2011
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/btree for documentation.
// See http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
using namespace boost::filesystem;
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace {
} // unnamed namespace
int cpp_main(int, char*[])
{
std::string prefix("d:\\temp\\");
std::cout << "prefix is " << prefix << '\n';
const std::size_t safe_size = 260 - prefix.size() - 100; // Windows MAX_PATH is 260
std::string safe_x_string(safe_size, 'x');
std::string safe_y_string(safe_size, 'y');
std::string path_escape("\\\\?\\");
path x_p(prefix + safe_x_string);
path y_p(path_escape + prefix + safe_x_string + "\\" + safe_y_string);
std::cout << "x_p.native().size() is " << x_p.native().size() << '\n';
std::cout << "y_p.native().size() is " << y_p.native().size() << '\n';
create_directory(x_p);
BOOST_TEST(exists(x_p));
create_directory(y_p);
BOOST_TEST(exists(y_p));
//std::cout << "directory x.../y... ready for testing, where ... is " << safe_size
// << " repeats of x and y, respectively\n";
BOOST_TEST(exists(x_p));
//remove_all(x_p);
return ::boost::report_errors();
}

View File

@@ -0,0 +1,35 @@
// macro_default_test program --------------------------------------------------------//
// Copyright Beman Dawes 2012
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#undef BOOST_ALL_DYN_LINK
#undef BOOST_ALL_STATIC_LINK
#undef BOOST_FILESYSTEM_DYN_LINK
#undef BOOST_FILESYSTEM_STATIC_LINK
#undef BOOST_SYSTEM_DYN_LINK
#undef BOOST_SYSTEM_STATIC_LINK
#ifndef BOOST_ALL_NO_LIB
#define BOOST_ALL_NO_LIB
#endif
#include <boost/filesystem/config.hpp>
#include <boost/system/config.hpp>
#ifndef BOOST_FILESYSTEM_STATIC_LINK
#error BOOST_FILESYSTEM_STATIC_LINK not set by default
#endif
#ifndef BOOST_SYSTEM_STATIC_LINK
#error BOOST_SYSTEM_STATIC_LINK not set by default
#endif
int main()
{
return 0;
}

View File

@@ -0,0 +1,22 @@
// Boost Filesystem odr1_test.cpp ----------------------------------------------------//
// Copyright Beman Dawes 2014.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/filesystem.hpp>
namespace boost {
namespace filesystem {
void tu2();
}
} // namespace boost
int main()
{
boost::filesystem::tu2();
return 0;
}

View File

@@ -0,0 +1,20 @@
// Boost Filesystem odr2_test.cpp ----------------------------------------------------//
// Copyright Beman Dawes 2014.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/filesystem.hpp>
namespace boost {
namespace filesystem {
void tu2()
{
}
} // namespace filesystem
} // namespace boost

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,380 @@
// operations_unit_test.cpp ----------------------------------------------------------//
// Copyright Beman Dawes 2008, 2009, 2015
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
// ------------------------------------------------------------------------------------//
// This program is misnamed - it is really a smoke test rather than a unit test
// ------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem.hpp> // make sure filesystem.hpp works
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <iostream>
using namespace boost::filesystem;
using namespace boost::system;
using std::cout;
using std::endl;
using std::string;
#define CHECK(x) check(x, __FILE__, __LINE__)
namespace {
bool cleanup = true;
void check(bool ok, const char* file, int line)
{
if (ok)
return;
++::boost::detail::test_errors();
cout << file << '(' << line << "): test failed\n";
}
// file_status_test ----------------------------------------------------------------//
void file_status_test()
{
cout << "file_status test..." << endl;
file_status s = status(".");
int v = s.permissions();
cout << " status(\".\") permissions are "
<< std::oct << (v & 0777) << std::dec << endl;
CHECK((v & 0400) == 0400);
s = symlink_status(".");
v = s.permissions();
cout << " symlink_status(\".\") permissions are "
<< std::oct << (v & 0777) << std::dec << endl;
CHECK((v & 0400) == 0400);
}
// query_test ----------------------------------------------------------------------//
void query_test()
{
cout << "query test..." << endl;
error_code ec;
CHECK(file_size("no-such-file", ec) == static_cast< boost::uintmax_t >(-1));
CHECK(ec == errc::no_such_file_or_directory);
CHECK(status("no-such-file") == file_status(file_not_found, no_perms));
CHECK(exists("/"));
CHECK(is_directory("/"));
CHECK(!exists("no-such-file"));
exists("/", ec);
if (ec)
{
cout << "exists(\"/\", ec) resulted in non-zero ec.value()" << endl;
cout << "ec value: " << ec.value() << ", message: " << ec.message() << endl;
}
CHECK(!ec);
CHECK(exists("/"));
CHECK(is_directory("/"));
CHECK(!is_regular_file("/"));
CHECK(!boost::filesystem::is_empty("/"));
CHECK(!is_other("/"));
}
// directory_iterator_test -----------------------------------------------//
void directory_iterator_test()
{
cout << "directory_iterator_test..." << endl;
directory_iterator end;
directory_iterator it(".");
CHECK(!it->path().empty());
if (is_regular_file(it->status()))
{
CHECK(is_regular_file(it->symlink_status()));
CHECK(!is_directory(it->status()));
CHECK(!is_symlink(it->status()));
CHECK(!is_directory(it->symlink_status()));
CHECK(!is_symlink(it->symlink_status()));
}
else
{
CHECK(is_directory(it->status()));
CHECK(is_directory(it->symlink_status()));
CHECK(!is_regular_file(it->status()));
CHECK(!is_regular_file(it->symlink_status()));
CHECK(!is_symlink(it->status()));
CHECK(!is_symlink(it->symlink_status()));
}
for (; it != end; ++it)
{
//cout << " " << it->path() << "\n";
}
CHECK(directory_iterator(".") != directory_iterator());
CHECK(directory_iterator() == end);
#ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
for (directory_entry& x : directory_iterator("."))
{
CHECK(!x.path().empty());
//cout << " " << x.path() << "\n";
}
const directory_iterator dir_itr(".");
for (directory_entry& x : dir_itr)
{
CHECK(!x.path().empty());
//cout << " " << x.path() << "\n";
}
#endif
for (directory_iterator itr("."); itr != directory_iterator(); ++itr)
{
CHECK(!itr->path().empty());
//cout << " " << itr->path() << "\n";
}
cout << "directory_iterator_test complete" << endl;
}
// recursive_directory_iterator_test -----------------------------------------------//
void recursive_directory_iterator_test()
{
cout << "recursive_directory_iterator_test..." << endl;
recursive_directory_iterator end;
recursive_directory_iterator it(".");
CHECK(!it->path().empty());
if (is_regular_file(it->status()))
{
CHECK(is_regular_file(it->symlink_status()));
CHECK(!is_directory(it->status()));
CHECK(!is_symlink(it->status()));
CHECK(!is_directory(it->symlink_status()));
CHECK(!is_symlink(it->symlink_status()));
}
else
{
CHECK(is_directory(it->status()));
CHECK(is_directory(it->symlink_status()));
CHECK(!is_regular_file(it->status()));
CHECK(!is_regular_file(it->symlink_status()));
CHECK(!is_symlink(it->status()));
CHECK(!is_symlink(it->symlink_status()));
}
for (; it != end; ++it)
{
//cout << " " << it->path() << "\n";
}
CHECK(recursive_directory_iterator(".") != recursive_directory_iterator());
CHECK(recursive_directory_iterator() == end);
#ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
for (directory_entry& x : recursive_directory_iterator("."))
{
CHECK(!x.path().empty());
//cout << " " << x.path() << "\n";
}
const recursive_directory_iterator dir_itr(".");
for (directory_entry& x : dir_itr)
{
CHECK(!x.path().empty());
//cout << " " << x.path() << "\n";
}
#endif
for (recursive_directory_iterator itr(".");
itr != recursive_directory_iterator(); ++itr)
{
CHECK(!itr->path().empty());
//cout << " " << itr->path() << "\n";
}
cout << "recursive_directory_iterator_test complete" << endl;
}
// operations_test -------------------------------------------------------//
void operations_test()
{
cout << "operations test..." << endl;
error_code ec;
CHECK(!create_directory("/", ec));
CHECK(!boost::filesystem::remove("no-such-file-or-directory"));
CHECK(!remove_all("no-such-file-or-directory"));
space_info info = space("/");
CHECK(info.available <= info.capacity);
CHECK(equivalent("/", "/"));
CHECK(!equivalent("/", "."));
std::time_t ft = last_write_time(".");
ft = -1;
last_write_time(".", ft, ec);
}
// directory_entry_test ------------------------------------------------------------//
void directory_entry_test()
{
cout << "directory_entry test..." << endl;
directory_entry de("foo.bar", file_status(regular_file, owner_all), file_status(directory_file, group_all));
CHECK(de.path() == "foo.bar");
CHECK(de.status() == file_status(regular_file, owner_all));
CHECK(de.symlink_status() == file_status(directory_file, group_all));
CHECK(de < directory_entry("goo.bar"));
CHECK(de == directory_entry("foo.bar"));
CHECK(de != directory_entry("goo.bar"));
de.replace_filename("bar.foo");
CHECK(de.path() == "bar.foo");
}
// directory_entry_overload_test ---------------------------------------------------//
void directory_entry_overload_test()
{
cout << "directory_entry overload test..." << endl;
directory_iterator it(".");
path p(*it);
}
// error_handling_test -------------------------------------------------------------//
void error_handling_test()
{
cout << "error handling test..." << endl;
bool threw(false);
try
{
file_size("no-such-file");
}
catch (const boost::filesystem::filesystem_error& ex)
{
threw = true;
cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n"
"what() returns "
<< ex.what() << "\n";
}
catch (...)
{
cout << "\nunexpected exception type caught" << endl;
}
CHECK(threw);
error_code ec;
CHECK(!create_directory("/", ec));
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
// //
// main //
// //
//--------------------------------------------------------------------------------------//
int cpp_main(int argc, char* argv[])
{
// document state of critical macros
#ifdef BOOST_POSIX_API
cout << "BOOST_POSIX_API is defined\n";
#endif
#ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API is defined\n";
#endif
cout << "BOOST_FILESYSTEM_DECL" << BOOST_STRINGIZE(=BOOST_FILESYSTEM_DECL) << "\n";
cout << "BOOST_SYMBOL_VISIBLE" << BOOST_STRINGIZE(=BOOST_SYMBOL_VISIBLE) << "\n";
cout << "current_path() is " << current_path().string() << endl;
if (argc >= 2)
{
cout << "argv[1] is '" << argv[1] << "', changing current_path() to it" << endl;
error_code ec;
current_path(argv[1], ec);
if (ec)
{
cout << "current_path('" << argv[1] << "') failed: " << ec << ": " << ec.message() << endl;
}
cout << "current_path() is " << current_path().string() << endl;
}
const path temp_dir(current_path() / ".." / unique_path("op-unit_test-%%%%-%%%%-%%%%"));
cout << "temp_dir is " << temp_dir.string() << endl;
create_directory(temp_dir);
file_status_test();
query_test();
directory_iterator_test();
recursive_directory_iterator_test();
operations_test();
directory_entry_test();
directory_entry_overload_test();
error_handling_test();
cout << unique_path() << endl;
cout << unique_path("foo-%%%%%-%%%%%-bar") << endl;
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%-bar") << endl;
cout << unique_path("foo-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-%%%%%-bar") << endl;
cout << "testing complete" << endl;
// post-test cleanup
if (cleanup)
{
cout << "post-test removal of " << temp_dir << endl;
BOOST_TEST(remove_all(temp_dir) != 0);
// above was added just to simplify testing, but it ended up detecting
// a bug (failure to close an internal search handle).
cout << "post-test removal complete" << endl;
// BOOST_TEST(!fs::exists(dir)); // nice test, but doesn't play well with TortoiseGit cache
}
return ::boost::report_errors();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
// Boost Filesystem path_times.cpp ---------------------------------------------------//
// Copyright Beman Dawes 2013
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/config/warning_disable.hpp>
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/timer/timer.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/cstdint.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace fs = boost::filesystem;
using namespace boost::timer;
#include <fstream>
#include <iostream>
using std::cout;
using std::endl;
namespace {
boost::int64_t max_cycles;
template< class STD_STRING >
nanosecond_type time_ctor(const STD_STRING& s)
{
boost::timer::auto_cpu_timer tmr;
boost::int64_t count = 0;
do
{
fs::path p(s);
++count;
} while (count < max_cycles);
boost::timer::cpu_times elapsed = tmr.elapsed();
return elapsed.user + elapsed.system;
}
nanosecond_type time_loop()
{
boost::timer::auto_cpu_timer tmr;
boost::int64_t count = 0;
do
{
++count;
} while (count < max_cycles);
boost::timer::cpu_times elapsed = tmr.elapsed();
return elapsed.user + elapsed.system;
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
// main //
//--------------------------------------------------------------------------------------//
int cpp_main(int argc, char* argv[])
{
if (argc != 2)
{
cout << "Usage: path_times <cycles-in-millions>\n";
return 1;
}
max_cycles = std::atoi(argv[1]) * 1000000LL;
cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;
cout << "time_loop" << endl;
nanosecond_type x = time_loop();
cout << "time_ctor with string" << endl;
nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));
cout << "time_ctor with wstring" << endl;
nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
if (s > w)
cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl;
else
cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl;
cout << "returning from main()" << endl;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,24 @@
// Copyright 2017 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/system
#include <boost/filesystem.hpp>
#include <boost/core/lightweight_test.hpp>
namespace fs = boost::filesystem;
int main()
{
fs::path p1("a");
fs::path p2 = p1 / "b";
BOOST_TEST_EQ(p2, "a/b");
return boost::report_errors();
}

View File

@@ -0,0 +1,119 @@
// filesystem relative_test.cpp ---------------------------------------------------- //
// Copyright Beman Dawes 2015
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
// ---------------------------------------------------------------------------------- //
//
// At least initially, development is easier if these tests are in a separate file.
//
// ---------------------------------------------------------------------------------- //
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/detail/lightweight_test_report.hpp>
#include <iostream>
using boost::filesystem::path;
using std::cout;
using std::endl;
namespace {
void lexically_relative_test()
{
cout << "lexically_relative_test..." << endl;
BOOST_TEST(path("").lexically_relative("") == "");
BOOST_TEST(path("").lexically_relative("/foo") == "");
BOOST_TEST(path("/foo").lexically_relative("") == "");
BOOST_TEST(path("/foo").lexically_relative("/foo") == ".");
BOOST_TEST(path("").lexically_relative("foo") == "");
BOOST_TEST(path("foo").lexically_relative("") == "");
BOOST_TEST(path("foo").lexically_relative("foo") == ".");
BOOST_TEST(path("a/b/c").lexically_relative("a") == "b/c");
BOOST_TEST(path("a//b//c").lexically_relative("a") == "b/c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b") == "c");
BOOST_TEST(path("a///b//c").lexically_relative("a//b") == "c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/c") == ".");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x") == "..");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");
BOOST_TEST(path("a/b/c").lexically_relative("a/x") == "../b/c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/x") == "../c");
BOOST_TEST(path("a/b/c").lexically_relative("a/x/y") == "../../b/c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/x/y") == "../../c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x/y/z") == "../../..");
BOOST_TEST(path("a/b/c").lexically_relative("a/") == "b/c");
BOOST_TEST(path("a/b/c").lexically_relative("a/.") == "b/c");
BOOST_TEST(path("a/b/c").lexically_relative("a/./") == "b/c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/..") == "");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/../") == "");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/d/..") == "c");
BOOST_TEST(path("a/b/c").lexically_relative("a/b/d/../") == "c");
// paths unrelated except first element, and first element is root directory
BOOST_TEST(path("/a/b/c").lexically_relative("/x") == "../a/b/c");
BOOST_TEST(path("/a/b/c").lexically_relative("/x/y") == "../../a/b/c");
BOOST_TEST(path("/a/b/c").lexically_relative("/x/y/z") == "../../../a/b/c");
// paths unrelated
BOOST_TEST(path("a/b/c").lexically_relative("x") == "");
BOOST_TEST(path("a/b/c").lexically_relative("x/y") == "");
BOOST_TEST(path("a/b/c").lexically_relative("x/y/z") == "");
BOOST_TEST(path("a/b/c").lexically_relative("/x") == "");
BOOST_TEST(path("a/b/c").lexically_relative("/x/y") == "");
BOOST_TEST(path("a/b/c").lexically_relative("/x/y/z") == "");
BOOST_TEST(path("a/b/c").lexically_relative("/a/b/c") == "");
// TODO: add some Windows-only test cases that probe presence or absence of
// drive specifier-and root-directory
// Some tests from Jamie Allsop's paper
BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d");
BOOST_TEST(path("/a/b/c").lexically_relative("/a/d") == "../b/c");
#ifdef BOOST_WINDOWS_API
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "../y");
#else
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "");
#endif
BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == "");
// From issue #1976
BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new");
}
void lexically_proximate_test()
{
cout << "lexically_proximate_test..." << endl;
// paths unrelated
BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c");
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
// //
// main //
// //
//--------------------------------------------------------------------------------------//
int test_main(int, char*[])
{
// document state of critical macros
#ifdef BOOST_POSIX_API
cout << "BOOST_POSIX_API" << endl;
#endif
#ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API" << endl;
#endif
lexically_relative_test();
lexically_proximate_test();
return ::boost::report_errors();
}

View File

@@ -0,0 +1,62 @@
// filesystem sample_test.cpp ----------------------------------------------//
// Copyright Beman Dawes 2012
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// --------------------------------------------------------------------------//
//
// This program provides a template for bug reporting test cases.
//
// --------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
#include <string>
#include <cstring>
#ifndef BOOST_LIGHTWEIGHT_MAIN
#include <boost/test/prg_exec_monitor.hpp>
#else
#include <boost/detail/lightweight_main.hpp>
#endif
namespace fs = boost::filesystem;
using fs::path;
using std::cout;
using std::endl;
using std::string;
using std::wstring;
namespace {
bool cleanup = true;
}
// cpp_main ----------------------------------------------------------------//
int cpp_main(int argc, char* argv[])
{
if (argc > 1 && std::strcmp(argv[1], "--no-cleanup") == 0)
cleanup = false;
// Test cases go after this block of comments
// Use test case macros from boost/core/lightweight_test.hpp:
//
// BOOST_TEST(predicate); // test passes if predicate evaluates to true
// BOOST_TEST_EQ(x, y); // test passes if x == y
// BOOST_TEST_NE(x, y); // test passes if x != y
// BOOST_ERROR(msg); // test fails, outputs msg
// Examples:
// BOOST_TEST(path("f00").size() == 3); // test passes
// BOOST_TEST_EQ(path("f00").size(), 3); // test passes
// BOOST_MSG("Oops!"); // test fails, outputs "Oops!"
if (cleanup)
{
// Remove any test files or directories here
}
return ::boost::report_errors();
}

View File

@@ -0,0 +1,20 @@
# Copyright 2020 Andrey Semashev
#
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
#
# NOTE: This does NOT run the unit tests for Boost.Filesystem.
# It only tests, if the CMakeLists.txt file in it's root works as expected
cmake_minimum_required(VERSION 3.5)
project(BoostFilesystemCMakeSelfTest)
# Use experimental superproject to pull library dependencies recursively
set(BOOST_ENABLE_CMAKE 1)
add_subdirectory(../../../.. "${CMAKE_CURRENT_BINARY_DIR}/boost_superproject")
add_definitions(-DBOOST_ALL_NO_LIB)
add_executable(boost_filesystem_cmake_self_test main.cpp)
target_link_libraries(boost_filesystem_cmake_self_test Boost::filesystem)

View File

@@ -0,0 +1,13 @@
// Copyright (c) 2020 Andrey Semashev
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path p(".");
boost::filesystem::is_directory(p);
}

View File

@@ -0,0 +1,72 @@
// test_codecvt.hpp ------------------------------------------------------------------//
// Copyright Beman Dawes 2009, 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#ifndef BOOST_FILESYSTEM_TEST_CODECVT_HPP
#define BOOST_FILESYSTEM_TEST_CODECVT_HPP
#include <boost/filesystem/config.hpp>
#include <locale>
#include <cwchar> // for mbstate_t
//------------------------------------------------------------------------------------//
// //
// class test_codecvt //
// //
// Warning: partial implementation; even do_in and do_out only partially meet the //
// standard library specifications as the "to" buffer must hold the entire result. //
// //
// The value of a wide character is the value of the corresponding narrow character //
// plus 1. This ensures that compares against expected values will fail if the //
// code conversion did not occur as expected. //
// //
//------------------------------------------------------------------------------------//
class test_codecvt :
public std::codecvt< wchar_t, char, std::mbstate_t >
{
public:
explicit test_codecvt() :
std::codecvt< wchar_t, char, std::mbstate_t >()
{
}
protected:
virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t&, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
{
for (; from != from_end && to != to_end; ++from, ++to)
*to = wchar_t(*from + 1);
if (to == to_end)
return error;
*to = L'\0';
from_next = from;
to_next = to;
return ok;
}
virtual std::codecvt_base::result do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const
{
for (; from != from_end && to != to_end; ++from, ++to)
*to = static_cast< char >(*from - 1);
if (to == to_end)
return error;
*to = '\0';
from_next = from;
to_next = to;
return ok;
}
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw() { return 0; }
};
#endif // BOOST_FILESYSTEM_TEST_CODECVT_HPP

View File

@@ -0,0 +1,106 @@
// windows_attributes ----------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// Useful for debugging status related issues //
//--------------------------------------------------------------------------------------//
#include <boost/filesystem.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <windows.h>
#include <map>
#include <utility>
#include <iostream>
#include <string>
using std::make_pair;
namespace fs = boost::filesystem;
int cpp_main(int argc, char* argv[])
{
typedef std::map< DWORD, std::string > decode_type;
decode_type table;
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
if (argc < 2)
{
std::cout << "Usage: windows_attributes path\n";
return 1;
}
// report Win32 ::GetFileAttributesA()
DWORD at(::GetFileAttributesA(argv[1]));
if (at == INVALID_FILE_ATTRIBUTES)
{
std::cout << "GetFileAttributes(\"" << argv[1]
<< "\") returned INVALID_FILE_ATTRIBUTES\n";
return 0;
}
std::cout << "GetFileAttributes(\"" << argv[1]
<< "\") returned ";
bool bar = false;
for (decode_type::iterator it = table.begin(); it != table.end(); ++it)
{
if (!(it->first & at))
continue;
if (bar)
std::cout << " | ";
bar = true;
std::cout << it->second;
at &= ~it->first;
}
std::cout << std::endl;
if (at)
std::cout << "plus unknown attributes " << at << std::endl;
// report Boost Filesystem file_type
fs::file_status stat = fs::status(argv[1]);
const char* types[] =
{
"status_error",
"file_not_found",
"regular_file",
"directory_file",
// the following may not apply to some operating systems or file systems
"symlink_file",
"block_file",
"character_file",
"fifo_file",
"socket_file",
"reparse_file", // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
"type_unknown" // file does exist", but isn't one of the above types or
// we don't have strong enough permission to find its type
};
std::cout << "boost::filesystem::status().type() is " << types[stat.type()] << std::endl;
return 0;
}