]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Tests/CheckUnicodeSourceFiles.py
0083ad8589ba8caa098f7f72898dd8d541ff5cc3
2 # Unit tests for AutoGen.UniClassObject
4 # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 from Common
.Misc
import PathClass
26 import AutoGen
.UniClassObject
as BtUni
28 from Common
import EdkLogger
29 EdkLogger
.InitializeForUnitTest()
31 class Tests(TestTools
.BaseToolsTest
):
34 #langdef en-US "English"
35 #string STR_A #language en-US "STR_A for en-US"
38 def EncodeToFile(self
, encoding
, string
=None):
40 string
= self
.SampleData
41 data
= codecs
.encode(string
, encoding
)
43 self
.WriteTmpFile(path
, data
)
44 return PathClass(self
.GetTmpFilePath(path
))
46 def ErrorFailure(self
, error
, encoding
, shouldPass
):
47 msg
= error
+ ' should '
50 msg
+= 'be generated for '
51 msg
+= '%s data in a .uni file' % encoding
54 def UnicodeErrorFailure(self
, encoding
, shouldPass
):
55 self
.ErrorFailure('UnicodeError', encoding
, shouldPass
)
57 def EdkErrorFailure(self
, encoding
, shouldPass
):
58 self
.ErrorFailure('EdkLogger.FatalError', encoding
, shouldPass
)
60 def CheckFile(self
, encoding
, shouldPass
, string
=None):
61 path
= self
.EncodeToFile(encoding
, string
)
63 BtUni
.UniFileClassObject([path
])
70 self
.UnicodeErrorFailure(encoding
, shouldPass
)
71 except EdkLogger
.FatalError
:
75 self
.EdkErrorFailure(encoding
, shouldPass
)
79 self
.EdkErrorFailure(encoding
, shouldPass
)
81 def testUtf16InUniFile(self
):
82 self
.CheckFile('utf_16', shouldPass
=True)
84 TheTestSuite
= TestTools
.MakeTheTestSuite(locals())
86 if __name__
== '__main__':
87 allTests
= TheTestSuite()
88 unittest
.TextTestRunner().run(allTests
)