diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-24 21:54:27 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-25 22:28:41 +0200 |
commit | e4c08cd44e37f28cd11d62a95f4791ace663c62d (patch) | |
tree | 31336517474147a3f9894c98b040164cc4bb7a9e /tests/blogc-make/check_atom.c | |
parent | 1d6a1510c20794393cc45a71334724aee5bef473 (diff) | |
download | blogc-e4c08cd44e37f28cd11d62a95f4791ace663c62d.tar.gz blogc-e4c08cd44e37f28cd11d62a95f4791ace663c62d.tar.bz2 blogc-e4c08cd44e37f28cd11d62a95f4791ace663c62d.zip |
make: fixed filename generation for rules and atom feed
Diffstat (limited to 'tests/blogc-make/check_atom.c')
-rw-r--r-- | tests/blogc-make/check_atom.c | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c index 43ed93d..ac68e67 100644 --- a/tests/blogc-make/check_atom.c +++ b/tests/blogc-make/check_atom.c @@ -22,13 +22,14 @@ static void -test_atom_empty(void **state) +test_atom_empty_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("")); bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); + bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); bc_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); @@ -48,11 +49,73 @@ test_atom_empty(void **state) " <title type=\"text\">{{ SITE_TITLE }}{% ifdef FILTER_TAG %} - " "{{ FILTER_TAG }}{% endif %}</title>\n" " <id>{{ BASE_URL }}{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}" - "{% endif %}.xml</id>\n" + "{% else %}/index{% endif %}.xml</id>\n" " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n" " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n" " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}{% ifdef FILTER_TAG %}" - "/{{ FILTER_TAG }}{% endif %}.xml\" rel=\"self\" />\n" + "/{{ FILTER_TAG }}{% else %}/index{% endif %}.xml\" rel=\"self\" />\n" + " <author>\n" + " <name>{{ AUTHOR_NAME }}</name>\n" + " <email>{{ AUTHOR_EMAIL }}</email>\n" + " </author>\n" + " <subtitle type=\"text\">{{ SITE_TAGLINE }}</subtitle>\n" + " {% block listing %}\n" + " <entry>\n" + " <title type=\"text\">{{ TITLE }}</title>\n" + " <id>{{ BASE_URL }}/{{ FILENAME }}.html</id>\n" + " <updated>{{ DATE_FORMATTED }}</updated>\n" + " <published>{{ DATE_FORMATTED }}</published>\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/{{ FILENAME }}.html\" />\n" + " <author>\n" + " <name>{{ AUTHOR_NAME }}</name>\n" + " <email>{{ AUTHOR_EMAIL }}</email>\n" + " </author>\n" + " <content type=\"html\"><![CDATA[{{ CONTENT }}]]></content>\n" + " </entry>\n" + " {% endblock %}\n" + "</feed>\n"); + + free(cmp); + bm_atom_destroy(rv); + free(rv); + bc_trie_free(settings->settings); + free(settings); +} + + +static void +test_atom_empty_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("")); + bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml")); + bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); + bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); + + 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, + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" + " <title type=\"text\">{{ SITE_TITLE }}{% ifdef FILTER_TAG %} - " + "{{ FILTER_TAG }}{% endif %}</title>\n" + " <id>{{ BASE_URL }}{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}" + "{% endif %}/index.xml</id>\n" + " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}{% ifdef FILTER_TAG %}" + "/{{ FILTER_TAG }}{% endif %}/index.xml\" rel=\"self\" />\n" " <author>\n" " <name>{{ AUTHOR_NAME }}</name>\n" " <email>{{ AUTHOR_EMAIL }}</email>\n" @@ -61,10 +124,10 @@ test_atom_empty(void **state) " {% block listing %}\n" " <entry>\n" " <title type=\"text\">{{ TITLE }}</title>\n" - " <id>{{ BASE_URL }}/{{ FILENAME }}/</id>\n" + " <id>{{ BASE_URL }}/{{ FILENAME }}/index.html</id>\n" " <updated>{{ DATE_FORMATTED }}</updated>\n" " <published>{{ DATE_FORMATTED }}</published>\n" - " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/{{ FILENAME }}/\" />\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/{{ FILENAME }}/index.html\" />\n" " <author>\n" " <name>{{ AUTHOR_NAME }}</name>\n" " <email>{{ AUTHOR_EMAIL }}</email>\n" @@ -90,6 +153,7 @@ test_atom_file(void **state) 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_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); bc_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); @@ -122,10 +186,10 @@ test_atom_file(void **state) " {% block listing %}\n" " <entry>\n" " <title type=\"text\">{{ TITLE }}</title>\n" - " <id>{{ BASE_URL }}/post/{{ FILENAME }}/</id>\n" + " <id>{{ BASE_URL }}/post/{{ FILENAME }}.html</id>\n" " <updated>{{ DATE_FORMATTED }}</updated>\n" " <published>{{ DATE_FORMATTED }}</published>\n" - " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}/\" />\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}.html\" />\n" " <author>\n" " <name>{{ AUTHOR_NAME }}</name>\n" " <email>{{ AUTHOR_EMAIL }}</email>\n" @@ -151,6 +215,7 @@ test_atom_dir(void **state) 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_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); bc_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); @@ -183,10 +248,10 @@ test_atom_dir(void **state) " {% block listing %}\n" " <entry>\n" " <title type=\"text\">{{ TITLE }}</title>\n" - " <id>{{ BASE_URL }}/post/{{ FILENAME }}/</id>\n" + " <id>{{ BASE_URL }}/post/{{ FILENAME }}/index.html</id>\n" " <updated>{{ DATE_FORMATTED }}</updated>\n" " <published>{{ DATE_FORMATTED }}</published>\n" - " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}/\" />\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}/index.html\" />\n" " <author>\n" " <name>{{ AUTHOR_NAME }}</name>\n" " <email>{{ AUTHOR_EMAIL }}</email>\n" @@ -208,7 +273,8 @@ int main(void) { const UnitTest tests[] = { - unit_test(test_atom_empty), + unit_test(test_atom_empty_file), + unit_test(test_atom_empty_dir), unit_test(test_atom_file), unit_test(test_atom_dir), }; |