X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=libstdc%2B%2B-v3%2Ftestsuite%2F27_io%2Fbasic_filebuf%2Fseekoff%2Fwchar_t%2F9875_seekoff.cc;fp=libstdc%2B%2B-v3%2Ftestsuite%2F27_io%2Fbasic_filebuf%2Fseekoff%2Fwchar_t%2F9875_seekoff.cc;h=312386a24747b777b28cc0de98bc7884c4277926;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc new file mode 100644 index 00000000..312386a2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include + +class Cvt : public std::codecvt +{ +protected: + 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 + { + std::size_t from_len = from_end - from; + std::size_t to_len = (to_end - to) / sizeof(wchar_t); + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len; + to_next = to + len * sizeof(wchar_t); + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + 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 + { + std::size_t from_len = + (from_end - from) / sizeof(wchar_t); + std::size_t to_len = to_end - to; + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len * sizeof(wchar_t); + to_next = to + len; + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(std::mbstate_t&, char*, char*, char*&) const + { return std::codecvt_base::noconv; } + + virtual int do_encoding() const throw() { return sizeof(wchar_t); } + virtual bool do_always_noconv() const throw() { return false; } + + virtual int + do_length(std::mbstate_t&, const char* from, const char* end, + std::size_t max) + { + std::size_t len = (end - from) / sizeof(wchar_t); + return std::min(len, max) * sizeof(wchar_t); + } + + virtual int do_max_length() const throw() { return sizeof(wchar_t); } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // seekoff + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_9875_seekoff", ios_base::out | ios_base::in | ios_base::trunc); + fb.sputn(L"0123456789", 10); + fb.pubseekoff(-3, ios_base::cur); + VERIFY( fb.sgetc() == L'7' ); + fb.pubseekoff(-3, ios_base::cur); + VERIFY( fb.sgetc() == L'4' ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +}