Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / seekoff / wchar_t / 2.cc
blobe7969ac098af810961b2747c9a75f839867169be
1 // { dg-require-namedlocale "se_NO.UTF-8" }
3 // 2003-09-08 Petur Runolfsson <peturr02@ru.is>
5 // Copyright (C) 2003-2013 Free Software Foundation, Inc.
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 3, or (at your option)
11 // any later version.
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.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // 27.8.1.4 Overridden virtual functions
24 #include <fstream>
25 #include <locale>
26 #include <cstdio>
27 #include <testsuite_hooks.h>
29 // Check that basic_filebuf::seekoff handles UTF-8 when open for input and
30 // output.
31 void test02()
33 using namespace std;
34 typedef wfilebuf::int_type int_type;
35 bool test __attribute__((unused)) = true;
36 const char name[] = "tmp_seekoff-2.tst";
38 locale loc = locale("se_NO.UTF-8");
40 const size_t size = 10;
41 wchar_t buf[size];
42 streamsize n;
44 wfilebuf fb;
45 fb.pubimbue(loc);
46 fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
48 n = fb.sputn(L"\xa0st", 3);
49 VERIFY( n == 3 );
51 fb.pubseekoff(0, ios_base::beg);
52 n = fb.sgetn(buf, 2);
53 VERIFY( n == 2 );
54 VERIFY( !wmemcmp(buf, L"\xa0s", 2) );
56 fb.pubseekoff(0, ios_base::cur);
57 n = fb.sputn(L"\xb2R", 2);
58 VERIFY( n == 2 );
60 fb.pubseekoff(0, ios_base::beg);
61 n = fb.sgetn(buf, size);
62 VERIFY( n == 4 );
63 VERIFY( !wmemcmp(buf, L"\xa0s\xb2R", 4) );
65 fb.pubseekoff(0, ios_base::beg);
66 n = fb.sputn(L"\x90m\x92n\x94", 5);
67 VERIFY( n == 5 );
69 fb.pubseekoff(0, ios_base::beg);
70 n = fb.sgetn(buf, 2);
71 VERIFY( n == 2 );
72 VERIFY( !wmemcmp(buf, L"\x90m", 2) );
74 fb.pubseekoff(0, ios_base::end);
75 n = fb.sputn(L"I\xbfJ", 3);
76 VERIFY( n == 3 );
78 fb.pubseekoff(0, ios_base::beg);
79 n = fb.sgetn(buf, size);
80 VERIFY( n == 8 );
81 VERIFY( !wmemcmp(buf, L"\x90m\x92n\x94I\xbfJ", 8) );
83 fb.close();
86 int main()
88 test02();
89 return 0;