## @file
# This file contain unit test for DecParser
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
import os
import unittest
Dec, \
_DecDefine, \
_DecPcd, \
_DecGuid, \
FileContent, \
_DecBase, \
#
# Test CleanString
#
#
# Test _DecBase._MacroParser function
#
# Raise fatal error, macro name must be upper case letter
# No macro name given
#
# Test _DecBase._TryBackSlash function
#
Content = [
# Right case
'test no backslash',
'test with backslash \\',
'continue second line',
# Do not precede with whitespace
'\\',
# Empty line after backlash is not allowed
'line with backslash \\',
''
]
#
# Right case, assert return values
#
#
# Error cases, assert raise exception
#
#
# Test _DecBase.Parse function
#
# List of DataItem
return Line == '[TOP]'
return Item
# List of Data
self.ItemObject = []
# Top parser
return False
return TestParser.ItemObject
pass
Content = \
'''# Top comment
[TOP]
# sub1 head comment
(test item has both head and tail comment) # sub1 tail comment
# sub2 head comment
(test item has head and special tail comment)
# @comment test TailCommentStrategy branch
(test item has no comment)
# test NextLine branch
[TOP]
sub-item
'''
# Two sections
# 3 subitems
# Comment content
# Comment line number
# Comment content
# Comment line number
# Comment content
# 1 subitems
#
# Test _DecDefine._ParseItem
#
return Obj
#
# Test _DecLibraryclass._ParseItem
#
return Obj
#
# Test _DecPcd._ParseItem
#
return Obj
item = self.GetObj('gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE|BOOLEAN|0x0000000d')._ParseItem()
obj = self.GetObj('gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE|BOOLEAN|0x0000000d | abc')
#
# Test _DecInclude._ParseItem
#
#
# Test code to be added
#
pass
#
# Test _DecGuid._ParseItem
#
return Obj
' {0x9c, 0x9a, 0xed, 0x90, 0xd0, 0x8a, 0x5e, 0x12 }}')._ParseItem()
self.assertEqual(item.GuidCValue, '{ 0xdfb386f7, 0xe100, 0x43ad, {0x9c, 0x9a, 0xed, 0x90, 0xd0, 0x8a, 0x5e, 0x12 }}')
#
# Test Dec.__init__
#
class TmpFile:
try:
except:
pass
try:
except:
pass
#
# Test Dec._UserExtentionSectionParser
#
'''[userextensions.intel."myid"]
[userextensions.intel."myid".IA32]
[userextensions.intel."myid".IA32,]
[userextensions.intel."myid]
'''
)
# OK: [userextensions.intel."myid"]
# OK: [userextensions.intel."myid".IA32]
# Fail: [userextensions.intel."myid".IA32,]
# Fail: [userextensions.intel."myid]
#
# Test Dec._SectionHeaderParser
#
'''[no section start or end
[,] # empty sub-section
[unknow_section_name]
[Includes.IA32.other] # no third one
[PcdsFeatureFlag, PcdsFixedAtBuild] # feature flag PCD must not be in the same section of other types of PCD
[Includes.IA32, Includes.IA32]
[Includes, Includes.IA32] # common cannot be with other arch
[Includes.IA32, PcdsFeatureFlag] # different section name
''' )
# [no section start or end
#[,] # empty sub-section
# [unknow_section_name]
# [Includes.IA32.other] # no third one
# [PcdsFeatureFlag, PcdsFixedAtBuild]
# [Includes.IA32, Includes.IA32]
# [Includes, Includes.IA32] # common cannot be with other arch
# [Includes.IA32, PcdsFeatureFlag] # different section name not allowed
#
# Test Dec._ParseDecComment
#
'''# abc
##''')
'''# abc
#
[section_start]''')
if __name__ == '__main__':