From 7f08d096aa234ee1d5610417c3759f3d2db1f611 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Fri, 24 Nov 2023 10:31:15 +0100 Subject: [PATCH] Move serialization hash unit tests in a separate file --- common/wivrn_serialization.h | 32 ------------------ common/wivrn_serialization_ut.cpp | 54 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 common/wivrn_serialization_ut.cpp diff --git a/common/wivrn_serialization.h b/common/wivrn_serialization.h index d424b179..997c697a 100644 --- a/common/wivrn_serialization.h +++ b/common/wivrn_serialization.h @@ -574,19 +574,6 @@ struct serialization_traits } }; -namespace unit_tests -{ -template -constexpr uint64_t hash(T s) -{ - return details::hash_context{}.feed(s); -} - -static_assert(hash("test") == 0xf9e6e6ef197c2b25); -static_assert(hash(1234) == 0x1fabbdf10314a21d); -static_assert(hash(-1234) == 0x77fa1c9653db5a84); -static_assert(hash(0) == 0xaf63ad4c86019caf); - template constexpr uint64_t serialization_type_hash() { @@ -595,23 +582,4 @@ constexpr uint64_t serialization_type_hash() return h.hash; } -static_assert(serialization_type_hash() == hash("uint8")); -static_assert(serialization_type_hash() == hash("int32")); -static_assert(serialization_type_hash() == hash("float32")); -static_assert(serialization_type_hash() == hash("float64")); -static_assert(serialization_type_hash() == hash("duration")); -static_assert(serialization_type_hash>() == hash("optional")); -static_assert(serialization_type_hash>() == hash("vector")); -static_assert(serialization_type_hash>() == hash("array")); -static_assert(serialization_type_hash() == hash("string")); -static_assert(serialization_type_hash>() == hash("variant")); - -struct test -{ - int x; - float y; -}; -static_assert(serialization_type_hash() == hash("structure{int32,float32}")); -} // namespace unit_tests - } // namespace xrt::drivers::wivrn diff --git a/common/wivrn_serialization_ut.cpp b/common/wivrn_serialization_ut.cpp new file mode 100644 index 00000000..ddf04ff1 --- /dev/null +++ b/common/wivrn_serialization_ut.cpp @@ -0,0 +1,54 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2022 Guillaume Meunier + * Copyright (C) 2022 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wivrn_serialization.h" + +using namespace xrt::drivers::wivrn; + +namespace +{ +template +constexpr uint64_t hash(T s) +{ + return details::hash_context{}.feed(s); +} + +static_assert(hash("test") == 0xf9e6e6ef197c2b25); +static_assert(hash(1234) == 0x1fabbdf10314a21d); +static_assert(hash(-1234) == 0x77fa1c9653db5a84); +static_assert(hash(0) == 0xaf63ad4c86019caf); + +static_assert(serialization_type_hash() == hash("uint8")); +static_assert(serialization_type_hash() == hash("int32")); +static_assert(serialization_type_hash() == hash("float32")); +static_assert(serialization_type_hash() == hash("float64")); +static_assert(serialization_type_hash() == hash("duration")); +static_assert(serialization_type_hash>() == hash("optional")); +static_assert(serialization_type_hash>() == hash("vector")); +static_assert(serialization_type_hash>() == hash("array")); +static_assert(serialization_type_hash() == hash("string")); +static_assert(serialization_type_hash>() == hash("variant")); + +struct test +{ + int x; + float y; +}; +static_assert(serialization_type_hash() == hash("structure{int32,float32}")); +} // namespace unit_tests