OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_filebuf/] [seekpos/] [wchar_t/] [9875_seekpos.cc] - Blame information for rev 565

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
2
//
3
// This file is part of the GNU ISO C++ Library.  This library is free
4
// software; you can redistribute it and/or modify it under the
5
// terms of the GNU General Public License as published by the
6
// Free Software Foundation; either version 3, or (at your option)
7
// any later version.
8
 
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
 
14
// You should have received a copy of the GNU General Public License along
15
// with this library; see the file COPYING3.  If not see
16
// <http://www.gnu.org/licenses/>.
17
 
18
// 27.8.1.4 Overridden virtual functions
19
 
20 565 jeremybenn
// { dg-xfail-run-if "not supported on OR32 newlib" { or32-*-elf } }
21
 
22 424 jeremybenn
#include <fstream>
23
#include <locale>
24
#include <algorithm>
25
#include <cstring>
26
#include <testsuite_hooks.h>
27
 
28
class Cvt : public std::codecvt<wchar_t, char, mbstate_t>
29
{
30
protected:
31
  virtual std::codecvt_base::result
32
  do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end,
33
         const wchar_t*& from_next, char* to, char* to_end,
34
         char*& to_next) const
35
  {
36
    std::size_t from_len = from_end - from;
37
    std::size_t to_len = (to_end - to) / sizeof(wchar_t);
38
    std::size_t len = std::min(from_len, to_len);
39
    std::memcpy(to, from, len * sizeof(wchar_t));
40
    from_next = from + len;
41
    to_next = to + len * sizeof(wchar_t);
42
    return from_next == from_end ? std::codecvt_base::ok :
43
           std::codecvt_base::partial;
44
  }
45
 
46
  virtual std::codecvt_base::result
47
  do_in(std::mbstate_t&, const char* from, const char* from_end,
48
        const char*& from_next, wchar_t* to, wchar_t* to_end,
49
        wchar_t*& to_next) const
50
  {
51
    std::size_t from_len =
52
      (from_end - from) / sizeof(wchar_t);
53
    std::size_t to_len = to_end - to;
54
    std::size_t len = std::min(from_len, to_len);
55
    std::memcpy(to, from, len * sizeof(wchar_t));
56
    from_next = from + len * sizeof(wchar_t);
57
    to_next = to + len;
58
    return from_next == from_end ? std::codecvt_base::ok :
59
           std::codecvt_base::partial;
60
  }
61
 
62
  virtual std::codecvt_base::result
63
  do_unshift(std::mbstate_t&, char*, char*, char*&) const
64
  { return std::codecvt_base::noconv; }
65
 
66
  virtual int do_encoding() const throw() { return sizeof(wchar_t); }
67
  virtual bool do_always_noconv() const throw() { return false; }
68
 
69
  virtual int
70
  do_length(std::mbstate_t&, const char* from, const char* end,
71
            std::size_t max)
72
  {
73
    std::size_t len = (end - from) / sizeof(wchar_t);
74
    return std::min(len, max) * sizeof(wchar_t);
75
  }
76
 
77
  virtual int do_max_length() const throw() { return sizeof(wchar_t); }
78
};
79
 
80
void test01()
81
{
82
  using namespace std;
83
  bool test __attribute__((unused)) = true;
84
 
85
  // seekpos
86
  wfilebuf fb;
87
  fb.pubimbue(locale(locale::classic(), new Cvt));
88
  fb.open("tmp_9875_seekpos", ios_base::out | ios_base::in | ios_base::trunc);
89
  fb.sputn(L"0123456789", 10);
90
 
91
  streampos p1 = fb.pubseekoff(0, ios_base::cur);
92
  VERIFY( p1 != streampos(-1) );
93
  fb.sputc(L'a');
94
 
95
  streampos p2 = fb.pubseekpos(p1);
96
  VERIFY( p2 != streampos(-1) );
97
  VERIFY( p2 == p1 );
98
  VERIFY( fb.sgetc() == L'a' );
99
 
100
  fb.pubseekoff(0, ios_base::beg);
101
  wchar_t buf[11];
102
  streamsize s1 = fb.sgetn(buf, 11);
103
  VERIFY( s1 == 11 );
104
  VERIFY( !wmemcmp(buf, L"0123456789a", 11) );
105
 
106
  fb.close();
107
}
108
 
109
int main()
110
{
111
  test01();
112
  return 0;
113
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.