1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_codecvt_null.cpp
4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // should pass compilation and execution. Note: compilation with compilers
10 // which use wchar_t as 2 byte objects will emit warnings. These should be
13 #include <algorithm> // std::copy
19 #include <cstdio> // remove
20 #include <cstddef> // NULL, size_t
22 #include <boost/config.hpp>
23 #if defined(BOOST_NO_STDC_NAMESPACE)
29 #include "test_tools.hpp"
31 #include <boost/archive/add_facet.hpp>
32 #include <boost/archive/codecvt_null.hpp>
33 #include <boost/archive/iterators/ostream_iterator.hpp>
34 #include <boost/archive/iterators/istream_iterator.hpp>
36 template<std::size_t S>
39 static wchar_t wchar_encoding[];
43 wchar_t test_data<2>::wchar_encoding[] = {
53 wchar_t test_data<4>::wchar_encoding[] = {
71 int test_main( int /* argc */, char* /* argv */[] ) {
72 const char * testfile = boost::archive::tmpnam(NULL);
73 BOOST_REQUIRE(NULL != testfile);
76 std::locale * null_locale =
77 boost::archive::add_facet(old_loc, new boost::archive::codecvt_null<wchar_t>);
79 typedef test_data<sizeof(wchar_t)> td;
82 ofs.imbue(*null_locale);
83 ofs.open(testfile, std::ios::binary);
86 #if ! defined(__BORLANDC__)
87 // borland 5.60 complains about this
88 td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t),
90 // so use this instead
91 td::wchar_encoding + 6,
93 boost::archive::iterators::ostream_iterator<wchar_t>(ofs)
99 ifs.imbue(*null_locale);
100 ifs.open(testfile, std::ios::binary);
103 #if ! defined(__BORLANDC__)
104 // borland 5.60 complains about this
105 td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t),
107 // so use this instead
108 td::wchar_encoding + 6,
110 boost::archive::iterators::istream_iterator<wchar_t>(ifs)
116 std::wofstream ofs("testfile2");
117 ofs.imbue(*null_locale);
122 std::wifstream ifs("testfile2");
123 ifs.imbue(*null_locale);
126 std::cout << "i=" << i << std::endl;
127 std::cout << "i2=" << i2 << std::endl;
128 BOOST_CHECK(i == i2);
133 std::remove(testfile);