Skip to content

Commit

Permalink
Update AudioContent and AudioProgramme to use generic parameter checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rsjbailey committed Jun 29, 2021
1 parent 72fc291 commit 4e13581
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 71 deletions.
59 changes: 56 additions & 3 deletions tests/audio_content_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,64 @@
#include <catch2/catch.hpp>
#include "adm/elements/audio_content.hpp"
#include "adm/elements/audio_object.hpp"
#include "helper/parameter_checks.hpp"
#include "adm/utilities/element_io.hpp"

using namespace adm;
TEST_CASE("audio_content parameters") {
using namespace adm_test;
auto contentName = AudioContentName("MyContent");
auto audioContent = AudioContent::create(AudioContentName(contentName));
SECTION("AudioContentName") {
check_required_param<AudioContentName>(
audioContent, hasDefaultOf(contentName),
canBeSetTo(AudioContentName("SomethingElse")));
}
SECTION("AudioContentId") {
check_required_param<AudioContentId>(
audioContent, hasDefaultOf(AudioContentId{}),
canBeSetTo(AudioContentId(AudioContentIdValue(2))));
}
SECTION("AudioContentLanguage") {
check_optional_param<AudioContentLanguage>(
audioContent, canBeSetTo(AudioContentLanguage("de")));
}
SECTION("DialogId") {
check_optional_param<DialogueId>(audioContent,
canBeSetTo(Dialogue::NON_DIALOGUE));
}
SECTION("ContentKind") {
check_optional_param<ContentKind>(
audioContent, canBeSetTo(ContentKind{MixedContentKind{}}));
}
SECTION("ContentKind variants") {
SECTION("Dialog") {
check_optional_param<DialogueContentKind>(
audioContent, canBeSetTo(DialogueContent::COMMENTARY));
}
SECTION("NonDialog") {
check_optional_param<NonDialogueContentKind>(
audioContent, canBeSetTo(NonDialogueContent::EFFECT));
}
SECTION("Mixed") {
check_optional_param<MixedContentKind>(
audioContent, canBeSetTo(MixedContent::HEARING_IMPAIRED));
}
}
SECTION("LoudnessMetadatas") {
LoudnessMetadatas loudness = LoudnessMetadatas{
LoudnessMetadata{}, LoudnessMetadata{LoudnessMethod{"Guess"}}};
SECTION("check get/set") {
check_optional_param<LoudnessMetadatas>(audioContent,
canBeSetTo(loudness));
}
SECTION("add/remove") {
check_vector_param<LoudnessMetadatas>(audioContent, canBeSetTo(loudness));
}
}
}

TEST_CASE("audio_content") {
using namespace adm;
{
auto audioContent = AudioContent::create(AudioContentName("MyContent"));
audioContent->set(AudioContentId(AudioContentIdValue(1)));
Expand Down Expand Up @@ -63,8 +118,6 @@ TEST_CASE("audio_content") {
}

TEST_CASE("audio_content_dialogue_interdependencies") {
using namespace adm;

auto audioContent = AudioContent::create(AudioContentName("MyContent"));

audioContent->set(DialogueContent::VOICEOVER);
Expand Down
129 changes: 61 additions & 68 deletions tests/audio_programme_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,79 +1,72 @@
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
#include <catch2/catch.hpp>
#include "adm/elements/audio_programme.hpp"
#include "helper/parameter_checks.hpp"
#include "helper/ostream_operators.hpp"

TEST_CASE("audio_programme") {
using namespace adm;
// Attributes / Elements
{
auto audioProgramme =
AudioProgramme::create(AudioProgrammeName("MyProgramme"));
audioProgramme->set(AudioProgrammeId(AudioProgrammeIdValue(1)));
audioProgramme->set(AudioProgrammeLanguage("de"));
audioProgramme->set(Start(std::chrono::seconds(0)));
audioProgramme->set(End(std::chrono::seconds(10)));
audioProgramme->add(LoudnessMetadata());
audioProgramme->set(MaxDuckingDepth(-30));
// NOTE: AudioProgrammeReferenceScreen is not yet implemented.
// audioProgramme->set(AudioProgrammeReferenceScreen());
using namespace adm;
using namespace adm_test;

REQUIRE(audioProgramme->has<AudioProgrammeId>());
REQUIRE(audioProgramme->has<AudioProgrammeName>());
REQUIRE(audioProgramme->has<AudioProgrammeLanguage>());
REQUIRE(audioProgramme->has<Start>());
REQUIRE(audioProgramme->has<End>());
REQUIRE(audioProgramme->has<LoudnessMetadatas>());
REQUIRE(audioProgramme->has<MaxDuckingDepth>());
// NOTE: AudioProgrammeReferenceScreen is not yet implemented.
// REQUIRE(audioProgramme->has<AudioProgrammeReferenceScreen>());

REQUIRE(
audioProgramme->get<AudioProgrammeId>().get<AudioProgrammeIdValue>() ==
1u);
REQUIRE(audioProgramme->get<AudioProgrammeName>() == "MyProgramme");
REQUIRE(audioProgramme->get<AudioProgrammeLanguage>() == "de");
REQUIRE(audioProgramme->get<Start>().get() == std::chrono::seconds(0));
REQUIRE(audioProgramme->get<End>().get() == std::chrono::seconds(10));
REQUIRE(audioProgramme->get<MaxDuckingDepth>() == -30);
// NOTE: AudioProgrammeReferenceScreen is not yet implemented.
// REQUIRE(audioProgramme->get<AudioProgrammeReferenceScreen>() == ???);

audioProgramme->unset<AudioProgrammeLanguage>();
audioProgramme->unset<Start>();
audioProgramme->unset<End>();
audioProgramme->unset<LoudnessMetadatas>();
audioProgramme->unset<MaxDuckingDepth>();
// NOTE: AudioProgrammeReferenceScreen is not yet implemented.
// audioProgramme->unset<AudioProgrammeReferenceScreen>();

REQUIRE(!audioProgramme->has<AudioProgrammeLanguage>());
REQUIRE(audioProgramme->has<Start>());
REQUIRE(!audioProgramme->has<End>());
REQUIRE(!audioProgramme->has<LoudnessMetadatas>());
REQUIRE(!audioProgramme->has<MaxDuckingDepth>());
// NOTE: AudioProgrammeReferenceScreen is not yet implemented.
// REQUIRE(!audioProgramme->has<AudioProgrammeReferenceScreen>());
TEST_CASE("audio_programme parameters") {
using std::chrono::seconds;
auto audioProgramme =
AudioProgramme::create(AudioProgrammeName("MyProgramme"));
SECTION("AudioProgrammeName") {
check_required_param<AudioProgrammeName>(audioProgramme,
hasDefaultOf("MyProgramme"),
canBeSetTo("SomethingElse"));
}
SECTION("AudioProgrammeId") {
check_required_param<AudioProgrammeId>(
audioProgramme, hasDefaultOf(AudioProgrammeIdValue{}),
canBeSetTo(AudioProgrammeIdValue(2u)));
}
SECTION("AudioProgrammeLanguage") {
check_optional_param<AudioProgrammeLanguage>(audioProgramme,
canBeSetTo("fr"));
}
SECTION("Start") {
check_defaulted_param<Start>(audioProgramme, hasDefaultOf(seconds{0}),
canBeSetTo(seconds{1}));
}
// References
{
auto audioProgramme =
AudioProgramme::create(AudioProgrammeName("MyProgramme"));
SECTION("End") {
check_optional_param<End>(audioProgramme, canBeSetTo(seconds(10)));
}
SECTION("LoudnessMetadatas") {
LoudnessMetadatas loudness = LoudnessMetadatas{
LoudnessMetadata{}, LoudnessMetadata{LoudnessMethod{"Guess"}}};
SECTION("check get/set") {
check_optional_param<LoudnessMetadatas>(audioProgramme,
canBeSetTo(loudness));
}
SECTION("add/remove") {
check_vector_param<LoudnessMetadatas>(audioProgramme,
canBeSetTo(loudness));
}
}
SECTION("MaxDuckingDepth") {
check_optional_param<MaxDuckingDepth>(audioProgramme, canBeSetTo(-30.0));
}
}

auto referencedAudioContent =
AudioContent::create(AudioContentName("MyContent"));
TEST_CASE("audio_programme references") {
auto audioProgramme =
AudioProgramme::create(AudioProgrammeName("MyProgramme"));

// add references
audioProgramme->addReference(referencedAudioContent);
audioProgramme->addReference(referencedAudioContent);
REQUIRE(audioProgramme->getReferences<AudioContent>().size() == 1);
auto referencedAudioContent =
AudioContent::create(AudioContentName("MyContent"));

// remove references
audioProgramme->removeReference(referencedAudioContent);
REQUIRE(audioProgramme->getReferences<AudioContent>().size() == 0);
// add references
audioProgramme->addReference(referencedAudioContent);
audioProgramme->addReference(referencedAudioContent);
REQUIRE(audioProgramme->getReferences<AudioContent>().size() == 1);

// clear references
audioProgramme->addReference(referencedAudioContent);
audioProgramme->clearReferences<AudioContent>();
REQUIRE(audioProgramme->getReferences<AudioContent>().size() == 0);
}
// remove references
audioProgramme->removeReference(referencedAudioContent);
REQUIRE(audioProgramme->getReferences<AudioContent>().size() == 0);

// clear references
audioProgramme->addReference(referencedAudioContent);
audioProgramme->clearReferences<AudioContent>();
REQUIRE(audioProgramme->getReferences<AudioContent>().size() == 0);
}

0 comments on commit 4e13581

Please sign in to comment.