1## @file 2# This file contain unit test for Test [Binary] section part of InfParser 3# 4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR> 5# 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 10# 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. 13 14import os 15#import Object.Parser.InfObject as InfObject 16from Object.Parser.InfCommonObject import CurrentLine 17from Object.Parser.InfCommonObject import InfLineCommentObject 18from Object.Parser.InfBinaryObject import InfBinariesObject 19import Logger.Log as Logger 20import Library.GlobalData as Global 21## 22# Test Common binary item 23# 24 25#-------------start of common binary item test input--------------------------# 26 27# 28# Only has 1 element, binary item Type 29# 30SectionStringsCommonItem1 = \ 31""" 32GUID 33""" 34# 35# Have 2 elements, binary item Type and FileName 36# 37SectionStringsCommonItem2 = \ 38""" 39GUID | Test/Test.guid 40""" 41 42# 43# Have 3 elements, Type | FileName | Target | Family | TagName | FeatureFlagExp 44# 45SectionStringsCommonItem3 = \ 46""" 47GUID | Test/Test.guid | DEBUG 48""" 49 50# 51# Have 3 elements, Type | FileName | Target 52# Target with MACRO defined in [Define] section 53# 54SectionStringsCommonItem4 = \ 55""" 56GUID | Test/Test.guid | $(TARGET) 57""" 58 59# 60# Have 3 elements, Type | FileName | Target 61# FileName with MACRO defined in [Binary] section 62# 63SectionStringsCommonItem5 = \ 64""" 65DEFINE BINARY_FILE_PATH = Test 66GUID | $(BINARY_FILE_PATH)/Test.guid | $(TARGET) 67""" 68 69# 70# Have 4 elements, Type | FileName | Target | Family 71# 72SectionStringsCommonItem6 = \ 73""" 74GUID | Test/Test.guid | DEBUG | * 75""" 76 77# 78# Have 4 elements, Type | FileName | Target | Family 79# 80SectionStringsCommonItem7 = \ 81""" 82GUID | Test/Test.guid | DEBUG | MSFT 83""" 84 85# 86# Have 5 elements, Type | FileName | Target | Family | TagName 87# 88SectionStringsCommonItem8 = \ 89""" 90GUID | Test/Test.guid | DEBUG | MSFT | TEST 91""" 92 93# 94# Have 6 elements, Type | FileName | Target | Family | TagName | FFE 95# 96SectionStringsCommonItem9 = \ 97""" 98GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE 99""" 100 101# 102# Have 7 elements, Type | FileName | Target | Family | TagName | FFE | Overflow 103# Test wrong format 104# 105SectionStringsCommonItem10 = \ 106""" 107GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE | OVERFLOW 108""" 109 110#-------------end of common binary item test input----------------------------# 111 112 113 114#-------------start of VER type binary item test input------------------------# 115 116# 117# Has 1 element, error format 118# 119SectionStringsVerItem1 = \ 120""" 121VER 122""" 123# 124# Have 5 elements, error format(Maximum elements amount is 4) 125# 126SectionStringsVerItem2 = \ 127""" 128VER | Test/Test.ver | * | TRUE | OverFlow 129""" 130 131# 132# Have 2 elements, Type | FileName 133# 134SectionStringsVerItem3 = \ 135""" 136VER | Test/Test.ver 137""" 138 139# 140# Have 3 elements, Type | FileName | Target 141# 142SectionStringsVerItem4 = \ 143""" 144VER | Test/Test.ver | DEBUG 145""" 146 147# 148# Have 4 elements, Type | FileName | Target | FeatureFlagExp 149# 150SectionStringsVerItem5 = \ 151""" 152VER | Test/Test.ver | DEBUG | TRUE 153""" 154 155# 156# Exist 2 VER items, both opened. 157# 158SectionStringsVerItem6 = \ 159""" 160VER | Test/Test.ver | * | TRUE 161VER | Test/Test2.ver | * | TRUE 162""" 163 164 165# 166# Exist 2 VER items, only 1 opened. 167# 168SectionStringsVerItem7 = \ 169""" 170VER | Test/Test.ver | * | TRUE 171VER | Test/Test2.ver | * | FALSE 172""" 173 174#-------------end of VER type binary item test input--------------------------# 175 176 177#-------------start of UI type binary item test input-------------------------# 178 179# 180# Test only one UI section can exist 181# 182SectionStringsUiItem1 = \ 183""" 184UI | Test/Test.ui | * | TRUE 185UI | Test/Test2.ui | * | TRUE 186""" 187 188SectionStringsUiItem2 = \ 189""" 190UI | Test/Test.ui | * | TRUE 191SEC_UI | Test/Test2.ui | * | TRUE 192""" 193 194SectionStringsUiItem3 = \ 195""" 196UI | Test/Test.ui | * | TRUE 197UI | Test/Test2.ui | * | FALSE 198""" 199 200# 201# Has 1 element, error format 202# 203SectionStringsUiItem4 = \ 204""" 205UI 206""" 207# 208# Have 5 elements, error format(Maximum elements amount is 4) 209# 210SectionStringsUiItem5 = \ 211""" 212UI | Test/Test.ui | * | TRUE | OverFlow 213""" 214 215# 216# Have 2 elements, Type | FileName 217# 218SectionStringsUiItem6 = \ 219""" 220UI | Test/Test.ui 221""" 222 223# 224# Have 3 elements, Type | FileName | Target 225# 226SectionStringsUiItem7 = \ 227""" 228UI | Test/Test.ui | DEBUG 229""" 230 231# 232# Have 4 elements, Type | FileName | Target | FeatureFlagExp 233# 234SectionStringsUiItem8 = \ 235""" 236UI | Test/Test.ui | DEBUG | TRUE 237""" 238#---------------end of UI type binary item test input-------------------------# 239 240 241gFileName = "BinarySectionTest.inf" 242 243## 244# Construct SectionString for call section parser usage. 245# 246def StringToSectionString(String): 247 Lines = String.split('\n') 248 LineNo = 0 249 SectionString = [] 250 for Line in Lines: 251 if Line.strip() == '': 252 continue 253 SectionString.append((Line, LineNo, '')) 254 LineNo = LineNo + 1 255 256 return SectionString 257 258def PrepareTest(String): 259 SectionString = StringToSectionString(String) 260 ItemList = [] 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: 266 # 267 # Create a temp file for test. 268 # 269 FileName = os.path.normpath(os.path.realpath(ValueList[1].strip())) 270 try: 271 TempFile = open (FileName, "w") 272 TempFile.close() 273 except: 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() 280 281 ItemList.append((ValueList, InfLineCommentObject, CurrentLine)) 282 283 return ItemList 284 285if __name__ == '__main__': 286 Logger.Initialize() 287 288 InfBinariesInstance = InfBinariesObject() 289 ArchList = ['COMMON'] 290 Global.gINF_MODULE_DIR = os.getcwd() 291 292 AllPassedFlag = True 293 294 # 295 # For All Ui test 296 # 297 UiStringList = [ 298 SectionStringsUiItem1, 299 SectionStringsUiItem2, 300 SectionStringsUiItem3, 301 SectionStringsUiItem4, 302 SectionStringsUiItem5, 303 SectionStringsUiItem6, 304 SectionStringsUiItem7, 305 SectionStringsUiItem8 306 ] 307 308 for Item in UiStringList: 309 Ui = PrepareTest(Item) 310 if Item == SectionStringsUiItem4 or Item == SectionStringsUiItem5: 311 try: 312 InfBinariesInstance.SetBinary(Ui = Ui, ArchList = ArchList) 313 except Logger.FatalError: 314 pass 315 else: 316 try: 317 InfBinariesInstance.SetBinary(Ui = Ui, ArchList = ArchList) 318 except: 319 AllPassedFlag = False 320 321 # 322 # For All Ver Test 323 # 324 VerStringList = [ 325 SectionStringsVerItem1, 326 SectionStringsVerItem2, 327 SectionStringsVerItem3, 328 SectionStringsVerItem4, 329 SectionStringsVerItem5, 330 SectionStringsVerItem6, 331 SectionStringsVerItem7 332 ] 333 for Item in VerStringList: 334 Ver = PrepareTest(Item) 335 if Item == SectionStringsVerItem1 or \ 336 Item == SectionStringsVerItem2: 337 338 try: 339 InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList) 340 except: 341 pass 342 343 else: 344 try: 345 InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList) 346 except: 347 AllPassedFlag = False 348 349 # 350 # For All Common Test 351 # 352 CommonStringList = [ 353 SectionStringsCommonItem1, 354 SectionStringsCommonItem2, 355 SectionStringsCommonItem3, 356 SectionStringsCommonItem4, 357 SectionStringsCommonItem5, 358 SectionStringsCommonItem6, 359 SectionStringsCommonItem7, 360 SectionStringsCommonItem8, 361 SectionStringsCommonItem9, 362 SectionStringsCommonItem10 363 ] 364 365 for Item in CommonStringList: 366 CommonBin = PrepareTest(Item) 367 if Item == SectionStringsCommonItem10 or \ 368 Item == SectionStringsCommonItem1: 369 370 try: 371 InfBinariesInstance.SetBinary(CommonBinary = CommonBin, ArchList = ArchList) 372 except: 373 pass 374 375 else: 376 try: 377 InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList) 378 except: 379 print "Test Failed!" 380 AllPassedFlag = False 381 382 if AllPassedFlag : 383 print 'All tests passed...' 384 else: 385 print 'Some unit test failed!' 386 387