2
0
mirror of https://github.com/boostorg/nowide.git synced 2026-02-15 13:12:21 +00:00
Files
nowide/test/test_fs.cpp
Flamefire f213fd90f4 Fix exception path of tests
Even in case of exceptions boost::report_errors has to be called
2019-12-13 19:24:44 +01:00

70 lines
2.0 KiB
C++

//
// Copyright (c) 2015 Artyom Beilis (Tonkikh)
//
// 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)
//
#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS
#endif
#include <boost/nowide/integration/filesystem.hpp>
#include <boost/nowide/fstream.hpp>
#include <boost/nowide/cstdio.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
#include <iostream>
#include "test.hpp"
namespace detail
{
static char const * utf8_name = "\xf0\x9d\x92\x9e-\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82.txt";
static wchar_t const * wide_name = L"\U0001D49E-\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042.txt";
static std::string prefix = boost::filesystem::unique_path( "nowide-%%%%-%%%%-" ).string();
static std::string utf8_name_str = prefix + utf8_name;
static std::wstring wide_name_str = boost::nowide::widen( prefix ) + wide_name;
} // detail
static char const * utf8_name = detail::utf8_name_str.c_str();
static wchar_t const * wide_name = detail::wide_name_str.c_str();
int main()
{
try {
boost::nowide::nowide_filesystem();
TEST(boost::nowide::widen(utf8_name) == wide_name);
TEST(boost::nowide::narrow(wide_name) == utf8_name);
boost::nowide::ofstream f(utf8_name);
TEST(f);
f << "Test" << std::endl;
f.close();
TEST(boost::filesystem::is_regular_file(wide_name)==true);
TEST(boost::filesystem::is_regular_file(utf8_name)==true);
boost::nowide::remove(utf8_name);
TEST(boost::filesystem::is_regular_file(utf8_name)==false);
TEST(boost::filesystem::is_regular_file(wide_name)==false);
}
catch(std::exception const &e) {
std::cerr << "Failed : " << e.what() << std::endl;
BOOST_NOWIDE_TEST_RETURN_FAILURE;
}
return boost::report_errors();
}
///
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4