diff options
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms/unique_copy')
6 files changed, 348 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/1.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/1.cc new file mode 100644 index 000000000..ca79b354c --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/1.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2005, 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/>. + +// 25.2.8 [lib.alg.unique] + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::output_iterator_wrapper; +using std::unique_copy; + +typedef test_container<int, input_iterator_wrapper> Icontainer; +typedef test_container<int, forward_iterator_wrapper> Fcontainer; +typedef test_container<int, output_iterator_wrapper> Ocontainer; + +int array1[] = {0, 0, 0, 1, 1, 1}; +int array2[2]; + +void +test1() +{ + bool test __attribute__((unused)) = true; + Icontainer con1(array1, array1); + Ocontainer con2(array2, array2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin()).ptr == array2 ); +} + +void +test2() +{ + bool test __attribute__((unused)) = true; + Icontainer con1(array1, array1 + 6); + Ocontainer con2(array2, array2 + 2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin()).ptr + == array2 + 2 ); + VERIFY( array2[0] == 0 && array2[1] == 1 ); +} + +void +test3() +{ + bool test __attribute__((unused)) = true; + Icontainer con1(array1, array1); + Fcontainer con2(array2, array2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin()).ptr == array2 ); +} + +void +test4() +{ + bool test __attribute__((unused)) = true; + Icontainer con1(array1, array1 + 6); + Fcontainer con2(array2, array2 + 2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin()).ptr + == array2 + 2 ); + VERIFY( array2[0] == 0 && array2[1] == 1 ); +} + +int +main() +{ + test1(); + test2(); + test3(); + test4(); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/2.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/2.cc new file mode 100644 index 000000000..f0879a4d1 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/2.cc @@ -0,0 +1,85 @@ +// 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/>. + +// 25.2.8 [lib.alg.unique] + +#include <algorithm> +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> + +using __gnu_test::test_container; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::output_iterator_wrapper; +using std::unique_copy; +using std::equal_to; + +typedef test_container<int, forward_iterator_wrapper> Fcontainer; +typedef test_container<int, output_iterator_wrapper> Ocontainer; + +int array1[] = {0, 0, 0, 1, 1, 1}; +int array2[2]; + +void +test1() +{ + bool test __attribute__((unused)) = true; + Fcontainer con1(array1, array1); + Ocontainer con2(array2, array2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin()).ptr == array2 ); +} + +void +test2() +{ + bool test __attribute__((unused)) = true; + Fcontainer con1(array1, array1 + 6); + Ocontainer con2(array2, array2 + 2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin()).ptr + == array2 + 2 ); + VERIFY( array2[0] == 0 && array2[1] == 1 ); +} + +void +test3() +{ + bool test __attribute__((unused)) = true; + Fcontainer con1(array1, array1); + Ocontainer con2(array2, array2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin(), + equal_to<int>()).ptr == array2 ); +} + +void +test4() +{ + bool test __attribute__((unused)) = true; + Fcontainer con1(array1, array1 + 6); + Ocontainer con2(array2, array2 + 2); + VERIFY( unique_copy(con1.begin(), con1.end(), con2.begin(), + equal_to<int>()).ptr == array2 + 2 ); + VERIFY( array2[0] == 0 && array2[1] == 1 ); +} + +int +main() +{ + test1(); + test2(); + test3(); + test4(); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc new file mode 100644 index 000000000..009c1a3a9 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc @@ -0,0 +1,50 @@ +// 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 <algorithm> +#include <iterator> +#include <sstream> +#include <testsuite_hooks.h> + +struct no_assign +{ + int const x; + no_assign() : x(23) { } + operator int() const { return x; } +}; + +// libstdc++/26133 +void test01() +{ + bool test __attribute__((unused)) = true; + std::ostringstream oss1, oss2; + + no_assign in[4]; + + std::unique_copy(in, in + 4, std::ostream_iterator<int>(oss1, "\n")); + VERIFY( oss1.str() == "23\n" ); + + std::unique_copy(in, in + 4, std::ostream_iterator<int>(oss2, "\n"), + std::equal_to<int>()); + VERIFY( oss2.str() == "23\n" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/check_type.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/check_type.cc new file mode 100644 index 000000000..9b5342074 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/check_type.cc @@ -0,0 +1,54 @@ +// Copyright (C) 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.5.8 [lib.alg.unique_copy] + +// { dg-do compile } + +#include <algorithm> +#include <testsuite_iterators.h> + +using __gnu_test::input_iterator_wrapper; +using __gnu_test::output_iterator_wrapper; + +struct S1 { }; + +struct S2 +{ + S2(const S1&) {} +}; + +bool +operator==(const S1&, const S1&) {return true;} + +struct X1 { }; + +struct X2 +{ + X2(const X1&) {} +}; + +bool +predicate(const X1&, const X1&) {return true;} + +output_iterator_wrapper<S2> +test1(input_iterator_wrapper<S1>& s1, output_iterator_wrapper<S2>& s2) +{ return std::unique_copy(s1, s1, s2); } + +output_iterator_wrapper<X2> +test2(input_iterator_wrapper<X1>& x1, output_iterator_wrapper<X2>& x2) +{ return std::unique_copy(x1, x1, x2, predicate); } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..1b2283ada --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/requirements/explicit_instantiation/2.cc @@ -0,0 +1,38 @@ +// { 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 <functional> +#include <testsuite_api.h> + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* in_iterator_type; + typedef value_type* out_iterator_type; + typedef std::less<value_type> predicate_type; + + template out_iterator_type unique_copy(in_iterator_type, in_iterator_type, out_iterator_type); + template out_iterator_type unique_copy(in_iterator_type, in_iterator_type, out_iterator_type, predicate_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/requirements/explicit_instantiation/pod.cc new file mode 100644 index 000000000..15508973a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/requirements/explicit_instantiation/pod.cc @@ -0,0 +1,37 @@ +// { 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* in_iterator_type; + typedef value_type* out_iterator_type; + typedef std::less<value_type> predicate_type; + + template out_iterator_type unique_copy(in_iterator_type, in_iterator_type, out_iterator_type); + template out_iterator_type unique_copy(in_iterator_type, in_iterator_type, out_iterator_type, predicate_type); +} |