From 109c797d7c89223c9eed07dc322448b5c5fe3373 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 25 May 2019 16:52:49 +0200 Subject: Convert to sibs, add curl download, write test --- tests/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/main.c (limited to 'tests') diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..3ba930b --- /dev/null +++ b/tests/main.c @@ -0,0 +1,45 @@ +#include +#include "../include/Program.h" +#include +#include +#include + +typedef struct { + char *data; + size_t size; +} Buffer; + +static int program_output_callback(char *data, int size, void *userdata) { + Buffer *buf = userdata; + size_t new_size = buf->size + size; + buf->data = realloc(buf->data, new_size + 1); + buf->data[new_size] = '\0'; + memcpy(buf->data + buf->size, data, size); + buf->size = new_size; + return 0; +} + +static void html_search_callback(QuickMediaHtmlNode *node, void *userdata) { + const char *href = quickmedia_html_node_get_attribute_value(node, "href"); + QuickMediaStringView text = quickmedia_html_node_get_text(node); + printf("a href: %s, text: %.*s\n", href, text.size, text.data); +} + +int main(int argc, char **argv) { + Buffer buf; + buf.data = NULL; + buf.size = 0; + char *args[] = { "/usr/bin/curl", "-s", "-L", "https://manganelo.com/search/naruto", NULL }; + exec_program(args, program_output_callback, &buf); + /*printf("%s\n", buf.data);*/ + + QuickMediaHtmlSearch html_search; + if(quickmedia_html_search_init(&html_search, buf.data) != 0) + return -1; + if(quickmedia_html_find_nodes_xpath(&html_search, "//h3[class=\"story_name\"]//a", html_search_callback, NULL) != 0) + return -1; + quickmedia_html_search_deinit(&html_search); + + free(buf.data); + return 0; +} -- cgit v1.2.3