## @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 unittest
#
# Test ParseHeaderCommentSection
#
pass
pass
#
#
'''# License1
# License2
#
## @file
# example abstract
#
# example description
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# License3
#'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = 'example abstract'
ExpectedDescription = 'example description'
'Copyright (c) 2007 - 2010,'\
' Intel Corporation. All rights reserved.<BR>'
ExpectedLicense = 'License1\nLicense2\n\nLicense3'
#
#
''' # License1
# License2
#
## @file
# example abstract
#
# example description
#
#Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = 'example abstract'
ExpectedDescription = 'example description'
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>'
ExpectedLicense = 'License1\nLicense2'
#
# but no abstract/description
#
''' # License1
# License2
#
## @file
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# License3 Line1
# License3 Line2
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = ''
ExpectedDescription = ''
'Copyright (c) 2007 - 2010,'\
' Intel Corporation. All rights reserved.<BR>'
ExpectedLicense = \
'License1\n' \
'License2\n\n' \
'License3 Line1\n' \
'License3 Line2'
#
# Normal case4: format example in spec
#
TestCommentLines = \
'''
## @file
# Abstract
#
# Description
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = 'Abstract'
ExpectedDescription = 'Description'
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>'
ExpectedLicense = \
'License'
#
# Normal case5: other line between copyright
#
TestCommentLines = \
'''
## @file
# Abstract
#
# Description
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# other line
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = 'Abstract'
ExpectedDescription = 'Description'
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>\n'\
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>'
ExpectedLicense = \
'License'
#
# Normal case6: multiple lines of copyright
#
TestCommentLines = \
'''
## @file
# Abstract
#
# Description
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR>
#
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = 'Abstract'
ExpectedDescription = 'Description'
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>\n'\
'Copyright (c) 2007 - 2010, FOO1 Corporation.'\
' All rights reserved.<BR>\n'\
'Copyright (c) 2007 - 2010, FOO2 Corporation.'\
' All rights reserved.<BR>'
ExpectedLicense = \
'License'
#
# Normal case7: Abstract not present
#
TestCommentLines = \
'''
## @file
#
# Description
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR>
#
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = ''
ExpectedDescription = 'Description'
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>\n'\
'Copyright (c) 2007 - 2010, FOO1 Corporation.'\
' All rights reserved.<BR>\n'\
'Copyright (c) 2007 - 2010, FOO2 Corporation.'\
' All rights reserved.<BR>'
ExpectedLicense = \
'License'
#
# Normal case8: Description not present
#
TestCommentLines = \
'''
## @file
# Abstact
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
ExpectedAbstract = 'Abstact'
ExpectedDescription = ''
'Copyright (c) 2007 - 2010, Intel Corporation.'\
' All rights reserved.<BR>'
ExpectedLicense = \
'License'
#
# Error case1: No copyright found
#
TestCommentLines = \
'''
## @file
# Abstract
#
# Description
#
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
"PhonyFile")
#
# Error case2: non-empty non-comment lines passed in
#
TestCommentLines = \
'''
## @file
# Abstract
#
this is invalid line
# Description
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# License
#
##'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
"PhonyFile")
#
# Test ParseGenericComment
#
pass
pass
#
# Normal case1: one line of comment
#
TestCommentLines = \
'''# hello world'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
#
# Normal case2: multiple lines of comment
#
TestCommentLines = \
'''## hello world
# second line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
'hello world\n' + 'second line')
#
# Normal case3: multiple lines of comment, non comment lines will be skipped
#
TestCommentLines = \
'''## hello world
This is not comment line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
'hello world\n\n')
#
# Test ParseDecPcdGenericComment
#
pass
pass
#
# Normal case1: comments with no special comment
#
TestCommentLines = \
'''## hello world
# second line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
'hello world\n' + 'second line')
#
# Normal case2: comments with valid list
#
TestCommentLines = \
'''## hello world
# second line
# @ValidList 1, 2, 3
# other line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
'hello world\n' + 'second line\n' + 'other line')
#
# Normal case3: comments with valid range
#
TestCommentLines = \
'''## hello world
# second line
# @ValidRange LT 1 AND GT 2
# other line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
'hello world\n' + 'second line\n' + 'other line')
#
# Normal case4: comments with valid expression
#
TestCommentLines = \
'''## hello world
# second line
# @Expression LT 1 AND GT 2
# other line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
'hello world\n' + 'second line\n' + 'other line')
#
# Normal case5: comments with valid expression and no generic comment
#
TestCommentLines = \
'''# @Expression LT 1 AND GT 2'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
#
# Normal case6: comments with only generic help text
#
TestCommentLines = \
'''#'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
#
# Error case1: comments with both expression and valid list, use later
# ignore the former and with a warning message
#
TestCommentLines = \
'''## hello world
# second line
# @ValidList 1, 2, 3
# @Expression LT 1 AND GT 2
# other line'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
try:
except Logger.FatalError:
pass
#
# Test ParseDecPcdTailComment
#
pass
pass
#
# Normal case1: comments with no SupModeList
#
TestCommentLines = \
'''## #hello world'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
(SupModeList, HelpStr) = \
'hello world')
#
# Normal case2: comments with one SupMode
#
TestCommentLines = \
'''## BASE #hello world'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
(SupModeList, HelpStr) = \
'hello world')
['BASE'])
#
# Normal case3: comments with more than one SupMode
#
TestCommentLines = \
'''## BASE UEFI_APPLICATION #hello world'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
(SupModeList, HelpStr) = \
'hello world')
['BASE', 'UEFI_APPLICATION'])
#
# Normal case4: comments with more than one SupMode, no help text
#
TestCommentLines = \
'''## BASE UEFI_APPLICATION'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
(SupModeList, HelpStr) = \
['BASE', 'UEFI_APPLICATION'])
#
# Normal case5: general comments with no supModList, extract from real case
#
TestCommentLines = \
''' # 1 = 128MB, 2 = 256MB, 3 = MAX'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
(SupModeList, HelpStr) = \
'1 = 128MB, 2 = 256MB, 3 = MAX')
#
# Error case2: comments with supModList contains valid and invalid
# module type
#
TestCommentLines = \
'''## BASE INVALID_MODULE_TYPE #hello world'''
LineNum = 0
TestCommentLinesList = []
for Comment in CommentList:
LineNum += 1
try:
except Logger.FatalError:
pass
#
# Test _IsCopyrightLine
#
pass
pass
#
# Normal case
#
Line = 'this is a copyright ( line'
#
# Normal case
#
Line = 'this is a Copyright ( line'
#
# Normal case
#
Line = 'this is not aCopyright ( line'
#
# Normal case
#
Line = 'this is Copyright( line'
#
# Normal case
#
Line = 'this is Copyright (line'
#
# Normal case
#
Line = 'this is not Copyright line'
#
# Normal case
#
Line = 'Copyright (c) line'
#
# Normal case
#
Line = ' Copyright (c) line'
#
# Normal case
#
Line = 'not a Copyright '
if __name__ == '__main__':