Skip to content

Commit 1f8d856

Browse files
committed
test.cpp: added tests for incomplete UTF sequences
1 parent 6635c5b commit 1f8d856

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,12 @@ static void utf8()
22152215
ASSERT_EQUALS("123", readfile("\xEF\xBB\xBF 123"));
22162216
}
22172217

2218+
static void utf8_invalid()
2219+
{
2220+
ASSERT_EQUALS("", readfile("\xEF 123"));
2221+
ASSERT_EQUALS("", readfile("\xEF\xBB 123"));
2222+
}
2223+
22182224
static void unicode()
22192225
{
22202226
{
@@ -2247,6 +2253,42 @@ static void unicode()
22472253
}
22482254
}
22492255

2256+
static void unicode_invalid()
2257+
{
2258+
{
2259+
const char code[] = "\xFF";
2260+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2261+
}
2262+
{
2263+
const char code[] = "\xFE";
2264+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2265+
}
2266+
{
2267+
const char code[] = "\xFE\xFF\x31";
2268+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2269+
}
2270+
{
2271+
const char code[] = "\xFF\xFE\x31";
2272+
ASSERT_EQUALS("1", readfile(code, sizeof(code)));
2273+
}
2274+
{
2275+
const char code[] = "\xFE\xFF\x31\x32";
2276+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2277+
}
2278+
{
2279+
const char code[] = "\xFF\xFE\x31\x32";
2280+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2281+
}
2282+
{
2283+
const char code[] = "\xFE\xFF\x00\x31\x00\x32\x33";
2284+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2285+
}
2286+
{
2287+
const char code[] = "\xFF\xFE\x31\x00\x32\x00\x33";
2288+
ASSERT_EQUALS("123", readfile(code, sizeof(code)));
2289+
}
2290+
}
2291+
22502292
static void warning()
22512293
{
22522294
const char code[] = "#warning MSG\n1";
@@ -2604,7 +2646,9 @@ static void runTests(int argc, char **argv, Input input)
26042646

26052647
// utf/unicode
26062648
TEST_CASE(utf8);
2649+
TEST_CASE(utf8_invalid);
26072650
TEST_CASE(unicode);
2651+
TEST_CASE(unicode_invalid);
26082652

26092653
TEST_CASE(warning);
26102654

0 commit comments

Comments
 (0)