diff options
author | Paolo Carlini <paolo@gcc.gnu.org> | 2006-01-04 11:34:45 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2006-01-04 11:34:45 +0000 |
commit | f7ace77f1f4a713c2e96b4daf6181216b5df29d9 (patch) | |
tree | cd3bddece803156966caae41da6fe7437f45b8f1 /libstdc++-v3/testsuite | |
parent | db5d99e8b1c97aac22051f5dfd9296283e0d9848 (diff) | |
download | gcc-f7ace77f1f4a713c2e96b4daf6181216b5df29d9.zip gcc-f7ace77f1f4a713c2e96b4daf6181216b5df29d9.tar.gz gcc-f7ace77f1f4a713c2e96b4daf6181216b5df29d9.tar.bz2 |
sso_string_base.h (__sso_string_base<>::_M_dataplus): Use _CharT_alloc_type as base class.
2006-01-04 Paolo Carlini <pcarlini@suse.de>
* include/ext/sso_string_base.h (__sso_string_base<>::_M_dataplus):
Use _CharT_alloc_type as base class.
(_M_get_allocator, _M_swap, _M_create, _M_destroy): Adjust.
* include/ext/vstring.h (get_allocator): Tidy.
2006-01-04 Paolo Carlini <pcarlini@suse.de>
Implement Option 3 of DR 431 for all the containers.
* include/bits/allocator.h (struct __alloc_swap): Add, swaps
allocators, optimized to nothing in case they are empty.
* include/bits/stl_deque.h (deque<>::swap): Use it.
* include/bits/stl_list.h (list<>::swap): Likewise.
* include/bits/stl_tree.h (_Rb_tree<>::swap): Likewise.
* include/bits/stl_vector.h (vector<>::swap): Likewise.
* include/tr1/hashtable (hashtable<>::swap): Likewise.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_swap):
Likewise.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_swap):
Likewise.
* include/ext/vstring_util.h (__vstring_utility<>::_Alloc_hider):
Clean-up (now vstring uses the generic __alloc_swap facility).
* include/tr1/unordered_map: Adjust includes.
* include/tr1/unordered_set: Likewise.
* docs/html/ext/howto.html: Add an entry for DR 431.
* testsuite/23_containers/deque/modifiers/swap.cc: Move to...
* testsuite/23_containers/deque/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/deque/modifiers/swap/2.cc: New.
* testsuite/23_containers/deque/modifiers/swap/3.cc: New.
* testsuite/23_containers/list/modifiers/swap.cc: Move to...
* testsuite/23_containers/list/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/list/modifiers/swap/2.cc: New.
* testsuite/23_containers/list/modifiers/swap/3.cc: New.
* testsuite/23_containers/vector/modifiers/swap.cc: Move to...
* testsuite/23_containers/vector/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/vector/modifiers/swap/2.cc: New.
* testsuite/23_containers/vector/modifiers/swap/3.cc: New.
* testsuite/23_containers/set/modifiers/swap.cc: Move to...
* testsuite/23_containers/set/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/set/modifiers/swap/2.cc: New.
* testsuite/23_containers/set/modifiers/swap/3.cc: New.
* testsuite/23_containers/map/modifiers/swap.cc: Move to...
* testsuite/23_containers/map/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/map/modifiers/swap/2.cc: New.
* testsuite/23_containers/map/modifiers/swap/3.cc: New.
* testsuite/23_containers/multiset/modifiers/swap.cc: Move to...
* testsuite/23_containers/multiset/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/multiset/modifiers/swap/2.cc: New.
* testsuite/23_containers/multiset/modifiers/swap/3.cc: New.
* testsuite/23_containers/multimap/modifiers/swap.cc: Move to...
* testsuite/23_containers/multimap/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/multimap/modifiers/swap/2.cc: New.
* testsuite/23_containers/multimap/modifiers/swap/3.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc: New.
From-SVN: r109324
Diffstat (limited to 'libstdc++-v3/testsuite')
29 files changed, 3541 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc index 2834ae5..2834ae5 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc new file mode 100644 index 0000000..25402a7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc @@ -0,0 +1,133 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.1.3 deque::swap + +#include <deque> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef deque<char, my_alloc> my_deque; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_deque::size_type size01, size02; + + my_alloc alloc01(1); + + my_deque deq01(alloc01); + size01 = deq01.size(); + my_deque deq02(alloc01); + size02 = deq02.size(); + + deq01.swap(deq02); + VERIFY( deq01.size() == size02 ); + VERIFY( deq01.empty() ); + VERIFY( deq02.size() == size01 ); + VERIFY( deq02.empty() ); + + my_deque deq03(alloc01); + size01 = deq03.size(); + my_deque deq04(title02, title02 + N2, alloc01); + size02 = deq04.size(); + + deq03.swap(deq04); + VERIFY( deq03.size() == size02 ); + VERIFY( equal(deq03.begin(), deq03.end(), title02) ); + VERIFY( deq04.size() == size01 ); + VERIFY( deq04.empty() ); + + my_deque deq05(title01, title01 + N1, alloc01); + size01 = deq05.size(); + my_deque deq06(title02, title02 + N2, alloc01); + size02 = deq06.size(); + + deq05.swap(deq06); + VERIFY( deq05.size() == size02 ); + VERIFY( equal(deq05.begin(), deq05.end(), title02) ); + VERIFY( deq06.size() == size01 ); + VERIFY( equal(deq06.begin(), deq06.end(), title01) ); + + my_deque deq07(title01, title01 + N1, alloc01); + size01 = deq07.size(); + my_deque deq08(title03, title03 + N3, alloc01); + size02 = deq08.size(); + + deq07.swap(deq08); + VERIFY( deq07.size() == size02 ); + VERIFY( equal(deq07.begin(), deq07.end(), title03) ); + VERIFY( deq08.size() == size01 ); + VERIFY( equal(deq08.begin(), deq08.end(), title01) ); + + my_deque deq09(title03, title03 + N3, alloc01); + size01 = deq09.size(); + my_deque deq10(title04, title04 + N4, alloc01); + size02 = deq10.size(); + + deq09.swap(deq10); + VERIFY( deq09.size() == size02 ); + VERIFY( equal(deq09.begin(), deq09.end(), title04) ); + VERIFY( deq10.size() == size01 ); + VERIFY( equal(deq10.begin(), deq10.end(), title03) ); + + my_deque deq11(title04, title04 + N4, alloc01); + size01 = deq11.size(); + my_deque deq12(title01, title01 + N1, alloc01); + size02 = deq12.size(); + + deq11.swap(deq12); + VERIFY( deq11.size() == size02 ); + VERIFY( equal(deq11.begin(), deq11.end(), title01) ); + VERIFY( deq12.size() == size01 ); + VERIFY( equal(deq12.begin(), deq12.end(), title04) ); + + my_deque deq13(title03, title03 + N3, alloc01); + size01 = deq13.size(); + my_deque deq14(title03, title03 + N3, alloc01); + size02 = deq14.size(); + + deq13.swap(deq14); + VERIFY( deq13.size() == size02 ); + VERIFY( equal(deq13.begin(), deq13.end(), title03) ); + VERIFY( deq14.size() == size01 ); + VERIFY( equal(deq14.begin(), deq14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc new file mode 100644 index 0000000..70f5e2a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc @@ -0,0 +1,162 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.1.3 deque::swap + +#include <deque> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef deque<char, my_alloc> my_deque; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_deque::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_deque deq01(alloc01); + size01 = deq01.size(); + personality01 = deq01.get_allocator().get_personality(); + my_deque deq02(alloc02); + size02 = deq02.size(); + personality02 = deq02.get_allocator().get_personality(); + + deq01.swap(deq02); + VERIFY( deq01.size() == size02 ); + VERIFY( deq01.empty() ); + VERIFY( deq02.size() == size01 ); + VERIFY( deq02.empty() ); + VERIFY( deq01.get_allocator().get_personality() == personality02 ); + VERIFY( deq02.get_allocator().get_personality() == personality01 ); + + my_deque deq03(alloc02); + size01 = deq03.size(); + personality01 = deq03.get_allocator().get_personality(); + my_deque deq04(title02, title02 + N2, alloc01); + size02 = deq04.size(); + personality02 = deq04.get_allocator().get_personality(); + + deq03.swap(deq04); + VERIFY( deq03.size() == size02 ); + VERIFY( equal(deq03.begin(), deq03.end(), title02) ); + VERIFY( deq04.size() == size01 ); + VERIFY( deq04.empty() ); + VERIFY( deq03.get_allocator().get_personality() == personality02 ); + VERIFY( deq04.get_allocator().get_personality() == personality01 ); + + my_deque deq05(title01, title01 + N1, alloc01); + size01 = deq05.size(); + personality01 = deq05.get_allocator().get_personality(); + my_deque deq06(title02, title02 + N2, alloc02); + size02 = deq06.size(); + personality02 = deq06.get_allocator().get_personality(); + + deq05.swap(deq06); + VERIFY( deq05.size() == size02 ); + VERIFY( equal(deq05.begin(), deq05.end(), title02) ); + VERIFY( deq06.size() == size01 ); + VERIFY( equal(deq06.begin(), deq06.end(), title01) ); + VERIFY( deq05.get_allocator().get_personality() == personality02 ); + VERIFY( deq06.get_allocator().get_personality() == personality01 ); + + my_deque deq07(title01, title01 + N1, alloc02); + size01 = deq07.size(); + personality01 = deq07.get_allocator().get_personality(); + my_deque deq08(title03, title03 + N3, alloc01); + size02 = deq08.size(); + personality02 = deq08.get_allocator().get_personality(); + + deq07.swap(deq08); + VERIFY( deq07.size() == size02 ); + VERIFY( equal(deq07.begin(), deq07.end(), title03) ); + VERIFY( deq08.size() == size01 ); + VERIFY( equal(deq08.begin(), deq08.end(), title01) ); + VERIFY( deq07.get_allocator().get_personality() == personality02 ); + VERIFY( deq08.get_allocator().get_personality() == personality01 ); + + my_deque deq09(title03, title03 + N3, alloc01); + size01 = deq09.size(); + personality01 = deq09.get_allocator().get_personality(); + my_deque deq10(title04, title04 + N4, alloc02); + size02 = deq10.size(); + personality02 = deq10.get_allocator().get_personality(); + + deq09.swap(deq10); + VERIFY( deq09.size() == size02 ); + VERIFY( equal(deq09.begin(), deq09.end(), title04) ); + VERIFY( deq10.size() == size01 ); + VERIFY( equal(deq10.begin(), deq10.end(), title03) ); + VERIFY( deq09.get_allocator().get_personality() == personality02 ); + VERIFY( deq10.get_allocator().get_personality() == personality01 ); + + my_deque deq11(title04, title04 + N4, alloc02); + size01 = deq11.size(); + personality01 = deq11.get_allocator().get_personality(); + my_deque deq12(title01, title01 + N1, alloc01); + size02 = deq12.size(); + personality02 = deq12.get_allocator().get_personality(); + + deq11.swap(deq12); + VERIFY( deq11.size() == size02 ); + VERIFY( equal(deq11.begin(), deq11.end(), title01) ); + VERIFY( deq12.size() == size01 ); + VERIFY( equal(deq12.begin(), deq12.end(), title04) ); + VERIFY( deq11.get_allocator().get_personality() == personality02 ); + VERIFY( deq12.get_allocator().get_personality() == personality01 ); + + my_deque deq13(title03, title03 + N3, alloc01); + size01 = deq13.size(); + personality01 = deq13.get_allocator().get_personality(); + my_deque deq14(title03, title03 + N3, alloc02); + size02 = deq14.size(); + personality02 = deq14.get_allocator().get_personality(); + + deq13.swap(deq14); + VERIFY( deq13.size() == size02 ); + VERIFY( equal(deq13.begin(), deq13.end(), title03) ); + VERIFY( deq14.size() == size01 ); + VERIFY( equal(deq14.begin(), deq14.end(), title03) ); + VERIFY( deq13.get_allocator().get_personality() == personality02 ); + VERIFY( deq14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc index a277ac5..a277ac5 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc new file mode 100644 index 0000000..084143c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc @@ -0,0 +1,133 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.2.3 list::swap + +#include <list> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef list<char, my_alloc> my_list; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_list::size_type size01, size02; + + my_alloc alloc01(1); + + my_list lis01(alloc01); + size01 = lis01.size(); + my_list lis02(alloc01); + size02 = lis02.size(); + + lis01.swap(lis02); + VERIFY( lis01.size() == size02 ); + VERIFY( lis01.empty() ); + VERIFY( lis02.size() == size01 ); + VERIFY( lis02.empty() ); + + my_list lis03(alloc01); + size01 = lis03.size(); + my_list lis04(title02, title02 + N2, alloc01); + size02 = lis04.size(); + + lis03.swap(lis04); + VERIFY( lis03.size() == size02 ); + VERIFY( equal(lis03.begin(), lis03.end(), title02) ); + VERIFY( lis04.size() == size01 ); + VERIFY( lis04.empty() ); + + my_list lis05(title01, title01 + N1, alloc01); + size01 = lis05.size(); + my_list lis06(title02, title02 + N2, alloc01); + size02 = lis06.size(); + + lis05.swap(lis06); + VERIFY( lis05.size() == size02 ); + VERIFY( equal(lis05.begin(), lis05.end(), title02) ); + VERIFY( lis06.size() == size01 ); + VERIFY( equal(lis06.begin(), lis06.end(), title01) ); + + my_list lis07(title01, title01 + N1, alloc01); + size01 = lis07.size(); + my_list lis08(title03, title03 + N3, alloc01); + size02 = lis08.size(); + + lis07.swap(lis08); + VERIFY( lis07.size() == size02 ); + VERIFY( equal(lis07.begin(), lis07.end(), title03) ); + VERIFY( lis08.size() == size01 ); + VERIFY( equal(lis08.begin(), lis08.end(), title01) ); + + my_list lis09(title03, title03 + N3, alloc01); + size01 = lis09.size(); + my_list lis10(title04, title04 + N4, alloc01); + size02 = lis10.size(); + + lis09.swap(lis10); + VERIFY( lis09.size() == size02 ); + VERIFY( equal(lis09.begin(), lis09.end(), title04) ); + VERIFY( lis10.size() == size01 ); + VERIFY( equal(lis10.begin(), lis10.end(), title03) ); + + my_list lis11(title04, title04 + N4, alloc01); + size01 = lis11.size(); + my_list lis12(title01, title01 + N1, alloc01); + size02 = lis12.size(); + + lis11.swap(lis12); + VERIFY( lis11.size() == size02 ); + VERIFY( equal(lis11.begin(), lis11.end(), title01) ); + VERIFY( lis12.size() == size01 ); + VERIFY( equal(lis12.begin(), lis12.end(), title04) ); + + my_list lis13(title03, title03 + N3, alloc01); + size01 = lis13.size(); + my_list lis14(title03, title03 + N3, alloc01); + size02 = lis14.size(); + + lis13.swap(lis14); + VERIFY( lis13.size() == size02 ); + VERIFY( equal(lis13.begin(), lis13.end(), title03) ); + VERIFY( lis14.size() == size01 ); + VERIFY( equal(lis14.begin(), lis14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc new file mode 100644 index 0000000..714e0cc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc @@ -0,0 +1,162 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.2.3 list::swap + +#include <list> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef list<char, my_alloc> my_list; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_list::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_list lis01(alloc01); + size01 = lis01.size(); + personality01 = lis01.get_allocator().get_personality(); + my_list lis02(alloc02); + size02 = lis02.size(); + personality02 = lis02.get_allocator().get_personality(); + + lis01.swap(lis02); + VERIFY( lis01.size() == size02 ); + VERIFY( lis01.empty() ); + VERIFY( lis02.size() == size01 ); + VERIFY( lis02.empty() ); + VERIFY( lis01.get_allocator().get_personality() == personality02 ); + VERIFY( lis02.get_allocator().get_personality() == personality01 ); + + my_list lis03(alloc02); + size01 = lis03.size(); + personality01 = lis03.get_allocator().get_personality(); + my_list lis04(title02, title02 + N2, alloc01); + size02 = lis04.size(); + personality02 = lis04.get_allocator().get_personality(); + + lis03.swap(lis04); + VERIFY( lis03.size() == size02 ); + VERIFY( equal(lis03.begin(), lis03.end(), title02) ); + VERIFY( lis04.size() == size01 ); + VERIFY( lis04.empty() ); + VERIFY( lis03.get_allocator().get_personality() == personality02 ); + VERIFY( lis04.get_allocator().get_personality() == personality01 ); + + my_list lis05(title01, title01 + N1, alloc01); + size01 = lis05.size(); + personality01 = lis05.get_allocator().get_personality(); + my_list lis06(title02, title02 + N2, alloc02); + size02 = lis06.size(); + personality02 = lis06.get_allocator().get_personality(); + + lis05.swap(lis06); + VERIFY( lis05.size() == size02 ); + VERIFY( equal(lis05.begin(), lis05.end(), title02) ); + VERIFY( lis06.size() == size01 ); + VERIFY( equal(lis06.begin(), lis06.end(), title01) ); + VERIFY( lis05.get_allocator().get_personality() == personality02 ); + VERIFY( lis06.get_allocator().get_personality() == personality01 ); + + my_list lis07(title01, title01 + N1, alloc02); + size01 = lis07.size(); + personality01 = lis07.get_allocator().get_personality(); + my_list lis08(title03, title03 + N3, alloc01); + size02 = lis08.size(); + personality02 = lis08.get_allocator().get_personality(); + + lis07.swap(lis08); + VERIFY( lis07.size() == size02 ); + VERIFY( equal(lis07.begin(), lis07.end(), title03) ); + VERIFY( lis08.size() == size01 ); + VERIFY( equal(lis08.begin(), lis08.end(), title01) ); + VERIFY( lis07.get_allocator().get_personality() == personality02 ); + VERIFY( lis08.get_allocator().get_personality() == personality01 ); + + my_list lis09(title03, title03 + N3, alloc01); + size01 = lis09.size(); + personality01 = lis09.get_allocator().get_personality(); + my_list lis10(title04, title04 + N4, alloc02); + size02 = lis10.size(); + personality02 = lis10.get_allocator().get_personality(); + + lis09.swap(lis10); + VERIFY( lis09.size() == size02 ); + VERIFY( equal(lis09.begin(), lis09.end(), title04) ); + VERIFY( lis10.size() == size01 ); + VERIFY( equal(lis10.begin(), lis10.end(), title03) ); + VERIFY( lis09.get_allocator().get_personality() == personality02 ); + VERIFY( lis10.get_allocator().get_personality() == personality01 ); + + my_list lis11(title04, title04 + N4, alloc02); + size01 = lis11.size(); + personality01 = lis11.get_allocator().get_personality(); + my_list lis12(title01, title01 + N1, alloc01); + size02 = lis12.size(); + personality02 = lis12.get_allocator().get_personality(); + + lis11.swap(lis12); + VERIFY( lis11.size() == size02 ); + VERIFY( equal(lis11.begin(), lis11.end(), title01) ); + VERIFY( lis12.size() == size01 ); + VERIFY( equal(lis12.begin(), lis12.end(), title04) ); + VERIFY( lis11.get_allocator().get_personality() == personality02 ); + VERIFY( lis12.get_allocator().get_personality() == personality01 ); + + my_list lis13(title03, title03 + N3, alloc01); + size01 = lis13.size(); + personality01 = lis13.get_allocator().get_personality(); + my_list lis14(title03, title03 + N3, alloc02); + size02 = lis14.size(); + personality02 = lis14.get_allocator().get_personality(); + + lis13.swap(lis14); + VERIFY( lis13.size() == size02 ); + VERIFY( equal(lis13.begin(), lis13.end(), title03) ); + VERIFY( lis14.size() == size01 ); + VERIFY( equal(lis14.begin(), lis14.end(), title03) ); + VERIFY( lis13.get_allocator().get_personality() == personality02 ); + VERIFY( lis14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc index 85aa95c..85aa95c 100644 --- a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc new file mode 100644 index 0000000..5b1a17b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc @@ -0,0 +1,147 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.1 map::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef map<char, int, less<char>, my_alloc> my_map; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + map<char, int> map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + map<char, int> map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + map<char, int> map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + map<char, int> map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_map::size_type size01, size02; + + my_alloc alloc01(1); + + my_map map01(less<char>(), alloc01); + size01 = map01.size(); + my_map map02(less<char>(), alloc01); + size02 = map02.size(); + + map01.swap(map02); + VERIFY( map01.size() == size02 ); + VERIFY( map01.empty() ); + VERIFY( map02.size() == size01 ); + VERIFY( map02.empty() ); + + my_map map03(less<char>(), alloc01); + size01 = map03.size(); + my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map04.size(); + + map03.swap(map04); + VERIFY( map03.size() == size02 ); + VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) ); + VERIFY( map04.size() == size01 ); + VERIFY( map04.empty() ); + + my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map05.size(); + my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map06.size(); + + map05.swap(map06); + VERIFY( map05.size() == size02 ); + VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) ); + VERIFY( map06.size() == size01 ); + VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) ); + + my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map07.size(); + my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map08.size(); + + map07.swap(map08); + VERIFY( map07.size() == size02 ); + VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) ); + VERIFY( map08.size() == size01 ); + VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) ); + + my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map09.size(); + my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01); + size02 = map10.size(); + + map09.swap(map10); + VERIFY( map09.size() == size02 ); + VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) ); + VERIFY( map10.size() == size01 ); + VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) ); + + my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01); + size01 = map11.size(); + my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size02 = map12.size(); + + map11.swap(map12); + VERIFY( map11.size() == size02 ); + VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) ); + VERIFY( map12.size() == size01 ); + VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) ); + + my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map13.size(); + my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map14.size(); + + map13.swap(map14); + VERIFY( map13.size() == size02 ); + VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) ); + VERIFY( map14.size() == size01 ); + VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc new file mode 100644 index 0000000..2152b4b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc @@ -0,0 +1,176 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.1 map::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef map<char, int, less<char>, my_alloc> my_map; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + map<char, int> map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + map<char, int> map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + map<char, int> map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + map<char, int> map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_map::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_map map01(less<char>(), alloc01); + size01 = map01.size(); + personality01 = map01.get_allocator().get_personality(); + my_map map02(less<char>(), alloc02); + size02 = map02.size(); + personality02 = map02.get_allocator().get_personality(); + + map01.swap(map02); + VERIFY( map01.size() == size02 ); + VERIFY( map01.empty() ); + VERIFY( map02.size() == size01 ); + VERIFY( map02.empty() ); + VERIFY( map01.get_allocator().get_personality() == personality02 ); + VERIFY( map02.get_allocator().get_personality() == personality01 ); + + my_map map03(less<char>(), alloc02); + size01 = map03.size(); + personality01 = map03.get_allocator().get_personality(); + my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map04.size(); + personality02 = map04.get_allocator().get_personality(); + + map03.swap(map04); + VERIFY( map03.size() == size02 ); + VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) ); + VERIFY( map04.size() == size01 ); + VERIFY( map04.empty() ); + VERIFY( map03.get_allocator().get_personality() == personality02 ); + VERIFY( map04.get_allocator().get_personality() == personality01 ); + + my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map05.size(); + personality01 = map05.get_allocator().get_personality(); + my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc02); + size02 = map06.size(); + personality02 = map06.get_allocator().get_personality(); + + map05.swap(map06); + VERIFY( map05.size() == size02 ); + VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) ); + VERIFY( map06.size() == size01 ); + VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) ); + VERIFY( map05.get_allocator().get_personality() == personality02 ); + VERIFY( map06.get_allocator().get_personality() == personality01 ); + + my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc02); + size01 = map07.size(); + personality01 = map07.get_allocator().get_personality(); + my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map08.size(); + personality02 = map08.get_allocator().get_personality(); + + map07.swap(map08); + VERIFY( map07.size() == size02 ); + VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) ); + VERIFY( map08.size() == size01 ); + VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) ); + VERIFY( map07.get_allocator().get_personality() == personality02 ); + VERIFY( map08.get_allocator().get_personality() == personality01 ); + + my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map09.size(); + personality01 = map09.get_allocator().get_personality(); + my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02); + size02 = map10.size(); + personality02 = map10.get_allocator().get_personality(); + + map09.swap(map10); + VERIFY( map09.size() == size02 ); + VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) ); + VERIFY( map10.size() == size01 ); + VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) ); + VERIFY( map09.get_allocator().get_personality() == personality02 ); + VERIFY( map10.get_allocator().get_personality() == personality01 ); + + my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02); + size01 = map11.size(); + personality01 = map11.get_allocator().get_personality(); + my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size02 = map12.size(); + personality02 = map12.get_allocator().get_personality(); + + map11.swap(map12); + VERIFY( map11.size() == size02 ); + VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) ); + VERIFY( map12.size() == size01 ); + VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) ); + VERIFY( map11.get_allocator().get_personality() == personality02 ); + VERIFY( map12.get_allocator().get_personality() == personality01 ); + + my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map13.size(); + personality01 = map13.get_allocator().get_personality(); + my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc02); + size02 = map14.size(); + personality02 = map14.get_allocator().get_personality(); + + map13.swap(map14); + VERIFY( map13.size() == size02 ); + VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) ); + VERIFY( map14.size() == size01 ); + VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) ); + VERIFY( map13.get_allocator().get_personality() == personality02 ); + VERIFY( map14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc index 76cbe46..76cbe46 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc new file mode 100644 index 0000000..dc2c9c9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc @@ -0,0 +1,147 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.2 multimap::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1); + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + my_mmap mmap02(less<char>(), alloc01); + size02 = mmap02.size(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + + my_mmap mmap03(less<char>(), alloc01); + size01 = mmap03.size(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap06.size(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap07.size(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size02 = mmap10.size(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size01 = mmap11.size(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap14.size(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc new file mode 100644 index 0000000..9214490 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc @@ -0,0 +1,176 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.2 multimap::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + personality01 = mmap01.get_allocator().get_personality(); + my_mmap mmap02(less<char>(), alloc02); + size02 = mmap02.size(); + personality02 = mmap02.get_allocator().get_personality(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + VERIFY( mmap01.get_allocator().get_personality() == personality02 ); + VERIFY( mmap02.get_allocator().get_personality() == personality01 ); + + my_mmap mmap03(less<char>(), alloc02); + size01 = mmap03.size(); + personality01 = mmap03.get_allocator().get_personality(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + personality02 = mmap04.get_allocator().get_personality(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + VERIFY( mmap03.get_allocator().get_personality() == personality02 ); + VERIFY( mmap04.get_allocator().get_personality() == personality01 ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + personality01 = mmap05.get_allocator().get_personality(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc02); + size02 = mmap06.size(); + personality02 = mmap06.get_allocator().get_personality(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + VERIFY( mmap05.get_allocator().get_personality() == personality02 ); + VERIFY( mmap06.get_allocator().get_personality() == personality01 ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc02); + size01 = mmap07.size(); + personality01 = mmap07.get_allocator().get_personality(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + personality02 = mmap08.get_allocator().get_personality(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + VERIFY( mmap07.get_allocator().get_personality() == personality02 ); + VERIFY( mmap08.get_allocator().get_personality() == personality01 ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + personality01 = mmap09.get_allocator().get_personality(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size02 = mmap10.size(); + personality02 = mmap10.get_allocator().get_personality(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + VERIFY( mmap09.get_allocator().get_personality() == personality02 ); + VERIFY( mmap10.get_allocator().get_personality() == personality01 ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size01 = mmap11.size(); + personality01 = mmap11.get_allocator().get_personality(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + personality02 = mmap12.get_allocator().get_personality(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + VERIFY( mmap11.get_allocator().get_personality() == personality02 ); + VERIFY( mmap12.get_allocator().get_personality() == personality01 ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + personality01 = mmap13.get_allocator().get_personality(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc02); + size02 = mmap14.size(); + personality02 = mmap14.get_allocator().get_personality(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); + VERIFY( mmap13.get_allocator().get_personality() == personality02 ); + VERIFY( mmap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc index 2385199..2385199 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc new file mode 100644 index 0000000..587dc9c4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc @@ -0,0 +1,138 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.4 multiset::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef multiset<char, less<char>, my_alloc> my_multiset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + const multiset<char> mset01_ref(title01, title01 + N1); + const multiset<char> mset02_ref(title02, title02 + N2); + const multiset<char> mset03_ref(title03, title03 + N3); + const multiset<char> mset04_ref(title04, title04 + N4); + + my_multiset::size_type size01, size02; + + my_alloc alloc01(1); + + my_multiset mset01(less<char>(), alloc01); + size01 = mset01.size(); + my_multiset mset02(less<char>(), alloc01); + size02 = mset02.size(); + + mset01.swap(mset02); + VERIFY( mset01.size() == size02 ); + VERIFY( mset01.empty() ); + VERIFY( mset02.size() == size01 ); + VERIFY( mset02.empty() ); + + my_multiset mset03(less<char>(), alloc01); + size01 = mset03.size(); + my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); + size02 = mset04.size(); + + mset03.swap(mset04); + VERIFY( mset03.size() == size02 ); + VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); + VERIFY( mset04.size() == size01 ); + VERIFY( mset04.empty() ); + + my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); + size01 = mset05.size(); + my_multiset mset06(title02, title02 + N2, less<char>(), alloc01); + size02 = mset06.size(); + + mset05.swap(mset06); + VERIFY( mset05.size() == size02 ); + VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); + VERIFY( mset06.size() == size01 ); + VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); + + my_multiset mset07(title01, title01 + N1, less<char>(), alloc01); + size01 = mset07.size(); + my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); + size02 = mset08.size(); + + mset07.swap(mset08); + VERIFY( mset07.size() == size02 ); + VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); + VERIFY( mset08.size() == size01 ); + VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); + + my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); + size01 = mset09.size(); + my_multiset mset10(title04, title04 + N4, less<char>(), alloc01); + size02 = mset10.size(); + + mset09.swap(mset10); + VERIFY( mset09.size() == size02 ); + VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); + VERIFY( mset10.size() == size01 ); + VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); + + my_multiset mset11(title04, title04 + N4, less<char>(), alloc01); + size01 = mset11.size(); + my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); + size02 = mset12.size(); + + mset11.swap(mset12); + VERIFY( mset11.size() == size02 ); + VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); + VERIFY( mset12.size() == size01 ); + VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); + + my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); + size01 = mset13.size(); + my_multiset mset14(title03, title03 + N3, less<char>(), alloc01); + size02 = mset14.size(); + + mset13.swap(mset14); + VERIFY( mset13.size() == size02 ); + VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); + VERIFY( mset14.size() == size01 ); + VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc new file mode 100644 index 0000000..e5a05d7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc @@ -0,0 +1,167 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.4 multiset::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef multiset<char, less<char>, my_alloc> my_multiset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + const multiset<char> mset01_ref(title01, title01 + N1); + const multiset<char> mset02_ref(title02, title02 + N2); + const multiset<char> mset03_ref(title03, title03 + N3); + const multiset<char> mset04_ref(title04, title04 + N4); + + my_multiset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_multiset mset01(less<char>(), alloc01); + size01 = mset01.size(); + personality01 = mset01.get_allocator().get_personality(); + my_multiset mset02(less<char>(), alloc02); + size02 = mset02.size(); + personality02 = mset02.get_allocator().get_personality(); + + mset01.swap(mset02); + VERIFY( mset01.size() == size02 ); + VERIFY( mset01.empty() ); + VERIFY( mset02.size() == size01 ); + VERIFY( mset02.empty() ); + VERIFY( mset01.get_allocator().get_personality() == personality02 ); + VERIFY( mset02.get_allocator().get_personality() == personality01 ); + + my_multiset mset03(less<char>(), alloc02); + size01 = mset03.size(); + personality01 = mset03.get_allocator().get_personality(); + my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); + size02 = mset04.size(); + personality02 = mset04.get_allocator().get_personality(); + + mset03.swap(mset04); + VERIFY( mset03.size() == size02 ); + VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); + VERIFY( mset04.size() == size01 ); + VERIFY( mset04.empty() ); + VERIFY( mset03.get_allocator().get_personality() == personality02 ); + VERIFY( mset04.get_allocator().get_personality() == personality01 ); + + my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); + size01 = mset05.size(); + personality01 = mset05.get_allocator().get_personality(); + my_multiset mset06(title02, title02 + N2, less<char>(), alloc02); + size02 = mset06.size(); + personality02 = mset06.get_allocator().get_personality(); + + mset05.swap(mset06); + VERIFY( mset05.size() == size02 ); + VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); + VERIFY( mset06.size() == size01 ); + VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); + VERIFY( mset05.get_allocator().get_personality() == personality02 ); + VERIFY( mset06.get_allocator().get_personality() == personality01 ); + + my_multiset mset07(title01, title01 + N1, less<char>(), alloc02); + size01 = mset07.size(); + personality01 = mset07.get_allocator().get_personality(); + my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); + size02 = mset08.size(); + personality02 = mset08.get_allocator().get_personality(); + + mset07.swap(mset08); + VERIFY( mset07.size() == size02 ); + VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); + VERIFY( mset08.size() == size01 ); + VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); + VERIFY( mset07.get_allocator().get_personality() == personality02 ); + VERIFY( mset08.get_allocator().get_personality() == personality01 ); + + my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); + size01 = mset09.size(); + personality01 = mset09.get_allocator().get_personality(); + my_multiset mset10(title04, title04 + N4, less<char>(), alloc02); + size02 = mset10.size(); + personality02 = mset10.get_allocator().get_personality(); + + mset09.swap(mset10); + VERIFY( mset09.size() == size02 ); + VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); + VERIFY( mset10.size() == size01 ); + VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); + VERIFY( mset09.get_allocator().get_personality() == personality02 ); + VERIFY( mset10.get_allocator().get_personality() == personality01 ); + + my_multiset mset11(title04, title04 + N4, less<char>(), alloc02); + size01 = mset11.size(); + personality01 = mset11.get_allocator().get_personality(); + my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); + size02 = mset12.size(); + personality02 = mset12.get_allocator().get_personality(); + + mset11.swap(mset12); + VERIFY( mset11.size() == size02 ); + VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); + VERIFY( mset12.size() == size01 ); + VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); + VERIFY( mset11.get_allocator().get_personality() == personality02 ); + VERIFY( mset12.get_allocator().get_personality() == personality01 ); + + my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); + size01 = mset13.size(); + personality01 = mset13.get_allocator().get_personality(); + my_multiset mset14(title03, title03 + N3, less<char>(), alloc02); + size02 = mset14.size(); + personality02 = mset14.get_allocator().get_personality(); + + mset13.swap(mset14); + VERIFY( mset13.size() == size02 ); + VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); + VERIFY( mset14.size() == size01 ); + VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); + VERIFY( mset13.get_allocator().get_personality() == personality02 ); + VERIFY( mset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc index 7efa8a6..7efa8a6 100644 --- a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc new file mode 100644 index 0000000..1849630 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc @@ -0,0 +1,138 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.3 set::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef set<char, less<char>, my_alloc> my_set; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + const set<char> set01_ref(title01, title01 + N1); + const set<char> set02_ref(title02, title02 + N2); + const set<char> set03_ref(title03, title03 + N3); + const set<char> set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1); + + my_set set01(less<char>(), alloc01); + size01 = set01.size(); + my_set set02(less<char>(), alloc01); + size02 = set02.size(); + + set01.swap(set02); + VERIFY( set01.size() == size02 ); + VERIFY( set01.empty() ); + VERIFY( set02.size() == size01 ); + VERIFY( set02.empty() ); + + my_set set03(less<char>(), alloc01); + size01 = set03.size(); + my_set set04(title02, title02 + N2, less<char>(), alloc01); + size02 = set04.size(); + + set03.swap(set04); + VERIFY( set03.size() == size02 ); + VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) ); + VERIFY( set04.size() == size01 ); + VERIFY( set04.empty() ); + + my_set set05(title01, title01 + N1, less<char>(), alloc01); + size01 = set05.size(); + my_set set06(title02, title02 + N2, less<char>(), alloc01); + size02 = set06.size(); + + set05.swap(set06); + VERIFY( set05.size() == size02 ); + VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) ); + VERIFY( set06.size() == size01 ); + VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) ); + + my_set set07(title01, title01 + N1, less<char>(), alloc01); + size01 = set07.size(); + my_set set08(title03, title03 + N3, less<char>(), alloc01); + size02 = set08.size(); + + set07.swap(set08); + VERIFY( set07.size() == size02 ); + VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) ); + VERIFY( set08.size() == size01 ); + VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) ); + + my_set set09(title03, title03 + N3, less<char>(), alloc01); + size01 = set09.size(); + my_set set10(title04, title04 + N4, less<char>(), alloc01); + size02 = set10.size(); + + set09.swap(set10); + VERIFY( set09.size() == size02 ); + VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) ); + VERIFY( set10.size() == size01 ); + VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) ); + + my_set set11(title04, title04 + N4, less<char>(), alloc01); + size01 = set11.size(); + my_set set12(title01, title01 + N1, less<char>(), alloc01); + size02 = set12.size(); + + set11.swap(set12); + VERIFY( set11.size() == size02 ); + VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) ); + VERIFY( set12.size() == size01 ); + VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) ); + + my_set set13(title03, title03 + N3, less<char>(), alloc01); + size01 = set13.size(); + my_set set14(title03, title03 + N3, less<char>(), alloc01); + size02 = set14.size(); + + set13.swap(set14); + VERIFY( set13.size() == size02 ); + VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) ); + VERIFY( set14.size() == size01 ); + VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc new file mode 100644 index 0000000..8e71af4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc @@ -0,0 +1,167 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.3 set::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef set<char, less<char>, my_alloc> my_set; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + const set<char> set01_ref(title01, title01 + N1); + const set<char> set02_ref(title02, title02 + N2); + const set<char> set03_ref(title03, title03 + N3); + const set<char> set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_set set01(less<char>(), alloc01); + size01 = set01.size(); + personality01 = set01.get_allocator().get_personality(); + my_set set02(less<char>(), alloc02); + size02 = set02.size(); + personality02 = set02.get_allocator().get_personality(); + + set01.swap(set02); + VERIFY( set01.size() == size02 ); + VERIFY( set01.empty() ); + VERIFY( set02.size() == size01 ); + VERIFY( set02.empty() ); + VERIFY( set01.get_allocator().get_personality() == personality02 ); + VERIFY( set02.get_allocator().get_personality() == personality01 ); + + my_set set03(less<char>(), alloc02); + size01 = set03.size(); + personality01 = set03.get_allocator().get_personality(); + my_set set04(title02, title02 + N2, less<char>(), alloc01); + size02 = set04.size(); + personality02 = set04.get_allocator().get_personality(); + + set03.swap(set04); + VERIFY( set03.size() == size02 ); + VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) ); + VERIFY( set04.size() == size01 ); + VERIFY( set04.empty() ); + VERIFY( set03.get_allocator().get_personality() == personality02 ); + VERIFY( set04.get_allocator().get_personality() == personality01 ); + + my_set set05(title01, title01 + N1, less<char>(), alloc01); + size01 = set05.size(); + personality01 = set05.get_allocator().get_personality(); + my_set set06(title02, title02 + N2, less<char>(), alloc02); + size02 = set06.size(); + personality02 = set06.get_allocator().get_personality(); + + set05.swap(set06); + VERIFY( set05.size() == size02 ); + VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) ); + VERIFY( set06.size() == size01 ); + VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) ); + VERIFY( set05.get_allocator().get_personality() == personality02 ); + VERIFY( set06.get_allocator().get_personality() == personality01 ); + + my_set set07(title01, title01 + N1, less<char>(), alloc02); + size01 = set07.size(); + personality01 = set07.get_allocator().get_personality(); + my_set set08(title03, title03 + N3, less<char>(), alloc01); + size02 = set08.size(); + personality02 = set08.get_allocator().get_personality(); + + set07.swap(set08); + VERIFY( set07.size() == size02 ); + VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) ); + VERIFY( set08.size() == size01 ); + VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) ); + VERIFY( set07.get_allocator().get_personality() == personality02 ); + VERIFY( set08.get_allocator().get_personality() == personality01 ); + + my_set set09(title03, title03 + N3, less<char>(), alloc01); + size01 = set09.size(); + personality01 = set09.get_allocator().get_personality(); + my_set set10(title04, title04 + N4, less<char>(), alloc02); + size02 = set10.size(); + personality02 = set10.get_allocator().get_personality(); + + set09.swap(set10); + VERIFY( set09.size() == size02 ); + VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) ); + VERIFY( set10.size() == size01 ); + VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) ); + VERIFY( set09.get_allocator().get_personality() == personality02 ); + VERIFY( set10.get_allocator().get_personality() == personality01 ); + + my_set set11(title04, title04 + N4, less<char>(), alloc02); + size01 = set11.size(); + personality01 = set11.get_allocator().get_personality(); + my_set set12(title01, title01 + N1, less<char>(), alloc01); + size02 = set12.size(); + personality02 = set12.get_allocator().get_personality(); + + set11.swap(set12); + VERIFY( set11.size() == size02 ); + VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) ); + VERIFY( set12.size() == size01 ); + VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) ); + VERIFY( set11.get_allocator().get_personality() == personality02 ); + VERIFY( set12.get_allocator().get_personality() == personality01 ); + + my_set set13(title03, title03 + N3, less<char>(), alloc01); + size01 = set13.size(); + personality01 = set13.get_allocator().get_personality(); + my_set set14(title03, title03 + N3, less<char>(), alloc02); + size02 = set14.size(); + personality02 = set14.get_allocator().get_personality(); + + set13.swap(set14); + VERIFY( set13.size() == size02 ); + VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) ); + VERIFY( set14.size() == size01 ); + VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) ); + VERIFY( set13.get_allocator().get_personality() == personality02 ); + VERIFY( set14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc index 8489945..8489945 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc new file mode 100644 index 0000000..ea41b4a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc @@ -0,0 +1,133 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.4.3 vector::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef vector<char, my_alloc> my_vector; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1); + + my_vector vec01(alloc01); + size01 = vec01.size(); + my_vector vec02(alloc01); + size02 = vec02.size(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + + my_vector vec03(alloc01); + size01 = vec03.size(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + my_vector vec06(title02, title02 + N2, alloc01); + size02 = vec06.size(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + + my_vector vec07(title01, title01 + N1, alloc01); + size01 = vec07.size(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + my_vector vec10(title04, title04 + N4, alloc01); + size02 = vec10.size(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + + my_vector vec11(title04, title04 + N4, alloc01); + size01 = vec11.size(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + my_vector vec14(title03, title03 + N3, alloc01); + size02 = vec14.size(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc new file mode 100644 index 0000000..7f1acdc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc @@ -0,0 +1,162 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.4.3 vector::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef vector<char, my_alloc> my_vector; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_vector vec01(alloc01); + size01 = vec01.size(); + personality01 = vec01.get_allocator().get_personality(); + my_vector vec02(alloc02); + size02 = vec02.size(); + personality02 = vec02.get_allocator().get_personality(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + VERIFY( vec01.get_allocator().get_personality() == personality02 ); + VERIFY( vec02.get_allocator().get_personality() == personality01 ); + + my_vector vec03(alloc02); + size01 = vec03.size(); + personality01 = vec03.get_allocator().get_personality(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + personality02 = vec04.get_allocator().get_personality(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + VERIFY( vec03.get_allocator().get_personality() == personality02 ); + VERIFY( vec04.get_allocator().get_personality() == personality01 ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + personality01 = vec05.get_allocator().get_personality(); + my_vector vec06(title02, title02 + N2, alloc02); + size02 = vec06.size(); + personality02 = vec06.get_allocator().get_personality(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + VERIFY( vec05.get_allocator().get_personality() == personality02 ); + VERIFY( vec06.get_allocator().get_personality() == personality01 ); + + my_vector vec07(title01, title01 + N1, alloc02); + size01 = vec07.size(); + personality01 = vec07.get_allocator().get_personality(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + personality02 = vec08.get_allocator().get_personality(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + VERIFY( vec07.get_allocator().get_personality() == personality02 ); + VERIFY( vec08.get_allocator().get_personality() == personality01 ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + personality01 = vec09.get_allocator().get_personality(); + my_vector vec10(title04, title04 + N4, alloc02); + size02 = vec10.size(); + personality02 = vec10.get_allocator().get_personality(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + VERIFY( vec09.get_allocator().get_personality() == personality02 ); + VERIFY( vec10.get_allocator().get_personality() == personality01 ); + + my_vector vec11(title04, title04 + N4, alloc02); + size01 = vec11.size(); + personality01 = vec11.get_allocator().get_personality(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + personality02 = vec12.get_allocator().get_personality(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + VERIFY( vec11.get_allocator().get_personality() == personality02 ); + VERIFY( vec12.get_allocator().get_personality() == personality01 ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + personality01 = vec13.get_allocator().get_personality(); + my_vector vec14(title03, title03 + N3, alloc02); + size02 = vec14.size(); + personality02 = vec14.get_allocator().get_personality(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); + VERIFY( vec13.get_allocator().get_personality() == personality02 ); + VERIFY( vec14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc new file mode 100644 index 0000000..d379774 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc @@ -0,0 +1,162 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.4 unordered_map::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_map<char, int, hash<char>, equal_to<char>, my_alloc> + my_umap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef map<char, int> my_map; + my_map map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + my_map map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + my_map map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + my_map map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_umap::size_type size01, size02; + + my_alloc alloc01(1); + + my_umap umap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umap01.size(); + my_umap umap02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = umap02.size(); + + umap01.swap(umap02); + VERIFY( umap01.size() == size02 ); + VERIFY( umap01.empty() ); + VERIFY( umap02.size() == size01 ); + VERIFY( umap02.empty() ); + + my_umap umap03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umap03.size(); + my_umap umap04(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap04.size(); + + umap03.swap(umap04); + VERIFY( umap03.size() == size02 ); + VERIFY( my_map(umap03.begin(), umap03.end()) == map02_ref ); + VERIFY( umap04.size() == size01 ); + VERIFY( umap04.empty() ); + + my_umap umap05(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap05.size(); + my_umap umap06(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap06.size(); + + umap05.swap(umap06); + VERIFY( umap05.size() == size02 ); + VERIFY( my_map(umap05.begin(), umap05.end()) == map02_ref ); + VERIFY( umap06.size() == size01 ); + VERIFY( my_map(umap06.begin(), umap06.end()) == map01_ref ); + + my_umap umap07(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap07.size(); + my_umap umap08(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap08.size(); + + umap07.swap(umap08); + VERIFY( umap07.size() == size02 ); + VERIFY( my_map(umap07.begin(), umap07.end()) == map03_ref ); + VERIFY( umap08.size() == size01 ); + VERIFY( my_map(umap08.begin(), umap08.end()) == map01_ref ); + + my_umap umap09(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap09.size(); + my_umap umap10(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap10.size(); + + umap09.swap(umap10); + VERIFY( umap09.size() == size02 ); + VERIFY( my_map(umap09.begin(), umap09.end()) == map04_ref ); + VERIFY( umap10.size() == size01 ); + VERIFY( my_map(umap10.begin(), umap10.end()) == map03_ref ); + + my_umap umap11(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap11.size(); + my_umap umap12(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap12.size(); + + umap11.swap(umap12); + VERIFY( umap11.size() == size02 ); + VERIFY( my_map(umap11.begin(), umap11.end()) == map01_ref ); + VERIFY( umap12.size() == size01 ); + VERIFY( my_map(umap12.begin(), umap12.end()) == map04_ref ); + + my_umap umap13(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap13.size(); + my_umap umap14(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap14.size(); + + umap13.swap(umap14); + VERIFY( umap13.size() == size02 ); + VERIFY( my_map(umap13.begin(), umap13.end()) == map03_ref ); + VERIFY( umap14.size() == size01 ); + VERIFY( my_map(umap14.begin(), umap14.end()) == map03_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc new file mode 100644 index 0000000..8d70829 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc @@ -0,0 +1,191 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.4 unordered_map::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_map<char, int, hash<char>, equal_to<char>, my_alloc> + my_umap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef map<char, int> my_map; + my_map map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + my_map map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + my_map map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + my_map map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_umap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_umap umap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umap01.size(); + personality01 = umap01.get_allocator().get_personality(); + my_umap umap02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = umap02.size(); + personality02 = umap02.get_allocator().get_personality(); + + umap01.swap(umap02); + VERIFY( umap01.size() == size02 ); + VERIFY( umap01.empty() ); + VERIFY( umap02.size() == size01 ); + VERIFY( umap02.empty() ); + VERIFY( umap01.get_allocator().get_personality() == personality02 ); + VERIFY( umap02.get_allocator().get_personality() == personality01 ); + + my_umap umap03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = umap03.size(); + personality01 = umap03.get_allocator().get_personality(); + my_umap umap04(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap04.size(); + personality02 = umap04.get_allocator().get_personality(); + + umap03.swap(umap04); + VERIFY( umap03.size() == size02 ); + VERIFY( my_map(umap03.begin(), umap03.end()) == map02_ref ); + VERIFY( umap04.size() == size01 ); + VERIFY( umap04.empty() ); + VERIFY( umap03.get_allocator().get_personality() == personality02 ); + VERIFY( umap04.get_allocator().get_personality() == personality01 ); + + my_umap umap05(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap05.size(); + personality01 = umap05.get_allocator().get_personality(); + my_umap umap06(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umap06.size(); + personality02 = umap06.get_allocator().get_personality(); + + umap05.swap(umap06); + VERIFY( umap05.size() == size02 ); + VERIFY( my_map(umap05.begin(), umap05.end()) == map02_ref ); + VERIFY( umap06.size() == size01 ); + VERIFY( my_map(umap06.begin(), umap06.end()) == map01_ref ); + VERIFY( umap05.get_allocator().get_personality() == personality02 ); + VERIFY( umap06.get_allocator().get_personality() == personality01 ); + + my_umap umap07(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umap07.size(); + personality01 = umap07.get_allocator().get_personality(); + my_umap umap08(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap08.size(); + personality02 = umap08.get_allocator().get_personality(); + + umap07.swap(umap08); + VERIFY( umap07.size() == size02 ); + VERIFY( my_map(umap07.begin(), umap07.end()) == map03_ref ); + VERIFY( umap08.size() == size01 ); + VERIFY( my_map(umap08.begin(), umap08.end()) == map01_ref ); + VERIFY( umap07.get_allocator().get_personality() == personality02 ); + VERIFY( umap08.get_allocator().get_personality() == personality01 ); + + my_umap umap09(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap09.size(); + personality01 = umap09.get_allocator().get_personality(); + my_umap umap10(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umap10.size(); + personality02 = umap10.get_allocator().get_personality(); + + umap09.swap(umap10); + VERIFY( umap09.size() == size02 ); + VERIFY( my_map(umap09.begin(), umap09.end()) == map04_ref ); + VERIFY( umap10.size() == size01 ); + VERIFY( my_map(umap10.begin(), umap10.end()) == map03_ref ); + VERIFY( umap09.get_allocator().get_personality() == personality02 ); + VERIFY( umap10.get_allocator().get_personality() == personality01 ); + + my_umap umap11(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umap11.size(); + personality01 = umap11.get_allocator().get_personality(); + my_umap umap12(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap12.size(); + personality02 = umap12.get_allocator().get_personality(); + + umap11.swap(umap12); + VERIFY( umap11.size() == size02 ); + VERIFY( my_map(umap11.begin(), umap11.end()) == map01_ref ); + VERIFY( umap12.size() == size01 ); + VERIFY( my_map(umap12.begin(), umap12.end()) == map04_ref ); + VERIFY( umap11.get_allocator().get_personality() == personality02 ); + VERIFY( umap12.get_allocator().get_personality() == personality01 ); + + my_umap umap13(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap13.size(); + personality01 = umap13.get_allocator().get_personality(); + my_umap umap14(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umap14.size(); + personality02 = umap14.get_allocator().get_personality(); + + umap13.swap(umap14); + VERIFY( umap13.size() == size02 ); + VERIFY( my_map(umap13.begin(), umap13.end()) == map03_ref ); + VERIFY( umap14.size() == size01 ); + VERIFY( my_map(umap14.begin(), umap14.end()) == map03_ref ); + VERIFY( umap13.get_allocator().get_personality() == personality02 ); + VERIFY( umap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc new file mode 100644 index 0000000..7648e08 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc @@ -0,0 +1,175 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.6 unordered_multimap::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_multimap<char, int, hash<char>, equal_to<char>, my_alloc> + my_ummap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multimap<char, int> my_mmap; + my_mmap mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + my_mmap mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + my_mmap mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + my_mmap mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + typedef map<char, int> my_map; + + my_ummap::size_type size01, size02; + + my_alloc alloc01(1); + + my_ummap ummap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = ummap01.size(); + my_ummap ummap02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = ummap02.size(); + + ummap01.swap(ummap02); + VERIFY( ummap01.size() == size02 ); + VERIFY( ummap01.empty() ); + VERIFY( ummap02.size() == size01 ); + VERIFY( ummap02.empty() ); + + my_ummap ummap03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = ummap03.size(); + my_ummap ummap04(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap04.size(); + + ummap03.swap(ummap04); + VERIFY( ummap03.size() == size02 ); + VERIFY( my_map(ummap03.begin(), ummap03.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap04.size() == size01 ); + VERIFY( ummap04.empty() ); + + my_ummap ummap05(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap05.size(); + my_ummap ummap06(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap06.size(); + + ummap05.swap(ummap06); + VERIFY( ummap05.size() == size02 ); + VERIFY( my_map(ummap05.begin(), ummap05.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap06.size() == size01 ); + VERIFY( my_map(ummap06.begin(), ummap06.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + + my_ummap ummap07(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap07.size(); + my_ummap ummap08(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap08.size(); + + ummap07.swap(ummap08); + VERIFY( ummap07.size() == size02 ); + VERIFY( my_map(ummap07.begin(), ummap07.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap08.size() == size01 ); + VERIFY( my_map(ummap08.begin(), ummap08.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + + my_ummap ummap09(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap09.size(); + my_ummap ummap10(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap10.size(); + + ummap09.swap(ummap10); + VERIFY( ummap09.size() == size02 ); + VERIFY( my_map(ummap09.begin(), ummap09.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + VERIFY( ummap10.size() == size01 ); + VERIFY( my_map(ummap10.begin(), ummap10.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + + my_ummap ummap11(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap11.size(); + my_ummap ummap12(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap12.size(); + + ummap11.swap(ummap12); + VERIFY( ummap11.size() == size02 ); + VERIFY( my_map(ummap11.begin(), ummap11.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap12.size() == size01 ); + VERIFY( my_map(ummap12.begin(), ummap12.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + + my_ummap ummap13(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap13.size(); + my_ummap ummap14(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap14.size(); + + ummap13.swap(ummap14); + VERIFY( ummap13.size() == size02 ); + VERIFY( my_map(ummap13.begin(), ummap13.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap14.size() == size01 ); + VERIFY( my_map(ummap14.begin(), ummap14.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc new file mode 100644 index 0000000..f7744eb --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc @@ -0,0 +1,204 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.6 unordered_multimap::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_multimap<char, int, hash<char>, equal_to<char>, my_alloc> + my_ummap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multimap<char, int> my_mmap; + my_mmap mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + my_mmap mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + my_mmap mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + my_mmap mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + typedef map<char, int> my_map; + + my_ummap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_ummap ummap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = ummap01.size(); + personality01 = ummap01.get_allocator().get_personality(); + my_ummap ummap02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = ummap02.size(); + personality02 = ummap02.get_allocator().get_personality(); + + ummap01.swap(ummap02); + VERIFY( ummap01.size() == size02 ); + VERIFY( ummap01.empty() ); + VERIFY( ummap02.size() == size01 ); + VERIFY( ummap02.empty() ); + VERIFY( ummap01.get_allocator().get_personality() == personality02 ); + VERIFY( ummap02.get_allocator().get_personality() == personality01 ); + + my_ummap ummap03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = ummap03.size(); + personality01 = ummap03.get_allocator().get_personality(); + my_ummap ummap04(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap04.size(); + personality02 = ummap04.get_allocator().get_personality(); + + ummap03.swap(ummap04); + VERIFY( ummap03.size() == size02 ); + VERIFY( my_map(ummap03.begin(), ummap03.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap04.size() == size01 ); + VERIFY( ummap04.empty() ); + VERIFY( ummap03.get_allocator().get_personality() == personality02 ); + VERIFY( ummap04.get_allocator().get_personality() == personality01 ); + + my_ummap ummap05(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap05.size(); + personality01 = ummap05.get_allocator().get_personality(); + my_ummap ummap06(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = ummap06.size(); + personality02 = ummap06.get_allocator().get_personality(); + + ummap05.swap(ummap06); + VERIFY( ummap05.size() == size02 ); + VERIFY( my_map(ummap05.begin(), ummap05.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap06.size() == size01 ); + VERIFY( my_map(ummap06.begin(), ummap06.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap05.get_allocator().get_personality() == personality02 ); + VERIFY( ummap06.get_allocator().get_personality() == personality01 ); + + my_ummap ummap07(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = ummap07.size(); + personality01 = ummap07.get_allocator().get_personality(); + my_ummap ummap08(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap08.size(); + personality02 = ummap08.get_allocator().get_personality(); + + ummap07.swap(ummap08); + VERIFY( ummap07.size() == size02 ); + VERIFY( my_map(ummap07.begin(), ummap07.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap08.size() == size01 ); + VERIFY( my_map(ummap08.begin(), ummap08.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap07.get_allocator().get_personality() == personality02 ); + VERIFY( ummap08.get_allocator().get_personality() == personality01 ); + + my_ummap ummap09(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap09.size(); + personality01 = ummap09.get_allocator().get_personality(); + my_ummap ummap10(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = ummap10.size(); + personality02 = ummap10.get_allocator().get_personality(); + + ummap09.swap(ummap10); + VERIFY( ummap09.size() == size02 ); + VERIFY( my_map(ummap09.begin(), ummap09.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + VERIFY( ummap10.size() == size01 ); + VERIFY( my_map(ummap10.begin(), ummap10.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap09.get_allocator().get_personality() == personality02 ); + VERIFY( ummap10.get_allocator().get_personality() == personality01 ); + + my_ummap ummap11(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = ummap11.size(); + personality01 = ummap11.get_allocator().get_personality(); + my_ummap ummap12(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap12.size(); + personality02 = ummap12.get_allocator().get_personality(); + + ummap11.swap(ummap12); + VERIFY( ummap11.size() == size02 ); + VERIFY( my_map(ummap11.begin(), ummap11.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap12.size() == size01 ); + VERIFY( my_map(ummap12.begin(), ummap12.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + VERIFY( ummap11.get_allocator().get_personality() == personality02 ); + VERIFY( ummap12.get_allocator().get_personality() == personality01 ); + + my_ummap ummap13(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap13.size(); + personality01 = ummap13.get_allocator().get_personality(); + my_ummap ummap14(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = ummap14.size(); + personality02 = ummap14.get_allocator().get_personality(); + + ummap13.swap(ummap14); + VERIFY( ummap13.size() == size02 ); + VERIFY( my_map(ummap13.begin(), ummap13.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap14.size() == size01 ); + VERIFY( my_map(ummap14.begin(), ummap14.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap13.get_allocator().get_personality() == personality02 ); + VERIFY( ummap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc new file mode 100644 index 0000000..ca0194e --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc @@ -0,0 +1,153 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.5 unordered_multiset::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc> + my_umset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multiset<char> my_mset; + const my_mset mset01_ref(title01, title01 + N1); + const my_mset mset02_ref(title02, title02 + N2); + const my_mset mset03_ref(title03, title03 + N3); + const my_mset mset04_ref(title04, title04 + N4); + + my_umset::size_type size01, size02; + + my_alloc alloc01(1); + + my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umset01.size(); + my_umset umset02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = umset02.size(); + + umset01.swap(umset02); + VERIFY( umset01.size() == size02 ); + VERIFY( umset01.empty() ); + VERIFY( umset02.size() == size01 ); + VERIFY( umset02.empty() ); + + my_umset umset03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umset03.size(); + my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset04.size(); + + umset03.swap(umset04); + VERIFY( umset03.size() == size02 ); + VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref ); + VERIFY( umset04.size() == size01 ); + VERIFY( umset04.empty() ); + + my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset05.size(); + my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset06.size(); + + umset05.swap(umset06); + VERIFY( umset05.size() == size02 ); + VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref ); + VERIFY( umset06.size() == size01 ); + VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref ); + + my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset07.size(); + my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset08.size(); + + umset07.swap(umset08); + VERIFY( umset07.size() == size02 ); + VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref ); + VERIFY( umset08.size() == size01 ); + VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref ); + + my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset09.size(); + my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset10.size(); + + umset09.swap(umset10); + VERIFY( umset09.size() == size02 ); + VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref ); + VERIFY( umset10.size() == size01 ); + VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref ); + + my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset11.size(); + my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset12.size(); + + umset11.swap(umset12); + VERIFY( umset11.size() == size02 ); + VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref ); + VERIFY( umset12.size() == size01 ); + VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref ); + + my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset13.size(); + my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset14.size(); + + umset13.swap(umset14); + VERIFY( umset13.size() == size02 ); + VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref ); + VERIFY( umset14.size() == size01 ); + VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc new file mode 100644 index 0000000..a95ddd5 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc @@ -0,0 +1,182 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.5 unordered_multiset::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc> + my_umset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multiset<char> my_mset; + const my_mset mset01_ref(title01, title01 + N1); + const my_mset mset02_ref(title02, title02 + N2); + const my_mset mset03_ref(title03, title03 + N3); + const my_mset mset04_ref(title04, title04 + N4); + + my_umset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umset01.size(); + personality01 = umset01.get_allocator().get_personality(); + my_umset umset02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = umset02.size(); + personality02 = umset02.get_allocator().get_personality(); + + umset01.swap(umset02); + VERIFY( umset01.size() == size02 ); + VERIFY( umset01.empty() ); + VERIFY( umset02.size() == size01 ); + VERIFY( umset02.empty() ); + VERIFY( umset01.get_allocator().get_personality() == personality02 ); + VERIFY( umset02.get_allocator().get_personality() == personality01 ); + + my_umset umset03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = umset03.size(); + personality01 = umset03.get_allocator().get_personality(); + my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset04.size(); + personality02 = umset04.get_allocator().get_personality(); + + umset03.swap(umset04); + VERIFY( umset03.size() == size02 ); + VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref ); + VERIFY( umset04.size() == size01 ); + VERIFY( umset04.empty() ); + VERIFY( umset03.get_allocator().get_personality() == personality02 ); + VERIFY( umset04.get_allocator().get_personality() == personality01 ); + + my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset05.size(); + personality01 = umset05.get_allocator().get_personality(); + my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umset06.size(); + personality02 = umset06.get_allocator().get_personality(); + + umset05.swap(umset06); + VERIFY( umset05.size() == size02 ); + VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref ); + VERIFY( umset06.size() == size01 ); + VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref ); + VERIFY( umset05.get_allocator().get_personality() == personality02 ); + VERIFY( umset06.get_allocator().get_personality() == personality01 ); + + my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umset07.size(); + personality01 = umset07.get_allocator().get_personality(); + my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset08.size(); + personality02 = umset08.get_allocator().get_personality(); + + umset07.swap(umset08); + VERIFY( umset07.size() == size02 ); + VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref ); + VERIFY( umset08.size() == size01 ); + VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref ); + VERIFY( umset07.get_allocator().get_personality() == personality02 ); + VERIFY( umset08.get_allocator().get_personality() == personality01 ); + + my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset09.size(); + personality01 = umset09.get_allocator().get_personality(); + my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umset10.size(); + personality02 = umset10.get_allocator().get_personality(); + + umset09.swap(umset10); + VERIFY( umset09.size() == size02 ); + VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref ); + VERIFY( umset10.size() == size01 ); + VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref ); + VERIFY( umset09.get_allocator().get_personality() == personality02 ); + VERIFY( umset10.get_allocator().get_personality() == personality01 ); + + my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umset11.size(); + personality01 = umset11.get_allocator().get_personality(); + my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset12.size(); + personality02 = umset12.get_allocator().get_personality(); + + umset11.swap(umset12); + VERIFY( umset11.size() == size02 ); + VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref ); + VERIFY( umset12.size() == size01 ); + VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref ); + VERIFY( umset11.get_allocator().get_personality() == personality02 ); + VERIFY( umset12.get_allocator().get_personality() == personality01 ); + + my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset13.size(); + personality01 = umset13.get_allocator().get_personality(); + my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umset14.size(); + personality02 = umset14.get_allocator().get_personality(); + + umset13.swap(umset14); + VERIFY( umset13.size() == size02 ); + VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref ); + VERIFY( umset14.size() == size01 ); + VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref ); + VERIFY( umset13.get_allocator().get_personality() == personality02 ); + VERIFY( umset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc new file mode 100644 index 0000000..1928c9e --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc @@ -0,0 +1,152 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.3 unordered_set::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef set<char> my_set; + const my_set set01_ref(title01, title01 + N1); + const my_set set02_ref(title02, title02 + N2); + const my_set set03_ref(title03, title03 + N3); + const my_set set04_ref(title04, title04 + N4); + + my_uset::size_type size01, size02; + + my_alloc alloc01(1); + + my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = uset01.size(); + my_uset uset02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = uset02.size(); + + uset01.swap(uset02); + VERIFY( uset01.size() == size02 ); + VERIFY( uset01.empty() ); + VERIFY( uset02.size() == size01 ); + VERIFY( uset02.empty() ); + + my_uset uset03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = uset03.size(); + my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset04.size(); + + uset03.swap(uset04); + VERIFY( uset03.size() == size02 ); + VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref ); + VERIFY( uset04.size() == size01 ); + VERIFY( uset04.empty() ); + + my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset05.size(); + my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset06.size(); + + uset05.swap(uset06); + VERIFY( uset05.size() == size02 ); + VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref ); + VERIFY( uset06.size() == size01 ); + VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref ); + + my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset07.size(); + my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset08.size(); + + uset07.swap(uset08); + VERIFY( uset07.size() == size02 ); + VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref ); + VERIFY( uset08.size() == size01 ); + VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref ); + + my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset09.size(); + my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset10.size(); + + uset09.swap(uset10); + VERIFY( uset09.size() == size02 ); + VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref ); + VERIFY( uset10.size() == size01 ); + VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref ); + + my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset11.size(); + my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset12.size(); + + uset11.swap(uset12); + VERIFY( uset11.size() == size02 ); + VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref ); + VERIFY( uset12.size() == size01 ); + VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref ); + + my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset13.size(); + my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset14.size(); + + uset13.swap(uset14); + VERIFY( uset13.size() == size02 ); + VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref ); + VERIFY( uset14.size() == size01 ); + VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc new file mode 100644 index 0000000..46e859c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc @@ -0,0 +1,181 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.3 unordered_set::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef set<char> my_set; + const my_set set01_ref(title01, title01 + N1); + const my_set set02_ref(title02, title02 + N2); + const my_set set03_ref(title03, title03 + N3); + const my_set set04_ref(title04, title04 + N4); + + my_uset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = uset01.size(); + personality01 = uset01.get_allocator().get_personality(); + my_uset uset02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = uset02.size(); + personality02 = uset02.get_allocator().get_personality(); + + uset01.swap(uset02); + VERIFY( uset01.size() == size02 ); + VERIFY( uset01.empty() ); + VERIFY( uset02.size() == size01 ); + VERIFY( uset02.empty() ); + VERIFY( uset01.get_allocator().get_personality() == personality02 ); + VERIFY( uset02.get_allocator().get_personality() == personality01 ); + + my_uset uset03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = uset03.size(); + personality01 = uset03.get_allocator().get_personality(); + my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset04.size(); + personality02 = uset04.get_allocator().get_personality(); + + uset03.swap(uset04); + VERIFY( uset03.size() == size02 ); + VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref ); + VERIFY( uset04.size() == size01 ); + VERIFY( uset04.empty() ); + VERIFY( uset03.get_allocator().get_personality() == personality02 ); + VERIFY( uset04.get_allocator().get_personality() == personality01 ); + + my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset05.size(); + personality01 = uset05.get_allocator().get_personality(); + my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = uset06.size(); + personality02 = uset06.get_allocator().get_personality(); + + uset05.swap(uset06); + VERIFY( uset05.size() == size02 ); + VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref ); + VERIFY( uset06.size() == size01 ); + VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref ); + VERIFY( uset05.get_allocator().get_personality() == personality02 ); + VERIFY( uset06.get_allocator().get_personality() == personality01 ); + + my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = uset07.size(); + personality01 = uset07.get_allocator().get_personality(); + my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset08.size(); + personality02 = uset08.get_allocator().get_personality(); + + uset07.swap(uset08); + VERIFY( uset07.size() == size02 ); + VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref ); + VERIFY( uset08.size() == size01 ); + VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref ); + VERIFY( uset07.get_allocator().get_personality() == personality02 ); + VERIFY( uset08.get_allocator().get_personality() == personality01 ); + + my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset09.size(); + personality01 = uset09.get_allocator().get_personality(); + my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = uset10.size(); + personality02 = uset10.get_allocator().get_personality(); + + uset09.swap(uset10); + VERIFY( uset09.size() == size02 ); + VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref ); + VERIFY( uset10.size() == size01 ); + VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref ); + VERIFY( uset09.get_allocator().get_personality() == personality02 ); + VERIFY( uset10.get_allocator().get_personality() == personality01 ); + + my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = uset11.size(); + personality01 = uset11.get_allocator().get_personality(); + my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset12.size(); + personality02 = uset12.get_allocator().get_personality(); + + uset11.swap(uset12); + VERIFY( uset11.size() == size02 ); + VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref ); + VERIFY( uset12.size() == size01 ); + VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref ); + VERIFY( uset11.get_allocator().get_personality() == personality02 ); + VERIFY( uset12.get_allocator().get_personality() == personality01 ); + + my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset13.size(); + personality01 = uset13.get_allocator().get_personality(); + my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = uset14.size(); + personality02 = uset14.get_allocator().get_personality(); + + uset13.swap(uset14); + VERIFY( uset13.size() == size02 ); + VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref ); + VERIFY( uset14.size() == size01 ); + VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref ); + VERIFY( uset13.get_allocator().get_personality() == personality02 ); + VERIFY( uset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} |