aboutsummaryrefslogtreecommitdiffstats
path: root/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common')
-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
5 files changed, 0 insertions, 2052 deletions
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);
-}