@@ -2679,7 +2679,7 @@ static void readfile_nullbyte()
26792679 const char code[] = " ab\0 cd" ;
26802680 simplecpp::OutputList outputList;
26812681 ASSERT_EQUALS (" ab cd" , readfile (code,sizeof (code), &outputList));
2682- ASSERT_EQUALS (true , outputList.empty ()); // should warning be written?
2682+ ASSERT_EQUALS (true , outputList.empty ()); // TODO: should warning be written?
26832683}
26842684
26852685static void readfile_char ()
@@ -2829,6 +2829,71 @@ static void readfile_file_not_found()
28292829 ASSERT_EQUALS (" file0,0,file_not_found,File is missing: NotAFile\n " , toString (outputList));
28302830}
28312831
2832+ static void readfile_empty ()
2833+ {
2834+ const char code[] = " " ;
2835+ simplecpp::OutputList outputList;
2836+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2837+ ASSERT_EQUALS (true , outputList.empty ());
2838+ }
2839+
2840+ // the BOM/UTF-16 detection reads two bytes
2841+ static void readfile_onebyte ()
2842+ {
2843+ const char code[] = " ." ;
2844+ simplecpp::OutputList outputList;
2845+ ASSERT_EQUALS (" ." , readfile (code,sizeof (code), &outputList));
2846+ ASSERT_EQUALS (true , outputList.empty ());
2847+ }
2848+
2849+ static void readfile_utf16_le_unsupported ()
2850+ {
2851+ const char code[] = " \xfe\xff\xd8\x3d\xde\x42 " ; // smiley emoji
2852+ simplecpp::OutputList outputList;
2853+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2854+ ASSERT_EQUALS (" file0,1,unhandled_char_error,The code contains unhandled character(s) (character code=255). Neither unicode nor extended ascii is supported.\n " , toString (outputList));
2855+ }
2856+
2857+ static void readfile_utf16_be_unsupported ()
2858+ {
2859+ const char code[] = " \xff\xfe\x3d\xd8\x42\xde " ; // smiley emoji
2860+ simplecpp::OutputList outputList;
2861+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2862+ ASSERT_EQUALS (" file0,1,unhandled_char_error,The code contains unhandled character(s) (character code=255). Neither unicode nor extended ascii is supported.\n " , toString (outputList));
2863+ }
2864+
2865+ static void readfile_utf16_le_incomplete ()
2866+ {
2867+ const char code[] = " \xfe\xff\x00\x31\x00\x32\x00 " ; // the last UTF16 char is incomplete
2868+ simplecpp::OutputList outputList;
2869+ ASSERT_EQUALS (" 12" , readfile (code,sizeof (code), &outputList));
2870+ ASSERT_EQUALS (true , outputList.empty ());
2871+ }
2872+
2873+ static void readfile_utf16_be_incomplete ()
2874+ {
2875+ const char code[] = " \xff\xfe\x31\x00\x32\x00\x33 " ; // the last UTF16 char is incomplete
2876+ simplecpp::OutputList outputList;
2877+ ASSERT_EQUALS (" 12" , readfile (code,sizeof (code), &outputList));
2878+ ASSERT_EQUALS (true , outputList.empty ());
2879+ }
2880+
2881+ static void readfile_utf16_le_bom_incomplete ()
2882+ {
2883+ const char code[] = " \xfe " ;
2884+ simplecpp::OutputList outputList;
2885+ ASSERT_EQUALS (" 12" , readfile (code,sizeof (code), &outputList));
2886+ ASSERT_EQUALS (true , outputList.empty ());
2887+ }
2888+
2889+ static void readfile_utf16_be_bom_incomplete ()
2890+ {
2891+ const char code[] = " \xff " ;
2892+ simplecpp::OutputList outputList;
2893+ ASSERT_EQUALS (" 12" , readfile (code,sizeof (code), &outputList));
2894+ ASSERT_EQUALS (true , outputList.empty ());
2895+ }
2896+
28322897static void stringify1 ()
28332898{
28342899 const char code_c[] = " #include \" A.h\"\n "
@@ -3869,6 +3934,14 @@ static void runTests(int argc, char **argv, Input input)
38693934 TEST_CASE (readfile_unhandled_chars);
38703935 TEST_CASE (readfile_error);
38713936 TEST_CASE (readfile_file_not_found);
3937+ TEST_CASE (readfile_empty);
3938+ TEST_CASE (readfile_onebyte);
3939+ TEST_CASE (readfile_utf16_le_unsupported);
3940+ TEST_CASE (readfile_utf16_be_unsupported);
3941+ TEST_CASE (readfile_utf16_le_incomplete);
3942+ TEST_CASE (readfile_utf16_be_incomplete);
3943+ TEST_CASE (readfile_utf16_le_bom_incomplete);
3944+ TEST_CASE (readfile_utf16_be_bom_incomplete);
38723945
38733946 TEST_CASE (stringify1);
38743947
0 commit comments