From 1099a4d991942655c0291a74b488322d5da533bd Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 3 Jul 2016 21:52:51 +0200 Subject: utf8: skip BOM, if found --- tests/check_utf8.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests') 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 = "" "\xc2\xab Newer posts"; 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); } -- cgit v1.2.3-18-g5258