From cc83a438aed1bf6fea1795fa6108fecf40d1ac91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 18 Nov 2018 09:45:11 -0500 Subject: [PATCH] t: tests for ogg_reader --- t/CMakeLists.txt | 5 ++++- t/ogg.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 t/ogg.cc diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index 9025a6e..8f48f38 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -1,6 +1,9 @@ add_executable(opus.t EXCLUDE_FROM_ALL opus.cc) target_link_libraries(opus.t libopustags) +add_executable(ogg.t EXCLUDE_FROM_ALL ogg.cc) +target_link_libraries(ogg.t libopustags) + add_executable(error.t EXCLUDE_FROM_ALL error.cc) target_link_libraries(error.t libopustags) @@ -9,5 +12,5 @@ configure_file(gobble.opus . COPYONLY) add_custom_target( check COMMAND prove "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" - DEPENDS opustags gobble.opus opus.t error.t + DEPENDS opustags gobble.opus opus.t ogg.t error.t ) diff --git a/t/ogg.cc b/t/ogg.cc new file mode 100644 index 0000000..f93ce71 --- /dev/null +++ b/t/ogg.cc @@ -0,0 +1,50 @@ +#include +#include "tap.h" + +static void check_ref_ogg() +{ + FILE* input = fopen("gobble.opus", "r"); + if (input == nullptr) + throw failure("could not open gobble.opus"); + ot::ogg_reader reader(input); + + ot::status rc = reader.read_page(); + if (rc != ot::status::ok) + throw failure("could not read the first page"); + rc = reader.read_packet(); + if (rc != ot::status::ok) + throw failure("could not read the first packet"); + if (reader.packet.bytes != 19) + throw failure("unexpected length for the first packet"); + rc = reader.read_packet(); + if (rc != ot::status::end_of_page) + throw failure("got an unexpected second packet on the first page"); + + rc = reader.read_page(); + if (rc != ot::status::ok) + throw failure("could not read the second page"); + rc = reader.read_packet(); + if (rc != ot::status::ok) + throw failure("could not read the second packet"); + if (reader.packet.bytes != 62) + throw failure("unexpected length for the first packet"); + rc = reader.read_packet(); + if (rc != ot::status::end_of_page) + throw failure("got an unexpected second packet on the second page"); + + while (!ogg_page_eos(&reader.page)) { + rc = reader.read_page(); + if (rc != ot::status::ok) + throw failure("failure reading a page"); + } + rc = reader.read_page(); + if (rc != ot::status::end_of_stream) + throw failure("did not correctly detect the end of stream"); +} + +int main(int argc, char **argv) +{ + std::cout << "1..1\n"; + run(check_ref_ogg, "check a reference ogg stream"); + return 0; +}