aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-05-25 02:17:15 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 06:54:59 +0200
commitc17412cce925ce226d3835a2e59b4d9f31b5b3ed (patch)
treebdef2c8cbbda218f7cb75fbc39e6c786d7dfeaf9 /tests
Initial commit
Diffstat (limited to 'tests')
-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;
+}