text tests

This commit is contained in:
simon987 2020-04-07 16:50:14 -04:00
parent a0c9d21863
commit f6cd9c42e3
3 changed files with 65 additions and 15 deletions

View File

@ -11,33 +11,63 @@ static scan_arc_ctx_t arc_list_ctx;
static scan_text_ctx_t text_500_ctx;
TEST(TextTest, BookCsvContentLen) {
const char *filepath = "libscan-test-files/test_files/text/books.csv";
TEST(Text, BookCsvContentLen) {
vfile_t f;
document_t doc;
doc.meta_head = nullptr;
doc.meta_tail = nullptr;
load_file(filepath, &f);
load_doc_file("libscan-test-files/test_files/text/books.csv", &f, &doc);
parse_text(&text_500_ctx, &f, &doc);
ASSERT_NEAR(strlen(get_meta(&doc, MetaContent)->str_val), 500, 1);
CLOSE_FILE(f)
destroy_doc(&doc);
cleanup(&doc, &f);
}
TEST(TextTest, MemUtf8_1) {
const char *content = "a"; //todo
TEST(Text, MemUtf8_1) {
const char *content = "a";
vfile_t f;
document_t doc;
doc.meta_head = nullptr;
doc.meta_tail = nullptr;
load_mem((void *) content, strlen(content), &f);
load_doc_mem((void *) content, strlen(content), &f, &doc);
parse_text(&text_500_ctx, &f, &doc);
ASSERT_EQ(strlen(get_meta(&doc, MetaContent)->str_val), 1);
destroy_doc(&doc);
cleanup(&doc, &f);
}
TEST(Text, MemUtf8_Invalid1) {
const char *content = "12345\xE0";
vfile_t f;
document_t doc;
load_doc_mem((void *) content, strlen(content), &f, &doc);
parse_text(&text_500_ctx, &f, &doc);
ASSERT_STREQ(get_meta(&doc, MetaContent)->str_val, "12345");
cleanup(&doc, &f);
}
TEST(Text, MemUtf8_2) {
const char *content = "最後測試";
vfile_t f;
document_t doc;
load_doc_mem((void *) content, strlen(content), &f, &doc);
parse_text(&text_500_ctx, &f, &doc);
ASSERT_STREQ(get_meta(&doc, MetaContent)->str_val, "最後測試");
cleanup(&doc, &f);
}
TEST(Text, MemUtf8_Invalid2) {
const char *content = "最後測\xe8\xa9";
vfile_t f;
document_t doc;
load_doc_mem((void *) content, strlen(content), &f, &doc);
parse_text(&text_500_ctx, &f, &doc);
ASSERT_STREQ(get_meta(&doc, MetaContent)->str_val, "最後測");
cleanup(&doc, &f);
}

View File

@ -32,6 +32,23 @@ void fs_close(vfile_t *f) {
}
}
void load_doc_file(const char *filepath, vfile_t *f, document_t *doc) {
doc->meta_head = nullptr;
doc->meta_tail = nullptr;
load_file(filepath, f);
}
void load_doc_mem(void *mem, size_t mem_len, vfile_t *f, document_t *doc) {
doc->meta_head = nullptr;
doc->meta_tail = nullptr;
load_mem(mem, mem_len, f);
}
void cleanup(document_t *doc, vfile_t *f) {
destroy_doc(doc);
CLOSE_FILE((*f))
}
void load_file(const char *filepath, vfile_t *f) {
stat(filepath, &f->info);
f->fd = open(filepath, O_RDONLY);

View File

@ -5,6 +5,9 @@
void load_file(const char *filepath, vfile_t *f);
void load_mem(void *mem, size_t size, vfile_t *f);
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, ...) {
// noop