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