Skip to content

Commit

Permalink
Added running hash unit tests for boost version that might be compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Aug 21, 2024
1 parent 5ad694d commit a4bba4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/code_from_boost/hash/hash.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file contains code extracted from boost 1.78, extracted by wcjohns 20240809.
* This file contains code extracted from boost 1.85 (or possible partially from 1.78), extracted by wcjohns 20240809.
*
* It is the minimal amount of the boost hash implementation that we need to
* hash a SpecFile to generate a UUID based on spectrum file contents.
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ if( SpecUtils_ENABLE_URI_SPECTRA )
)
endif()

if( PERFORM_DEVELOPER_CHECKS )
if( PERFORM_DEVELOPER_CHECKS AND (Boost_VERSION VERSION_GREATER_EQUAL "1.81.0") )
add_executable( test_hash test_hash.cpp )
target_link_libraries( test_hash PRIVATE SpecUtils Boost::system )
target_include_directories( test_hash PUBLIC ../3rdparty )
Expand Down
13 changes: 11 additions & 2 deletions unit_tests/test_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

static_assert( PERFORM_DEVELOPER_CHECKS, "PERFORM_DEVELOPER_CHECKS must be set to on to test hashing (because we need to link to boost)" );

#include <boost/version.hpp>
#include <boost/functional/hash.hpp>
#include "code_from_boost/hash/hash.hpp"

static_assert( PERFORM_DEVELOPER_CHECKS, "PERFORM_DEVELOPER_CHECKS must be set to on to test hashing (because we need to link to boost)" );

//Untested, but it looks like
// It looks like the version of the hash code we are using was extracted from boost 108500,
// and from https://www.boost.org/users/history/ , it looks like container_hash was added
// in 1.81, so I'm guessing this is where the hash code changed.
// It looks like boost 1.78 doesnt give same hash values as boost 1.85.
static_assert( BOOST_VERSION >= 108100, "Our hashing should only be compared against boost 1.85" );


using namespace std;


Expand Down

0 comments on commit a4bba4a

Please sign in to comment.