d78301422a
2010-09-03 François Dumont <francois.cppdevs@free.fr> * testsuite/lib/libstdc++.exp ([check_v3_target_debug_mode]): Fix so that it really detects when debug mode is activated. * testsuite/util/debug/construct_neg.h, insert_neg.h, assign_neg.h: Remove, content moved... * testsuite/util/debug/checks.h: ... here. Modify checks to take the type of the container to test rather than an intermediate container type traits helper. * testsuite/23_containers/unordered_map/debug/insert1_neg.cc: Update to use dg-require-debug-mode when necessary and use new check functions. * testsuite/23_containers/unordered_map/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/multimap/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/set/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/set/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/set/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/set/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/set/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/set/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/set/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/set/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/vector/debug/assign1_neg.cc: Likewise. * testsuite/23_containers/vector/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/vector/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/vector/debug/assign2_neg.cc: Likewise. * testsuite/23_containers/vector/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/vector/debug/assign3_neg.cc: Likewise. * testsuite/23_containers/vector/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/vector/debug/assign4_neg.cc: Likewise. * testsuite/23_containers/vector/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/vector/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/vector/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/vector/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/unordered_set/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/deque/debug/assign1_neg.cc: Likewise. * testsuite/23_containers/deque/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/deque/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/deque/debug/assign2_neg.cc: Likewise. * testsuite/23_containers/deque/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/deque/debug/assign3_neg.cc: Likewise. * testsuite/23_containers/deque/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/deque/debug/assign4_neg.cc: Likewise. * testsuite/23_containers/deque/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/deque/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/deque/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/deque/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/multiset/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/list/debug/assign1_neg.cc: Likewise. * testsuite/23_containers/list/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/list/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/list/debug/assign2_neg.cc: Likewise. * testsuite/23_containers/list/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/list/debug/assign3_neg.cc: Likewise. * testsuite/23_containers/list/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/list/debug/assign4_neg.cc: Likewise. * testsuite/23_containers/list/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/list/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/list/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/list/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/unordered_multiset/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/map/debug/insert1_neg.cc: Likewise. * testsuite/23_containers/map/debug/construct1_neg.cc: Likewise. * testsuite/23_containers/map/debug/construct2_neg.cc: Likewise. * testsuite/23_containers/map/debug/insert2_neg.cc: Likewise. * testsuite/23_containers/map/debug/construct3_neg.cc: Likewise. * testsuite/23_containers/map/debug/insert3_neg.cc: Likewise. * testsuite/23_containers/map/debug/construct4_neg.cc: Likewise. * testsuite/23_containers/map/debug/insert4_neg.cc: Likewise. * testsuite/23_containers/unordered_map/debug/cont_traits.h: Remove. * testsuite/23_containers/unordered_map/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/multimap/debug/cont_traits.h: Likewise. * testsuite/23_containers/multimap/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/set/debug/cont_traits.h: Likewise. * testsuite/23_containers/set/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/unordered_multimap/debug/cont_traits.h: Likewise. * testsuite/23_containers/unordered_multimap/debug/ debug_cont_traits.h: Likewise. * testsuite/23_containers/vector/debug/cont_traits.h: Likewise. * testsuite/23_containers/vector/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/unordered_set/debug/cont_traits.h: Likewise. * testsuite/23_containers/unordered_set/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/deque/debug/cont_traits.h: Likewise. * testsuite/23_containers/deque/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/multiset/debug/cont_traits.h: Likewise. * testsuite/23_containers/multiset/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/list/debug/cont_traits.h: Likewise. * testsuite/23_containers/list/debug/debug_cont_traits.h: Likewise. * testsuite/23_containers/unordered_multiset/debug/cont_traits.h: Likewise. * testsuite/23_containers/unordered_multiset/debug/ debug_cont_traits.h: Likewise. * testsuite/23_containers/map/debug/cont_traits.h: Likewise. * testsuite/23_containers/map/debug/debug_cont_traits.h: Likewise. * testsuite/21_strings/basic_string/element_access/char: Tidy. * testsuite/21_strings/basic_string/element_access/wchar_t: Likewise. From-SVN: r163837
380 lines
10 KiB
C++
380 lines
10 KiB
C++
// Copyright (C) 2010 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING3. If not see
|
|
// <http://www.gnu.org/licenses/>.
|
|
//
|
|
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <list>
|
|
#ifndef _GLIBCXX_DEBUG
|
|
# include <debug/vector>
|
|
# include <debug/deque>
|
|
# include <debug/list>
|
|
#endif
|
|
#include <testsuite_hooks.h>
|
|
|
|
namespace __gnu_test
|
|
{
|
|
template<typename _Tp>
|
|
struct CopyableValueType
|
|
{
|
|
typedef _Tp value_type;
|
|
};
|
|
|
|
template<typename _Tp1, typename _Tp2>
|
|
struct CopyableValueType<std::pair<const _Tp1, _Tp2> >
|
|
{
|
|
typedef std::pair<_Tp1, _Tp2> value_type;
|
|
};
|
|
|
|
template<typename _Tp>
|
|
struct generate_unique
|
|
{
|
|
typedef _Tp value_type;
|
|
|
|
operator value_type()
|
|
{
|
|
static value_type _S_;
|
|
++_S_;
|
|
return _S_;
|
|
}
|
|
};
|
|
|
|
template<typename _Tp1, typename _Tp2>
|
|
struct generate_unique<std::pair<_Tp1, _Tp2> >
|
|
{
|
|
typedef _Tp1 first_type;
|
|
typedef _Tp2 second_type;
|
|
typedef std::pair<_Tp1, _Tp2> pair_type;
|
|
|
|
operator pair_type()
|
|
{
|
|
static first_type _S_1;
|
|
static second_type _S_2;
|
|
++_S_1;
|
|
++_S_2;
|
|
return pair_type(_S_1, _S_2);
|
|
}
|
|
};
|
|
|
|
// Check that invalid range of pointers is detected
|
|
template<typename _Tp>
|
|
void
|
|
check_assign1()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::vector<val_type> vector_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
vector_type v;
|
|
for (int i = 0; i != 5; ++i)
|
|
v.push_back(gu);
|
|
VERIFY(v.size() == 5);
|
|
|
|
const val_type* first = &v.front() + 1;
|
|
const val_type* last = first + 2;
|
|
|
|
cont_type c1;
|
|
c1.assign(first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2;
|
|
c2.assign(last, first); // Expected failure
|
|
}
|
|
|
|
// Check that invalid range of debug random iterators is detected
|
|
template<typename _Tp>
|
|
void
|
|
check_assign2()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::vector<val_type> vector_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
vector_type v;
|
|
for (int i = 0; i != 5; ++i)
|
|
v.push_back(gu);
|
|
VERIFY(v.size() == 5);
|
|
|
|
typename vector_type::iterator first = v.begin() + 1;
|
|
typename vector_type::iterator last = first + 2;
|
|
cont_type c1;
|
|
c1.assign(first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2;
|
|
c2.assign(last, first); // Expected failure
|
|
}
|
|
|
|
// Check that invalid range of debug !random debug iterators is detected
|
|
template<typename _Tp>
|
|
void
|
|
check_assign3()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::list<val_type> list_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
list_type l;
|
|
for (int i = 0; i != 5; ++i)
|
|
l.push_back(gu);
|
|
VERIFY(l.size() == 5);
|
|
|
|
typename list_type::iterator first = l.begin(); ++first;
|
|
typename list_type::iterator last = first; ++last; ++last;
|
|
cont_type c1;
|
|
c1.assign(first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2;
|
|
c2.assign(last, first); // Expected failure
|
|
}
|
|
|
|
// Check that invalid range of pointers is detected
|
|
template<typename _Tp>
|
|
void
|
|
check_construct1()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::vector<val_type> vector_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
vector_type v;
|
|
for (int i = 0; i != 5; ++i)
|
|
v.push_back(gu);
|
|
VERIFY(v.size() == 5);
|
|
|
|
val_type *first = &v.front() + 1;
|
|
val_type *last = first + 2;
|
|
cont_type c1(first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2(last, first); // Expected failure
|
|
}
|
|
|
|
// Check that invalid range of debug random iterators is detected
|
|
template<typename _Tp>
|
|
void
|
|
check_construct2()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::vector<val_type> vector_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
vector_type v;
|
|
for (int i = 0; i != 5; ++i)
|
|
v.push_back(gu);
|
|
VERIFY(v.size() == 5);
|
|
|
|
typename vector_type::iterator first = v.begin() + 1;
|
|
typename vector_type::iterator last = first + 2;
|
|
cont_type c1(first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2(last, first); // Expected failure
|
|
}
|
|
|
|
// Check that invalid range of debug not random iterators is detected
|
|
template<typename _Tp>
|
|
void
|
|
check_construct3()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::list<val_type> list_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
list_type l;
|
|
for (int i = 0; i != 5; ++i)
|
|
l.push_back(gu);
|
|
VERIFY(l.size() == 5);
|
|
|
|
typename list_type::iterator first = l.begin(); ++first;
|
|
typename list_type::iterator last = first; ++last; ++last;
|
|
cont_type c1(first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2(last, first); // Expected failure
|
|
}
|
|
|
|
template <typename _Cont>
|
|
struct InsertRangeHelper
|
|
{
|
|
template <typename _It>
|
|
static void
|
|
Insert(_Cont& cont, _It first, _It last)
|
|
{ cont.insert(first, last); }
|
|
};
|
|
|
|
template <typename _Cont>
|
|
struct InsertRangeHelperAux
|
|
{
|
|
template <typename _It>
|
|
static void
|
|
Insert(_Cont& cont, _It first, _It last)
|
|
{ cont.insert(cont.begin(), first, last); }
|
|
};
|
|
|
|
template <typename _Tp1, typename _Tp2>
|
|
struct InsertRangeHelper<std::vector<_Tp1, _Tp2> >
|
|
: InsertRangeHelperAux<std::vector<_Tp1, _Tp2> >
|
|
{ };
|
|
|
|
template <typename _Tp1, typename _Tp2>
|
|
struct InsertRangeHelper<std::deque<_Tp1, _Tp2> >
|
|
: InsertRangeHelperAux<std::deque<_Tp1, _Tp2> >
|
|
{ };
|
|
|
|
template <typename _Tp1, typename _Tp2>
|
|
struct InsertRangeHelper<std::list<_Tp1, _Tp2> >
|
|
: InsertRangeHelperAux<std::list<_Tp1, _Tp2> >
|
|
{ };
|
|
|
|
#ifndef _GLIBCXX_DEBUG
|
|
template <typename _Tp1, typename _Tp2>
|
|
struct InsertRangeHelper<__gnu_debug::vector<_Tp1, _Tp2> >
|
|
: InsertRangeHelperAux<__gnu_debug::vector<_Tp1, _Tp2> >
|
|
{ };
|
|
|
|
template <typename _Tp1, typename _Tp2>
|
|
struct InsertRangeHelper<__gnu_debug::deque<_Tp1, _Tp2> >
|
|
: InsertRangeHelperAux<__gnu_debug::deque<_Tp1, _Tp2> >
|
|
{ };
|
|
|
|
template <typename _Tp1, typename _Tp2>
|
|
struct InsertRangeHelper<__gnu_debug::list<_Tp1, _Tp2> >
|
|
: InsertRangeHelperAux<__gnu_debug::list<_Tp1, _Tp2> >
|
|
{ };
|
|
#endif
|
|
|
|
template<typename _Tp>
|
|
void
|
|
check_insert1()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::vector<val_type> vector_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
vector_type v;
|
|
for (int i = 0; i != 5; ++i)
|
|
v.push_back(gu);
|
|
VERIFY(v.size() == 5);
|
|
|
|
const val_type* first = &v.front() + 1;
|
|
const val_type* last = first + 2;
|
|
|
|
cont_type c1;
|
|
InsertRangeHelper<cont_type>::Insert(c1, first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2;
|
|
InsertRangeHelper<cont_type>::Insert(c2, last, first); // Expected failure
|
|
}
|
|
|
|
template<typename _Tp>
|
|
void
|
|
check_insert2()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::vector<val_type> vector_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
vector_type v;
|
|
for (int i = 0; i != 5; ++i)
|
|
v.push_back(gu);
|
|
VERIFY(v.size() == 5);
|
|
|
|
typename vector_type::iterator first = v.begin() + 1;
|
|
typename vector_type::iterator last = first + 2;
|
|
|
|
cont_type c1;
|
|
InsertRangeHelper<cont_type>::Insert(c1, first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2;
|
|
InsertRangeHelper<cont_type>::Insert(c2, last, first); // Expected failure
|
|
}
|
|
|
|
template<typename _Tp>
|
|
void
|
|
check_insert3()
|
|
{
|
|
bool test __attribute__((unused)) = true;
|
|
|
|
typedef _Tp cont_type;
|
|
typedef typename cont_type::value_type cont_val_type;
|
|
typedef typename CopyableValueType<cont_val_type>::value_type val_type;
|
|
typedef std::list<val_type> list_type;
|
|
|
|
generate_unique<val_type> gu;
|
|
|
|
list_type l;
|
|
for (int i = 0; i != 5; ++i)
|
|
l.push_back(gu);
|
|
VERIFY(l.size() == 5);
|
|
|
|
typename list_type::iterator first = l.begin(); ++first;
|
|
typename list_type::iterator last = first; ++last; ++last;
|
|
|
|
cont_type c1;
|
|
InsertRangeHelper<cont_type>::Insert(c1, first, last);
|
|
VERIFY(c1.size() == 2);
|
|
|
|
cont_type c2;
|
|
InsertRangeHelper<cont_type>::Insert(c2, last, first); // Expected failure
|
|
}
|
|
}
|
|
|