2 # This file contain unit test for Test [Binary] section part of InfParser
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # 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.
15 #import Object.Parser.InfObject as InfObject
16 from Object
.Parser
.InfCommonObject
import CurrentLine
17 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
18 from Object
.Parser
.InfBinaryObject
import InfBinariesObject
19 import Logger
.Log
as Logger
20 import Library
.GlobalData
as Global
22 # Test Common binary item
25 #-------------start of common binary item test input--------------------------#
28 # Only has 1 element, binary item Type
30 SectionStringsCommonItem1
= \
35 # Have 2 elements, binary item Type and FileName
37 SectionStringsCommonItem2
= \
43 # Have 3 elements, Type | FileName | Target | Family | TagName | FeatureFlagExp
45 SectionStringsCommonItem3
= \
47 GUID | Test/Test.guid | DEBUG
51 # Have 3 elements, Type | FileName | Target
52 # Target with MACRO defined in [Define] section
54 SectionStringsCommonItem4
= \
56 GUID | Test/Test.guid | $(TARGET)
60 # Have 3 elements, Type | FileName | Target
61 # FileName with MACRO defined in [Binary] section
63 SectionStringsCommonItem5
= \
65 DEFINE BINARY_FILE_PATH = Test
66 GUID | $(BINARY_FILE_PATH)/Test.guid | $(TARGET)
70 # Have 4 elements, Type | FileName | Target | Family
72 SectionStringsCommonItem6
= \
74 GUID | Test/Test.guid | DEBUG | *
78 # Have 4 elements, Type | FileName | Target | Family
80 SectionStringsCommonItem7
= \
82 GUID | Test/Test.guid | DEBUG | MSFT
86 # Have 5 elements, Type | FileName | Target | Family | TagName
88 SectionStringsCommonItem8
= \
90 GUID | Test/Test.guid | DEBUG | MSFT | TEST
94 # Have 6 elements, Type | FileName | Target | Family | TagName | FFE
96 SectionStringsCommonItem9
= \
98 GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE
102 # Have 7 elements, Type | FileName | Target | Family | TagName | FFE | Overflow
105 SectionStringsCommonItem10
= \
107 GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE | OVERFLOW
110 #-------------end of common binary item test input----------------------------#
114 #-------------start of VER type binary item test input------------------------#
117 # Has 1 element, error format
119 SectionStringsVerItem1
= \
124 # Have 5 elements, error format(Maximum elements amount is 4)
126 SectionStringsVerItem2
= \
128 VER | Test/Test.ver | * | TRUE | OverFlow
132 # Have 2 elements, Type | FileName
134 SectionStringsVerItem3
= \
140 # Have 3 elements, Type | FileName | Target
142 SectionStringsVerItem4
= \
144 VER | Test/Test.ver | DEBUG
148 # Have 4 elements, Type | FileName | Target | FeatureFlagExp
150 SectionStringsVerItem5
= \
152 VER | Test/Test.ver | DEBUG | TRUE
156 # Exist 2 VER items, both opened.
158 SectionStringsVerItem6
= \
160 VER | Test/Test.ver | * | TRUE
161 VER | Test/Test2.ver | * | TRUE
166 # Exist 2 VER items, only 1 opened.
168 SectionStringsVerItem7
= \
170 VER | Test/Test.ver | * | TRUE
171 VER | Test/Test2.ver | * | FALSE
174 #-------------end of VER type binary item test input--------------------------#
177 #-------------start of UI type binary item test input-------------------------#
180 # Test only one UI section can exist
182 SectionStringsUiItem1
= \
184 UI | Test/Test.ui | * | TRUE
185 UI | Test/Test2.ui | * | TRUE
188 SectionStringsUiItem2
= \
190 UI | Test/Test.ui | * | TRUE
191 SEC_UI | Test/Test2.ui | * | TRUE
194 SectionStringsUiItem3
= \
196 UI | Test/Test.ui | * | TRUE
197 UI | Test/Test2.ui | * | FALSE
201 # Has 1 element, error format
203 SectionStringsUiItem4
= \
208 # Have 5 elements, error format(Maximum elements amount is 4)
210 SectionStringsUiItem5
= \
212 UI | Test/Test.ui | * | TRUE | OverFlow
216 # Have 2 elements, Type | FileName
218 SectionStringsUiItem6
= \
224 # Have 3 elements, Type | FileName | Target
226 SectionStringsUiItem7
= \
228 UI | Test/Test.ui | DEBUG
232 # Have 4 elements, Type | FileName | Target | FeatureFlagExp
234 SectionStringsUiItem8
= \
236 UI | Test/Test.ui | DEBUG | TRUE
238 #---------------end of UI type binary item test input-------------------------#
241 gFileName
= "BinarySectionTest.inf"
244 # Construct SectionString for call section parser usage.
246 def StringToSectionString(String
):
247 Lines
= String
.split('\n')
251 if Line
.strip() == '':
253 SectionString
.append((Line
, LineNo
, ''))
258 def PrepareTest(String
):
259 SectionString
= StringToSectionString(String
)
261 for Item
in SectionString
:
262 ValueList
= Item
[0].split('|')
263 for count
in range(len(ValueList
)):
264 ValueList
[count
] = ValueList
[count
].strip()
265 if len(ValueList
) >= 2:
267 # Create a temp file for test.
269 FileName
= os
.path
.normpath(os
.path
.realpath(ValueList
[1].strip()))
271 TempFile
= open (FileName
, "w")
274 print "File Create Error"
275 CurrentLine
= CurrentLine()
276 CurrentLine
.SetFileName("Test")
277 CurrentLine
.SetLineString(Item
[0])
278 CurrentLine
.SetLineNo(Item
[1])
279 InfLineCommentObject
= InfLineCommentObject()
281 ItemList
.append((ValueList
, InfLineCommentObject
, CurrentLine
))
285 if __name__
== '__main__':
288 InfBinariesInstance
= InfBinariesObject()
289 ArchList
= ['COMMON']
290 Global
.gINF_MODULE_DIR
= os
.getcwd()
298 SectionStringsUiItem1
,
299 SectionStringsUiItem2
,
300 SectionStringsUiItem3
,
301 SectionStringsUiItem4
,
302 SectionStringsUiItem5
,
303 SectionStringsUiItem6
,
304 SectionStringsUiItem7
,
305 SectionStringsUiItem8
308 for Item
in UiStringList
:
309 Ui
= PrepareTest(Item
)
310 if Item
== SectionStringsUiItem4
or Item
== SectionStringsUiItem5
:
312 InfBinariesInstance
.SetBinary(Ui
= Ui
, ArchList
= ArchList
)
313 except Logger
.FatalError
:
317 InfBinariesInstance
.SetBinary(Ui
= Ui
, ArchList
= ArchList
)
319 AllPassedFlag
= False
325 SectionStringsVerItem1
,
326 SectionStringsVerItem2
,
327 SectionStringsVerItem3
,
328 SectionStringsVerItem4
,
329 SectionStringsVerItem5
,
330 SectionStringsVerItem6
,
331 SectionStringsVerItem7
333 for Item
in VerStringList
:
334 Ver
= PrepareTest(Item
)
335 if Item
== SectionStringsVerItem1
or \
336 Item
== SectionStringsVerItem2
:
339 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
345 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
347 AllPassedFlag
= False
350 # For All Common Test
353 SectionStringsCommonItem1
,
354 SectionStringsCommonItem2
,
355 SectionStringsCommonItem3
,
356 SectionStringsCommonItem4
,
357 SectionStringsCommonItem5
,
358 SectionStringsCommonItem6
,
359 SectionStringsCommonItem7
,
360 SectionStringsCommonItem8
,
361 SectionStringsCommonItem9
,
362 SectionStringsCommonItem10
365 for Item
in CommonStringList
:
366 CommonBin
= PrepareTest(Item
)
367 if Item
== SectionStringsCommonItem10
or \
368 Item
== SectionStringsCommonItem1
:
371 InfBinariesInstance
.SetBinary(CommonBinary
= CommonBin
, ArchList
= ArchList
)
377 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
380 AllPassedFlag
= False
383 print 'All tests passed...'
385 print 'Some unit test failed!'