t: test ot::read_comments

This commit is contained in:
Frédéric Mangano-Tarumi 2018-11-24 11:11:59 -05:00
parent af61b01448
commit 26411d3843
3 changed files with 41 additions and 1 deletions

View File

@ -84,6 +84,18 @@ struct status {
std::string message;
};
/**
* Call a fopen-like function that returns a FILE* such that the returned pointer is smart and calls
* fclose on destruction.
*
* Example : `auto my_file = ot::make_file(fopen, "foo.txt", "r");`
*/
template <typename Opener, typename... Args>
std::unique_ptr<FILE, decltype(&fclose)> make_file(Opener&& f, Args&&... args)
{
return {f(std::forward<Args>(args)...), &fclose};
}
/***********************************************************************************************//**
* \defgroup ogg Ogg
* \{

View File

@ -4,10 +4,13 @@ target_link_libraries(opus.t libopustags)
add_executable(ogg.t EXCLUDE_FROM_ALL ogg.cc)
target_link_libraries(ogg.t libopustags)
add_executable(cli.t EXCLUDE_FROM_ALL cli.cc)
target_link_libraries(cli.t libopustags)
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 ogg.t
DEPENDS opustags gobble.opus opus.t ogg.t cli.t
)

25
t/cli.cc Normal file
View File

@ -0,0 +1,25 @@
#include <opustags.h>
#include "tap.h"
const char *user_comments = R"raw(
TITLE=a b c
ARTIST=X
Artist=Y
)raw";
void check_read_comments()
{
auto input = ot::make_file(fmemopen, const_cast<char*>(user_comments), strlen(user_comments), "r");
auto comments = ot::read_comments(input.get());
auto&& expected = {"TITLE=a b c", "ARTIST=X", "Artist=Y"};
if (!std::equal(comments.begin(), comments.end(), expected.begin(), expected.end()))
throw failure("parsed user comments did not match expectations");
}
int main(int argc, char **argv)
{
std::cout << "1..1\n";
run(check_read_comments, "check tags parsing");
return 0;
}