diff options
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers')
22 files changed, 1311 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/bitset/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/invalidation/1.cc new file mode 100644 index 00000000000..7ca3053cff1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/invalidation/1.cc @@ -0,0 +1,46 @@ +// Bitset reference invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/bitset> +#include <testsuite_hooks.h> + +using __gnu_debug::bitset; + +bool test = true; + +// Disappear +void test01() +{ + bitset<32>::reference* i; + { + bitset<32> bs; + bs.flip(7); + i = new bitset<32>::reference(bs[7]); + VERIFY(*i); + } + VERIFY(i->_M_singular()); + delete i; +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/deque/invalidation/1.cc new file mode 100644 index 00000000000..4529b288ef4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/invalidation/1.cc @@ -0,0 +1,53 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Assignment +void test01() +{ + deque<int> v1; + deque<int> v2; + + deque<int>::iterator i = v1.end(); + VERIFY(!i._M_dereferenceable() && !i._M_singular()); + + v1 = v2; + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(v2.begin(), v2.end()); + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(17, 42); + VERIFY(i._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/deque/invalidation/2.cc new file mode 100644 index 00000000000..106c118accc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/invalidation/2.cc @@ -0,0 +1,53 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Resize +void test02() +{ + deque<int> v(10, 17); + + deque<int>::iterator before = v.begin() + 6; + deque<int>::iterator at = before + 1; + deque<int>::iterator after = at + 1; + + // Shrink + v.resize(7); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_singular()); + + // Grow + before = v.begin() + 6; + v.resize(17); + VERIFY(before._M_singular()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/invalidation/3.cc b/libstdc++-v3/testsuite/23_containers/deque/invalidation/3.cc new file mode 100644 index 00000000000..60103c1fd7e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/invalidation/3.cc @@ -0,0 +1,62 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Insert +void test03() +{ + deque<int> v(10, 17); + + // Insert a single element + deque<int>::iterator before = v.begin() + 6; + deque<int>::iterator at = before + 1; + deque<int>::iterator after = at; + at = v.insert(at, 42); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Insert multiple copies + before = v.begin() + 6; + at = before + 1; + v.insert(at, 3, 42); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); + + // Insert iterator range + static int data[] = { 2, 3, 5, 7 }; + before = v.begin() + 6; + at = before + 1; + v.insert(at, &data[0], &data[0] + 4); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); +} + +int main() +{ + test03(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/deque/invalidation/4.cc new file mode 100644 index 00000000000..1918737cf93 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/invalidation/4.cc @@ -0,0 +1,69 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Erase +void test04() +{ + deque<int> v(20, 42); + + // Single element erase (middle) + deque<int>::iterator before = v.begin(); + deque<int>::iterator at = before + 3; + deque<int>::iterator after = at; + at = v.erase(at); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Single element erase (end) + before = v.begin(); + at = before; + after = at + 1; + at = v.erase(at); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before + 3; + v.erase(at, at + 3); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); +} + +int main() +{ + test04(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/list/invalidation/1.cc new file mode 100644 index 00000000000..86d9031a9c3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/invalidation/1.cc @@ -0,0 +1,60 @@ +// List iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::list; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + list<int> v1; + list<int> v2; + + v1.push_front(17); + + list<int>::iterator start = v1.begin(); + list<int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + finish = v1.end(); + v1.assign(v2.begin(), v2.end()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + finish = v1.end(); + v1.assign(17, 42); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/list/invalidation/2.cc new file mode 100644 index 00000000000..117aa61abea --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/invalidation/2.cc @@ -0,0 +1,55 @@ +// List iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::list; +using std::advance; + +bool test = true; + +// Resize +void test02() +{ + list<int> v(10, 17); + + list<int>::iterator before = v.begin(); + advance(before, 6); + list<int>::iterator at = before; + advance(at, 1); + list<int>::iterator after = at; + advance(after, 1); + list<int>::iterator finish = v.end(); + + // Shrink + v.resize(7); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/invalidation/3.cc b/libstdc++-v3/testsuite/23_containers/list/invalidation/3.cc new file mode 100644 index 00000000000..59af360ed84 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/invalidation/3.cc @@ -0,0 +1,78 @@ +// List iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::list; +using std::advance; + +bool test = true; + +// Erase +void test03() +{ + list<int> v(20, 42); + + // Single element erase (middle) + list<int>::iterator before = v.begin(); + list<int>::iterator at = before; + advance(at, 3); + list<int>::iterator after = at; + at = v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Single element erase (end) + before = v.begin(); + at = before; + after = at; + ++after; + at = v.erase(at); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 3); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + list<int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test03(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/list/invalidation/4.cc new file mode 100644 index 00000000000..90f99709f16 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/invalidation/4.cc @@ -0,0 +1,55 @@ +// List iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::list; +using std::advance; + +bool test = true; + +// Splice +void test04() +{ + list<int> l1(10, 17); + list<int> l2(10, 42); + + list<int>::iterator start2 = l2.begin(); + list<int>::iterator end2 = start2; + advance(end2, 5); + list<int>::iterator after2 = end2; + advance(after2, 2); + + l1.splice(l1.begin(), l2, start2, end2); + VERIFY(start2._M_dereferenceable()); + VERIFY(end2._M_dereferenceable()); + VERIFY(after2._M_dereferenceable()); + VERIFY(start2._M_attached_to(&l1)); + VERIFY(end2._M_attached_to(&l2)); + VERIFY(after2._M_attached_to(&l2)); +} + +int main() +{ + test04(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operators/4.cc b/libstdc++-v3/testsuite/23_containers/list/operators/4.cc index 5de95b9eb5e..bbebfb59a23 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operators/4.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operators/4.cc @@ -76,14 +76,18 @@ test04() CompLastLt::reset(); list0401.merge(list0402, lt); VERIFY(list0401 == list0404); +#ifndef _GLIBCXX_DEBUG VERIFY(lt.count() <= (N + M - 1)); +#endif CompLastEq eq; CompLastEq::reset(); list0401.unique(eq); VERIFY(list0401 == list0405); +#ifndef _GLIBCXX_DEBUG VERIFY(eq.count() == (N + M - 1)); +#endif } int main() diff --git a/libstdc++-v3/testsuite/23_containers/map/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/map/invalidation/1.cc new file mode 100644 index 00000000000..a62a98d863f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/invalidation/1.cc @@ -0,0 +1,52 @@ +// Map iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/map> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::map; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + map<int, int> v1; + map<int, int> v2; + + v1[17] = 42; + + map<int, int>::iterator start = v1.begin(); + map<int, int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/map/invalidation/2.cc new file mode 100644 index 00000000000..0086deb81fa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/invalidation/2.cc @@ -0,0 +1,71 @@ +// Map iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/map> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::map; +using std::advance; + +bool test = true; + +// Erase +void test02() +{ + map<int, int> v; + for (int i = 0; i < 20; ++i) + v[i] = 20-i; + + // Single element erase (middle) + map<int, int>::iterator before = v.begin(); + map<int, int>::iterator at = before; + advance(at, 3); + map<int, int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + map<int, int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/invalidation/1.cc new file mode 100644 index 00000000000..71b5385aed3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/invalidation/1.cc @@ -0,0 +1,53 @@ +// Multimap iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/map> +#include <iterator> +#include <testsuite_hooks.h> +#include <utility> + +using __gnu_debug::multimap; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + multimap<int, int> v1; + multimap<int, int> v2; + + v1.insert(std::make_pair(17, 42)); + + multimap<int, int>::iterator start = v1.begin(); + multimap<int, int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/invalidation/2.cc new file mode 100644 index 00000000000..c6f659e7f5c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/invalidation/2.cc @@ -0,0 +1,72 @@ +// Multimap iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/map> +#include <iterator> +#include <testsuite_hooks.h> +#include <utility> + +using __gnu_debug::multimap; +using std::advance; + +bool test = true; + +// Erase +void test02() +{ + multimap<int, int> v; + for (int i = 0; i < 20; ++i) + v.insert(std::make_pair(i, 20-i)); + + // Single element erase (middle) + multimap<int, int>::iterator before = v.begin(); + multimap<int, int>::iterator at = before; + advance(at, 3); + multimap<int, int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + multimap<int, int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/invalidation/1.cc new file mode 100644 index 00000000000..0d9b76f2f4c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/invalidation/1.cc @@ -0,0 +1,52 @@ +// Multiset iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::multiset; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + multiset<int> v1; + multiset<int> v2; + + v1.insert(17); + + multiset<int>::iterator start = v1.begin(); + multiset<int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/invalidation/2.cc new file mode 100644 index 00000000000..fbca3c476fe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/invalidation/2.cc @@ -0,0 +1,71 @@ +// Multiset iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::multiset; +using std::advance; + +bool test = true; + +// Erase +void test02() +{ + multiset<int> v; + for (int i = 0; i < 20; ++i) + v.insert(i); + + // Single element erase (middle) + multiset<int>::iterator before = v.begin(); + multiset<int>::iterator at = before; + advance(at, 3); + multiset<int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + multiset<int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/set/invalidation/1.cc new file mode 100644 index 00000000000..5a58f6fad71 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/invalidation/1.cc @@ -0,0 +1,52 @@ +// Set iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::set; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + set<int> v1; + set<int> v2; + + v1.insert(17); + + set<int>::iterator start = v1.begin(); + set<int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/set/invalidation/2.cc new file mode 100644 index 00000000000..25277d843b9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/invalidation/2.cc @@ -0,0 +1,71 @@ +// Set iterator invalidation tests + +// Copyright (C) 2003 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. + +#include <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::set; +using std::advance; + +bool test = true; + +// Erase +void test02() +{ + set<int> v; + for (int i = 0; i < 20; ++i) + v.insert(i); + + // Single element erase (middle) + set<int>::iterator before = v.begin(); + set<int>::iterator at = before; + advance(at, 3); + set<int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + set<int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/vector/invalidation/1.cc new file mode 100644 index 00000000000..ccbcb159046 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/invalidation/1.cc @@ -0,0 +1,60 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003 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. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Assignment +void test01() +{ + vector<int> v1; + vector<int> v2; + + vector<int>::iterator i = v1.end(); + VERIFY(!i._M_dereferenceable() && !i._M_singular()); + + v1 = v2; + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(v2.begin(), v2.end()); + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(17, 42); + VERIFY(i._M_singular()); +} + +int main() +{ + test01(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/vector/invalidation/2.cc new file mode 100644 index 00000000000..1f596391832 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/invalidation/2.cc @@ -0,0 +1,65 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003 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. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Resize +void test02() +{ + vector<int> v(10, 17); + v.reserve(20); + + vector<int>::iterator before = v.begin() + 6; + vector<int>::iterator at = before + 1; + vector<int>::iterator after = at + 1; + + // Shrink + v.resize(7); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_singular()); + + // Grow, without reallocation + before = v.begin() + 6; + v.resize(17); + VERIFY(before._M_dereferenceable()); + + // Grow, with reallocation + v.resize(42); + VERIFY(before._M_singular()); +} + +int main() +{ + test02(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/invalidation/3.cc b/libstdc++-v3/testsuite/23_containers/vector/invalidation/3.cc new file mode 100644 index 00000000000..656dd61f715 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/invalidation/3.cc @@ -0,0 +1,90 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003 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. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Insert +void test03() +{ + vector<int> v(10, 17); + v.reserve(30); + + // Insert a single element + vector<int>::iterator before = v.begin() + 6; + vector<int>::iterator at = before + 1; + vector<int>::iterator after = at; + at = v.insert(at, 42); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Insert multiple copies + before = v.begin() + 6; + at = before + 1; + v.insert(at, 3, 42); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // Insert iterator range + static int data[] = { 2, 3, 5, 7 }; + before = v.begin() + 6; + at = before + 1; + v.insert(at, &data[0], &data[0] + 4); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // Insert with reallocation + before = v.begin() + 6; + at = before + 1; + v.insert(at, 30, 17); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); + + // Single insert with reallocation + vector<int> v2; + v2.reserve(100); + at = v2.begin(); + v2.insert(at, 100, 17); + at = v2.end() - 1; + before = v2.begin(); + VERIFY(at._M_dereferenceable()); + VERIFY(before._M_dereferenceable()); + at = v2.insert(at, 42); + VERIFY(at._M_dereferenceable()); + VERIFY(before._M_singular()); +} + +int main() +{ + test03(); + return !test; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/vector/invalidation/4.cc new file mode 100644 index 00000000000..1492d9c0cec --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/invalidation/4.cc @@ -0,0 +1,67 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003 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. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Erase +void test04() +{ + vector<int> v(20, 42); + + // Single element erase + vector<int>::iterator before = v.begin(); + vector<int>::iterator at = before + 3; + vector<int>::iterator after = at; + at = v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Multiple element erase + before = v.begin(); + at = before + 3; + v.erase(at, at + 3); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); +} + +int main() +{ + test04(); + return !test; +} |