summaryrefslogtreecommitdiff
path: root/tests/unistr/test-u8-mbtouc.c
diff options
context:
space:
mode:
authorManuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>2016-05-27 14:28:30 +0100
committerManuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>2016-05-27 14:28:30 +0100
commita9a31b1de5776a3b08a82101a4fa711294f0dd1d (patch)
tree159134a624e51509f40ed8823249f09a70d1dda3 /tests/unistr/test-u8-mbtouc.c
parent5f2b09982312c98863eb9a8dfe2c608b81f58259 (diff)
Imported Upstream version 0.9.6+really0.9.3upstream/0.9.6+really0.9.3
Diffstat (limited to 'tests/unistr/test-u8-mbtouc.c')
-rw-r--r--tests/unistr/test-u8-mbtouc.c161
1 files changed, 1 insertions, 160 deletions
diff --git a/tests/unistr/test-u8-mbtouc.c b/tests/unistr/test-u8-mbtouc.c
index 9e3b9601..f6960a68 100644
--- a/tests/unistr/test-u8-mbtouc.c
+++ b/tests/unistr/test-u8-mbtouc.c
@@ -1,5 +1,5 @@
/* Test of u8_mbtouc() function.
- Copyright (C) 2010-2015 Free Software Foundation, Inc.
+ Copyright (C) 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,169 +24,10 @@
#include "test-u8-mbtouc.h"
-static void
-test_safe_function (int (*my_u8_mbtouc) (ucs4_t *, const uint8_t *, size_t))
-{
- ucs4_t uc;
- int ret;
-
- /* Test behaviour required by ISO 10646-1, sections R.7 and 2.3c, namely,
- that a "malformed sequence" is interpreted in the same way as
- "a character that is outside the adopted subset".
- Reference:
- Markus Kuhn: UTF-8 decoder capability and stress test
- <http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt>
- <http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html>
- */
- /* 3.1. Test that each unexpected continuation byte is signalled as a
- malformed sequence of its own. */
- {
- static const uint8_t input[] = { '"', 0x80, 0xBF, 0x80, 0xBF, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 6);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 5);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 2, 4);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 3, 3);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 4, 2);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 5, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
- /* 3.2. Lonely start characters. */
- {
- ucs4_t c;
- uint8_t input[2];
-
- for (c = 0xC0; c <= 0xFF; c++)
- {
- input[0] = c;
- input[1] = ' ';
-
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 2);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- }
- }
- /* 3.3. Sequences with last continuation byte missing. */
- /* 3.3.1. 2-byte sequence with last byte missing. */
- {
- static const uint8_t input[] = { '"', 0xC0, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 3);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 2);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 2, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
- /* 3.3.6. 2-byte sequence with last byte missing. */
- {
- static const uint8_t input[] = { '"', 0xDF, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 3);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 2);
- ASSERT (ret == 1);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 2, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
- /* 3.3.2. 3-byte sequence with last byte missing. */
- {
- static const uint8_t input[] = { '"', 0xE0, 0x80, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 4);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 3);
- ASSERT (ret == 2);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 3, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
- /* 3.3.7. 3-byte sequence with last byte missing. */
- {
- static const uint8_t input[] = { '"', 0xEF, 0xBF, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 4);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 3);
- ASSERT (ret == 2);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 3, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
- /* 3.3.3. 4-byte sequence with last byte missing. */
- {
- static const uint8_t input[] = { '"', 0xF0, 0x80, 0x80, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 5);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 4);
- ASSERT (ret == 3);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 4, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
- /* 3.3.8. 4-byte sequence with last byte missing. */
- {
- static const uint8_t input[] = { '"', 0xF7, 0xBF, 0xBF, '"' };
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input, 5);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 1, 4);
- ASSERT (ret == 3);
- ASSERT (uc == 0xFFFD);
- uc = 0xBADFACE;
- ret = my_u8_mbtouc (&uc, input + 4, 1);
- ASSERT (ret == 1);
- ASSERT (uc == 0x0022);
- }
-}
-
int
main ()
{
test_function (u8_mbtouc);
- test_safe_function (u8_mbtouc);
return 0;
}