Skip to content

Commit cd084ae

Browse files
committed
test.cpp: added tests for incomplete UTF sequences
1 parent 76b94e3 commit cd084ae

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

test.cpp

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

2236+
static void utf8_invalid()
2237+
{
2238+
ASSERT_EQUALS("", readfile("\xEF 123"));
2239+
ASSERT_EQUALS("", readfile("\xEF\xBB 123"));
2240+
}
2241+
22362242
static void unicode()
22372243
{
22382244
{
@@ -2265,6 +2271,42 @@ static void unicode()
22652271
}
22662272
}
22672273

2274+
static void unicode_invalid()
2275+
{
2276+
{
2277+
const char code[] = "\xFF";
2278+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2279+
}
2280+
{
2281+
const char code[] = "\xFE";
2282+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2283+
}
2284+
{
2285+
const char code[] = "\xFE\xFF\x31";
2286+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2287+
}
2288+
{
2289+
const char code[] = "\xFF\xFE\x31";
2290+
ASSERT_EQUALS("1", readfile(code, sizeof(code)));
2291+
}
2292+
{
2293+
const char code[] = "\xFE\xFF\x31\x32";
2294+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2295+
}
2296+
{
2297+
const char code[] = "\xFF\xFE\x31\x32";
2298+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2299+
}
2300+
{
2301+
const char code[] = "\xFE\xFF\x00\x31\x00\x32\x33";
2302+
ASSERT_EQUALS("", readfile(code, sizeof(code)));
2303+
}
2304+
{
2305+
const char code[] = "\xFF\xFE\x31\x00\x32\x00\x33";
2306+
ASSERT_EQUALS("123", readfile(code, sizeof(code)));
2307+
}
2308+
}
2309+
22682310
static void warning()
22692311
{
22702312
const char code[] = "#warning MSG\n1";
@@ -2687,7 +2729,9 @@ int main(int argc, char **argv)
26872729

26882730
// utf/unicode
26892731
TEST_CASE(utf8);
2732+
TEST_CASE(utf8_invalid);
26902733
TEST_CASE(unicode);
2734+
TEST_CASE(unicode_invalid);
26912735

26922736
TEST_CASE(warning);
26932737

0 commit comments

Comments
 (0)