From 26c822559b89468817f140034ed7890ce6b17638 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 4 Nov 2024 13:33:00 +0200 Subject: [PATCH] Add test/append_zero_sized.cpp --- test/Jamfile | 2 ++ test/append_pointer.cpp | 2 +- test/append_zero_sized.cpp | 63 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/append_zero_sized.cpp diff --git a/test/Jamfile b/test/Jamfile index a713a19..fecfe2c 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -73,6 +73,8 @@ run hash_append_5.cpp ; run hash_append_range.cpp ; run hash_append_range_2.cpp ; +run append_zero_sized.cpp ; + # hash_append, constexpr compile append_byte_sized_cx.cpp ; diff --git a/test/append_pointer.cpp b/test/append_pointer.cpp index 53b6213..c4fa2de 100644 --- a/test/append_pointer.cpp +++ b/test/append_pointer.cpp @@ -1,4 +1,4 @@ -// Copyright 2024 Peter Dimov. +// Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt diff --git a/test/append_zero_sized.cpp b/test/append_zero_sized.cpp new file mode 100644 index 0000000..d5006b3 --- /dev/null +++ b/test/append_zero_sized.cpp @@ -0,0 +1,63 @@ +// Copyright 2024 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include + +template void test( T const* first, T const* last, R r ) +{ + Hash h; + Flavor f; + + boost::hash2::hash_append_range( h, f, first, last ); + + BOOST_TEST_EQ( h.result(), r ); +} + +struct X +{ +}; + +BOOST_DESCRIBE_STRUCT(X, (), ()) + +// A hash_append call must always result in a call to Hash::update + +int main() +{ + using namespace boost::hash2; + + { + boost::array v[ 3 ]; + + test( v + 0, v + 1, 84696351 ); + test( v + 0, v + 2, 292984781 ); + test( v + 0, v + 3, 1253111735 ); + } + + { + std::array v[ 3 ]; + + test( v + 0, v + 1, 84696351 ); + test( v + 0, v + 2, 292984781 ); + test( v + 0, v + 3, 1253111735 ); + } + +#if defined(BOOST_DESCRIBE_CXX14) + + { + X v[ 3 ]; + + test( v + 0, v + 1, 84696351 ); + test( v + 0, v + 2, 292984781 ); + test( v + 0, v + 3, 1253111735 ); + } + +#endif + + return boost::report_errors(); +}