t: tests for ogg_reader

This commit is contained in:
Frédéric Mangano-Tarumi 2018-11-18 09:45:11 -05:00
parent 6ed0326a74
commit cc83a438ae
2 changed files with 54 additions and 1 deletions

View File

@ -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
)

50
t/ogg.cc Normal file
View File

@ -0,0 +1,50 @@
#include <opustags.h>
#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;
}