aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_utf8.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/check_utf8.c')
-rw-r--r--tests/check_utf8.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/check_utf8.c b/tests/check_utf8.c
index b0dec4e..9f98886 100644
--- a/tests/check_utf8.c
+++ b/tests/check_utf8.c
@@ -18,6 +18,8 @@
#include "../src/utf8.h"
#include "../src/utils.h"
+// this file MUST be ASCII
+
static void
test_utf8_valid(void **state)
@@ -25,8 +27,10 @@ test_utf8_valid(void **state)
const char *c = "<a href=\"{{ BASE_URL }}/page/{{ PREVIOUS_PAGE }}/\">"
"\xc2\xab Newer posts</a>";
assert_true(blogc_utf8_validate((uint8_t*) c, strlen(c)));
- const uint8_t d[3] = {0xe2, 0x82, 0xac};
+ const uint8_t d[3] = {0xe2, 0x82, 0xac}; // euro sign
assert_true(blogc_utf8_validate(d, 3));
+ const uint8_t e[3] = {0xef, 0xbb, 0xbf}; // utf-8 bom
+ assert_true(blogc_utf8_validate(e, 3));
}
@@ -70,6 +74,21 @@ test_utf8_invalid_str(void **state)
}
+static void
+test_utf8_skip_bom(void **state)
+{
+ const char c[4] = {0xef, 0xbb, 0xbf, 0};
+ assert_int_equal(blogc_utf8_skip_bom(c, 2), 0);
+ assert_int_equal(blogc_utf8_skip_bom(c, 3), 3);
+ assert_string_equal(c + 3, "");
+ const char d[8] = {0xef, 0xbb, 0xbf, 'b', 'o', 'l', 'a', 0};
+ assert_int_equal(blogc_utf8_skip_bom(d, 8), 3);
+ assert_string_equal(d + 3, "bola");
+ const char e[5] = "bola";
+ assert_int_equal(blogc_utf8_skip_bom(e, 4), 0);
+}
+
+
int
main(void)
{
@@ -78,6 +97,7 @@ main(void)
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);
}