Add an extra test for a Borland bug I found.

[SVN r32685]
This commit is contained in:
Daniel James
2006-02-07 00:45:32 +00:00
parent b626dc405e
commit 3cb7963112
3 changed files with 100 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ rule hash-test ( names + : extras * )
[ hash-test hash_string_test ]
[ hash-test hash_range_test ]
[ hash-test hash_custom_test ]
[ hash-test hash_global_namespace_test ]
[ hash-test hash_built_in_array_test ]
[ hash-test hash_value_array_test ]
[ hash-test hash_vector_test ]

View File

@@ -8,6 +8,11 @@ import testing ;
alias framework : /boost/test//boost_unit_test_framework ;
project hash-tests
: requirements
<toolset>gcc:<define>_GLIBCXX_DEBUG
;
test-suite functional/hash
:
[ run hash_fwd_test_1.cpp framework ]
@@ -19,6 +24,7 @@ test-suite functional/hash
[ run hash_string_test.cpp framework ]
[ run hash_range_test.cpp framework ]
[ run hash_custom_test.cpp framework ]
[ run hash_global_namespace_test.cpp framework ]
[ run hash_built_in_array_test.cpp framework ]
[ run hash_value_array_test.cpp framework ]
[ run hash_vector_test.cpp framework ]

View File

@@ -0,0 +1,93 @@
// (C) Copyright Daniel James 2005.
// Use, modification and distribution are subject to 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)
// This test demonstrates an ADL bug in Borland 5.5 where ADL isn't performed
// in the global namespace.
#include <boost/config.hpp>
#include <cstddef>
struct custom
{
int value_;
std::size_t hash() const
{
return value_ * 10;
}
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
friend std::size_t hash_value(custom const& x )
{
return x.hash();
}
#endif
custom(int x) : value_(x) {}
};
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace boost
{
std::size_t hash_value(custom x)
{
return x.hash();
}
}
#endif
#include "./config.hpp"
#ifdef TEST_EXTENSIONS
# ifdef TEST_STD_INCLUDES
# include <functional>
# else
# include <boost/functional/hash/hash.hpp>
# endif
#endif
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#ifdef TEST_EXTENSIONS
#include <vector>
#include <string>
#include <cctype>
BOOST_AUTO_TEST_CASE(custom_tests)
{
HASH_NAMESPACE::hash<custom> custom_hasher;
BOOST_CHECK(custom_hasher(10) == 100u);
custom x(55);
BOOST_CHECK(custom_hasher(x) == 550u);
{
using namespace HASH_NAMESPACE;
BOOST_CHECK(custom_hasher(x) == hash_value(x));
}
std::vector<custom> custom_vector;
custom_vector.push_back(5);
custom_vector.push_back(25);
custom_vector.push_back(35);
std::size_t seed = 0;
HASH_NAMESPACE::hash_combine(seed, custom(5));
HASH_NAMESPACE::hash_combine(seed, custom(25));
HASH_NAMESPACE::hash_combine(seed, custom(35));
std::size_t seed2 = 0;
HASH_NAMESPACE::hash_combine(seed2, 50u);
HASH_NAMESPACE::hash_combine(seed2, 250u);
HASH_NAMESPACE::hash_combine(seed2, 350u);
BOOST_CHECK(seed ==
HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end()));
BOOST_CHECK(seed == seed2);
}
#endif // TEST_EXTENSIONS