aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-12-23 23:45:54 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-12-23 23:45:54 +0100
commit14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6 (patch)
tree31b3d9a6f9f6144b08b852d016b5b4bdfce553ef /tests
parent8e62072d91193b4894adda9c40544c18c1a01f57 (diff)
downloadblogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.tar.gz
blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.tar.bz2
blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.zip
Revert "build: removing src/utils and replacing with squareball"
This reverts commit 950e6c9148eca244a89d18a21d4ae4e5c3d1c646.
Diffstat (limited to 'tests')
-rw-r--r--tests/check_content_parser.c2
-rw-r--r--tests/check_error.c2
-rw-r--r--tests/check_loader.c544
-rw-r--r--tests/check_renderer.c224
-rw-r--r--tests/check_source_parser.c142
-rw-r--r--tests/check_template_parser.c62
-rw-r--r--tests/check_utils.c824
7 files changed, 1312 insertions, 488 deletions
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index 545a1c4..dc3485e 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -16,7 +16,7 @@
#include <cmocka.h>
#include <string.h>
#include "../src/content-parser.h"
-#include <squareball.h>
+#include "../src/utils/utils.h"
static void
diff --git a/tests/check_error.c b/tests/check_error.c
index ea339d6..17e1c40 100644
--- a/tests/check_error.c
+++ b/tests/check_error.c
@@ -16,7 +16,7 @@
#include <cmocka.h>
#include <string.h>
#include "../src/error.h"
-#include <squareball.h>
+#include "../src/utils/utils.h"
static void
diff --git a/tests/check_loader.c b/tests/check_loader.c
index 243b7d5..f5be3e7 100644
--- a/tests/check_loader.c
+++ b/tests/check_loader.c
@@ -18,7 +18,7 @@
#include <stdio.h>
#include "../src/template-parser.h"
#include "../src/loader.h"
-#include <squareball.h>
+#include "../src/utils/utils.h"
static void
@@ -80,11 +80,11 @@ test_template_parse_from_file(void **state)
{
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola");
- will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n"));
- sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ will_return(__wrap_blogc_file_get_contents, b_strdup("{{ BOLA }}\n"));
+ b_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_non_null(l);
- assert_int_equal(sb_slist_length(l), 2);
+ assert_int_equal(b_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);
- sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(sb_trie_size(t), 5);
- assert_string_equal(sb_trie_lookup(t, "ASD"), "123");
- assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola");
- assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola");
- sb_trie_free(t);
+ assert_int_equal(b_trie_size(t), 5);
+ assert_string_equal(b_trie_lookup(t, "ASD"), "123");
+ assert_string_equal(b_trie_lookup(t, "FILENAME"), "bola");
+ assert_string_equal(b_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
+ assert_string_equal(b_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
+ assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola");
+ b_trie_free(t);
}
@@ -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);
- sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"TAGS: yay, chunda\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_null(t);
- sb_trie_free(c);
- sb_slist_free_full(s, free);
+ b_trie_free(c);
+ b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_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, sb_strdup(
+ will_return(__wrap_blogc_file_get_contents, b_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- s = sb_slist_append(s, sb_strdup("bola1.txt"));
- s = sb_slist_append(s, sb_strdup("bola2.txt"));
- 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);
+ 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);
assert_null(err);
assert_non_null(t);
- 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);
+ 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);
}
@@ -735,16 +735,16 @@ static void
test_source_parse_from_files_null(void **state)
{
blogc_error_t *err = NULL;
- sb_slist_t *s = NULL;
- sb_trie_t *c = sb_trie_new(free);
- sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ 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);
assert_null(err);
assert_null(t);
- 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);
+ 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);
}
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index 802b159..cb8f8f1 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 <squareball.h>
+#include "../src/utils/utils.h"
-static sb_slist_t*
+static b_slist_t*
create_sources(unsigned int count)
{
const char *s[] = {
@@ -46,12 +46,12 @@ create_sources(unsigned int count)
};
assert_false(count > 3);
blogc_error_t *err = NULL;
- sb_slist_t *l = NULL;
+ b_slist_t *l = NULL;
for (unsigned int i = 0; i < count; i++) {
- l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
+ l = b_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
assert_null(err);
}
- assert_int_equal(sb_slist_length(l), count);
+ assert_int_equal(b_slist_length(l), count);
return l;
}
@@ -76,10 +76,10 @@ test_render_entry(void **state)
"{% if GUDA > \"zxd\" %}LOL3{% endif %}\n"
"{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -99,7 +99,7 @@ test_render_entry(void **state)
"\n"
"LOL4\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -119,10 +119,10 @@ test_render_listing(void **state)
"bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(3);
+ b_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, true);
assert_string_equal(out,
@@ -140,7 +140,7 @@ test_render_listing(void **state)
"bola: asd3\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -160,7 +160,7 @@ test_render_listing_empty(void **state)
"bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_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);
@@ -187,10 +187,10 @@ test_render_ifdef(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -198,7 +198,7 @@ test_render_ifdef(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -216,10 +216,10 @@ test_render_ifdef2(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -229,7 +229,7 @@ test_render_ifdef2(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -247,10 +247,10 @@ test_render_ifdef3(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -262,7 +262,7 @@ test_render_ifdef3(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -280,10 +280,10 @@ test_render_ifndef(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -295,7 +295,7 @@ test_render_ifndef(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -314,10 +314,10 @@ test_render_if_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -330,7 +330,7 @@ test_render_if_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -349,10 +349,10 @@ test_render_if_neq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -365,7 +365,7 @@ test_render_if_neq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -384,10 +384,10 @@ test_render_if_lt(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -400,7 +400,7 @@ test_render_if_lt(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -419,10 +419,10 @@ test_render_if_gt(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -435,7 +435,7 @@ test_render_if_gt(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -456,10 +456,10 @@ test_render_if_lt_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -474,7 +474,7 @@ test_render_if_lt_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -495,10 +495,10 @@ test_render_if_gt_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -513,7 +513,7 @@ test_render_if_gt_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -533,21 +533,21 @@ test_render_outside_block(void **state)
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}lol{% endif %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
- sb_trie_t *c = sb_trie_new(free);
- sb_trie_insert(c, "GUDA", sb_strdup("asd"));
+ b_trie_t *c = b_trie_new(free);
+ b_trie_insert(c, "GUDA", b_strdup("asd"));
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"bola\n"
"\n"
"lol\n");
- sb_trie_free(c);
+ b_trie_free(c);
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -566,14 +566,14 @@ test_render_prefer_local_variable(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
- sb_trie_t *c = sb_trie_new(free);
- sb_trie_insert(c, "GUDA", sb_strdup("hehe"));
- sb_trie_insert(c, "LOL", sb_strdup("hmm"));
+ b_trie_t *c = b_trie_new(free);
+ b_trie_insert(c, "GUDA", b_strdup("hehe"));
+ b_trie_insert(c, "LOL", b_strdup("hmm"));
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
@@ -584,9 +584,9 @@ test_render_prefer_local_variable(void **state)
"\n"
"\n"
"\n");
- sb_trie_free(c);
+ b_trie_free(c);
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -602,12 +602,12 @@ test_render_respect_variable_scope(void **state)
"{% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- sb_slist_t *s = create_sources(1);
+ b_slist_t *s = create_sources(1);
assert_non_null(s);
- sb_trie_t *c = sb_trie_new(free);
+ b_trie_t *c = b_trie_new(free);
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
@@ -616,9 +616,9 @@ test_render_respect_variable_scope(void **state)
"\n"
"asd\n"
"\n");
- sb_trie_free(c);
+ b_trie_free(c);
blogc_template_free_stmts(l);
- sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
free(out);
}
@@ -626,112 +626,112 @@ test_render_respect_variable_scope(void **state)
static void
test_get_variable(void **state)
{
- 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"));
+ 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"));
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));
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
static void
test_get_variable_only_local(void **state)
{
- 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"));
+ 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"));
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));
- sb_trie_free(l);
+ b_trie_free(l);
}
static void
test_get_variable_only_global(void **state)
{
- 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;
+ 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;
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));
- sb_trie_free(g);
+ b_trie_free(g);
}
static void
test_format_date(void **state)
{
- 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"));
+ 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"));
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03:04");
free(date);
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
static void
test_format_date_with_global_format(void **state)
{
- 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);
+ 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);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03 -- 04");
free(date);
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
static void
test_format_date_without_format(void **state)
{
- sb_trie_t *g = sb_trie_new(free);
- sb_trie_t *l = sb_trie_new(free);
+ b_trie_t *g = b_trie_new(free);
+ b_trie_t *l = b_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);
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
static void
test_format_date_without_date(void **state)
{
- sb_trie_t *g = sb_trie_new(free);
- sb_trie_t *l = sb_trie_new(free);
+ b_trie_t *g = b_trie_new(free);
+ b_trie_t *l = b_trie_new(free);
char *date = blogc_format_date(NULL, g, l);
assert_null(date);
free(date);
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
static void
test_format_variable(void **state)
{
- 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"));
+ 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"));
char *tmp = blogc_format_variable("NAME", g, l);
assert_string_equal(tmp, "chunda");
free(tmp);
@@ -739,24 +739,24 @@ test_format_variable(void **state)
assert_string_equal(tmp, "chunda2");
free(tmp);
assert_null(blogc_format_variable("BOLA", g, l));
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
static void
test_format_variable_with_date(void **state)
{
- 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"));
+ 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"));
char *tmp = blogc_format_variable("DATE_FORMATTED", g, l);
assert_string_equal(tmp, "14:15");
free(tmp);
- sb_trie_free(g);
- sb_trie_free(l);
+ b_trie_free(g);
+ b_trie_free(l);
}
diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c
index 686a228..4d8518e 100644
--- a/tests/check_source_parser.c
+++ b/tests/check_source_parser.c
@@ -17,7 +17,7 @@
#include <string.h>
#include "../src/source-parser.h"
#include "../src/error.h"
-#include <squareball.h>
+#include "../src/utils/utils.h"
static void
@@ -31,23 +31,23 @@ test_source_parse(void **state)
"\n"
"bola\n";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
- assert_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"),
+ 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"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(source, "CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -62,23 +62,23 @@ test_source_parse_crlf(void **state)
"\r\n"
"bola\r\n";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
- assert_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"),
+ 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"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(sb_trie_lookup(source, "CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\r\n"
"\r\n"
"bola\r\n");
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -95,23 +95,23 @@ test_source_parse_with_spaces(void **state)
"\n"
"bola\n";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
- assert_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"),
+ 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"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(source, "CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -131,21 +131,21 @@ test_source_parse_with_excerpt(void **state)
"guda\n"
"yay";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
- assert_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"),
+ 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"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(sb_trie_lookup(source, "CONTENT"),
+ assert_string_equal(b_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n"
"<p>guda\n"
"yay</p>\n");
- assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(b_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");
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -163,13 +163,13 @@ test_source_parse_config_empty(void **state)
{
const char *a = "";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -194,14 +194,14 @@ test_source_parse_config_no_key(void **state)
{
const char *a = "BOLa";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -210,14 +210,14 @@ test_source_parse_config_no_key2(void **state)
{
const char *a = "BOLA";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_trie_free(source);
}
@@ -243,7 +243,7 @@ test_source_parse_config_no_value2(void **state)
{
const char *a = "BOLA:";
blogc_error_t *err = NULL;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_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;
- sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ b_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);
- sb_trie_free(source);
+ b_trie_free(source);
}
diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c
index 0e42976..b712f22 100644
--- a/tests/check_template_parser.c
+++ b/tests/check_template_parser.c
@@ -17,11 +17,11 @@
#include <string.h>
#include "../src/template-parser.h"
#include "../src/error.h"
-#include <squareball.h>
+#include "../src/utils/utils.h"
static void
-blogc_assert_template_stmt(sb_slist_t *l, const char *value,
+blogc_assert_template_stmt(b_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(sb_slist_t *l, const char *value,
static void
-blogc_assert_template_if_stmt(sb_slist_t *l, const char *variable,
+blogc_assert_template_if_stmt(b_slist_t *l, const char *variable,
blogc_template_stmt_operator_t operator, const char *operand)
{
blogc_template_stmt_t *stmt = l->data;
@@ -63,7 +63,7 @@ test_template_parse(void **state)
"{% block listing_once %}asd{% endblock %}\n"
"{% if BOLA == \"1\\\"0\" %}aee{% endif %}";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "Test\n\n ",
@@ -80,7 +80,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);
- sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ b_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\n", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
@@ -133,7 +133,7 @@ test_template_parse_crlf(void **state)
"{% block listing_once %}asd{% endblock %}\r\n"
"{% if BOLA == \"1\\\"0\" %}aee{% endif %}";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "Test\r\n\r\n ",
@@ -150,7 +150,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);
- sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ b_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\r\n", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
@@ -212,7 +212,7 @@ test_template_parse_html(void **state)
" </body>\n"
"</html>\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "<html>\n <head>\n ",
@@ -231,7 +231,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);
- sb_slist_t *tmp = stmts->next->next->next->next->next->next->next->next;
+ b_slist_t *tmp = stmts->next->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_CONTENT_STMT);
@@ -322,7 +322,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -338,7 +338,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);
- sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ b_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",
@@ -353,7 +353,7 @@ test_template_parse_invalid_block_start(void **state)
{
const char *a = "{% ASD %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -371,7 +371,7 @@ test_template_parse_invalid_block_nested(void **state)
"{% block entry %}\n"
"{% block listing %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -387,7 +387,7 @@ test_template_parse_invalid_block_not_open(void **state)
{
const char *a = "{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -403,7 +403,7 @@ test_template_parse_invalid_endif_not_open(void **state)
{
const char *a = "{% block listing %}{% endif %}{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -420,7 +420,7 @@ test_template_parse_invalid_block_name(void **state)
{
const char *a = "{% chunda %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -437,7 +437,7 @@ test_template_parse_invalid_block_type_start(void **state)
{
const char *a = "{% block ENTRY %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -453,7 +453,7 @@ test_template_parse_invalid_block_type(void **state)
{
const char *a = "{% block chunda %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -469,7 +469,7 @@ test_template_parse_invalid_ifdef_start(void **state)
{
const char *a = "{% block entry %}{% ifdef guda %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -486,7 +486,7 @@ test_template_parse_invalid_ifdef_variable(void **state)
{
const char *a = "{% block entry %}{% ifdef BoLA %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -503,7 +503,7 @@ test_template_parse_invalid_if_operator(void **state)
{
const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -520,7 +520,7 @@ test_template_parse_invalid_if_operand(void **state)
{
const char *a = "{% block entry %}{% if BOLA == asd %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -537,7 +537,7 @@ test_template_parse_invalid_if_operand2(void **state)
{
const char *a = "{% block entry %}{% if BOLA == \"asd %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -554,7 +554,7 @@ test_template_parse_invalid_block_end(void **state)
{
const char *a = "{% block entry }}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -570,7 +570,7 @@ test_template_parse_invalid_variable_name(void **state)
{
const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -587,7 +587,7 @@ test_template_parse_invalid_variable_name2(void **state)
{
const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -604,7 +604,7 @@ test_template_parse_invalid_variable_end(void **state)
{
const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -621,7 +621,7 @@ test_template_parse_invalid_close(void **state)
{
const char *a = "{% block entry %%\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -637,7 +637,7 @@ test_template_parse_invalid_close2(void **state)
{
const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -654,7 +654,7 @@ test_template_parse_invalid_if_not_closed(void **state)
{
const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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);
@@ -669,7 +669,7 @@ test_template_parse_invalid_block_not_closed(void **state)
{
const char *a = "{% block entry %}\n";
blogc_error_t *err = NULL;
- sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ b_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
new file mode 100644
index 0000000..a42c75a
--- /dev/null
+++ b/tests/check_utils.c
@@ -0,0 +1,824 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdlib.h>
+
+#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_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);
+ 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_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);
+}