]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/UnitTest/CommentGeneratingUnitTest.py
2 # This file contain unit test for CommentParsing
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 import Logger
.Log
as Logger
12 from GenMetaFile
.GenInfFile
import GenGuidSections
13 from GenMetaFile
.GenInfFile
import GenProtocolPPiSections
14 from GenMetaFile
.GenInfFile
import GenPcdSections
15 from GenMetaFile
.GenInfFile
import GenSpecialSections
16 from Library
.CommentGenerating
import GenGenericCommentF
17 from Library
.CommentGenerating
import _GetHelpStr
18 from Object
.POM
.CommonObject
import TextObject
19 from Object
.POM
.CommonObject
import GuidObject
20 from Object
.POM
.CommonObject
import ProtocolObject
21 from Object
.POM
.CommonObject
import PpiObject
22 from Object
.POM
.CommonObject
import PcdObject
23 from Object
.POM
.ModuleObject
import HobObject
25 from Library
.StringUtils
import GetSplitValueList
26 from Library
.DataType
import TAB_SPACE_SPLIT
27 from Library
.DataType
import TAB_LANGUAGE_EN_US
28 from Library
.DataType
import TAB_LANGUAGE_ENG
29 from Library
.DataType
import ITEM_UNDEFINED
30 from Library
.DataType
import TAB_INF_FEATURE_PCD
31 from Library
import GlobalData
32 from Library
.Misc
import CreateDirectory
37 class _GetHelpStrTest(unittest
.TestCase
):
45 # Normal case1: have one help text object with Lang = 'en-US'
47 def testNormalCase1(self
):
48 HelpStr
= 'Hello world'
49 HelpTextObj
= TextObject()
50 HelpTextObj
.SetLang(TAB_LANGUAGE_EN_US
)
51 HelpTextObj
.SetString(HelpStr
)
53 HelpTextList
= [HelpTextObj
]
54 Result
= _GetHelpStr(HelpTextList
)
55 self
.assertEqual(Result
, HelpStr
)
58 # Normal case2: have two help text object with Lang = 'en-US' and other
60 def testNormalCase2(self
):
61 HelpStr
= 'Hello world'
62 HelpTextObj
= TextObject()
63 HelpTextObj
.SetLang(TAB_LANGUAGE_ENG
)
64 HelpTextObj
.SetString(HelpStr
)
66 HelpTextList
= [HelpTextObj
]
68 ExpectedStr
= 'Hello world1'
69 HelpTextObj
= TextObject()
70 HelpTextObj
.SetLang(TAB_LANGUAGE_EN_US
)
71 HelpTextObj
.SetString(ExpectedStr
)
73 HelpTextList
.append(HelpTextObj
)
75 Result
= _GetHelpStr(HelpTextList
)
76 self
.assertEqual(Result
, ExpectedStr
)
79 # Normal case3: have two help text object with Lang = '' and 'eng'
81 def testNormalCase3(self
):
82 HelpStr
= 'Hello world'
83 HelpTextObj
= TextObject()
84 HelpTextObj
.SetLang('')
85 HelpTextObj
.SetString(HelpStr
)
87 HelpTextList
= [HelpTextObj
]
89 ExpectedStr
= 'Hello world1'
90 HelpTextObj
= TextObject()
91 HelpTextObj
.SetLang(TAB_LANGUAGE_ENG
)
92 HelpTextObj
.SetString(ExpectedStr
)
94 HelpTextList
.append(HelpTextObj
)
96 Result
= _GetHelpStr(HelpTextList
)
97 self
.assertEqual(Result
, ExpectedStr
)
100 # Normal case4: have two help text object with Lang = '' and ''
102 def testNormalCase4(self
):
104 ExpectedStr
= 'Hello world1'
105 HelpTextObj
= TextObject()
106 HelpTextObj
.SetLang(TAB_LANGUAGE_ENG
)
107 HelpTextObj
.SetString(ExpectedStr
)
108 HelpTextList
= [HelpTextObj
]
110 HelpStr
= 'Hello world'
111 HelpTextObj
= TextObject()
112 HelpTextObj
.SetLang('')
113 HelpTextObj
.SetString(HelpStr
)
114 HelpTextList
.append(HelpTextObj
)
116 Result
= _GetHelpStr(HelpTextList
)
117 self
.assertEqual(Result
, ExpectedStr
)
120 # Normal case: have three help text object with Lang = '','en', 'en-US'
122 def testNormalCase5(self
):
124 ExpectedStr
= 'Hello world1'
125 HelpTextObj
= TextObject()
126 HelpTextObj
.SetLang(TAB_LANGUAGE_EN_US
)
127 HelpTextObj
.SetString(ExpectedStr
)
128 HelpTextList
= [HelpTextObj
]
130 HelpStr
= 'Hello unknown world'
131 HelpTextObj
= TextObject()
132 HelpTextObj
.SetLang('')
133 HelpTextObj
.SetString(HelpStr
)
134 HelpTextList
.append(HelpTextObj
)
136 HelpStr
= 'Hello mysterious world'
137 HelpTextObj
= TextObject()
138 HelpTextObj
.SetLang('')
139 HelpTextObj
.SetString(HelpStr
)
140 HelpTextList
.append(HelpTextObj
)
142 Result
= _GetHelpStr(HelpTextList
)
143 self
.assertEqual(Result
, ExpectedStr
)
146 self
.assertEqual(Result
, ExpectedStr
)
148 HelpTextList
.sort(reverse
=True)
149 self
.assertEqual(Result
, ExpectedStr
)
153 # Test GenGuidSections
155 class GenGuidSectionsTest(unittest
.TestCase
):
163 # This is the API to generate Guid Object to help UnitTest
165 def GuidFactory(self
, CName
, FFE
, Usage
, GuidType
, VariableName
, HelpStr
):
168 Guid
.SetFeatureFlag(FFE
)
169 Guid
.SetGuidTypeList([GuidType
])
171 Guid
.SetVariableName(VariableName
)
173 HelpTextObj
= TextObject()
174 HelpTextObj
.SetLang('')
175 HelpTextObj
.SetString(HelpStr
)
176 Guid
.SetHelpTextList([HelpTextObj
])
181 # Normal case: have two GuidObject
183 def testNormalCase1(self
):
191 HelpStr
= 'Usage comment line 1'
192 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
193 VariableName
, HelpStr
)
194 GuidList
.append(Guid1
)
199 GuidType
= 'Variable'
201 HelpStr
= 'Usage comment line 2'
202 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
203 VariableName
, HelpStr
)
204 GuidList
.append(Guid1
)
206 Result
= GenGuidSections(GuidList
)
207 Expected
= '''[Guids]
208 ## PRODUCES ## Event # Usage comment line 1
209 ## CONSUMES ## Variable: # Usage comment line 2
211 self
.assertEqual(Result
.strip(), Expected
)
214 # Normal case: have two GuidObject
216 def testNormalCase2(self
):
224 HelpStr
= 'Usage comment line 1'
225 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
226 VariableName
, HelpStr
)
227 GuidList
.append(Guid1
)
232 GuidType
= 'UNDEFINED'
234 HelpStr
= 'Generic comment line 1\n Generic comment line 2'
235 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
236 VariableName
, HelpStr
)
237 GuidList
.append(Guid1
)
239 Result
= GenGuidSections(GuidList
)
240 Expected
= '''[Guids]
241 ## PRODUCES ## Event # Usage comment line 1
242 # Generic comment line 1
243 # Generic comment line 2
246 self
.assertEqual(Result
.strip(), Expected
)
249 # Normal case: have two GuidObject, one help goes to generic help,
250 # the other go into usage comment
252 def testNormalCase3(self
):
258 GuidType
= 'UNDEFINED'
260 HelpStr
= 'Generic comment'
261 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
262 VariableName
, HelpStr
)
263 GuidList
.append(Guid1
)
270 HelpStr
= 'Usage comment line 1'
271 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
272 VariableName
, HelpStr
)
273 GuidList
.append(Guid1
)
275 Result
= GenGuidSections(GuidList
)
276 Expected
= '''[Guids]
278 ## PRODUCES ## Event # Usage comment line 1
281 self
.assertEqual(Result
.strip(), Expected
)
284 # Normal case: have one GuidObject, generic comment multiple lines
286 def testNormalCase5(self
):
292 GuidType
= 'UNDEFINED'
294 HelpStr
= 'Generic comment line1 \n generic comment line 2'
295 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
296 VariableName
, HelpStr
)
297 GuidList
.append(Guid1
)
299 Result
= GenGuidSections(GuidList
)
300 Expected
= '''[Guids]
301 # Generic comment line1
302 # generic comment line 2
305 self
.assertEqual(Result
.strip(), Expected
)
308 # Normal case: have one GuidObject, usage comment multiple lines
310 def testNormalCase6(self
):
318 HelpStr
= 'Usage comment line 1\n Usage comment line 2'
319 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
320 VariableName
, HelpStr
)
321 GuidList
.append(Guid1
)
323 Result
= GenGuidSections(GuidList
)
324 Expected
= '''[Guids]
325 Guid1|FFE1 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
327 self
.assertEqual(Result
.strip(), Expected
.strip())
330 # Normal case: have one GuidObject, usage comment one line
332 def testNormalCase7(self
):
338 GuidType
= 'UNDEFINED'
340 HelpStr
= 'Usage comment line 1'
341 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
342 VariableName
, HelpStr
)
343 GuidList
.append(Guid1
)
345 Result
= GenGuidSections(GuidList
)
346 Expected
= '''[Guids]
347 Guid1|FFE1 # Usage comment line 1
349 self
.assertEqual(Result
.strip(), Expected
.strip())
352 # Normal case: have two GuidObject
354 def testNormalCase8(self
):
362 HelpStr
= 'Usage comment line 1\n Usage comment line 2'
363 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
364 VariableName
, HelpStr
)
365 GuidList
.append(Guid1
)
372 HelpStr
= 'Usage comment line 3'
373 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
374 VariableName
, HelpStr
)
375 GuidList
.append(Guid1
)
377 Result
= GenGuidSections(GuidList
)
378 Expected
= '''[Guids]
379 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
380 ## PRODUCES ## Event # Usage comment line 3
383 self
.assertEqual(Result
.strip(), Expected
.strip())
386 # Normal case: have no GuidObject
388 def testNormalCase9(self
):
391 Result
= GenGuidSections(GuidList
)
393 self
.assertEqual(Result
.strip(), Expected
.strip())
396 # Normal case: have one GuidObject with no comment generated
398 def testNormalCase10(self
):
404 GuidType
= 'UNDEFINED'
407 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
408 VariableName
, HelpStr
)
409 GuidList
.append(Guid1
)
411 Result
= GenGuidSections(GuidList
)
412 Expected
= '''[Guids]
415 self
.assertEqual(Result
.strip(), Expected
.strip())
418 # Normal case: have three GuidObject
420 def testNormalCase11(self
):
426 GuidType
= 'UNDEFINED'
428 HelpStr
= 'general comment line 1'
429 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
430 VariableName
, HelpStr
)
431 GuidList
.append(Guid1
)
438 HelpStr
= 'Usage comment line 3'
439 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
440 VariableName
, HelpStr
)
441 GuidList
.append(Guid1
)
446 GuidType
= 'UNDEFINED'
448 HelpStr
= 'general comment line 2'
449 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
450 VariableName
, HelpStr
)
451 GuidList
.append(Guid1
)
453 Result
= GenGuidSections(GuidList
)
454 Expected
= '''[Guids]
455 # general comment line 1
456 ## PRODUCES ## Event # Usage comment line 3
457 # general comment line 2
460 self
.assertEqual(Result
.strip(), Expected
.strip())
463 # Normal case: have three GuidObject, with Usage/Type and no help
465 def testNormalCase12(self
):
474 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
475 VariableName
, HelpStr
)
476 GuidList
.append(Guid1
)
484 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
485 VariableName
, HelpStr
)
486 GuidList
.append(Guid1
)
494 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
495 VariableName
, HelpStr
)
496 GuidList
.append(Guid1
)
498 Result
= GenGuidSections(GuidList
)
499 Expected
= '''[Guids]
505 self
.assertEqual(Result
.strip(), Expected
.strip())
508 # Test GenProtocolPPiSections
510 class GenProtocolPPiSectionsTest(unittest
.TestCase
):
518 # This is the API to generate Protocol/Ppi Object to help UnitTest
520 def ObjectFactory(self
, CName
, FFE
, Usage
, Notify
, HelpStr
, IsProtocol
):
522 Object
= ProtocolObject()
526 Object
.SetCName(CName
)
527 Object
.SetFeatureFlag(FFE
)
528 Object
.SetUsage(Usage
)
529 Object
.SetNotify(Notify
)
531 HelpTextObj
= TextObject()
532 HelpTextObj
.SetLang('')
533 HelpTextObj
.SetString(HelpStr
)
534 Object
.SetHelpTextList([HelpTextObj
])
538 # Usage Notify Help INF Comment
539 #1 UNDEFINED true Present ## UNDEFINED ## NOTIFY # Help
540 #2 UNDEFINED true Not Present ## UNDEFINED ## NOTIFY
541 #3 UNDEFINED false Present ## UNDEFINED # Help
542 #4 UNDEFINED false Not Present ## UNDEFINED
543 #5 UNDEFINED Not Present Present # Help
544 #6 UNDEFINED Not Present Not Present <empty>
545 #7 Other true Present ## Other ## NOTIFY # Help
546 #8 Other true Not Present ## Other ## NOTIFY
547 #9 Other false Present ## Other # Help
548 #A Other false Not Present ## Other
549 #B Other Not Present Present ## Other # Help
550 #C Other Not Present Not Present ## Other
552 def testNormalCase1(self
):
562 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
564 ObjectList
.append(Object
)
567 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
568 Expected
= '''[Protocols]
569 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
570 self
.assertEqual(Result
.strip(), Expected
)
574 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
576 ObjectList
.append(Object
)
579 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
581 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
582 self
.assertEqual(Result
.strip(), Expected
)
584 def testNormalCase2(self
):
594 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
596 ObjectList
.append(Object
)
599 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
600 Expected
= '''[Protocols]
601 Guid1|FFE1 ## UNDEFINED ## NOTIFY'''
602 self
.assertEqual(Result
.strip(), Expected
)
604 def testNormalCase3(self
):
614 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
616 ObjectList
.append(Object
)
619 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
620 Expected
= '''[Protocols]
621 Guid1|FFE1 ## UNDEFINED # Help'''
622 self
.assertEqual(Result
.strip(), Expected
)
624 def testNormalCase4(self
):
634 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
636 ObjectList
.append(Object
)
639 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
640 Expected
= '''[Protocols]
641 Guid1|FFE1 ## UNDEFINED'''
642 self
.assertEqual(Result
.strip(), Expected
)
644 def testNormalCase5(self
):
654 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
656 ObjectList
.append(Object
)
659 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
660 Expected
= '''[Protocols]
662 self
.assertEqual(Result
.strip(), Expected
)
664 def testNormalCase6(self
):
674 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
676 ObjectList
.append(Object
)
679 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
680 Expected
= '''[Protocols]
682 self
.assertEqual(Result
.strip(), Expected
)
684 def testNormalCase7(self
):
694 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
696 ObjectList
.append(Object
)
699 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
700 Expected
= '''[Protocols]
701 Guid1|FFE1 ## PRODUCES ## NOTIFY # Help'''
702 self
.assertEqual(Result
.strip(), Expected
)
704 def testNormalCase8(self
):
714 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
716 ObjectList
.append(Object
)
719 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
720 Expected
= '''[Protocols]
721 Guid1|FFE1 ## PRODUCES ## NOTIFY'''
722 self
.assertEqual(Result
.strip(), Expected
)
724 def testNormalCase9(self
):
734 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
736 ObjectList
.append(Object
)
739 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
740 Expected
= '''[Protocols]
741 Guid1|FFE1 ## PRODUCES # Help'''
742 self
.assertEqual(Result
.strip(), Expected
)
744 def testNormalCaseA(self
):
754 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
756 ObjectList
.append(Object
)
759 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
760 Expected
= '''[Protocols]
761 Guid1|FFE1 ## PRODUCES'''
762 self
.assertEqual(Result
.strip(), Expected
)
764 def testNormalCaseB(self
):
774 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
776 ObjectList
.append(Object
)
779 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
780 Expected
= '''[Protocols]
781 Guid1|FFE1 ## PRODUCES # Help'''
782 self
.assertEqual(Result
.strip(), Expected
)
784 def testNormalCaseC(self
):
794 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
796 ObjectList
.append(Object
)
799 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
800 Expected
= '''[Protocols]
801 Guid1|FFE1 ## PRODUCES'''
802 self
.assertEqual(Result
.strip(), Expected
)
805 # Test GenPcdSections
807 class GenPcdSectionsTest(unittest
.TestCase
):
815 # This is the API to generate Pcd Object to help UnitTest
817 def ObjectFactory(self
, ItemType
, TSCName
, CName
, DValue
, FFE
, Usage
, Str
):
821 Object
.SetItemType(ItemType
)
822 Object
.SetTokenSpaceGuidCName(TSCName
)
823 Object
.SetCName(CName
)
824 Object
.SetDefaultValue(DValue
)
825 Object
.SetFeatureFlag(FFE
)
826 Object
.SetValidUsage(Usage
)
828 HelpTextObj
= TextObject()
829 HelpTextObj
.SetLang('')
830 HelpTextObj
.SetString(HelpStr
)
831 Object
.SetHelpTextList([HelpTextObj
])
836 # Usage Help INF Comment
837 #1 UNDEFINED Present # Help
838 #2 UNDEFINED Not Present <empty>
839 #3 Other Present ## Other # Help
840 #4 Other Not Present ## Other
842 def testNormalCase1(self
):
853 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
855 ObjectList
.append(Object
)
857 Result
= GenPcdSections(ObjectList
)
860 'TSCName.CName|DValue|FFE # Help'
861 self
.assertEqual(Result
.strip(), Expected
)
863 def testNormalCase2(self
):
874 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
876 ObjectList
.append(Object
)
878 Result
= GenPcdSections(ObjectList
)
879 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE'
880 self
.assertEqual(Result
.strip(), Expected
)
882 def testNormalCase3(self
):
893 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
895 ObjectList
.append(Object
)
897 Result
= GenPcdSections(ObjectList
)
898 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES # Help'
899 self
.assertEqual(Result
.strip(), Expected
)
901 def testNormalCase4(self
):
912 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
914 ObjectList
.append(Object
)
916 Result
= GenPcdSections(ObjectList
)
917 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES'
918 self
.assertEqual(Result
.strip(), Expected
)
921 # multiple lines for normal usage
923 def testNormalCase5(self
):
932 Str
= 'commment line 1\ncomment line 2'
933 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
935 ObjectList
.append(Object
)
937 Result
= GenPcdSections(ObjectList
)
939 TSCName.CName|DValue|FFE ## CONSUMES # commment line 1 comment line 2'''
940 self
.assertEqual(Result
.strip(), Expected
)
943 # multiple lines for UNDEFINED usage
945 def testNormalCase6(self
):
954 Str
= 'commment line 1\ncomment line 2'
955 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
957 ObjectList
.append(Object
)
960 Str
= 'commment line 3'
961 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
963 ObjectList
.append(Object
)
965 Result
= GenPcdSections(ObjectList
)
970 TSCName.CName|DValue|FFE'''
971 self
.assertEqual(Result
.strip(), Expected
)
974 # multiple lines for UNDEFINED and normal usage
976 def testNormalCase7(self
):
985 Str
= 'commment line 1\ncomment line 2'
986 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
988 ObjectList
.append(Object
)
992 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
994 ObjectList
.append(Object
)
997 Str
= 'commment line 3'
998 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1000 ObjectList
.append(Object
)
1002 Result
= GenPcdSections(ObjectList
)
1008 TSCName.CName|DValue|FFE'''
1009 self
.assertEqual(Result
.strip(), Expected
)
1011 # Usage Help INF Comment
1012 # CONSUMES Present # Help (keep <EOL> and insert '#' at beginning of each new line)
1013 # CONSUMES Not Present <empty>
1016 # TAB_INF_FEATURE_PCD
1018 def testNormalCase8(self
):
1020 ItemType
= TAB_INF_FEATURE_PCD
1027 Str
= 'commment line 1\ncomment line 2'
1028 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1030 ObjectList
.append(Object
)
1032 Result
= GenPcdSections(ObjectList
)
1033 Expected
= '''[FeaturePcd]
1036 TSCName.CName|DValue|FFE'''
1037 self
.assertEqual(Result
.strip(), Expected
)
1040 # TAB_INF_FEATURE_PCD
1042 def testNormalCase9(self
):
1044 ItemType
= TAB_INF_FEATURE_PCD
1052 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1054 ObjectList
.append(Object
)
1056 Result
= GenPcdSections(ObjectList
)
1057 Expected
= '''[FeaturePcd]
1058 TSCName.CName|DValue|FFE'''
1059 self
.assertEqual(Result
.strip(), Expected
)
1062 # TAB_INF_FEATURE_PCD
1064 def testNormalCase10(self
):
1066 ItemType
= TAB_INF_FEATURE_PCD
1073 Str
= 'commment line 1\ncomment line 2'
1074 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1076 ObjectList
.append(Object
)
1078 Result
= GenPcdSections(ObjectList
)
1084 TSCName.CName|DValue|FFE
1086 self
.assertEqual(Result
, Expected
)
1090 # Test GenSpecialSections of Hob
1092 class GenHobSectionsTest(unittest
.TestCase
):
1100 # This is the API to generate Event Object to help UnitTest
1102 def ObjectFactory(self
, SupArchList
, Type
, Usage
, Str
):
1103 Object
= HobObject()
1106 Object
.SetHobType(Type
)
1107 Object
.SetUsage(Usage
)
1108 Object
.SetSupArchList(SupArchList
)
1110 HelpTextObj
= TextObject()
1111 HelpTextObj
.SetLang('')
1112 HelpTextObj
.SetString(HelpStr
)
1113 Object
.SetHelpTextList([HelpTextObj
])
1117 def testNormalCase1(self
):
1119 SupArchList
= ['X64']
1124 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1125 ObjectList
.append(Object
)
1127 Result
= GenSpecialSections(ObjectList
, 'Hob')
1128 Expected
= '''# [Hob.X64]
1136 self
.assertEqual(Result
, Expected
)
1138 def testNormalCase2(self
):
1145 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1146 ObjectList
.append(Object
)
1148 Result
= GenSpecialSections(ObjectList
, 'Hob')
1149 Expected
= '''# [Hob]
1157 self
.assertEqual(Result
, Expected
)
1159 def testNormalCase3(self
):
1161 SupArchList
= ['X64']
1164 Str
= '\nComment Line 1\n\n'
1166 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1167 ObjectList
.append(Object
)
1169 Result
= GenSpecialSections(ObjectList
, 'Hob')
1170 Expected
= '''# [Hob.X64]
1178 self
.assertEqual(Result
, Expected
)
1180 def testNormalCase4(self
):
1182 SupArchList
= ['X64']
1185 Str
= '\nComment Line 1\n'
1187 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1188 ObjectList
.append(Object
)
1190 Result
= GenSpecialSections(ObjectList
, 'Hob')
1191 Expected
= '''# [Hob.X64]
1199 self
.assertEqual(Result
, Expected
)
1201 def testNormalCase5(self
):
1203 SupArchList
= ['X64']
1206 Str
= 'Comment Line 1\n\n'
1208 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1209 ObjectList
.append(Object
)
1211 Result
= GenSpecialSections(ObjectList
, 'Hob')
1212 Expected
= '''# [Hob.X64]
1220 self
.assertEqual(Result
, Expected
)
1222 def testNormalCase6(self
):
1224 SupArchList
= ['X64']
1229 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1230 ObjectList
.append(Object
)
1232 Result
= GenSpecialSections(ObjectList
, 'Hob')
1233 Expected
= '''# [Hob.X64]
1238 self
.assertEqual(Result
, Expected
)
1240 def testNormalCase7(self
):
1242 SupArchList
= ['X64']
1245 Str
= '\nNew Stack HoB'
1248 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1249 ObjectList
.append(Object
)
1251 Result
= GenSpecialSections(ObjectList
, 'Hob')
1252 Expected
= '''# [Hob.X64]
1260 self
.assertEqual(Result
, Expected
)
1262 def testNormalCase8(self
):
1264 SupArchList
= ['X64']
1267 Str
= '\nNew Stack HoB\n\nTail Comment'
1270 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1271 ObjectList
.append(Object
)
1273 Result
= GenSpecialSections(ObjectList
, 'Hob')
1274 Expected
= '''# [Hob.X64]
1284 self
.assertEqual(Result
, Expected
)
1286 def testNormalCase9(self
):
1288 SupArchList
= ['X64']
1294 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1295 ObjectList
.append(Object
)
1297 Result
= GenSpecialSections(ObjectList
, 'Hob')
1298 Expected
= '''# [Hob.X64]
1306 self
.assertEqual(Result
, Expected
)
1308 def testNormalCase10(self
):
1310 SupArchList
= ['X64']
1315 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1316 ObjectList
.append(Object
)
1318 Result
= GenSpecialSections(ObjectList
, 'Hob')
1319 Expected
= '''# [Hob.X64]
1327 self
.assertEqual(Result
, Expected
)
1329 def testNormalCase11(self
):
1331 SupArchList
= ['X64']
1336 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1337 ObjectList
.append(Object
)
1339 Result
= GenSpecialSections(ObjectList
, 'Hob')
1340 Expected
= '''# [Hob.X64]
1348 self
.assertEqual(Result
, Expected
)
1350 def testNormalCase12(self
):
1352 SupArchList
= ['X64']
1357 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1358 ObjectList
.append(Object
)
1360 Result
= GenSpecialSections(ObjectList
, 'Hob')
1361 Expected
= '''# [Hob.X64]
1370 self
.assertEqual(Result
, Expected
)
1373 # Test GenGenericCommentF
1375 class GenGenericCommentFTest(unittest
.TestCase
):
1382 def testNormalCase1(self
):
1383 CommentLines
= 'Comment Line 1'
1384 Result
= GenGenericCommentF(CommentLines
)
1385 Expected
= '# Comment Line 1\n'
1386 self
.assertEqual(Result
, Expected
)
1388 def testNormalCase2(self
):
1390 Result
= GenGenericCommentF(CommentLines
)
1392 self
.assertEqual(Result
, Expected
)
1394 def testNormalCase3(self
):
1395 CommentLines
= '\n\n\n'
1396 Result
= GenGenericCommentF(CommentLines
)
1397 Expected
= '#\n#\n#\n'
1398 self
.assertEqual(Result
, Expected
)
1400 def testNormalCase4(self
):
1401 CommentLines
= 'coment line 1\n'
1402 Result
= GenGenericCommentF(CommentLines
)
1403 Expected
= '# coment line 1\n'
1404 self
.assertEqual(Result
, Expected
)
1406 def testNormalCase5(self
):
1407 CommentLines
= 'coment line 1\n coment line 2\n'
1408 Result
= GenGenericCommentF(CommentLines
)
1409 Expected
= '# coment line 1\n# coment line 2\n'
1410 self
.assertEqual(Result
, Expected
)
1412 if __name__
== '__main__':