From f63fb03b25b33d5c2ef5ef0eaad016b4ee4aee65 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 13 Feb 2016 01:02:12 +0100 Subject: content-parser: fixed bug that parsed text with '!' + link as image --- tests/check_content_parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 970ec5c..e8e412a 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1360,6 +1360,10 @@ test_content_parse_inline(void **state) assert_non_null(html); assert_string_equal(html, "bola"); free(html); + html = blogc_content_parse_inline("bola!"); + assert_non_null(html); + assert_string_equal(html, "bola!"); + free(html); } @@ -1475,6 +1479,10 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "bola\n"); free(html); + html = blogc_content_parse_inline("[bola!](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola!\n"); + free(html); html = blogc_content_parse_inline("[bola]\n(http://example.org/)\n"); assert_non_null(html); assert_string_equal(html, "bola\n"); @@ -1491,6 +1499,12 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "bola(2)[3]**!\\\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 cmocka, though.\n"); + free(html); // "invalid" html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n"); assert_non_null(html); -- cgit v1.2.3-18-g5258 From 31d376735ab2aaaed0934edcce676113f83a7de7 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 04:58:13 +0100 Subject: content-parser: fixed parser bug when handling links do not handle something like this as a valid link: [asd] asd (asd) --- tests/check_content_parser.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index e8e412a..73bbe9b 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1487,6 +1487,14 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "bola\n"); free(html); + html = blogc_content_parse_inline("[bola]\r\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("[bola] \r\n (http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); html = blogc_content_parse_inline("[bo\nla](http://example.org/)\n"); assert_non_null(html); assert_string_equal(html, "bo\nla\n"); @@ -1505,6 +1513,10 @@ test_content_parse_inline_link(void **state) assert_string_equal(html, "test suite!)\n" "depends on cmocka, 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); -- cgit v1.2.3-18-g5258 From 9902e223799f40776d1131aa0d48fc766637746e Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 14:30:40 +0100 Subject: content-parser: added more tests --- tests/check_content_parser.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 73bbe9b..048d2f2 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1598,6 +1598,18 @@ test_content_parse_inline_image(void **state) assert_non_null(html); assert_string_equal(html, "\"bola\"\n"); free(html); + html = blogc_content_parse_inline("![bola]\r\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\n"); + free(html); + html = blogc_content_parse_inline("![bola] \r\n (http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\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("![bo\nla](http://example.org/)\n"); assert_non_null(html); -- cgit v1.2.3-18-g5258 From b73afb052337d3c11d90efb5e90c2818063dda4d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 15:13:34 +0100 Subject: content-parser: added more tests --- tests/check_content_parser.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 048d2f2..fb56c19 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1606,6 +1606,21 @@ test_content_parse_inline_image(void **state) assert_non_null(html); assert_string_equal(html, "\"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, + ""); + 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, + ""); + free(html); html = blogc_content_parse_inline("asd ![bola]chunda(1234)"); assert_non_null(html); assert_string_equal(html, "asd ![bola]chunda(1234)"); -- cgit v1.2.3-18-g5258 From 437ea5b71f7a1f6cd5d09b28259a8e49acab7fbc Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 16:43:31 +0100 Subject: man: tests: minor documentation fix and more test coverage --- tests/check_content_parser.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index fb56c19..ea069a7 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1621,6 +1621,15 @@ test_content_parse_inline_image(void **state) ""); 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, + ""); + free(html); html = blogc_content_parse_inline("asd ![bola]chunda(1234)"); assert_non_null(html); assert_string_equal(html, "asd ![bola]chunda(1234)"); -- cgit v1.2.3-18-g5258 From 3b0f9293a3432023cdca91df01418347d9781ffa Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 26 Feb 2016 01:04:32 +0100 Subject: build: replace src/utils with squareball --- tests/check_content_parser.c | 2 +- tests/check_error.c | 2 +- tests/check_loader.c | 544 +++++++++++++------------- tests/check_renderer.c | 288 +++++++------- tests/check_source_parser.c | 142 +++---- tests/check_template_parser.c | 80 ++-- tests/check_utils.c | 879 ------------------------------------------ 7 files changed, 529 insertions(+), 1408 deletions(-) delete mode 100644 tests/check_utils.c (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index ea069a7..03f2213 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -16,7 +16,7 @@ #include #include #include "../src/content-parser.h" -#include "../src/utils/utils.h" +#include static void diff --git a/tests/check_error.c b/tests/check_error.c index d3af9c0..4effb08 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -16,7 +16,7 @@ #include #include #include "../src/error.h" -#include "../src/utils/utils.h" +#include static void diff --git a/tests/check_loader.c b/tests/check_loader.c index ac8bdb3..52bd056 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -18,7 +18,7 @@ #include #include "../src/template-parser.h" #include "../src/loader.h" -#include "../src/utils/utils.h" +#include 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,20 @@ 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"), "

bola

\n"); - assert_string_equal(b_trie_lookup(t, "CONTENT"), "

bola

\n"); - assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola"); - b_trie_free(t); + assert_int_equal(sb_trie_size(t), 5); + 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"), "

bola

\n"); + assert_string_equal(sb_trie_lookup(t, "CONTENT"), "

bola

\n"); + assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola"); + sb_trie_free(t); } @@ -129,7 +129,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 +139,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 +181,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 +227,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 +305,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 +384,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 +462,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 +547,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 +625,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 +695,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 +735,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..e863360 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 -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" "

bola

\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..a16a923 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -17,7 +17,7 @@ #include #include "../src/source-parser.h" #include "../src/error.h" -#include "../src/utils/utils.h" +#include static void @@ -31,23 +31,23 @@ 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), 5); + 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"), "

This is a test

\n" "

bola

\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\n" "

bola

\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); + sb_trie_free(source); } @@ -62,23 +62,23 @@ 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), 5); + 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"), "

This is a test

\r\n" "

bola

\r\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\r\n" "

bola

\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); + sb_trie_free(source); } @@ -95,23 +95,23 @@ 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), 5); + 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"), "

This is a test

\n" "

bola

\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\n" "

bola

\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); + sb_trie_free(source); } @@ -131,21 +131,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), 5); + 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"), "

This is a test

\n" "

bola

\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\n" "

bola

\n" "

guda\n" "yay

\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 +154,7 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"); - b_trie_free(source); + sb_trie_free(source); } @@ -163,13 +163,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 +178,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 +194,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 +210,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 +226,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 +234,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 +243,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 +251,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 +260,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 +268,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 +277,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 +285,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 +294,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 +302,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 +311,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 +319,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 +328,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 +336,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 +345,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 +353,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 +362,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 +370,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 +379,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 +387,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 +396,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 +404,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 +413,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 +421,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 +430,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 +438,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 +447,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 +455,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 +464,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 +472,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); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index f655896..ed4328b 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -17,11 +17,11 @@ #include #include "../src/template-parser.h" #include "../src/error.h" -#include "../src/utils/utils.h" +#include 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) " \n" "\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, "\n \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 My cool blog - Main page\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 deleted file mode 100644 index a511dda..0000000 --- a/tests/check_utils.c +++ /dev/null @@ -1,879 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2016 Rafael G. Martins - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#include -#include -#include -#include - -#include - -#include "../src/utils/utils.h" - - -static void -test_slist_append(void **state) -{ - b_slist_t *l = NULL; - l = b_slist_append(l, (void*) b_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")); - 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); -} - - -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); - assert_string_equal(t1, "bola"); - assert_string_equal(t2, "guda"); - assert_string_equal(t3, "chunda"); - free(t1); - free(t2); - free(t3); -} - - -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); -} - - -static void -test_strdup(void **state) -{ - char *str = b_strdup("bola"); - assert_string_equal(str, "bola"); - free(str); - str = b_strdup(NULL); - assert_null(str); -} - - -static void -test_strndup(void **state) -{ - char *str = b_strndup("bolaguda", 4); - assert_string_equal(str, "bola"); - free(str); - str = b_strndup("bolaguda", 30); - assert_string_equal(str, "bolaguda"); - free(str); - str = b_strndup("bolaguda", 8); - assert_string_equal(str, "bolaguda"); - free(str); - str = b_strdup(NULL); - assert_null(str); -} - - -static void -test_strdup_printf(void **state) -{ - char *str = b_strdup_printf("bola"); - assert_string_equal(str, "bola"); - free(str); - str = b_strdup_printf("bola, %s", "guda"); - assert_string_equal(str, "bola, guda"); - free(str); -} - - -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")); -} - - -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")); -} - - -static void -test_str_lstrip(void **state) -{ - char *str = b_strdup(" \tbola\n \t"); - assert_string_equal(b_str_lstrip(str), "bola\n \t"); - free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_lstrip(str), "guda"); - free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_lstrip(str), ""); - free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_lstrip(str), ""); - free(str); - str = b_strdup(""); - assert_string_equal(b_str_lstrip(str), ""); - free(str); - assert_null(b_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"); - free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_rstrip(str), "guda"); - free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_rstrip(str), ""); - free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_rstrip(str), ""); - free(str); - str = b_strdup(""); - assert_string_equal(b_str_rstrip(str), ""); - free(str); - assert_null(b_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"); - free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_strip(str), "guda"); - free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_strip(str), ""); - free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_strip(str), ""); - free(str); - str = b_strdup(""); - assert_string_equal(b_str_strip(str), ""); - free(str); - assert_null(b_str_strip(NULL)); -} - - -static void -test_str_split(void **state) -{ - char **strv = b_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); - 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); - assert_string_equal(strv[0], "bola:guda:chunda"); - assert_null(strv[1]); - b_strv_free(strv); - strv = b_str_split("", ':', 1); - assert_null(strv[0]); - b_strv_free(strv); - assert_null(b_str_split(NULL, ':', 0)); -} - - -static void -test_str_replace(void **state) -{ - char *str = b_str_replace("bolao", 'o', "zaz"); - assert_string_equal(str, "bzazlazaz"); - free(str); - str = b_str_replace("bolao", 'b', "zaz"); - assert_string_equal(str, "zazolao"); - free(str); -} - - -static void -test_strv_join(void **state) -{ - const char *pieces[] = {"guda","bola", "chunda", NULL}; - char *str = b_strv_join(pieces, ":"); - assert_string_equal(str, "guda:bola:chunda"); - free(str); - const char *pieces2[] = {NULL}; - str = b_strv_join(pieces2, ":"); - assert_string_equal(str, ""); - free(str); - assert_null(b_strv_join(NULL, ":")); -} - - -static void -test_strv_length(void **state) -{ - char *pieces[] = {"guda","bola", "chunda", NULL}; - assert_int_equal(b_strv_length(pieces), 3); - char *pieces2[] = {NULL}; - assert_int_equal(b_strv_length(pieces2), 0); - assert_int_equal(b_strv_length(NULL), 0); -} - - -static void -test_string_new(void **state) -{ - b_string_t *str = b_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)); -} - - -static void -test_string_free(void **state) -{ - b_string_t *str = b_string_new(); - free(str->str); - str->str = b_strdup("bola"); - str->len = 4; - str->allocated_len = B_STRING_CHUNK_SIZE; - char *tmp = b_string_free(str, false); - assert_string_equal(tmp, "bola"); - free(tmp); -} - - -static void -test_string_append_len(void **state) -{ - b_string_t *str = b_string_new(); - str = b_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_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_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, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); - str = b_string_append_len(str, NULL, 0); - str = b_string_append_len(str, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); - assert_non_null(str); - assert_string_equal(str->str, - "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" - "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" - "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" - "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" - "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" - "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" - "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" - "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" - "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" - "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" - "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" - "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" - "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" - "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" - "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" - "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" - "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)); -} - - -static void -test_string_append(void **state) -{ - b_string_t *str = b_string_new(); - str = b_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_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, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); - str = b_string_append(str, NULL); - str = b_string_append(str, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); - assert_non_null(str); - assert_string_equal(str->str, - "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" - "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" - "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" - "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" - "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" - "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" - "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" - "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" - "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" - "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" - "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" - "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" - "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" - "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" - "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" - "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" - "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)); -} - - -static void -test_string_append_c(void **state) -{ - b_string_t *str = b_string_new(); - str = b_string_append_len(str, "guda", 4); - for (int i = 0; i < 600; i++) - str = b_string_append_c(str, 'c'); - assert_non_null(str); - assert_string_equal(str->str, - "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "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)); -} - - -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); - 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)); -} - - -static void -test_trie_new(void **state) -{ - b_trie_t *trie = b_trie_new(free); - assert_non_null(trie); - assert_null(trie->root); - assert_true(trie->free_func == free); - b_trie_free(trie); -} - - -static void -test_trie_insert(void **state) -{ - b_trie_t *trie = b_trie_new(free); - - b_trie_insert(trie, "bola", b_strdup("guda")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - 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, "chu", b_strdup("nda")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->key == 'c'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'h'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'u'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->data, "nda"); - - - b_trie_insert(trie, "bote", b_strdup("aba")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->key == 'c'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'h'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'u'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->data, "nda"); - - assert_true(trie->root->child->child->next->key == 't'); - assert_null(trie->root->child->child->next->data); - assert_true(trie->root->child->child->next->child->key == 'e'); - assert_null(trie->root->child->child->next->child->data); - assert_true(trie->root->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); - - - b_trie_insert(trie, "bo", b_strdup("haha")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->key == 'c'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'h'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'u'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->data, "nda"); - - assert_true(trie->root->child->child->next->key == 't'); - assert_null(trie->root->child->child->next->data); - assert_true(trie->root->child->child->next->child->key == 'e'); - assert_null(trie->root->child->child->next->child->data); - assert_true(trie->root->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); - - 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); - - - trie = b_trie_new(free); - - b_trie_insert(trie, "chu", b_strdup("nda")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - - b_trie_insert(trie, "bola", b_strdup("guda")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - assert_true(trie->root->next->key == 'b'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'o'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'l'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == 'a'); - assert_null(trie->root->next->child->child->child->data); - assert_true(trie->root->next->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - - - b_trie_insert(trie, "bote", b_strdup("aba")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - assert_true(trie->root->next->key == 'b'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'o'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'l'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == 'a'); - assert_null(trie->root->next->child->child->child->data); - assert_true(trie->root->next->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->child->child->next->key == 't'); - assert_null(trie->root->next->child->child->next->data); - assert_true(trie->root->next->child->child->next->child->key == 'e'); - assert_null(trie->root->next->child->child->next->child->data); - assert_true(trie->root->next->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); - - - b_trie_insert(trie, "bo", b_strdup("haha")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - assert_true(trie->root->next->key == 'b'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'o'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'l'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == 'a'); - assert_null(trie->root->next->child->child->child->data); - assert_true(trie->root->next->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->child->child->next->key == 't'); - assert_null(trie->root->next->child->child->next->data); - assert_true(trie->root->next->child->child->next->child->key == 'e'); - assert_null(trie->root->next->child->child->next->child->data); - assert_true(trie->root->next->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); - - 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); -} - - -static void -test_trie_insert_duplicated(void **state) -{ - b_trie_t *trie = b_trie_new(free); - - b_trie_insert(trie, "bola", b_strdup("guda")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - 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")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - 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); -} - - -static void -test_trie_keep_data(void **state) -{ - b_trie_t *trie = b_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); - - b_trie_free(trie); - - assert_string_equal(t1, "guda"); - assert_string_equal(t2, "nda"); - assert_string_equal(t3, "aba"); - assert_string_equal(t4, "haha"); -} - - -static void -test_trie_lookup(void **state) -{ - b_trie_t *trie = b_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")); - - 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(b_trie_lookup(trie, "arcoiro")); - - b_trie_free(trie); - - trie = b_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")); - - 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(b_trie_lookup(trie, "arcoiro")); - - b_trie_free(trie); -} - - -static void -test_trie_size(void **state) -{ - b_trie_t *trie = b_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")); - - assert_int_equal(b_trie_size(trie), 4); - assert_int_equal(b_trie_size(NULL), 0); - - b_trie_free(trie); - - trie = b_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")); - - assert_int_equal(b_trie_size(trie), 7); - assert_int_equal(b_trie_size(NULL), 0); - - b_trie_free(trie); -} - - -static unsigned int counter; -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) -{ - assert_string_equal(key, expected_keys[counter]); - assert_string_equal((char*) data, expected_datas[counter++]); -} - - -static void -test_trie_foreach(void **state) -{ - b_trie_t *trie = b_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")); - - counter = 0; - b_trie_foreach(trie, mock_foreach); - - b_trie_free(trie); -} - - -int -main(void) -{ - const UnitTest tests[] = { - - // slist - unit_test(test_slist_append), - unit_test(test_slist_free), - unit_test(test_slist_length), - - // strings - unit_test(test_strdup), - unit_test(test_strndup), - unit_test(test_strdup_printf), - unit_test(test_str_starts_with), - unit_test(test_str_ends_with), - unit_test(test_str_lstrip), - unit_test(test_str_rstrip), - unit_test(test_str_strip), - unit_test(test_str_split), - unit_test(test_str_replace), - unit_test(test_strv_join), - unit_test(test_strv_length), - unit_test(test_string_new), - unit_test(test_string_free), - unit_test(test_string_append_len), - unit_test(test_string_append), - unit_test(test_string_append_c), - unit_test(test_string_append_printf), - - // trie - unit_test(test_trie_new), - unit_test(test_trie_insert), - unit_test(test_trie_insert_duplicated), - unit_test(test_trie_keep_data), - unit_test(test_trie_lookup), - unit_test(test_trie_size), - unit_test(test_trie_foreach), - }; - return run_tests(tests); -} -- cgit v1.2.3-18-g5258 From 2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:35:16 +0100 Subject: content-parser: convert -- and --- to &ndash and &mdash --- tests/check_content_parser.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 03f2213..bc21317 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -106,8 +106,8 @@ test_content_parse(void **state) "1. chunda\n" "3. fuuuu\n" "\n" - "+ chunda2\n" - "+ fuuuu2\n" + "- chunda2\n" + "- fuuuu2\n" "\n" "\n" "

guda\n" "yay

\n" - "

bola

\n"); + "

bola\n" + "— foo\n" + "– bar

\n" + "

— asd

\n" + "

– lol

\n"); free(html); } @@ -194,7 +204,13 @@ test_content_parse_crlf(void **state) "guda\r\n" "yay\r\n" "\r\n" - "**bola**\r\n", &l); + "**bola**\r\n" + "-- foo\r\n" + "--- bar\r\n" + "\r\n" + "-- asd\r\n" + "\r\n" + "--- lol\r\n", &l); assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, @@ -228,7 +244,11 @@ test_content_parse_crlf(void **state) "\r\n" "

guda\r\n" "yay

\r\n" - "

bola

\r\n"); + "

bola\r\n" + "— foo\r\n" + "– bar

\r\n" + "

— asd

\r\n" + "

– lol

\r\n"); free(html); } -- cgit v1.2.3-18-g5258 From de986bafd7d765e94059c0e88df93a352d85d7aa Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:39:45 +0100 Subject: content-parser: fixed a bug in previous patch --- tests/check_content_parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index bc21317..d9d2528 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -117,7 +117,7 @@ test_content_parse(void **state) "yay\n" "\n" "**bola**\n" - "-- foo\n" + "-- foo-bar\n" "--- bar\n" "\n" "-- asd\n" @@ -157,7 +157,7 @@ test_content_parse(void **state) "

guda\n" "yay

\n" "

bola\n" - "— foo\n" + "— foo-bar\n" "– bar

\n" "

— asd

\n" "

– lol

\n"); @@ -205,7 +205,7 @@ test_content_parse_crlf(void **state) "yay\r\n" "\r\n" "**bola**\r\n" - "-- foo\r\n" + "-- foo-bar\r\n" "--- bar\r\n" "\r\n" "-- asd\r\n" @@ -245,7 +245,7 @@ test_content_parse_crlf(void **state) "

guda\r\n" "yay

\r\n" "

bola\r\n" - "— foo\r\n" + "— foo-bar\r\n" "– bar

\r\n" "

— asd

\r\n" "

– lol

\r\n"); -- cgit v1.2.3-18-g5258 From 1645987e132d063847aa95c0693570b44bb2d7d5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:46:40 +0100 Subject: content-parser: fixed em/en-dash logic --- tests/check_content_parser.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index d9d2528..b20f8d0 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -157,10 +157,10 @@ test_content_parse(void **state) "

guda\n" "yay

\n" "

bola\n" - "— foo-bar\n" - "– bar

\n" - "

— asd

\n" - "

– lol

\n"); + "– foo-bar\n" + "— bar

\n" + "

– asd

\n" + "

— lol

\n"); free(html); } @@ -245,10 +245,10 @@ test_content_parse_crlf(void **state) "

guda\r\n" "yay

\r\n" "

bola\r\n" - "— foo-bar\r\n" - "– bar

\r\n" - "

— asd

\r\n" - "

– lol

\r\n"); + "– foo-bar\r\n" + "— bar

\r\n" + "

– asd

\r\n" + "

— lol

\r\n"); free(html); } -- cgit v1.2.3-18-g5258 From a2b3551dfb9460470bd79f5648bf597c517c40d4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 13 Mar 2016 01:48:49 +0100 Subject: *: use squareball error infrastructure --- tests/check_datetime_parser.c | 216 +++++++++++++++++++++--------------------- tests/check_error.c | 44 ++++----- tests/check_loader.c | 30 +++--- tests/check_renderer.c | 40 ++++---- tests/check_source_parser.c | 122 ++++++++++++------------ tests/check_template_parser.c | 190 ++++++++++++++++++------------------- 6 files changed, 321 insertions(+), 321 deletions(-) (limited to 'tests') diff --git a/tests/check_datetime_parser.c b/tests/check_datetime_parser.c index ba5a79d..aef366e 100644 --- a/tests/check_datetime_parser.c +++ b/tests/check_datetime_parser.c @@ -24,7 +24,7 @@ static void test_convert_datetime(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -36,7 +36,7 @@ test_convert_datetime(void **state) static void test_convert_datetime_implicit_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -48,7 +48,7 @@ test_convert_datetime_implicit_seconds(void **state) static void test_convert_datetime_implicit_minutes(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -60,7 +60,7 @@ test_convert_datetime_implicit_minutes(void **state) static void test_convert_datetime_implicit_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -72,529 +72,529 @@ test_convert_datetime_implicit_hours(void **state) static void test_convert_datetime_invalid_formats(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("20", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '20', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("201", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '201', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-3", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-3', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 ", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 ', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:13:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("a010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2a10-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_3rd_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("20a0-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_4th_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("201a-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("1899-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid year. Found 1899, must be >= 1900."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_hyphen(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010 11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between year and month. Found ' ', must be '-'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_month(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-a1-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_month(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-1a-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_month(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-13-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid month. Found 13, must be >= 1 and <= 12."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_hyphen(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11 30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between month and day. Found ' ', must be '-'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_day(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-a0 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_day(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-3a 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_day(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-32 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid day. Found 32, must be >= 1 and <= 31."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_space(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30-12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between date and time. Found '-', must be ' ' " "(empty space)."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 a2:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 1a:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 24:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid hours. Found 24, must be >= 0 and <= 23."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_colon(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12 13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between hours and minutes. Found ' ', must be ':'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_minutes(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:a3:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_minutes(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:1a:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_colon(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13 14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between minutes and seconds. Found ' ', must be ':'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:a4", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:1a", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:69", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid seconds. Found 69, must be >= 0 and <= 60."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_format_long(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:14", "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" "yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk" @@ -613,7 +613,7 @@ test_convert_datetime_invalid_format_long(void **state) "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Failed to format DATE variable, FORMAT is too long: " "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" @@ -631,7 +631,7 @@ test_convert_datetime_invalid_format_long(void **state) "uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq" "gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj" "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg"); - blogc_error_free(err); + sb_error_free(err); } diff --git a/tests/check_error.c b/tests/check_error.c index 4effb08..7fc3c3e 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -22,22 +22,22 @@ static void test_error_new(void **state) { - blogc_error_t *error = blogc_error_new(1, "bola %s"); + sb_error_t *error = sb_error_new(1, "bola %s"); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "bola %s"); - blogc_error_free(error); + sb_error_free(error); } static void test_error_new_printf(void **state) { - blogc_error_t *error = blogc_error_new_printf(2, "bola %s", "guda"); + sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); assert_non_null(error); - assert_int_equal(error->type, 2); + assert_int_equal(error->code, 2); assert_string_equal(error->msg, "bola guda"); - blogc_error_free(error); + sb_error_free(error); } @@ -45,32 +45,32 @@ static void test_error_parser(void **state) { const char *a = "bola\nguda\nchunda\n"; - blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); + sb_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - blogc_error_free(error); + sb_error_free(error); a = ""; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10"); - blogc_error_free(error); + sb_error_free(error); } @@ -78,26 +78,26 @@ static void test_error_parser_crlf(void **state) { const char *a = "bola\r\nguda\r\nchunda\r\n"; - blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); + sb_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - blogc_error_free(error); + sb_error_free(error); } diff --git a/tests/check_loader.c b/tests/check_loader.c index 52bd056..0db6194 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -52,7 +52,7 @@ test_get_filename(void **state) char* -__wrap_blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) +__wrap_blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) { assert_null(*err); const char *_path = mock_type(const char*); @@ -78,7 +78,7 @@ __wrap_blogc_fprintf(FILE *stream, const char *format, ...) static void test_template_parse_from_file(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n")); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -92,7 +92,7 @@ test_template_parse_from_file(void **state) static void test_template_parse_from_file_null(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, NULL); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -104,7 +104,7 @@ test_template_parse_from_file_null(void **state) static void test_source_parse_from_file(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" @@ -126,7 +126,7 @@ test_source_parse_from_file(void **state) static void test_source_parse_from_file_null(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, NULL); sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); @@ -156,7 +156,7 @@ test_source_parse_from_files(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -200,7 +200,7 @@ test_source_parse_from_files_filter_by_tag(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -268,7 +268,7 @@ test_source_parse_from_files_filter_by_page(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -346,7 +346,7 @@ test_source_parse_from_files_filter_by_page2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -425,7 +425,7 @@ test_source_parse_from_files_filter_by_page3(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -508,7 +508,7 @@ test_source_parse_from_files_filter_by_page_and_tag(void **state) "TAGS: yay chunda\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -588,7 +588,7 @@ test_source_parse_from_files_filter_by_page_invalid(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -666,7 +666,7 @@ test_source_parse_from_files_filter_by_page_invalid2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -711,7 +711,7 @@ test_source_parse_from_files_without_all_dates(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -734,7 +734,7 @@ test_source_parse_from_files_without_all_dates(void **state) static void test_source_parse_from_files_null(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); diff --git a/tests/check_renderer.c b/tests/check_renderer.c index e863360..d71f045 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -46,7 +46,7 @@ create_sources(unsigned int count) "ahahahahahahahaha3", }; assert_false(count > 3); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = NULL; for (unsigned int i = 0; i < count; i++) { l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err)); @@ -78,7 +78,7 @@ test_render_entry(void **state) "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -125,7 +125,7 @@ test_render_listing(void **state) "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -173,7 +173,7 @@ test_render_listing_empty(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -200,7 +200,7 @@ test_render_ifdef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -229,7 +229,7 @@ test_render_ifdef2(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -260,7 +260,7 @@ test_render_ifdef3(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -293,7 +293,7 @@ test_render_ifndef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -327,7 +327,7 @@ test_render_if_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -362,7 +362,7 @@ test_render_if_neq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -397,7 +397,7 @@ test_render_if_lt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -432,7 +432,7 @@ test_render_if_gt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -469,7 +469,7 @@ test_render_if_lt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -508,7 +508,7 @@ test_render_if_gt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -539,7 +539,7 @@ test_render_foreach(void **state) "{% block entry %}\n" "{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -564,7 +564,7 @@ test_render_foreach_if(void **state) "{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}" "{% endif %} {% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -595,7 +595,7 @@ test_render_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}lol{% endif %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -628,7 +628,7 @@ test_render_prefer_local_variable(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -664,7 +664,7 @@ test_render_respect_variable_scope(void **state) "{% ifdef LOL %}{{ LOL }}{% endif %}\n" "{% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -696,7 +696,7 @@ test_render_ifcount_bug(void **state) "{% ifdef ASD %}ASD{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index a16a923..fba997a 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -30,7 +30,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -61,7 +61,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -94,7 +94,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -130,7 +130,7 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -162,13 +162,13 @@ static void test_source_parse_config_empty(void **state) { const char *a = ""; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your source file is empty."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -177,14 +177,14 @@ static void test_source_parse_config_invalid_key(void **state) { const char *a = "bola: guda"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, 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); + sb_error_free(err); sb_trie_free(source); } @@ -193,14 +193,14 @@ static void test_source_parse_config_no_key(void **state) { const char *a = "BOLa"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, 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); + sb_error_free(err); sb_trie_free(source); } @@ -209,14 +209,14 @@ static void test_source_parse_config_no_key2(void **state) { const char *a = "BOLA"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, 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); + sb_error_free(err); sb_trie_free(source); } @@ -225,15 +225,15 @@ static void test_source_parse_config_no_value(void **state) { const char *a = "BOLA:\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -242,15 +242,15 @@ static void test_source_parse_config_no_value2(void **state) { const char *a = "BOLA:"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -259,15 +259,15 @@ static void test_source_parse_config_reserved_name(void **state) { const char *a = "FILENAME: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'FILENAME' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -276,15 +276,15 @@ static void test_source_parse_config_reserved_name2(void **state) { const char *a = "CONTENT: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'CONTENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -293,15 +293,15 @@ static void test_source_parse_config_reserved_name3(void **state) { const char *a = "DATE_FORMATTED: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -310,15 +310,15 @@ static void test_source_parse_config_reserved_name4(void **state) { const char *a = "DATE_FIRST_FORMATTED: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -327,15 +327,15 @@ static void test_source_parse_config_reserved_name5(void **state) { const char *a = "DATE_LAST_FORMATTED: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -344,15 +344,15 @@ static void test_source_parse_config_reserved_name6(void **state) { const char *a = "PAGE_FIRST: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_FIRST' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -361,15 +361,15 @@ static void test_source_parse_config_reserved_name7(void **state) { const char *a = "PAGE_PREVIOUS: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -378,15 +378,15 @@ static void test_source_parse_config_reserved_name8(void **state) { const char *a = "PAGE_CURRENT: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_CURRENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -395,15 +395,15 @@ static void test_source_parse_config_reserved_name9(void **state) { const char *a = "PAGE_NEXT: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_NEXT' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -412,15 +412,15 @@ static void test_source_parse_config_reserved_name10(void **state) { const char *a = "PAGE_LAST: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_LAST' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -429,15 +429,15 @@ static void test_source_parse_config_reserved_name11(void **state) { const char *a = "BLOGC_VERSION: 1.0\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'BLOGC_VERSION' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -446,15 +446,15 @@ static void test_source_parse_config_value_no_line_ending(void **state) { const char *a = "BOLA: asd"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "No line ending after the configuration value for 'BOLA'.\n" "Error occurred near line 1, position 10: BOLA: asd"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -463,15 +463,15 @@ static void test_source_parse_invalid_separator(void **state) { const char *a = "BOLA: asd\n---#"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid content separator. Must be more than one '-' characters.\n" "Error occurred near line 2, position 4: ---#"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index ed4328b..9419607 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -63,7 +63,7 @@ test_template_parse(void **state) "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -143,7 +143,7 @@ test_template_parse_crlf(void **state) "{% block listing_once %}asd{% endblock %}\r\n" "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -231,7 +231,7 @@ test_template_parse_html(void **state) " {% block listing_once %}{% endblock %}\n" " \n" "\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -341,7 +341,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -372,35 +372,35 @@ static void test_template_parse_invalid_block_start(void **state) { const char *a = "{% ASD %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 4: {% ASD %}"); - blogc_error_free(err); + sb_error_free(err); a = "{%-- block entry %}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" "Error occurred near line 1, position 4: {%-- block entry %}"); - blogc_error_free(err); + sb_error_free(err); a = "{% block entry --%}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" "Error occurred near line 1, position 17: {% block entry --%}"); - blogc_error_free(err); + sb_error_free(err); } @@ -410,15 +410,15 @@ test_template_parse_invalid_block_nested(void **state) const char *a = "{% block entry %}\n" "{% block listing %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Blocks can't be nested.\n" "Error occurred near line 2, position 9: {% block listing %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -428,15 +428,15 @@ test_template_parse_invalid_foreach_nested(void **state) const char *a = "{% foreach A %}\n" "{% foreach B %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'foreach' statements can't be nested.\n" "Error occurred near line 2, position 11: {% foreach B %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -444,15 +444,15 @@ static void test_template_parse_invalid_block_not_open(void **state) { const char *a = "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endblock' statement without an open 'block' statement.\n" "Error occurred near line 1, position 12: {% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -460,16 +460,16 @@ static void test_template_parse_invalid_endif_not_open(void **state) { const char *a = "{% block listing %}{% endif %}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endif' statement without an open 'ifdef' or 'ifndef' statement.\n" "Error occurred near line 1, position 28: " "{% block listing %}{% endif %}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -477,15 +477,15 @@ static void test_template_parse_invalid_endforeach_not_open(void **state) { const char *a = "{% endforeach %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endforeach' statement without an open 'foreach' statement.\n" "Error occurred near line 1, position 14: {% endforeach %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -493,16 +493,16 @@ static void test_template_parse_invalid_block_name(void **state) { const char *a = "{% chunda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement type: Allowed types are: 'block', 'endblock', 'ifdef', " "'ifndef', 'endif', 'foreach' and 'endforeach'.\n" "Error occurred near line 1, position 10: {% chunda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -510,15 +510,15 @@ static void test_template_parse_invalid_block_type_start(void **state) { const char *a = "{% block ENTRY %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 10: {% block ENTRY %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -526,15 +526,15 @@ static void test_template_parse_invalid_block_type(void **state) { const char *a = "{% block chunda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -542,16 +542,16 @@ static void test_template_parse_invalid_ifdef_start(void **state) { const char *a = "{% block entry %}{% ifdef guda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef guda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -559,16 +559,16 @@ static void test_template_parse_invalid_foreach_start(void **state) { const char *a = "{% block entry %}{% foreach guda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% foreach guda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -576,16 +576,16 @@ static void test_template_parse_invalid_ifdef_variable(void **state) { const char *a = "{% block entry %}{% ifdef BoLA %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 28: " "{% block entry %}{% ifdef BoLA %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -593,16 +593,16 @@ static void test_template_parse_invalid_ifdef_variable2(void **state) { const char *a = "{% block entry %}{% ifdef 0123 %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef 0123 %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -610,16 +610,16 @@ static void test_template_parse_invalid_foreach_variable(void **state) { const char *a = "{% block entry %}{% foreach BoLA %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 30: " "{% block entry %}{% foreach BoLA %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -627,16 +627,16 @@ static void test_template_parse_invalid_foreach_variable2(void **state) { const char *a = "{% block entry %}{% foreach 0123 %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: {% block entry %}" "{% foreach 0123 %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -644,16 +644,16 @@ static void test_template_parse_invalid_if_operator(void **state) { const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% if BOLA = \"asd\" %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -661,16 +661,16 @@ static void test_template_parse_invalid_if_operand(void **state) { const char *a = "{% block entry %}{% if BOLA == asd %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == asd %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -678,16 +678,16 @@ static void test_template_parse_invalid_if_operand2(void **state) { const char *a = "{% block entry %}{% if BOLA == \"asd %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Found an open double-quoted string.\n" "Error occurred near line 1, position 31: " "{% block entry %}{% if BOLA == \"asd %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -695,16 +695,16 @@ static void test_template_parse_invalid_if_operand3(void **state) { const char *a = "{% block entry %}{% if BOLA == 0123 %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == 0123 %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -712,15 +712,15 @@ static void test_template_parse_invalid_block_end(void **state) { const char *a = "{% block entry }}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '%}'.\n" "Error occurred near line 1, position 16: {% block entry }}"); - blogc_error_free(err); + sb_error_free(err); } @@ -728,16 +728,16 @@ static void test_template_parse_invalid_variable_name(void **state) { const char *a = "{% block entry %}{{ bola }}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: " "{% block entry %}{{ bola }}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -745,16 +745,16 @@ static void test_template_parse_invalid_variable_name2(void **state) { const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 22: " "{% block entry %}{{ Bola }}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -762,16 +762,16 @@ static void test_template_parse_invalid_variable_name3(void **state) { const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}" "{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -779,16 +779,16 @@ static void test_template_parse_invalid_variable_end(void **state) { const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}}'.\n" "Error occurred near line 1, position 26: " "{% block entry %}{{ BOLA %}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -796,15 +796,15 @@ static void test_template_parse_invalid_close(void **state) { const char *a = "{% block entry %%\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 17: {% block entry %%"); - blogc_error_free(err); + sb_error_free(err); } @@ -812,16 +812,16 @@ static void test_template_parse_invalid_close2(void **state) { const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 27: " "{% block entry %}{{ BOLA }%{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -829,14 +829,14 @@ static void test_template_parse_invalid_if_not_closed(void **state) { const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "1 open 'ifdef' and/or 'ifndef' statements " "were not closed!"); - blogc_error_free(err); + sb_error_free(err); } @@ -844,13 +844,13 @@ static void test_template_parse_invalid_block_not_closed(void **state) { const char *a = "{% block entry %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open block was not closed!"); - blogc_error_free(err); + sb_error_free(err); } @@ -858,13 +858,13 @@ static void test_template_parse_invalid_foreach_not_closed(void **state) { const char *a = "{% foreach ASD %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open 'foreach' statement was not closed!"); - blogc_error_free(err); + sb_error_free(err); } -- cgit v1.2.3-18-g5258 From 37592b57b31987519e59117d49bccd0207e67f15 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 13 Mar 2016 03:05:17 +0100 Subject: error: removed uneeded tests --- tests/check_error.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'tests') diff --git a/tests/check_error.c b/tests/check_error.c index 7fc3c3e..c990b45 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -19,28 +19,6 @@ #include -static void -test_error_new(void **state) -{ - sb_error_t *error = sb_error_new(1, "bola %s"); - assert_non_null(error); - assert_int_equal(error->code, 1); - assert_string_equal(error->msg, "bola %s"); - sb_error_free(error); -} - - -static void -test_error_new_printf(void **state) -{ - sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); - assert_non_null(error); - assert_int_equal(error->code, 2); - assert_string_equal(error->msg, "bola guda"); - sb_error_free(error); -} - - static void test_error_parser(void **state) { @@ -105,8 +83,6 @@ int main(void) { const UnitTest tests[] = { - unit_test(test_error_new), - unit_test(test_error_new_printf), unit_test(test_error_parser), unit_test(test_error_parser_crlf), }; -- cgit v1.2.3-18-g5258 From 001c16ac605ee65f5688534e42c10395db3f0d5a Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 17 Apr 2016 04:01:51 +0200 Subject: content-parser: do not convert -- and --- to &ndash and &mdash inside code --- tests/check_content_parser.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index b20f8d0..ea3a9a2 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1751,6 +1751,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, "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, "foo -- bar"); + free(html); + html = blogc_content_parse_inline("``foo --- bar``"); + assert_non_null(html); + assert_string_equal(html, "foo --- bar"); + free(html); +} + + int main(void) { @@ -1793,6 +1823,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); } -- cgit v1.2.3-18-g5258 From 9b2a563b4931ca39cd6dd14bf85cda627714a4b2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 20 Apr 2016 02:50:20 +0200 Subject: content-parser: extract post description from content description is the first line of the first paragraph parsed from content file. users can override it declaring DESCRIPTION variable in source file itself. this also fixes a bug with line endings when using single line blockquotes. --- tests/check_content_parser.c | 412 +++++++++++++++++++++++++++++++++---------- tests/check_loader.c | 3 +- tests/check_source_parser.c | 46 ++++- 3 files changed, 367 insertions(+), 94 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index ea3a9a2..0eaab70 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -81,6 +81,7 @@ static void test_content_parse(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# um\n" "## dois\n" @@ -122,9 +123,11 @@ test_content_parse(void **state) "\n" "-- asd\n" "\n" - "--- lol\n", &l); + "--- 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, "

um

\n" "

dois

\n" @@ -162,6 +165,7 @@ test_content_parse(void **state) "

– asd

\n" "

— lol

\n"); free(html); + free(d); } @@ -169,6 +173,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" @@ -210,9 +215,11 @@ test_content_parse_crlf(void **state) "\r\n" "-- asd\r\n" "\r\n" - "--- lol\r\n", &l); + "--- 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, "

um

\r\n" "

dois

\r\n" @@ -250,6 +257,7 @@ test_content_parse_crlf(void **state) "

– asd

\r\n" "

— lol

\r\n"); free(html); + free(d); } @@ -257,6 +265,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" @@ -265,9 +274,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, "

test

\n" "

chunda

\n" @@ -275,6 +286,8 @@ test_content_parse_with_excerpt(void **state) "lol

\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" @@ -283,15 +296,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, "

test

\n" "

chunda

\n" "

guda\n" "lol

\n"); free(html); + free(d); } @@ -299,6 +315,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" @@ -307,9 +324,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, "

test

\r\n" "

chunda

\r\n" @@ -317,6 +336,8 @@ test_content_parse_with_excerpt_crlf(void **state) "lol

\r\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\r\n" "\r\n" @@ -325,26 +346,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, "

test

\r\n" "

chunda

\r\n" "

guda\r\n" "lol

\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, "

bola

\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, "

bola

\n"); free(html); @@ -353,7 +377,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, "

bola

\n" @@ -366,11 +390,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, "

bola

\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, "

bola

\r\n"); free(html); @@ -379,7 +403,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, "

bola

\r\n" @@ -392,11 +416,11 @@ test_content_parse_header_crlf(void **state) static void test_content_parse_html(void **state) { - char *html = blogc_content_parse("
\n
", NULL); + char *html = blogc_content_parse("
\n
", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\n
\n"); free(html); - html = blogc_content_parse("
\n
\n", NULL); + html = blogc_content_parse("
\n
\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\n
\n"); free(html); @@ -406,7 +430,7 @@ test_content_parse_html(void **state) "
\n" "
\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "

bola

\n" @@ -419,11 +443,11 @@ test_content_parse_html(void **state) static void test_content_parse_html_crlf(void **state) { - char *html = blogc_content_parse("
\r\n
", NULL); + char *html = blogc_content_parse("
\r\n
", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\r\n
\r\n"); free(html); - html = blogc_content_parse("
\r\n
\r\n", NULL); + html = blogc_content_parse("
\r\n
\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\r\n
\r\n"); free(html); @@ -433,7 +457,7 @@ test_content_parse_html_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, "

bola

\r\n" @@ -446,27 +470,40 @@ 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, "

bola\n" "guda

\n" "
\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, "

bola\n" "guda

\n" "
\n"); free(html); + html = blogc_content_parse( + "bola\n" + "\n" + "> bola\n" + "\n" + "chunda\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "

bola

\n" + "

bola

\n" + "
\n" + "

chunda

\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, "

bola

\n" @@ -481,27 +518,40 @@ 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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" "guda

\r\n" "
\r\n"); free(html); + html = blogc_content_parse( + "bola\r\n" + "\r\n" + "> bola\r\n" + "\r\n" + "chunda\r\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "

bola

\r\n" + "

bola

\r\n" + "
\r\n" + "

chunda

\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, "

bola

\r\n" @@ -516,13 +566,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, "
bola\n"
         "guda
\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, "
bola\n"
@@ -534,7 +584,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,
         "

bola

\n" @@ -548,13 +598,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, "
bola\r\n"
         "guda
\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, "
bola\r\n"
@@ -566,7 +616,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,
         "

bola

\r\n" @@ -580,28 +630,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, "

bola\n" "guda

\n" "
\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, "

bola\n" "guda

\n" "
\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, "

bola\n" "guda

\n" "
\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, "

bola\n" @@ -613,7 +663,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, "

bola

\n" @@ -625,7 +675,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, "

bola

\n" @@ -638,28 +688,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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" @@ -671,7 +721,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, "

bola

\r\n" @@ -683,7 +733,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, "

bola

\r\n" @@ -701,7 +751,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, "

lol

\n" @@ -716,7 +766,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, "

lol

\n" @@ -733,7 +783,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, "

lol

\n" @@ -753,7 +803,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, "

lol

\n" @@ -769,7 +819,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, "
    \n" @@ -789,7 +839,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, "

    lol

    \r\n" @@ -804,7 +854,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, "

    lol

    \r\n" @@ -821,7 +871,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, "

    lol

    \r\n" @@ -841,7 +891,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, "

    lol

    \r\n" @@ -857,7 +907,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, "
      \r\n" @@ -877,7 +927,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, "

      lol

      \n" @@ -892,7 +942,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, "

      lol

      \n" @@ -909,7 +959,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, "

      lol

      \n" @@ -929,7 +979,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, "

      lol

      \n" @@ -945,7 +995,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, "
        \n" @@ -965,7 +1015,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, "

        lol

        \r\n" @@ -980,7 +1030,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, "

        lol

        \r\n" @@ -997,7 +1047,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, "

        lol

        \r\n" @@ -1017,7 +1067,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, "

        lol

        \r\n" @@ -1033,7 +1083,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, "
          \r\n" @@ -1045,10 +1095,177 @@ test_content_parse_ordered_list_crlf(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, + "

          foo

          \n" + "

          bar

          \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, + "

          foo

          \n" + "

          bar

          \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, + "

          foo

          \n" + "

          qwe\n" + "bar

          \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, + "

          foo

          \n" + "

          qwe

          \n" + "
          \n" + "

          bar

          \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, + "

          foo

          \n" + "

          qwe\n" + "zxc

          \n" + "
          \n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          qwe\r\n" + "bar

          \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, + "

          foo

          \r\n" + "

          qwe

          \r\n" + "
          \r\n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          qwe\r\n" + "zxc

          \r\n" + "
          \r\n" + "

          bar

          \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" @@ -1056,9 +1273,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, "

          test

          \n" "

          chunda\n" @@ -1067,6 +1286,8 @@ test_content_parse_invalid_excerpt(void **state) "lol

          \n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" @@ -1074,9 +1295,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, "

          test

          \n" "

          chunda

          \n" @@ -1085,15 +1308,19 @@ test_content_parse_invalid_excerpt(void **state) "lol

          \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, "

          test

          \n" "

          chunda..

          \n" @@ -1101,21 +1328,26 @@ test_content_parse_invalid_excerpt(void **state) "lol

          \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, "

          test

          \n" "

          chunda

          \n" "

          ...guda\n" "lol

          \n"); free(html); + free(d); } @@ -1125,7 +1357,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, "

          asd

          \n" @@ -1142,7 +1374,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, "

          asd

          \n" @@ -1159,7 +1391,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, "

          > asd\n" @@ -1168,7 +1400,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, "

          > asd\n" @@ -1183,7 +1415,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, "

          asd\n" @@ -1193,7 +1425,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, "

          asd\n" @@ -1207,11 +1439,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, "

          asd

          \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, "

          asd

          \n"); free(html); @@ -1224,7 +1456,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, "

          asd\n" @@ -1233,7 +1465,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, "

          asd\n" @@ -1241,7 +1473,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, "

          asd\n" @@ -1250,7 +1482,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, "

          asd\n" @@ -1263,7 +1495,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, "

          chunda

          \n" @@ -1280,7 +1512,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, "

          1. asd\n" @@ -1289,7 +1521,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, "

          1. asd\n" @@ -1297,7 +1529,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, "

          1. asd\n" @@ -1306,7 +1538,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, "

          1. asd\n" @@ -1319,7 +1551,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, "

          chunda

          \n" @@ -1329,7 +1561,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, "

          1 asd\n" @@ -1337,7 +1569,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, "

          a. asd\n" @@ -1345,18 +1577,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, "

          1.\n" "asd\n" "2. qwe

          \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, "

          1.

          \n"); free(html); - html = blogc_content_parse("1 ", NULL); + html = blogc_content_parse("1 ", NULL, NULL); assert_non_null(html); assert_string_equal(html, "

          1

          \n"); free(html); @@ -1806,6 +2038,8 @@ main(void) unit_test(test_content_parse_unordered_list_crlf), unit_test(test_content_parse_ordered_list), unit_test(test_content_parse_ordered_list_crlf), + 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), diff --git a/tests/check_loader.c b/tests/check_loader.c index 0db6194..c0e30df 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -113,12 +113,13 @@ test_source_parse_from_file(void **state) sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); assert_null(err); assert_non_null(t); - assert_int_equal(sb_trie_size(t), 5); + 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"), "

          bola

          \n"); assert_string_equal(sb_trie_lookup(t, "CONTENT"), "

          bola

          \n"); assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola"); + assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola"); sb_trie_free(t); } diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index fba997a..a2a3ddc 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -34,7 +34,7 @@ test_source_parse(void **state) 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), 5); + 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"), @@ -47,6 +47,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); sb_trie_free(source); } @@ -65,7 +66,7 @@ test_source_parse_crlf(void **state) 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), 5); + 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"), @@ -78,6 +79,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); sb_trie_free(source); } @@ -98,7 +100,7 @@ test_source_parse_with_spaces(void **state) 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), 5); + 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"), @@ -111,6 +113,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); sb_trie_free(source); } @@ -134,7 +137,7 @@ test_source_parse_with_excerpt(void **state) 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), 5); + 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"), @@ -154,6 +157,40 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"); + 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"; + sb_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"), + "

          This is a test

          \n" + "

          bola

          \n"); + assert_string_equal(sb_trie_lookup(source, "CONTENT"), + "

          This is a test

          \n" + "

          bola

          \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); } @@ -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), -- cgit v1.2.3-18-g5258 From c5e4f4c2d29831151bdce1802787b9cf012c3e5e Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:30:49 +0200 Subject: Revert "error: removed uneeded tests" This reverts commit 37592b57b31987519e59117d49bccd0207e67f15. --- tests/check_error.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/check_error.c b/tests/check_error.c index c990b45..7fc3c3e 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -19,6 +19,28 @@ #include +static void +test_error_new(void **state) +{ + sb_error_t *error = sb_error_new(1, "bola %s"); + assert_non_null(error); + assert_int_equal(error->code, 1); + assert_string_equal(error->msg, "bola %s"); + sb_error_free(error); +} + + +static void +test_error_new_printf(void **state) +{ + sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); + assert_non_null(error); + assert_int_equal(error->code, 2); + assert_string_equal(error->msg, "bola guda"); + sb_error_free(error); +} + + static void test_error_parser(void **state) { @@ -83,6 +105,8 @@ int main(void) { const UnitTest tests[] = { + unit_test(test_error_new), + unit_test(test_error_new_printf), unit_test(test_error_parser), unit_test(test_error_parser_crlf), }; -- cgit v1.2.3-18-g5258 From 6153580a13e7e7c48e38fa446572c8adcae08084 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:31:02 +0200 Subject: Revert "*: use squareball error infrastructure" This reverts commit a2b3551dfb9460470bd79f5648bf597c517c40d4. --- tests/check_datetime_parser.c | 216 +++++++++++++++++++++--------------------- tests/check_error.c | 44 ++++----- tests/check_loader.c | 30 +++--- tests/check_renderer.c | 40 ++++---- tests/check_source_parser.c | 122 ++++++++++++------------ tests/check_template_parser.c | 190 ++++++++++++++++++------------------- 6 files changed, 321 insertions(+), 321 deletions(-) (limited to 'tests') diff --git a/tests/check_datetime_parser.c b/tests/check_datetime_parser.c index aef366e..ba5a79d 100644 --- a/tests/check_datetime_parser.c +++ b/tests/check_datetime_parser.c @@ -24,7 +24,7 @@ static void test_convert_datetime(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -36,7 +36,7 @@ test_convert_datetime(void **state) static void test_convert_datetime_implicit_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -48,7 +48,7 @@ test_convert_datetime_implicit_seconds(void **state) static void test_convert_datetime_implicit_minutes(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -60,7 +60,7 @@ test_convert_datetime_implicit_minutes(void **state) static void test_convert_datetime_implicit_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -72,529 +72,529 @@ test_convert_datetime_implicit_hours(void **state) static void test_convert_datetime_invalid_formats(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("20", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '20', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("201", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '201', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-3", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-3', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 ", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 ', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:13:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("a010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2a10-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_3rd_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("20a0-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_4th_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("201a-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("1899-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid year. Found 1899, must be >= 1900."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_hyphen(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010 11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between year and month. Found ' ', must be '-'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_month(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-a1-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_month(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-1a-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_month(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-13-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid month. Found 13, must be >= 1 and <= 12."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_hyphen(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11 30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between month and day. Found ' ', must be '-'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_day(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-a0 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_day(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-3a 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_day(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-32 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid day. Found 32, must be >= 1 and <= 31."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_space(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30-12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between date and time. Found '-', must be ' ' " "(empty space)."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 a2:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 1a:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 24:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid hours. Found 24, must be >= 0 and <= 23."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_colon(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12 13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between hours and minutes. Found ' ', must be ':'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_minutes(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:a3:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_minutes(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:1a:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_colon(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13 14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between minutes and seconds. Found ' ', must be ':'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:a4", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:1a", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:69", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid seconds. Found 69, must be >= 0 and <= 60."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_format_long(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:14", "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" "yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk" @@ -613,7 +613,7 @@ test_convert_datetime_invalid_format_long(void **state) "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Failed to format DATE variable, FORMAT is too long: " "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" @@ -631,7 +631,7 @@ test_convert_datetime_invalid_format_long(void **state) "uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq" "gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj" "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg"); - sb_error_free(err); + blogc_error_free(err); } diff --git a/tests/check_error.c b/tests/check_error.c index 7fc3c3e..4effb08 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -22,22 +22,22 @@ static void test_error_new(void **state) { - sb_error_t *error = sb_error_new(1, "bola %s"); + blogc_error_t *error = blogc_error_new(1, "bola %s"); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "bola %s"); - sb_error_free(error); + blogc_error_free(error); } static void test_error_new_printf(void **state) { - sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); + blogc_error_t *error = blogc_error_new_printf(2, "bola %s", "guda"); assert_non_null(error); - assert_int_equal(error->code, 2); + assert_int_equal(error->type, 2); assert_string_equal(error->msg, "bola guda"); - sb_error_free(error); + blogc_error_free(error); } @@ -45,32 +45,32 @@ static void test_error_parser(void **state) { const char *a = "bola\nguda\nchunda\n"; - sb_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); + blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - sb_error_free(error); + blogc_error_free(error); a = ""; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10"); - sb_error_free(error); + blogc_error_free(error); } @@ -78,26 +78,26 @@ static void test_error_parser_crlf(void **state) { const char *a = "bola\r\nguda\r\nchunda\r\n"; - sb_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); + blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - sb_error_free(error); + blogc_error_free(error); } diff --git a/tests/check_loader.c b/tests/check_loader.c index c0e30df..a07376a 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -52,7 +52,7 @@ test_get_filename(void **state) char* -__wrap_blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) +__wrap_blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) { assert_null(*err); const char *_path = mock_type(const char*); @@ -78,7 +78,7 @@ __wrap_blogc_fprintf(FILE *stream, const char *format, ...) static void test_template_parse_from_file(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n")); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -92,7 +92,7 @@ test_template_parse_from_file(void **state) static void test_template_parse_from_file_null(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, NULL); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -104,7 +104,7 @@ test_template_parse_from_file_null(void **state) static void test_source_parse_from_file(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" @@ -127,7 +127,7 @@ test_source_parse_from_file(void **state) static void test_source_parse_from_file_null(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, NULL); sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); @@ -157,7 +157,7 @@ test_source_parse_from_files(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -201,7 +201,7 @@ test_source_parse_from_files_filter_by_tag(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -269,7 +269,7 @@ test_source_parse_from_files_filter_by_page(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -347,7 +347,7 @@ test_source_parse_from_files_filter_by_page2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -426,7 +426,7 @@ test_source_parse_from_files_filter_by_page3(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -509,7 +509,7 @@ test_source_parse_from_files_filter_by_page_and_tag(void **state) "TAGS: yay chunda\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -589,7 +589,7 @@ test_source_parse_from_files_filter_by_page_invalid(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -667,7 +667,7 @@ test_source_parse_from_files_filter_by_page_invalid2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -712,7 +712,7 @@ test_source_parse_from_files_without_all_dates(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -735,7 +735,7 @@ test_source_parse_from_files_without_all_dates(void **state) static void test_source_parse_from_files_null(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; 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); diff --git a/tests/check_renderer.c b/tests/check_renderer.c index d71f045..e863360 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -46,7 +46,7 @@ create_sources(unsigned int count) "ahahahahahahahaha3", }; assert_false(count > 3); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = NULL; for (unsigned int i = 0; i < count; i++) { l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err)); @@ -78,7 +78,7 @@ test_render_entry(void **state) "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -125,7 +125,7 @@ test_render_listing(void **state) "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -173,7 +173,7 @@ test_render_listing_empty(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -200,7 +200,7 @@ test_render_ifdef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -229,7 +229,7 @@ test_render_ifdef2(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -260,7 +260,7 @@ test_render_ifdef3(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -293,7 +293,7 @@ test_render_ifndef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -327,7 +327,7 @@ test_render_if_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -362,7 +362,7 @@ test_render_if_neq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -397,7 +397,7 @@ test_render_if_lt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -432,7 +432,7 @@ test_render_if_gt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -469,7 +469,7 @@ test_render_if_lt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -508,7 +508,7 @@ test_render_if_gt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -539,7 +539,7 @@ test_render_foreach(void **state) "{% block entry %}\n" "{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -564,7 +564,7 @@ test_render_foreach_if(void **state) "{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}" "{% endif %} {% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -595,7 +595,7 @@ test_render_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}lol{% endif %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -628,7 +628,7 @@ test_render_prefer_local_variable(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -664,7 +664,7 @@ test_render_respect_variable_scope(void **state) "{% ifdef LOL %}{{ LOL }}{% endif %}\n" "{% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -696,7 +696,7 @@ test_render_ifcount_bug(void **state) "{% ifdef ASD %}ASD{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index a2a3ddc..0f891dd 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -30,7 +30,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -62,7 +62,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -96,7 +96,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -133,7 +133,7 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -199,13 +199,13 @@ static void test_source_parse_config_empty(void **state) { const char *a = ""; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your source file is empty."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -214,14 +214,14 @@ static void test_source_parse_config_invalid_key(void **state) { const char *a = "bola: guda"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + 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"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -230,14 +230,14 @@ static void test_source_parse_config_no_key(void **state) { const char *a = "BOLa"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + 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"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -246,14 +246,14 @@ static void test_source_parse_config_no_key2(void **state) { const char *a = "BOLA"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + 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"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -262,15 +262,15 @@ static void test_source_parse_config_no_value(void **state) { const char *a = "BOLA:\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -279,15 +279,15 @@ static void test_source_parse_config_no_value2(void **state) { const char *a = "BOLA:"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -296,15 +296,15 @@ static void test_source_parse_config_reserved_name(void **state) { const char *a = "FILENAME: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'FILENAME' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -313,15 +313,15 @@ static void test_source_parse_config_reserved_name2(void **state) { const char *a = "CONTENT: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'CONTENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -330,15 +330,15 @@ static void test_source_parse_config_reserved_name3(void **state) { const char *a = "DATE_FORMATTED: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -347,15 +347,15 @@ static void test_source_parse_config_reserved_name4(void **state) { const char *a = "DATE_FIRST_FORMATTED: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -364,15 +364,15 @@ static void test_source_parse_config_reserved_name5(void **state) { const char *a = "DATE_LAST_FORMATTED: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -381,15 +381,15 @@ static void test_source_parse_config_reserved_name6(void **state) { const char *a = "PAGE_FIRST: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_FIRST' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -398,15 +398,15 @@ static void test_source_parse_config_reserved_name7(void **state) { const char *a = "PAGE_PREVIOUS: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -415,15 +415,15 @@ static void test_source_parse_config_reserved_name8(void **state) { const char *a = "PAGE_CURRENT: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_CURRENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -432,15 +432,15 @@ static void test_source_parse_config_reserved_name9(void **state) { const char *a = "PAGE_NEXT: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_NEXT' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -449,15 +449,15 @@ static void test_source_parse_config_reserved_name10(void **state) { const char *a = "PAGE_LAST: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_LAST' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -466,15 +466,15 @@ static void test_source_parse_config_reserved_name11(void **state) { const char *a = "BLOGC_VERSION: 1.0\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'BLOGC_VERSION' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -483,15 +483,15 @@ static void test_source_parse_config_value_no_line_ending(void **state) { const char *a = "BOLA: asd"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "No line ending after the configuration value for 'BOLA'.\n" "Error occurred near line 1, position 10: BOLA: asd"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -500,15 +500,15 @@ static void test_source_parse_invalid_separator(void **state) { const char *a = "BOLA: asd\n---#"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid content separator. Must be more than one '-' characters.\n" "Error occurred near line 2, position 4: ---#"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index 9419607..ed4328b 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -63,7 +63,7 @@ test_template_parse(void **state) "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -143,7 +143,7 @@ test_template_parse_crlf(void **state) "{% block listing_once %}asd{% endblock %}\r\n" "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -231,7 +231,7 @@ test_template_parse_html(void **state) " {% block listing_once %}
    {% endblock %}\n" " \n" "\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -341,7 +341,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -372,35 +372,35 @@ static void test_template_parse_invalid_block_start(void **state) { const char *a = "{% ASD %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 4: {% ASD %}"); - sb_error_free(err); + blogc_error_free(err); a = "{%-- block entry %}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" "Error occurred near line 1, position 4: {%-- block entry %}"); - sb_error_free(err); + blogc_error_free(err); a = "{% block entry --%}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" "Error occurred near line 1, position 17: {% block entry --%}"); - sb_error_free(err); + blogc_error_free(err); } @@ -410,15 +410,15 @@ test_template_parse_invalid_block_nested(void **state) const char *a = "{% block entry %}\n" "{% block listing %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Blocks can't be nested.\n" "Error occurred near line 2, position 9: {% block listing %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -428,15 +428,15 @@ test_template_parse_invalid_foreach_nested(void **state) const char *a = "{% foreach A %}\n" "{% foreach B %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'foreach' statements can't be nested.\n" "Error occurred near line 2, position 11: {% foreach B %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -444,15 +444,15 @@ static void test_template_parse_invalid_block_not_open(void **state) { const char *a = "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endblock' statement without an open 'block' statement.\n" "Error occurred near line 1, position 12: {% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -460,16 +460,16 @@ static void test_template_parse_invalid_endif_not_open(void **state) { const char *a = "{% block listing %}{% endif %}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endif' statement without an open 'ifdef' or 'ifndef' statement.\n" "Error occurred near line 1, position 28: " "{% block listing %}{% endif %}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -477,15 +477,15 @@ static void test_template_parse_invalid_endforeach_not_open(void **state) { const char *a = "{% endforeach %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endforeach' statement without an open 'foreach' statement.\n" "Error occurred near line 1, position 14: {% endforeach %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -493,16 +493,16 @@ static void test_template_parse_invalid_block_name(void **state) { const char *a = "{% chunda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement type: Allowed types are: 'block', 'endblock', 'ifdef', " "'ifndef', 'endif', 'foreach' and 'endforeach'.\n" "Error occurred near line 1, position 10: {% chunda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -510,15 +510,15 @@ static void test_template_parse_invalid_block_type_start(void **state) { const char *a = "{% block ENTRY %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 10: {% block ENTRY %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -526,15 +526,15 @@ static void test_template_parse_invalid_block_type(void **state) { const char *a = "{% block chunda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -542,16 +542,16 @@ static void test_template_parse_invalid_ifdef_start(void **state) { const char *a = "{% block entry %}{% ifdef guda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef guda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -559,16 +559,16 @@ static void test_template_parse_invalid_foreach_start(void **state) { const char *a = "{% block entry %}{% foreach guda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% foreach guda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -576,16 +576,16 @@ static void test_template_parse_invalid_ifdef_variable(void **state) { const char *a = "{% block entry %}{% ifdef BoLA %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 28: " "{% block entry %}{% ifdef BoLA %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -593,16 +593,16 @@ static void test_template_parse_invalid_ifdef_variable2(void **state) { const char *a = "{% block entry %}{% ifdef 0123 %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef 0123 %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -610,16 +610,16 @@ static void test_template_parse_invalid_foreach_variable(void **state) { const char *a = "{% block entry %}{% foreach BoLA %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 30: " "{% block entry %}{% foreach BoLA %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -627,16 +627,16 @@ static void test_template_parse_invalid_foreach_variable2(void **state) { const char *a = "{% block entry %}{% foreach 0123 %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: {% block entry %}" "{% foreach 0123 %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -644,16 +644,16 @@ static void test_template_parse_invalid_if_operator(void **state) { const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% if BOLA = \"asd\" %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -661,16 +661,16 @@ static void test_template_parse_invalid_if_operand(void **state) { const char *a = "{% block entry %}{% if BOLA == asd %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == asd %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -678,16 +678,16 @@ static void test_template_parse_invalid_if_operand2(void **state) { const char *a = "{% block entry %}{% if BOLA == \"asd %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Found an open double-quoted string.\n" "Error occurred near line 1, position 31: " "{% block entry %}{% if BOLA == \"asd %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -695,16 +695,16 @@ static void test_template_parse_invalid_if_operand3(void **state) { const char *a = "{% block entry %}{% if BOLA == 0123 %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == 0123 %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -712,15 +712,15 @@ static void test_template_parse_invalid_block_end(void **state) { const char *a = "{% block entry }}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '%}'.\n" "Error occurred near line 1, position 16: {% block entry }}"); - sb_error_free(err); + blogc_error_free(err); } @@ -728,16 +728,16 @@ static void test_template_parse_invalid_variable_name(void **state) { const char *a = "{% block entry %}{{ bola }}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: " "{% block entry %}{{ bola }}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -745,16 +745,16 @@ static void test_template_parse_invalid_variable_name2(void **state) { const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 22: " "{% block entry %}{{ Bola }}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -762,16 +762,16 @@ static void test_template_parse_invalid_variable_name3(void **state) { const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}" "{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -779,16 +779,16 @@ static void test_template_parse_invalid_variable_end(void **state) { const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}}'.\n" "Error occurred near line 1, position 26: " "{% block entry %}{{ BOLA %}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -796,15 +796,15 @@ static void test_template_parse_invalid_close(void **state) { const char *a = "{% block entry %%\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 17: {% block entry %%"); - sb_error_free(err); + blogc_error_free(err); } @@ -812,16 +812,16 @@ static void test_template_parse_invalid_close2(void **state) { const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 27: " "{% block entry %}{{ BOLA }%{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -829,14 +829,14 @@ static void test_template_parse_invalid_if_not_closed(void **state) { const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "1 open 'ifdef' and/or 'ifndef' statements " "were not closed!"); - sb_error_free(err); + blogc_error_free(err); } @@ -844,13 +844,13 @@ static void test_template_parse_invalid_block_not_closed(void **state) { const char *a = "{% block entry %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open block was not closed!"); - sb_error_free(err); + blogc_error_free(err); } @@ -858,13 +858,13 @@ static void test_template_parse_invalid_foreach_not_closed(void **state) { const char *a = "{% foreach ASD %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open 'foreach' statement was not closed!"); - sb_error_free(err); + blogc_error_free(err); } -- cgit v1.2.3-18-g5258 From 74b2ee22a6b60d53b1241e0c52284b288e561599 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:38:10 +0200 Subject: moved squareball back to blogc source tree. i don't have enough time to maintain a separated library at this point, and worry about soname bump, library stability, etc. all the code is trivial enough to be copied around, and all the utils are implemented as single file now, to make it easier to copy. --- tests/check_source_parser.c | 2 +- tests/check_utils.c | 959 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 960 insertions(+), 1 deletion(-) create mode 100644 tests/check_utils.c (limited to 'tests') diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 0f891dd..477399c 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -173,7 +173,7 @@ test_source_parse_with_description(void **state) "# This is a test\n" "\n" "bola\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); diff --git a/tests/check_utils.c b/tests/check_utils.c new file mode 100644 index 0000000..6a6ceca --- /dev/null +++ b/tests/check_utils.c @@ -0,0 +1,959 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2014-2016 Rafael G. Martins + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include + +#include + +#include "../src/utils.h" + +#define SB_STRING_CHUNK_SIZE 128 + + +static void +test_slist_append(void **state) +{ + 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 = 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); + 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) +{ + 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"); + free(t1); + free(t2); + free(t3); +} + + +static void +test_slist_length(void **state) +{ + 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 = sb_strdup("bola"); + assert_string_equal(str, "bola"); + free(str); + str = sb_strdup(NULL); + assert_null(str); +} + + +static void +test_strndup(void **state) +{ + char *str = sb_strndup("bolaguda", 4); + assert_string_equal(str, "bola"); + free(str); + str = sb_strndup("bolaguda", 30); + assert_string_equal(str, "bolaguda"); + free(str); + str = sb_strndup("bolaguda", 8); + assert_string_equal(str, "bolaguda"); + free(str); + str = sb_strdup(NULL); + assert_null(str); +} + + +static void +test_strdup_printf(void **state) +{ + char *str = sb_strdup_printf("bola"); + assert_string_equal(str, "bola"); + free(str); + str = sb_strdup_printf("bola, %s", "guda"); + assert_string_equal(str, "bola, guda"); + free(str); +} + + +static void +test_str_starts_with(void **state) +{ + 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(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 = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_lstrip(str), "bola\n \t"); + free(str); + str = sb_strdup("guda"); + assert_string_equal(sb_str_lstrip(str), "guda"); + free(str); + str = sb_strdup("\n"); + assert_string_equal(sb_str_lstrip(str), ""); + free(str); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_lstrip(str), ""); + free(str); + str = sb_strdup(""); + assert_string_equal(sb_str_lstrip(str), ""); + free(str); + assert_null(sb_str_lstrip(NULL)); +} + + +static void +test_str_rstrip(void **state) +{ + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_rstrip(str), " \tbola"); + free(str); + str = sb_strdup("guda"); + assert_string_equal(sb_str_rstrip(str), "guda"); + free(str); + str = sb_strdup("\n"); + assert_string_equal(sb_str_rstrip(str), ""); + free(str); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_rstrip(str), ""); + free(str); + str = sb_strdup(""); + assert_string_equal(sb_str_rstrip(str), ""); + free(str); + assert_null(sb_str_rstrip(NULL)); +} + + +static void +test_str_strip(void **state) +{ + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_strip(str), "bola"); + free(str); + str = sb_strdup("guda"); + assert_string_equal(sb_str_strip(str), "guda"); + free(str); + str = sb_strdup("\n"); + assert_string_equal(sb_str_strip(str), ""); + free(str); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_strip(str), ""); + free(str); + str = sb_strdup(""); + assert_string_equal(sb_str_strip(str), ""); + free(str); + assert_null(sb_str_strip(NULL)); +} + + +static void +test_str_split(void **state) +{ + 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]); + 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]); + sb_strv_free(strv); + strv = sb_str_split("bola:guda:chunda", ':', 1); + assert_string_equal(strv[0], "bola:guda:chunda"); + assert_null(strv[1]); + sb_strv_free(strv); + strv = sb_str_split("", ':', 1); + assert_null(strv[0]); + sb_strv_free(strv); + assert_null(sb_str_split(NULL, ':', 0)); +} + + +static void +test_str_replace(void **state) +{ + char *str = sb_str_replace("bolao", 'o', "zaz"); + assert_string_equal(str, "bzazlazaz"); + free(str); + 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) +{ + char *pieces[] = {"guda","bola", "chunda", NULL}; + char *str = sb_strv_join(pieces, ":"); + assert_string_equal(str, "guda:bola:chunda"); + free(str); + char *pieces2[] = {NULL}; + str = sb_strv_join(pieces2, ":"); + assert_string_equal(str, ""); + free(str); + assert_null(sb_strv_join(pieces, NULL)); + assert_null(sb_strv_join(NULL, ":")); + assert_null(sb_strv_join(NULL, NULL)); +} + + +static void +test_strv_length(void **state) +{ + char *pieces[] = {"guda","bola", "chunda", NULL}; + assert_int_equal(sb_strv_length(pieces), 3); + char *pieces2[] = {NULL}; + assert_int_equal(sb_strv_length(pieces2), 0); + assert_int_equal(sb_strv_length(NULL), 0); +} + + +static void +test_string_new(void **state) +{ + 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, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); +} + + +static void +test_string_free(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; + 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) +{ + 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, 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, 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, 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" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); + str = sb_string_append_len(str, NULL, 0); + str = sb_string_append_len(str, + "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" + "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" + "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); + assert_non_null(str); + assert_string_equal(str->str, + "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" + "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" + "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" + "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" + "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" + "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" + "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" + "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" + "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" + "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" + "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" + "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" + "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" + "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" + "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" + "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" + "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" + "fkeannglvsxprqzfekdinssqymtfexf"); + assert_int_equal(str->len, 1204); + 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) +{ + 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, 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, 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" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); + str = sb_string_append(str, NULL); + str = sb_string_append(str, + "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" + "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" + "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); + assert_non_null(str); + assert_string_equal(str->str, + "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" + "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" + "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" + "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" + "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" + "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" + "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" + "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" + "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" + "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" + "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" + "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" + "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" + "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" + "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" + "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" + "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" + "fkeannglvsxprqzfekdinssqymtfexf"); + assert_int_equal(str->len, 1204); + 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) +{ + sb_string_t *str = sb_string_new(); + str = sb_string_append_len(str, "guda", 4); + for (int i = 0; i < 600; i++) + str = sb_string_append_c(str, 'c'); + assert_non_null(str); + assert_string_equal(str->str, + "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "cccccccccccccccccccccccccccccccccccccccccccccccccccc"); + assert_int_equal(str->len, 604); + 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) +{ + 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, 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) +{ + sb_trie_t *trie = sb_trie_new(free); + assert_non_null(trie); + assert_null(trie->root); + assert_true(trie->free_func == free); + sb_trie_free(trie); +} + + +static void +test_trie_insert(void **state) +{ + sb_trie_t *trie = sb_trie_new(free); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->key == 'c'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'h'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'u'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->data, "nda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->key == 'c'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'h'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'u'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->data, "nda"); + + assert_true(trie->root->child->child->next->key == 't'); + assert_null(trie->root->child->child->next->data); + assert_true(trie->root->child->child->next->child->key == 'e'); + assert_null(trie->root->child->child->next->child->data); + assert_true(trie->root->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->key == 'c'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'h'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'u'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->data, "nda"); + + assert_true(trie->root->child->child->next->key == 't'); + assert_null(trie->root->child->child->next->data); + assert_true(trie->root->child->child->next->child->key == 'e'); + assert_null(trie->root->child->child->next->child->data); + assert_true(trie->root->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); + + assert_true(trie->root->child->child->next->next->key == '\0'); + assert_string_equal(trie->root->child->child->next->next->data, "haha"); + + sb_trie_free(trie); + + + trie = sb_trie_new(free); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + assert_true(trie->root->next->key == 'b'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'o'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'l'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == 'a'); + assert_null(trie->root->next->child->child->child->data); + assert_true(trie->root->next->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + assert_true(trie->root->next->key == 'b'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'o'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'l'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == 'a'); + assert_null(trie->root->next->child->child->child->data); + assert_true(trie->root->next->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->child->child->next->key == 't'); + assert_null(trie->root->next->child->child->next->data); + assert_true(trie->root->next->child->child->next->child->key == 'e'); + assert_null(trie->root->next->child->child->next->child->data); + assert_true(trie->root->next->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + assert_true(trie->root->next->key == 'b'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'o'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'l'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == 'a'); + assert_null(trie->root->next->child->child->child->data); + assert_true(trie->root->next->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->child->child->next->key == 't'); + assert_null(trie->root->next->child->child->next->data); + assert_true(trie->root->next->child->child->next->child->key == 'e'); + assert_null(trie->root->next->child->child->next->child->data); + assert_true(trie->root->next->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); + + assert_true(trie->root->next->child->child->next->next->key == '\0'); + assert_string_equal(trie->root->next->child->child->next->next->data, "haha"); + + sb_trie_free(trie); +} + + +static void +test_trie_insert_duplicated(void **state) +{ + sb_trie_t *trie = sb_trie_new(free); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "asdf"); + + sb_trie_free(trie); + + trie = NULL; + sb_trie_insert(trie, "bola", NULL); + assert_null(trie); +} + + +static void +test_trie_keep_data(void **state) +{ + sb_trie_t *trie = sb_trie_new(NULL); + + char *t1 = "guda"; + char *t2 = "nda"; + char *t3 = "aba"; + char *t4 = "haha"; + + sb_trie_insert(trie, "bola", t1); + sb_trie_insert(trie, "chu", t2); + sb_trie_insert(trie, "bote", t3); + sb_trie_insert(trie, "bo", t4); + + sb_trie_free(trie); + + assert_string_equal(t1, "guda"); + assert_string_equal(t2, "nda"); + assert_string_equal(t3, "aba"); + assert_string_equal(t4, "haha"); +} + + +static void +test_trie_lookup(void **state) +{ + 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")); + + 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_null(sb_trie_lookup(trie, "arcoiro")); + + sb_trie_free(trie); + + trie = sb_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")); + + 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_null(sb_trie_lookup(trie, "arcoiro")); + + sb_trie_free(trie); + + assert_null(sb_trie_lookup(NULL, "bola")); +} + + +static void +test_trie_size(void **state) +{ + 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")); + + assert_int_equal(sb_trie_size(trie), 4); + assert_int_equal(sb_trie_size(NULL), 0); + + sb_trie_free(trie); + + trie = sb_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")); + + assert_int_equal(sb_trie_size(trie), 7); + assert_int_equal(sb_trie_size(NULL), 0); + + sb_trie_free(trie); +} + + +static unsigned int counter; +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, void *user_data) +{ + assert_string_equal(user_data, "foo"); + assert_string_equal(key, expected_keys[counter]); + assert_string_equal((char*) data, expected_datas[counter++]); +} + + +static void +test_trie_foreach(void **state) +{ + sb_trie_t *trie = sb_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")); + + counter = 0; + 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"); + + sb_trie_free(trie); +} + + +int +main(void) +{ + const UnitTest tests[] = { + + // slist + unit_test(test_slist_append), + unit_test(test_slist_prepend), + unit_test(test_slist_free), + unit_test(test_slist_length), + + // strfuncs + unit_test(test_strdup), + unit_test(test_strndup), + unit_test(test_strdup_printf), + unit_test(test_str_starts_with), + unit_test(test_str_ends_with), + unit_test(test_str_lstrip), + unit_test(test_str_rstrip), + unit_test(test_str_strip), + unit_test(test_str_split), + 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), + unit_test(test_string_append_printf), + + // trie + unit_test(test_trie_new), + unit_test(test_trie_insert), + unit_test(test_trie_insert_duplicated), + unit_test(test_trie_keep_data), + unit_test(test_trie_lookup), + unit_test(test_trie_size), + unit_test(test_trie_foreach), + }; + return run_tests(tests); +} -- cgit v1.2.3-18-g5258 From 9699bf0ce6b34c0d05c509925f3367f2200caad5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 02:34:19 +0200 Subject: remove squareball for good --- tests/check_content_parser.c | 2 +- tests/check_error.c | 2 +- tests/check_loader.c | 2 +- tests/check_renderer.c | 2 +- tests/check_source_parser.c | 2 +- tests/check_template_parser.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 0eaab70..2444ebb 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -16,7 +16,7 @@ #include #include #include "../src/content-parser.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_error.c b/tests/check_error.c index 4effb08..8818b00 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -16,7 +16,7 @@ #include #include #include "../src/error.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_loader.c b/tests/check_loader.c index a07376a..4a5dc32 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -18,7 +18,7 @@ #include #include "../src/template-parser.h" #include "../src/loader.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_renderer.c b/tests/check_renderer.c index e863360..13e7309 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -19,7 +19,7 @@ #include "../src/renderer.h" #include "../src/source-parser.h" #include "../src/template-parser.h" -#include +#include "../src/utils.h" static sb_slist_t* diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 477399c..d94dc70 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -17,7 +17,7 @@ #include #include "../src/source-parser.h" #include "../src/error.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index ed4328b..40a09be 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -17,7 +17,7 @@ #include #include "../src/template-parser.h" #include "../src/error.h" -#include +#include "../src/utils.h" static void -- cgit v1.2.3-18-g5258