aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/blogc-git-receiver/check_post_receive.c20
-rw-r--r--tests/blogc-make/check_atom.c36
-rw-r--r--tests/blogc-make/check_exec.c102
-rw-r--r--tests/blogc-make/check_rules.c80
-rw-r--r--tests/blogc-make/check_settings.c172
-rw-r--r--tests/blogc-runserver/check_httpd_utils.c5
-rw-r--r--tests/blogc/check_datetime_parser.c220
-rw-r--r--tests/blogc/check_loader.c736
-rw-r--r--tests/blogc/check_renderer.c374
-rw-r--r--tests/blogc/check_source_parser.c325
-rw-r--r--tests/blogc/check_template_parser.c367
-rw-r--r--tests/common/check_config_parser.c719
-rw-r--r--tests/common/check_error.c109
-rw-r--r--tests/common/check_stdin.c54
-rw-r--r--tests/common/check_utf8.c101
-rw-r--r--tests/common/check_utils.c1069
16 files changed, 1220 insertions, 3269 deletions
diff --git a/tests/blogc-git-receiver/check_post_receive.c b/tests/blogc-git-receiver/check_post_receive.c
index 5d2d742..ed582e9 100644
--- a/tests/blogc-git-receiver/check_post_receive.c
+++ b/tests/blogc-git-receiver/check_post_receive.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/post-receive.h"
@@ -24,20 +24,20 @@ __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_post_receive_get_config_section(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
- 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_post_receive_get_config_section(config,
"/home/blogc/repos/foo.git", "/home/blogc"));
- bc_config_free(config);
+ sb_config_free(config);
will_return(__wrap_realpath, NULL);
will_return(__wrap_realpath, "/home/blogc/repos/bar.git");
@@ -51,13 +51,13 @@ test_post_receive_get_config_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_post_receive_get_config_section(config,
"/home/blogc/repos/bar.git", "/home/blogc");
assert_string_equal(s, "repo:bar.git");
free(s);
- bc_config_free(config);
+ sb_config_free(config);
will_return(__wrap_realpath, NULL);
will_return(__wrap_realpath, "/home/blogc/repos/asd/bar.git");
@@ -71,13 +71,13 @@ test_post_receive_get_config_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_post_receive_get_config_section(config,
"/home/blogc/repos/asd/bar.git", "/home/blogc");
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 6faa53e..9c17a61 100644
--- a/tests/blogc-make/check_atom.c
+++ b/tests/blogc-make/check_atom.c
@@ -13,31 +13,29 @@
#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_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"));
+ 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"));
- bc_error_t *err = NULL;
+ 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);
@@ -77,7 +75,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);
}
@@ -85,20 +83,20 @@ 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"));
+ 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"));
- bc_error_t *err = NULL;
+ 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);
@@ -138,7 +136,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);
}
diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c
index c3a8193..6be3074 100644
--- a/tests/blogc-make/check_exec.c
+++ b/tests/blogc-make/check_exec.c
@@ -18,10 +18,10 @@
#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 +75,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, true,
@@ -106,10 +106,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);
}
@@ -117,16 +117,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, true,
@@ -151,10 +151,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);
}
@@ -162,17 +162,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, true,
"main.tmpl", "foo.html", true, true);
@@ -196,11 +196,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);
}
@@ -208,10 +208,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, true,
"main.tmpl", "foo.html", false, true);
@@ -231,8 +231,8 @@ 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);
}
diff --git a/tests/blogc-make/check_rules.c b/tests/blogc-make/check_rules.c
index c8bd9a8..3154380 100644
--- a/tests/blogc-make/check_rules.c
+++ b/tests/blogc-make/check_rules.c
@@ -13,70 +13,70 @@
#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 6eaaaec..a5940bb 100644
--- a/tests/blogc-make/check_settings.c
+++ b/tests/blogc-make/check_settings.c
@@ -13,24 +13,24 @@
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
+#include "../../src/blogc-make/error.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_int_equal(err->code, BLOGC_MAKE_ERROR_SETTINGS);
assert_string_equal(err->msg,
"[global] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -45,14 +45,14 @@ 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_int_equal(err->code, BLOGC_MAKE_ERROR_SETTINGS);
assert_string_equal(err->msg,
"[global] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -67,14 +67,14 @@ 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_int_equal(err->code, BLOGC_MAKE_ERROR_SETTINGS);
assert_string_equal(err->msg,
"[environment] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -113,36 +113,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_null(s->root_dir);
- 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), 15);
- 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), 15);
+ 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(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_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
@@ -202,36 +202,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_null(s->root_dir);
- 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), 15);
- 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), 15);
+ 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(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_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
@@ -291,36 +291,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_null(s->root_dir);
- 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), 15);
- 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), 15);
+ 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(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_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
diff --git a/tests/blogc-runserver/check_httpd_utils.c b/tests/blogc-runserver/check_httpd_utils.c
index e0fabe3..c3d4844 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 eb9a0a6..05ba09b 100644
--- a/tests/blogc/check_datetime_parser.c
+++ b/tests/blogc/check_datetime_parser.c
@@ -12,14 +12,16 @@
#include <cmocka.h>
#include <stdlib.h>
#include <locale.h>
-#include "../../src/common/error.h"
+#include <squareball.h>
+
+#include "../../src/blogc/error.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 +33,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 +45,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 +57,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 +69,529 @@ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '20', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '201', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11-', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11-3', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11-30 ', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11-30 1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid year. Found 1899, must be >= 1900.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid separator between year and month. Found ' ', must be '-'.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid month. Found 13, must be >= 1 and <= 12.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid separator between month and day. Found ' ', must be '-'.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid day. Found 32, must be >= 1 and <= 31.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid hours. Found 24, must be >= 0 and <= 23.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid separator between hours and minutes. Found ' ', must be ':'.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid separator between minutes and seconds. Found ' ', must be ':'.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ 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_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Invalid seconds. Found 69, must be >= 0 and <= 60.");
- bc_error_free(err);
+ 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,7 +610,7 @@ test_convert_datetime_invalid_format_long(void **state)
"jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
+ assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER);
assert_string_equal(err->msg,
"Failed to format DATE variable, FORMAT is too long: "
"bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
@@ -626,7 +628,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_loader.c b/tests/blogc/check_loader.c
index 504b296..6bae759 100644
--- a/tests/blogc/check_loader.c
+++ b/tests/blogc/check_loader.c
@@ -13,8 +13,9 @@
#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/error.h"
#include "../../src/blogc/template-parser.h"
#include "../../src/blogc/loader.h"
@@ -50,9 +51,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 +68,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 +82,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 +94,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,654 +129,654 @@ 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_reverse(void **state)
{
- 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, "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, "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"));
- 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(""));
- 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(""));
+ 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"), "");
- 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"), "");
+ 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_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_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_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), 11);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola7");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06");
- 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), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola7");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "2");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
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_int_equal(err->code, BLOGC_ERROR_LOADER);
assert_string_equal(err->msg,
"'DATE' variable provided for at least one source file, but not for "
"all source files. It must be provided for all files.\n");
- 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_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 369ba3d..51bf20a 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, 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, 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);
}
@@ -171,8 +171,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, true);
@@ -198,11 +198,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, false);
assert_string_equal(out,
@@ -210,7 +210,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);
}
@@ -227,11 +227,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, false);
assert_string_equal(out,
@@ -241,7 +241,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);
}
@@ -258,11 +258,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, false);
assert_string_equal(out,
@@ -274,7 +274,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);
}
@@ -293,11 +293,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, false);
assert_string_equal(out,
@@ -310,7 +310,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);
}
@@ -329,11 +329,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, false);
assert_string_equal(out,
@@ -344,7 +344,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);
}
@@ -363,11 +363,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, false);
assert_string_equal(out,
@@ -376,7 +376,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);
}
@@ -396,11 +396,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, false);
assert_string_equal(out,
@@ -414,7 +414,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);
}
@@ -432,11 +432,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, false);
assert_string_equal(out,
@@ -449,7 +449,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);
}
@@ -468,11 +468,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, false);
assert_string_equal(out,
@@ -486,7 +486,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);
}
@@ -505,11 +505,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, false);
assert_string_equal(out,
@@ -523,7 +523,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);
}
@@ -542,11 +542,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, false);
assert_string_equal(out,
@@ -560,7 +560,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);
}
@@ -579,11 +579,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, false);
assert_string_equal(out,
@@ -597,7 +597,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);
}
@@ -618,11 +618,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, false);
assert_string_equal(out,
@@ -638,7 +638,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);
}
@@ -659,11 +659,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, false);
assert_string_equal(out,
@@ -679,7 +679,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);
}
@@ -691,11 +691,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, false);
assert_string_equal(out,
@@ -703,7 +703,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);
}
@@ -716,11 +716,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, false);
assert_string_equal(out,
@@ -728,7 +728,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);
}
@@ -742,11 +742,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, false);
assert_string_equal(out,
@@ -754,7 +754,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);
}
@@ -773,22 +773,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, 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);
}
@@ -806,15 +806,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, c, false);
assert_string_equal(out,
"\n"
@@ -825,9 +825,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);
}
@@ -842,13 +842,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, c, false);
assert_string_equal(out,
"\n"
@@ -857,9 +857,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);
}
@@ -874,23 +874,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, 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);
}
@@ -898,100 +898,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);
}
@@ -999,13 +999,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);
@@ -1023,19 +1023,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);
@@ -1045,18 +1045,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);
@@ -1068,7 +1068,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);
}
@@ -1083,31 +1083,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_source_parser.c b/tests/blogc/check_source_parser.c
index d40633f..142e957 100644
--- a/tests/blogc/check_source_parser.c
+++ b/tests/blogc/check_source_parser.c
@@ -11,8 +11,9 @@
#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/error.h"
#include "../../src/blogc/source-parser.h"
@@ -26,26 +27,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 +60,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 +95,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 +133,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 +157,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 +174,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 +208,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 +235,14 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg, "Your source file is empty.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -249,15 +250,15 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Can't find a configuration key or the content separator.\n"
"Error occurred near line 1, position 1: bola: guda");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -265,15 +266,15 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Invalid configuration key.\n"
"Error occurred near line 1, position 4: BOLa");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -281,15 +282,15 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Your last configuration key is missing ':' and the value\n"
"Error occurred near line 1, position 5: BOLA");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -298,12 +299,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 +312,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -328,16 +329,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'FILENAME' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -345,16 +346,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'CONTENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -362,16 +363,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'DATE_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -379,16 +380,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -396,16 +397,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -413,16 +414,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'PAGE_FIRST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -430,16 +431,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -447,16 +448,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'PAGE_CURRENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -464,16 +465,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'PAGE_NEXT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -481,16 +482,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'PAGE_LAST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -498,16 +499,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"'BLOGC_VERSION' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -515,16 +516,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"No line ending after the configuration value for 'BOLA'.\n"
"Error occurred near line 1, position 10: BOLA: asd");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -532,16 +533,16 @@ 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_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Invalid content separator. Must be more than one '-' characters.\n"
"Error occurred near line 2, position 4: ---#");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c
index a6d9034..2720534 100644
--- a/tests/blogc/check_template_parser.c
+++ b/tests/blogc/check_template_parser.c
@@ -11,13 +11,14 @@
#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/error.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 +31,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;
@@ -59,8 +60,8 @@ test_template_parse(void **state)
"{% block listing_once %}asd{% endblock %}\n"
"{%- foreach BOLA %}hahaha{% endforeach %}\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",
@@ -77,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);
@@ -143,8 +144,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",
@@ -161,7 +162,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);
@@ -235,8 +236,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 ",
@@ -255,7 +256,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);
@@ -345,8 +346,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);
@@ -362,7 +363,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",
@@ -392,8 +393,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);
@@ -409,7 +410,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,
@@ -444,35 +445,35 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Must begin with lowercase letter.\n"
"Error occurred near line 1, position 4: {% ASD %}");
- 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Duplicated whitespace cleaner before statement.\n"
"Error occurred near line 1, position 4: {%-- block entry %}");
- 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Duplicated whitespace cleaner after statement.\n"
"Error occurred near line 1, position 17: {% block entry --%}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -482,15 +483,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Blocks can't be nested.\n"
"Error occurred near line 2, position 9: {% block listing %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -500,15 +501,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'foreach' statements can't be nested.\n"
"Error occurred near line 2, position 11: {% foreach B %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -516,15 +517,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'endblock' statement without an open 'block' statement.\n"
"Error occurred near line 1, position 12: {% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -532,16 +533,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'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);
}
@@ -549,16 +550,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'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);
}
@@ -566,16 +567,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'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);
}
@@ -583,15 +584,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 14: {% endforeach %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -600,16 +601,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 49: {% foreach TAGS %}"
"{% block entry %}{% endforeach %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -618,16 +619,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 65: {% block entry %}"
"{% foreach TAGS %}{% endforeach %}{% endforeach %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -636,14 +637,14 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"An open 'foreach' statement was not closed inside a 'entry' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -652,14 +653,14 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"An open 'foreach' statement was not closed inside a 'entry' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -667,16 +668,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"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);
}
@@ -684,15 +685,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid block syntax. Must begin with lowercase letter.\n"
"Error occurred near line 1, position 10: {% block ENTRY %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -700,15 +701,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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n"
"Error occurred near line 1, position 16: {% block chunda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -716,16 +717,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{% ifdef guda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -733,16 +734,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid foreach variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 29: "
"{% block entry %}{% foreach guda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -750,16 +751,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 28: "
"{% block entry %}{% ifdef BoLA %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -767,16 +768,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{% ifdef 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -784,16 +785,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid foreach variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 30: "
"{% block entry %}{% foreach BoLA %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -801,16 +802,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid foreach variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 29: {% block entry %}"
"{% foreach 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -818,16 +819,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n"
"Error occurred near line 1, position 29: "
"{% block entry %}{% if BOLA = \"asd\" %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -835,16 +836,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid 'if' operand. Must be double-quoted static string or variable.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == asd %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -852,16 +853,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Found an open double-quoted string.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == \"asd %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -869,16 +870,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid 'if' operand. Must be double-quoted static string or variable.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -886,15 +887,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"'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);
}
@@ -902,16 +903,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"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);
}
@@ -926,15 +927,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"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);
}
@@ -942,15 +943,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Must end with '%}'.\n"
"Error occurred near line 1, position 16: {% block entry }}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -958,16 +959,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 21: "
"{% block entry %}{{ bola }}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -975,16 +976,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 22: "
"{% block entry %}{{ Bola }}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -992,16 +993,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}"
"{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1009,16 +1010,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Must end with '}}'.\n"
"Error occurred near line 1, position 26: "
"{% block entry %}{{ BOLA %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1026,15 +1027,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Must end with '}'.\n"
"Error occurred near line 1, position 17: {% block entry %%");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1042,16 +1043,16 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"Invalid statement syntax. Must end with '}'.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{{ BOLA }%{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1059,14 +1060,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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg, "1 open 'if', 'ifdef' and/or 'ifndef' statements "
"were not closed!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1074,15 +1075,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
"a 'listing' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1090,15 +1091,15 @@ 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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg,
"1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
"a 'listing' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1106,13 +1107,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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg, "An open block was not closed!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1120,13 +1121,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_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER);
assert_string_equal(err->msg, "An open 'foreach' statement was not closed!");
- bc_error_free(err);
+ 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 b1e42a6..0000000
--- a/tests/common/check_config_parser.c
+++ /dev/null
@@ -1,719 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2017 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_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_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 e2b4c9f..0000000
--- a/tests/common/check_error.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2017 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_stdin.c b/tests/common/check_stdin.c
deleted file mode 100644
index 64c4714..0000000
--- a/tests/common/check_stdin.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2017 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 fd2c4f1..0000000
--- a/tests/common/check_utf8.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2017 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 12ef921..0000000
--- a/tests/common/check_utils.c
+++ /dev/null
@@ -1,1069 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2017 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_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_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);
-}