]>
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 - 2014, Intel Corporation. All rights reserved.<BR>
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
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.
17 import Logger
.Log
as Logger
18 from GenMetaFile
.GenInfFile
import GenGuidSections
19 from GenMetaFile
.GenInfFile
import GenProtocolPPiSections
20 from GenMetaFile
.GenInfFile
import GenPcdSections
21 from GenMetaFile
.GenInfFile
import GenSpecialSections
22 from Library
.CommentGenerating
import GenGenericCommentF
23 from Library
.CommentGenerating
import _GetHelpStr
24 from Object
.POM
.CommonObject
import TextObject
25 from Object
.POM
.CommonObject
import GuidObject
26 from Object
.POM
.CommonObject
import ProtocolObject
27 from Object
.POM
.CommonObject
import PpiObject
28 from Object
.POM
.CommonObject
import PcdObject
29 from Object
.POM
.ModuleObject
import HobObject
31 from Library
.String
import GetSplitValueList
32 from Library
.DataType
import TAB_SPACE_SPLIT
33 from Library
.DataType
import TAB_LANGUAGE_EN_US
34 from Library
.DataType
import TAB_LANGUAGE_ENG
35 from Library
.DataType
import ITEM_UNDEFINED
36 from Library
.DataType
import TAB_INF_FEATURE_PCD
37 from Library
import GlobalData
38 from Library
.Misc
import CreateDirectory
43 class _GetHelpStrTest(unittest
.TestCase
):
51 # Normal case1: have one help text object with Lang = 'en-US'
53 def testNormalCase1(self
):
54 HelpStr
= 'Hello world'
55 HelpTextObj
= TextObject()
56 HelpTextObj
.SetLang(TAB_LANGUAGE_EN_US
)
57 HelpTextObj
.SetString(HelpStr
)
59 HelpTextList
= [HelpTextObj
]
60 Result
= _GetHelpStr(HelpTextList
)
61 self
.assertEqual(Result
, HelpStr
)
64 # Normal case2: have two help text object with Lang = 'en-US' and other
66 def testNormalCase2(self
):
67 HelpStr
= 'Hello world'
68 HelpTextObj
= TextObject()
69 HelpTextObj
.SetLang(TAB_LANGUAGE_ENG
)
70 HelpTextObj
.SetString(HelpStr
)
72 HelpTextList
= [HelpTextObj
]
74 ExpectedStr
= 'Hello world1'
75 HelpTextObj
= TextObject()
76 HelpTextObj
.SetLang(TAB_LANGUAGE_EN_US
)
77 HelpTextObj
.SetString(ExpectedStr
)
79 HelpTextList
.append(HelpTextObj
)
81 Result
= _GetHelpStr(HelpTextList
)
82 self
.assertEqual(Result
, ExpectedStr
)
85 # Normal case3: have two help text object with Lang = '' and 'eng'
87 def testNormalCase3(self
):
88 HelpStr
= 'Hello world'
89 HelpTextObj
= TextObject()
90 HelpTextObj
.SetLang('')
91 HelpTextObj
.SetString(HelpStr
)
93 HelpTextList
= [HelpTextObj
]
95 ExpectedStr
= 'Hello world1'
96 HelpTextObj
= TextObject()
97 HelpTextObj
.SetLang(TAB_LANGUAGE_ENG
)
98 HelpTextObj
.SetString(ExpectedStr
)
100 HelpTextList
.append(HelpTextObj
)
102 Result
= _GetHelpStr(HelpTextList
)
103 self
.assertEqual(Result
, ExpectedStr
)
106 # Normal case4: have two help text object with Lang = '' and ''
108 def testNormalCase4(self
):
110 ExpectedStr
= 'Hello world1'
111 HelpTextObj
= TextObject()
112 HelpTextObj
.SetLang(TAB_LANGUAGE_ENG
)
113 HelpTextObj
.SetString(ExpectedStr
)
114 HelpTextList
= [HelpTextObj
]
116 HelpStr
= 'Hello world'
117 HelpTextObj
= TextObject()
118 HelpTextObj
.SetLang('')
119 HelpTextObj
.SetString(HelpStr
)
120 HelpTextList
.append(HelpTextObj
)
122 Result
= _GetHelpStr(HelpTextList
)
123 self
.assertEqual(Result
, ExpectedStr
)
126 # Normal case: have three help text object with Lang = '','en', 'en-US'
128 def testNormalCase5(self
):
130 ExpectedStr
= 'Hello world1'
131 HelpTextObj
= TextObject()
132 HelpTextObj
.SetLang(TAB_LANGUAGE_EN_US
)
133 HelpTextObj
.SetString(ExpectedStr
)
134 HelpTextList
= [HelpTextObj
]
136 HelpStr
= 'Hello unknown world'
137 HelpTextObj
= TextObject()
138 HelpTextObj
.SetLang('')
139 HelpTextObj
.SetString(HelpStr
)
140 HelpTextList
.append(HelpTextObj
)
142 HelpStr
= 'Hello mysterious world'
143 HelpTextObj
= TextObject()
144 HelpTextObj
.SetLang('')
145 HelpTextObj
.SetString(HelpStr
)
146 HelpTextList
.append(HelpTextObj
)
148 Result
= _GetHelpStr(HelpTextList
)
149 self
.assertEqual(Result
, ExpectedStr
)
152 self
.assertEqual(Result
, ExpectedStr
)
154 HelpTextList
.sort(reverse
=True)
155 self
.assertEqual(Result
, ExpectedStr
)
159 # Test GenGuidSections
161 class GenGuidSectionsTest(unittest
.TestCase
):
169 # This is the API to generate Guid Object to help UnitTest
171 def GuidFactory(self
, CName
, FFE
, Usage
, GuidType
, VariableName
, HelpStr
):
174 Guid
.SetFeatureFlag(FFE
)
175 Guid
.SetGuidTypeList([GuidType
])
177 Guid
.SetVariableName(VariableName
)
179 HelpTextObj
= TextObject()
180 HelpTextObj
.SetLang('')
181 HelpTextObj
.SetString(HelpStr
)
182 Guid
.SetHelpTextList([HelpTextObj
])
187 # Normal case: have two GuidObject
189 def testNormalCase1(self
):
197 HelpStr
= 'Usage comment line 1'
198 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
199 VariableName
, HelpStr
)
200 GuidList
.append(Guid1
)
205 GuidType
= 'Variable'
207 HelpStr
= 'Usage comment line 2'
208 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
209 VariableName
, HelpStr
)
210 GuidList
.append(Guid1
)
212 Result
= GenGuidSections(GuidList
)
213 Expected
= '''[Guids]
214 ## PRODUCES ## Event # Usage comment line 1
215 ## CONSUMES ## Variable: # Usage comment line 2
217 self
.assertEqual(Result
.strip(), Expected
)
220 # Normal case: have two GuidObject
222 def testNormalCase2(self
):
230 HelpStr
= 'Usage comment line 1'
231 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
232 VariableName
, HelpStr
)
233 GuidList
.append(Guid1
)
238 GuidType
= 'UNDEFINED'
240 HelpStr
= 'Generic comment line 1\n Generic comment line 2'
241 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
242 VariableName
, HelpStr
)
243 GuidList
.append(Guid1
)
245 Result
= GenGuidSections(GuidList
)
246 Expected
= '''[Guids]
247 ## PRODUCES ## Event # Usage comment line 1
248 # Generic comment line 1
249 # Generic comment line 2
252 self
.assertEqual(Result
.strip(), Expected
)
255 # Normal case: have two GuidObject, one help goes to generic help,
256 # the other go into usage comment
258 def testNormalCase3(self
):
264 GuidType
= 'UNDEFINED'
266 HelpStr
= 'Generic comment'
267 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
268 VariableName
, HelpStr
)
269 GuidList
.append(Guid1
)
276 HelpStr
= 'Usage comment line 1'
277 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
278 VariableName
, HelpStr
)
279 GuidList
.append(Guid1
)
281 Result
= GenGuidSections(GuidList
)
282 Expected
= '''[Guids]
284 ## PRODUCES ## Event # Usage comment line 1
287 self
.assertEqual(Result
.strip(), Expected
)
290 # Normal case: have one GuidObject, generic comment multiple lines
292 def testNormalCase5(self
):
298 GuidType
= 'UNDEFINED'
300 HelpStr
= 'Generic comment line1 \n generic comment line 2'
301 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
302 VariableName
, HelpStr
)
303 GuidList
.append(Guid1
)
305 Result
= GenGuidSections(GuidList
)
306 Expected
= '''[Guids]
307 # Generic comment line1
308 # generic comment line 2
311 self
.assertEqual(Result
.strip(), Expected
)
314 # Normal case: have one GuidObject, usage comment multiple lines
316 def testNormalCase6(self
):
324 HelpStr
= 'Usage comment line 1\n Usage comment line 2'
325 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
326 VariableName
, HelpStr
)
327 GuidList
.append(Guid1
)
329 Result
= GenGuidSections(GuidList
)
330 Expected
= '''[Guids]
331 Guid1|FFE1 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
333 self
.assertEqual(Result
.strip(), Expected
.strip())
336 # Normal case: have one GuidObject, usage comment one line
338 def testNormalCase7(self
):
344 GuidType
= 'UNDEFINED'
346 HelpStr
= 'Usage comment line 1'
347 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
348 VariableName
, HelpStr
)
349 GuidList
.append(Guid1
)
351 Result
= GenGuidSections(GuidList
)
352 Expected
= '''[Guids]
353 Guid1|FFE1 # Usage comment line 1
355 self
.assertEqual(Result
.strip(), Expected
.strip())
358 # Normal case: have two GuidObject
360 def testNormalCase8(self
):
368 HelpStr
= 'Usage comment line 1\n Usage comment line 2'
369 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
370 VariableName
, HelpStr
)
371 GuidList
.append(Guid1
)
378 HelpStr
= 'Usage comment line 3'
379 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
380 VariableName
, HelpStr
)
381 GuidList
.append(Guid1
)
383 Result
= GenGuidSections(GuidList
)
384 Expected
= '''[Guids]
385 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
386 ## PRODUCES ## Event # Usage comment line 3
389 self
.assertEqual(Result
.strip(), Expected
.strip())
392 # Normal case: have no GuidObject
394 def testNormalCase9(self
):
397 Result
= GenGuidSections(GuidList
)
399 self
.assertEqual(Result
.strip(), Expected
.strip())
402 # Normal case: have one GuidObject with no comment generated
404 def testNormalCase10(self
):
410 GuidType
= 'UNDEFINED'
413 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
414 VariableName
, HelpStr
)
415 GuidList
.append(Guid1
)
417 Result
= GenGuidSections(GuidList
)
418 Expected
= '''[Guids]
421 self
.assertEqual(Result
.strip(), Expected
.strip())
424 # Normal case: have three GuidObject
426 def testNormalCase11(self
):
432 GuidType
= 'UNDEFINED'
434 HelpStr
= 'general comment line 1'
435 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
436 VariableName
, HelpStr
)
437 GuidList
.append(Guid1
)
444 HelpStr
= 'Usage comment line 3'
445 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
446 VariableName
, HelpStr
)
447 GuidList
.append(Guid1
)
452 GuidType
= 'UNDEFINED'
454 HelpStr
= 'general comment line 2'
455 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
456 VariableName
, HelpStr
)
457 GuidList
.append(Guid1
)
459 Result
= GenGuidSections(GuidList
)
460 Expected
= '''[Guids]
461 # general comment line 1
462 ## PRODUCES ## Event # Usage comment line 3
463 # general comment line 2
466 self
.assertEqual(Result
.strip(), Expected
.strip())
469 # Normal case: have three GuidObject, with Usage/Type and no help
471 def testNormalCase12(self
):
480 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
481 VariableName
, HelpStr
)
482 GuidList
.append(Guid1
)
490 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
491 VariableName
, HelpStr
)
492 GuidList
.append(Guid1
)
500 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
501 VariableName
, HelpStr
)
502 GuidList
.append(Guid1
)
504 Result
= GenGuidSections(GuidList
)
505 Expected
= '''[Guids]
511 self
.assertEqual(Result
.strip(), Expected
.strip())
514 # Test GenProtocolPPiSections
516 class GenProtocolPPiSectionsTest(unittest
.TestCase
):
524 # This is the API to generate Protocol/Ppi Object to help UnitTest
526 def ObjectFactory(self
, CName
, FFE
, Usage
, Notify
, HelpStr
, IsProtocol
):
528 Object
= ProtocolObject()
532 Object
.SetCName(CName
)
533 Object
.SetFeatureFlag(FFE
)
534 Object
.SetUsage(Usage
)
535 Object
.SetNotify(Notify
)
537 HelpTextObj
= TextObject()
538 HelpTextObj
.SetLang('')
539 HelpTextObj
.SetString(HelpStr
)
540 Object
.SetHelpTextList([HelpTextObj
])
544 # Usage Notify Help INF Comment
545 #1 UNDEFINED true Present ## UNDEFINED ## NOTIFY # Help
546 #2 UNDEFINED true Not Present ## UNDEFINED ## NOTIFY
547 #3 UNDEFINED false Present ## UNDEFINED # Help
548 #4 UNDEFINED false Not Present ## UNDEFINED
549 #5 UNDEFINED Not Present Present # Help
550 #6 UNDEFINED Not Present Not Present <empty>
551 #7 Other true Present ## Other ## NOTIFY # Help
552 #8 Other true Not Present ## Other ## NOTIFY
553 #9 Other false Present ## Other # Help
554 #A Other false Not Present ## Other
555 #B Other Not Present Present ## Other # Help
556 #C Other Not Present Not Present ## Other
558 def testNormalCase1(self
):
568 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
570 ObjectList
.append(Object
)
573 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
574 Expected
= '''[Protocols]
575 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
576 self
.assertEqual(Result
.strip(), Expected
)
580 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
582 ObjectList
.append(Object
)
585 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
587 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
588 self
.assertEqual(Result
.strip(), Expected
)
590 def testNormalCase2(self
):
600 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
602 ObjectList
.append(Object
)
605 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
606 Expected
= '''[Protocols]
607 Guid1|FFE1 ## UNDEFINED ## NOTIFY'''
608 self
.assertEqual(Result
.strip(), Expected
)
610 def testNormalCase3(self
):
620 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
622 ObjectList
.append(Object
)
625 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
626 Expected
= '''[Protocols]
627 Guid1|FFE1 ## UNDEFINED # Help'''
628 self
.assertEqual(Result
.strip(), Expected
)
630 def testNormalCase4(self
):
640 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
642 ObjectList
.append(Object
)
645 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
646 Expected
= '''[Protocols]
647 Guid1|FFE1 ## UNDEFINED'''
648 self
.assertEqual(Result
.strip(), Expected
)
650 def testNormalCase5(self
):
660 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
662 ObjectList
.append(Object
)
665 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
666 Expected
= '''[Protocols]
668 self
.assertEqual(Result
.strip(), Expected
)
670 def testNormalCase6(self
):
680 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
682 ObjectList
.append(Object
)
685 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
686 Expected
= '''[Protocols]
688 self
.assertEqual(Result
.strip(), Expected
)
690 def testNormalCase7(self
):
700 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
702 ObjectList
.append(Object
)
705 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
706 Expected
= '''[Protocols]
707 Guid1|FFE1 ## PRODUCES ## NOTIFY # Help'''
708 self
.assertEqual(Result
.strip(), Expected
)
710 def testNormalCase8(self
):
720 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
722 ObjectList
.append(Object
)
725 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
726 Expected
= '''[Protocols]
727 Guid1|FFE1 ## PRODUCES ## NOTIFY'''
728 self
.assertEqual(Result
.strip(), Expected
)
730 def testNormalCase9(self
):
740 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
742 ObjectList
.append(Object
)
745 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
746 Expected
= '''[Protocols]
747 Guid1|FFE1 ## PRODUCES # Help'''
748 self
.assertEqual(Result
.strip(), Expected
)
750 def testNormalCaseA(self
):
760 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
762 ObjectList
.append(Object
)
765 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
766 Expected
= '''[Protocols]
767 Guid1|FFE1 ## PRODUCES'''
768 self
.assertEqual(Result
.strip(), Expected
)
770 def testNormalCaseB(self
):
780 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
782 ObjectList
.append(Object
)
785 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
786 Expected
= '''[Protocols]
787 Guid1|FFE1 ## PRODUCES # Help'''
788 self
.assertEqual(Result
.strip(), Expected
)
790 def testNormalCaseC(self
):
800 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
802 ObjectList
.append(Object
)
805 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
806 Expected
= '''[Protocols]
807 Guid1|FFE1 ## PRODUCES'''
808 self
.assertEqual(Result
.strip(), Expected
)
811 # Test GenPcdSections
813 class GenPcdSectionsTest(unittest
.TestCase
):
821 # This is the API to generate Pcd Object to help UnitTest
823 def ObjectFactory(self
, ItemType
, TSCName
, CName
, DValue
, FFE
, Usage
, Str
):
827 Object
.SetItemType(ItemType
)
828 Object
.SetTokenSpaceGuidCName(TSCName
)
829 Object
.SetCName(CName
)
830 Object
.SetDefaultValue(DValue
)
831 Object
.SetFeatureFlag(FFE
)
832 Object
.SetValidUsage(Usage
)
834 HelpTextObj
= TextObject()
835 HelpTextObj
.SetLang('')
836 HelpTextObj
.SetString(HelpStr
)
837 Object
.SetHelpTextList([HelpTextObj
])
842 # Usage Help INF Comment
843 #1 UNDEFINED Present # Help
844 #2 UNDEFINED Not Present <empty>
845 #3 Other Present ## Other # Help
846 #4 Other Not Present ## Other
848 def testNormalCase1(self
):
859 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
861 ObjectList
.append(Object
)
863 Result
= GenPcdSections(ObjectList
)
866 'TSCName.CName|DValue|FFE # Help'
867 self
.assertEqual(Result
.strip(), Expected
)
869 def testNormalCase2(self
):
880 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
882 ObjectList
.append(Object
)
884 Result
= GenPcdSections(ObjectList
)
885 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE'
886 self
.assertEqual(Result
.strip(), Expected
)
888 def testNormalCase3(self
):
899 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
901 ObjectList
.append(Object
)
903 Result
= GenPcdSections(ObjectList
)
904 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES # Help'
905 self
.assertEqual(Result
.strip(), Expected
)
907 def testNormalCase4(self
):
918 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
920 ObjectList
.append(Object
)
922 Result
= GenPcdSections(ObjectList
)
923 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES'
924 self
.assertEqual(Result
.strip(), Expected
)
927 # multiple lines for normal usage
929 def testNormalCase5(self
):
938 Str
= 'commment line 1\ncomment line 2'
939 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
941 ObjectList
.append(Object
)
943 Result
= GenPcdSections(ObjectList
)
945 TSCName.CName|DValue|FFE ## CONSUMES # commment line 1 comment line 2'''
946 self
.assertEqual(Result
.strip(), Expected
)
949 # multiple lines for UNDEFINED usage
951 def testNormalCase6(self
):
960 Str
= 'commment line 1\ncomment line 2'
961 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
963 ObjectList
.append(Object
)
966 Str
= 'commment line 3'
967 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
969 ObjectList
.append(Object
)
971 Result
= GenPcdSections(ObjectList
)
976 TSCName.CName|DValue|FFE'''
977 self
.assertEqual(Result
.strip(), Expected
)
980 # multiple lines for UNDEFINED and normal usage
982 def testNormalCase7(self
):
991 Str
= 'commment line 1\ncomment line 2'
992 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
994 ObjectList
.append(Object
)
998 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1000 ObjectList
.append(Object
)
1003 Str
= 'commment line 3'
1004 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1006 ObjectList
.append(Object
)
1008 Result
= GenPcdSections(ObjectList
)
1014 TSCName.CName|DValue|FFE'''
1015 self
.assertEqual(Result
.strip(), Expected
)
1017 # Usage Help INF Comment
1018 # CONSUMES Present # Help (keep <EOL> and insert '#' at beginning of each new line)
1019 # CONSUMES Not Present <empty>
1022 # TAB_INF_FEATURE_PCD
1024 def testNormalCase8(self
):
1026 ItemType
= TAB_INF_FEATURE_PCD
1033 Str
= 'commment line 1\ncomment line 2'
1034 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1036 ObjectList
.append(Object
)
1038 Result
= GenPcdSections(ObjectList
)
1039 Expected
= '''[FeaturePcd]
1042 TSCName.CName|DValue|FFE'''
1043 self
.assertEqual(Result
.strip(), Expected
)
1046 # TAB_INF_FEATURE_PCD
1048 def testNormalCase9(self
):
1050 ItemType
= TAB_INF_FEATURE_PCD
1058 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1060 ObjectList
.append(Object
)
1062 Result
= GenPcdSections(ObjectList
)
1063 Expected
= '''[FeaturePcd]
1064 TSCName.CName|DValue|FFE'''
1065 self
.assertEqual(Result
.strip(), Expected
)
1068 # TAB_INF_FEATURE_PCD
1070 def testNormalCase10(self
):
1072 ItemType
= TAB_INF_FEATURE_PCD
1079 Str
= 'commment line 1\ncomment line 2'
1080 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1082 ObjectList
.append(Object
)
1084 Result
= GenPcdSections(ObjectList
)
1090 TSCName.CName|DValue|FFE
1092 self
.assertEqual(Result
, Expected
)
1096 # Test GenSpecialSections of Hob
1098 class GenHobSectionsTest(unittest
.TestCase
):
1106 # This is the API to generate Event Object to help UnitTest
1108 def ObjectFactory(self
, SupArchList
, Type
, Usage
, Str
):
1109 Object
= HobObject()
1112 Object
.SetHobType(Type
)
1113 Object
.SetUsage(Usage
)
1114 Object
.SetSupArchList(SupArchList
)
1116 HelpTextObj
= TextObject()
1117 HelpTextObj
.SetLang('')
1118 HelpTextObj
.SetString(HelpStr
)
1119 Object
.SetHelpTextList([HelpTextObj
])
1123 def testNormalCase1(self
):
1125 SupArchList
= ['X64']
1130 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1131 ObjectList
.append(Object
)
1133 Result
= GenSpecialSections(ObjectList
, 'Hob')
1134 Expected
= '''# [Hob.X64]
1142 self
.assertEqual(Result
, Expected
)
1144 def testNormalCase2(self
):
1151 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1152 ObjectList
.append(Object
)
1154 Result
= GenSpecialSections(ObjectList
, 'Hob')
1155 Expected
= '''# [Hob]
1163 self
.assertEqual(Result
, Expected
)
1165 def testNormalCase3(self
):
1167 SupArchList
= ['X64']
1170 Str
= '\nComment Line 1\n\n'
1172 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1173 ObjectList
.append(Object
)
1175 Result
= GenSpecialSections(ObjectList
, 'Hob')
1176 Expected
= '''# [Hob.X64]
1184 self
.assertEqual(Result
, Expected
)
1186 def testNormalCase4(self
):
1188 SupArchList
= ['X64']
1191 Str
= '\nComment Line 1\n'
1193 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1194 ObjectList
.append(Object
)
1196 Result
= GenSpecialSections(ObjectList
, 'Hob')
1197 Expected
= '''# [Hob.X64]
1205 self
.assertEqual(Result
, Expected
)
1207 def testNormalCase5(self
):
1209 SupArchList
= ['X64']
1212 Str
= 'Comment Line 1\n\n'
1214 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1215 ObjectList
.append(Object
)
1217 Result
= GenSpecialSections(ObjectList
, 'Hob')
1218 Expected
= '''# [Hob.X64]
1226 self
.assertEqual(Result
, Expected
)
1228 def testNormalCase6(self
):
1230 SupArchList
= ['X64']
1235 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1236 ObjectList
.append(Object
)
1238 Result
= GenSpecialSections(ObjectList
, 'Hob')
1239 Expected
= '''# [Hob.X64]
1244 self
.assertEqual(Result
, Expected
)
1246 def testNormalCase7(self
):
1248 SupArchList
= ['X64']
1251 Str
= '\nNew Stack HoB'
1254 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1255 ObjectList
.append(Object
)
1257 Result
= GenSpecialSections(ObjectList
, 'Hob')
1258 Expected
= '''# [Hob.X64]
1266 self
.assertEqual(Result
, Expected
)
1268 def testNormalCase8(self
):
1270 SupArchList
= ['X64']
1273 Str
= '\nNew Stack HoB\n\nTail Comment'
1276 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1277 ObjectList
.append(Object
)
1279 Result
= GenSpecialSections(ObjectList
, 'Hob')
1280 Expected
= '''# [Hob.X64]
1290 self
.assertEqual(Result
, Expected
)
1292 def testNormalCase9(self
):
1294 SupArchList
= ['X64']
1300 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1301 ObjectList
.append(Object
)
1303 Result
= GenSpecialSections(ObjectList
, 'Hob')
1304 Expected
= '''# [Hob.X64]
1312 self
.assertEqual(Result
, Expected
)
1314 def testNormalCase10(self
):
1316 SupArchList
= ['X64']
1321 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1322 ObjectList
.append(Object
)
1324 Result
= GenSpecialSections(ObjectList
, 'Hob')
1325 Expected
= '''# [Hob.X64]
1333 self
.assertEqual(Result
, Expected
)
1335 def testNormalCase11(self
):
1337 SupArchList
= ['X64']
1342 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1343 ObjectList
.append(Object
)
1345 Result
= GenSpecialSections(ObjectList
, 'Hob')
1346 Expected
= '''# [Hob.X64]
1354 self
.assertEqual(Result
, Expected
)
1356 def testNormalCase12(self
):
1358 SupArchList
= ['X64']
1363 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1364 ObjectList
.append(Object
)
1366 Result
= GenSpecialSections(ObjectList
, 'Hob')
1367 Expected
= '''# [Hob.X64]
1376 self
.assertEqual(Result
, Expected
)
1379 # Test GenGenericCommentF
1381 class GenGenericCommentFTest(unittest
.TestCase
):
1388 def testNormalCase1(self
):
1389 CommentLines
= 'Comment Line 1'
1390 Result
= GenGenericCommentF(CommentLines
)
1391 Expected
= '# Comment Line 1\n'
1392 self
.assertEqual(Result
, Expected
)
1394 def testNormalCase2(self
):
1396 Result
= GenGenericCommentF(CommentLines
)
1398 self
.assertEqual(Result
, Expected
)
1400 def testNormalCase3(self
):
1401 CommentLines
= '\n\n\n'
1402 Result
= GenGenericCommentF(CommentLines
)
1403 Expected
= '#\n#\n#\n'
1404 self
.assertEqual(Result
, Expected
)
1406 def testNormalCase4(self
):
1407 CommentLines
= 'coment line 1\n'
1408 Result
= GenGenericCommentF(CommentLines
)
1409 Expected
= '# coment line 1\n'
1410 self
.assertEqual(Result
, Expected
)
1412 def testNormalCase5(self
):
1413 CommentLines
= 'coment line 1\n coment line 2\n'
1414 Result
= GenGenericCommentF(CommentLines
)
1415 Expected
= '# coment line 1\n# coment line 2\n'
1416 self
.assertEqual(Result
, Expected
)
1418 if __name__
== '__main__':