diff --git a/test/exception/constructor_tests.cpp b/test/exception/constructor_tests.cpp index 87230879..390f391a 100644 --- a/test/exception/constructor_tests.cpp +++ b/test/exception/constructor_tests.cpp @@ -9,6 +9,7 @@ #include #include #include "../helpers/random_values.hpp" +#include "../helpers/input_iterator.hpp" struct objects { @@ -111,9 +112,20 @@ struct range_construct_test5 : public range, objects } }; -// TODO: Write a test using an input iterator. +template +struct input_range_construct_test : public range, objects +{ + input_range_construct_test() : range(60) {} + + void run() const { + T x(test::input_iterator(this->values.begin()), + test::input_iterator(this->values.end()), + 0, hash, equal_to, allocator); + } +}; RUN_EXCEPTION_TESTS( (construct_test1)(construct_test2)(construct_test3)(construct_test4)(construct_test5) - (range_construct_test1)(range_construct_test2)(range_construct_test3)(range_construct_test4)(range_construct_test5), + (range_construct_test1)(range_construct_test2)(range_construct_test3)(range_construct_test4)(range_construct_test5) + (input_range_construct_test), CONTAINER_SEQ) diff --git a/test/exception/erase_tests.cpp b/test/exception/erase_tests.cpp index 6e8339d0..98cc5b1e 100644 --- a/test/exception/erase_tests.cpp +++ b/test/exception/erase_tests.cpp @@ -25,7 +25,14 @@ struct erase_test_base : public test::exception_base } void check(T const& x) const { - // TODO: Check that exception was thrown by hash or predicate object? + std::string scope(test::scope); + + // TODO: Instead of checking for 'operator==', I should check against + // a scope stack. + BOOST_CHECK(scope.find("hash::") != std::string::npos || + scope.find("equal_to::") != std::string::npos || + scope == "operator==(object, object)"); + test::check_equivalent_keys(x); } }; diff --git a/test/exception/insert_tests.cpp b/test/exception/insert_tests.cpp index 925330f8..ff779be7 100644 --- a/test/exception/insert_tests.cpp +++ b/test/exception/insert_tests.cpp @@ -12,6 +12,7 @@ #include "../helpers/random_values.hpp" #include "../helpers/invariants.hpp" #include "../helpers/strong.hpp" +#include "../helpers/input_iterator.hpp" #include @@ -31,7 +32,7 @@ struct insert_test_base : public test::exception_base void check(T const& x, strong_type const& strong) const { std::string scope(test::scope); - if(scope.find_first_of("hash::operator()") == std::string::npos) + if(scope.find("hash::operator()") == std::string::npos) strong.test(x); test::check_equivalent_keys(x); } diff --git a/test/exception/rehash_tests.cpp b/test/exception/rehash_tests.cpp index 07801021..9811c162 100644 --- a/test/exception/rehash_tests.cpp +++ b/test/exception/rehash_tests.cpp @@ -33,9 +33,13 @@ struct rehash_test_base : public test::exception_base void check(T const& x, strong_type const& strong) const { std::string scope(test::scope); - if(scope.find_first_of("hash::operator()") == std::string::npos && - scope.find_first_of("equal_to::operator()") == std::string::npos) + // TODO: Instead of checking for 'operator==', I should check against + // a scope stack. + if(scope.find("hash::operator()") == std::string::npos && + scope.find("equal_to::operator()") == std::string::npos && + scope != "operator==(object, object)") strong.test(x); + test::check_equivalent_keys(x); } }; @@ -78,3 +82,4 @@ struct rehash_test4 : rehash_test_base RUN_EXCEPTION_TESTS( (rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4), CONTAINER_SEQ) + diff --git a/test/helpers/helpers.hpp b/test/helpers/helpers.hpp index 6a1cadef..83f4a432 100644 --- a/test/helpers/helpers.hpp +++ b/test/helpers/helpers.hpp @@ -13,26 +13,26 @@ namespace test { typedef typename Container::key_type key_type; - static key_type get_key(key_type const& x) + static key_type const& get_key(key_type const& x) { return x; } template - static key_type get_key(std::pair const& x, char = 0) + static key_type const& get_key(std::pair const& x, char = 0) { return x.first; } template - static key_type get_key(std::pair const& x, unsigned char = 0) + static key_type const& get_key(std::pair const& x, unsigned char = 0) { return x.first; } }; template - inline typename Container::key_type get_key(T const& x) + inline typename Container::key_type const& get_key(T const& x) { return get_key_impl::get_key(x); } diff --git a/test/helpers/input_iterator.hpp b/test/helpers/input_iterator.hpp new file mode 100644 index 00000000..3731a408 --- /dev/null +++ b/test/helpers/input_iterator.hpp @@ -0,0 +1,37 @@ + +// Copyright 2005-2006 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(BOOST_UNORDERED_TEST_HELPERS_INPUT_ITERATOR_HEADER) +#define BOOST_UNORDERED_TEST_HELPERS_INPUT_ITERATOR_HEADER + +#include +#include + +namespace test +{ + // TODO: Make this a stricter input iterator. + template + struct input_iterator_adaptor + : boost::iterator_adaptor< + input_iterator_adaptor, Iterator, + boost::use_default, std::input_iterator_tag> + { + typedef boost::iterator_adaptor< + input_iterator_adaptor, Iterator, + boost::use_default, std::input_iterator_tag> base; + + explicit input_iterator_adaptor(Iterator it = Iterator()) + : base(it) {} + }; + + template + input_iterator_adaptor input_iterator(Iterator it) + { + return input_iterator_adaptor(it); + } +} + +#endif + diff --git a/test/unordered/constructor_tests.cpp b/test/unordered/constructor_tests.cpp index fa72a454..48d7be23 100644 --- a/test/unordered/constructor_tests.cpp +++ b/test/unordered/constructor_tests.cpp @@ -10,6 +10,7 @@ #include "../helpers/random_values.hpp" #include "../helpers/tracker.hpp" #include "../helpers/equivalent.hpp" +#include "../helpers/input_iterator.hpp" #include @@ -204,6 +205,15 @@ void constructor_tests2(T* = 0) test::check_container(x, v); test::check_container(y, x); } + + std::cerr<<"Construct 8 - from input iterator\n"; + { + test::random_values v(100); + T x(test::input_iterator(v.begin()), test::input_iterator(v.end()), 0, hf1, eq1); + T y(test::input_iterator(x.begin()), test::input_iterator(x.end()), 0, hf2, eq2); + test::check_container(x, v); + test::check_container(y, x); + } } int main() diff --git a/test/unordered/erase_tests.cpp b/test/unordered/erase_tests.cpp index 05319e5c..d6cb1408 100644 --- a/test/unordered/erase_tests.cpp +++ b/test/unordered/erase_tests.cpp @@ -78,7 +78,6 @@ void erase_tests1(Container* = 0) BOOST_TEST(next == (index == 0 ? x.begin() : boost::next(prev))); BOOST_TEST(x.count(key) == count - 1); - std::cerr< @@ -199,6 +200,19 @@ void insert_tests2(X* = 0) test::check_equivalent_keys(x); } + + std::cerr<<"insert input iterator range tests.\n"; + + { + X x; + const_iterator pos = x.begin(); + + test::random_values v(1000); + x.insert(test::input_iterator(v.begin()), test::input_iterator(v.end())); + test::check_container(x, v); + + test::check_equivalent_keys(x); + } } template