From c17412cce925ce226d3835a2e59b4d9f31b5b3ed Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 25 May 2019 02:17:15 +0200 Subject: Initial commit --- tests/main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/main.c (limited to 'tests/main.c') diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..eb1abc7 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,33 @@ +#include +#include "../include/quickmedia/HtmlSearch.h" +#include +#include + +static char* get_file_content(const char *filepath) { + FILE *file = fopen(filepath, "rb"); + assert(file); + + fseek(file, 0, SEEK_END); + size_t filesize = ftell(file); + fseek(file, 0, SEEK_SET); + + char *buffer = malloc(filesize + 1); + buffer[filesize] = '\0'; + fread(buffer, 1, filesize, file); + + return buffer; +} + +static void result_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, node value: %.*s\n", href, text.size, text.data); +} + +int main(int argc, char **argv) +{ + char *file_content = get_file_content("test_files/test.html"); + int result = quickmedia_html_find_nodes_xpath(file_content, "//h3[class=\"story_name\"]//a", result_callback, NULL); + free(file_content); + return result; +} -- cgit v1.2.3