mirror of
https://github.com/fmang/opustags.git
synced 2025-01-16 05:03:13 +01:00
t: check parse_tags on a simple sample
This commit is contained in:
parent
af988efd8a
commit
a3a6cb4e36
@ -34,7 +34,7 @@
|
||||
#define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||
#endif
|
||||
|
||||
int ot::parse_tags(char *data, long len, opus_tags *tags)
|
||||
int ot::parse_tags(const char *data, long len, opus_tags *tags)
|
||||
{
|
||||
long pos;
|
||||
if (len < 8+4+4)
|
||||
|
@ -40,7 +40,7 @@ struct opus_tags {
|
||||
const char **comment;
|
||||
};
|
||||
|
||||
int parse_tags(char *data, long len, opus_tags *tags);
|
||||
int parse_tags(const char *data, long len, opus_tags *tags);
|
||||
int render_tags(opus_tags *tags, ogg_packet *op);
|
||||
void delete_tags(opus_tags *tags, const char *field);
|
||||
int add_tags(opus_tags *tags, const char **tags_to_add, uint32_t count);
|
||||
|
51
t/unit.cc
51
t/unit.cc
@ -8,10 +8,59 @@
|
||||
|
||||
#include <opustags.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
class failure : public std::runtime_error {
|
||||
public:
|
||||
failure(const char *message) : std::runtime_error(message) {}
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
static void run(F test, const char *name)
|
||||
{
|
||||
bool result = false;
|
||||
try {
|
||||
result = test();
|
||||
} catch (failure& e) {
|
||||
std::cout << "# " << e.what() << "\n";
|
||||
}
|
||||
std::cout << (result ? "ok" : "not ok") << " - " << name << "\n";
|
||||
}
|
||||
|
||||
static const char standard_OpusTags[] =
|
||||
"OpusTags"
|
||||
"\x14\x00\x00\x00" "opustags test packet"
|
||||
"\x02\x00\x00\x00"
|
||||
"\x09\x00\x00\x00" "TITLE=Foo"
|
||||
"\x0a\x00\x00\x00" "ARTIST=Bar";
|
||||
|
||||
static bool parse_standard()
|
||||
{
|
||||
ot::opus_tags tags;
|
||||
int rc = ot::parse_tags(standard_OpusTags, sizeof(standard_OpusTags) - 1, &tags);
|
||||
if (rc != 0)
|
||||
throw failure("ot::parse_tags did not return 0");
|
||||
if (tags.vendor_length != 20)
|
||||
throw failure("the vendor string length is invalid");
|
||||
if (memcmp(tags.vendor_string, "opustags test packet", 20) != 0)
|
||||
throw failure("the vendor string is invalid");
|
||||
if (tags.count != 2)
|
||||
throw failure("bad number of comments");
|
||||
if (tags.lengths[0] != 9 || tags.lengths[1] != 10)
|
||||
throw failure("bad comment lengths");
|
||||
if (memcmp(tags.comment[0], "TITLE=Foo", tags.lengths[0]) != 0)
|
||||
throw failure("bad title comment");
|
||||
if (memcmp(tags.comment[1], "ARTIST=Bar", tags.lengths[1]) != 0)
|
||||
throw failure("bad artist comment");
|
||||
ot::free_tags(&tags);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "1..1\nok - trivial\n";
|
||||
std::cout << "1..1\n";
|
||||
run(parse_standard, "parse a standard OpusTags packet");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user