Update the unordered tests. Several changes including extra erase tests. The newer version of the containers have a hairy erase implementation, so need to test all the special cases. Also, a few extra tests here and there, avoid a couple of warnings and remove some old TODOs.

[SVN r3341]
This commit is contained in:
Daniel James
2006-10-31 22:19:26 +00:00
parent 136e2fe3ba
commit ec310f7b80
20 changed files with 316 additions and 134 deletions
+17 -21
View File
@@ -17,12 +17,6 @@
#include <cstdlib>
#include "../helpers/fwd.hpp"
// TODO:
// a) This can only be included in compile unit.
// b) This stuff should be somewhere else.
// but I'm feeling too lazy right now (although sadly not lazy enough to
// avoid reinventing yet another wheel).
#define RUN_EXCEPTION_TESTS(test_seq, param_seq) \
BOOST_PP_SEQ_FOR_EACH_PRODUCT(RUN_EXCEPTION_TESTS_OP, (test_seq)(param_seq))
@@ -213,6 +207,11 @@ namespace exception
}
}
~object() {
tag1_ = -1;
tag2_ = -1;
}
object& operator=(object const& x)
{
SCOPE(object::operator=(object)) {
@@ -346,7 +345,7 @@ namespace exception
return *this;
}
std::size_t operator()(object const& x1, object const& x2) const {
bool operator()(object const& x1, object const& x2) const {
SCOPE(equal_to::operator()(object, object)) {
EPOINT("Mock equal_to function.");
}
@@ -376,10 +375,6 @@ namespace exception
}
};
// TODO: Need to track that same allocator is used to allocate, construct,
// deconstruct and destroy objects. Also, need to check that constructed
// objects are deconstructed (Boost.Test should take care of memory leaks
// for us).
template <class T>
class allocator
{
@@ -394,14 +389,14 @@ namespace exception
template <class U> struct rebind { typedef allocator<U> other; };
explicit allocator(int t = 0)
explicit allocator(int = 0)
{
SCOPE(allocator::allocator()) {
EPOINT("Mock allocator default constructor.");
}
}
template <class Y> allocator(allocator<Y> const& x)
template <class Y> allocator(allocator<Y> const&)
{
SCOPE(allocator::allocator()) {
EPOINT("Mock allocator template copy constructor.");
@@ -424,8 +419,11 @@ namespace exception
return *this;
}
// If address throws, then it can't be used in erase or the
// destructor, which is very limiting. I need to check up on
// this.
pointer address(reference r) {
// TODO: Is this no throw? Major problems if it isn't.
//SCOPE(allocator::address(reference)) {
// EPOINT("Mock allocator address function.");
//}
@@ -433,7 +431,6 @@ namespace exception
}
const_pointer address(const_reference r) {
// TODO: Is this no throw? Major problems if it isn't.
//SCOPE(allocator::address(const_reference)) {
// EPOINT("Mock allocator const address function.");
//}
@@ -469,7 +466,7 @@ namespace exception
//return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type n)
void deallocate(pointer p, size_type)
{
//::operator delete((void*) p);
if(p) {
@@ -495,13 +492,12 @@ namespace exception
}
};
// It's pretty much impossible to write a compliant swap when these
// two can throw. So they don't.
template <class T>
inline bool operator==(allocator<T> const& x, allocator<T> const& y)
inline bool operator==(allocator<T> const&, allocator<T> const&)
{
// TODO: I can't meet the exception requirements for swap if this
// throws. Does the standard specify that allocator comparisons can't
// throw?
//
//SCOPE(operator==(allocator, allocator)) {
// EPOINT("Mock allocator equality operator.");
//}
+5 -22
View File
@@ -47,19 +47,12 @@ namespace minimal
{
public:
static hash create() { return hash(); }
// TODO: hash has to be default constructible for the default
// parameters. Maybe use an alternative version for testing
// other member functions.
//
// Or maybe it's required to be default constructible?
// The Container requirements include a default constructor.
hash() {}
hash(hash const&) {}
// TODO: Required to be assignable?
hash& operator=(hash const&) { return *this; }
~hash() {}
std::size_t operator()(T const& x) const { return 0; }
std::size_t operator()(T const&) const { return 0; }
};
template <class T>
@@ -67,15 +60,8 @@ namespace minimal
{
public:
static equal_to create() { return equal_to(); }
// TODO: equal_to has to be default constructible for the default
// parameters. Maybe use an alternative version for testing
// other member functions.
//
// Or maybe it's required to be default constructible?
// The Container requirements include a default constructor.
equal_to() {}
equal_to(equal_to const&) {}
// TODO: Required to be assignable?
equal_to& operator=(equal_to const&) { return *this; }
~equal_to() {}
@@ -173,9 +159,6 @@ namespace minimal
bool operator>=(const_pointer const& x) const { return ptr_ >= x.ptr_; }
};
// TODO: Issue 560 suggests that an allocator doesn't have to have
// a default constructor.
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#560
template <class T>
class allocator
{
@@ -207,7 +190,7 @@ namespace minimal
return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type n)
void deallocate(pointer p, size_type)
{
::operator delete((void*) p.ptr_);
}
@@ -225,19 +208,19 @@ namespace minimal
};
template <class T>
inline bool operator==(allocator<T> const& x, allocator<T> const& y)
inline bool operator==(allocator<T> const&, allocator<T> const&)
{
return true;
}
template <class T>
inline bool operator!=(allocator<T> const& x, allocator<T> const& y)
inline bool operator!=(allocator<T> const&, allocator<T> const&)
{
return false;
}
template <class T>
void swap(allocator<T>& x, allocator<T>& y)
void swap(allocator<T>&, allocator<T>&)
{
}
}
+8 -8
View File
@@ -32,6 +32,11 @@ namespace test
public:
explicit object(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {}
~object() {
tag1_ = -1;
tag2_ = -1;
}
friend bool operator==(object const& x1, object const& x2) {
return x1.tag1_ == x2.tag1_ && x1.tag2_ == x2.tag2_;
}
@@ -222,7 +227,7 @@ namespace test
void track_allocate(void *ptr, std::size_t n, std::size_t size, int tag)
{
if(n == 0) {
// TODO: This is unspecified - not undefined, so what to do?
BOOST_ERROR("Allocating 0 length array.");
}
else {
++count_allocations;
@@ -238,7 +243,6 @@ namespace test
if(pos == allocated_memory.end()) {
BOOST_ERROR("Deallocating unknown pointer.");
} else {
// TODO: Not exception safe.
BOOST_TEST(pos->first.start == ptr);
BOOST_TEST(pos->first.end == (char*) ptr + n * size);
BOOST_TEST(pos->second.tag_ == tag);
@@ -249,21 +253,18 @@ namespace test
if(count_allocations > 0) --count_allocations;
}
void track_construct(void* ptr, std::size_t size, int tag)
void track_construct(void* ptr, std::size_t /*size*/, int tag)
{
std::map<memory_area, memory_track>::iterator pos
= allocated_memory.find(memory_area(ptr, ptr));
if(pos == allocated_memory.end())
BOOST_ERROR("Constructing unknown pointer.");
BOOST_TEST(pos->second.tag_ == tag);
//TODO: Track the number of allocations, and make sure the number
// of constructions doesn't exceed it. If you're feeling keen,
// perhaps track the individual objects in the array.
++count_constructions;
++pos->second.constructed_;
}
void track_destroy(void* ptr, std::size_t size, int tag)
void track_destroy(void* ptr, std::size_t /*size*/, int tag)
{
std::map<memory_area, memory_track>::iterator pos
= allocated_memory.find(memory_area(ptr, ptr));
@@ -302,7 +303,6 @@ namespace test
allocator(allocator const& x) : tag_(x.tag_) { detail::allocator_ref(); }
~allocator() { detail::allocator_unref(); }
// TODO: Shall I check these?
pointer address(reference r) { return pointer(&r); }
const_pointer address(const_reference r) { return const_pointer(&r); }