X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FTests%2FCheckUnicodeSourceFiles.py;h=6ae62f180a840090141d4fdf23aafe0e3a7e99c8;hb=156d6d65a5ac1e31d36381b7726c42066891a845;hp=ad5fd189639d620f78c58da0900a02ddfdea10c4;hpb=dadfab5b23c3f02ab8396a5487122de797188845;p=mirror_edk2.git diff --git a/BaseTools/Tests/CheckUnicodeSourceFiles.py b/BaseTools/Tests/CheckUnicodeSourceFiles.py index ad5fd18963..6ae62f180a 100644 --- a/BaseTools/Tests/CheckUnicodeSourceFiles.py +++ b/BaseTools/Tests/CheckUnicodeSourceFiles.py @@ -114,6 +114,66 @@ class Tests(TestTools.BaseToolsTest): self.CheckFile(encoding=None, shouldPass=False, string=data) + def testValidUtf8File(self): + self.CheckFile(encoding='utf_8', shouldPass=True) + + def testValidUtf8FileWithBom(self): + # + # Same test as testValidUtf8File, but add the UTF-8 BOM + # + data = codecs.BOM_UTF8 + codecs.encode(self.SampleData, 'utf_8') + + self.CheckFile(encoding=None, shouldPass=True, string=data) + + def test32bitUnicodeCharInUtf8File(self): + data = u''' + #langdef en-US "English" + #string STR_A #language en-US "CodePoint (\U00010300) > 0xFFFF" + ''' + + self.CheckFile('utf_16', shouldPass=False, string=data) + + def test32bitUnicodeCharInUtf8File(self): + data = u''' + #langdef en-US "English" + #string STR_A #language en-US "CodePoint (\U00010300) > 0xFFFF" + ''' + + self.CheckFile('utf_8', shouldPass=False, string=data) + + def test32bitUnicodeCharInUtf8Comment(self): + data = u''' + // Even in comments, we reject non-UCS-2 chars: \U00010300 + #langdef en-US "English" + #string STR_A #language en-US "A" + ''' + + self.CheckFile('utf_8', shouldPass=False, string=data) + + def testSurrogatePairUnicodeCharInUtf8File(self): + # + # Surrogate Pair code points are used in UTF-16 files to + # encode the Supplementary Plane characters. In UTF-8, it is + # trivial to encode these code points, but they are not valid + # code points for characters, since they are reserved for the + # UTF-16 Surrogate Pairs. + # + # This test makes sure that BaseTools rejects these characters + # if seen in a .uni file. + # + data = '\xed\xa0\x81' + + self.CheckFile(encoding=None, shouldPass=False, string=data) + + def testSurrogatePairUnicodeCharInUtf8FileWithBom(self): + # + # Same test as testSurrogatePairUnicodeCharInUtf8File, but add + # the UTF-8 BOM + # + data = codecs.BOM_UTF8 + '\xed\xa0\x81' + + self.CheckFile(encoding=None, shouldPass=False, string=data) + TheTestSuite = TestTools.MakeTheTestSuite(locals()) if __name__ == '__main__':