2
0
mirror of https://github.com/boostorg/nowide.git synced 2026-02-15 13:12:21 +00:00
Files
nowide/test/test_stdio.cpp
2019-12-14 13:35:37 +01:00

64 lines
1.8 KiB
C++

//
// Copyright (c) 2012 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/cstdio.hpp>
#include <boost/filesystem/operations.hpp>
#include <iostream>
#include <cstring>
#include "test.hpp"
int main()
{
try {
std::string prefix = boost::filesystem::unique_path( "nowide-%%%%-%%%%-" ).string();
std::string example = prefix + "\xd7\xa9-\xd0\xbc-\xce\xbd.txt";
std::wstring wexample = boost::nowide::widen( prefix ) + L"\u05e9-\u043c-\u03bd.txt";
#ifdef BOOST_WINDOWS
FILE *f=_wfopen(wexample.c_str(),L"w");
#else
FILE *f=std::fopen(example.c_str(),"w");
#endif
TEST(f);
std::fprintf(f,"test\n");
std::fclose(f);
f=0;
TEST((f=boost::nowide::fopen(example.c_str(),"r"))!=0);
char buf[16];
TEST(std::fgets(buf,16,f)!=0);
TEST(std::strcmp(buf,"test\n")==0);
TEST((f=boost::nowide::freopen(example.c_str(),"r+",f))!=0);
std::fclose(f);
f=0;
TEST(boost::nowide::rename(example.c_str(),(example+".1").c_str())==0);
TEST(boost::nowide::remove(example.c_str())<0);
TEST((f=boost::nowide::fopen((example+".1").c_str(),"r"))!=0);
std::fclose(f);
f=0;
TEST(boost::nowide::remove(example.c_str())<0);
TEST(boost::nowide::remove((example+".1").c_str())==0);
}
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