Skip to content

Commit

Permalink
Add test/append_digest.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Nov 4, 2024
1 parent 61c8a12 commit 20b2d2e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ run hash_append_range.cpp ;
run hash_append_range_2.cpp ;

run append_zero_sized.cpp ;
run append_digest.cpp ;

# hash_append, constexpr

Expand Down
55 changes: 55 additions & 0 deletions test/append_digest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2017, 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/fnv1a.hpp>
#include <boost/hash2/digest.hpp>
#include <boost/core/lightweight_test.hpp>
#include <array>

template<class Hash, class Flavor, class R> void test( R r )
{
Flavor f;

{
unsigned char v[4] = { 1, 2, 3, 4 };

Hash h;

hash_append( h, f, v );

BOOST_TEST_EQ( h.result(), r );
}

{
std::array<unsigned char, 4> v = {{ 1, 2, 3, 4 }};

Hash h;

hash_append( h, f, v );

BOOST_TEST_EQ( h.result(), r );
}

{
boost::hash2::digest<4> v = {{ 1, 2, 3, 4 }};

Hash h;

hash_append( h, f, v );

BOOST_TEST_EQ( h.result(), r );
}
}

int main()
{
using namespace boost::hash2;

test<fnv1a_32, default_flavor>( 1463068797 );
test<fnv1a_32, little_endian_flavor>( 1463068797 );
test<fnv1a_32, big_endian_flavor>( 1463068797 );

return boost::report_errors();
}

0 comments on commit 20b2d2e

Please sign in to comment.