diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-05-07 04:43:30 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-05-07 04:43:30 +0200 |
commit | 68e4c6ce2cbcc16f5613a7731d4cfac13e4d3354 (patch) | |
tree | b07274c5478a9058be5eb67e3ba7be293a7c8df5 /tests | |
parent | 4b676a3e0a21d494a1d47efcaf995537b29ff2b9 (diff) | |
parent | 4230e93c64c78ca4276a164704c8dc8a67e466e1 (diff) | |
download | blogc-68e4c6ce2cbcc16f5613a7731d4cfac13e4d3354.tar.gz blogc-68e4c6ce2cbcc16f5613a7731d4cfac13e4d3354.tar.bz2 blogc-68e4c6ce2cbcc16f5613a7731d4cfac13e4d3354.zip |
Merge branch 'master' into feature/directives
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check_content_parser.c | 659 | ||||
-rw-r--r-- | tests/check_error.c | 2 | ||||
-rw-r--r-- | tests/check_loader.c | 545 | ||||
-rw-r--r-- | tests/check_renderer.c | 288 | ||||
-rw-r--r-- | tests/check_source_parser.c | 180 | ||||
-rw-r--r-- | tests/check_template_parser.c | 80 | ||||
-rw-r--r-- | tests/check_utils.c | 524 |
7 files changed, 1372 insertions, 906 deletions
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 165810d..4f201d1 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -17,7 +17,7 @@ #include <string.h> #include "../src/content-parser.h" #include "../src/directives.h" -#include "../src/utils/utils.h" +#include "../src/utils.h" static void @@ -82,6 +82,7 @@ static void test_content_parse(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# um\n" "## dois\n" @@ -107,8 +108,8 @@ test_content_parse(void **state) "1. chunda\n" "3. fuuuu\n" "\n" - "+ chunda2\n" - "+ fuuuu2\n" + "- chunda2\n" + "- fuuuu2\n" "\n" "<style>\n" " chunda\n" @@ -117,9 +118,17 @@ test_content_parse(void **state) "guda\n" "yay\n" "\n" - "**bola**\n", &l); + "**bola**\n" + "-- foo-bar\n" + "--- bar\n" + "\n" + "-- asd\n" + "\n" + "--- lol\n", &l, &d); assert_non_null(html); assert_int_equal(l, 0); + assert_non_null(d); + assert_string_equal(d, "bola"); assert_string_equal(html, "<h1 id=\"um\">um</h1>\n" "<h2 id=\"dois\">dois</h2>\n" @@ -151,8 +160,13 @@ test_content_parse(void **state) "</style>\n" "<p>guda\n" "yay</p>\n" - "<p><strong>bola</strong></p>\n"); + "<p><strong>bola</strong>\n" + "– foo-bar\n" + "— bar</p>\n" + "<p>– asd</p>\n" + "<p>— lol</p>\n"); free(html); + free(d); } @@ -160,6 +174,7 @@ static void test_content_parse_crlf(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# um\r\n" "## dois\r\n" @@ -195,9 +210,17 @@ test_content_parse_crlf(void **state) "guda\r\n" "yay\r\n" "\r\n" - "**bola**\r\n", &l); + "**bola**\r\n" + "-- foo-bar\r\n" + "--- bar\r\n" + "\r\n" + "-- asd\r\n" + "\r\n" + "--- lol\r\n", &l, &d); assert_non_null(html); assert_int_equal(l, 0); + assert_non_null(d); + assert_string_equal(d, "bola"); assert_string_equal(html, "<h1 id=\"um\">um</h1>\r\n" "<h2 id=\"dois\">dois</h2>\r\n" @@ -229,8 +252,13 @@ test_content_parse_crlf(void **state) "</style>\r\n" "<p>guda\r\n" "yay</p>\r\n" - "<p><strong>bola</strong></p>\r\n"); + "<p><strong>bola</strong>\r\n" + "– foo-bar\r\n" + "— bar</p>\r\n" + "<p>– asd</p>\r\n" + "<p>— lol</p>\r\n"); free(html); + free(d); } @@ -238,6 +266,7 @@ static void test_content_parse_with_excerpt(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# test\n" "\n" @@ -246,9 +275,11 @@ test_content_parse_with_excerpt(void **state) "..\n" "\n" "guda\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 38); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\n" "<p>chunda</p>\n" @@ -256,6 +287,8 @@ test_content_parse_with_excerpt(void **state) "lol</p>\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" @@ -264,15 +297,18 @@ test_content_parse_with_excerpt(void **state) "...\n" "\n" "guda\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 38); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\n" "<p>chunda</p>\n" "<p>guda\n" "lol</p>\n"); free(html); + free(d); } @@ -280,6 +316,7 @@ static void test_content_parse_with_excerpt_crlf(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# test\r\n" "\r\n" @@ -288,9 +325,11 @@ test_content_parse_with_excerpt_crlf(void **state) "..\r\n" "\r\n" "guda\r\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 40); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\r\n" "<p>chunda</p>\r\n" @@ -298,6 +337,8 @@ test_content_parse_with_excerpt_crlf(void **state) "lol</p>\r\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\r\n" "\r\n" @@ -306,26 +347,29 @@ test_content_parse_with_excerpt_crlf(void **state) "...\r\n" "\r\n" "guda\r\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 40); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\r\n" "<p>chunda</p>\r\n" "<p>guda\r\n" "lol</p>\r\n"); free(html); + free(d); } static void test_content_parse_header(void **state) { - char *html = blogc_content_parse("## bola", NULL); + char *html = blogc_content_parse("## bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n"); free(html); - html = blogc_content_parse("## bola\n", NULL); + html = blogc_content_parse("## bola\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n"); free(html); @@ -334,7 +378,7 @@ test_content_parse_header(void **state) "\n" "## bola\n" "\n" - "guda\n", NULL); + "guda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\n" @@ -347,11 +391,11 @@ test_content_parse_header(void **state) static void test_content_parse_header_crlf(void **state) { - char *html = blogc_content_parse("## bola", NULL); + char *html = blogc_content_parse("## bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n"); free(html); - html = blogc_content_parse("## bola\r\n", NULL); + html = blogc_content_parse("## bola\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\r\n"); free(html); @@ -360,7 +404,7 @@ test_content_parse_header_crlf(void **state) "\r\n" "## bola\r\n" "\r\n" - "guda\r\n", NULL); + "guda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\r\n" @@ -373,11 +417,11 @@ test_content_parse_header_crlf(void **state) static void test_content_parse_html(void **state) { - char *html = blogc_content_parse("<div>\n</div>", NULL); + char *html = blogc_content_parse("<div>\n</div>", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<div>\n</div>\n"); free(html); - html = blogc_content_parse("<div>\n</div>\n", NULL); + html = blogc_content_parse("<div>\n</div>\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<div>\n</div>\n"); free(html); @@ -387,7 +431,7 @@ test_content_parse_html(void **state) "<div>\n" "</div>\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\n" @@ -400,11 +444,11 @@ test_content_parse_html(void **state) static void test_content_parse_html_crlf(void **state) { - char *html = blogc_content_parse("<div>\r\n</div>", NULL); + char *html = blogc_content_parse("<div>\r\n</div>", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<div>\r\n</div>\r\n"); free(html); - html = blogc_content_parse("<div>\r\n</div>\r\n", NULL); + html = blogc_content_parse("<div>\r\n</div>\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<div>\r\n</div>\r\n"); free(html); @@ -414,7 +458,7 @@ test_content_parse_html_crlf(void **state) "<div>\r\n" "</div>\r\n" "\r\n" - "chunda\r\n", NULL); + "chunda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\r\n" @@ -427,14 +471,14 @@ test_content_parse_html_crlf(void **state) static void test_content_parse_blockquote(void **state) { - char *html = blogc_content_parse("> bola\n> guda", NULL); + char *html = blogc_content_parse("> bola\n> guda", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<blockquote><p>bola\n" "guda</p>\n" "</blockquote>\n"); free(html); - html = blogc_content_parse("> bola\n> guda\n", NULL); + html = blogc_content_parse("> bola\n> guda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<blockquote><p>bola\n" @@ -445,9 +489,22 @@ test_content_parse_blockquote(void **state) "bola\n" "\n" "> bola\n" + "\n" + "chunda\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "<p>bola</p>\n" + "<blockquote><p>bola</p>\n" + "</blockquote>\n" + "<p>chunda</p>\n"); + free(html); + html = blogc_content_parse( + "bola\n" + "\n" + "> bola\n" "> guda\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\n" @@ -462,14 +519,14 @@ test_content_parse_blockquote(void **state) static void test_content_parse_blockquote_crlf(void **state) { - char *html = blogc_content_parse("> bola\r\n> guda", NULL); + char *html = blogc_content_parse("> bola\r\n> guda", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<blockquote><p>bola\r\n" "guda</p>\r\n" "</blockquote>\r\n"); free(html); - html = blogc_content_parse("> bola\r\n> guda\r\n", NULL); + html = blogc_content_parse("> bola\r\n> guda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<blockquote><p>bola\r\n" @@ -480,9 +537,22 @@ test_content_parse_blockquote_crlf(void **state) "bola\r\n" "\r\n" "> bola\r\n" + "\r\n" + "chunda\r\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "<p>bola</p>\r\n" + "<blockquote><p>bola</p>\r\n" + "</blockquote>\r\n" + "<p>chunda</p>\r\n"); + free(html); + html = blogc_content_parse( + "bola\r\n" + "\r\n" + "> bola\r\n" "> guda\r\n" "\r\n" - "chunda\r\n", NULL); + "chunda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\r\n" @@ -497,13 +567,13 @@ test_content_parse_blockquote_crlf(void **state) static void test_content_parse_code(void **state) { - char *html = blogc_content_parse(" bola\n guda", NULL); + char *html = blogc_content_parse(" bola\n guda", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<pre><code>bola\n" "guda</code></pre>\n"); free(html); - html = blogc_content_parse(" bola\n guda\n", NULL); + html = blogc_content_parse(" bola\n guda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<pre><code>bola\n" @@ -515,7 +585,7 @@ test_content_parse_code(void **state) " bola\n" " guda\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\n" @@ -529,13 +599,13 @@ test_content_parse_code(void **state) static void test_content_parse_code_crlf(void **state) { - char *html = blogc_content_parse(" bola\r\n guda", NULL); + char *html = blogc_content_parse(" bola\r\n guda", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<pre><code>bola\r\n" "guda</code></pre>\r\n"); free(html); - html = blogc_content_parse(" bola\r\n guda\r\n", NULL); + html = blogc_content_parse(" bola\r\n guda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<pre><code>bola\r\n" @@ -547,7 +617,7 @@ test_content_parse_code_crlf(void **state) " bola\r\n" " guda\r\n" "\r\n" - "chunda\r\n", NULL); + "chunda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\r\n" @@ -561,28 +631,28 @@ test_content_parse_code_crlf(void **state) static void test_content_parse_horizontal_rule(void **state) { - char *html = blogc_content_parse("bola\nguda\n\n**", NULL); + char *html = blogc_content_parse("bola\nguda\n\n**", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\n" "guda</p>\n" "<hr />\n"); free(html); - html = blogc_content_parse("bola\nguda\n\n++++", NULL); + html = blogc_content_parse("bola\nguda\n\n++++", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\n" "guda</p>\n" "<hr />\n"); free(html); - html = blogc_content_parse("bola\nguda\n\n--\n", NULL); + html = blogc_content_parse("bola\nguda\n\n--\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\n" "guda</p>\n" "<hr />\n"); free(html); - html = blogc_content_parse("bola\nguda\n\n****\n", NULL); + html = blogc_content_parse("bola\nguda\n\n****\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\n" @@ -594,7 +664,7 @@ test_content_parse_horizontal_rule(void **state) "\n" "**\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\n" @@ -606,7 +676,7 @@ test_content_parse_horizontal_rule(void **state) "\n" "----\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\n" @@ -619,28 +689,28 @@ test_content_parse_horizontal_rule(void **state) static void test_content_parse_horizontal_rule_crlf(void **state) { - char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL); + char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\r\n" "guda</p>\r\n" "<hr />\r\n"); free(html); - html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL); + html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\r\n" "guda</p>\r\n" "<hr />\r\n"); free(html); - html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL); + html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\r\n" "guda</p>\r\n" "<hr />\r\n"); free(html); - html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL); + html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola\r\n" @@ -652,7 +722,7 @@ test_content_parse_horizontal_rule_crlf(void **state) "\r\n" "**\r\n" "\r\n" - "chunda\r\n", NULL); + "chunda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\r\n" @@ -664,7 +734,7 @@ test_content_parse_horizontal_rule_crlf(void **state) "\r\n" "----\r\n" "\r\n" - "chunda\r\n", NULL); + "chunda\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>bola</p>\r\n" @@ -682,7 +752,7 @@ test_content_parse_unordered_list(void **state) "\n" "* asd\n" "* qwe\n" - "* zxc", NULL); + "* zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -697,7 +767,7 @@ test_content_parse_unordered_list(void **state) "\n" "* asd\n" "* qwe\n" - "* zxc\n", NULL); + "* zxc\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -714,7 +784,7 @@ test_content_parse_unordered_list(void **state) "* qwe\n" "* zxc\n" "\n" - "fuuuu\n", NULL); + "fuuuu\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -734,7 +804,7 @@ test_content_parse_unordered_list(void **state) "* zxc\n" " 1234\n" "\n" - "fuuuu\n", NULL); + "fuuuu\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -750,7 +820,7 @@ test_content_parse_unordered_list(void **state) html = blogc_content_parse( "* asd\n" "* qwe\n" - "* zxc", NULL); + "* zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<ul>\n" @@ -770,7 +840,7 @@ test_content_parse_unordered_list_crlf(void **state) "\r\n" "* asd\r\n" "* qwe\r\n" - "* zxc", NULL); + "* zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -785,7 +855,7 @@ test_content_parse_unordered_list_crlf(void **state) "\r\n" "* asd\r\n" "* qwe\r\n" - "* zxc\r\n", NULL); + "* zxc\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -802,7 +872,7 @@ test_content_parse_unordered_list_crlf(void **state) "* qwe\r\n" "* zxc\r\n" "\r\n" - "fuuuu\r\n", NULL); + "fuuuu\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -822,7 +892,7 @@ test_content_parse_unordered_list_crlf(void **state) "* zxc\r\n" " 1234\r\n" "\r\n" - "fuuuu\r\n", NULL); + "fuuuu\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -838,7 +908,7 @@ test_content_parse_unordered_list_crlf(void **state) html = blogc_content_parse( "* asd\r\n" "* qwe\r\n" - "* zxc", NULL); + "* zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<ul>\r\n" @@ -858,7 +928,7 @@ test_content_parse_ordered_list(void **state) "\n" "1. asd\n" "2. qwe\n" - "3. zxc", NULL); + "3. zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -873,7 +943,7 @@ test_content_parse_ordered_list(void **state) "\n" "1. asd\n" "2. qwe\n" - "3. zxc\n", NULL); + "3. zxc\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -890,7 +960,7 @@ test_content_parse_ordered_list(void **state) "2. qwe\n" "3. zxc\n" "\n" - "fuuuu\n", NULL); + "fuuuu\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -910,7 +980,7 @@ test_content_parse_ordered_list(void **state) "3. zxc\n" " 1234\n" "\n" - "fuuuu\n", NULL); + "fuuuu\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\n" @@ -926,7 +996,7 @@ test_content_parse_ordered_list(void **state) html = blogc_content_parse( "1. asd\n" "2. qwe\n" - "3. zxc", NULL); + "3. zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<ol>\n" @@ -946,7 +1016,7 @@ test_content_parse_ordered_list_crlf(void **state) "\r\n" "1. asd\r\n" "2. qwe\r\n" - "3. zxc", NULL); + "3. zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -961,7 +1031,7 @@ test_content_parse_ordered_list_crlf(void **state) "\r\n" "1. asd\r\n" "2. qwe\r\n" - "3. zxc\r\n", NULL); + "3. zxc\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -978,7 +1048,7 @@ test_content_parse_ordered_list_crlf(void **state) "2. qwe\r\n" "3. zxc\r\n" "\r\n" - "fuuuu\r\n", NULL); + "fuuuu\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -998,7 +1068,7 @@ test_content_parse_ordered_list_crlf(void **state) "3. zxc\r\n" " 1234\r\n" "\r\n" - "fuuuu\r\n", NULL); + "fuuuu\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>lol</p>\r\n" @@ -1014,7 +1084,7 @@ test_content_parse_ordered_list_crlf(void **state) html = blogc_content_parse( "1. asd\r\n" "2. qwe\r\n" - "3. zxc", NULL); + "3. zxc", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<ol>\r\n" @@ -1037,15 +1107,15 @@ __wrap_blogc_directive_loader(blogc_directive_ctx_t *ctx, blogc_error_t **err) assert_null(ctx->argument); else assert_string_equal(ctx->argument, arg); - assert_int_equal(b_trie_size(ctx->params), mock_type(unsigned int)); + assert_int_equal(sb_trie_size(ctx->params), mock_type(unsigned int)); - for (unsigned int i = 0; i < b_trie_size(ctx->params); i++) { + for (unsigned int i = 0; i < sb_trie_size(ctx->params); i++) { const char *key = mock_type(const char*); const char *value = mock_type(const char*); - assert_string_equal(b_trie_lookup(ctx->params, key), value); + assert_string_equal(sb_trie_lookup(ctx->params, key), value); } - return b_strdup("CHUNDA\n"); + return sb_strdup("CHUNDA\n"); } @@ -1057,7 +1127,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); char *html = blogc_content_parse( ".. bola::", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1068,7 +1138,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola::\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1079,7 +1149,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola:: ", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1090,7 +1160,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola:: \n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1101,7 +1171,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola::\r\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1115,7 +1185,7 @@ test_content_parse_directive(void **state) html = blogc_content_parse( ".. bola::\n" " :asd: qwe", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1129,7 +1199,7 @@ test_content_parse_directive(void **state) html = blogc_content_parse( ".. bola::\n" " :asd: qwe\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1143,7 +1213,7 @@ test_content_parse_directive(void **state) html = blogc_content_parse( ".. bola::\r\n" "\t:asd: qwe\r\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1160,7 +1230,7 @@ test_content_parse_directive(void **state) ".. bola::\n" "\t\t:asd: qwe\n" "\t\t:zxc: vbn", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1177,7 +1247,7 @@ test_content_parse_directive(void **state) ".. bola::\n" " :asd: qwe\n" " :zxc: vbn\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1194,7 +1264,7 @@ test_content_parse_directive(void **state) ".. bola::\r\n" " :asd: qwe\r\n" " :zxc: vbn\r\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1217,7 +1287,7 @@ test_content_parse_directive(void **state) " :ert: zxvc\n" " :qwe: bola\n" "\n" - "bola", NULL); + "bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1242,7 +1312,7 @@ test_content_parse_directive(void **state) " :ert: zxvc\r\n" " :qwe: bola\r\n" "\r\n" - "bola", NULL); + "bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1261,7 +1331,7 @@ test_content_parse_directive(void **state) "\n" ".. bola::\n" "\n" - ".. bola::", NULL); + ".. bola::", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1280,7 +1350,7 @@ test_content_parse_directive(void **state) "\n" ".. bola:: asd\n" "\n" - ".. bola:: asd\n", NULL); + ".. bola:: asd\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1299,7 +1369,7 @@ test_content_parse_directive(void **state) "\r\n" ".. bola::\r\n" "\r\n" - ".. bola::\r\n", NULL); + ".. bola::\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1321,7 +1391,7 @@ test_content_parse_directive(void **state) ".. bola::\n" " :asd: qwe\n" "\n" - ".. bola::", NULL); + ".. bola::", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1343,7 +1413,7 @@ test_content_parse_directive(void **state) ".. bola:: asd\n" " :asd: qwe\n" "\n" - ".. bola:: asd\n", NULL); + ".. bola:: asd\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1365,7 +1435,7 @@ test_content_parse_directive(void **state) ".. bola::\n" " :asd: qwe\n" "\n" - ".. bola::\n", NULL); + ".. bola::\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1387,7 +1457,7 @@ test_content_parse_directive(void **state) ".. bola::\r\n" " :asd: qwe\r\n" "\r\n" - ".. bola::\r\n", NULL); + ".. bola::\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1412,7 +1482,7 @@ test_content_parse_directive(void **state) " :asd: qwe\n" "\n" ".. bola::\n" - " :asd: zxc\n", NULL); + " :asd: zxc\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1437,7 +1507,7 @@ test_content_parse_directive(void **state) " :asd: qwe\r\n" "\r\n" ".. bola::\r\n" - " :asd: zxc\r\n", NULL); + " :asd: zxc\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1468,7 +1538,7 @@ test_content_parse_directive(void **state) "\n" ".. bola::\n" " :asd: qwe\n" - " :qwe: 456", NULL); + " :qwe: 456", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1499,7 +1569,7 @@ test_content_parse_directive(void **state) "\n" ".. bola:: asd\n" " :asd: qwe\n" - " :qwe: 456\n", NULL); + " :qwe: 456\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1530,7 +1600,7 @@ test_content_parse_directive(void **state) "\n" ".. bola::\n" " :asd: qwe\n" - " :qwe: 456\n", NULL); + " :qwe: 456\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1561,7 +1631,7 @@ test_content_parse_directive(void **state) "\r\n" ".. bola::\r\n" " :asd: qwe\r\n" - " :qwe: 456\r\n", NULL); + " :qwe: 456\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1574,7 +1644,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola:: chunda", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1585,7 +1655,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola:: chunda\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1596,7 +1666,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, 0); html = blogc_content_parse( ".. bola:: chunda\r\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1610,7 +1680,7 @@ test_content_parse_directive(void **state) html = blogc_content_parse( ".. bola:: chunda\n" " :asd: qwe", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1624,7 +1694,7 @@ test_content_parse_directive(void **state) html = blogc_content_parse( ".. bola:: chunda\n" " :asd: qwe\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1638,7 +1708,7 @@ test_content_parse_directive(void **state) html = blogc_content_parse( ".. bola:: chunda\r\n" " :asd: qwe\r\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1655,7 +1725,7 @@ test_content_parse_directive(void **state) ".. bola:: chunda\n" " :asd: qwe\n" " :zxc: vbn", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1672,7 +1742,7 @@ test_content_parse_directive(void **state) ".. bola:: chunda\n" " :asd: qwe\n" " :zxc: vbn\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1689,7 +1759,7 @@ test_content_parse_directive(void **state) ".. bola:: chunda\r\n" " :asd: qwe\r\n" " :zxc: vbn\r\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "CHUNDA\n"); @@ -1712,7 +1782,7 @@ test_content_parse_directive(void **state) " :ert: zxvc\n" " :qwe: bola\n" "\n" - "bola", NULL); + "bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\n" @@ -1737,7 +1807,7 @@ test_content_parse_directive(void **state) " :ert: zxvc\r\n" " :qwe: bola\r\n" "\r\n" - "bola", NULL); + "bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1773,7 +1843,7 @@ test_content_parse_directive(void **state) " :asd: qwe\r\n" " :ert: zxvc\r\n" "\r\n" - "bola", NULL); + "bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<h1 id=\"foo\">foo</h1>\r\n" @@ -1785,9 +1855,176 @@ test_content_parse_directive(void **state) static void +test_content_parse_description(void **state) +{ + char *d = NULL; + char *html = blogc_content_parse( + "# foo\n" + "\n" + "bar", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\n" + "<p>bar</p>\n"); + assert_non_null(d); + assert_string_equal(d, "bar"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\n" + "\n" + "bar\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\n" + "<p>bar</p>\n"); + assert_non_null(d); + assert_string_equal(d, "bar"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\n" + "\n" + "qwe\n" + "bar\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\n" + "<p>qwe\n" + "bar</p>\n"); + assert_non_null(d); + assert_string_equal(d, "qwe"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\n" + "\n" + "> qwe\n" + "\n" + "bar\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\n" + "<blockquote><p>qwe</p>\n" + "</blockquote>\n" + "<p>bar</p>\n"); + assert_non_null(d); + assert_string_equal(d, "qwe"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\n" + "\n" + "> qwe\n" + "> zxc\n" + "\n" + "bar\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\n" + "<blockquote><p>qwe\n" + "zxc</p>\n" + "</blockquote>\n" + "<p>bar</p>\n"); + assert_non_null(d); + assert_string_equal(d, "qwe"); + free(html); + free(d); +} + + +static void +test_content_parse_description_crlf(void **state) +{ + char *d = NULL; + char *html = blogc_content_parse( + "# foo\r\n" + "\r\n" + "bar", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\r\n" + "<p>bar</p>\r\n"); + assert_non_null(d); + assert_string_equal(d, "bar"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\r\n" + "\r\n" + "bar\r\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\r\n" + "<p>bar</p>\r\n"); + assert_non_null(d); + assert_string_equal(d, "bar"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\r\n" + "\r\n" + "qwe\r\n" + "bar\r\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\r\n" + "<p>qwe\r\n" + "bar</p>\r\n"); + assert_non_null(d); + assert_string_equal(d, "qwe"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\r\n" + "\r\n" + "> qwe\r\n" + "\r\n" + "bar\r\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\r\n" + "<blockquote><p>qwe</p>\r\n" + "</blockquote>\r\n" + "<p>bar</p>\r\n"); + assert_non_null(d); + assert_string_equal(d, "qwe"); + free(html); + free(d); + d = NULL; + html = blogc_content_parse( + "# foo\r\n" + "\r\n" + "> qwe\r\n" + "> zxc\r\n" + "\r\n" + "bar\r\n", NULL, &d); + assert_non_null(html); + assert_string_equal(html, + "<h1 id=\"foo\">foo</h1>\r\n" + "<blockquote><p>qwe\r\n" + "zxc</p>\r\n" + "</blockquote>\r\n" + "<p>bar</p>\r\n"); + assert_non_null(d); + assert_string_equal(d, "qwe"); + free(html); + free(d); +} + + +static void test_content_parse_invalid_excerpt(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# test\n" "\n" @@ -1795,9 +2032,11 @@ test_content_parse_invalid_excerpt(void **state) "..\n" "\n" "guda\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 0); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\n" "<p>chunda\n" @@ -1806,6 +2045,8 @@ test_content_parse_invalid_excerpt(void **state) "lol</p>\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" @@ -1813,9 +2054,11 @@ test_content_parse_invalid_excerpt(void **state) "\n" "...\n" "guda\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 0); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\n" "<p>chunda</p>\n" @@ -1824,15 +2067,19 @@ test_content_parse_invalid_excerpt(void **state) "lol</p>\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" "chunda..\n" "\n" "guda\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 0); + assert_non_null(d); + assert_string_equal(d, "chunda.."); assert_string_equal(html, "<h1 id=\"test\">test</h1>\n" "<p>chunda..</p>\n" @@ -1840,21 +2087,26 @@ test_content_parse_invalid_excerpt(void **state) "lol</p>\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" "chunda\n" "\n" "...guda\n" - "lol", &l); + "lol", &l, &d); assert_non_null(html); assert_int_equal(l, 0); + assert_non_null(d); + assert_string_equal(d, "chunda"); assert_string_equal(html, "<h1 id=\"test\">test</h1>\n" "<p>chunda</p>\n" "<p>...guda\n" "lol</p>\n"); free(html); + free(d); } @@ -1864,7 +2116,7 @@ test_content_parse_invalid_header(void **state) char *html = blogc_content_parse( "asd\n" "\n" - "##bola\n", NULL); + "##bola\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>asd</p>\n" @@ -1881,7 +2133,7 @@ test_content_parse_invalid_header_empty(void **state) "\n" "##\n" "\n" - "qwe\n", NULL); + "qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>asd</p>\n" @@ -1898,7 +2150,7 @@ test_content_parse_invalid_blockquote(void **state) char *html = blogc_content_parse( "> asd\n" "> bola\n" - "> foo\n", NULL); + "> foo\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>> asd\n" @@ -1907,7 +2159,7 @@ test_content_parse_invalid_blockquote(void **state) free(html); html = blogc_content_parse( "> asd\n" - "> bola", NULL); + "> bola", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>> asd\n" @@ -1922,7 +2174,7 @@ test_content_parse_invalid_code(void **state) char *html = blogc_content_parse( " asd\n" " bola\n" - " foo\n", NULL); + " foo\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p> asd\n" @@ -1932,7 +2184,7 @@ test_content_parse_invalid_code(void **state) html = blogc_content_parse( " asd\n" " bola\n" - " foo", NULL); + " foo", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p> asd\n" @@ -1946,11 +2198,11 @@ static void test_content_parse_invalid_horizontal_rule(void **state) { // this generates invalid html, but... - char *html = blogc_content_parse("** asd", NULL); + char *html = blogc_content_parse("** asd", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p><strong> asd</p>\n"); free(html); - html = blogc_content_parse("** asd\n", NULL); + html = blogc_content_parse("** asd\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p><strong> asd</p>\n"); free(html); @@ -1963,7 +2215,7 @@ test_content_parse_invalid_unordered_list(void **state) // more invalid html char *html = blogc_content_parse( "* asd\n" - "1. qwe", NULL); + "1. qwe", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p><em> asd\n" @@ -1972,7 +2224,7 @@ test_content_parse_invalid_unordered_list(void **state) html = blogc_content_parse( "* asd\n" "1. qwe\n" - "\n", NULL); + "\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p><em> asd\n" @@ -1980,7 +2232,7 @@ test_content_parse_invalid_unordered_list(void **state) free(html); html = blogc_content_parse( "* asd\n" - "1. qwe\n", NULL); + "1. qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p><em> asd\n" @@ -1989,7 +2241,7 @@ test_content_parse_invalid_unordered_list(void **state) free(html); html = blogc_content_parse( "* asd\n" - "1. qwe\n", NULL); + "1. qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p><em> asd\n" @@ -2002,7 +2254,7 @@ test_content_parse_invalid_unordered_list(void **state) "* asd\n" "1. qwe\n" "\n" - "poi\n", NULL); + "poi\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>chunda</p>\n" @@ -2019,7 +2271,7 @@ test_content_parse_invalid_ordered_list(void **state) // more invalid html char *html = blogc_content_parse( "1. asd\n" - "* qwe", NULL); + "* qwe", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1. asd\n" @@ -2028,7 +2280,7 @@ test_content_parse_invalid_ordered_list(void **state) html = blogc_content_parse( "1. asd\n" "* qwe\n" - "\n", NULL); + "\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1. asd\n" @@ -2036,7 +2288,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1. asd\n" - "* qwe\n", NULL); + "* qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1. asd\n" @@ -2045,7 +2297,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1. asd\n" - "* qwe\n", NULL); + "* qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1. asd\n" @@ -2058,7 +2310,7 @@ test_content_parse_invalid_ordered_list(void **state) "1. asd\n" "* qwe\n" "\n" - "poi\n", NULL); + "poi\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>chunda</p>\n" @@ -2068,7 +2320,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1 asd\n" - "* qwe\n", NULL); + "* qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1 asd\n" @@ -2076,7 +2328,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "a. asd\n" - "2. qwe\n", NULL); + "2. qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>a. asd\n" @@ -2084,18 +2336,18 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1.\nasd\n" - "2. qwe\n", NULL); + "2. qwe\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1.\n" "asd\n" "2. qwe</p>\n"); free(html); - html = blogc_content_parse("1.\n", NULL); + html = blogc_content_parse("1.\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1.</p>\n"); free(html); - html = blogc_content_parse("1 ", NULL); + html = blogc_content_parse("1 ", NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>1 </p>\n"); free(html); @@ -2107,7 +2359,7 @@ test_content_parse_invalid_directive(void **state) { char *html = blogc_content_parse( ".. ", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. </p>\n"); @@ -2115,7 +2367,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. \n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. </p>\n"); @@ -2123,7 +2375,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. ", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. <br /></p>\n"); @@ -2131,7 +2383,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. \n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. <br /></p>\n"); @@ -2139,7 +2391,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. a", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. a</p>\n"); @@ -2147,7 +2399,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. a\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. a</p>\n"); @@ -2155,7 +2407,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd</p>\n"); @@ -2163,7 +2415,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd</p>\n"); @@ -2171,7 +2423,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd:", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd:</p>\n"); @@ -2179,7 +2431,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd:\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd:</p>\n"); @@ -2188,7 +2440,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2198,7 +2450,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2208,7 +2460,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :a", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2218,7 +2470,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :a\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2228,7 +2480,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :as", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2238,7 +2490,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :as\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2248,7 +2500,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :as:", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2258,7 +2510,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :as:\n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2268,7 +2520,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :as: ", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2278,7 +2530,7 @@ test_content_parse_invalid_directive(void **state) html = blogc_content_parse( ".. asd::\n" " :as: \n", - NULL); + NULL, NULL); assert_non_null(html); assert_string_equal(html, "<p>.. asd::\n" @@ -2304,6 +2556,10 @@ test_content_parse_inline(void **state) assert_non_null(html); assert_string_equal(html, "<em>bola</em>"); free(html); + html = blogc_content_parse_inline("bola!"); + assert_non_null(html); + assert_string_equal(html, "bola!"); + free(html); } @@ -2419,10 +2675,22 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n"); free(html); + html = blogc_content_parse_inline("[bola!](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "<a href=\"http://example.org/\">bola!</a>\n"); + free(html); html = blogc_content_parse_inline("[bola]\n(http://example.org/)\n"); assert_non_null(html); assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n"); free(html); + html = blogc_content_parse_inline("[bola]\r\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n"); + free(html); + html = blogc_content_parse_inline("[bola] \r\n (http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n"); + free(html); html = blogc_content_parse_inline("[bo\nla](http://example.org/)\n"); assert_non_null(html); assert_string_equal(html, "<a href=\"http://example.org/\">bo\nla</a>\n"); @@ -2435,6 +2703,16 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "<a href=\"http://example.org/\"><code>bola(2)[3]**!\\</code></a>\n"); free(html); + html = blogc_content_parse_inline("test suite!)\n" + "depends on [cmocka](http://cmocka.org/), though.\n"); + assert_non_null(html); + assert_string_equal(html, "test suite!)\n" + "depends on <a href=\"http://cmocka.org/\">cmocka</a>, though.\n"); + free(html); + html = blogc_content_parse_inline("asd [bola]chunda(1234)"); + assert_non_null(html); + assert_string_equal(html, "asd [bola]chunda(1234)"); + free(html); // "invalid" html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n"); assert_non_null(html); @@ -2516,6 +2794,42 @@ test_content_parse_inline_image(void **state) assert_non_null(html); assert_string_equal(html, "<img src=\"http://example.org/\" alt=\"bola\">\n"); free(html); + html = blogc_content_parse_inline("![bola]\r\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "<img src=\"http://example.org/\" alt=\"bola\">\n"); + free(html); + html = blogc_content_parse_inline("![bola] \r\n (http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "<img src=\"http://example.org/\" alt=\"bola\">\n"); + free(html); + html = blogc_content_parse_inline( + "[![This is the image alt text](picture.jpg)](https://blogc.rgm.io)"); + assert_non_null(html); + assert_string_equal(html, + "<a href=\"https://blogc.rgm.io\"><img src=\"picture.jpg\" " + "alt=\"This is the image alt text\"></a>"); + free(html); + html = blogc_content_parse_inline( + "[![This is the image alt text]\n" + "(picture.jpg)](https://blogc.rgm.io)"); + assert_non_null(html); + assert_string_equal(html, + "<a href=\"https://blogc.rgm.io\"><img src=\"picture.jpg\" " + "alt=\"This is the image alt text\"></a>"); + free(html); + html = blogc_content_parse_inline( + "[![This is the image alt text]\n" + "(picture.jpg)]\n" + "(https://blogc.rgm.io)"); + assert_non_null(html); + assert_string_equal(html, + "<a href=\"https://blogc.rgm.io\"><img src=\"picture.jpg\" " + "alt=\"This is the image alt text\"></a>"); + free(html); + html = blogc_content_parse_inline("asd ![bola]chunda(1234)"); + assert_non_null(html); + assert_string_equal(html, "asd ![bola]chunda(1234)"); + free(html); // "invalid" html = blogc_content_parse_inline("![bo\nla](http://example.org/)\n"); assert_non_null(html); @@ -2613,6 +2927,36 @@ test_content_parse_inline_line_break_crlf(void **state) } +static void +test_content_parse_inline_endash_emdash(void **state) +{ + char *html = blogc_content_parse_inline("foo -- bar"); + assert_non_null(html); + assert_string_equal(html, "foo – bar"); + free(html); + html = blogc_content_parse_inline("foo --- bar"); + assert_non_null(html); + assert_string_equal(html, "foo — bar"); + free(html); + html = blogc_content_parse_inline("`foo -- bar`"); + assert_non_null(html); + assert_string_equal(html, "<code>foo -- bar</code>"); + free(html); + html = blogc_content_parse_inline("`foo --- bar`"); + assert_non_null(html); + assert_string_equal(html, "<code>foo --- bar</code>"); + free(html); + html = blogc_content_parse_inline("``foo -- bar``"); + assert_non_null(html); + assert_string_equal(html, "<code>foo -- bar</code>"); + free(html); + html = blogc_content_parse_inline("``foo --- bar``"); + assert_non_null(html); + assert_string_equal(html, "<code>foo --- bar</code>"); + free(html); +} + + int main(void) { @@ -2639,6 +2983,8 @@ main(void) unit_test(test_content_parse_ordered_list), unit_test(test_content_parse_ordered_list_crlf), unit_test(test_content_parse_directive), + unit_test(test_content_parse_description), + unit_test(test_content_parse_description_crlf), unit_test(test_content_parse_invalid_excerpt), unit_test(test_content_parse_invalid_header), unit_test(test_content_parse_invalid_header_empty), @@ -2657,6 +3003,7 @@ main(void) unit_test(test_content_parse_inline_image), unit_test(test_content_parse_inline_line_break), unit_test(test_content_parse_inline_line_break_crlf), + unit_test(test_content_parse_inline_endash_emdash), }; return run_tests(tests); } diff --git a/tests/check_error.c b/tests/check_error.c index d3af9c0..8818b00 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -16,7 +16,7 @@ #include <cmocka.h> #include <string.h> #include "../src/error.h" -#include "../src/utils/utils.h" +#include "../src/utils.h" static void diff --git a/tests/check_loader.c b/tests/check_loader.c index ac8bdb3..4a5dc32 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -18,7 +18,7 @@ #include <stdio.h> #include "../src/template-parser.h" #include "../src/loader.h" -#include "../src/utils/utils.h" +#include "../src/utils.h" static void @@ -80,11 +80,11 @@ test_template_parse_from_file(void **state) { blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); - will_return(__wrap_blogc_file_get_contents, b_strdup("{{ BOLA }}\n")); - b_slist_t *l = blogc_template_parse_from_file("bola", &err); + will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n")); + sb_slist_t *l = blogc_template_parse_from_file("bola", &err); assert_null(err); assert_non_null(l); - assert_int_equal(b_slist_length(l), 2); + assert_int_equal(sb_slist_length(l), 2); blogc_template_free_stmts(l); } @@ -95,7 +95,7 @@ test_template_parse_from_file_null(void **state) blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, NULL); - b_slist_t *l = blogc_template_parse_from_file("bola", &err); + sb_slist_t *l = blogc_template_parse_from_file("bola", &err); assert_null(err); assert_null(l); } @@ -106,20 +106,21 @@ test_source_parse_from_file(void **state) { blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "--------\n" "bola")); - b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); + sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_trie_size(t), 5); - assert_string_equal(b_trie_lookup(t, "ASD"), "123"); - assert_string_equal(b_trie_lookup(t, "FILENAME"), "bola"); - assert_string_equal(b_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(t, "CONTENT"), "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola"); - b_trie_free(t); + assert_int_equal(sb_trie_size(t), 6); + assert_string_equal(sb_trie_lookup(t, "ASD"), "123"); + assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola"); + assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n"); + assert_string_equal(sb_trie_lookup(t, "CONTENT"), "<p>bola</p>\n"); + assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola"); + assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola"); + sb_trie_free(t); } @@ -129,7 +130,7 @@ test_source_parse_from_file_null(void **state) blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, NULL); - b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); + sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); assert_null(err); assert_null(t); } @@ -139,41 +140,41 @@ static void test_source_parse_from_files(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - b_trie_t *c = b_trie_new(free); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 3); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 4); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola3"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 4); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -181,45 +182,45 @@ static void test_source_parse_from_files_filter_by_tag(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "TAGS: chunda\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "TAGS: bola, chunda\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_TAG", b_strdup("chunda")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 5); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 5); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -227,77 +228,77 @@ static void test_source_parse_from_files_filter_by_page(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7891\n" "DATE: 2004-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola5.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7892\n" "DATE: 2005-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola6.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7893\n" "DATE: 2006-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola7.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - s = b_slist_append(s, b_strdup("bola4.txt")); - s = b_slist_append(s, b_strdup("bola5.txt")); - s = b_slist_append(s, b_strdup("bola6.txt")); - s = b_slist_append(s, b_strdup("bola7.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_PAGE", b_strdup("1")); - b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + s = sb_slist_append(s, sb_strdup("bola4.txt")); + s = sb_slist_append(s, sb_strdup("bola5.txt")); + s = sb_slist_append(s, sb_strdup("bola6.txt")); + s = sb_slist_append(s, sb_strdup("bola7.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1")); + sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 10); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 10); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -305,78 +306,78 @@ static void test_source_parse_from_files_filter_by_page2(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7891\n" "DATE: 2004-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola5.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7892\n" "DATE: 2005-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola6.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7893\n" "DATE: 2006-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola7.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - s = b_slist_append(s, b_strdup("bola4.txt")); - s = b_slist_append(s, b_strdup("bola5.txt")); - s = b_slist_append(s, b_strdup("bola6.txt")); - s = b_slist_append(s, b_strdup("bola7.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_PAGE", b_strdup("3")); - b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + s = sb_slist_append(s, sb_strdup("bola4.txt")); + s = sb_slist_append(s, sb_strdup("bola5.txt")); + s = sb_slist_append(s, sb_strdup("bola6.txt")); + s = sb_slist_append(s, sb_strdup("bola7.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_PAGE", sb_strdup("3")); + sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 11); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola6"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "3"); - assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "3"); - assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "4"); - assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 11); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola6"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "3"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "3"); + assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "4"); + assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -384,77 +385,77 @@ static void test_source_parse_from_files_filter_by_page3(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7891\n" "DATE: 2004-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola5.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7892\n" "DATE: 2005-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola6.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7893\n" "DATE: 2006-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola7.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - s = b_slist_append(s, b_strdup("bola4.txt")); - s = b_slist_append(s, b_strdup("bola5.txt")); - s = b_slist_append(s, b_strdup("bola6.txt")); - s = b_slist_append(s, b_strdup("bola7.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_PAGE", b_strdup("1")); - b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + s = sb_slist_append(s, sb_strdup("bola4.txt")); + s = sb_slist_append(s, sb_strdup("bola5.txt")); + s = sb_slist_append(s, sb_strdup("bola6.txt")); + s = sb_slist_append(s, sb_strdup("bola7.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1")); + sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 10); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 10); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -462,84 +463,84 @@ static void test_source_parse_from_files_filter_by_page_and_tag(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "TAGS: chunda\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "TAGS: chunda bola\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7891\n" "DATE: 2004-02-03 04:05:06\n" "TAGS: bola\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola5.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7892\n" "DATE: 2005-02-03 04:05:06\n" "TAGS: chunda\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola6.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7893\n" "DATE: 2006-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola7.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" "TAGS: yay chunda\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - s = b_slist_append(s, b_strdup("bola4.txt")); - s = b_slist_append(s, b_strdup("bola5.txt")); - s = b_slist_append(s, b_strdup("bola6.txt")); - s = b_slist_append(s, b_strdup("bola7.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_TAG", b_strdup("chunda")); - b_trie_insert(c, "FILTER_PAGE", b_strdup("2")); - b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + s = sb_slist_append(s, sb_strdup("bola4.txt")); + s = sb_slist_append(s, sb_strdup("bola5.txt")); + s = sb_slist_append(s, sb_strdup("bola6.txt")); + s = sb_slist_append(s, sb_strdup("bola7.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda")); + sb_trie_insert(c, "FILTER_PAGE", sb_strdup("2")); + sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 11); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola7"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda"); - assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "2"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 11); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola7"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "2"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -547,77 +548,77 @@ static void test_source_parse_from_files_filter_by_page_invalid(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7891\n" "DATE: 2004-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola5.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7892\n" "DATE: 2005-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola6.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7893\n" "DATE: 2006-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola7.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - s = b_slist_append(s, b_strdup("bola4.txt")); - s = b_slist_append(s, b_strdup("bola5.txt")); - s = b_slist_append(s, b_strdup("bola6.txt")); - s = b_slist_append(s, b_strdup("bola7.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_PAGE", b_strdup("-1")); - b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + s = sb_slist_append(s, sb_strdup("bola4.txt")); + s = sb_slist_append(s, sb_strdup("bola5.txt")); + s = sb_slist_append(s, sb_strdup("bola6.txt")); + s = sb_slist_append(s, sb_strdup("bola7.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_PAGE", sb_strdup("-1")); + sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 10); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); - assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); - assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "-1"); - assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2"); - assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); - assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 10); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "-1"); + assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2"); + assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -625,64 +626,64 @@ static void test_source_parse_from_files_filter_by_page_invalid2(void **state) { will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "DATE: 2001-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7891\n" "DATE: 2004-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola5.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7892\n" "DATE: 2005-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola6.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7893\n" "DATE: 2006-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola7.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - s = b_slist_append(s, b_strdup("bola4.txt")); - s = b_slist_append(s, b_strdup("bola5.txt")); - s = b_slist_append(s, b_strdup("bola6.txt")); - s = b_slist_append(s, b_strdup("bola7.txt")); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "FILTER_PAGE", b_strdup("5")); - b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + s = sb_slist_append(s, sb_strdup("bola4.txt")); + s = sb_slist_append(s, sb_strdup("bola5.txt")); + s = sb_slist_append(s, sb_strdup("bola6.txt")); + s = sb_slist_append(s, sb_strdup("bola7.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "FILTER_PAGE", sb_strdup("5")); + sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2")); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_null(t); - b_trie_free(c); - b_slist_free_full(s, free); + sb_trie_free(c); + sb_slist_free_full(s, free); } @@ -695,39 +696,39 @@ test_source_parse_from_files_without_all_dates(void **state) "file, but not for all source files. This means that you may get wrong " "values for 'DATE_FIRST' and 'DATE_LAST' variables.\n"); will_return(__wrap_blogc_file_get_contents, "bola1.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola2.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 456\n" "DATE: 2002-02-03 04:05:06\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola3.txt"); - will_return(__wrap_blogc_file_get_contents, b_strdup( + will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); blogc_error_t *err = NULL; - b_slist_t *s = NULL; - s = b_slist_append(s, b_strdup("bola1.txt")); - s = b_slist_append(s, b_strdup("bola2.txt")); - s = b_slist_append(s, b_strdup("bola3.txt")); - b_trie_t *c = b_trie_new(free); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_strdup("bola1.txt")); + s = sb_slist_append(s, sb_strdup("bola2.txt")); + s = sb_slist_append(s, sb_strdup("bola3.txt")); + sb_trie_t *c = sb_trie_new(free); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_non_null(t); - assert_int_equal(b_slist_length(t), 3); // it is enough, no need to look at the items - assert_int_equal(b_trie_size(c), 3); - assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); - assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola3"); - assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06"); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items + assert_int_equal(sb_trie_size(c), 3); + assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3"); + assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06"); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } @@ -735,16 +736,16 @@ static void test_source_parse_from_files_null(void **state) { blogc_error_t *err = NULL; - b_slist_t *s = NULL; - b_trie_t *c = b_trie_new(free); - b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + sb_slist_t *s = NULL; + sb_trie_t *c = sb_trie_new(free); + sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); assert_null(err); assert_null(t); - assert_int_equal(b_slist_length(t), 0); - assert_int_equal(b_trie_size(c), 0); - b_trie_free(c); - b_slist_free_full(s, free); - b_slist_free_full(t, (b_free_func_t) b_trie_free); + assert_int_equal(sb_slist_length(t), 0); + assert_int_equal(sb_trie_size(c), 0); + sb_trie_free(c); + sb_slist_free_full(s, free); + sb_slist_free_full(t, (sb_free_func_t) sb_trie_free); } diff --git a/tests/check_renderer.c b/tests/check_renderer.c index d6bc947..13e7309 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -19,10 +19,10 @@ #include "../src/renderer.h" #include "../src/source-parser.h" #include "../src/template-parser.h" -#include "../src/utils/utils.h" +#include "../src/utils.h" -static b_slist_t* +static sb_slist_t* create_sources(unsigned int count) { const char *s[] = { @@ -47,12 +47,12 @@ create_sources(unsigned int count) }; assert_false(count > 3); blogc_error_t *err = NULL; - b_slist_t *l = NULL; + sb_slist_t *l = NULL; for (unsigned int i = 0; i < count; i++) { - l = b_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err)); + l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err)); assert_null(err); } - assert_int_equal(b_slist_length(l), count); + assert_int_equal(sb_slist_length(l), count); return l; } @@ -79,10 +79,10 @@ test_render_entry(void **state) "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -104,7 +104,7 @@ test_render_entry(void **state) "lol foo haha lol bar haha lol baz haha \n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -126,10 +126,10 @@ test_render_listing(void **state) "{% foreach TAGS_ASD %}yay{% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(3); + sb_slist_t *s = create_sources(3); assert_non_null(s); char *out = blogc_render(l, s, NULL, true); assert_string_equal(out, @@ -153,7 +153,7 @@ test_render_listing(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -174,7 +174,7 @@ test_render_listing_empty(void **state) "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); char *out = blogc_render(l, NULL, NULL, true); @@ -201,10 +201,10 @@ test_render_ifdef(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -212,7 +212,7 @@ test_render_ifdef(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -230,10 +230,10 @@ test_render_ifdef2(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -243,7 +243,7 @@ test_render_ifdef2(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -261,10 +261,10 @@ test_render_ifdef3(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -276,7 +276,7 @@ test_render_ifdef3(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -294,10 +294,10 @@ test_render_ifndef(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -309,7 +309,7 @@ test_render_ifndef(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -328,10 +328,10 @@ test_render_if_eq(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -344,7 +344,7 @@ test_render_if_eq(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -363,10 +363,10 @@ test_render_if_neq(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -379,7 +379,7 @@ test_render_if_neq(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -398,10 +398,10 @@ test_render_if_lt(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -414,7 +414,7 @@ test_render_if_lt(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -433,10 +433,10 @@ test_render_if_gt(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -449,7 +449,7 @@ test_render_if_gt(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -470,10 +470,10 @@ test_render_if_lt_eq(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -488,7 +488,7 @@ test_render_if_lt_eq(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -509,10 +509,10 @@ test_render_if_gt_eq(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -527,7 +527,7 @@ test_render_if_gt_eq(void **state) "\n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -540,10 +540,10 @@ test_render_foreach(void **state) "{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -551,7 +551,7 @@ test_render_foreach(void **state) " foo bar baz \n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -565,10 +565,10 @@ test_render_foreach_if(void **state) "{% endif %} {% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); char *out = blogc_render(l, s, NULL, false); assert_string_equal(out, @@ -576,7 +576,7 @@ test_render_foreach_if(void **state) " bar \n" "\n"); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -596,21 +596,21 @@ test_render_outside_block(void **state) "{{ BOLA }}\n" "{% ifndef CHUNDA %}lol{% endif %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "GUDA", b_strdup("asd")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "GUDA", sb_strdup("asd")); char *out = blogc_render(l, s, c, false); assert_string_equal(out, "bola\n" "\n" "lol\n"); - b_trie_free(c); + sb_trie_free(c); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -629,14 +629,14 @@ test_render_prefer_local_variable(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); - b_trie_t *c = b_trie_new(free); - b_trie_insert(c, "GUDA", b_strdup("hehe")); - b_trie_insert(c, "LOL", b_strdup("hmm")); + sb_trie_t *c = sb_trie_new(free); + sb_trie_insert(c, "GUDA", sb_strdup("hehe")); + sb_trie_insert(c, "LOL", sb_strdup("hmm")); char *out = blogc_render(l, s, c, false); assert_string_equal(out, "\n" @@ -647,9 +647,9 @@ test_render_prefer_local_variable(void **state) "\n" "\n" "\n"); - b_trie_free(c); + sb_trie_free(c); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -665,12 +665,12 @@ test_render_respect_variable_scope(void **state) "{% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = create_sources(1); + sb_slist_t *s = create_sources(1); assert_non_null(s); - b_trie_t *c = b_trie_new(free); + sb_trie_t *c = sb_trie_new(free); char *out = blogc_render(l, s, c, false); assert_string_equal(out, "\n" @@ -679,9 +679,9 @@ test_render_respect_variable_scope(void **state) "\n" "asd\n" "\n"); - b_trie_free(c); + sb_trie_free(c); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -697,22 +697,22 @@ test_render_ifcount_bug(void **state) "{% endif %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - b_slist_t *s = NULL; - s = b_slist_append(s, b_trie_new(free)); - b_trie_insert(s->data, "TITLE", b_strdup("bola")); - b_trie_t *c = b_trie_new(free); + sb_slist_t *s = NULL; + s = sb_slist_append(s, sb_trie_new(free)); + sb_trie_insert(s->data, "TITLE", sb_strdup("bola")); + sb_trie_t *c = sb_trie_new(free); char *out = blogc_render(l, s, c, false); assert_string_equal(out, "\n" "<h3>bola</h3>\n" "\n" "\n"); - b_trie_free(c); + sb_trie_free(c); blogc_template_free_stmts(l); - b_slist_free_full(s, (b_free_func_t) b_trie_free); + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); free(out); } @@ -720,112 +720,112 @@ test_render_ifcount_bug(void **state) static void test_get_variable(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "NAME", b_strdup("bola")); - b_trie_insert(g, "TITLE", b_strdup("bola2")); - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "NAME", b_strdup("chunda")); - b_trie_insert(l, "TITLE", b_strdup("chunda2")); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "NAME", sb_strdup("bola")); + sb_trie_insert(g, "TITLE", sb_strdup("bola2")); + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "NAME", sb_strdup("chunda")); + sb_trie_insert(l, "TITLE", sb_strdup("chunda2")); assert_string_equal(blogc_get_variable("NAME", g, l), "chunda"); assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2"); assert_null(blogc_get_variable("BOLA", g, l)); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_get_variable_only_local(void **state) { - b_trie_t *g = NULL; - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "NAME", b_strdup("chunda")); - b_trie_insert(l, "TITLE", b_strdup("chunda2")); + sb_trie_t *g = NULL; + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "NAME", sb_strdup("chunda")); + sb_trie_insert(l, "TITLE", sb_strdup("chunda2")); assert_string_equal(blogc_get_variable("NAME", g, l), "chunda"); assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2"); assert_null(blogc_get_variable("BOLA", g, l)); - b_trie_free(l); + sb_trie_free(l); } static void test_get_variable_only_global(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "NAME", b_strdup("bola")); - b_trie_insert(g, "TITLE", b_strdup("bola2")); - b_trie_t *l = NULL; + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "NAME", sb_strdup("bola")); + sb_trie_insert(g, "TITLE", sb_strdup("bola2")); + sb_trie_t *l = NULL; assert_string_equal(blogc_get_variable("NAME", g, l), "bola"); assert_string_equal(blogc_get_variable("TITLE", g, l), "bola2"); assert_null(blogc_get_variable("BOLA", g, l)); - b_trie_free(g); + sb_trie_free(g); } static void test_format_date(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %M")); - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "DATE_FORMAT", b_strdup("%R")); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M")); + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "DATE_FORMAT", sb_strdup("%R")); char *date = blogc_format_date("2015-01-02 03:04:05", g, l); assert_string_equal(date, "03:04"); free(date); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_format_date_with_global_format(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %M")); - b_trie_t *l = b_trie_new(free); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M")); + sb_trie_t *l = sb_trie_new(free); char *date = blogc_format_date("2015-01-02 03:04:05", g, l); assert_string_equal(date, "03 -- 04"); free(date); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_format_date_without_format(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_t *l = b_trie_new(free); + sb_trie_t *g = sb_trie_new(free); + sb_trie_t *l = sb_trie_new(free); char *date = blogc_format_date("2015-01-02 03:04:05", g, l); assert_string_equal(date, "2015-01-02 03:04:05"); free(date); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_format_date_without_date(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_t *l = b_trie_new(free); + sb_trie_t *g = sb_trie_new(free); + sb_trie_t *l = sb_trie_new(free); char *date = blogc_format_date(NULL, g, l); assert_null(date); free(date); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_format_variable(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "NAME", b_strdup("bola")); - b_trie_insert(g, "TITLE", b_strdup("bola2")); - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "NAME", b_strdup("chunda")); - b_trie_insert(l, "TITLE", b_strdup("chunda2")); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "NAME", sb_strdup("bola")); + sb_trie_insert(g, "TITLE", sb_strdup("bola2")); + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "NAME", sb_strdup("chunda")); + sb_trie_insert(l, "TITLE", sb_strdup("chunda2")); char *tmp = blogc_format_variable("NAME", g, l, NULL); assert_string_equal(tmp, "chunda"); free(tmp); @@ -833,37 +833,37 @@ test_format_variable(void **state) assert_string_equal(tmp, "chunda2"); free(tmp); assert_null(blogc_format_variable("BOLA", g, l, NULL)); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_format_variable_with_date(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "DATE", b_strdup("2010-11-12 13:14:15")); - b_trie_insert(g, "DATE_FORMAT", b_strdup("%R")); - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "DATE", b_strdup("2011-12-13 14:15:16")); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "DATE", sb_strdup("2010-11-12 13:14:15")); + sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%R")); + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "DATE", sb_strdup("2011-12-13 14:15:16")); char *tmp = blogc_format_variable("DATE_FORMATTED", g, l, NULL); assert_string_equal(tmp, "14:15"); free(tmp); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } static void test_format_variable_foreach(void **state) { - b_slist_t *l = NULL; - l = b_slist_append(l, b_strdup("asd")); - l = b_slist_append(l, b_strdup("qwe")); + sb_slist_t *l = NULL; + l = sb_slist_append(l, sb_strdup("asd")); + l = sb_slist_append(l, sb_strdup("qwe")); char *tmp = blogc_format_variable("FOREACH_ITEM", NULL, NULL, l->next); assert_string_equal(tmp, "qwe"); free(tmp); - b_slist_free_full(l, free); + sb_slist_free_full(l, free); } @@ -877,31 +877,31 @@ test_format_variable_foreach_empty(void **state) static void test_split_list_variable(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "TAGS", b_strdup("asd lol hehe")); - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "TAGS", b_strdup("asd lol XD")); - b_slist_t *tmp = blogc_split_list_variable("TAGS", g, l); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe")); + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD")); + sb_slist_t *tmp = blogc_split_list_variable("TAGS", g, l); assert_string_equal(tmp->data, "asd"); assert_string_equal(tmp->next->data, "lol"); assert_string_equal(tmp->next->next->data, "XD"); - b_slist_free_full(tmp, free); - b_trie_free(g); - b_trie_free(l); + sb_slist_free_full(tmp, free); + sb_trie_free(g); + sb_trie_free(l); } static void test_split_list_variable_not_found(void **state) { - b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "TAGS", b_strdup("asd lol hehe")); - b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "TAGS", b_strdup("asd lol XD")); - b_slist_t *tmp = blogc_split_list_variable("TAG", g, l); + sb_trie_t *g = sb_trie_new(free); + sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe")); + sb_trie_t *l = sb_trie_new(free); + sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD")); + sb_slist_t *tmp = blogc_split_list_variable("TAG", g, l); assert_null(tmp); - b_trie_free(g); - b_trie_free(l); + sb_trie_free(g); + sb_trie_free(l); } diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 8d6c039..d94dc70 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -17,7 +17,7 @@ #include <string.h> #include "../src/source-parser.h" #include "../src/error.h" -#include "../src/utils/utils.h" +#include "../src/utils.h" static void @@ -31,23 +31,24 @@ test_source_parse(void **state) "\n" "bola\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(b_trie_size(source), 5); - assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd"); - assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); - assert_string_equal(b_trie_lookup(source, "EXCERPT"), + assert_int_equal(sb_trie_size(source), 6); + assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd"); + assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda"); + assert_string_equal(sb_trie_lookup(source, "EXCERPT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\n" "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\n" "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), + assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"), "# This is a test\n" "\n" "bola\n"); - b_trie_free(source); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); + sb_trie_free(source); } @@ -62,23 +63,24 @@ test_source_parse_crlf(void **state) "\r\n" "bola\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(b_trie_size(source), 5); - assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd"); - assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); - assert_string_equal(b_trie_lookup(source, "EXCERPT"), + assert_int_equal(sb_trie_size(source), 6); + assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd"); + assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda"); + assert_string_equal(sb_trie_lookup(source, "EXCERPT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\r\n" "<p>bola</p>\r\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\r\n" "<p>bola</p>\r\n"); - assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), + assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"), "# This is a test\r\n" "\r\n" "bola\r\n"); - b_trie_free(source); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); + sb_trie_free(source); } @@ -95,23 +97,24 @@ test_source_parse_with_spaces(void **state) "\n" "bola\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(b_trie_size(source), 5); - assert_string_equal(b_trie_lookup(source, "VAR1"), "chunda"); - assert_string_equal(b_trie_lookup(source, "BOLA"), "guda"); - assert_string_equal(b_trie_lookup(source, "EXCERPT"), + assert_int_equal(sb_trie_size(source), 6); + assert_string_equal(sb_trie_lookup(source, "VAR1"), "chunda"); + assert_string_equal(sb_trie_lookup(source, "BOLA"), "guda"); + assert_string_equal(sb_trie_lookup(source, "EXCERPT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\n" "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\n" "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), + assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"), "# This is a test\n" "\n" "bola\n"); - b_trie_free(source); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); + sb_trie_free(source); } @@ -131,21 +134,21 @@ test_source_parse_with_excerpt(void **state) "guda\n" "yay"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(b_trie_size(source), 5); - assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd"); - assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); - assert_string_equal(b_trie_lookup(source, "EXCERPT"), + assert_int_equal(sb_trie_size(source), 6); + assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd"); + assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda"); + assert_string_equal(sb_trie_lookup(source, "EXCERPT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\n" "<p>bola</p>\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "<h1 id=\"this-is-a-test\">This is a test</h1>\n" "<p>bola</p>\n" "<p>guda\n" "yay</p>\n"); - assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), + assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"), "# This is a test\n" "\n" "bola\n" @@ -154,7 +157,41 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"); - b_trie_free(source); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); + sb_trie_free(source); +} + + +static void +test_source_parse_with_description(void **state) +{ + const char *a = + "VAR1: asd asd\n" + "VAR2: 123chunda\n" + "DESCRIPTION: huehuehuebrbr\n" + "----------\n" + "# This is a test\n" + "\n" + "bola\n"; + blogc_error_t *err = NULL; + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); + assert_null(err); + assert_non_null(source); + assert_int_equal(sb_trie_size(source), 6); + assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd"); + assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda"); + assert_string_equal(sb_trie_lookup(source, "EXCERPT"), + "<h1 id=\"this-is-a-test\">This is a test</h1>\n" + "<p>bola</p>\n"); + assert_string_equal(sb_trie_lookup(source, "CONTENT"), + "<h1 id=\"this-is-a-test\">This is a test</h1>\n" + "<p>bola</p>\n"); + assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"), + "# This is a test\n" + "\n" + "bola\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr"); + sb_trie_free(source); } @@ -163,13 +200,13 @@ test_source_parse_config_empty(void **state) { const char *a = ""; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your source file is empty."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -178,14 +215,14 @@ test_source_parse_config_invalid_key(void **state) { const char *a = "bola: guda"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Can't find a configuration key or the content separator.\n" "Error occurred near line 1, position 1: bola: guda"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -194,14 +231,14 @@ test_source_parse_config_no_key(void **state) { const char *a = "BOLa"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid configuration key.\n" "Error occurred near line 1, position 4: BOLa"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -210,14 +247,14 @@ test_source_parse_config_no_key2(void **state) { const char *a = "BOLA"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your last configuration key is missing ':' and the value\n" "Error occurred near line 1, position 5: BOLA"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -226,7 +263,7 @@ test_source_parse_config_no_value(void **state) { const char *a = "BOLA:\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -234,7 +271,7 @@ test_source_parse_config_no_value(void **state) "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -243,7 +280,7 @@ test_source_parse_config_no_value2(void **state) { const char *a = "BOLA:"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -251,7 +288,7 @@ test_source_parse_config_no_value2(void **state) "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -260,7 +297,7 @@ test_source_parse_config_reserved_name(void **state) { const char *a = "FILENAME: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -268,7 +305,7 @@ test_source_parse_config_reserved_name(void **state) "'FILENAME' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -277,7 +314,7 @@ test_source_parse_config_reserved_name2(void **state) { const char *a = "CONTENT: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -285,7 +322,7 @@ test_source_parse_config_reserved_name2(void **state) "'CONTENT' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -294,7 +331,7 @@ test_source_parse_config_reserved_name3(void **state) { const char *a = "DATE_FORMATTED: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -302,7 +339,7 @@ test_source_parse_config_reserved_name3(void **state) "'DATE_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -311,7 +348,7 @@ test_source_parse_config_reserved_name4(void **state) { const char *a = "DATE_FIRST_FORMATTED: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -319,7 +356,7 @@ test_source_parse_config_reserved_name4(void **state) "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -328,7 +365,7 @@ test_source_parse_config_reserved_name5(void **state) { const char *a = "DATE_LAST_FORMATTED: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -336,7 +373,7 @@ test_source_parse_config_reserved_name5(void **state) "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -345,7 +382,7 @@ test_source_parse_config_reserved_name6(void **state) { const char *a = "PAGE_FIRST: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -353,7 +390,7 @@ test_source_parse_config_reserved_name6(void **state) "'PAGE_FIRST' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -362,7 +399,7 @@ test_source_parse_config_reserved_name7(void **state) { const char *a = "PAGE_PREVIOUS: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -370,7 +407,7 @@ test_source_parse_config_reserved_name7(void **state) "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -379,7 +416,7 @@ test_source_parse_config_reserved_name8(void **state) { const char *a = "PAGE_CURRENT: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -387,7 +424,7 @@ test_source_parse_config_reserved_name8(void **state) "'PAGE_CURRENT' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -396,7 +433,7 @@ test_source_parse_config_reserved_name9(void **state) { const char *a = "PAGE_NEXT: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -404,7 +441,7 @@ test_source_parse_config_reserved_name9(void **state) "'PAGE_NEXT' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -413,7 +450,7 @@ test_source_parse_config_reserved_name10(void **state) { const char *a = "PAGE_LAST: asd\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -421,7 +458,7 @@ test_source_parse_config_reserved_name10(void **state) "'PAGE_LAST' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -430,7 +467,7 @@ test_source_parse_config_reserved_name11(void **state) { const char *a = "BLOGC_VERSION: 1.0\r\n"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -438,7 +475,7 @@ test_source_parse_config_reserved_name11(void **state) "'BLOGC_VERSION' variable is forbidden in source files. It will be set " "for you by the compiler."); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -447,7 +484,7 @@ test_source_parse_config_value_no_line_ending(void **state) { const char *a = "BOLA: asd"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -455,7 +492,7 @@ test_source_parse_config_value_no_line_ending(void **state) "No line ending after the configuration value for 'BOLA'.\n" "Error occurred near line 1, position 10: BOLA: asd"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -464,7 +501,7 @@ test_source_parse_invalid_separator(void **state) { const char *a = "BOLA: asd\n---#"; blogc_error_t *err = NULL; - b_trie_t *source = blogc_source_parse(a, strlen(a), &err); + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); @@ -472,7 +509,7 @@ test_source_parse_invalid_separator(void **state) "Invalid content separator. Must be more than one '-' characters.\n" "Error occurred near line 2, position 4: ---#"); blogc_error_free(err); - b_trie_free(source); + sb_trie_free(source); } @@ -484,6 +521,7 @@ main(void) unit_test(test_source_parse_crlf), unit_test(test_source_parse_with_spaces), unit_test(test_source_parse_with_excerpt), + unit_test(test_source_parse_with_description), unit_test(test_source_parse_config_empty), unit_test(test_source_parse_config_invalid_key), unit_test(test_source_parse_config_no_key), diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index f655896..40a09be 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -17,11 +17,11 @@ #include <string.h> #include "../src/template-parser.h" #include "../src/error.h" -#include "../src/utils/utils.h" +#include "../src/utils.h" static void -blogc_assert_template_stmt(b_slist_t *l, const char *value, +blogc_assert_template_stmt(sb_slist_t *l, const char *value, const blogc_template_stmt_type_t type) { blogc_template_stmt_t *stmt = l->data; @@ -34,7 +34,7 @@ blogc_assert_template_stmt(b_slist_t *l, const char *value, static void -blogc_assert_template_if_stmt(b_slist_t *l, const char *variable, +blogc_assert_template_if_stmt(sb_slist_t *l, const char *variable, blogc_template_stmt_operator_t operator, const char *operand) { blogc_template_stmt_t *stmt = l->data; @@ -64,7 +64,7 @@ test_template_parse(void **state) "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); blogc_assert_template_stmt(stmts, "Test", @@ -81,7 +81,7 @@ test_template_parse(void **state) BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); - b_slist_t *tmp = stmts->next->next->next->next->next->next->next; + sb_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); blogc_assert_template_stmt(tmp->next, "\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); @@ -144,7 +144,7 @@ test_template_parse_crlf(void **state) "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); blogc_assert_template_stmt(stmts, "Test", @@ -161,7 +161,7 @@ test_template_parse_crlf(void **state) BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); - b_slist_t *tmp = stmts->next->next->next->next->next->next->next; + sb_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); blogc_assert_template_stmt(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); @@ -232,7 +232,7 @@ test_template_parse_html(void **state) " </body>\n" "</html>\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); blogc_assert_template_stmt(stmts, "<html>\n <head>\n ", @@ -251,7 +251,7 @@ test_template_parse_html(void **state) "\n ", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next->next->next->next->next->next->next, "listing_once", BLOGC_TEMPLATE_BLOCK_STMT); - b_slist_t *tmp = stmts->next->next->next->next->next->next->next->next; + sb_slist_t *tmp = stmts->next->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "\n <title>My cool blog - Main page</title>\n ", BLOGC_TEMPLATE_CONTENT_STMT); @@ -342,7 +342,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state) "{{ BOLA }}\n" "{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); blogc_assert_template_stmt(stmts, "GUDA", BLOGC_TEMPLATE_IFDEF_STMT); @@ -358,7 +358,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state) BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "CHUNDA", BLOGC_TEMPLATE_IFNDEF_STMT); - b_slist_t *tmp = stmts->next->next->next->next->next->next->next; + sb_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "CHUNDA", BLOGC_TEMPLATE_VARIABLE_STMT); blogc_assert_template_stmt(tmp->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(tmp->next->next, "\n", @@ -373,7 +373,7 @@ test_template_parse_invalid_block_start(void **state) { const char *a = "{% ASD %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -411,7 +411,7 @@ test_template_parse_invalid_block_nested(void **state) "{% block entry %}\n" "{% block listing %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -429,7 +429,7 @@ test_template_parse_invalid_foreach_nested(void **state) "{% foreach A %}\n" "{% foreach B %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -445,7 +445,7 @@ test_template_parse_invalid_block_not_open(void **state) { const char *a = "{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -461,7 +461,7 @@ test_template_parse_invalid_endif_not_open(void **state) { const char *a = "{% block listing %}{% endif %}{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -478,7 +478,7 @@ test_template_parse_invalid_endforeach_not_open(void **state) { const char *a = "{% endforeach %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -494,7 +494,7 @@ test_template_parse_invalid_block_name(void **state) { const char *a = "{% chunda %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -511,7 +511,7 @@ test_template_parse_invalid_block_type_start(void **state) { const char *a = "{% block ENTRY %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -527,7 +527,7 @@ test_template_parse_invalid_block_type(void **state) { const char *a = "{% block chunda %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -543,7 +543,7 @@ test_template_parse_invalid_ifdef_start(void **state) { const char *a = "{% block entry %}{% ifdef guda %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -560,7 +560,7 @@ test_template_parse_invalid_foreach_start(void **state) { const char *a = "{% block entry %}{% foreach guda %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -577,7 +577,7 @@ test_template_parse_invalid_ifdef_variable(void **state) { const char *a = "{% block entry %}{% ifdef BoLA %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -594,7 +594,7 @@ test_template_parse_invalid_ifdef_variable2(void **state) { const char *a = "{% block entry %}{% ifdef 0123 %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -611,7 +611,7 @@ test_template_parse_invalid_foreach_variable(void **state) { const char *a = "{% block entry %}{% foreach BoLA %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -628,7 +628,7 @@ test_template_parse_invalid_foreach_variable2(void **state) { const char *a = "{% block entry %}{% foreach 0123 %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -645,7 +645,7 @@ test_template_parse_invalid_if_operator(void **state) { const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -662,7 +662,7 @@ test_template_parse_invalid_if_operand(void **state) { const char *a = "{% block entry %}{% if BOLA == asd %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -679,7 +679,7 @@ test_template_parse_invalid_if_operand2(void **state) { const char *a = "{% block entry %}{% if BOLA == \"asd %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -696,7 +696,7 @@ test_template_parse_invalid_if_operand3(void **state) { const char *a = "{% block entry %}{% if BOLA == 0123 %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -713,7 +713,7 @@ test_template_parse_invalid_block_end(void **state) { const char *a = "{% block entry }}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -729,7 +729,7 @@ test_template_parse_invalid_variable_name(void **state) { const char *a = "{% block entry %}{{ bola }}{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -746,7 +746,7 @@ test_template_parse_invalid_variable_name2(void **state) { const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -763,7 +763,7 @@ test_template_parse_invalid_variable_name3(void **state) { const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -780,7 +780,7 @@ test_template_parse_invalid_variable_end(void **state) { const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -797,7 +797,7 @@ test_template_parse_invalid_close(void **state) { const char *a = "{% block entry %%\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -813,7 +813,7 @@ test_template_parse_invalid_close2(void **state) { const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -830,7 +830,7 @@ test_template_parse_invalid_if_not_closed(void **state) { const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -845,7 +845,7 @@ test_template_parse_invalid_block_not_closed(void **state) { const char *a = "{% block entry %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); @@ -859,7 +859,7 @@ test_template_parse_invalid_foreach_not_closed(void **state) { const char *a = "{% foreach ASD %}\n"; blogc_error_t *err = NULL; - b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); diff --git a/tests/check_utils.c b/tests/check_utils.c index a511dda..6a6ceca 100644 --- a/tests/check_utils.c +++ b/tests/check_utils.c @@ -13,38 +13,58 @@ #include <stdlib.h> -#include "../src/utils/utils.h" +#include "../src/utils.h" + +#define SB_STRING_CHUNK_SIZE 128 static void test_slist_append(void **state) { - b_slist_t *l = NULL; - l = b_slist_append(l, (void*) b_strdup("bola")); + sb_slist_t *l = NULL; + l = sb_slist_append(l, (void*) sb_strdup("bola")); assert_non_null(l); assert_string_equal(l->data, "bola"); assert_null(l->next); - l = b_slist_append(l, (void*) b_strdup("guda")); + l = sb_slist_append(l, (void*) sb_strdup("guda")); assert_non_null(l); assert_string_equal(l->data, "bola"); assert_non_null(l->next); assert_string_equal(l->next->data, "guda"); assert_null(l->next->next); - b_slist_free_full(l, free); + sb_slist_free_full(l, free); +} + + +static void +test_slist_prepend(void **state) +{ + sb_slist_t *l = NULL; + l = sb_slist_prepend(l, (void*) sb_strdup("bola")); + assert_non_null(l); + assert_string_equal(l->data, "bola"); + assert_null(l->next); + l = sb_slist_prepend(l, (void*) sb_strdup("guda")); + assert_non_null(l); + assert_string_equal(l->data, "guda"); + assert_non_null(l->next); + assert_string_equal(l->next->data, "bola"); + assert_null(l->next->next); + sb_slist_free_full(l, free); } static void test_slist_free(void **state) { - b_slist_t *l = NULL; - char *t1 = b_strdup("bola"); - char *t2 = b_strdup("guda"); - char *t3 = b_strdup("chunda"); - l = b_slist_append(l, (void*) t1); - l = b_slist_append(l, (void*) t2); - l = b_slist_append(l, (void*) t3); - b_slist_free(l); + sb_slist_t *l = NULL; + char *t1 = sb_strdup("bola"); + char *t2 = sb_strdup("guda"); + char *t3 = sb_strdup("chunda"); + l = sb_slist_append(l, (void*) t1); + l = sb_slist_append(l, (void*) t2); + l = sb_slist_append(l, (void*) t3); + sb_slist_free(l); assert_string_equal(t1, "bola"); assert_string_equal(t2, "guda"); assert_string_equal(t3, "chunda"); @@ -57,22 +77,23 @@ test_slist_free(void **state) static void test_slist_length(void **state) { - b_slist_t *l = NULL; - l = b_slist_append(l, (void*) b_strdup("bola")); - l = b_slist_append(l, (void*) b_strdup("guda")); - l = b_slist_append(l, (void*) b_strdup("chunda")); - assert_int_equal(b_slist_length(l), 3); - b_slist_free_full(l, free); + sb_slist_t *l = NULL; + l = sb_slist_append(l, (void*) sb_strdup("bola")); + l = sb_slist_append(l, (void*) sb_strdup("guda")); + l = sb_slist_append(l, (void*) sb_strdup("chunda")); + assert_int_equal(sb_slist_length(l), 3); + sb_slist_free_full(l, free); + assert_int_equal(sb_slist_length(NULL), 0); } static void test_strdup(void **state) { - char *str = b_strdup("bola"); + char *str = sb_strdup("bola"); assert_string_equal(str, "bola"); free(str); - str = b_strdup(NULL); + str = sb_strdup(NULL); assert_null(str); } @@ -80,16 +101,16 @@ test_strdup(void **state) static void test_strndup(void **state) { - char *str = b_strndup("bolaguda", 4); + char *str = sb_strndup("bolaguda", 4); assert_string_equal(str, "bola"); free(str); - str = b_strndup("bolaguda", 30); + str = sb_strndup("bolaguda", 30); assert_string_equal(str, "bolaguda"); free(str); - str = b_strndup("bolaguda", 8); + str = sb_strndup("bolaguda", 8); assert_string_equal(str, "bolaguda"); free(str); - str = b_strdup(NULL); + str = sb_strdup(NULL); assert_null(str); } @@ -97,10 +118,10 @@ test_strndup(void **state) static void test_strdup_printf(void **state) { - char *str = b_strdup_printf("bola"); + char *str = sb_strdup_printf("bola"); assert_string_equal(str, "bola"); free(str); - str = b_strdup_printf("bola, %s", "guda"); + str = sb_strdup_printf("bola, %s", "guda"); assert_string_equal(str, "bola, guda"); free(str); } @@ -109,140 +130,146 @@ test_strdup_printf(void **state) static void test_str_starts_with(void **state) { - assert_true(b_str_starts_with("bolaguda", "bola")); - assert_true(b_str_starts_with("bola", "bola")); - assert_false(b_str_starts_with("gudabola", "bola")); - assert_false(b_str_starts_with("guda", "bola")); - assert_false(b_str_starts_with("bola", "bolaguda")); + assert_true(sb_str_starts_with("bolaguda", "bola")); + assert_true(sb_str_starts_with("bola", "bola")); + assert_false(sb_str_starts_with("gudabola", "bola")); + assert_false(sb_str_starts_with("guda", "bola")); + assert_false(sb_str_starts_with("bola", "bolaguda")); } static void test_str_ends_with(void **state) { - assert_true(b_str_ends_with("bolaguda", "guda")); - assert_true(b_str_ends_with("bola", "bola")); - assert_false(b_str_ends_with("gudabola", "guda")); - assert_false(b_str_ends_with("guda", "bola")); - assert_false(b_str_ends_with("bola", "gudabola")); + assert_true(sb_str_ends_with("bolaguda", "guda")); + assert_true(sb_str_ends_with("bola", "bola")); + assert_false(sb_str_ends_with("gudabola", "guda")); + assert_false(sb_str_ends_with("guda", "bola")); + assert_false(sb_str_ends_with("bola", "gudabola")); } static void test_str_lstrip(void **state) { - char *str = b_strdup(" \tbola\n \t"); - assert_string_equal(b_str_lstrip(str), "bola\n \t"); + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_lstrip(str), "bola\n \t"); free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_lstrip(str), "guda"); + str = sb_strdup("guda"); + assert_string_equal(sb_str_lstrip(str), "guda"); free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_lstrip(str), ""); + str = sb_strdup("\n"); + assert_string_equal(sb_str_lstrip(str), ""); free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_lstrip(str), ""); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_lstrip(str), ""); free(str); - str = b_strdup(""); - assert_string_equal(b_str_lstrip(str), ""); + str = sb_strdup(""); + assert_string_equal(sb_str_lstrip(str), ""); free(str); - assert_null(b_str_lstrip(NULL)); + assert_null(sb_str_lstrip(NULL)); } static void test_str_rstrip(void **state) { - char *str = b_strdup(" \tbola\n \t"); - assert_string_equal(b_str_rstrip(str), " \tbola"); + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_rstrip(str), " \tbola"); free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_rstrip(str), "guda"); + str = sb_strdup("guda"); + assert_string_equal(sb_str_rstrip(str), "guda"); free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_rstrip(str), ""); + str = sb_strdup("\n"); + assert_string_equal(sb_str_rstrip(str), ""); free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_rstrip(str), ""); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_rstrip(str), ""); free(str); - str = b_strdup(""); - assert_string_equal(b_str_rstrip(str), ""); + str = sb_strdup(""); + assert_string_equal(sb_str_rstrip(str), ""); free(str); - assert_null(b_str_rstrip(NULL)); + assert_null(sb_str_rstrip(NULL)); } static void test_str_strip(void **state) { - char *str = b_strdup(" \tbola\n \t"); - assert_string_equal(b_str_strip(str), "bola"); + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_strip(str), "bola"); free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_strip(str), "guda"); + str = sb_strdup("guda"); + assert_string_equal(sb_str_strip(str), "guda"); free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_strip(str), ""); + str = sb_strdup("\n"); + assert_string_equal(sb_str_strip(str), ""); free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_strip(str), ""); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_strip(str), ""); free(str); - str = b_strdup(""); - assert_string_equal(b_str_strip(str), ""); + str = sb_strdup(""); + assert_string_equal(sb_str_strip(str), ""); free(str); - assert_null(b_str_strip(NULL)); + assert_null(sb_str_strip(NULL)); } static void test_str_split(void **state) { - char **strv = b_str_split("bola:guda:chunda", ':', 0); + char **strv = sb_str_split("bola:guda:chunda", ':', 0); assert_string_equal(strv[0], "bola"); assert_string_equal(strv[1], "guda"); assert_string_equal(strv[2], "chunda"); assert_null(strv[3]); - b_strv_free(strv); - strv = b_str_split("bola:guda:chunda", ':', 2); + sb_strv_free(strv); + strv = sb_str_split("bola:guda:chunda", ':', 2); assert_string_equal(strv[0], "bola"); assert_string_equal(strv[1], "guda:chunda"); assert_null(strv[2]); - b_strv_free(strv); - strv = b_str_split("bola:guda:chunda", ':', 1); + sb_strv_free(strv); + strv = sb_str_split("bola:guda:chunda", ':', 1); assert_string_equal(strv[0], "bola:guda:chunda"); assert_null(strv[1]); - b_strv_free(strv); - strv = b_str_split("", ':', 1); + sb_strv_free(strv); + strv = sb_str_split("", ':', 1); assert_null(strv[0]); - b_strv_free(strv); - assert_null(b_str_split(NULL, ':', 0)); + sb_strv_free(strv); + assert_null(sb_str_split(NULL, ':', 0)); } static void test_str_replace(void **state) { - char *str = b_str_replace("bolao", 'o', "zaz"); + char *str = sb_str_replace("bolao", 'o', "zaz"); assert_string_equal(str, "bzazlazaz"); free(str); - str = b_str_replace("bolao", 'b', "zaz"); + str = sb_str_replace("bolao", 'b', "zaz"); assert_string_equal(str, "zazolao"); free(str); + str = sb_str_replace("bolao", 'b', NULL); + assert_string_equal(str, "bolao"); + free(str); + assert_null(sb_str_replace(NULL, 'b', "zaz")); } static void test_strv_join(void **state) { - const char *pieces[] = {"guda","bola", "chunda", NULL}; - char *str = b_strv_join(pieces, ":"); + char *pieces[] = {"guda","bola", "chunda", NULL}; + char *str = sb_strv_join(pieces, ":"); assert_string_equal(str, "guda:bola:chunda"); free(str); - const char *pieces2[] = {NULL}; - str = b_strv_join(pieces2, ":"); + char *pieces2[] = {NULL}; + str = sb_strv_join(pieces2, ":"); assert_string_equal(str, ""); free(str); - assert_null(b_strv_join(NULL, ":")); + assert_null(sb_strv_join(pieces, NULL)); + assert_null(sb_strv_join(NULL, ":")); + assert_null(sb_strv_join(NULL, NULL)); } @@ -250,68 +277,88 @@ static void test_strv_length(void **state) { char *pieces[] = {"guda","bola", "chunda", NULL}; - assert_int_equal(b_strv_length(pieces), 3); + assert_int_equal(sb_strv_length(pieces), 3); char *pieces2[] = {NULL}; - assert_int_equal(b_strv_length(pieces2), 0); - assert_int_equal(b_strv_length(NULL), 0); + assert_int_equal(sb_strv_length(pieces2), 0); + assert_int_equal(sb_strv_length(NULL), 0); } static void test_string_new(void **state) { - b_string_t *str = b_string_new(); + sb_string_t *str = sb_string_new(); assert_non_null(str); assert_string_equal(str->str, ""); assert_int_equal(str->len, 0); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); } static void test_string_free(void **state) { - b_string_t *str = b_string_new(); + sb_string_t *str = sb_string_new(); free(str->str); - str->str = b_strdup("bola"); + str->str = sb_strdup("bola"); str->len = 4; - str->allocated_len = B_STRING_CHUNK_SIZE; - char *tmp = b_string_free(str, false); + str->allocated_len = SB_STRING_CHUNK_SIZE; + char *tmp = sb_string_free(str, false); assert_string_equal(tmp, "bola"); free(tmp); + assert_null(sb_string_free(NULL, false)); +} + + +static void +test_string_dup(void **state) +{ + sb_string_t *str = sb_string_new(); + free(str->str); + str->str = sb_strdup("bola"); + str->len = 4; + str->allocated_len = SB_STRING_CHUNK_SIZE; + sb_string_t *new = sb_string_dup(str); + assert_non_null(new); + assert_string_equal(new->str, "bola"); + assert_int_equal(new->len, 4); + assert_int_equal(new->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(new, true)); + assert_null(sb_string_free(str, true)); + assert_null(sb_string_dup(NULL)); } static void test_string_append_len(void **state) { - b_string_t *str = b_string_new(); - str = b_string_append_len(str, "guda", 4); + sb_string_t *str = sb_string_new(); + str = sb_string_append_len(str, "guda", 4); assert_non_null(str); assert_string_equal(str->str, "guda"); assert_int_equal(str->len, 4); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); - str = b_string_new(); - str = b_string_append_len(str, "guda", 4); - str = b_string_append_len(str, "bola", 4); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append_len(str, "guda", 4); + str = sb_string_append_len(str, "bola", 4); assert_non_null(str); assert_string_equal(str->str, "gudabola"); assert_int_equal(str->len, 8); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); - str = b_string_new(); - str = b_string_append_len(str, "guda", 3); - str = b_string_append_len(str, "bola", 4); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append_len(str, "guda", 3); + str = sb_string_append_len(str, "bola", 4); assert_non_null(str); assert_string_equal(str->str, "gudbola"); assert_int_equal(str->len, 7); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); - str = b_string_new(); - str = b_string_append_len(str, "guda", 4); - str = b_string_append_len(str, + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append_len(str, "guda", 4); + str = sb_string_append_len(str, "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" @@ -321,8 +368,8 @@ test_string_append_len(void **state) "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); - str = b_string_append_len(str, NULL, 0); - str = b_string_append_len(str, + str = sb_string_append_len(str, NULL, 0); + str = sb_string_append_len(str, "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" @@ -353,32 +400,40 @@ test_string_append_len(void **state) "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" "fkeannglvsxprqzfekdinssqymtfexf"); assert_int_equal(str->len, 1204); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10); - assert_null(b_string_free(str, true)); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE * 10); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append_len(str, NULL, 0); + assert_non_null(str); + assert_string_equal(str->str, ""); + assert_int_equal(str->len, 0); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + assert_null(sb_string_append_len(NULL, "foo", 3)); } static void test_string_append(void **state) { - b_string_t *str = b_string_new(); - str = b_string_append(str, "guda"); + sb_string_t *str = sb_string_new(); + str = sb_string_append(str, "guda"); assert_non_null(str); assert_string_equal(str->str, "guda"); assert_int_equal(str->len, 4); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); - str = b_string_new(); - str = b_string_append(str, "guda"); - str = b_string_append(str, "bola"); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append(str, "guda"); + str = sb_string_append(str, "bola"); assert_non_null(str); assert_string_equal(str->str, "gudabola"); assert_int_equal(str->len, 8); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); - str = b_string_new(); - str = b_string_append(str, "guda"); - str = b_string_append(str, + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append(str, "guda"); + str = sb_string_append(str, "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" @@ -388,8 +443,8 @@ test_string_append(void **state) "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); - str = b_string_append(str, NULL); - str = b_string_append(str, + str = sb_string_append(str, NULL); + str = sb_string_append(str, "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" @@ -420,18 +475,27 @@ test_string_append(void **state) "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" "fkeannglvsxprqzfekdinssqymtfexf"); assert_int_equal(str->len, 1204); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10); - assert_null(b_string_free(str, true)); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE * 10); + assert_null(sb_string_free(str, true)); + str = sb_string_new(); + str = sb_string_append(str, NULL); + assert_non_null(str); + assert_string_equal(str->str, ""); + assert_int_equal(str->len, 0); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + assert_null(sb_string_append(NULL, "asd")); + assert_null(sb_string_append(NULL, NULL)); } static void test_string_append_c(void **state) { - b_string_t *str = b_string_new(); - str = b_string_append_len(str, "guda", 4); + sb_string_t *str = sb_string_new(); + str = sb_string_append_len(str, "guda", 4); for (int i = 0; i < 600; i++) - str = b_string_append_c(str, 'c'); + str = sb_string_append_c(str, 'c'); assert_non_null(str); assert_string_equal(str->str, "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" @@ -444,41 +508,43 @@ test_string_append_c(void **state) "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" "cccccccccccccccccccccccccccccccccccccccccccccccccccc"); assert_int_equal(str->len, 604); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 5); - assert_null(b_string_free(str, true)); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE * 5); + assert_null(sb_string_free(str, true)); + assert_null(sb_string_append_c(NULL, 0)); } static void test_string_append_printf(void **state) { - b_string_t *str = b_string_new(); - str = b_string_append_printf(str, "guda: %s %d", "bola", 1); + sb_string_t *str = sb_string_new(); + str = sb_string_append_printf(str, "guda: %s %d", "bola", 1); assert_non_null(str); assert_string_equal(str->str, "guda: bola 1"); assert_int_equal(str->len, 12); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE); - assert_null(b_string_free(str, true)); + assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); + assert_null(sb_string_append_printf(NULL, "asd")); } static void test_trie_new(void **state) { - b_trie_t *trie = b_trie_new(free); + sb_trie_t *trie = sb_trie_new(free); assert_non_null(trie); assert_null(trie->root); assert_true(trie->free_func == free); - b_trie_free(trie); + sb_trie_free(trie); } static void test_trie_insert(void **state) { - b_trie_t *trie = b_trie_new(free); + sb_trie_t *trie = sb_trie_new(free); - b_trie_insert(trie, "bola", b_strdup("guda")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); assert_true(trie->root->key == 'b'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'o'); @@ -491,7 +557,7 @@ test_trie_insert(void **state) assert_string_equal(trie->root->child->child->child->child->data, "guda"); - b_trie_insert(trie, "chu", b_strdup("nda")); + sb_trie_insert(trie, "chu", sb_strdup("nda")); assert_true(trie->root->key == 'b'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'o'); @@ -513,7 +579,7 @@ test_trie_insert(void **state) assert_string_equal(trie->root->next->child->child->child->data, "nda"); - b_trie_insert(trie, "bote", b_strdup("aba")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); assert_true(trie->root->key == 'b'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'o'); @@ -542,7 +608,7 @@ test_trie_insert(void **state) assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); - b_trie_insert(trie, "bo", b_strdup("haha")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); assert_true(trie->root->key == 'b'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'o'); @@ -573,12 +639,12 @@ test_trie_insert(void **state) assert_true(trie->root->child->child->next->next->key == '\0'); assert_string_equal(trie->root->child->child->next->next->data, "haha"); - b_trie_free(trie); + sb_trie_free(trie); - trie = b_trie_new(free); + trie = sb_trie_new(free); - b_trie_insert(trie, "chu", b_strdup("nda")); + sb_trie_insert(trie, "chu", sb_strdup("nda")); assert_true(trie->root->key == 'c'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'h'); @@ -589,7 +655,7 @@ test_trie_insert(void **state) assert_string_equal(trie->root->child->child->child->data, "nda"); - b_trie_insert(trie, "bola", b_strdup("guda")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); assert_true(trie->root->key == 'c'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'h'); @@ -611,7 +677,7 @@ test_trie_insert(void **state) assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - b_trie_insert(trie, "bote", b_strdup("aba")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); assert_true(trie->root->key == 'c'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'h'); @@ -640,7 +706,7 @@ test_trie_insert(void **state) assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); - b_trie_insert(trie, "bo", b_strdup("haha")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); assert_true(trie->root->key == 'c'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'h'); @@ -671,16 +737,16 @@ test_trie_insert(void **state) assert_true(trie->root->next->child->child->next->next->key == '\0'); assert_string_equal(trie->root->next->child->child->next->next->data, "haha"); - b_trie_free(trie); + sb_trie_free(trie); } static void test_trie_insert_duplicated(void **state) { - b_trie_t *trie = b_trie_new(free); + sb_trie_t *trie = sb_trie_new(free); - b_trie_insert(trie, "bola", b_strdup("guda")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); assert_true(trie->root->key == 'b'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'o'); @@ -692,7 +758,7 @@ test_trie_insert_duplicated(void **state) assert_true(trie->root->child->child->child->child->key == '\0'); assert_string_equal(trie->root->child->child->child->child->data, "guda"); - b_trie_insert(trie, "bola", b_strdup("asdf")); + sb_trie_insert(trie, "bola", sb_strdup("asdf")); assert_true(trie->root->key == 'b'); assert_null(trie->root->data); assert_true(trie->root->child->key == 'o'); @@ -704,26 +770,30 @@ test_trie_insert_duplicated(void **state) assert_true(trie->root->child->child->child->child->key == '\0'); assert_string_equal(trie->root->child->child->child->child->data, "asdf"); - b_trie_free(trie); + sb_trie_free(trie); + + trie = NULL; + sb_trie_insert(trie, "bola", NULL); + assert_null(trie); } static void test_trie_keep_data(void **state) { - b_trie_t *trie = b_trie_new(NULL); + sb_trie_t *trie = sb_trie_new(NULL); char *t1 = "guda"; char *t2 = "nda"; char *t3 = "aba"; char *t4 = "haha"; - b_trie_insert(trie, "bola", t1); - b_trie_insert(trie, "chu", t2); - b_trie_insert(trie, "bote", t3); - b_trie_insert(trie, "bo", t4); + sb_trie_insert(trie, "bola", t1); + sb_trie_insert(trie, "chu", t2); + sb_trie_insert(trie, "bote", t3); + sb_trie_insert(trie, "bo", t4); - b_trie_free(trie); + sb_trie_free(trie); assert_string_equal(t1, "guda"); assert_string_equal(t2, "nda"); @@ -735,72 +805,74 @@ test_trie_keep_data(void **state) static void test_trie_lookup(void **state) { - b_trie_t *trie = b_trie_new(free); + sb_trie_t *trie = sb_trie_new(free); + + sb_trie_insert(trie, "bola", sb_strdup("guda")); + sb_trie_insert(trie, "chu", sb_strdup("nda")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); - b_trie_insert(trie, "bola", b_strdup("guda")); - b_trie_insert(trie, "chu", b_strdup("nda")); - b_trie_insert(trie, "bote", b_strdup("aba")); - b_trie_insert(trie, "bo", b_strdup("haha")); + assert_string_equal(sb_trie_lookup(trie, "bola"), "guda"); + assert_string_equal(sb_trie_lookup(trie, "chu"), "nda"); + assert_string_equal(sb_trie_lookup(trie, "bote"), "aba"); + assert_string_equal(sb_trie_lookup(trie, "bo"), "haha"); - assert_string_equal(b_trie_lookup(trie, "bola"), "guda"); - assert_string_equal(b_trie_lookup(trie, "chu"), "nda"); - assert_string_equal(b_trie_lookup(trie, "bote"), "aba"); - assert_string_equal(b_trie_lookup(trie, "bo"), "haha"); + assert_null(sb_trie_lookup(trie, "arcoiro")); - assert_null(b_trie_lookup(trie, "arcoiro")); + sb_trie_free(trie); - b_trie_free(trie); + trie = sb_trie_new(free); - trie = b_trie_new(free); + sb_trie_insert(trie, "chu", sb_strdup("nda")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); + sb_trie_insert(trie, "copa", sb_strdup("bu")); + sb_trie_insert(trie, "b", sb_strdup("c")); + sb_trie_insert(trie, "test", sb_strdup("asd")); - b_trie_insert(trie, "chu", b_strdup("nda")); - b_trie_insert(trie, "bola", b_strdup("guda")); - b_trie_insert(trie, "bote", b_strdup("aba")); - b_trie_insert(trie, "bo", b_strdup("haha")); - b_trie_insert(trie, "copa", b_strdup("bu")); - b_trie_insert(trie, "b", b_strdup("c")); - b_trie_insert(trie, "test", b_strdup("asd")); + assert_string_equal(sb_trie_lookup(trie, "bola"), "guda"); + assert_string_equal(sb_trie_lookup(trie, "chu"), "nda"); + assert_string_equal(sb_trie_lookup(trie, "bote"), "aba"); + assert_string_equal(sb_trie_lookup(trie, "bo"), "haha"); - assert_string_equal(b_trie_lookup(trie, "bola"), "guda"); - assert_string_equal(b_trie_lookup(trie, "chu"), "nda"); - assert_string_equal(b_trie_lookup(trie, "bote"), "aba"); - assert_string_equal(b_trie_lookup(trie, "bo"), "haha"); + assert_null(sb_trie_lookup(trie, "arcoiro")); - assert_null(b_trie_lookup(trie, "arcoiro")); + sb_trie_free(trie); - b_trie_free(trie); + assert_null(sb_trie_lookup(NULL, "bola")); } static void test_trie_size(void **state) { - b_trie_t *trie = b_trie_new(free); + sb_trie_t *trie = sb_trie_new(free); - b_trie_insert(trie, "bola", b_strdup("guda")); - b_trie_insert(trie, "chu", b_strdup("nda")); - b_trie_insert(trie, "bote", b_strdup("aba")); - b_trie_insert(trie, "bo", b_strdup("haha")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); + sb_trie_insert(trie, "chu", sb_strdup("nda")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); - assert_int_equal(b_trie_size(trie), 4); - assert_int_equal(b_trie_size(NULL), 0); + assert_int_equal(sb_trie_size(trie), 4); + assert_int_equal(sb_trie_size(NULL), 0); - b_trie_free(trie); + sb_trie_free(trie); - trie = b_trie_new(free); + trie = sb_trie_new(free); - b_trie_insert(trie, "chu", b_strdup("nda")); - b_trie_insert(trie, "bola", b_strdup("guda")); - b_trie_insert(trie, "bote", b_strdup("aba")); - b_trie_insert(trie, "bo", b_strdup("haha")); - b_trie_insert(trie, "copa", b_strdup("bu")); - b_trie_insert(trie, "b", b_strdup("c")); - b_trie_insert(trie, "test", b_strdup("asd")); + sb_trie_insert(trie, "chu", sb_strdup("nda")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); + sb_trie_insert(trie, "copa", sb_strdup("bu")); + sb_trie_insert(trie, "b", sb_strdup("c")); + sb_trie_insert(trie, "test", sb_strdup("asd")); - assert_int_equal(b_trie_size(trie), 7); - assert_int_equal(b_trie_size(NULL), 0); + assert_int_equal(sb_trie_size(trie), 7); + assert_int_equal(sb_trie_size(NULL), 0); - b_trie_free(trie); + sb_trie_free(trie); } @@ -809,8 +881,9 @@ static char *expected_keys[] = {"chu", "copa", "bola", "bote", "bo", "b", "test" static char *expected_datas[] = {"nda", "bu", "guda", "aba", "haha", "c", "asd"}; static void -mock_foreach(const char *key, void *data) +mock_foreach(const char *key, void *data, void *user_data) { + assert_string_equal(user_data, "foo"); assert_string_equal(key, expected_keys[counter]); assert_string_equal((char*) data, expected_datas[counter++]); } @@ -819,20 +892,23 @@ mock_foreach(const char *key, void *data) static void test_trie_foreach(void **state) { - b_trie_t *trie = b_trie_new(free); + sb_trie_t *trie = sb_trie_new(free); - b_trie_insert(trie, "chu", b_strdup("nda")); - b_trie_insert(trie, "bola", b_strdup("guda")); - b_trie_insert(trie, "bote", b_strdup("aba")); - b_trie_insert(trie, "bo", b_strdup("haha")); - b_trie_insert(trie, "copa", b_strdup("bu")); - b_trie_insert(trie, "b", b_strdup("c")); - b_trie_insert(trie, "test", b_strdup("asd")); + sb_trie_insert(trie, "chu", sb_strdup("nda")); + sb_trie_insert(trie, "bola", sb_strdup("guda")); + sb_trie_insert(trie, "bote", sb_strdup("aba")); + sb_trie_insert(trie, "bo", sb_strdup("haha")); + sb_trie_insert(trie, "copa", sb_strdup("bu")); + sb_trie_insert(trie, "b", sb_strdup("c")); + sb_trie_insert(trie, "test", sb_strdup("asd")); counter = 0; - b_trie_foreach(trie, mock_foreach); + sb_trie_foreach(trie, mock_foreach, "foo"); + sb_trie_foreach(NULL, mock_foreach, "foo"); + sb_trie_foreach(trie, NULL, "foo"); + sb_trie_foreach(NULL, NULL, "foo"); - b_trie_free(trie); + sb_trie_free(trie); } @@ -843,10 +919,11 @@ main(void) // slist unit_test(test_slist_append), + unit_test(test_slist_prepend), unit_test(test_slist_free), unit_test(test_slist_length), - // strings + // strfuncs unit_test(test_strdup), unit_test(test_strndup), unit_test(test_strdup_printf), @@ -859,8 +936,11 @@ main(void) unit_test(test_str_replace), unit_test(test_strv_join), unit_test(test_strv_length), + + // string unit_test(test_string_new), unit_test(test_string_free), + unit_test(test_string_dup), unit_test(test_string_append_len), unit_test(test_string_append), unit_test(test_string_append_c), |