Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: read test data directly from the source dir #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
include(${PROJECT_SOURCE_DIR}/submodules/catch2.cmake)

set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_data")
configure_file(test_config.hpp.in test_config.hpp)

# working directory for tests containing misc. outputs
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/test_data_out")

# --- unit tests ---
function(add_adm_test name)
add_executable(${name} ${name}.cpp)
Expand All @@ -10,18 +16,16 @@ function(add_adm_test name)
)
target_include_directories(${name} PRIVATE
${PROJECT_SOURCE_DIR}/submodules
# for including test_config.h
${CMAKE_CURRENT_BINARY_DIR}
)
add_test(
NAME ${name}
COMMAND $<TARGET_FILE:${name}>
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/test_data"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/test_data_out"
)
endfunction()

# copy test files so unit test can find them relative to their running location
# when executed as "test" target
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/test_data" DESTINATION ${PROJECT_BINARY_DIR})

add_adm_test("adm_auto_parenting_tests")
add_adm_test("adm_common_definitions_tests")
add_adm_test("adm_document_tests")
Expand Down
4 changes: 3 additions & 1 deletion tests/helper/file_comparator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <fstream>
#include <string>
#include <streambuf>
#include "test_config.hpp"

class FileComparator : public Catch::MatcherBase<std::string> {
public:
Expand All @@ -11,7 +12,8 @@ class FileComparator : public Catch::MatcherBase<std::string> {

virtual bool match(const std::string& received) const override {
bool check_successful = false;
std::ifstream acceptedFile(filename_ + ".accepted." + extension_);
std::ifstream acceptedFile(
data_file(filename_ + ".accepted." + extension_));
if (acceptedFile.is_open()) {
std::string acceptedStr((std::istreambuf_iterator<char>(acceptedFile)),
std::istreambuf_iterator<char>());
Expand Down
9 changes: 9 additions & 0 deletions tests/test_config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <string>

#cmakedefine TEST_DATA_DIR "${TEST_DATA_DIR}"

inline std::string data_file(const std::string &fname) {
// use macro form so we get an error if it's not defined in cmake
return TEST_DATA_DIR "/" + fname;
}
18 changes: 11 additions & 7 deletions tests/xml_parser_audio_block_format_direct_speakers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include "adm/elements/audio_channel_format.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_block_format_direct_speakers") {
using namespace adm;
auto document = parseXml("xml_parser/audio_block_format_direct_speakers.xml");
auto document =
parseXml(data_file("xml_parser/audio_block_format_direct_speakers.xml"));
auto channelFormat =
document->lookup(parseAudioChannelFormatId("AC_00011001"));
REQUIRE(channelFormat->get<AudioChannelFormatId>()
Expand All @@ -31,8 +33,8 @@ TEST_CASE("xml_parser/audio_block_format_direct_speakers") {

TEST_CASE("xml_parser/audio_block_format_direct_speakers_cartesian") {
using namespace adm;
auto document =
parseXml("xml_parser/audio_block_format_direct_speakers_cartesian.xml");
auto document = parseXml(
data_file("xml_parser/audio_block_format_direct_speakers_cartesian.xml"));
REQUIRE(!document->getElements<AudioChannelFormat>().empty());
auto channelFormat =
document->lookup(parseAudioChannelFormatId("AC_00011001"));
Expand Down Expand Up @@ -84,15 +86,17 @@ TEST_CASE("xml_parser/audio_block_format_direct_speakers_cartesian") {
TEST_CASE("xml_parser/audio_block_format_direct_speakers_cartesian_bad_bound") {
using namespace adm;
REQUIRE_THROWS_AS(
parseXml("xml_parser/"
"audio_block_format_direct_speakers_cartesian_bad_bound.xml"),
parseXml(data_file(
"xml_parser/"
"audio_block_format_direct_speakers_cartesian_bad_bound.xml")),
error::XmlParsingError);
}

TEST_CASE("xml_parser/audio_block_format_direct_speakers_cartesian_bad_coord") {
using namespace adm;
REQUIRE_THROWS_AS(
parseXml("xml_parser/"
"audio_block_format_direct_speakers_cartesian_bad_coord.xml"),
parseXml(data_file(
"xml_parser/"
"audio_block_format_direct_speakers_cartesian_bad_coord.xml")),
error::XmlParsingError);
}
3 changes: 2 additions & 1 deletion tests/xml_parser_audio_block_format_hoa_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "adm/elements/audio_channel_format.hpp"
#include "adm/elements/frequency.hpp"
#include "adm/parse.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_block_format_hoa") {
using namespace adm;
auto document = parseXml("xml_parser/audio_block_format_hoa.xml");
auto document = parseXml(data_file("xml_parser/audio_block_format_hoa.xml"));
auto channelFormat =
document->lookup(parseAudioChannelFormatId("AC_00041001"));
REQUIRE(channelFormat->get<AudioChannelFormatId>()
Expand Down
4 changes: 3 additions & 1 deletion tests/xml_parser_audio_block_format_objects_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include "adm/elements/audio_channel_format.hpp"
#include "adm/elements/frequency.hpp"
#include "adm/parse.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_block_format_objects") {
using namespace adm;
{
auto document = parseXml("xml_parser/audio_block_format_objects.xml");
auto document =
parseXml(data_file("xml_parser/audio_block_format_objects.xml"));
auto channelFormat =
document->lookup(parseAudioChannelFormatId("AC_00031001"));
REQUIRE(channelFormat->get<AudioChannelFormatId>()
Expand Down
9 changes: 5 additions & 4 deletions tests/xml_parser_audio_channel_format_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include "adm/elements/frequency.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_channel_format") {
using namespace adm;
{
auto document = parseXml("xml_parser/audio_channel_format.xml");
auto document = parseXml(data_file("xml_parser/audio_channel_format.xml"));
auto channelFormat =
document->lookup(parseAudioChannelFormatId("AC_00031002"));

Expand All @@ -27,7 +28,7 @@ TEST_CASE("xml_parser/audio_channel_format") {
}

TEST_CASE("xml_parser/audio_channel_format_duplicate_id") {
REQUIRE_THROWS_AS(
adm::parseXml("xml_parser/audio_channel_format_duplicate_id.xml"),
adm::error::XmlParsingDuplicateId);
REQUIRE_THROWS_AS(adm::parseXml(data_file(
"xml_parser/audio_channel_format_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}
8 changes: 5 additions & 3 deletions tests/xml_parser_audio_content_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "adm/elements/audio_content.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_content") {
using namespace adm;
auto document = parseXml("xml_parser/audio_content.xml");
auto document = parseXml(data_file("xml_parser/audio_content.xml"));
auto audioContent = document->lookup(parseAudioContentId("ACO_1001"));

REQUIRE(audioContent->has<AudioContentName>() == true);
Expand All @@ -26,6 +27,7 @@ TEST_CASE("xml_parser/audio_content") {
}

TEST_CASE("xml_parser/audio_content_duplicate_id") {
REQUIRE_THROWS_AS(adm::parseXml("xml_parser/audio_content_duplicate_id.xml"),
adm::error::XmlParsingDuplicateId);
REQUIRE_THROWS_AS(
adm::parseXml(data_file("xml_parser/audio_content_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}
11 changes: 7 additions & 4 deletions tests/xml_parser_audio_object_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "adm/elements/audio_object.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_object") {
using namespace adm;
auto document = parseXml("xml_parser/audio_object.xml");
auto document = parseXml(data_file("xml_parser/audio_object.xml"));
auto audioObject = document->lookup(parseAudioObjectId("AO_1001"));

REQUIRE(audioObject->has<AudioObjectName>() == true);
Expand All @@ -32,13 +33,15 @@ TEST_CASE("xml_parser/audio_object") {
}

TEST_CASE("xml_parser/audio_object_duplicate_id") {
REQUIRE_THROWS_AS(adm::parseXml("xml_parser/audio_object_duplicate_id.xml"),
adm::error::XmlParsingDuplicateId);
REQUIRE_THROWS_AS(
adm::parseXml(data_file("xml_parser/audio_object_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}

TEST_CASE("xml_parser/audio_object_interaction") {
using namespace adm;
auto document = adm::parseXml("xml_parser/audio_object_interaction.xml");
auto document =
adm::parseXml(data_file("xml_parser/audio_object_interaction.xml"));
auto audioObjects = document->getElements<AudioObject>();
REQUIRE(audioObjects.size() == 2);

Expand Down
8 changes: 4 additions & 4 deletions tests/xml_parser_audio_pack_format_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "adm/elements/audio_pack_format.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_pack_format") {
using namespace adm;
auto document = parseXml("../test_data/xml_parser/audio_pack_format.xml");
auto document = parseXml(data_file("xml_parser/audio_pack_format.xml"));
auto audioPackFormat =
document->lookup(parseAudioPackFormatId("AP_00011001"));

Expand All @@ -26,14 +27,13 @@ TEST_CASE("xml_parser/audio_pack_format") {

TEST_CASE("xml_parser/audio_pack_format_duplicate_id") {
REQUIRE_THROWS_AS(
adm::parseXml("../test_data/xml_parser/audio_pack_format_duplicate_id.xml"),
adm::parseXml(data_file("xml_parser/audio_pack_format_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}


TEST_CASE("xml_parser/audio_pack_format_hoa") {
using namespace adm;
auto document = parseXml("../test_data/xml_parser/audio_pack_format_hoa.xml");
auto document = parseXml(data_file("xml_parser/audio_pack_format_hoa.xml"));
auto audioPackFormatGeneric =
document->lookup(parseAudioPackFormatId("AP_00041001"));

Expand Down
5 changes: 3 additions & 2 deletions tests/xml_parser_audio_programme_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include "adm/elements/audio_programme.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_programme") {
{
using namespace adm;
auto document = parseXml("xml_parser/audio_programme.xml");
auto document = parseXml(data_file("xml_parser/audio_programme.xml"));
auto audioProgramme = document->lookup(parseAudioProgrammeId("APR_1001"));

REQUIRE(audioProgramme->has<AudioProgrammeName>() == true);
Expand Down Expand Up @@ -43,6 +44,6 @@ TEST_CASE("xml_parser/audio_programme") {

TEST_CASE("xml_parser/audio_programme_duplicate_id") {
REQUIRE_THROWS_AS(
adm::parseXml("xml_parser/audio_programme_duplicate_id.xml"),
adm::parseXml(data_file("xml_parser/audio_programme_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}
9 changes: 5 additions & 4 deletions tests/xml_parser_audio_stream_format_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "adm/elements/frequency.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_stream_format") {
using namespace adm;
auto document = parseXml("xml_parser/audio_stream_format.xml");
auto document = parseXml(data_file("xml_parser/audio_stream_format.xml"));
auto streamFormat = document->lookup(parseAudioStreamFormatId("AS_00031001"));
REQUIRE(streamFormat->get<AudioStreamFormatId>()
.get<AudioStreamFormatIdValue>() == 0x1001u);
Expand All @@ -19,7 +20,7 @@ TEST_CASE("xml_parser/audio_stream_format") {
}

TEST_CASE("xml_parser/audio_stream_format_duplicate_id") {
REQUIRE_THROWS_AS(
adm::parseXml("xml_parser/audio_stream_format_duplicate_id.xml"),
adm::error::XmlParsingDuplicateId);
REQUIRE_THROWS_AS(adm::parseXml(data_file(
"xml_parser/audio_stream_format_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}
9 changes: 5 additions & 4 deletions tests/xml_parser_audio_track_format_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "adm/elements/frequency.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_track_format") {
using namespace adm;
auto document = parseXml("xml_parser/audio_track_format.xml");
auto document = parseXml(data_file("xml_parser/audio_track_format.xml"));
auto trackFormat =
document->lookup(parseAudioTrackFormatId("AT_00030001_01"));
REQUIRE(
Expand All @@ -24,7 +25,7 @@ TEST_CASE("xml_parser/audio_track_format") {
}

TEST_CASE("xml_parser/audio_track_format_duplicate_id") {
REQUIRE_THROWS_AS(
adm::parseXml("xml_parser/audio_track_format_duplicate_id.xml"),
adm::error::XmlParsingDuplicateId);
REQUIRE_THROWS_AS(adm::parseXml(data_file(
"xml_parser/audio_track_format_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}
5 changes: 3 additions & 2 deletions tests/xml_parser_audio_track_uid_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "adm/elements/audio_track_uid.hpp"
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/audio_track_uid") {
using namespace adm;
auto document = parseXml("xml_parser/audio_track_uid.xml");
auto document = parseXml(data_file("xml_parser/audio_track_uid.xml"));
auto audioTrackUid = document->lookup(parseAudioTrackUidId("ATU_00000001"));

REQUIRE(audioTrackUid->has<AudioTrackUidId>() == true);
Expand All @@ -22,6 +23,6 @@ TEST_CASE("xml_parser/audio_track_uid") {

TEST_CASE("xml_parser/audio_track_uid_duplicate_id") {
REQUIRE_THROWS_AS(
adm::parseXml("xml_parser/audio_track_uid_duplicate_id.xml"),
adm::parseXml(data_file("xml_parser/audio_track_uid_duplicate_id.xml")),
adm::error::XmlParsingDuplicateId);
}
3 changes: 2 additions & 1 deletion tests/xml_parser_common_definitions_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <catch2/catch.hpp>
#include <sstream>
#include "adm/parse.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/with_common_definitions") {
adm::parseXml("xml_parser/with_common_definitions.xml");
adm::parseXml(data_file("xml_parser/with_common_definitions.xml"));
}
9 changes: 5 additions & 4 deletions tests/xml_parser_find_audio_format_extended_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#include <catch2/catch.hpp>
#include <sstream>
#include "adm/parse.hpp"
#include "test_config.hpp"

TEST_CASE("xml_parser/find_audio_format_extended_ebu") {
adm::parseXml("xml_parser/find_audio_format_extended_ebu.xml");
adm::parseXml(data_file("xml_parser/find_audio_format_extended_ebu.xml"));
}

TEST_CASE("find_audio_format_extended_itu") {
adm::parseXml("xml_parser/find_audio_format_extended_itu.xml",
adm::parseXml(data_file("xml_parser/find_audio_format_extended_itu.xml"),
adm::xml::ParserOptions::recursive_node_search);
}

TEST_CASE("xml_parser/find_audio_format_extended_ebu_with_other_metadata") {
adm::parseXml(
"xml_parser/find_audio_format_extended_ebu_with_other_metadata.xml");
adm::parseXml(data_file(
"xml_parser/find_audio_format_extended_ebu_with_other_metadata.xml"));
}
3 changes: 2 additions & 1 deletion tests/xml_parser_unresolved_references_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <sstream>
#include "adm/parse.hpp"
#include "adm/errors.hpp"
#include "test_config.hpp"

std::string formatFilepath(const std::string& filename) {
std::stringstream ss;
Expand All @@ -16,7 +17,7 @@ TEST_CASE("xml_parser/unresolved_references") {
"audio_track_uid_1", "audio_track_uid_2", "audio_track_format",
"audio_stream_format_1", "audio_stream_format_2"}) {
SECTION(filename) {
REQUIRE_THROWS_AS(adm::parseXml(formatFilepath(filename)),
REQUIRE_THROWS_AS(adm::parseXml(data_file(formatFilepath(filename))),
adm::error::XmlParsingUnresolvedReference);
}
}
Expand Down