diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-26 22:23:30 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-26 22:23:30 +0200 |
commit | defb396ee51c80d2df1c7bbc58dbefd0c6a0b165 (patch) | |
tree | 4af8d88b10a57cc5c8e18147c6fe0696c2f33867 /tests | |
parent | 69caadbe08b27188ac0ab3bd0e49bf3ee4f8244c (diff) | |
download | blogc-defb396ee51c80d2df1c7bbc58dbefd0c6a0b165.tar.gz blogc-defb396ee51c80d2df1c7bbc58dbefd0c6a0b165.tar.bz2 blogc-defb396ee51c80d2df1c7bbc58dbefd0c6a0b165.zip |
make: added atom_dump helper rule
Diffstat (limited to 'tests')
-rw-r--r-- | tests/blogc-make/check_atom.c | 212 | ||||
-rwxr-xr-x | tests/blogc-make/check_blogc_make.sh.in | 38 |
2 files changed, 250 insertions, 0 deletions
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c index f58f2ba..d04abd3 100644 --- a/tests/blogc-make/check_atom.c +++ b/tests/blogc-make/check_atom.c @@ -22,6 +22,214 @@ static void +test_atom_generate_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")); + + char *cmp = bm_atom_generate(settings); + + assert_non_null(cmp); + + 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 }}" + "{% 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 }}{% 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); + bc_trie_free(settings->settings); + free(settings); +} + + +static void +test_atom_generate_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")); + + char *cmp = bm_atom_generate(settings); + + assert_non_null(cmp); + + 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" + " </author>\n" + " <subtitle type=\"text\">{{ SITE_TAGLINE }}</subtitle>\n" + " {% block listing %}\n" + " <entry>\n" + " <title type=\"text\">{{ TITLE }}</title>\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 }}/index.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); + bc_trie_free(settings->settings); + free(settings); +} + + +static void +test_atom_generate_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_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); + + char *cmp = bm_atom_generate(settings); + + assert_non_null(cmp); + + 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 }}/atom{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}" + "{% endif %}.xml</id>\n" + " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/atom{% ifdef FILTER_TAG %}" + "/{{ FILTER_TAG }}{% 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 }}/post/{{ FILENAME }}.html</id>\n" + " <updated>{{ DATE_FORMATTED }}</updated>\n" + " <published>{{ DATE_FORMATTED }}</published>\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ 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); + bc_trie_free(settings->settings); + free(settings); +} + + +static void +test_atom_generate_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_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); + + char *cmp = bm_atom_generate(settings); + + assert_non_null(cmp); + + 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 }}/atom{% 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 }}/atom{% ifdef FILTER_TAG %}" + "/{{ FILTER_TAG }}{% endif %}/index.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 }}/post/{{ FILENAME }}/index.html</id>\n" + " <updated>{{ DATE_FORMATTED }}</updated>\n" + " <published>{{ DATE_FORMATTED }}</published>\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}/index.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); + bc_trie_free(settings->settings); + free(settings); +} + + +static void test_atom_empty_file(void **state) { bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); @@ -399,6 +607,10 @@ int main(void) { const UnitTest tests[] = { + unit_test(test_atom_generate_empty_file), + unit_test(test_atom_generate_empty_dir), + unit_test(test_atom_generate_file), + unit_test(test_atom_generate_dir), unit_test(test_atom_empty_file), unit_test(test_atom_empty_dir), unit_test(test_atom_file), diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in index 35a7c41..c62cd65 100755 --- a/tests/blogc-make/check_blogc_make.sh.in +++ b/tests/blogc-make/check_blogc_make.sh.in @@ -1639,8 +1639,46 @@ rm "${TEMP}/output.txt" unset OUTPUT_DIR + +### atom_dump rule + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" atom_dump | tee "${TEMP}/atom.xml" + +cat > "${TEMP}/expected-atom-dump.xml" <<EOF +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + <title type="text">{{ SITE_TITLE }}{% ifdef FILTER_TAG %} - {{ FILTER_TAG }}{% endif %}</title> + <id>{{ BASE_URL }}/atoom{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}{% endif %}/index.xml</id> + <updated>{{ DATE_FIRST_FORMATTED }}</updated> + <link href="{{ BASE_DOMAIN }}{{ BASE_URL }}/" /> + <link href="{{ BASE_DOMAIN }}{{ BASE_URL }}/atoom{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}{% endif %}/index.xml" rel="self" /> + <author> + <name>{{ AUTHOR_NAME }}</name> + <email>{{ AUTHOR_EMAIL }}</email> + </author> + <subtitle type="text">{{ SITE_TAGLINE }}</subtitle> + {% block listing %} + <entry> + <title type="text">{{ TITLE }}</title> + <id>{{ BASE_URL }}/poost/{{ FILENAME }}.html</id> + <updated>{{ DATE_FORMATTED }}</updated> + <published>{{ DATE_FORMATTED }}</published> + <link href="{{ BASE_DOMAIN }}{{ BASE_URL }}/poost/{{ FILENAME }}.html" /> + <author> + <name>{{ AUTHOR_NAME }}</name> + <email>{{ AUTHOR_EMAIL }}</email> + </author> + <content type="html"><![CDATA[{{ CONTENT }}]]></content> + </entry> + {% endblock %} +</feed> +EOF +diff -uN "${TEMP}/atom.xml" "${TEMP}/expected-atom-dump.xml" + +rm "${TEMP}/atom.xml" rm -rf "${TEMP}/proj" + ############################################################################### ### empty prefixes with some posts |