]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc
testsuite_hooks.cc: Remove try_named_locale.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / seekoff / wchar_t / 2.cc
CommitLineData
f63a8495
PC
1// { dg-require-namedlocale "" }
2
8c8dec01
PR
3// 2003-09-08 Petur Runolfsson <peturr02@ru.is>
4
f63a8495 5// Copyright (C) 2003, 2005 Free Software Foundation, Inc.
8c8dec01
PR
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 2, or (at your option)
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License along
19// with this library; see the file COPYING. If not, write to the Free
20// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21// USA.
22
23// 27.8.1.4 Overridden virtual functions
24
25#include <fstream>
26#include <locale>
27#include <cstdio>
28#include <testsuite_hooks.h>
29
30// Check that basic_filebuf::seekoff handles UTF-8 when open for input and
31// output.
32void test02()
33{
34 using namespace std;
35 typedef wfilebuf::int_type int_type;
11f10e6b 36 bool test __attribute__((unused)) = true;
8c8dec01
PR
37 const char name[] = "tmp_seekoff-2.tst";
38
f63a8495 39 locale loc = locale("se_NO.UTF-8");
8c8dec01
PR
40
41 const size_t size = 10;
42 wchar_t buf[size];
43 streamsize n;
44
45 wfilebuf fb;
46 fb.pubimbue(loc);
47 fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
48
49 n = fb.sputn(L"\xa0st", 3);
50 VERIFY( n == 3 );
51
52 fb.pubseekoff(0, ios_base::beg);
53 n = fb.sgetn(buf, 2);
54 VERIFY( n == 2 );
55 VERIFY( !wmemcmp(buf, L"\xa0s", 2) );
56
57 fb.pubseekoff(0, ios_base::cur);
58 n = fb.sputn(L"\xb2R", 2);
59 VERIFY( n == 2 );
60
61 fb.pubseekoff(0, ios_base::beg);
62 n = fb.sgetn(buf, size);
63 VERIFY( n == 4 );
64 VERIFY( !wmemcmp(buf, L"\xa0s\xb2R", 4) );
65
66 fb.pubseekoff(0, ios_base::beg);
67 n = fb.sputn(L"\x90m\x92n\x94", 5);
68 VERIFY( n == 5 );
69
70 fb.pubseekoff(0, ios_base::beg);
71 n = fb.sgetn(buf, 2);
72 VERIFY( n == 2 );
73 VERIFY( !wmemcmp(buf, L"\x90m", 2) );
74
75 fb.pubseekoff(0, ios_base::end);
76 n = fb.sputn(L"I\xbfJ", 3);
77 VERIFY( n == 3 );
78
79 fb.pubseekoff(0, ios_base::beg);
80 n = fb.sgetn(buf, size);
81 VERIFY( n == 8 );
82 VERIFY( !wmemcmp(buf, L"\x90m\x92n\x94I\xbfJ", 8) );
83
84 fb.close();
85}
86
87int main()
88{
89 test02();
90 return 0;
91}