From 0002d5d2bc68f9381ec990ea94307bafa700b0ad Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 21 Mar 2006 12:25:11 +0000 Subject: re PR libstdc++/25482 (Specialize (overload) std::copy/find for streambuf iterators) 2006-03-21 Paolo Carlini PR libstdc++/25482 * include/bits/stl_algobase.h (__copy_aux(_CharT*, _CharT*, ostreambuf_iterator<_CharT>), __copy_aux(const _CharT*, const _CharT*, ostreambuf_iterator<_CharT>), __copy_aux(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, _CharT*), copy(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, ostreambuf_iterator<_CharT>)): Declare. * include/bits/stl_algo.h (find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, _CharT)): Likewise. * include/bits/streambuf_iterator.h (copy(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, ostreambuf_iterator<_CharT>), __copy_aux(_CharT*, _CharT*, ostreambuf_iterator<_CharT>), __copy_aux(const _CharT*, const _CharT*, ostreambuf_iterator<_CharT>), __copy_aux(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, _CharT*), find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, _CharT)): Define. (class istreambuf_iterator<>, class ostreambuf_iterator<>): Declare friends. * include/std/std_streambuf.h (class basic_streambuf<>): Likewise. * include/bits/cpp_type_traits.h (struct __is_char<>): Add. * testsuite/25_algorithms/copy/streambuf_iterators/char/1.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/char/2.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/char/3.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/1.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/2.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/3.cc: New. * testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc: New. * testsuite/25_algorithms/find/istreambuf_iterators/char/1.cc: New. * testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc: New. * testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/1.cc: New. * testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc: New. * testsuite/performance/25_algorithms/copy_streambuf_iterators.cc: New. * testsuite/performance/25_algorithms/find_istreambuf_iterators.cc: New. From-SVN: r112247 --- .../copy/streambuf_iterators/char/1.cc | 76 +++++++++++++++ .../copy/streambuf_iterators/char/2.cc | 77 +++++++++++++++ .../copy/streambuf_iterators/char/3.cc | 72 ++++++++++++++ .../copy/streambuf_iterators/char/4.cc | 56 +++++++++++ .../copy/streambuf_iterators/wchar_t/1.cc | 76 +++++++++++++++ .../copy/streambuf_iterators/wchar_t/2.cc | 77 +++++++++++++++ .../copy/streambuf_iterators/wchar_t/3.cc | 72 ++++++++++++++ .../copy/streambuf_iterators/wchar_t/4.cc | 56 +++++++++++ .../find/istreambuf_iterators/char/1.cc | 84 ++++++++++++++++ .../find/istreambuf_iterators/char/2.cc | 60 ++++++++++++ .../find/istreambuf_iterators/wchar_t/1.cc | 84 ++++++++++++++++ .../find/istreambuf_iterators/wchar_t/2.cc | 60 ++++++++++++ .../25_algorithms/copy_streambuf_iterators.cc | 107 +++++++++++++++++++++ .../25_algorithms/find_istreambuf_iterators.cc | 63 ++++++++++++ 14 files changed, 1020 insertions(+) create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/1.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/2.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/3.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/1.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc create mode 100644 libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc (limited to 'libstdc++-v3/testsuite') diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/1.cc new file mode 100644 index 0000000..f90f325 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/1.cc @@ -0,0 +1,76 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + typedef ostreambuf_iterator out_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + istringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + + ostringstream oss1; + out_iterator_type out1(oss1); + + out1 = copy(beg1, beg1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(end1, end1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = 'x'; + VERIFY( oss1.str() == str1 + 'x' ); + oss1.str(""); + + iss1.seekg(0); + oss1.seekp(0); + oss1.str(""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = 'y'; + VERIFY( oss1.str() == str1 + 'y' ); + oss1.str(""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == "" ); + + iss1.seekg(0); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/2.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/2.cc new file mode 100644 index 0000000..333ad1e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/2.cc @@ -0,0 +1,77 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + istringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + + char buffer1[sizeof(data1) * 5]; + memset(buffer1, '*', sizeof(buffer1)); + char* out1 = buffer1; + + out1 = copy(beg1, beg1, out1); + VERIFY( out1 == buffer1 ); + + out1 = copy(end1, end1, out1); + VERIFY( out1 == buffer1 ); + + out1 = copy(beg1, end1, out1); + VERIFY( string(buffer1, out1) == str1 ); + *out1++ = 'x'; + VERIFY( string(buffer1, out1) == str1 + 'x' ); + memset(buffer1, '*', sizeof(buffer1)); + + iss1.seekg(0); + out1 = buffer1; + memset(buffer1, '*', sizeof(buffer1)); + out1 = copy(beg1, end1, out1); + VERIFY( string(buffer1, out1) == str1 ); + *out1++ = 'y'; + VERIFY( string(buffer1, out1) == str1 + 'y' ); + out1 = buffer1; + memset(buffer1, '*', sizeof(buffer1)); + out1 = copy(beg1, end1, out1); + VERIFY( string(buffer1, out1) == "" ); + + iss1.seekg(0); + out1 = copy(beg1, end1, out1); + VERIFY( string(buffer1, out1) == str1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/3.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/3.cc new file mode 100644 index 0000000..0db1239 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/3.cc @@ -0,0 +1,72 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef ostreambuf_iterator out_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + const char* beg1 = data1; + const char* end1 = beg1 + str1.size(); + + ostringstream oss1; + out_iterator_type out1(oss1); + + out1 = copy(beg1, beg1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(end1, end1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = 'x'; + VERIFY( oss1.str() == str1 + 'x' ); + oss1.str(""); + + oss1.seekp(0); + oss1.str(""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = 'y'; + VERIFY( oss1.str() == str1 + 'y' ); + oss1.str(""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 + str1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc new file mode 100644 index 0000000..2af78d5 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc @@ -0,0 +1,56 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + ifstream fbuf_ref("istream_unformatted-1.txt"), + fbuf("istream_unformatted-1.txt"); + + char buffer_ref[16500], + buffer[16500]; + + fbuf_ref.read(buffer_ref, 16500); + + in_iterator_type beg(fbuf); + in_iterator_type end; + copy(beg, end, buffer); + + VERIFY( fbuf_ref.good() ); + VERIFY( fbuf.good() ); + + VERIFY( !memcmp(buffer, buffer_ref, 16500) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/1.cc new file mode 100644 index 0000000..3f4cc55 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/1.cc @@ -0,0 +1,76 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + typedef ostreambuf_iterator out_iterator_type; + + const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin"; + const wstring str1(data1); + wistringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + + wostringstream oss1; + out_iterator_type out1(oss1); + + out1 = copy(beg1, beg1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(end1, end1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = L'x'; + VERIFY( oss1.str() == str1 + L'x' ); + oss1.str(L""); + + iss1.seekg(0); + oss1.seekp(0); + oss1.str(L""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = L'y'; + VERIFY( oss1.str() == str1 + L'y' ); + oss1.str(L""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == L"" ); + + iss1.seekg(0); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/2.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/2.cc new file mode 100644 index 0000000..1e11a2f --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/2.cc @@ -0,0 +1,77 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin"; + const wstring str1(data1); + wistringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + + wchar_t buffer1[sizeof(data1) * 5 / sizeof(wchar_t)]; + wmemset(buffer1, L'*', sizeof(buffer1) / sizeof(wchar_t)); + wchar_t* out1 = buffer1; + + out1 = copy(beg1, beg1, out1); + VERIFY( out1 == buffer1 ); + + out1 = copy(end1, end1, out1); + VERIFY( out1 == buffer1 ); + + out1 = copy(beg1, end1, out1); + VERIFY( wstring(buffer1, out1) == str1 ); + *out1++ = L'x'; + VERIFY( wstring(buffer1, out1) == str1 + L'x' ); + wmemset(buffer1, L'*', sizeof(buffer1) / sizeof(wchar_t)); + + iss1.seekg(0); + out1 = buffer1; + wmemset(buffer1, L'*', sizeof(buffer1) / sizeof(wchar_t)); + out1 = copy(beg1, end1, out1); + VERIFY( wstring(buffer1, out1) == str1 ); + *out1++ = L'y'; + VERIFY( wstring(buffer1, out1) == str1 + L'y' ); + out1 = buffer1; + wmemset(buffer1, L'*', sizeof(buffer1) / sizeof(wchar_t)); + out1 = copy(beg1, end1, out1); + VERIFY( wstring(buffer1, out1) == L"" ); + + iss1.seekg(0); + out1 = copy(beg1, end1, out1); + VERIFY( wstring(buffer1, out1) == str1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/3.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/3.cc new file mode 100644 index 0000000..8edca40 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/3.cc @@ -0,0 +1,72 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef ostreambuf_iterator out_iterator_type; + + const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin"; + const wstring str1(data1); + const wchar_t* beg1 = data1; + const wchar_t* end1 = beg1 + str1.size(); + + wostringstream oss1; + out_iterator_type out1(oss1); + + out1 = copy(beg1, beg1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(end1, end1, out1); + VERIFY( oss1.str().empty() ); + + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = L'x'; + VERIFY( oss1.str() == str1 + L'x' ); + oss1.str(L""); + + oss1.seekp(0); + oss1.str(L""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + *out1 = L'y'; + VERIFY( oss1.str() == str1 + L'y' ); + oss1.str(L""); + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 ); + + out1 = copy(beg1, end1, out1); + VERIFY( oss1.str() == str1 + str1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc new file mode 100644 index 0000000..96478bb --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc @@ -0,0 +1,56 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + wifstream fbuf_ref("istream_unformatted-1.txt"), + fbuf("istream_unformatted-1.txt"); + + wchar_t buffer_ref[16500], + buffer[16500]; + + fbuf_ref.read(buffer_ref, 16500); + + in_iterator_type beg(fbuf); + in_iterator_type end; + copy(beg, end, buffer); + + VERIFY( fbuf_ref.good() ); + VERIFY( fbuf.good() ); + + VERIFY( !wmemcmp(buffer, buffer_ref, 16500) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/1.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/1.cc new file mode 100644 index 0000000..33b5ec1 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/1.cc @@ -0,0 +1,84 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + istringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1, it1; + + it1 = find(beg1, beg1, 'l'); + VERIFY( it1 == beg1 ); + VERIFY( *it1 == 'D' ); + + it1 = find(end1, end1, 'D'); + VERIFY( it1 == end1 ); + + it1 = find(end1, end1, 'Z'); + VERIFY( it1 == end1 ); + + it1 = find(beg1, end1, 'P'); + VERIFY( *it1 == 'P' ); + it1 = find(beg1, end1, 't'); + VERIFY( *it1 == 't' ); + ++it1; + VERIFY( *it1 == 'a' ); + + it1 = find(beg1, end1, 'H'); + VERIFY( *it1 == 'H' ); + it1 = find(beg1, end1, 'l'); + VERIFY( *it1 == 'l' ); + ++it1; + it1 = find(beg1, end1, 'l'); + VERIFY( *it1 == 'l' ); + ++it1; + VERIFY( *it1 == 'i' ); + it1 = find(beg1, end1, 'Z'); + VERIFY( it1 == end1 ); + + it1 = find(beg1, end1, 'D'); + VERIFY( it1 == end1 ); + + iss1.seekg(0); + it1 = find(beg1, end1, 'D'); + VERIFY( it1 != end1 ); + VERIFY( *it1 == 'D' ); + ++it1; + VERIFY( *it1 == 'r' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc new file mode 100644 index 0000000..682c515 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc @@ -0,0 +1,60 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + ifstream fbuf("istream_unformatted-1.txt"); + + in_iterator_type beg(fbuf); + in_iterator_type end; + + unsigned found = 0; + for (;;) + { + beg = find(beg, end, '1'); + if (beg == end) + break; + + ++found; + VERIFY( *beg == '1' ); + + for (unsigned sk = 0; sk < 9; sk++) + ++beg; + VERIFY( *beg == '0' ); + } + VERIFY( found == 1500 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/1.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/1.cc new file mode 100644 index 0000000..f8009d5 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/1.cc @@ -0,0 +1,84 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const wchar_t data1[] = L"Drei Phantasien nach Friedrich Holderlin"; + const wstring str1(data1); + wistringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1, it1; + + it1 = find(beg1, beg1, L'l'); + VERIFY( it1 == beg1 ); + VERIFY( *it1 == L'D' ); + + it1 = find(end1, end1, L'D'); + VERIFY( it1 == end1 ); + + it1 = find(end1, end1, L'Z'); + VERIFY( it1 == end1 ); + + it1 = find(beg1, end1, L'P'); + VERIFY( *it1 == L'P' ); + it1 = find(beg1, end1, L't'); + VERIFY( *it1 == L't' ); + ++it1; + VERIFY( *it1 == L'a' ); + + it1 = find(beg1, end1, L'H'); + VERIFY( *it1 == L'H' ); + it1 = find(beg1, end1, L'l'); + VERIFY( *it1 == L'l' ); + ++it1; + it1 = find(beg1, end1, L'l'); + VERIFY( *it1 == L'l' ); + ++it1; + VERIFY( *it1 == L'i' ); + it1 = find(beg1, end1, L'Z'); + VERIFY( it1 == end1 ); + + it1 = find(beg1, end1, L'D'); + VERIFY( it1 == end1 ); + + iss1.seekg(0); + it1 = find(beg1, end1, L'D'); + VERIFY( it1 != end1 ); + VERIFY( *it1 == L'D' ); + ++it1; + VERIFY( *it1 == L'r' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc new file mode 100644 index 0000000..efcedc1 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc @@ -0,0 +1,60 @@ +// 2006-03-20 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + wifstream fbuf("istream_unformatted-1.txt"); + + in_iterator_type beg(fbuf); + in_iterator_type end; + + unsigned found = 0; + for (;;) + { + beg = find(beg, end, L'1'); + if (beg == end) + break; + + ++found; + VERIFY( *beg == L'1' ); + + for (unsigned sk = 0; sk < 9; sk++) + ++beg; + VERIFY( *beg == L'0' ); + } + VERIFY( found == 1500 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc new file mode 100644 index 0000000..c9eee87 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc @@ -0,0 +1,107 @@ +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include +#include + +// libstdc++/25482 +int main() +{ + using namespace std; + using namespace __gnu_test; + + typedef istreambuf_iterator in_iterator_type; + typedef ostreambuf_iterator out_iterator_type; + + time_counter time; + resource_counter resource; + + const char data[] = "Contrappunto dialettico alla mente"; + + // istreambuf iterators -> ostreambuf iterator + { + istringstream iss(data); + in_iterator_type beg(iss); + in_iterator_type end; + + ostringstream oss; + out_iterator_type out(oss); + + start_counters(time, resource); + for (unsigned i = 0; i < 10000000; ++i) + { + copy(beg, end, out); + iss.seekg(0); + oss.seekp(0); + } + stop_counters(time, resource); + report_performance(__FILE__, "isb iters -> osb iter", time, resource); + clear_counters(time, resource); + } + + // char array -> ostreambuf iterator + { + const char* beg = data; + const char* end = data + sizeof(data) - 1; + + ostringstream oss; + out_iterator_type out(oss); + + start_counters(time, resource); + for (unsigned i = 0; i < 10000000; ++i) + { + copy(beg, end, out); + oss.seekp(0); + } + stop_counters(time, resource); + report_performance(__FILE__, "pointers -> osb iter", time, resource); + clear_counters(time, resource); + } + + // istreambuf iterators -> char array + { + istringstream iss(data); + in_iterator_type beg(iss); + in_iterator_type end; + + char out[sizeof(data)]; + + start_counters(time, resource); + for (unsigned i = 0; i < 10000000; ++i) + { + copy(beg, end, out); + iss.seekg(0); + } + stop_counters(time, resource); + report_performance(__FILE__, "isb iters -> pointer", time, resource); + clear_counters(time, resource); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc new file mode 100644 index 0000000..7c2d547 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include +#include + +// libstdc++/25482 +int main() +{ + using namespace std; + using namespace __gnu_test; + + typedef istreambuf_iterator in_iterator_type; + + istringstream iss("a0000b1111c2222d3333e4444f5555g6666h7777i8888j9999" + "k0000l1111m2222n3333o4444p5555q6666r7777s8888t9999"); + + in_iterator_type beg(iss); + in_iterator_type end; + + time_counter time; + resource_counter resource; + + start_counters(time, resource); + for (unsigned i = 0; i < 1000000; ++i) + { + for (char c = 'a'; c < 'u'; ++c) + { + find(beg, end, c); + iss.seekg(0); + } + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} -- cgit v1.1