From b832feb3894d95a82e88da05bb9fa29c6da26211 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 1 Jan 2017 18:14:22 +0100 Subject: make: added a bunch of tests --- tests/blogc-make/check_atom.c | 154 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 tests/blogc-make/check_atom.c (limited to 'tests/blogc-make/check_atom.c') diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c new file mode 100644 index 0000000..cceec23 --- /dev/null +++ b/tests/blogc-make/check_atom.c @@ -0,0 +1,154 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2015-2016 Rafael G. Martins + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include + +#include +#include + +#include "../../src/blogc-make/atom.h" +#include "../../src/blogc-make/settings.h" +#include "../../src/common/file.h" +#include "../../src/common/error.h" +#include "../../src/common/utils.h" + + +static void +test_atom_file(void **state) +{ + bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); + settings->settings = bc_trie_new(free); + bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); + bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); + bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); + + bc_error_t *err = NULL; + char *rv = bm_atom_deploy(settings, &err); + + assert_non_null(rv); + assert_null(err); + + size_t cmp_len; + char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err); + + assert_non_null(cmp); + assert_null(err); + + assert_string_equal(cmp, + "\n" + "\n" + " {{ SITE_TITLE }}{% ifdef FILTER_TAG %} - " + "{{ FILTER_TAG }}{% endif %}\n" + " {{ BASE_URL }}/atom{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}" + "{% endif %}.xml\n" + " {{ DATE_FIRST_FORMATTED }}\n" + " \n" + " \n" + " \n" + " {{ AUTHOR_NAME }}\n" + " {{ AUTHOR_EMAIL }}\n" + " \n" + " {{ SITE_TAGLINE }}\n" + " {% block listing %}\n" + " \n" + " {{ TITLE }}\n" + " {{ BASE_URL }}/post/{{ FILENAME }}/\n" + " {{ DATE_FORMATTED }}\n" + " {{ DATE_FORMATTED }}\n" + " \n" + " \n" + " {{ AUTHOR_NAME }}\n" + " {{ AUTHOR_EMAIL }}\n" + " \n" + " \n" + " \n" + " {% endblock %}\n" + "\n"); + + free(cmp); + bm_atom_destroy(rv); + free(rv); + bc_trie_free(settings->settings); + free(settings); +} + + +static void +test_atom_dir(void **state) +{ + bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); + settings->settings = bc_trie_new(free); + bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); + bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml")); + bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); + + bc_error_t *err = NULL; + char *rv = bm_atom_deploy(settings, &err); + + assert_non_null(rv); + assert_null(err); + + size_t cmp_len; + char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err); + + assert_non_null(cmp); + assert_null(err); + + assert_string_equal(cmp, + "\n" + "\n" + " {{ SITE_TITLE }}{% ifdef FILTER_TAG %} - " + "{{ FILTER_TAG }}{% endif %}\n" + " {{ BASE_URL }}/atom{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}" + "{% endif %}/index.xml\n" + " {{ DATE_FIRST_FORMATTED }}\n" + " \n" + " \n" + " \n" + " {{ AUTHOR_NAME }}\n" + " {{ AUTHOR_EMAIL }}\n" + " \n" + " {{ SITE_TAGLINE }}\n" + " {% block listing %}\n" + " \n" + " {{ TITLE }}\n" + " {{ BASE_URL }}/post/{{ FILENAME }}/\n" + " {{ DATE_FORMATTED }}\n" + " {{ DATE_FORMATTED }}\n" + " \n" + " \n" + " {{ AUTHOR_NAME }}\n" + " {{ AUTHOR_EMAIL }}\n" + " \n" + " \n" + " \n" + " {% endblock %}\n" + "\n"); + + free(cmp); + bm_atom_destroy(rv); + free(rv); + bc_trie_free(settings->settings); + free(settings); +} + + +int +main(void) +{ + const UnitTest tests[] = { + unit_test(test_atom_file), + unit_test(test_atom_dir), + }; + return run_tests(tests); +} -- cgit v1.2.3-18-g5258