aboutsummaryrefslogtreecommitdiff
path: root/tests/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/main.c')
-rw-r--r--tests/main.c33
1 files changed, 33 insertions, 0 deletions
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 <stdio.h>
+#include "../include/quickmedia/HtmlSearch.h"
+#include <assert.h>
+#include <stdlib.h>
+
+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;
+}