]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / stdio_sync_filebuf / wchar_t / 1.cc
CommitLineData
fd63f08b 1// 2003-05-01 Petur Runolfsson <peturr02@ru.is>
2
f1717362 3// Copyright (C) 2003-2016 Free Software Foundation, Inc.
fd63f08b 4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
fd63f08b 9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
fd63f08b 19
20#include <ext/stdio_sync_filebuf.h>
1f3fc4aa 21#include <cstring>
fd63f08b 22#include <testsuite_hooks.h>
23
24void test01()
25{
26 using namespace std;
f8ef786c 27 typedef char_traits<wchar_t> traits_type;
fd63f08b 28
f8ef786c 29 bool test __attribute__((unused)) = true;
fd63f08b 30 const char* c_lit = "black pearl jasmine tea";
31 const wchar_t* w_lit = L"black pearl jasmine tea";
5a2fc49d 32 unsigned size = strlen(c_lit);
fd63f08b 33 const char* name = "stdiobuf-1.txt";
34
35 FILE* fout = fopen(name, "w");
34bd3b47 36 VERIFY( fwrite(c_lit, 1, size, fout) == size );
fd63f08b 37 fclose(fout);
38
39 FILE* fin = fopen(name, "r");
40 __gnu_cxx::stdio_sync_filebuf<wchar_t> wsbuf(fin);
41
f8ef786c 42 VERIFY( traits_type::to_char_type(wsbuf.sgetc()) == w_lit[0] );
43 VERIFY( traits_type::to_char_type(getwc(fin)) == w_lit[0] );
44 VERIFY( traits_type::to_char_type(wsbuf.sgetc()) == w_lit[1] );
45 VERIFY( traits_type::to_char_type(wsbuf.sbumpc()) == w_lit[1] );
fd63f08b 46 VERIFY( ungetwc(L'Z', fin) == L'Z' );
47 VERIFY( wsbuf.sbumpc() == L'Z' );
f8ef786c 48 VERIFY( traits_type::to_char_type(getwc(fin)) == w_lit[2] );
fd63f08b 49 VERIFY( wsbuf.sputbackc(L'X') == L'X' );
50 VERIFY( getwc(fin) == L'X' );
51
52 wchar_t buf[5];
05d4d6b9 53 wmemset(buf, static_cast<wchar_t>(0xdeadbeef), 5);
fd63f08b 54 VERIFY( wsbuf.sgetn(buf, 5) == 5 );
55 VERIFY( !wmemcmp(buf, w_lit + 3, 5) );
f8ef786c 56 VERIFY( traits_type::to_char_type(getwc(fin)) == w_lit[8] );
fd63f08b 57
58 fclose(fin);
59}
60
61int main ()
62{
63 test01();
64 return 0;
65}