support for mobi files simon987/sist2#41

This commit is contained in:
2020-04-09 16:16:01 -04:00
parent 90c4ca3d6e
commit b7a565a1c4
9 changed files with 210 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ extern "C" {
#include "../libscan/ebook/ebook.h"
#include "../libscan/media/media.h"
#include "../libscan/ooxml/ooxml.h"
#include "../libscan/mobi/scan_mobi.h"
#include <libavutil/avutil.h>
}
@@ -22,6 +23,7 @@ static scan_media_ctx_t media_ctx;
static scan_ooxml_ctx_t ooxml_500_ctx;
static scan_mobi_ctx_t mobi_500_ctx;
/* Text */
@@ -298,6 +300,49 @@ TEST(Ooxml, Xlsx1) {
cleanup(&doc, &f);
}
/* Mobi */
TEST(Mobi, Mobi1) {
vfile_t f;
document_t doc;
load_doc_file("libscan-test-files/test_files/mobi/Norse Mythology - Neil Gaiman.mobi", &f, &doc);
parse_mobi(&mobi_500_ctx, &f, &doc);
ASSERT_STREQ(get_meta(&doc, MetaAuthor)->str_val, "Gaiman, Neil");
ASSERT_STREQ(get_meta(&doc, MetaTitle)->str_val, "Norse Mythology");
ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 1);
cleanup(&doc, &f);
}
TEST(Mobi, Azw) {
vfile_t f;
document_t doc;
load_doc_file("libscan-test-files/test_files/mobi/sample.azw", &f, &doc);
parse_mobi(&mobi_500_ctx, &f, &doc);
ASSERT_STREQ(get_meta(&doc, MetaAuthor)->str_val, "Nietzsche, Friedrich");
ASSERT_STREQ(get_meta(&doc, MetaTitle)->str_val, "On the Genealogy of Morality (Hackett Classics)");
ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 1);
cleanup(&doc, &f);
}
TEST(Mobi, Azw3) {
vfile_t f;
document_t doc;
load_doc_file("libscan-test-files/test_files/mobi/sample.azw3", &f, &doc);
parse_mobi(&mobi_500_ctx, &f, &doc);
ASSERT_STREQ(get_meta(&doc, MetaAuthor)->str_val, "George Orwell; Amélie Audiberti");
ASSERT_STREQ(get_meta(&doc, MetaTitle)->str_val, "1984");
ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 1);
cleanup(&doc, &f);
}
int main(int argc, char **argv) {
arc_recurse_ctx.log = noop_log;
arc_recurse_ctx.logf = noop_logf;
@@ -335,6 +380,10 @@ int main(int argc, char **argv) {
ooxml_500_ctx.log = noop_log;
ooxml_500_ctx.logf = noop_logf;
mobi_500_ctx.content_size = 500;
mobi_500_ctx.log = noop_log;
mobi_500_ctx.logf = noop_logf;
av_log_set_level(AV_LOG_QUIET);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();

View File

@@ -9,11 +9,11 @@ void load_doc_mem(void *mem, size_t mem_len, vfile_t *f, document_t *doc);
void load_doc_file(const char *filepath, vfile_t *f, document_t *doc);
void cleanup(document_t *doc, vfile_t *f);
static void noop_logf(char *filepath, int level, char *format, ...) {
static void noop_logf(const char *filepath, int level, char *format, ...) {
// noop
}
static void noop_log(char *filepath, int level, char *str) {
static void noop_log(const char *filepath, int level, char *str) {
// noop
}