From: paolo Date: Sun, 25 Apr 2004 12:56:41 +0000 (+0000) Subject: 2004-04-25 Paolo Carlini X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=afd3c60a7551a6f025874ccc543b1b6144f9272e;p=pf3gnuchains%2Fgcc-fork.git 2004-04-25 Paolo Carlini * testsuite/21_strings/basic_string/inserters_extractors/char/10.cc: New. * testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc: Likewise. * testsuite/27_io/basic_istream/getline/char/5.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@81159 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0f1838ee43b..0b728ee3ff6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2004-04-25 Paolo Carlini + + * testsuite/21_strings/basic_string/inserters_extractors/char/10.cc: + New. + * testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc: + Likewise. + * testsuite/27_io/basic_istream/getline/char/5.cc: Likewise. + 2004-04-24 Paolo Carlini Petur Runolfsson diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/10.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/10.cc new file mode 100644 index 00000000000..75b7e89d2a5 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/10.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 21.3.7.9 inserters and extractors + +#include +#include +#include +#include + +using namespace std; + +string prepare(string::size_type len, unsigned nchunks, char delim) +{ + string ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (string::size_type j = 0; j < len; ++j) + ret.push_back('a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void check(istream& stream, const string& str, char delim) +{ + bool test __attribute__((unused)) = true; + + string chunk; + string::size_type index = 0, index_new = 0; + + while (getline(stream, chunk, delim)) + { + index_new = str.find(delim, index); + VERIFY( !str.compare(index, index_new - index, chunk) ); + index = index_new + 1; + } + VERIFY( stream.eof() ); +} + +// istream& getline(istream&, string&, char) +void test01() +{ + const char filename[] = "inserters_extractors-2.txt"; + + const char delim = '|'; + const string data = prepare(777, 10, delim); + + ofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + ifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc new file mode 100644 index 00000000000..5f1e1d77d9e --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 21.3.7.9 inserters and extractors + +#include +#include +#include +#include + +using namespace std; + +wstring prepare(wstring::size_type len, unsigned nchunks, wchar_t delim) +{ + wstring ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (wstring::size_type j = 0; j < len; ++j) + ret.push_back(L'a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void check(wistream& stream, const wstring& str, wchar_t delim) +{ + bool test __attribute__((unused)) = true; + + wstring chunk; + wstring::size_type index = 0, index_new = 0; + + while (getline(stream, chunk, delim)) + { + index_new = str.find(delim, index); + VERIFY( !str.compare(index, index_new - index, chunk) ); + index = index_new + 1; + } + VERIFY( stream.eof() ); +} + +// istream& getline(istream&, string&, char) +void test01() +{ + const char filename[] = "inserters_extractors-2.txt"; + + const wchar_t delim = L'|'; + const wstring data = prepare(777, 10, delim); + + wofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + wifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc new file mode 100644 index 00000000000..b2f07725c64 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#include +#include +#include +#include + +using namespace std; + +string prepare(string::size_type len, unsigned nchunks, char delim) +{ + string ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (string::size_type j = 0; j < len; ++j) + ret.push_back('a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void check(istream& stream, const string& str, char delim) +{ + bool test __attribute__((unused)) = true; + + char buf[1000000]; + string::size_type index = 0, index_new = 0; + + while (stream.getline(buf, sizeof(buf), delim)) + { + index_new = str.find(delim, index); + VERIFY( stream.gcount() == index_new - index + 1 ); + VERIFY( !str.compare(index, index_new - index, buf) ); + index = index_new + 1; + } + VERIFY( stream.gcount() == 0 ); + VERIFY( stream.eof() ); +} + +void test01() +{ + const char filename[] = "istream_getline.txt"; + + const char delim = '|'; + const string data = prepare(777, 10, delim); + + ofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + ifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +}