Skip to content

Commit 4fb6599

Browse files
committed
test.cpp: added tests for incomplete UTF sequences
1 parent 33c7f5c commit 4fb6599

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
@@ -2217,6 +2217,12 @@ static void utf8()
22172217
ASSERT_EQUALS("123", readfile("\xEF\xBB\xBF 123"));
22182218
}
22192219

2220+
static void utf8_invalid()
2221+
{
2222+
ASSERT_EQUALS("", readfile("\xEF 123"));
2223+
ASSERT_EQUALS("", readfile("\xEF\xBB 123"));
2224+
}
2225+
22202226
static void unicode()
22212227
{
22222228
{
@@ -2249,6 +2255,42 @@ static void unicode()
22492255
}
22502256
}
22512257

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

26132655
// utf/unicode
26142656
TEST_CASE(utf8);
2657+
TEST_CASE(utf8_invalid);
26152658
TEST_CASE(unicode);
2659+
TEST_CASE(unicode_invalid);
26162660

26172661
TEST_CASE(warning);
26182662

0 commit comments

Comments
 (0)