diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/25_algorithms/copy | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms/copy')
17 files changed, 1052 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy/1.cc new file mode 100644 index 000000000..d73c15427 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/1.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2005, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.1 [lib.alg.copy] Copy. + +#include <algorithm> +#include <vector> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int N = sizeof(A) / sizeof(int); + + int i1[N]; + copy(A, A + N, i1); + VERIFY( equal(i1, i1 + N, A) ); + + vector<int> v1(N); + copy(A, A + N, v1.begin()); + VERIFY( equal(v1.begin(), v1.end(), A) ); + + short s1[N]; + copy(A, A + N, s1); + VERIFY( equal(s1, s1 + N, A) ); + + int i2[N]; + copy_backward(A, A + N, i2 + N); + VERIFY( equal(i2, i2 + N, A) ); + + vector<int> v2(N); + copy_backward(A, A + N, v2.end()); + VERIFY( equal(v2.begin(), v2.end(), A) ); + + short s2[N]; + copy_backward(A, A + N, s2 + N); + VERIFY( equal(s2, s2 + N, A) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/2.cc b/libstdc++-v3/testsuite/25_algorithms/copy/2.cc new file mode 100644 index 000000000..08d3f5994 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/2.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2004, 2005, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.1 [lib.alg.copy] Copy. + +#include <algorithm> +#include <vector> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int N = sizeof(A) / sizeof(int); + const vector<int> a(A, A + N); + + int i1[N]; + copy(a.begin(), a.end(), i1); + VERIFY( equal(i1, i1 + N, a.begin()) ); + + vector<int> v1(N); + copy(a.begin(), a.end(), v1.begin()); + VERIFY( equal(v1.begin(), v1.end(), a.begin()) ); + + short s1[N]; + copy(a.begin(), a.end(), s1); + VERIFY( equal(s1, s1 + N, a.begin()) ); + + int i2[N]; + copy_backward(a.begin(), a.end(), i2 + N); + VERIFY( equal(i2, i2 + N, a.begin()) ); + + vector<int> v2(N); + copy_backward(a.begin(), a.end(), v2.end()); + VERIFY( equal(v2.begin(), v2.end(), a.begin()) ); + + short s2[N]; + copy_backward(a.begin(), a.end(), s2 + N); + VERIFY( equal(s2, s2 + N, a.begin()) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/3.cc b/libstdc++-v3/testsuite/25_algorithms/copy/3.cc new file mode 100644 index 000000000..29caf3ae9 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/3.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2005, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.1 [lib.alg.copy] Copy. + +#include <algorithm> +#include <vector> +#include <deque> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int N = sizeof(A) / sizeof(int); + const deque<int> a(A, A + N); + + int i1[N]; + copy(a.begin(), a.end(), i1); + VERIFY( equal(i1, i1 + N, a.begin()) ); + + vector<int> v1(N); + copy(a.begin(), a.end(), v1.begin()); + VERIFY( equal(v1.begin(), v1.end(), a.begin()) ); + + short s1[N]; + copy(a.begin(), a.end(), s1); + VERIFY( equal(s1, s1 + N, a.begin()) ); + + int i2[N]; + copy_backward(a.begin(), a.end(), i2 + N); + VERIFY( equal(i2, i2 + N, a.begin()) ); + + vector<int> v2(N); + copy_backward(a.begin(), a.end(), v2.end()); + VERIFY( equal(v2.begin(), v2.end(), a.begin()) ); + + short s2[N]; + copy_backward(a.begin(), a.end(), s2 + N); + VERIFY( equal(s2, s2 + N, a.begin()) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/34595.cc b/libstdc++-v3/testsuite/25_algorithms/copy/34595.cc new file mode 100644 index 000000000..612eb4872 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/34595.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.1 [lib.alg.copy] Copy. + +#include <algorithm> +#include <testsuite_hooks.h> + +class Counting_output_iterator +: public std::iterator< std::output_iterator_tag, void, void, void, void > +{ + std::size_t c; +public: + Counting_output_iterator() : c(0) {} + Counting_output_iterator& operator++() { return *this; } + Counting_output_iterator& operator*() { return *this; } + + template <typename T> + void operator=(const T&) { ++c; } + + std::size_t current_counter() const { return c; } +}; + +// libstdc++/34595 +void test01() +{ + bool test __attribute__((unused)) = true; + + int t[10] = {0,}; + Counting_output_iterator cnt; + std::size_t res = std::copy(t+0, t+5, cnt).current_counter(); + + VERIFY( res == 5 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/4.cc b/libstdc++-v3/testsuite/25_algorithms/copy/4.cc new file mode 100644 index 000000000..885561a2b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/4.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2005, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.1 [lib.alg.copy] Copy. + +#include <algorithm> +#include <vector> +#include <list> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int N = sizeof(A) / sizeof(int); + const list<int> a(A, A + N); + + int i1[N]; + copy(a.begin(), a.end(), i1); + VERIFY( equal(i1, i1 + N, a.begin()) ); + + vector<int> v1(N); + copy(a.begin(), a.end(), v1.begin()); + VERIFY( equal(v1.begin(), v1.end(), a.begin()) ); + + short s1[N]; + copy(a.begin(), a.end(), s1); + VERIFY( equal(s1, s1 + N, a.begin()) ); + + int i2[N]; + copy_backward(a.begin(), a.end(), i2 + N); + VERIFY( equal(i2, i2 + N, a.begin()) ); + + vector<int> v2(N); + copy_backward(a.begin(), a.end(), v2.end()); + VERIFY( equal(v2.begin(), v2.end(), a.begin()) ); + + short s2[N]; + copy_backward(a.begin(), a.end(), s2 + N); + VERIFY( equal(s2, s2 + N, a.begin()) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/deque_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy/deque_iterators/1.cc new file mode 100644 index 000000000..172c2aed2 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/deque_iterators/1.cc @@ -0,0 +1,51 @@ +// 2009-12-23 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <algorithm> +#include <deque> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + deque<long> data(200); + for (unsigned i = 0; i < data.size(); ++i) + data[i] = i; + + const deque<long> data_1(data.size(), -1); + + for (unsigned i = 0; i < data.size(); i += 2) + for (unsigned j = i; j <= data.size(); j += 3) + for (unsigned k = 0; k + (j - i) <= data.size(); k += 5) + { + deque<long> d(data.size(), -1); + copy(data.begin() + i, data.begin() + j, d.begin() + k); + + VERIFY( equal(data.begin() + i, data.begin() + j, + d.begin() + k) ); + VERIFY( equal(d.begin(), d.begin() + k, data_1.begin()) ); + VERIFY( equal(d.begin() + k + (j - i), d.end(), data_1.begin()) ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc new file mode 100644 index 000000000..4781ba1de --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include <algorithm> +#include <iterator> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; +using __gnu_test::output_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::copy; + +typedef test_container<rvalstruct, input_iterator_wrapper> container_in; +typedef test_container<rvalstruct, output_iterator_wrapper> container_out; + +void test01() +{ + bool test __attribute__((unused)) = true; + + int inarray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int size = sizeof(inarray) / sizeof(int); + + rvalstruct in[size], out[size]; + std::copy(inarray, inarray + size, in); + + container_in incon(in, in + size); + container_out outcon(out, out + size); + + copy(std::move_iterator<input_iterator_wrapper<rvalstruct> >(incon.begin()), + std::move_iterator<input_iterator_wrapper<rvalstruct> >(incon.end()), + outcon.begin()); + VERIFY( std::equal(out, out + size, inarray) ); + for (int z = 0; z < size; ++z) + VERIFY( out[z].valid ); + for (int z = 0; z < size; ++z) + VERIFY( !in[z].valid ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/copy/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..720cc767b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/requirements/explicit_instantiation/2.cc @@ -0,0 +1,34 @@ +// { dg-do compile } + +// 2007-09-20 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <algorithm> +#include <testsuite_api.h> + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + + template iterator_type copy(iterator_type, iterator_type, iterator_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/copy/requirements/explicit_instantiation/pod.cc new file mode 100644 index 000000000..343d8027b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/requirements/explicit_instantiation/pod.cc @@ -0,0 +1,34 @@ +// { dg-do compile } + +// 2007-09-20 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <algorithm> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + + template iterator_type copy(iterator_type, iterator_type, iterator_type); +} 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 000000000..ab66f7251 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/1.cc @@ -0,0 +1,75 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator<char> in_iterator_type; + typedef ostreambuf_iterator<char> 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 000000000..201e27871 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/2.cc @@ -0,0 +1,77 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <cstring> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator<char> 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 000000000..d8f5dbfc6 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/3.cc @@ -0,0 +1,71 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef ostreambuf_iterator<char> 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 000000000..62ecf686d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc @@ -0,0 +1,58 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <fstream> +#include <algorithm> +#include <cstring> +#include <testsuite_hooks.h> + +// { dg-require-fileio "" } + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator<char> 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 000000000..655b3242d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/1.cc @@ -0,0 +1,75 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator<wchar_t> in_iterator_type; + typedef ostreambuf_iterator<wchar_t> 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 000000000..d7871320b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/2.cc @@ -0,0 +1,76 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator<wchar_t> 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 000000000..ac50b87de --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/3.cc @@ -0,0 +1,71 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef ostreambuf_iterator<wchar_t> 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 000000000..56a5cdef6 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc @@ -0,0 +1,55 @@ +// 2006-03-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <fstream> +#include <algorithm> +#include <testsuite_hooks.h> + +// In the occasion of libstdc++/25482 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef istreambuf_iterator<wchar_t> 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; +} |