From 634f55ceed45197e743c2d1c3df0c97c6f8888ae Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 16 Jan 2024 15:26:46 +0100 Subject: codec: Adding schema hashes and testing --- modules/codec/tests/schema.cpp | 66 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) (limited to 'modules/codec/tests/schema.cpp') diff --git a/modules/codec/tests/schema.cpp b/modules/codec/tests/schema.cpp index df90eb1..871feb7 100644 --- a/modules/codec/tests/schema.cpp +++ b/modules/codec/tests/schema.cpp @@ -1,14 +1,68 @@ #include + +#include #include "../c++/schema.h" #include "../c++/schema_hash.h" namespace { -SAW_TEST("Schema String Hash"){ - using namespace saw; - data str{"foo"}; - uint64_t hash = schema_hash::apply(0, str); - uint64_t expected_hash = 1524024712123765130u; +template +struct schema_hash_test { + static_assert(saw::always_false, "Needs the test pair"); +}; + +template +struct schema_test_pair{}; + +template +struct schema_hash_test> { + static void check(){ + using namespace saw; + uint64_t hash = schema_hash::apply(); + SAW_EXPECT( hash == expected, std::string{"Hash for "} + std::string{T::name.view()} + " is " + std::to_string(hash) +", but should be "+ std::to_string(expected) + "."); + } +}; + +template +struct schema_hash_test_multi { + template + static void check_ele(){ + using type = typename saw::parameter_pack_type::type; + + schema_hash_test::check(); - SAW_EXPECT( hash == expected_hash, std::string{"Hash is "} + std::to_string(hash) +", but should be 0."); + if constexpr ( (i+1) < sizeof...(T)){ + check_ele(); + } + } + + static void check(){ + if constexpr (sizeof...(T) > 0){ + check_ele<0>(); + } + } +}; + +namespace schema { +using namespace saw::schema; +} + +SAW_TEST("Schema Hashes"){ + using namespace saw; + schema_hash_test_multi< + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair, + schema_test_pair + >::check(); } } -- cgit v1.2.3