From 5f2b09982312c98863eb9a8dfe2c608b81f58259 Mon Sep 17 00:00:00 2001 From: "Manuel A. Fernandez Montecelo" Date: Thu, 26 May 2016 16:48:15 +0100 Subject: Imported Upstream version 0.9.6 --- tests/unistr/test-u8-mbsnlen.c | 61 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'tests/unistr/test-u8-mbsnlen.c') diff --git a/tests/unistr/test-u8-mbsnlen.c b/tests/unistr/test-u8-mbsnlen.c index 8e68550..e57e3ea 100644 --- a/tests/unistr/test-u8-mbsnlen.c +++ b/tests/unistr/test-u8-mbsnlen.c @@ -1,5 +1,5 @@ /* Test of u8_mbsnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 @@ -57,5 +57,64 @@ main () } } + /* 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 + + + */ + /* 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, '"' }; + ASSERT (u8_mbsnlen (input, 6) == 6); + } + /* 3.2. Lonely start characters. */ + { + ucs4_t c; + uint8_t input[2]; + + for (c = 0xC0; c <= 0xFF; c++) + { + input[0] = c; + input[1] = ' '; + + ASSERT (u8_mbsnlen (input, 2) == 2); + } + } + /* 3.3. Sequences with last continuation byte missing. */ + /* 3.3.1. 2-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xC0, '"' }; + ASSERT (u8_mbsnlen (input, 3) == 3); + } + /* 3.3.6. 2-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xDF, '"' }; + ASSERT (u8_mbsnlen (input, 3) == 3); + } + /* 3.3.2. 3-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xE0, 0x80, '"' }; + ASSERT (u8_mbsnlen (input, 4) == 3); + } + /* 3.3.7. 3-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xEF, 0xBF, '"' }; + ASSERT (u8_mbsnlen (input, 4) == 3); + } + /* 3.3.3. 4-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xF0, 0x80, 0x80, '"' }; + ASSERT (u8_mbsnlen (input, 5) == 3); + } + /* 3.3.8. 4-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xF7, 0xBF, 0xBF, '"' }; + ASSERT (u8_mbsnlen (input, 5) == 3); + } + return 0; } -- cgit v1.2.3