Skip to content

Commit

Permalink
Update test helpers to add generic vectorparameter checks and compari…
Browse files Browse the repository at this point in the history
…sor ops
  • Loading branch information
rsjbailey committed Jun 29, 2021
1 parent 8225a74 commit 72fc291
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
35 changes: 35 additions & 0 deletions tests/helper/parameter_checks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,34 @@ namespace adm_test {
}
}

template <typename ParamT, typename ElementT, typename VectorT>
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<VectorT>()) {
element.set(VectorT{});
}
}
SECTION("Check add & remove") {
auto items = element.template get<ParamT>();
REQUIRE(items.empty());
for (auto const& i : parameter_vector) {
element.add(i);
}
items = element.template get<ParamT>();
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<ParamT>();
REQUIRE(items.empty());
}
}

template <typename T>
class HasDefaultOf {
public:
Expand Down Expand Up @@ -127,6 +155,13 @@ namespace adm_test {
modifiedVal.get());
}

template <typename ParamT, typename ElementT, typename VectorT>
void check_vector_param(std::shared_ptr<ElementT> element,
detail::CanBeSetTo<VectorT> modifiedVal) {
detail::check_vector_impl<ParamT>(detail::get_from_shared(element),
modifiedVal.get());
}

template <typename T>
detail::HasDefaultOf<T> hasDefaultOf(T value) {
return detail::HasDefaultOf<T>(value);
Expand Down
54 changes: 14 additions & 40 deletions tests/helper/parameter_comparators.hpp
Original file line number Diff line number Diff line change
@@ -1,59 +1,33 @@
#pragma once

namespace detail {
template <typename ParameterT, typename ElementT>
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<ParameterT>() != rhs.template has<ParameterT>()) {
return false;
}
// either both have it or neither does. If neither, they're equal.
if (!lhs.template has<ParameterT>()) {
return true;
}
// otherwise both have the parameter, so compare.
return lhs.template get<ParameterT>() == rhs.template get<ParameterT>();
}

template <typename FirstParam, typename... Params>
struct Comparator {
template <typename ElementT>
static bool compareAll(ElementT const& lhs, ElementT const& rhs) {
return (compareOptionalParameter<FirstParam>(lhs, rhs) &&
Comparator<Params...>::compareAll(lhs, rhs));
}
};
template <typename FirstParam>
struct Comparator<FirstParam> {
template <typename ElementT>
static bool compareAll(ElementT const& lhs, ElementT const& rhs) {
return compareOptionalParameter<FirstParam>(lhs, rhs);
}
};
template <typename... Params, typename ElementT>
bool compareOptionals(ElementT const& lhs, ElementT const& rhs) {
return Comparator<Params...>::compareAll(lhs, rhs);
}
} // namespace detail
#include <adm/detail/optional_comparison.hpp>
#include <adm/elements_fwd.hpp>
#include <adm/elements/loudness_metadata.hpp>

namespace adm {
bool operator==(ChannelLock const& lhs, ChannelLock const& rhs) {
using ::detail::compareOptionals;
using detail::compareOptionals;
return compareOptionals<ChannelLockFlag, MaxDistance>(lhs, rhs);
}
bool operator==(ObjectDivergence const& lhs, ObjectDivergence const& rhs) {
using ::detail::compareOptionals;
using detail::compareOptionals;
return compareOptionals<Divergence, AzimuthRange, PositionRange>(lhs, rhs);
}
bool operator==(JumpPosition const& lhs, JumpPosition const& rhs) {
using ::detail::compareOptionals;
using detail::compareOptionals;
return compareOptionals<JumpPositionFlag, InterpolationLength>(lhs, rhs);
}
bool operator==(HeadphoneVirtualise const& lhs,
HeadphoneVirtualise const& rhs) {
using ::detail::compareOptionals;
using detail::compareOptionals;
return compareOptionals<Bypass, DirectToReverberantRatio>(lhs, rhs);
}
bool operator==(LoudnessMetadata const& lhs, LoudnessMetadata const& rhs) {
using detail::compareOptionals;
return compareOptionals<LoudnessMethod, LoudnessRecType,
LoudnessCorrectionType, IntegratedLoudness,
LoudnessRange, MaxTruePeak, MaxMomentary,
MaxShortTerm, DialogueLoudness>(lhs, rhs);
}
bool operator==(Gain const& lhs, Gain const& rhs) {
if (lhs.isDb() != rhs.isDb()) {
return false;
Expand Down

0 comments on commit 72fc291

Please sign in to comment.