Files
container_hash/test/hash_string_test.cpp
Daniel James e624b55a5c Automatically detect what float functions the compiler/library supports
in hash and seperate out some of the detail headers.

Merged revisions 53159-53161,53167-53169,53175,53185,53205,53247-53248,53254 via svnmerge from 
https://svn.boost.org/svn/boost/trunk

........
  r53159 | danieljames | 2009-05-21 22:21:11 +0100 (Thu, 21 May 2009) | 1 line
  
  Move the hash limits workaround into its own file.
........
  r53160 | danieljames | 2009-05-21 22:21:44 +0100 (Thu, 21 May 2009) | 1 line
  
  Move the two different hash float implementation into their own header.
........
  r53161 | danieljames | 2009-05-21 22:22:04 +0100 (Thu, 21 May 2009) | 1 line
  
  Try to automatically detect which float functions are available.
........
  r53167 | danieljames | 2009-05-22 07:00:56 +0100 (Fri, 22 May 2009) | 1 line
  
  Fix a typo.
........
  r53168 | danieljames | 2009-05-22 07:01:19 +0100 (Fri, 22 May 2009) | 3 lines
  
  Spell out exactly which functions can be used with which types.
  
  I was hitting some ambiguity errors when the function was for the wrong type.
........
  r53169 | danieljames | 2009-05-22 07:01:35 +0100 (Fri, 22 May 2009) | 1 line
  
  Some STLport fixes for hash.
........
  r53175 | danieljames | 2009-05-22 14:35:56 +0100 (Fri, 22 May 2009) | 2 lines
  
  Rename struct to avoid using 'type::'type' which confuses some
  compilers.
........
  r53185 | danieljames | 2009-05-22 20:00:35 +0100 (Fri, 22 May 2009) | 1 line
  
  Explicitly qualify 'none' to avoid confusion with boost::none.
........
  r53205 | danieljames | 2009-05-23 16:21:38 +0100 (Sat, 23 May 2009) | 4 lines
  
  Try to deal with macros for frexpl and ldexpl.
  
  The error message for msvc-9.0~wm5~stlport5.2 suggests that frexpl and ldexpl
  are macros.
........
  r53247 | danieljames | 2009-05-25 14:45:16 +0100 (Mon, 25 May 2009) | 4 lines
  
  Check for float functions with less templates.
  
  The only template mechanism now used is full specialization, so this should
  hopefully be more portable to compilers we don't test.
........
  r53248 | danieljames | 2009-05-25 15:27:00 +0100 (Mon, 25 May 2009) | 1 line
  
  Fix a couple of clumsy errors in the last commit.
........
  r53254 | danieljames | 2009-05-25 20:44:52 +0100 (Mon, 25 May 2009) | 1 line
  
  Hash change log.
........


[SVN r53361]
2009-05-28 20:42:55 +00:00

78 lines
2.1 KiB
C++

// Copyright 2005-2009 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)
#include "./config.hpp"
#ifdef TEST_STD_INCLUDES
# include <functional>
#else
# include <boost/functional/hash.hpp>
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <string>
#include "./compile_time.hpp"
void string_tests()
{
compile_time_tests((std::string*) 0);
HASH_NAMESPACE::hash<std::string> x1;
HASH_NAMESPACE::hash<std::string> x2;
BOOST_TEST(x1("Hello") == x2(std::string("Hel") + "lo"));
BOOST_TEST(x1("") == x2(std::string()));
#if defined(TEST_EXTENSIONS)
std::string value1;
std::string value2("Hello");
BOOST_TEST(x1(value1) == HASH_NAMESPACE::hash_value(value1));
BOOST_TEST(x1(value2) == HASH_NAMESPACE::hash_value(value2));
BOOST_TEST(HASH_NAMESPACE::hash_value(value1) ==
HASH_NAMESPACE::hash_range(value1.begin(), value1.end()));
BOOST_TEST(HASH_NAMESPACE::hash_value(value2) ==
HASH_NAMESPACE::hash_range(value2.begin(), value2.end()));
#endif
}
#if !defined(BOOST_NO_STD_WSTRING)
void wstring_tests()
{
compile_time_tests((std::wstring*) 0);
HASH_NAMESPACE::hash<std::wstring> x1;
HASH_NAMESPACE::hash<std::wstring> x2;
BOOST_TEST(x1(L"Hello") == x2(std::wstring(L"Hel") + L"lo"));
BOOST_TEST(x1(L"") == x2(std::wstring()));
#if defined(TEST_EXTENSIONS)
std::wstring value1;
std::wstring value2(L"Hello");
BOOST_TEST(x1(value1) == HASH_NAMESPACE::hash_value(value1));
BOOST_TEST(x1(value2) == HASH_NAMESPACE::hash_value(value2));
BOOST_TEST(HASH_NAMESPACE::hash_value(value1) ==
HASH_NAMESPACE::hash_range(value1.begin(), value1.end()));
BOOST_TEST(HASH_NAMESPACE::hash_value(value2) ==
HASH_NAMESPACE::hash_range(value2.begin(), value2.end()));
#endif
}
#endif
int main()
{
string_tests();
#if !defined(BOOST_NO_STD_WSTRING)
wstring_tests();
#endif
return boost::report_errors();
}