mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 02:25:52 +00:00
@@ -172,7 +172,14 @@ public:
|
|||||||
explicit
|
explicit
|
||||||
operator result_type() noexcept
|
operator result_type() noexcept
|
||||||
{
|
{
|
||||||
return retrieveHash();
|
auto result = retrieveHash();
|
||||||
|
resetBuffers();
|
||||||
|
if (state_)
|
||||||
|
{
|
||||||
|
XXH3_freeState(state_);
|
||||||
|
state_ = nullptr;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||||||
#include <xrpl/beast/hash/xxhasher.h>
|
#include <xrpl/beast/hash/xxhasher.h>
|
||||||
#include <xrpl/beast/unit_test.h>
|
#include <xrpl/beast/unit_test.h>
|
||||||
|
|
||||||
|
#include "../../../include/xrpl/protocol/digest.h"
|
||||||
|
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
|
||||||
class XXHasher_test : public unit_test::suite
|
class XXHasher_test : public unit_test::suite
|
||||||
@@ -182,6 +184,60 @@ public:
|
|||||||
17285302196561698791ULL);
|
17285302196561698791ULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testOperatorResultTypeDoesTheSameAsOtherHashers()
|
||||||
|
{
|
||||||
|
testcase("Operator result type does the same as other hashers");
|
||||||
|
xxhasher hasher1;
|
||||||
|
ripple::sha256_hasher hasher2{};
|
||||||
|
|
||||||
|
std::string object{"Hello xxhash"};
|
||||||
|
hasher1(object.data(), object.size());
|
||||||
|
hasher2(object.data(), object.size());
|
||||||
|
auto xxhashResult1 = static_cast<xxhasher::result_type>(hasher1);
|
||||||
|
auto xxhashResult2 = static_cast<xxhasher::result_type>(hasher1);
|
||||||
|
|
||||||
|
auto sha256Result1 = static_cast<ripple::sha256_hasher::result_type>(hasher2);
|
||||||
|
auto sha256Result2 = static_cast<ripple::sha256_hasher::result_type>(hasher2);
|
||||||
|
|
||||||
|
auto xxhashChanged = xxhashResult1 == xxhashResult2;
|
||||||
|
auto sha256Changed = sha256Result1 == sha256Result2;
|
||||||
|
BEAST_EXPECT(xxhashChanged == sha256Changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testHasherStateStillValidAfterReset()
|
||||||
|
{
|
||||||
|
testcase("Hasher state still valid after reset");
|
||||||
|
{
|
||||||
|
xxhasher hasher1;
|
||||||
|
|
||||||
|
std::string object{"Hello xxhash"};
|
||||||
|
hasher1(object.data(), object.size());
|
||||||
|
auto xxhashResult1 = static_cast<xxhasher::result_type>(hasher1);
|
||||||
|
hasher1(object.data(), object.size());
|
||||||
|
auto xxhashResult2 = static_cast<xxhasher::result_type>(hasher1);
|
||||||
|
|
||||||
|
BEAST_EXPECT(xxhashResult1 == xxhashResult2);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
xxhasher hasher1;
|
||||||
|
|
||||||
|
std::string object;
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
object += "Hello, xxHash!";
|
||||||
|
}
|
||||||
|
|
||||||
|
hasher1(object.data(), object.size());
|
||||||
|
auto xxhashResult1 = static_cast<xxhasher::result_type>(hasher1);
|
||||||
|
hasher1(object.data(), object.size());
|
||||||
|
auto xxhashResult2 = static_cast<xxhasher::result_type>(hasher1);
|
||||||
|
|
||||||
|
BEAST_EXPECT(xxhashResult1 == xxhashResult2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
@@ -194,6 +250,8 @@ public:
|
|||||||
testBigObjectWithSmallAndBigUpdatesWithSeed();
|
testBigObjectWithSmallAndBigUpdatesWithSeed();
|
||||||
testBigObjectWithOneUpdateWithoutSeed();
|
testBigObjectWithOneUpdateWithoutSeed();
|
||||||
testBigObjectWithOneUpdateWithSeed();
|
testBigObjectWithOneUpdateWithSeed();
|
||||||
|
testOperatorResultTypeDoesTheSameAsOtherHashers();
|
||||||
|
testHasherStateStillValidAfterReset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user