From 72fc291d25eb3d6b94c588085b27671395204a7a Mon Sep 17 00:00:00 2001 From: Richard Bailey Date: Tue, 29 Jun 2021 10:49:02 +0100 Subject: [PATCH] Update test helpers to add generic vectorparameter checks and comparisor ops --- tests/helper/parameter_checks.hpp | 35 +++++++++++++++++ tests/helper/parameter_comparators.hpp | 54 +++++++------------------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/tests/helper/parameter_checks.hpp b/tests/helper/parameter_checks.hpp index 7c9b4ce2..25c0b5e5 100644 --- a/tests/helper/parameter_checks.hpp +++ b/tests/helper/parameter_checks.hpp @@ -73,6 +73,34 @@ namespace adm_test { } } + template + void check_vector_impl(ElementT& element, VectorT parameter_vector) { + SECTION("test should be supplied with non-empty vector") { + using ValueT = typename VectorT::value_type; + // if it's an optional vector, set to empty vector + if (!element.template has()) { + element.set(VectorT{}); + } + } + SECTION("Check add & remove") { + auto items = element.template get(); + REQUIRE(items.empty()); + for (auto const& i : parameter_vector) { + element.add(i); + } + items = element.template get(); + REQUIRE(items.size() == parameter_vector.size()); + for (auto i = 0u; i != items.size(); ++i) { + REQUIRE(items[i] == parameter_vector[i]); + } + for (auto i = 0u; i != items.size(); ++i) { + element.remove(items[i]); + } + items = element.template get(); + REQUIRE(items.empty()); + } + } + template class HasDefaultOf { public: @@ -127,6 +155,13 @@ namespace adm_test { modifiedVal.get()); } + template + void check_vector_param(std::shared_ptr element, + detail::CanBeSetTo modifiedVal) { + detail::check_vector_impl(detail::get_from_shared(element), + modifiedVal.get()); + } + template detail::HasDefaultOf hasDefaultOf(T value) { return detail::HasDefaultOf(value); diff --git a/tests/helper/parameter_comparators.hpp b/tests/helper/parameter_comparators.hpp index 212f812c..1b7d8553 100644 --- a/tests/helper/parameter_comparators.hpp +++ b/tests/helper/parameter_comparators.hpp @@ -1,59 +1,33 @@ #pragma once - -namespace detail { - template - bool compareOptionalParameter(ElementT const& lhs, ElementT const& rhs) { - // if one has the parameter and the other doesn't they're not equal - if (lhs.template has() != rhs.template has()) { - return false; - } - // either both have it or neither does. If neither, they're equal. - if (!lhs.template has()) { - return true; - } - // otherwise both have the parameter, so compare. - return lhs.template get() == rhs.template get(); - } - - template - struct Comparator { - template - static bool compareAll(ElementT const& lhs, ElementT const& rhs) { - return (compareOptionalParameter(lhs, rhs) && - Comparator::compareAll(lhs, rhs)); - } - }; - template - struct Comparator { - template - static bool compareAll(ElementT const& lhs, ElementT const& rhs) { - return compareOptionalParameter(lhs, rhs); - } - }; - template - bool compareOptionals(ElementT const& lhs, ElementT const& rhs) { - return Comparator::compareAll(lhs, rhs); - } -} // namespace detail +#include +#include +#include namespace adm { bool operator==(ChannelLock const& lhs, ChannelLock const& rhs) { - using ::detail::compareOptionals; + using detail::compareOptionals; return compareOptionals(lhs, rhs); } bool operator==(ObjectDivergence const& lhs, ObjectDivergence const& rhs) { - using ::detail::compareOptionals; + using detail::compareOptionals; return compareOptionals(lhs, rhs); } bool operator==(JumpPosition const& lhs, JumpPosition const& rhs) { - using ::detail::compareOptionals; + using detail::compareOptionals; return compareOptionals(lhs, rhs); } bool operator==(HeadphoneVirtualise const& lhs, HeadphoneVirtualise const& rhs) { - using ::detail::compareOptionals; + using detail::compareOptionals; return compareOptionals(lhs, rhs); } + bool operator==(LoudnessMetadata const& lhs, LoudnessMetadata const& rhs) { + using detail::compareOptionals; + return compareOptionals(lhs, rhs); + } bool operator==(Gain const& lhs, Gain const& rhs) { if (lhs.isDb() != rhs.isDb()) { return false;