CommentGeneratingUnitTest.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
## @file
# This file contain unit test for CommentParsing
#
# 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
from Library import GlobalData
#
# Test _GetHelpStr
#
pass
pass
#
# Normal case1: have one help text object with Lang = 'en-US'
#
def testNormalCase1(self):
HelpStr = 'Hello world'
#
# Normal case2: have two help text object with Lang = 'en-US' and other
#
def testNormalCase2(self):
HelpStr = 'Hello world'
ExpectedStr = 'Hello world1'
#
# Normal case3: have two help text object with Lang = '' and 'eng'
#
def testNormalCase3(self):
HelpStr = 'Hello world'
ExpectedStr = 'Hello world1'
#
# Normal case4: have two help text object with Lang = '' and ''
#
def testNormalCase4(self):
ExpectedStr = 'Hello world1'
HelpStr = 'Hello world'
#
# Normal case: have three help text object with Lang = '','en', 'en-US'
#
def testNormalCase5(self):
ExpectedStr = 'Hello world1'
HelpStr = 'Hello unknown world'
HelpStr = 'Hello mysterious world'
#
# Test GenGuidSections
#
pass
pass
#
# This is the API to generate Guid Object to help UnitTest
#
Guid = GuidObject()
return Guid
#
# Normal case: have two GuidObject
#
def testNormalCase1(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 1'
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'CONSUMES'
GuidType = 'Variable'
VariableName = ''
HelpStr = 'Usage comment line 2'
Expected = '''[Guids]
## PRODUCES ## Event # Usage comment line 1
## CONSUMES ## Variable: # Usage comment line 2
Guid1|FFE1'''
#
# Normal case: have two GuidObject
#
def testNormalCase2(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 1'
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = 'Generic comment line 1\n Generic comment line 2'
Expected = '''[Guids]
## PRODUCES ## Event # Usage comment line 1
# Generic comment line 1
# Generic comment line 2
Guid1|FFE1'''
#
# Normal case: have two GuidObject, one help goes to generic help,
# the other go into usage comment
#
def testNormalCase3(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = 'Generic comment'
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 1'
Expected = '''[Guids]
# Generic comment
## PRODUCES ## Event # Usage comment line 1
Guid1|FFE1'''
#
# Normal case: have one GuidObject, generic comment multiple lines
#
def testNormalCase5(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = 'Generic comment line1 \n generic comment line 2'
Expected = '''[Guids]
# Generic comment line1
# generic comment line 2
Guid1|FFE1'''
#
# Normal case: have one GuidObject, usage comment multiple lines
#
def testNormalCase6(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 1\n Usage comment line 2'
Expected = '''[Guids]
Guid1|FFE1 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
'''
#
# Normal case: have one GuidObject, usage comment one line
#
def testNormalCase7(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = 'Usage comment line 1'
Expected = '''[Guids]
Guid1|FFE1 # Usage comment line 1
'''
#
# Normal case: have two GuidObject
#
def testNormalCase8(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 1\n Usage comment line 2'
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 3'
Expected = '''[Guids]
## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
## PRODUCES ## Event # Usage comment line 3
Guid1|FFE1
'''
#
# Normal case: have no GuidObject
#
def testNormalCase9(self):
GuidList = []
Expected = ''
#
# Normal case: have one GuidObject with no comment generated
#
def testNormalCase10(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = ''
Expected = '''[Guids]
Guid1|FFE1
'''
#
# Normal case: have three GuidObject
#
def testNormalCase11(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = 'general comment line 1'
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = 'Usage comment line 3'
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
GuidType = 'UNDEFINED'
VariableName = ''
HelpStr = 'general comment line 2'
Expected = '''[Guids]
# general comment line 1
## PRODUCES ## Event # Usage comment line 3
# general comment line 2
Guid1|FFE1
'''
#
#
def testNormalCase12(self):
GuidList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'GUID'
VariableName = ''
HelpStr = ''
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
GuidType = 'Event'
VariableName = ''
HelpStr = ''
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'CONSUMES'
GuidType = 'Event'
VariableName = ''
HelpStr = ''
Expected = '''[Guids]
## PRODUCES ## GUID
## PRODUCES ## Event
## CONSUMES ## Event
Guid1|FFE1
'''
#
# Test GenProtocolPPiSections
#
pass
pass
#
#
if IsProtocol:
Object = ProtocolObject()
else:
return Object
# Usage Notify Help INF Comment
#1 UNDEFINED true Present ## UNDEFINED ## NOTIFY # Help
#2 UNDEFINED true Not Present ## UNDEFINED ## NOTIFY
#3 UNDEFINED false Present ## UNDEFINED # Help
#4 UNDEFINED false Not Present ## UNDEFINED
#5 UNDEFINED Not Present Present # Help
#6 UNDEFINED Not Present Not Present <empty>
#7 Other true Present ## Other ## NOTIFY # Help
#8 Other true Not Present ## Other ## NOTIFY
#9 Other false Present ## Other # Help
#A Other false Not Present ## Other
#B Other Not Present Present ## Other # Help
#C Other Not Present Not Present ## Other
def testNormalCase1(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
HelpStr = 'Help'
Expected = '''[Protocols]
Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
ObjectList = []
Expected = '''[Ppis]
Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
def testNormalCase2(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
HelpStr = ''
Expected = '''[Protocols]
Guid1|FFE1 ## UNDEFINED ## NOTIFY'''
def testNormalCase3(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
HelpStr = 'Help'
Expected = '''[Protocols]
Guid1|FFE1 ## UNDEFINED # Help'''
def testNormalCase4(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
HelpStr = ''
Expected = '''[Protocols]
Guid1|FFE1 ## UNDEFINED'''
def testNormalCase5(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
Notify = ''
HelpStr = 'Help'
Expected = '''[Protocols]
Guid1|FFE1 # Help'''
def testNormalCase6(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'UNDEFINED'
Notify = ''
HelpStr = ''
Expected = '''[Protocols]
Guid1|FFE1'''
def testNormalCase7(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
HelpStr = 'Help'
Expected = '''[Protocols]
Guid1|FFE1 ## PRODUCES ## NOTIFY # Help'''
def testNormalCase8(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
HelpStr = ''
Expected = '''[Protocols]
Guid1|FFE1 ## PRODUCES ## NOTIFY'''
def testNormalCase9(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
HelpStr = 'Help'
Expected = '''[Protocols]
Guid1|FFE1 ## PRODUCES # Help'''
def testNormalCaseA(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
HelpStr = ''
Expected = '''[Protocols]
Guid1|FFE1 ## PRODUCES'''
def testNormalCaseB(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
Notify = ''
HelpStr = 'Help'
Expected = '''[Protocols]
Guid1|FFE1 ## PRODUCES # Help'''
def testNormalCaseC(self):
ObjectList = []
CName = 'Guid1'
FFE = 'FFE1'
Usage = 'PRODUCES'
Notify = ''
HelpStr = ''
Expected = '''[Protocols]
Guid1|FFE1 ## PRODUCES'''
#
# Test GenPcdSections
#
pass
pass
#
# This is the API to generate Pcd Object to help UnitTest
#
return Object
# Usage Help INF Comment
#1 UNDEFINED Present # Help
#2 UNDEFINED Not Present <empty>
#3 Other Present ## Other # Help
#4 Other Not Present ## Other
def testNormalCase1(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'UNDEFINED'
Str = 'Help'
Expected = \
'[Pcd]\n' + \
'TSCName.CName|DValue|FFE # Help'
def testNormalCase2(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'UNDEFINED'
Str = ''
Expected = '[Pcd]\nTSCName.CName|DValue|FFE'
def testNormalCase3(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'CONSUMES'
Str = 'Help'
Expected = '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES # Help'
def testNormalCase4(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'CONSUMES'
Str = ''
Expected = '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES'
#
# multiple lines for normal usage
#
def testNormalCase5(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'CONSUMES'
Str = 'commment line 1\ncomment line 2'
Expected = '''[Pcd]
TSCName.CName|DValue|FFE ## CONSUMES # commment line 1 comment line 2'''
#
# multiple lines for UNDEFINED usage
#
def testNormalCase6(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'UNDEFINED'
Str = 'commment line 1\ncomment line 2'
Usage = 'UNDEFINED'
Str = 'commment line 3'
Expected = '''[Pcd]
# commment line 1
# comment line 2
# commment line 3
TSCName.CName|DValue|FFE'''
#
# multiple lines for UNDEFINED and normal usage
#
def testNormalCase7(self):
ObjectList = []
ItemType = 'Pcd'
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'UNDEFINED'
Str = 'commment line 1\ncomment line 2'
Usage = 'CONSUMES'
Str = 'Foo'
Usage = 'UNDEFINED'
Str = 'commment line 3'
Expected = '''[Pcd]
# commment line 1
# comment line 2
## CONSUMES # Foo
# commment line 3
TSCName.CName|DValue|FFE'''
# Usage Help INF Comment
# CONSUMES Present # Help (keep <EOL> and insert '#' at beginning of each new line)
# CONSUMES Not Present <empty>
#
# TAB_INF_FEATURE_PCD
#
def testNormalCase8(self):
ObjectList = []
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'CONSUMES'
Str = 'commment line 1\ncomment line 2'
Expected = '''[FeaturePcd]
# commment line 1
# comment line 2
TSCName.CName|DValue|FFE'''
#
# TAB_INF_FEATURE_PCD
#
def testNormalCase9(self):
ObjectList = []
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'CONSUMES'
Str = ''
Expected = '''[FeaturePcd]
TSCName.CName|DValue|FFE'''
#
# TAB_INF_FEATURE_PCD
#
def testNormalCase10(self):
ObjectList = []
TSCName = 'TSCName'
CName = 'CName'
DValue = 'DValue'
FFE = 'FFE'
Usage = 'PRODUCES'
Str = 'commment line 1\ncomment line 2'
Expected = '''
[FeaturePcd]
# commment line 1
# comment line 2
TSCName.CName|DValue|FFE
'''
#
# Test GenSpecialSections of Hob
#
pass
pass
#
# This is the API to generate Event Object to help UnitTest
#
return Object
def testNormalCase1(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = 'Help'
Expected = '''# [Hob.X64]
# ##
# # Help
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase2(self):
ObjectList = []
SupArchList = []
Type = 'Foo'
Usage = 'UNDEFINED'
Str = 'Help'
Expected = '''# [Hob]
# ##
# # Help
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase3(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\nComment Line 1\n\n'
Expected = '''# [Hob.X64]
# ##
# # Comment Line 1
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase4(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\nComment Line 1\n'
Expected = '''# [Hob.X64]
# ##
# # Comment Line 1
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase5(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = 'Comment Line 1\n\n'
Expected = '''# [Hob.X64]
# ##
# # Comment Line 1
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase6(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = ''
Expected = '''# [Hob.X64]
# Foo ## UNDEFINED
#
#
'''
def testNormalCase7(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\nNew Stack HoB'
Expected = '''# [Hob.X64]
# ##
# # New Stack HoB
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase8(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\nNew Stack HoB\n\nTail Comment'
Expected = '''# [Hob.X64]
# ##
# # New Stack HoB
# #
# # Tail Comment
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase9(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\n\n'
Expected = '''# [Hob.X64]
# ##
# #
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase10(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\n'
Expected = '''# [Hob.X64]
# ##
# #
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase11(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\n\n\n'
Expected = '''# [Hob.X64]
# ##
# #
# #
# Foo ## UNDEFINED
#
#
'''
def testNormalCase12(self):
ObjectList = []
SupArchList = ['X64']
Type = 'Foo'
Usage = 'UNDEFINED'
Str = '\n\n\n\n'
Expected = '''# [Hob.X64]
# ##
# #
# #
# #
# Foo ## UNDEFINED
#
#
'''
#
# Test GenGenericCommentF
#
pass
pass
def testNormalCase1(self):
CommentLines = 'Comment Line 1'
Expected = '# Comment Line 1\n'
def testNormalCase2(self):
CommentLines = '\n'
Expected = '#\n'
def testNormalCase3(self):
CommentLines = '\n\n\n'
Expected = '#\n#\n#\n'
def testNormalCase4(self):
CommentLines = 'coment line 1\n'
Expected = '# coment line 1\n'
def testNormalCase5(self):
CommentLines = 'coment line 1\n coment line 2\n'
Expected = '# coment line 1\n# coment line 2\n'
if __name__ == '__main__':