| 1 |
// { dg-require-namedlocale "se_NO.UTF-8" } |
| 2 |
|
| 3 |
// 2003-09-08 Petur Runolfsson <[email protected]> |
| 4 |
|
| 5 |
// Copyright (C) 2003-2025 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. |
| 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 COPYING3. If not see |
| 20 |
// <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
// 27.8.1.4 Overridden virtual functions |
| 23 |
|
| 24 |
#include <fstream> |
| 25 |
#include <locale> |
| 26 |
#include <cstdio> |
| 27 |
#include <testsuite_hooks.h> |
| 28 |
|
| 29 |
// Check that basic_filebuf::seekoff handles UTF-8 when open for input and |
| 30 |
// output. |
| 31 |
void test02() |
| 32 |
{ |
| 33 |
using namespace std; |
| 34 |
typedef wfilebuf::int_type int_type; |
| 35 |
const char name[] = "tmp_seekoff-2.tst"; |
| 36 |
|
| 37 |
locale loc = locale("se_NO.UTF-8"); |
| 38 |
|
| 39 |
const size_t size = 10; |
| 40 |
wchar_t buf[size]; |
| 41 |
streamsize n; |
| 42 |
|
| 43 |
wfilebuf fb; |
| 44 |
fb.pubimbue(loc); |
| 45 |
fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); |
| 46 |
|
| 47 |
n = fb.sputn(L"\xa0st", 3); |
| 48 |
VERIFY( n == 3 ); |
| 49 |
|
| 50 |
fb.pubseekoff(0, ios_base::beg); |
| 51 |
n = fb.sgetn(buf, 2); |
| 52 |
VERIFY( n == 2 ); |
| 53 |
VERIFY( !wmemcmp(buf, L"\xa0s", 2) ); |
| 54 |
|
| 55 |
fb.pubseekoff(0, ios_base::cur); |
| 56 |
n = fb.sputn(L"\xb2R", 2); |
| 57 |
VERIFY( n == 2 ); |
| 58 |
|
| 59 |
fb.pubseekoff(0, ios_base::beg); |
| 60 |
n = fb.sgetn(buf, size); |
| 61 |
VERIFY( n == 4 ); |
| 62 |
VERIFY( !wmemcmp(buf, L"\xa0s\xb2R", 4) ); |
| 63 |
|
| 64 |
fb.pubseekoff(0, ios_base::beg); |
| 65 |
n = fb.sputn(L"\x90m\x92n\x94", 5); |
| 66 |
VERIFY( n == 5 ); |
| 67 |
|
| 68 |
fb.pubseekoff(0, ios_base::beg); |
| 69 |
n = fb.sgetn(buf, 2); |
| 70 |
VERIFY( n == 2 ); |
| 71 |
VERIFY( !wmemcmp(buf, L"\x90m", 2) ); |
| 72 |
|
| 73 |
fb.pubseekoff(0, ios_base::end); |
| 74 |
n = fb.sputn(L"I\xbfJ", 3); |
| 75 |
VERIFY( n == 3 ); |
| 76 |
|
| 77 |
fb.pubseekoff(0, ios_base::beg); |
| 78 |
n = fb.sgetn(buf, size); |
| 79 |
VERIFY( n == 8 ); |
| 80 |
VERIFY( !wmemcmp(buf, L"\x90m\x92n\x94I\xbfJ", 8) ); |
| 81 |
|
| 82 |
fb.close(); |
| 83 |
} |
| 84 |
|
| 85 |
int main() |
| 86 |
{ |
| 87 |
test02(); |
| 88 |
return 0; |
| 89 |
} |