Skip to content

Commit 5611856

Browse files
committed
test.cpp: added tests for incomplete UTF sequences
1 parent f13de95 commit 5611856

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
@@ -2275,6 +2275,12 @@ static void utf8()
22752275
ASSERT_EQUALS("123", readfile("\xEF\xBB\xBF 123"));
22762276
}
22772277

2278+
static void utf8_invalid()
2279+
{
2280+
ASSERT_EQUALS("", readfile("\xEF 123"));
2281+
ASSERT_EQUALS("", readfile("\xEF\xBB 123"));
2282+
}
2283+
22782284
static void unicode()
22792285
{
22802286
{
@@ -2307,6 +2313,42 @@ static void unicode()
23072313
}
23082314
}
23092315

2316+
static void unicode_invalid()
2317+
{
2318+
{
2319+
const char code[] = "\xFF";
2320+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2321+
}
2322+
{
2323+
const char code[] = "\xFE";
2324+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2325+
}
2326+
{
2327+
const char code[] = "\xFE\xFF\x31";
2328+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2329+
}
2330+
{
2331+
const char code[] = "\xFF\xFE\x31";
2332+
ASSERT_EQUALS("1", readfile(code, sizeof(code)));
2333+
}
2334+
{
2335+
const char code[] = "\xFE\xFF\x31\x32";
2336+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2337+
}
2338+
{
2339+
const char code[] = "\xFF\xFE\x31\x32";
2340+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2341+
}
2342+
{
2343+
const char code[] = "\xFE\xFF\x00\x31\x00\x32\x33";
2344+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2345+
}
2346+
{
2347+
const char code[] = "\xFF\xFE\x31\x00\x32\x00\x33";
2348+
ASSERT_EQUALS("123", readfile(code, sizeof(code)));
2349+
}
2350+
}
2351+
23102352
static void warning()
23112353
{
23122354
const char code[] = "#warning MSG\n1";
@@ -2672,7 +2714,9 @@ static void runTests(int argc, char **argv, Input input)
26722714

26732715
// utf/unicode
26742716
TEST_CASE(utf8);
2717+
TEST_CASE(utf8_invalid);
26752718
TEST_CASE(unicode);
2719+
TEST_CASE(unicode_invalid);
26762720

26772721
TEST_CASE(warning);
26782722

0 commit comments

Comments
 (0)