aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/blogc-git-receiver/check_settings.c20
-rw-r--r--tests/blogc-make/check_atom.c195
-rw-r--r--tests/blogc-make/check_exec.c115
-rw-r--r--tests/blogc-make/check_rules.c81
-rw-r--r--tests/blogc-make/check_settings.c187
-rw-r--r--tests/blogc-make/check_utils.c3
-rw-r--r--tests/blogc-runserver/check_httpd_utils.c5
-rw-r--r--tests/blogc/check_datetime_parser.c336
-rw-r--r--tests/blogc/check_funcvars.c33
-rw-r--r--tests/blogc/check_loader.c919
-rw-r--r--tests/blogc/check_renderer.c398
-rw-r--r--tests/blogc/check_rusage.c15
-rw-r--r--tests/blogc/check_source_parser.c376
-rw-r--r--tests/blogc/check_sysinfo.c41
-rw-r--r--tests/blogc/check_sysinfo2.c9
-rw-r--r--tests/blogc/check_template_parser.c495
-rw-r--r--tests/common/check_config_parser.c1037
-rw-r--r--tests/common/check_error.c109
-rw-r--r--tests/common/check_sort.c148
-rw-r--r--tests/common/check_stdin.c54
-rw-r--r--tests/common/check_utf8.c101
-rw-r--r--tests/common/check_utils.c1095
22 files changed, 1558 insertions, 4214 deletions
diff --git a/tests/blogc-git-receiver/check_settings.c b/tests/blogc-git-receiver/check_settings.c
index cb12037..6de5b32 100644
--- a/tests/blogc-git-receiver/check_settings.c
+++ b/tests/blogc-git-receiver/check_settings.c
@@ -12,8 +12,8 @@
#include <cmocka.h>
#include <string.h>
#include <stdlib.h>
-#include "../../src/common/config-parser.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc-git-receiver/settings.h"
@@ -24,21 +24,21 @@ __wrap_realpath(const char *path, char *resolved_path)
if (real_path == NULL)
return NULL;
assert_string_equal(path, real_path);
- return bc_strdup(real_path);
+ return sb_strdup(real_path);
}
static void
test_settings_get_section(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
setenv("HOME", "/home/blogc", 1);
- bc_config_t *config = bc_config_parse("", 0, NULL, &err);
+ sb_config_t *config = sb_config_parse("", 0, NULL, &err);
assert_null(err);
assert_null(bgr_settings_get_section(config, "/home/blogc/repos/foo.git"));
- bc_config_free(config);
+ sb_config_free(config);
will_return(__wrap_realpath, NULL);
will_return(__wrap_realpath, "/home/blogc/repos/bar.git");
@@ -52,12 +52,12 @@ test_settings_get_section(void **state)
"[repo:baz.git]\n"
"mirror = baz\n"
"\n";
- config = bc_config_parse(conf, strlen(conf), NULL, &err);
+ config = sb_config_parse(conf, strlen(conf), NULL, &err);
assert_null(err);
char *s = bgr_settings_get_section(config, "/home/blogc/repos/bar.git");
assert_string_equal(s, "repo:bar.git");
free(s);
- bc_config_free(config);
+ sb_config_free(config);
setenv("BLOGC_GIT_RECEIVER_BASE_DIR", "/home/bola", 1);
will_return(__wrap_realpath, NULL);
@@ -72,12 +72,12 @@ test_settings_get_section(void **state)
"[repo:asd/baz.git]\n"
"mirror = baz\n"
"\n";
- config = bc_config_parse(conf, strlen(conf), NULL, &err);
+ config = sb_config_parse(conf, strlen(conf), NULL, &err);
assert_null(err);
s = bgr_settings_get_section(config, "/home/bola/repos/asd/bar.git");
assert_string_equal(s, "repo:asd/bar.git");
free(s);
- bc_config_free(config);
+ sb_config_free(config);
}
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c
index 94c9a37..e9e24d3 100644
--- a/tests/blogc-make/check_atom.c
+++ b/tests/blogc-make/check_atom.c
@@ -10,26 +10,23 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "../../src/blogc-make/atom.h"
#include "../../src/blogc-make/settings.h"
-#include "../../src/common/file.h"
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
static void
test_atom_generate_empty_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
char *cmp = bm_atom_generate(settings);
@@ -68,7 +65,7 @@ test_atom_generate_empty_file(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -76,12 +73,12 @@ test_atom_generate_empty_file(void **state)
static void
test_atom_generate_empty_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
char *cmp = bm_atom_generate(settings);
@@ -120,7 +117,7 @@ test_atom_generate_empty_dir(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -128,12 +125,12 @@ test_atom_generate_empty_dir(void **state)
static void
test_atom_generate_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
char *cmp = bm_atom_generate(settings);
@@ -172,7 +169,7 @@ test_atom_generate_file(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -180,12 +177,12 @@ test_atom_generate_file(void **state)
static void
test_atom_generate_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
char *cmp = bm_atom_generate(settings);
@@ -224,7 +221,7 @@ test_atom_generate_dir(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -232,21 +229,21 @@ test_atom_generate_dir(void **state)
static void
test_atom_empty_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -286,7 +283,7 @@ test_atom_empty_file(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -294,21 +291,21 @@ test_atom_empty_file(void **state)
static void
test_atom_empty_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -348,7 +345,7 @@ test_atom_empty_dir(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -356,21 +353,21 @@ test_atom_empty_dir(void **state)
static void
test_atom_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -410,7 +407,7 @@ test_atom_file(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -418,21 +415,21 @@ test_atom_file(void **state)
static void
test_atom_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -472,7 +469,7 @@ test_atom_dir(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -480,27 +477,26 @@ test_atom_dir(void **state)
static void
test_atom_legacy_entry_id_empty(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
- bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+ sb_trie_insert(settings->settings, "atom_legacy_entry_id", sb_strdup("1"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_null(rv);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_ATOM);
- assert_string_equal(err->msg,
- "'atom_legacy_entry_id' setting is not supported anymore. see "
+ assert_string_equal(sb_error_to_string(err),
+ "atom: 'atom_legacy_entry_id' setting is not supported anymore. see "
"https://blogc.rgm.io/news/blogc-0.16.1/ for details");
- bc_error_free(err);
- bc_trie_free(settings->settings);
+ sb_error_free(err);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -508,27 +504,26 @@ test_atom_legacy_entry_id_empty(void **state)
static void
test_atom_legacy_entry_id(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
- bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+ sb_trie_insert(settings->settings, "atom_legacy_entry_id", sb_strdup("1"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_null(rv);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_ATOM);
- assert_string_equal(err->msg,
- "'atom_legacy_entry_id' setting is not supported anymore. see "
+ assert_string_equal(sb_error_to_string(err),
+ "atom: 'atom_legacy_entry_id' setting is not supported anymore. see "
"https://blogc.rgm.io/news/blogc-0.16.1/ for details");
- bc_error_free(err);
- bc_trie_free(settings->settings);
+ sb_error_free(err);
+ sb_trie_free(settings->settings);
free(settings);
}
diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c
index 6812496..c5d1d4e 100644
--- a/tests/blogc-make/check_exec.c
+++ b/tests/blogc-make/check_exec.c
@@ -14,14 +14,13 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <squareball.h>
#include "../../src/blogc-make/exec.h"
#include "../../src/blogc-make/settings.h"
-#include "../../src/common/utils.h"
int
@@ -75,16 +74,16 @@ test_find_binary(void **state)
static void
test_build_blogc_cmd_with_settings(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
- settings->global = bc_trie_new(free);
- bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
- bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8"));
+ settings->global = sb_trie_new(free);
+ sb_trie_insert(settings->global, "FOO", sb_strdup("BAR"));
+ sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
settings->tags = NULL;
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
@@ -113,10 +112,10 @@ test_build_blogc_cmd_with_settings(void **state)
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ'");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
- bc_trie_free(settings->settings);
- bc_trie_free(settings->global);
+ sb_trie_free(local);
+ sb_trie_free(variables);
+ sb_trie_free(settings->settings);
+ sb_trie_free(settings->global);
free(settings);
}
@@ -124,16 +123,16 @@ test_build_blogc_cmd_with_settings(void **state)
static void
test_build_blogc_cmd_with_settings_and_dev(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
- settings->global = bc_trie_new(free);
- bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
- bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8"));
+ settings->global = sb_trie_new(free);
+ sb_trie_insert(settings->global, "FOO", sb_strdup("BAR"));
+ sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
settings->tags = NULL;
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
@@ -166,10 +165,10 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
"-D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
- bc_trie_free(settings->settings);
- bc_trie_free(settings->global);
+ sb_trie_free(local);
+ sb_trie_free(variables);
+ sb_trie_free(settings->settings);
+ sb_trie_free(settings->global);
free(settings);
}
@@ -177,17 +176,17 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
static void
test_build_blogc_cmd_with_settings_and_tags(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
- settings->global = bc_trie_new(free);
- bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
- bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
- settings->tags = bc_str_split("asd foo bar", ' ', 0);
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8"));
+ settings->global = sb_trie_new(free);
+ sb_trie_insert(settings->global, "FOO", sb_strdup("BAR"));
+ sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
+ settings->tags = sb_str_split("asd foo bar", ' ', 0);
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
true, NULL, "main.tmpl", "foo.html", true, true);
@@ -219,11 +218,11 @@ test_build_blogc_cmd_with_settings_and_tags(void **state)
"-D BAR='BAZ' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
- bc_trie_free(settings->settings);
- bc_trie_free(settings->global);
- bc_strv_free(settings->tags);
+ sb_trie_free(local);
+ sb_trie_free(variables);
+ sb_trie_free(settings->settings);
+ sb_trie_free(settings->global);
+ sb_strv_free(settings->tags);
free(settings);
}
@@ -231,10 +230,10 @@ test_build_blogc_cmd_with_settings_and_tags(void **state)
static void
test_build_blogc_cmd_without_settings(void **state)
{
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, NULL,
true, NULL, "main.tmpl", "foo.html", false, true);
@@ -261,18 +260,18 @@ test_build_blogc_cmd_without_settings(void **state)
"blogc");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
+ sb_trie_free(local);
+ sb_trie_free(variables);
}
static void
test_build_blogc_cmd_print(void **state)
{
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, "LOL",
false, NULL, NULL, NULL, false, true);
@@ -296,8 +295,8 @@ test_build_blogc_cmd_print(void **state)
"blogc -p LOL");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
+ sb_trie_free(local);
+ sb_trie_free(variables);
}
diff --git a/tests/blogc-make/check_rules.c b/tests/blogc-make/check_rules.c
index ed2e46a..25ba0e1 100644
--- a/tests/blogc-make/check_rules.c
+++ b/tests/blogc-make/check_rules.c
@@ -10,73 +10,72 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "../../src/blogc-make/rules.h"
-#include "../../src/common/utils.h"
static void
test_rule_parse_args(void **state)
{
- bc_trie_t *t = bm_rule_parse_args("bola:foo=" + 4);
+ sb_trie_t *t = bm_rule_parse_args("bola:foo=" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "foo"), "");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=,baz=lol" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "foo"), "");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=,baz=lol,asd=qwe" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "qwe");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=,asd=qwe" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "");
- assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "qwe");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- assert_string_equal(bc_trie_lookup(t, "asd"), "");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=qwe" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "qwe");
+ sb_trie_free(t);
}
diff --git a/tests/blogc-make/check_settings.c b/tests/blogc-make/check_settings.c
index 7cebedc..3f091dd 100644
--- a/tests/blogc-make/check_settings.c
+++ b/tests/blogc-make/check_settings.c
@@ -10,27 +10,24 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "../../src/blogc-make/settings.h"
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
static void
test_settings_empty(void **state)
{
const char *a = "";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(s);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS);
- assert_string_equal(err->msg,
- "[global] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "settings: [global] key required but not found or empty: AUTHOR_NAME");
+ sb_error_free(err);
}
@@ -45,14 +42,13 @@ test_settings(void **state)
"[global]\n"
"BOLA = asd\n"
"GUDA = qwe\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(s);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS);
- assert_string_equal(err->msg,
- "[global] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "settings: [global] key required but not found or empty: AUTHOR_NAME");
+ sb_error_free(err);
}
@@ -67,14 +63,13 @@ test_settings_env(void **state)
"[environment]\n"
"BOLA = asd\n"
"GUDA = qwe\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(s);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS);
- assert_string_equal(err->msg,
- "[environment] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "settings: [environment] key required but not found or empty: AUTHOR_NAME");
+ sb_error_free(err);
}
@@ -113,36 +108,36 @@ test_settings2(void **state)
"jjjj\n"
"kkkk\n"
"llll\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(s);
- assert_int_equal(bc_trie_size(s->global), 7);
- assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd");
- assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
- assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 16);
- assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
- assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
- assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda");
- assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates");
- assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl");
- assert_string_equal(bc_trie_lookup(s->settings, "date_format"),
+ assert_int_equal(sb_trie_size(s->global), 7);
+ assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd");
+ assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
+ assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
+ assert_int_equal(sb_trie_size(s->settings), 16);
+ assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html");
+ assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda");
+ assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates");
+ assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl");
+ assert_string_equal(sb_trie_lookup(s->settings, "date_format"),
"%b %d, %Y, %I:%M %p GMT");
- assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
- assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
- assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
- assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), "");
+ assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page");
+ assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post");
+ assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), "");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
@@ -202,36 +197,36 @@ test_settings_env2(void **state)
"jjjj\n"
"kkkk\n"
"llll\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(s);
- assert_int_equal(bc_trie_size(s->global), 7);
- assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd");
- assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
- assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 16);
- assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
- assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
- assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda");
- assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates");
- assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl");
- assert_string_equal(bc_trie_lookup(s->settings, "date_format"),
+ assert_int_equal(sb_trie_size(s->global), 7);
+ assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd");
+ assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
+ assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
+ assert_int_equal(sb_trie_size(s->settings), 16);
+ assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html");
+ assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda");
+ assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates");
+ assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl");
+ assert_string_equal(sb_trie_lookup(s->settings, "date_format"),
"%b %d, %Y, %I:%M %p GMT");
- assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
- assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
- assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
- assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), "");
+ assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page");
+ assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post");
+ assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), "");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
@@ -291,36 +286,36 @@ test_settings_copy_files(void **state)
"jjjj\n"
"kkkk\n"
"llll\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(s);
- assert_int_equal(bc_trie_size(s->global), 7);
- assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd");
- assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
- assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 16);
- assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
- assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
- assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda");
- assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates");
- assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl");
- assert_string_equal(bc_trie_lookup(s->settings, "date_format"),
+ assert_int_equal(sb_trie_size(s->global), 7);
+ assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd");
+ assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
+ assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
+ assert_int_equal(sb_trie_size(s->settings), 16);
+ assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html");
+ assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda");
+ assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates");
+ assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl");
+ assert_string_equal(sb_trie_lookup(s->settings, "date_format"),
"%b %d, %Y, %I:%M %p GMT");
- assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
- assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
- assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
- assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), "");
+ assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page");
+ assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post");
+ assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), "");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
diff --git a/tests/blogc-make/check_utils.c b/tests/blogc-make/check_utils.c
index 5b3614d..852c0f7 100644
--- a/tests/blogc-make/check_utils.c
+++ b/tests/blogc-make/check_utils.c
@@ -10,11 +10,10 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
+#include <squareball.h>
#include "../../src/blogc-make/utils.h"
-#include "../../src/common/utils.h"
static void
diff --git a/tests/blogc-runserver/check_httpd_utils.c b/tests/blogc-runserver/check_httpd_utils.c
index 3e21e63..69c2a5b 100644
--- a/tests/blogc-runserver/check_httpd_utils.c
+++ b/tests/blogc-runserver/check_httpd_utils.c
@@ -12,7 +12,8 @@
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc-runserver/httpd-utils.h"
@@ -89,7 +90,7 @@ static void
test_urldecode(void **state)
{
for (size_t i = 0; i < 128; i++) {
- char *t = bc_strdup_printf("%%%02x", i);
+ char *t = sb_strdup_printf("%%%02x", i);
char *r = br_urldecode(t);
assert_int_equal(r[0], i);
assert_int_equal(r[1], 0);
diff --git a/tests/blogc/check_datetime_parser.c b/tests/blogc/check_datetime_parser.c
index 44c1af8..2a79bd4 100644
--- a/tests/blogc/check_datetime_parser.c
+++ b/tests/blogc/check_datetime_parser.c
@@ -12,14 +12,15 @@
#include <cmocka.h>
#include <stdlib.h>
#include <locale.h>
-#include "../../src/common/error.h"
+#include <squareball.h>
+
#include "../../src/blogc/datetime-parser.h"
static void
test_convert_datetime(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -31,7 +32,7 @@ test_convert_datetime(void **state)
static void
test_convert_datetime_implicit_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -43,7 +44,7 @@ test_convert_datetime_implicit_seconds(void **state)
static void
test_convert_datetime_implicit_minutes(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -55,7 +56,7 @@ test_convert_datetime_implicit_minutes(void **state)
static void
test_convert_datetime_implicit_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -67,529 +68,491 @@ test_convert_datetime_implicit_hours(void **state)
static void
test_convert_datetime_invalid_formats(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("20", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '20', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '20', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("201", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '201', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '201', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-1", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-3", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-3', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-3', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 ", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 ', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 ', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 1", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 12:1", "%b %d, %Y, %I:%M:%S %p GMT",
&err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 12:1', formats ""allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 12:13:1", "%b %d, %Y, %I:%M:%S %p GMT",
&err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("a010-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2a10-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_3rd_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("20a0-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_4th_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("201a-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("1899-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid year. Found 1899, must be >= 1900.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid year. Found 1899, must be >= 1900.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_hyphen(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010 11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between year and month. Found ' ', must be '-'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between year and month. Found ' ', must be '-'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_month(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-a1-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_month(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-1a-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_month(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-13-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid month. Found 13, must be >= 1 and <= 12.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid month. Found 13, must be >= 1 and <= 12.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_hyphen(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11 30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between month and day. Found ' ', must be '-'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between month and day. Found ' ', must be '-'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_day(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-a0 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_day(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-3a 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_day(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-32 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid day. Found 32, must be >= 1 and <= 31.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid day. Found 32, must be >= 1 and <= 31.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_space(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30-12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between date and time. Found '-', must be ' ' "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between date and time. Found '-', must be ' ' "
"(empty space).");
- bc_error_free(err);
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 a2:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 1a:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-30 24:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid hours. Found 24, must be >= 0 and <= 23.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid hours. Found 24, must be >= 0 and <= 23.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_colon(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12 13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between hours and minutes. Found ' ', must be ':'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between hours and minutes. Found ' ', must be ':'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_minutes(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:a3:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_minutes(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:1a:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_colon(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13 14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between minutes and seconds. Found ' ', must be ':'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between minutes and seconds. Found ' ', must be ':'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13:a4",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13:1a",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-30 12:13:69",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid seconds. Found 69, must be >= 0 and <= 60.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid seconds. Found 69, must be >= 0 and <= 60.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_format_long(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-30 12:13:14",
"bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
"yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk"
@@ -608,9 +571,8 @@ test_convert_datetime_invalid_format_long(void **state)
"jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Failed to format DATE variable, FORMAT is too long: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Failed to format DATE variable, FORMAT is too long: "
"bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
"yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk"
"tywccrvnraagtnedwdjtfobinobbymanppwqxubxeepotdyxuvircyshpmtrqyvbivtycs"
@@ -626,7 +588,7 @@ test_convert_datetime_invalid_format_long(void **state)
"uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq"
"gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj"
"jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg");
- bc_error_free(err);
+ sb_error_free(err);
}
diff --git a/tests/blogc/check_funcvars.c b/tests/blogc/check_funcvars.c
index 9d094d5..2c4acb0 100644
--- a/tests/blogc/check_funcvars.c
+++ b/tests/blogc/check_funcvars.c
@@ -13,16 +13,15 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/funcvars.h"
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents(const char *path, size_t *len, sb_error_t **err)
{
assert_string_equal(path, "/proc/1/cgroup");
- assert_false(utf8);
char *rv = mock_type(char*);
*len = strlen(rv);
return rv;
@@ -32,40 +31,40 @@ __wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t
static void
test_funcvars_eval(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
blogc_funcvars_eval(t, NULL);
blogc_funcvars_eval(t, "");
blogc_funcvars_eval(t, "BOLA");
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
- bc_trie_insert(t, "BOLA", bc_strdup("GUDA"));
+ sb_trie_insert(t, "BOLA", sb_strdup("GUDA"));
blogc_funcvars_eval(t, "BOLA");
- assert_int_equal(bc_trie_size(t), 1);
+ assert_int_equal(sb_trie_size(t), 1);
- bc_trie_free(t);
+ sb_trie_free(t);
}
static void
test_funcvars_eval_mocked(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
// this is the only function that isn't hidden behind conditional macros
// as of when this test was written. the other functions should be tested
// separately
- will_return(__wrap_bc_file_get_contents, bc_strdup("asd/docker/asd"));
+ will_return(__wrap_sb_file_get_contents, sb_strdup("asd/docker/asd"));
blogc_funcvars_eval(t, "BLOGC_SYSINFO_INSIDE_DOCKER");
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
- assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
+ assert_int_equal(sb_trie_size(t), 1);
// this specific function call is cached, so calling it again should not
- // call bc_file_get_contents_again
+ // call sb_file_get_contents_again
blogc_funcvars_eval(t, "BLOGC_SYSINFO_INSIDE_DOCKER");
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
- assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
+ assert_int_equal(sb_trie_size(t), 1);
- bc_trie_free(t);
+ sb_trie_free(t);
}
diff --git a/tests/blogc/check_loader.c b/tests/blogc/check_loader.c
index d65f418..9510a3d 100644
--- a/tests/blogc/check_loader.c
+++ b/tests/blogc/check_loader.c
@@ -13,8 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/template-parser.h"
#include "../../src/blogc/loader.h"
@@ -50,9 +50,8 @@ test_get_filename(void **state)
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents_utf8(const char *path, size_t *len, sb_error_t **err)
{
- assert_true(utf8);
assert_null(*err);
const char *_path = mock_type(const char*);
if (_path != NULL)
@@ -68,13 +67,13 @@ __wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t
static void
test_template_parse_from_file(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola");
- will_return(__wrap_bc_file_get_contents, bc_strdup("{{ BOLA }}\n"));
- bc_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup("{{ BOLA }}\n"));
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_non_null(l);
- assert_int_equal(bc_slist_length(l), 2);
+ assert_int_equal(sb_slist_length(l), 2);
blogc_template_free_ast(l);
}
@@ -82,10 +81,10 @@ test_template_parse_from_file(void **state)
static void
test_template_parse_from_file_null(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola");
- will_return(__wrap_bc_file_get_contents, NULL);
- bc_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola");
+ will_return(__wrap_sb_file_get_contents_utf8, NULL);
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_null(l);
}
@@ -94,33 +93,33 @@ test_template_parse_from_file_null(void **state)
static void
test_source_parse_from_file(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- bc_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 6);
- assert_string_equal(bc_trie_lookup(t, "ASD"), "123");
- assert_string_equal(bc_trie_lookup(t, "FILENAME"), "bola");
- assert_string_equal(bc_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(t, "RAW_CONTENT"), "bola");
- assert_string_equal(bc_trie_lookup(t, "DESCRIPTION"), "bola");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 6);
+ assert_string_equal(sb_trie_lookup(t, "ASD"), "123");
+ assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola");
+ sb_trie_free(t);
}
static void
test_source_parse_from_file_null(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola.txt");
- will_return(__wrap_bc_file_get_contents, NULL);
- bc_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, NULL);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_null(t);
}
@@ -129,813 +128,811 @@ test_source_parse_from_file_null(void **state)
static void
test_source_parse_from_files(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 4);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 4);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_sort(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-02 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2001-02-01 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 5);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-01 04:05:06");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola3");
+ 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"), "2001-02-01 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);
}
static void
test_source_parse_from_files_filter_reverse(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: bola, chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_REVERSE", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_REVERSE", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 5);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_REVERSE"), "1");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_REVERSE"), "1");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_sort_reverse(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-02 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2001-02-01 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_REVERSE", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_REVERSE", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 6);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_REVERSE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-01 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 6);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_REVERSE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-01 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2001-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);
}
static void
test_source_parse_from_files_filter_by_tag(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: bola, chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_TAG", bc_strdup("chunda"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 5);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_TAG"), "chunda");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 10);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page2(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("3"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("3"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 11);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola6");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "3");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "3");
- assert_string_equal(bc_trie_lookup(c, "PREVIOUS_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "4");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola6");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "4");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page3(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 10);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_sort_and_by_page_and_tag(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"TAGS: chunda bola\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"TAGS: bola\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"TAGS: yay chunda\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_TAG", bc_strdup("chunda"));
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("2"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ 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_SORT", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("2"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 12);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_TAG"), "chunda");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "PREVIOUS_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "2");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 12);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2003-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_SORT"), "1");
+ 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);
}
static void
test_source_parse_from_files_filter_by_page_invalid(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("-1"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("-1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 10);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "-1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "-1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page_invalid2(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("5"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("5"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_without_all_dates(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(t);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_LOADER);
- assert_string_equal(err->msg,
- "'DATE' variable provided for at least one source file, but not for "
+ assert_string_equal(sb_error_to_string(err),
+ "loader: 'DATE' variable provided for at least one source file, but not for "
"all source files. It must be provided for all files.");
- bc_error_free(err);
- assert_int_equal(bc_trie_size(c), 0);
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ sb_error_free(err);
+ assert_int_equal(sb_trie_size(c), 0);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_filter_sort_without_all_dates(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(t);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_LOADER);
- assert_string_equal(err->msg,
- "'FILTER_SORT' requires that 'DATE' variable is set for every source "
+ assert_string_equal(sb_error_to_string(err),
+ "loader: 'FILTER_SORT' requires that 'DATE' variable is set for every source "
"file: bola2.txt");
- bc_error_free(err);
- assert_int_equal(bc_trie_size(c), 1);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ sb_error_free(err);
+ assert_int_equal(sb_trie_size(c), 1);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_filter_sort_with_wrong_date(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2002-02-03 04:05:ab\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(t);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_LOADER);
- assert_string_equal(err->msg,
- "An error occurred while parsing 'DATE' variable: bola1.txt\n\nInvalid "
- "first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
- bc_error_free(err);
- assert_int_equal(bc_trie_size(c), 1);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ assert_string_equal(sb_error_to_string(err),
+ "loader: An error occurred while parsing 'DATE' variable: bola1.txt\n> "
+ "datetime: Invalid first digit of seconds. Found 'a', must be integer "
+ ">= 0 and <= 6.");
+ sb_error_free(err);
+ assert_int_equal(sb_trie_size(c), 1);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_null(void **state)
{
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- bc_trie_t *c = bc_trie_new(free);
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- assert_int_equal(bc_slist_length(t), 0);
- assert_int_equal(bc_trie_size(c), 0);
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 0);
+ assert_int_equal(sb_trie_size(c), 0);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
diff --git a/tests/blogc/check_renderer.c b/tests/blogc/check_renderer.c
index 479c239..63678b8 100644
--- a/tests/blogc/check_renderer.c
+++ b/tests/blogc/check_renderer.c
@@ -13,14 +13,14 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/renderer.h"
#include "../../src/blogc/source-parser.h"
#include "../../src/blogc/template-parser.h"
-static bc_slist_t*
+static sb_slist_t*
create_sources(size_t count)
{
const char *s[] = {
@@ -44,13 +44,13 @@ create_sources(size_t count)
"ahahahahahahahaha3",
};
assert_false(count > 3);
- bc_error_t *err = NULL;
- bc_slist_t *l = NULL;
+ sb_error_t *err = NULL;
+ sb_slist_t *l = NULL;
for (size_t i = 0; i < count; i++) {
- l = bc_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
+ l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
assert_null(err);
}
- assert_int_equal(bc_slist_length(l), count);
+ assert_int_equal(sb_slist_length(l), count);
return l;
}
@@ -76,11 +76,11 @@ test_render_entry(void **state)
"{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n"
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -102,7 +102,7 @@ test_render_entry(void **state)
"lol foo haha lol bar haha lol baz haha \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -123,11 +123,11 @@ test_render_listing(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, true);
assert_string_equal(out,
@@ -151,7 +151,7 @@ test_render_listing(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -173,11 +173,11 @@ test_render_listing_entry(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, true);
assert_string_equal(out,
@@ -202,7 +202,7 @@ test_render_listing_entry(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -225,17 +225,17 @@ test_render_listing_entry2(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
- bc_trie_t *entry = bc_trie_new(free);
- bc_trie_insert(entry, "FUUUUU", bc_strdup("XD"));
- bc_trie_insert(entry, "BAAAAA", bc_strdup(":p"));
+ sb_trie_t *entry = sb_trie_new(free);
+ sb_trie_insert(entry, "FUUUUU", sb_strdup("XD"));
+ sb_trie_insert(entry, "BAAAAA", sb_strdup(":p"));
char *out = blogc_render(l, s, entry, NULL, true);
- bc_trie_free(entry);
+ sb_trie_free(entry);
assert_string_equal(out,
"foo\n"
"fuuu\n"
@@ -259,7 +259,7 @@ test_render_listing_entry2(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -279,8 +279,8 @@ test_render_listing_empty(void **state)
"bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
char *out = blogc_render(l, NULL, NULL, NULL, true);
@@ -306,11 +306,11 @@ test_render_ifdef(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -318,7 +318,7 @@ test_render_ifdef(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -335,11 +335,11 @@ test_render_ifdef2(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -349,7 +349,7 @@ test_render_ifdef2(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -366,11 +366,11 @@ test_render_ifdef3(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -382,7 +382,7 @@ test_render_ifdef3(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -401,11 +401,11 @@ test_render_ifdef4(void **state)
"{% else %}lol\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -418,7 +418,7 @@ test_render_ifdef4(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -437,11 +437,11 @@ test_render_ifdef5(void **state)
"{% else %}lol\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -452,7 +452,7 @@ test_render_ifdef5(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -471,11 +471,11 @@ test_render_ifdef6(void **state)
"{% else %}lol\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -484,7 +484,7 @@ test_render_ifdef6(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -504,11 +504,11 @@ test_render_ifdef7(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -522,7 +522,7 @@ test_render_ifdef7(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -540,11 +540,11 @@ test_render_ifndef(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -557,7 +557,7 @@ test_render_ifndef(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -576,11 +576,11 @@ test_render_if_eq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -594,7 +594,7 @@ test_render_if_eq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -613,11 +613,11 @@ test_render_if_neq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -631,7 +631,7 @@ test_render_if_neq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -650,11 +650,11 @@ test_render_if_lt(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -668,7 +668,7 @@ test_render_if_lt(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -687,11 +687,11 @@ test_render_if_gt(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -705,7 +705,7 @@ test_render_if_gt(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -726,11 +726,11 @@ test_render_if_lt_eq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -746,7 +746,7 @@ test_render_if_lt_eq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -767,11 +767,11 @@ test_render_if_gt_eq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -787,7 +787,7 @@ test_render_if_gt_eq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -799,11 +799,11 @@ test_render_foreach(void **state)
"{% block entry %}\n"
"{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -811,7 +811,7 @@ test_render_foreach(void **state)
" foo bar baz \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -824,11 +824,11 @@ test_render_foreach_if(void **state)
"{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}"
"{% endif %} {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -836,7 +836,7 @@ test_render_foreach_if(void **state)
" bar \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -850,11 +850,11 @@ test_render_foreach_if_else(void **state)
"{% else %}{{ FOREACH_ITEM }}"
"{% endif %} {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -862,7 +862,7 @@ test_render_foreach_if_else(void **state)
"foo yay baz \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -881,22 +881,22 @@ test_render_outside_block(void **state)
"{% ifdef GUDA %}bola{% endif %}\n"
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}lol{% endif %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "GUDA", bc_strdup("asd"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("asd"));
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"bola\n"
"\n"
"lol\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -914,15 +914,15 @@ test_render_prefer_local_variable(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "GUDA", bc_strdup("hehe"));
- bc_trie_insert(c, "LOL", bc_strdup("hmm"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("hehe"));
+ sb_trie_insert(c, "LOL", sb_strdup("hmm"));
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"\n"
@@ -933,9 +933,9 @@ test_render_prefer_local_variable(void **state)
"\n"
"\n"
"\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -950,13 +950,13 @@ test_render_respect_variable_scope(void **state)
"{% ifdef LOL %}{{ LOL }}{% endif %}\n"
"{% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- bc_trie_t *c = bc_trie_new(free);
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"\n"
@@ -965,9 +965,9 @@ test_render_respect_variable_scope(void **state)
"\n"
"asd\n"
"\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -982,23 +982,23 @@ test_render_ifcount_bug(void **state)
"{% ifdef ASD %}ASD{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_trie_new(free));
- bc_trie_insert(s->data, "TITLE", bc_strdup("bola"));
- bc_trie_t *c = bc_trie_new(free);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_trie_new(free));
+ sb_trie_insert(s->data, "TITLE", sb_strdup("bola"));
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"\n"
"<h3>bola</h3>\n"
"\n"
"\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -1006,100 +1006,100 @@ test_render_ifcount_bug(void **state)
static void
test_get_variable(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "NAME", bc_strdup("bola"));
- bc_trie_insert(g, "TITLE", bc_strdup("bola2"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "NAME", bc_strdup("chunda"));
- bc_trie_insert(l, "TITLE", bc_strdup("chunda2"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_get_variable_only_local(void **state)
{
- bc_trie_t *g = NULL;
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "NAME", bc_strdup("chunda"));
- bc_trie_insert(l, "TITLE", bc_strdup("chunda2"));
+ sb_trie_t *g = NULL;
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- bc_trie_free(l);
+ sb_trie_free(l);
}
static void
test_get_variable_only_global(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "NAME", bc_strdup("bola"));
- bc_trie_insert(g, "TITLE", bc_strdup("bola2"));
- bc_trie_t *l = NULL;
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = NULL;
assert_string_equal(blogc_get_variable("NAME", g, l), "bola");
assert_string_equal(blogc_get_variable("TITLE", g, l), "bola2");
assert_null(blogc_get_variable("BOLA", g, l));
- bc_trie_free(g);
+ sb_trie_free(g);
}
static void
test_format_date(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "DATE_FORMAT", bc_strdup("%H -- %M"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "DATE_FORMAT", bc_strdup("%R"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE_FORMAT", sb_strdup("%R"));
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03:04");
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_with_global_format(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "DATE_FORMAT", bc_strdup("%H -- %M"));
- bc_trie_t *l = bc_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03 -- 04");
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_format(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_t *l = bc_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "2015-01-02 03:04:05");
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_date(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_t *l = bc_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date(NULL, g, l);
assert_null(date);
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
@@ -1107,13 +1107,13 @@ static void
test_format_variable(void **state)
{
// FIXME: test warnings
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "NAME", bc_strdup("bola"));
- bc_trie_insert(g, "TITLE", bc_strdup("bola2"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "NAME", bc_strdup("chunda"));
- bc_trie_insert(l, "TITLE", bc_strdup("chunda2"));
- bc_trie_insert(l, "SIZE", bc_strdup("1234567890987654321"));
+ 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"));
+ sb_trie_insert(l, "SIZE", sb_strdup("1234567890987654321"));
char *tmp = blogc_format_variable("NAME", g, l, NULL);
assert_string_equal(tmp, "chunda");
free(tmp);
@@ -1131,19 +1131,19 @@ test_format_variable(void **state)
free(tmp);
assert_null(blogc_format_variable("SIZE_", g, l, NULL));
assert_null(blogc_format_variable("BOLA", g, l, NULL));
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_with_date(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "DATE", bc_strdup("2010-11-12 13:14:15"));
- bc_trie_insert(g, "DATE_FORMAT", bc_strdup("%R"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "DATE", bc_strdup("2011-12-13 14:15:16"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE", sb_strdup("2010-11-12 13:14:15"));
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%R"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE", sb_strdup("2011-12-13 14:15:16"));
char *tmp = blogc_format_variable("DATE_FORMATTED", g, l, NULL);
assert_string_equal(tmp, "14:15");
free(tmp);
@@ -1153,18 +1153,18 @@ test_format_variable_with_date(void **state)
tmp = blogc_format_variable("DATE_FORMATTED_10", g, l, NULL);
assert_string_equal(tmp, "14:15");
free(tmp);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_foreach(void **state)
{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("asd"));
- l = bc_slist_append(l, bc_strdup("qwe"));
- l = bc_slist_append(l, bc_strdup("zxcvbn"));
+ sb_slist_t *l = NULL;
+ l = sb_slist_append(l, sb_strdup("asd"));
+ l = sb_slist_append(l, sb_strdup("qwe"));
+ l = sb_slist_append(l, sb_strdup("zxcvbn"));
char *tmp = blogc_format_variable("FOREACH_ITEM", NULL, NULL, l->next);
assert_string_equal(tmp, "qwe");
free(tmp);
@@ -1176,7 +1176,7 @@ test_format_variable_foreach(void **state)
l->next->next);
assert_string_equal(tmp, "zxcvbn");
free(tmp);
- bc_slist_free_full(l, free);
+ sb_slist_free_full(l, free);
}
@@ -1191,31 +1191,31 @@ test_format_variable_foreach_empty(void **state)
static void
test_split_list_variable(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "TAGS", bc_strdup("asd lol hehe"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "TAGS", bc_strdup("asd lol XD"));
- bc_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD"));
+ sb_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
assert_string_equal(tmp->data, "asd");
assert_string_equal(tmp->next->data, "lol");
assert_string_equal(tmp->next->next->data, "XD");
- bc_slist_free_full(tmp, free);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_slist_free_full(tmp, free);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_split_list_variable_not_found(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "TAGS", bc_strdup("asd lol hehe"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "TAGS", bc_strdup("asd lol XD"));
- bc_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD"));
+ sb_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
assert_null(tmp);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
diff --git a/tests/blogc/check_rusage.c b/tests/blogc/check_rusage.c
index ff64297..7296c4d 100644
--- a/tests/blogc/check_rusage.c
+++ b/tests/blogc/check_rusage.c
@@ -15,7 +15,8 @@
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/rusage.h"
@@ -99,18 +100,18 @@ test_rusage_format_memory(void **state)
static void
test_rusage_inject(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_getrusage, -1);
blogc_rusage_inject(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_getrusage, 0);
blogc_rusage_inject(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_RUSAGE_CPU_TIME"), "4.000s");
- assert_string_equal(bc_trie_lookup(t, "BLOGC_RUSAGE_MEMORY"), "10.010MB");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_RUSAGE_CPU_TIME"), "4.000s");
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_RUSAGE_MEMORY"), "10.010MB");
+ sb_trie_free(t);
}
diff --git a/tests/blogc/check_source_parser.c b/tests/blogc/check_source_parser.c
index f758522..5aa7a91 100644
--- a/tests/blogc/check_source_parser.c
+++ b/tests/blogc/check_source_parser.c
@@ -11,8 +11,8 @@
#include <setjmp.h>
#include <cmocka.h>
#include <string.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/source-parser.h"
@@ -26,26 +26,26 @@ test_source_parse(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -59,26 +59,26 @@ test_source_parse_crlf(void **state)
"# This is a test\r\n"
"\r\n"
"bola\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\r\n"
"\r\n"
"bola\r\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -94,26 +94,26 @@ test_source_parse_with_spaces(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "chunda");
- assert_string_equal(bc_trie_lookup(source, "BOLA"), "guda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "chunda");
+ assert_string_equal(sb_trie_lookup(source, "BOLA"), "guda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -132,22 +132,22 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n"
"<p>guda\n"
"yay</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n"
@@ -156,9 +156,9 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -173,26 +173,26 @@ test_source_parse_with_first_header(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "THIS IS CHUNDA!");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "THIS IS CHUNDA!");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -207,26 +207,26 @@ test_source_parse_with_description(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
+ sb_trie_free(source);
}
@@ -234,14 +234,13 @@ static void
test_source_parse_config_empty(void **state)
{
const char *a = "";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg, "Your source file is empty.");
- bc_error_free(err);
- bc_trie_free(source);
+ assert_string_equal(sb_error_to_string(err), "source: Your source file is empty.");
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -249,15 +248,14 @@ static void
test_source_parse_config_invalid_key(void **state)
{
const char *a = "bola: guda";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Can't find a configuration key or the content separator.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Can't find a configuration key or the content separator.\n"
"Error occurred near line 1, position 1: bola: guda");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -265,15 +263,14 @@ static void
test_source_parse_config_no_key(void **state)
{
const char *a = "BOLa";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Invalid configuration key.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Invalid configuration key.\n"
"Error occurred near line 1, position 4: BOLa");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -281,15 +278,14 @@ static void
test_source_parse_config_no_key2(void **state)
{
const char *a = "BOLA";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Your last configuration key is missing ':' and the value\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Your last configuration key is missing ':' and the value\n"
"Error occurred near line 1, position 5: BOLA");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -298,12 +294,12 @@ test_source_parse_config_no_value(void **state)
{
// this is a special case, not an error
const char *a = "BOLA:\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(source);
assert_null(err);
- assert_string_equal(bc_trie_lookup(source, "BOLA"), "");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "BOLA"), "");
+ sb_trie_free(source);
}
@@ -311,16 +307,15 @@ static void
test_source_parse_config_no_value2(void **state)
{
const char *a = "BOLA:";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Configuration value not provided for 'BOLA'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -328,16 +323,15 @@ static void
test_source_parse_config_reserved_name(void **state)
{
const char *a = "FILENAME: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'FILENAME' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'FILENAME' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -345,16 +339,15 @@ static void
test_source_parse_config_reserved_name2(void **state)
{
const char *a = "CONTENT: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'CONTENT' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'CONTENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -362,16 +355,15 @@ static void
test_source_parse_config_reserved_name3(void **state)
{
const char *a = "DATE_FORMATTED: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'DATE_FORMATTED' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'DATE_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -379,16 +371,15 @@ static void
test_source_parse_config_reserved_name4(void **state)
{
const char *a = "DATE_FIRST_FORMATTED: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -396,16 +387,15 @@ static void
test_source_parse_config_reserved_name5(void **state)
{
const char *a = "DATE_LAST_FORMATTED: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -413,16 +403,15 @@ static void
test_source_parse_config_reserved_name6(void **state)
{
const char *a = "PAGE_FIRST: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_FIRST' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_FIRST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -430,16 +419,15 @@ static void
test_source_parse_config_reserved_name7(void **state)
{
const char *a = "PAGE_PREVIOUS: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -447,16 +435,15 @@ static void
test_source_parse_config_reserved_name8(void **state)
{
const char *a = "PAGE_CURRENT: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_CURRENT' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_CURRENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -464,16 +451,15 @@ static void
test_source_parse_config_reserved_name9(void **state)
{
const char *a = "PAGE_NEXT: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_NEXT' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_NEXT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -481,16 +467,15 @@ static void
test_source_parse_config_reserved_name10(void **state)
{
const char *a = "PAGE_LAST: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_LAST' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_LAST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -498,16 +483,15 @@ static void
test_source_parse_config_reserved_name11(void **state)
{
const char *a = "BLOGC_VERSION: 1.0\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'BLOGC_VERSION' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'BLOGC_VERSION' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -515,16 +499,15 @@ static void
test_source_parse_config_value_no_line_ending(void **state)
{
const char *a = "BOLA: asd";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "No line ending after the configuration value for 'BOLA'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: No line ending after the configuration value for 'BOLA'.\n"
"Error occurred near line 1, position 10: BOLA: asd");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -532,16 +515,15 @@ static void
test_source_parse_invalid_separator(void **state)
{
const char *a = "BOLA: asd\n---#";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Invalid content separator. Must be more than one '-' characters.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Invalid content separator. Must be more than one '-' characters.\n"
"Error occurred near line 2, position 4: ---#");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
diff --git a/tests/blogc/check_sysinfo.c b/tests/blogc/check_sysinfo.c
index 01b81b9..13fcb1e 100644
--- a/tests/blogc/check_sysinfo.c
+++ b/tests/blogc/check_sysinfo.c
@@ -13,8 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/sysinfo.h"
#ifdef HAVE_SYSINFO_DATETIME
@@ -73,10 +73,9 @@ __wrap_gmtime(const time_t *timep)
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents(const char *path, size_t *len, sb_error_t **err)
{
assert_string_equal(path, "/proc/1/cgroup");
- assert_false(utf8);
char *rv = mock_type(char*);
*len = strlen(rv);
return rv;
@@ -103,19 +102,19 @@ test_sysinfo_get_hostname(void **state)
static void
test_sysinfo_inject_hostname(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_gethostname, NULL);
will_return(__wrap_gethostname, -1);
blogc_sysinfo_inject_hostname(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_gethostname, "bola");
will_return(__wrap_gethostname, 0);
blogc_sysinfo_inject_hostname(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_HOSTNAME"), "bola");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_HOSTNAME"), "bola");
+ sb_trie_free(t);
}
@@ -137,17 +136,17 @@ test_sysinfo_get_username(void **state)
static void
test_sysinfo_inject_username(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_getenv, NULL);
blogc_sysinfo_inject_username(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_getenv, "bola");
blogc_sysinfo_inject_username(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_USERNAME"), "bola");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_USERNAME"), "bola");
+ sb_trie_free(t);
}
@@ -173,21 +172,21 @@ test_sysinfo_get_datetime(void **state)
static void
test_sysinfo_inject_datetime(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_time, -1);
blogc_sysinfo_inject_datetime(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_time, 2);
blogc_sysinfo_inject_datetime(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_time, 1);
blogc_sysinfo_inject_datetime(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_DATETIME"), "1906-06-04 03:02:01");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_DATETIME"), "1906-06-04 03:02:01");
+ sb_trie_free(t);
}
@@ -196,7 +195,7 @@ test_sysinfo_get_inside_docker(void **state)
{
// the "positive" case was already tested in check_funcvars. this is done
// this way because this function caches the results in a global variable.
- will_return(__wrap_bc_file_get_contents, bc_strdup("bola"));
+ will_return(__wrap_sb_file_get_contents, sb_strdup("bola"));
assert_false(blogc_sysinfo_get_inside_docker());
}
diff --git a/tests/blogc/check_sysinfo2.c b/tests/blogc/check_sysinfo2.c
index 2bb4273..9a70059 100644
--- a/tests/blogc/check_sysinfo2.c
+++ b/tests/blogc/check_sysinfo2.c
@@ -13,8 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/sysinfo.h"
// this test exists because we can't test more than one return values for
@@ -23,11 +23,10 @@
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents(const char *path, size_t *len, sb_error_t **err)
{
assert_string_equal(path, "/proc/1/cgroup");
- assert_false(utf8);
- *err = bc_error_new(0, "");
+ *err = sb_strerror_new("");
return NULL;
}
diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c
index 15ef7c4..e3a3bd0 100644
--- a/tests/blogc/check_template_parser.c
+++ b/tests/blogc/check_template_parser.c
@@ -11,13 +11,13 @@
#include <setjmp.h>
#include <cmocka.h>
#include <string.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/template-parser.h"
static void
-blogc_assert_template_node(bc_slist_t *l, const char *data,
+blogc_assert_template_node(sb_slist_t *l, const char *data,
const blogc_template_node_type_t type)
{
blogc_template_node_t *node = l->data;
@@ -30,7 +30,7 @@ blogc_assert_template_node(bc_slist_t *l, const char *data,
static void
-blogc_assert_template_if_node(bc_slist_t *l, const char *variable,
+blogc_assert_template_if_node(sb_slist_t *l, const char *variable,
blogc_template_operator_t operator, const char *operand)
{
blogc_template_node_t *node = l->data;
@@ -60,8 +60,8 @@ test_template_parse(void **state)
"{%- foreach BOLA %}hahaha{% endforeach %}\n"
"{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}\n"
"{% block listing_entry %}lol{% endblock %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "Test",
@@ -78,7 +78,7 @@ test_template_parse(void **state)
BLOGC_TEMPLATE_NODE_ENDIF);
blogc_assert_template_node(ast->next->next->next->next->next->next, "\n",
BLOGC_TEMPLATE_NODE_CONTENT);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_IFNDEF);
blogc_assert_template_node(tmp->next, "\nbolao", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(tmp->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF);
@@ -149,8 +149,8 @@ test_template_parse_crlf(void **state)
"{% block listing_once %}asd{% endblock %}\r\n"
"{%- foreach BOLA %}hahaha{% endforeach %}\r\n"
"{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "Test",
@@ -167,7 +167,7 @@ test_template_parse_crlf(void **state)
BLOGC_TEMPLATE_NODE_ENDIF);
blogc_assert_template_node(ast->next->next->next->next->next->next, "\r\n",
BLOGC_TEMPLATE_NODE_CONTENT);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_IFNDEF);
blogc_assert_template_node(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(tmp->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF);
@@ -241,8 +241,8 @@ test_template_parse_html(void **state)
" {% block listing_once %}</ul>{% endblock %}\n"
" </body>\n"
"</html>\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "<html>\n <head>\n ",
@@ -261,7 +261,7 @@ test_template_parse_html(void **state)
"\n ", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(ast->next->next->next->next->next->next->next,
"listing_once", BLOGC_TEMPLATE_NODE_BLOCK);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_NODE_CONTENT);
@@ -370,8 +370,8 @@ test_template_parse_html_whitespace(void **state)
" {%\tblock\tlisting_once\t%}</ul>{%\nendblock\n%}\n"
" </body>\n"
"</html>\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "<html>\n <head>\n ",
@@ -390,7 +390,7 @@ test_template_parse_html_whitespace(void **state)
"\n ", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(ast->next->next->next->next->next->next->next,
"listing_once", BLOGC_TEMPLATE_NODE_BLOCK);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_NODE_CONTENT);
@@ -480,8 +480,8 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
"{% ifdef GUDA %}bola{% endif %}\n"
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "GUDA", BLOGC_TEMPLATE_NODE_IFDEF);
@@ -497,7 +497,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(ast->next->next->next->next->next->next,
"CHUNDA", BLOGC_TEMPLATE_NODE_IFNDEF);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, "CHUNDA", BLOGC_TEMPLATE_NODE_VARIABLE);
blogc_assert_template_node(tmp->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF);
blogc_assert_template_node(tmp->next->next, "\n",
@@ -527,8 +527,8 @@ test_template_parse_nested_else(void **state)
"bnm\n"
"{% endif %}\n"
"{% endif %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "GUDA", BLOGC_TEMPLATE_NODE_IFDEF);
@@ -544,7 +544,7 @@ test_template_parse_nested_else(void **state)
"CHUNDA", BLOGC_TEMPLATE_NODE_IFDEF);
blogc_assert_template_node(ast->next->next->next->next->next->next->next,
"\nqwe\n", BLOGC_TEMPLATE_NODE_CONTENT);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ELSE);
blogc_assert_template_node(tmp->next, "\nrty\n", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(tmp->next->next, NULL,
@@ -579,35 +579,32 @@ static void
test_template_parse_invalid_block_start(void **state)
{
const char *a = "{% ASD %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must begin with lowercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must begin with lowercase letter.\n"
"Error occurred near line 1, position 4: {% ASD %}");
- bc_error_free(err);
+ sb_error_free(err);
a = "{%-- block entry %}\n";
err = NULL;
ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Duplicated whitespace cleaner before statement.\n"
"Error occurred near line 1, position 4: {%-- block entry %}");
- bc_error_free(err);
+ sb_error_free(err);
a = "{% block entry --%}\n";
err = NULL;
ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Duplicated whitespace cleaner after statement.\n"
"Error occurred near line 1, position 17: {% block entry --%}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -617,15 +614,14 @@ test_template_parse_invalid_block_nested(void **state)
const char *a =
"{% block entry %}\n"
"{% block listing %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Blocks can't be nested.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Blocks can't be nested.\n"
"Error occurred near line 2, position 9: {% block listing %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -635,15 +631,14 @@ test_template_parse_invalid_foreach_nested(void **state)
const char *a =
"{% foreach A %}\n"
"{% foreach B %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'foreach' statements can't be nested.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'foreach' statements can't be nested.\n"
"Error occurred near line 2, position 11: {% foreach B %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -651,15 +646,14 @@ static void
test_template_parse_invalid_block_not_open(void **state)
{
const char *a = "{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endblock' statement without an open 'block' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endblock' statement without an open 'block' statement.\n"
"Error occurred near line 1, position 12: {% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -667,16 +661,15 @@ static void
test_template_parse_invalid_endif_not_open(void **state)
{
const char *a = "{% block listing %}{% endif %}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 28: "
"{% block listing %}{% endif %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -684,16 +677,15 @@ static void
test_template_parse_invalid_endif_not_open_inside_block(void **state)
{
const char *a = "{% ifdef BOLA %}{% block listing %}{% endif %}{% endblock %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 44: {% ifdef BOLA %}{% block "
"listing %}{% endif %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -701,16 +693,15 @@ static void
test_template_parse_invalid_else_not_open_inside_block(void **state)
{
const char *a = "{% ifdef BOLA %}{% block listing %}{% else %}{% endif %}{% endblock %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 43: {% ifdef BOLA %}"
"{% block listing %}{% else %}{% endif %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -718,15 +709,14 @@ static void
test_template_parse_invalid_endforeach_not_open(void **state)
{
const char *a = "{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endforeach' statement without an open 'foreach' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 14: {% endforeach %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -735,16 +725,15 @@ test_template_parse_invalid_endforeach_not_open_inside_block(void **state)
{
const char *a = "{% foreach TAGS %}{% block entry %}{% endforeach %}"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endforeach' statement without an open 'foreach' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 49: {% foreach TAGS %}"
"{% block entry %}{% endforeach %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -753,16 +742,15 @@ test_template_parse_invalid_endforeach_not_open_inside_block2(void **state)
{
const char *a = "{% block entry %}{% foreach TAGS %}"
"{% endforeach %}{% endforeach %}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endforeach' statement without an open 'foreach' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 65: {% block entry %}"
"{% foreach TAGS %}{% endforeach %}{% endforeach %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -771,14 +759,13 @@ test_template_parse_invalid_endforeach_not_closed_inside_block(void **state)
{
const char *a = "{% block entry %}{% foreach TAGS %}{% endblock %}"
"{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "An open 'foreach' statement was not closed inside a 'entry' block!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open 'foreach' statement was not closed inside a 'entry' block!");
+ sb_error_free(err);
}
@@ -787,14 +774,13 @@ test_template_parse_invalid_endforeach_not_closed_inside_block2(void **state)
{
const char *a = "{% block entry %}{% foreach TAGS %}{% endforeach %}"
"{% foreach TAGS %}{% endblock %}{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "An open 'foreach' statement was not closed inside a 'entry' block!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open 'foreach' statement was not closed inside a 'entry' block!");
+ sb_error_free(err);
}
@@ -802,16 +788,15 @@ static void
test_template_parse_invalid_block_name(void **state)
{
const char *a = "{% chunda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement type: Allowed types are: 'block', 'endblock', 'if', "
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement type: Allowed types are: 'block', 'endblock', 'if', "
"'ifdef', 'ifndef', 'else', 'endif', 'foreach' and 'endforeach'.\n"
"Error occurred near line 1, position 10: {% chunda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -819,15 +804,14 @@ static void
test_template_parse_invalid_block_type_start(void **state)
{
const char *a = "{% block ENTRY %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid block syntax. Must begin with lowercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid block syntax. Must begin with lowercase letter.\n"
"Error occurred near line 1, position 10: {% block ENTRY %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -835,16 +819,15 @@ static void
test_template_parse_invalid_block_type(void **state)
{
const char *a = "{% block chunda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' "
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' "
"and 'listing_entry'.\n"
"Error occurred near line 1, position 16: {% block chunda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -852,16 +835,15 @@ static void
test_template_parse_invalid_ifdef_start(void **state)
{
const char *a = "{% block entry %}{% ifdef guda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{% ifdef guda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -869,16 +851,15 @@ static void
test_template_parse_invalid_foreach_start(void **state)
{
const char *a = "{% block entry %}{% foreach guda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid foreach variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid foreach variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 29: "
"{% block entry %}{% foreach guda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -886,16 +867,15 @@ static void
test_template_parse_invalid_ifdef_variable(void **state)
{
const char *a = "{% block entry %}{% ifdef BoLA %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must be uppercase letter, number or '_'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 28: "
"{% block entry %}{% ifdef BoLA %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -903,16 +883,15 @@ static void
test_template_parse_invalid_ifdef_variable2(void **state)
{
const char *a = "{% block entry %}{% ifdef 0123 %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{% ifdef 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -920,16 +899,15 @@ static void
test_template_parse_invalid_foreach_variable(void **state)
{
const char *a = "{% block entry %}{% foreach BoLA %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid foreach variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 30: "
"{% block entry %}{% foreach BoLA %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -937,16 +915,15 @@ static void
test_template_parse_invalid_foreach_variable2(void **state)
{
const char *a = "{% block entry %}{% foreach 0123 %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid foreach variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid foreach variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 29: {% block entry %}"
"{% foreach 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -954,16 +931,15 @@ static void
test_template_parse_invalid_if_operator(void **state)
{
const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n"
"Error occurred near line 1, position 29: "
"{% block entry %}{% if BOLA = \"asd\" %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -971,16 +947,15 @@ static void
test_template_parse_invalid_if_operand(void **state)
{
const char *a = "{% block entry %}{% if BOLA == asd %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid 'if' operand. Must be double-quoted static string or variable.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid 'if' operand. Must be double-quoted static string or variable.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == asd %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -988,16 +963,15 @@ static void
test_template_parse_invalid_if_operand2(void **state)
{
const char *a = "{% block entry %}{% if BOLA == \"asd %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Found an open double-quoted string.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Found an open double-quoted string.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == \"asd %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1005,16 +979,15 @@ static void
test_template_parse_invalid_if_operand3(void **state)
{
const char *a = "{% block entry %}{% if BOLA == 0123 %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid 'if' operand. Must be double-quoted static string or variable.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid 'if' operand. Must be double-quoted static string or variable.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1022,15 +995,14 @@ static void
test_template_parse_invalid_else1(void **state)
{
const char *a = "{% else %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 8: {% else %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1038,16 +1010,15 @@ static void
test_template_parse_invalid_else2(void **state)
{
const char *a = "{% if BOLA == \"123\" %}{% if GUDA == \"1\" %}{% else %}{% else %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
+ assert_string_equal(sb_error_to_string(err),
+ "template: More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
"statement.\nError occurred near line 1, position 60: {% if BOLA == \"123\" "
"%}{% if GUDA == \"1\" %}{% else %}{% else %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1062,15 +1033,14 @@ test_template_parse_invalid_else3(void **state)
"{% endif %}\n"
"{% else %}\n"
"{% else %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
+ assert_string_equal(sb_error_to_string(err),
+ "template: More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
"statement.\nError occurred near line 7, position 8: {% else %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1078,15 +1048,14 @@ static void
test_template_parse_invalid_block_end(void **state)
{
const char *a = "{% block entry }}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '%}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '%}'.\n"
"Error occurred near line 1, position 16: {% block entry }}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1094,16 +1063,15 @@ static void
test_template_parse_invalid_variable_name(void **state)
{
const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 21: "
"{% block entry %}{{ bola }}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1111,16 +1079,15 @@ static void
test_template_parse_invalid_variable_name2(void **state)
{
const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must be uppercase letter, number or '_'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 22: "
"{% block entry %}{{ Bola }}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1128,16 +1095,15 @@ static void
test_template_parse_invalid_variable_name3(void **state)
{
const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}"
"{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1145,16 +1111,15 @@ static void
test_template_parse_invalid_variable_end(void **state)
{
const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '}}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '}}'.\n"
"Error occurred near line 1, position 26: "
"{% block entry %}{{ BOLA %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1162,15 +1127,14 @@ static void
test_template_parse_invalid_close(void **state)
{
const char *a = "{% block entry %%\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '}'.\n"
"Error occurred near line 1, position 17: {% block entry %%");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1178,16 +1142,15 @@ static void
test_template_parse_invalid_close2(void **state)
{
const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '}'.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{{ BOLA }%{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1195,14 +1158,14 @@ static void
test_template_parse_invalid_endif_not_closed(void **state)
{
const char *a = "{% block entry %}{% endblock %}{% ifdef BOLA %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg, "1 open 'if', 'ifdef' and/or 'ifndef' statements "
+ assert_string_equal(sb_error_to_string(err),
+ "template: 1 open 'if', 'ifdef' and/or 'ifndef' statements "
"were not closed!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1210,15 +1173,14 @@ static void
test_template_parse_invalid_endif_not_closed_inside_block(void **state)
{
const char *a = "{% block listing %}{% ifdef BOLA %}{% endblock %}{% endif %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
+ assert_string_equal(sb_error_to_string(err),
+ "template: 1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
"a 'listing' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1226,15 +1188,14 @@ static void
test_template_parse_invalid_else_not_closed_inside_block(void **state)
{
const char *a = "{% block listing %}{% ifdef BOLA %}{% else %}{% endblock %}{% endif %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
+ assert_string_equal(sb_error_to_string(err),
+ "template: 1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
"a 'listing' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1242,13 +1203,13 @@ static void
test_template_parse_invalid_block_not_closed(void **state)
{
const char *a = "{% block entry %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg, "An open block was not closed!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open block was not closed!");
+ sb_error_free(err);
}
@@ -1256,13 +1217,13 @@ static void
test_template_parse_invalid_foreach_not_closed(void **state)
{
const char *a = "{% foreach ASD %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg, "An open 'foreach' statement was not closed!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open 'foreach' statement was not closed!");
+ sb_error_free(err);
}
diff --git a/tests/common/check_config_parser.c b/tests/common/check_config_parser.c
deleted file mode 100644
index 49e2a5b..0000000
--- a/tests/common/check_config_parser.c
+++ /dev/null
@@ -1,1037 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 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 <string.h>
-
-#include "../../src/common/config-parser.h"
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
-
-
-static void
-test_config_empty(void **state)
-{
- const char *a = "";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 0);
- assert_string_equal(bc_config_get_with_default(c, "bola", "foo", "bar"), "bar");
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_empty(void **state)
-{
- const char *a = "[foo]";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 0);
- assert_null(k[0]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_multiple_keys(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty \n"
- "zxc = vbn";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty \n"
- "zxc = vbn\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n"
- "qwe = rty \r\n"
- "zxc = vbn\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_multiple_sections(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- assert_string_equal(bc_config_get(c, "bar", "lol"), "hehe");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "lol");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- assert_string_equal(bc_config_get(c, "bar", "lol"), "hehe");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "lol");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n"
- "qwe = rty\r\n"
- "zxc = vbn\r\n"
- "\r\n"
- "[bar]\r\n"
- "lol = hehe\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- assert_string_equal(bc_config_get(c, "bar", "lol"), "hehe");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "lol");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_list(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe\n"
- " asdasdadssad ";
- bc_error_t *err = NULL;
- const char *sections[] = {"bar", NULL};
- bc_config_t *c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- char **bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "lol = hehe");
- assert_string_equal(bar[1], "asdasdadssad");
- assert_null(bar[2]);
- bc_strv_free(bar);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe\n"
- "asdasdadssad\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "lol = hehe");
- assert_string_equal(bar[1], "asdasdadssad");
- assert_null(bar[2]);
- bc_strv_free(bar);
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n"
- "qwe = rty\r\n"
- "zxc = vbn\r\n"
- "\r\n"
- "[bar]\r\n"
- "lol = hehe\r\n"
- "asdasdadssad\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "lol = hehe");
- assert_string_equal(bar[1], "asdasdadssad");
- assert_null(bar[2]);
- bc_strv_free(bar);
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_quoted_values(void **state)
-{
- const char *a =
- "[foo]\n"
- "a = \"lol\"\n"
- "b = \"lo\\\"l\"\n"
- "c = \"lo'l\"\n"
- "d = 'lol'\n"
- "e = 'lo\\'l'\n"
- "f = 'lo\"l'\n"
- "g = \\\\asd\n"
- "h = \"\\\\asd\"\n"
- "i = '\\\\asd'\n";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 9);
- assert_string_equal(k[0], "a");
- assert_string_equal(k[1], "b");
- assert_string_equal(k[2], "c");
- assert_string_equal(k[3], "d");
- assert_string_equal(k[4], "e");
- assert_string_equal(k[5], "f");
- assert_string_equal(k[6], "g");
- assert_string_equal(k[7], "h");
- assert_string_equal(k[8], "i");
- assert_null(k[9]);
- bc_strv_free(k);
- assert_string_equal(bc_config_get(c, "foo", "a"), "lol");
- assert_string_equal(bc_config_get(c, "foo", "b"), "lo\"l");
- assert_string_equal(bc_config_get(c, "foo", "c"), "lo'l");
- assert_string_equal(bc_config_get(c, "foo", "d"), "'lol'");
- assert_string_equal(bc_config_get(c, "foo", "e"), "'lo'l'");
- assert_string_equal(bc_config_get(c, "foo", "f"), "'lo\"l'");
- assert_string_equal(bc_config_get(c, "foo", "g"), "\\asd");
- assert_string_equal(bc_config_get(c, "foo", "h"), "\\asd");
- assert_string_equal(bc_config_get(c, "foo", "i"), "'\\asd'");
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "\"lol\"\n"
- "\"lo\\\"l\"\n"
- "\"lo'l\"\n"
- "'lol'\n"
- "'lo\\'l'\n"
- "'lo\"l'\n"
- "\\\\asd\n"
- "\"\\\\asd\"\n"
- "'\\\\asd'\n"
- "\n"
- "[bar]\n"
- "'lol = hehe'\n"
- "\" asdasdadssad \"";
- err = NULL;
- const char *sections[] = {"foo", "bar", NULL};
- c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- char **bar = bc_config_get_list(c, "foo");
- assert_string_equal(bar[0], "lol");
- assert_string_equal(bar[1], "lo\"l");
- assert_string_equal(bar[2], "lo'l");
- assert_string_equal(bar[3], "'lol'");
- assert_string_equal(bar[4], "'lo'l'");
- assert_string_equal(bar[5], "'lo\"l'");
- assert_string_equal(bar[6], "\\asd");
- assert_string_equal(bar[7], "\\asd");
- assert_string_equal(bar[8], "'\\asd'");
- assert_null(bar[9]);
- bc_strv_free(bar);
- bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "'lol = hehe'");
- assert_string_equal(bar[1], " asdasdadssad ");
- assert_null(bar[2]);
- bc_strv_free(bar);
- k = bc_config_list_keys(c, "foo");
- assert_null(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_empty_values(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd =";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = \n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = foo\n"
- "qwe =";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = foo\n"
- "qwe = \n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd =\n"
- "qwe = foo";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = \n"
- "qwe = foo\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd =";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = \r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = foo\r\n"
- "qwe =";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = foo\r\n"
- "qwe = \r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd =\r\n"
- "qwe = foo";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = \r\n"
- "qwe = foo\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_key_prefix(void **state)
-{
- const char *a =
- "[foo]\n"
- "LAST_FLIGHT = lol\n"
- "LAST_FLIGHT_SLUG = hehe\n";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "LAST_FLIGHT");
- assert_string_equal(k[1], "LAST_FLIGHT_SLUG");
- assert_null(k[2]);
- bc_strv_free(k);
- assert_string_equal(bc_config_get(c, "foo", "LAST_FLIGHT"), "lol");
- assert_string_equal(bc_config_get(c, "foo", "LAST_FLIGHT_SLUG"), "hehe");
- bc_config_free(c);
-}
-
-
-static void
-test_config_error_start(void **state)
-{
- const char *a =
- "asd\n"
- "[foo]";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "File must start with section.\n"
- "Error occurred near line 1, position 1: asd");
- bc_error_free(err);
-}
-
-
-static void
-test_config_error_section_with_newline(void **state)
-{
- const char *a =
- "[foo\nbar]";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "Section names can't have new lines.\n"
- "Error occurred near line 1, position 5: [foo");
- bc_error_free(err);
-}
-
-
-static void
-test_config_error_key_without_value(void **state)
-{
- const char *a =
- "[foobar]\n"
- "asd = 12\n"
- "foo";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "Key without value: foo.\n"
- "Error occurred near line 3, position 3: foo");
- bc_error_free(err);
- a =
- "[foobar]\n"
- "asd = 12\n"
- "foo\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "Key without value: foo.\n"
- "Error occurred near line 3, position 4: foo");
- bc_error_free(err);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_config_empty),
- unit_test(test_config_section_empty),
- unit_test(test_config_section),
- unit_test(test_config_section_multiple_keys),
- unit_test(test_config_section_multiple_sections),
- unit_test(test_config_section_list),
- unit_test(test_config_quoted_values),
- unit_test(test_config_empty_values),
- unit_test(test_config_key_prefix),
- unit_test(test_config_error_start),
- unit_test(test_config_error_section_with_newline),
- unit_test(test_config_error_key_without_value),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_error.c b/tests/common/check_error.c
deleted file mode 100644
index d9806f9..0000000
--- a/tests/common/check_error.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 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 <string.h>
-#include "../../src/common/error.h"
-
-
-static void
-test_error_new(void **state)
-{
- bc_error_t *error = bc_error_new(1, "bola %s");
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg, "bola %s");
- bc_error_free(error);
-}
-
-
-static void
-test_error_new_printf(void **state)
-{
- bc_error_t *error = bc_error_new_printf(2, "bola %s", "guda");
- assert_non_null(error);
- assert_int_equal(error->type, 2);
- assert_string_equal(error->msg, "bola guda");
- bc_error_free(error);
-}
-
-
-static void
-test_error_parser(void **state)
-{
- const char *a = "bola\nguda\nchunda\n";
- bc_error_t *error = bc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\nguda\nchunda";
- error = bc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\nguda\nchunda";
- error = bc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 1, position 1: bola");
- bc_error_free(error);
- a = "";
- error = bc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg, "asd 10");
- bc_error_free(error);
-}
-
-
-static void
-test_error_parser_crlf(void **state)
-{
- const char *a = "bola\r\nguda\r\nchunda\r\n";
- bc_error_t *error = bc_error_parser(1, a, strlen(a), 13, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\r\nguda\r\nchunda";
- error = bc_error_parser(1, a, strlen(a), 13, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\r\nguda\r\nchunda";
- error = bc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 1, position 1: bola");
- bc_error_free(error);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_error_new),
- unit_test(test_error_new_printf),
- unit_test(test_error_parser),
- unit_test(test_error_parser_crlf),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_sort.c b/tests/common/check_sort.c
deleted file mode 100644
index f49710c..0000000
--- a/tests/common/check_sort.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 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 <string.h>
-#include "../../src/common/utils.h"
-#include "../../src/common/sort.h"
-
-
-static int
-sort_func(void *a, void *b)
-{
- return strcmp((char*) a, (char*) b);
-}
-
-
-static void
-test_slist_sort_empty(void **state)
-{
- bc_slist_t *l = NULL;
- assert_null(bc_slist_sort(l, (bc_sort_func_t) sort_func));
-}
-
-
-static void
-test_slist_sort_single(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("a"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_null(l->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_sorted(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("a"));
- l = bc_slist_append(l, bc_strdup("b"));
- l = bc_slist_append(l, bc_strdup("c"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_null(l->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_reverse(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("d"));
- l = bc_slist_append(l, bc_strdup("c"));
- l = bc_slist_append(l, bc_strdup("b"));
- l = bc_slist_append(l, bc_strdup("a"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_string_equal(l->next->next->next->data, "d");
- assert_null(l->next->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_mixed1(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("a"));
- l = bc_slist_append(l, bc_strdup("d"));
- l = bc_slist_append(l, bc_strdup("c"));
- l = bc_slist_append(l, bc_strdup("b"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_string_equal(l->next->next->next->data, "d");
- assert_null(l->next->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_mixed2(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("c"));
- l = bc_slist_append(l, bc_strdup("b"));
- l = bc_slist_append(l, bc_strdup("a"));
- l = bc_slist_append(l, bc_strdup("d"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_string_equal(l->next->next->next->data, "d");
- assert_null(l->next->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_slist_sort_empty),
- unit_test(test_slist_sort_single),
- unit_test(test_slist_sort_sorted),
- unit_test(test_slist_sort_reverse),
- unit_test(test_slist_sort_mixed1),
- unit_test(test_slist_sort_mixed2),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_stdin.c b/tests/common/check_stdin.c
deleted file mode 100644
index 716916d..0000000
--- a/tests/common/check_stdin.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 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 <string.h>
-#include <stdio.h>
-#include "../../src/common/stdin.h"
-
-
-int
-__wrap_fgetc(FILE *stream)
-{
- assert_int_equal(fileno(stream), fileno(stdin));
- return mock_type(int);
-}
-
-
-static void
-test_read(void **state)
-{
- will_return(__wrap_fgetc, EOF);
- char *t = bc_stdin_read();
- assert_non_null(t);
- assert_string_equal(t, "");
- free(t);
- will_return(__wrap_fgetc, 'b');
- will_return(__wrap_fgetc, 'o');
- will_return(__wrap_fgetc, 'l');
- will_return(__wrap_fgetc, 'a');
- will_return(__wrap_fgetc, EOF);
- t = bc_stdin_read();
- assert_non_null(t);
- assert_string_equal(t, "bola");
- free(t);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_read),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_utf8.c b/tests/common/check_utf8.c
deleted file mode 100644
index 05bf566..0000000
--- a/tests/common/check_utf8.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 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 <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-#include "../../src/common/utf8.h"
-#include "../../src/common/utils.h"
-
-// this file MUST be ASCII
-
-
-static void
-test_utf8_valid(void **state)
-{
- const char *c = "<a href=\"{{ BASE_URL }}/page/{{ PREVIOUS_PAGE }}/\">"
- "\xc2\xab Newer posts</a>";
- assert_true(bc_utf8_validate((uint8_t*) c, strlen(c)));
- const uint8_t d[3] = {0xe2, 0x82, 0xac}; // euro sign
- assert_true(bc_utf8_validate(d, 3));
- const uint8_t e[3] = {0xef, 0xbb, 0xbf}; // utf-8 bom
- assert_true(bc_utf8_validate(e, 3));
-}
-
-
-static void
-test_utf8_invalid(void **state)
-{
- const uint8_t c[4] = {0xff, 0xfe, 0xac, 0x20}; // utf-16
- assert_false(bc_utf8_validate(c, 4));
- const uint8_t d[8] = {0xff, 0xfe, 0x00, 0x00, 0xac, 0x20, 0x00, 0x00}; // utf-32
- assert_false(bc_utf8_validate(d, 8));
-}
-
-
-static void
-test_utf8_valid_str(void **state)
-{
- bc_string_t *s = bc_string_new();
- bc_string_append(s,
- "<a href=\"{{ BASE_URL }}/page/{{ PREVIOUS_PAGE }}/\">\xc2\xab Newer "
- "posts</a>");
- assert_true(bc_utf8_validate_str(s));
- bc_string_free(s, true);
- s = bc_string_new();
- bc_string_append(s, "\xe2\x82\xac");
- assert_true(bc_utf8_validate_str(s));
- bc_string_free(s, true);
-}
-
-
-static void
-test_utf8_invalid_str(void **state)
-{
- bc_string_t *s = bc_string_new();
- bc_string_append(s, "\xff\xfe\xac\x20"); // utf-16
- assert_false(bc_utf8_validate_str(s));
- bc_string_free(s, true);
- s = bc_string_new();
- bc_string_append(s, "\xff\xfe\x00\x00\xac\x20\x00\x00"); // utf-32
- assert_false(bc_utf8_validate_str(s));
- bc_string_free(s, true);
-}
-
-
-static void
-test_utf8_skip_bom(void **state)
-{
- const uint8_t c[4] = {0xef, 0xbb, 0xbf, 0};
- assert_int_equal(bc_utf8_skip_bom(c, 2), 0);
- assert_int_equal(bc_utf8_skip_bom(c, 3), 3);
- assert_string_equal(c + 3, "");
- const uint8_t d[8] = {0xef, 0xbb, 0xbf, 'b', 'o', 'l', 'a', 0};
- assert_int_equal(bc_utf8_skip_bom(d, 7), 3);
- assert_string_equal(d + 3, "bola");
- const uint8_t e[5] = "bola";
- assert_int_equal(bc_utf8_skip_bom(e, 4), 0);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_utf8_valid),
- unit_test(test_utf8_invalid),
- unit_test(test_utf8_valid_str),
- unit_test(test_utf8_invalid_str),
- unit_test(test_utf8_skip_bom),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_utils.c b/tests/common/check_utils.c
deleted file mode 100644
index cc14f4e..0000000
--- a/tests/common/check_utils.c
+++ /dev/null
@@ -1,1095 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 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 <stdbool.h>
-#include <stdlib.h>
-#include "../../src/common/utils.h"
-
-#define BC_STRING_CHUNK_SIZE 128
-
-
-static void
-test_slist_append(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, (void*) bc_strdup("bola"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_null(l->next);
- l = bc_slist_append(l, (void*) bc_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);
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_prepend(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_prepend(l, (void*) bc_strdup("bola"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_null(l->next);
- l = bc_slist_prepend(l, (void*) bc_strdup("guda"));
- assert_non_null(l);
- assert_string_equal(l->data, "guda");
- assert_non_null(l->next);
- assert_string_equal(l->next->data, "bola");
- assert_null(l->next->next);
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_free(void **state)
-{
- bc_slist_t *l = NULL;
- char *t1 = bc_strdup("bola");
- char *t2 = bc_strdup("guda");
- char *t3 = bc_strdup("chunda");
- l = bc_slist_append(l, (void*) t1);
- l = bc_slist_append(l, (void*) t2);
- l = bc_slist_append(l, (void*) t3);
- bc_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)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, (void*) bc_strdup("bola"));
- l = bc_slist_append(l, (void*) bc_strdup("guda"));
- l = bc_slist_append(l, (void*) bc_strdup("chunda"));
- assert_int_equal(bc_slist_length(l), 3);
- bc_slist_free_full(l, free);
- assert_int_equal(bc_slist_length(NULL), 0);
-}
-
-
-static void
-test_strdup(void **state)
-{
- char *str = bc_strdup("bola");
- assert_string_equal(str, "bola");
- free(str);
- str = bc_strdup(NULL);
- assert_null(str);
-}
-
-
-static void
-test_strndup(void **state)
-{
- char *str = bc_strndup("bolaguda", 4);
- assert_string_equal(str, "bola");
- free(str);
- str = bc_strndup("bolaguda", 30);
- assert_string_equal(str, "bolaguda");
- free(str);
- str = bc_strndup("bolaguda", 8);
- assert_string_equal(str, "bolaguda");
- free(str);
- str = bc_strdup(NULL);
- assert_null(str);
-}
-
-
-static void
-test_strdup_printf(void **state)
-{
- char *str = bc_strdup_printf("bola");
- assert_string_equal(str, "bola");
- free(str);
- str = bc_strdup_printf("bola, %s", "guda");
- assert_string_equal(str, "bola, guda");
- free(str);
-}
-
-
-static void
-test_str_starts_with(void **state)
-{
- assert_true(bc_str_starts_with("bolaguda", "bola"));
- assert_true(bc_str_starts_with("bola", "bola"));
- assert_false(bc_str_starts_with("gudabola", "bola"));
- assert_false(bc_str_starts_with("guda", "bola"));
- assert_false(bc_str_starts_with("bola", "bolaguda"));
-}
-
-
-static void
-test_str_ends_with(void **state)
-{
- assert_true(bc_str_ends_with("bolaguda", "guda"));
- assert_true(bc_str_ends_with("bola", "bola"));
- assert_false(bc_str_ends_with("gudabola", "guda"));
- assert_false(bc_str_ends_with("guda", "bola"));
- assert_false(bc_str_ends_with("bola", "gudabola"));
-}
-
-
-static void
-test_str_lstrip(void **state)
-{
- char *str = bc_strdup(" \tbola\n \t");
- assert_string_equal(bc_str_lstrip(str), "bola\n \t");
- free(str);
- str = bc_strdup("guda");
- assert_string_equal(bc_str_lstrip(str), "guda");
- free(str);
- str = bc_strdup("\n");
- assert_string_equal(bc_str_lstrip(str), "");
- free(str);
- str = bc_strdup("\t \n");
- assert_string_equal(bc_str_lstrip(str), "");
- free(str);
- str = bc_strdup("");
- assert_string_equal(bc_str_lstrip(str), "");
- free(str);
- assert_null(bc_str_lstrip(NULL));
-}
-
-
-static void
-test_str_rstrip(void **state)
-{
- char *str = bc_strdup(" \tbola\n \t");
- assert_string_equal(bc_str_rstrip(str), " \tbola");
- free(str);
- str = bc_strdup("guda");
- assert_string_equal(bc_str_rstrip(str), "guda");
- free(str);
- str = bc_strdup("\n");
- assert_string_equal(bc_str_rstrip(str), "");
- free(str);
- str = bc_strdup("\t \n");
- assert_string_equal(bc_str_rstrip(str), "");
- free(str);
- str = bc_strdup("");
- assert_string_equal(bc_str_rstrip(str), "");
- free(str);
- assert_null(bc_str_rstrip(NULL));
-}
-
-
-static void
-test_str_strip(void **state)
-{
- char *str = bc_strdup(" \tbola\n \t");
- assert_string_equal(bc_str_strip(str), "bola");
- free(str);
- str = bc_strdup("guda");
- assert_string_equal(bc_str_strip(str), "guda");
- free(str);
- str = bc_strdup("\n");
- assert_string_equal(bc_str_strip(str), "");
- free(str);
- str = bc_strdup("\t \n");
- assert_string_equal(bc_str_strip(str), "");
- free(str);
- str = bc_strdup("");
- assert_string_equal(bc_str_strip(str), "");
- free(str);
- assert_null(bc_str_strip(NULL));
-}
-
-
-static void
-test_str_split(void **state)
-{
- char **strv = bc_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]);
- bc_strv_free(strv);
- strv = bc_str_split("bola:guda:chunda", ':', 2);
- assert_string_equal(strv[0], "bola");
- assert_string_equal(strv[1], "guda:chunda");
- assert_null(strv[2]);
- bc_strv_free(strv);
- strv = bc_str_split("bola:guda:chunda", ':', 1);
- assert_string_equal(strv[0], "bola:guda:chunda");
- assert_null(strv[1]);
- bc_strv_free(strv);
- strv = bc_str_split("", ':', 1);
- assert_null(strv[0]);
- bc_strv_free(strv);
- assert_null(bc_str_split(NULL, ':', 0));
-}
-
-
-static void
-test_str_replace(void **state)
-{
- char *str = bc_str_replace("bolao", 'o', "zaz");
- assert_string_equal(str, "bzazlazaz");
- free(str);
- str = bc_str_replace("bolao", 'b', "zaz");
- assert_string_equal(str, "zazolao");
- free(str);
- str = bc_str_replace("bolao", 'b', NULL);
- assert_string_equal(str, "bolao");
- free(str);
- assert_null(bc_str_replace(NULL, 'b', "zaz"));
-}
-
-
-static void
-test_str_find(void **state)
-{
- assert_null(bc_str_find(NULL, 'c'));
- assert_string_equal(bc_str_find("bola", 'l'), "la");
- assert_string_equal(bc_str_find("bo\\lalala", 'l'), "lala");
- assert_string_equal(bc_str_find("bola", '\0'), "");
- assert_null(bc_str_find("bola", 'g'));
- assert_null(bc_str_find("bo\\la", 'l'));
-}
-
-
-static void
-test_str_to_bool(void **state)
-{
- assert_false(bc_str_to_bool(NULL));
- assert_true(bc_str_to_bool("1"));
- assert_true(bc_str_to_bool("y"));
- assert_true(bc_str_to_bool("Y"));
- assert_true(bc_str_to_bool("yes"));
- assert_true(bc_str_to_bool("YES"));
- assert_true(bc_str_to_bool("true"));
- assert_true(bc_str_to_bool("TRUE"));
- assert_true(bc_str_to_bool("on"));
- assert_true(bc_str_to_bool("ON"));
- assert_false(bc_str_to_bool("0"));
- assert_false(bc_str_to_bool("n"));
- assert_false(bc_str_to_bool("N"));
- assert_false(bc_str_to_bool("no"));
- assert_false(bc_str_to_bool("NO"));
- assert_false(bc_str_to_bool("false"));
- assert_false(bc_str_to_bool("FALSE"));
- assert_false(bc_str_to_bool("off"));
- assert_false(bc_str_to_bool("OFF"));
-}
-
-
-static void
-test_strv_join(void **state)
-{
- char *pieces[] = {"guda","bola", "chunda", NULL};
- char *str = bc_strv_join(pieces, ":");
- assert_string_equal(str, "guda:bola:chunda");
- free(str);
- char *pieces2[] = {NULL};
- str = bc_strv_join(pieces2, ":");
- assert_string_equal(str, "");
- free(str);
- assert_null(bc_strv_join(pieces, NULL));
- assert_null(bc_strv_join(NULL, ":"));
- assert_null(bc_strv_join(NULL, NULL));
-}
-
-
-static void
-test_strv_length(void **state)
-{
- char *pieces[] = {"guda","bola", "chunda", NULL};
- assert_int_equal(bc_strv_length(pieces), 3);
- char *pieces2[] = {NULL};
- assert_int_equal(bc_strv_length(pieces2), 0);
- assert_int_equal(bc_strv_length(NULL), 0);
-}
-
-
-static void
-test_string_new(void **state)
-{
- bc_string_t *str = bc_string_new();
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
-}
-
-
-static void
-test_string_free(void **state)
-{
- bc_string_t *str = bc_string_new();
- free(str->str);
- str->str = bc_strdup("bola");
- str->len = 4;
- str->allocated_len = BC_STRING_CHUNK_SIZE;
- char *tmp = bc_string_free(str, false);
- assert_string_equal(tmp, "bola");
- free(tmp);
- assert_null(bc_string_free(NULL, false));
-}
-
-
-static void
-test_string_dup(void **state)
-{
- bc_string_t *str = bc_string_new();
- free(str->str);
- str->str = bc_strdup("bola");
- str->len = 4;
- str->allocated_len = BC_STRING_CHUNK_SIZE;
- bc_string_t *new = bc_string_dup(str);
- assert_non_null(new);
- assert_string_equal(new->str, "bola");
- assert_int_equal(new->len, 4);
- assert_int_equal(new->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(new, true));
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_dup(NULL));
-}
-
-
-static void
-test_string_append_len(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_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, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- str = bc_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, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, "guda", 3);
- str = bc_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, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- str = bc_string_append_len(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600);
- str = bc_string_append_len(str, NULL, 0);
- str = bc_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, BC_STRING_CHUNK_SIZE * 10);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, NULL, 0);
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_len(NULL, "foo", 3));
-}
-
-
-static void
-test_string_append(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_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, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append(str, "guda");
- str = bc_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, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append(str, "guda");
- str = bc_string_append(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf");
- str = bc_string_append(str, NULL);
- str = bc_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, BC_STRING_CHUNK_SIZE * 10);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append(str, NULL);
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append(NULL, "asd"));
- assert_null(bc_string_append(NULL, NULL));
-}
-
-
-static void
-test_string_append_c(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- for (int i = 0; i < 600; i++)
- str = bc_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, BC_STRING_CHUNK_SIZE * 5);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_c(NULL, 0));
-}
-
-
-static void
-test_string_append_printf(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_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, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_printf(NULL, "asd"));
-}
-
-
-static void
-test_string_append_escaped(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append_escaped(str, NULL);
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- str = bc_string_append_escaped(str, "foo \\a bar \\\\ lol");
- assert_non_null(str);
- assert_string_equal(str->str, "foo a bar \\ lol");
- assert_int_equal(str->len, 15);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_escaped(NULL, "asd"));
-}
-
-
-static void
-test_trie_new(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
- assert_non_null(trie);
- assert_null(trie->root);
- assert_true(trie->free_func == free);
- bc_trie_free(trie);
-}
-
-
-static void
-test_trie_insert(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_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");
-
-
- bc_trie_insert(trie, "chu", bc_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");
-
-
- bc_trie_insert(trie, "bote", bc_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");
-
-
- bc_trie_insert(trie, "bo", bc_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");
-
- bc_trie_free(trie);
-
-
- trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_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");
-
-
- bc_trie_insert(trie, "bola", bc_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");
-
-
- bc_trie_insert(trie, "bote", bc_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");
-
-
- bc_trie_insert(trie, "bo", bc_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");
-
- bc_trie_free(trie);
-}
-
-
-static void
-test_trie_insert_duplicated(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_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");
-
- bc_trie_insert(trie, "bola", bc_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");
-
- bc_trie_free(trie);
-
- trie = NULL;
- bc_trie_insert(trie, "bola", NULL);
- assert_null(trie);
-}
-
-
-static void
-test_trie_keep_data(void **state)
-{
- bc_trie_t *trie = bc_trie_new(NULL);
-
- char *t1 = "guda";
- char *t2 = "nda";
- char *t3 = "aba";
- char *t4 = "haha";
-
- bc_trie_insert(trie, "bola", t1);
- bc_trie_insert(trie, "chu", t2);
- bc_trie_insert(trie, "bote", t3);
- bc_trie_insert(trie, "bo", t4);
-
- bc_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)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
-
- assert_string_equal(bc_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(bc_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(bc_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(bc_trie_lookup(trie, "bo"), "haha");
-
- assert_null(bc_trie_lookup(trie, "arcoiro"));
-
- bc_trie_free(trie);
-
- trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- bc_trie_insert(trie, "copa", bc_strdup("bu"));
- bc_trie_insert(trie, "b", bc_strdup("c"));
- bc_trie_insert(trie, "test", bc_strdup("asd"));
-
- assert_string_equal(bc_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(bc_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(bc_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(bc_trie_lookup(trie, "bo"), "haha");
-
- assert_null(bc_trie_lookup(trie, "arcoiro"));
-
- bc_trie_free(trie);
-
- assert_null(bc_trie_lookup(NULL, "bola"));
-}
-
-
-static void
-test_trie_size(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
-
- assert_int_equal(bc_trie_size(trie), 4);
- assert_int_equal(bc_trie_size(NULL), 0);
-
- bc_trie_free(trie);
-
- trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- bc_trie_insert(trie, "copa", bc_strdup("bu"));
- bc_trie_insert(trie, "b", bc_strdup("c"));
- bc_trie_insert(trie, "test", bc_strdup("asd"));
-
- assert_int_equal(bc_trie_size(trie), 7);
- assert_int_equal(bc_trie_size(NULL), 0);
-
- bc_trie_free(trie);
-}
-
-
-static size_t counter;
-static char *expected_keys[] = {"chu", "copa", "bola", "bote", "bo", "b", "test", "testa"};
-static char *expected_datas[] = {"nda", "bu", "guda", "aba", "haha", "c", "asd", "lol"};
-
-static void
-mock_foreach(const char *key, void *data, void *user_data)
-{
- assert_string_equal(user_data, "foo");
- assert_string_equal(key, expected_keys[counter]);
- assert_string_equal((char*) data, expected_datas[counter++]);
-}
-
-
-static void
-test_trie_foreach(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- bc_trie_insert(trie, "copa", bc_strdup("bu"));
- bc_trie_insert(trie, "b", bc_strdup("c"));
- bc_trie_insert(trie, "test", bc_strdup("asd"));
- bc_trie_insert(trie, "testa", bc_strdup("lol"));
-
- counter = 0;
- bc_trie_foreach(trie, mock_foreach, "foo");
- bc_trie_foreach(NULL, mock_foreach, "foo");
- bc_trie_foreach(trie, NULL, "foo");
- bc_trie_foreach(NULL, NULL, "foo");
- assert_int_equal(counter, 8);
-
- bc_trie_free(trie);
-}
-
-
-static void
-test_trie_inserted_after_prefix(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_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");
-
- bc_trie_insert(trie, "bolaoo", bc_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, "guda");
- assert_non_null(trie->root->child->child->child->child->next);
- assert_true(trie->root->child->child->child->child->next->key == 'o');
- assert_null(trie->root->child->child->child->child->next->data);
- assert_true(trie->root->child->child->child->child->next->child->key == 'o');
- assert_null(trie->root->child->child->child->child->next->child->data);
- assert_true(trie->root->child->child->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->next->child->child->data, "asdf");
-
- assert_int_equal(bc_trie_size(trie), 2);
- assert_string_equal(bc_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(bc_trie_lookup(trie, "bolaoo"), "asdf");
-
- bc_trie_free(trie);
-}
-
-
-static void
-test_shell_quote(void **state)
-{
- char *t;
- t = bc_shell_quote(NULL);
- assert_string_equal(t, "''");
- free(t);
- t = bc_shell_quote("!bola");
- assert_string_equal(t, "''\\!'bola'");
- free(t);
- t = bc_shell_quote("'bola");
- assert_string_equal(t, "''\\''bola'");
- free(t);
- t = bc_shell_quote("bo!bola");
- assert_string_equal(t, "'bo'\\!'bola'");
- free(t);
- t = bc_shell_quote("bo'bola");
- assert_string_equal(t, "'bo'\\''bola'");
- free(t);
- t = bc_shell_quote("bola!");
- assert_string_equal(t, "'bola'\\!''");
- free(t);
- t = bc_shell_quote("bola'");
- assert_string_equal(t, "'bola'\\'''");
- free(t);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
-
- // slist
- unit_test(test_slist_append),
- unit_test(test_slist_prepend),
- unit_test(test_slist_free),
- unit_test(test_slist_length),
-
- // strfuncs
- unit_test(test_strdup),
- unit_test(test_strndup),
- unit_test(test_strdup_printf),
- unit_test(test_str_starts_with),
- unit_test(test_str_ends_with),
- unit_test(test_str_lstrip),
- unit_test(test_str_rstrip),
- unit_test(test_str_strip),
- unit_test(test_str_split),
- unit_test(test_str_replace),
- unit_test(test_str_find),
- unit_test(test_str_to_bool),
- unit_test(test_strv_join),
- unit_test(test_strv_length),
-
- // string
- unit_test(test_string_new),
- unit_test(test_string_free),
- unit_test(test_string_dup),
- unit_test(test_string_append_len),
- unit_test(test_string_append),
- unit_test(test_string_append_c),
- unit_test(test_string_append_printf),
- unit_test(test_string_append_escaped),
-
- // 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),
- unit_test(test_trie_inserted_after_prefix),
-
- // shell
- unit_test(test_shell_quote),
- };
- return run_tests(tests);
-}