]>
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, 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 LANGUAGE_EN_US
34 from Library
.DataType
import ITEM_UNDEFINED
35 from Library
.DataType
import TAB_INF_FEATURE_PCD
36 from Library
import GlobalData
37 from Library
.Misc
import CreateDirectory
42 class _GetHelpStrTest(unittest
.TestCase
):
50 # Normal case1: have one help text object with Lang = 'en-US'
52 def testNormalCase1(self
):
53 HelpStr
= 'Hello world'
54 HelpTextObj
= TextObject()
55 HelpTextObj
.SetLang(LANGUAGE_EN_US
)
56 HelpTextObj
.SetString(HelpStr
)
58 HelpTextList
= [HelpTextObj
]
59 Result
= _GetHelpStr(HelpTextList
)
60 self
.assertEqual(Result
, HelpStr
)
63 # Normal case2: have two help text object with Lang = 'en-US' and other
65 def testNormalCase2(self
):
66 HelpStr
= 'Hello world'
67 HelpTextObj
= TextObject()
68 HelpTextObj
.SetLang('eng')
69 HelpTextObj
.SetString(HelpStr
)
71 HelpTextList
= [HelpTextObj
]
73 ExpectedStr
= 'Hello world1'
74 HelpTextObj
= TextObject()
75 HelpTextObj
.SetLang(LANGUAGE_EN_US
)
76 HelpTextObj
.SetString(ExpectedStr
)
78 HelpTextList
.append(HelpTextObj
)
80 Result
= _GetHelpStr(HelpTextList
)
81 self
.assertEqual(Result
, ExpectedStr
)
84 # Normal case3: have two help text object with Lang = '' and 'eng'
86 def testNormalCase3(self
):
87 HelpStr
= 'Hello world'
88 HelpTextObj
= TextObject()
89 HelpTextObj
.SetLang('')
90 HelpTextObj
.SetString(HelpStr
)
92 HelpTextList
= [HelpTextObj
]
94 ExpectedStr
= 'Hello world1'
95 HelpTextObj
= TextObject()
96 HelpTextObj
.SetLang('eng')
97 HelpTextObj
.SetString(ExpectedStr
)
99 HelpTextList
.append(HelpTextObj
)
101 Result
= _GetHelpStr(HelpTextList
)
102 self
.assertEqual(Result
, ExpectedStr
)
105 # Normal case4: have two help text object with Lang = '' and ''
107 def testNormalCase4(self
):
109 ExpectedStr
= 'Hello world1'
110 HelpTextObj
= TextObject()
111 HelpTextObj
.SetLang('eng')
112 HelpTextObj
.SetString(ExpectedStr
)
113 HelpTextList
= [HelpTextObj
]
115 HelpStr
= 'Hello world'
116 HelpTextObj
= TextObject()
117 HelpTextObj
.SetLang('')
118 HelpTextObj
.SetString(HelpStr
)
119 HelpTextList
.append(HelpTextObj
)
121 Result
= _GetHelpStr(HelpTextList
)
122 self
.assertEqual(Result
, ExpectedStr
)
125 # Normal case: have three help text object with Lang = '','en', 'en-US'
127 def testNormalCase5(self
):
129 ExpectedStr
= 'Hello world1'
130 HelpTextObj
= TextObject()
131 HelpTextObj
.SetLang(LANGUAGE_EN_US
)
132 HelpTextObj
.SetString(ExpectedStr
)
133 HelpTextList
= [HelpTextObj
]
135 HelpStr
= 'Hello unknown world'
136 HelpTextObj
= TextObject()
137 HelpTextObj
.SetLang('')
138 HelpTextObj
.SetString(HelpStr
)
139 HelpTextList
.append(HelpTextObj
)
141 HelpStr
= 'Hello mysterious world'
142 HelpTextObj
= TextObject()
143 HelpTextObj
.SetLang('')
144 HelpTextObj
.SetString(HelpStr
)
145 HelpTextList
.append(HelpTextObj
)
147 Result
= _GetHelpStr(HelpTextList
)
148 self
.assertEqual(Result
, ExpectedStr
)
151 self
.assertEqual(Result
, ExpectedStr
)
153 HelpTextList
.sort(reverse
=True)
154 self
.assertEqual(Result
, ExpectedStr
)
158 # Test GenGuidSections
160 class GenGuidSectionsTest(unittest
.TestCase
):
168 # This is the API to generate Guid Object to help UnitTest
170 def GuidFactory(self
, CName
, FFE
, Usage
, GuidType
, VariableName
, HelpStr
):
173 Guid
.SetFeatureFlag(FFE
)
174 Guid
.SetGuidTypeList([GuidType
])
176 Guid
.SetVariableName(VariableName
)
178 HelpTextObj
= TextObject()
179 HelpTextObj
.SetLang('')
180 HelpTextObj
.SetString(HelpStr
)
181 Guid
.SetHelpTextList([HelpTextObj
])
186 # Normal case: have two GuidObject
188 def testNormalCase1(self
):
196 HelpStr
= 'Usage comment line 1'
197 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
198 VariableName
, HelpStr
)
199 GuidList
.append(Guid1
)
204 GuidType
= 'Variable'
206 HelpStr
= 'Usage comment line 2'
207 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
208 VariableName
, HelpStr
)
209 GuidList
.append(Guid1
)
211 Result
= GenGuidSections(GuidList
)
212 Expected
= '''[Guids]
213 ## PRODUCES ## Event # Usage comment line 1
214 ## CONSUMES ## Variable: # Usage comment line 2
216 self
.assertEqual(Result
.strip(), Expected
)
219 # Normal case: have two GuidObject
221 def testNormalCase2(self
):
229 HelpStr
= 'Usage comment line 1'
230 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
231 VariableName
, HelpStr
)
232 GuidList
.append(Guid1
)
237 GuidType
= 'UNDEFINED'
239 HelpStr
= 'Generic comment line 1\n Generic comment line 2'
240 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
241 VariableName
, HelpStr
)
242 GuidList
.append(Guid1
)
244 Result
= GenGuidSections(GuidList
)
245 Expected
= '''[Guids]
246 ## PRODUCES ## Event # Usage comment line 1
247 # Generic comment line 1
248 # Generic comment line 2
251 self
.assertEqual(Result
.strip(), Expected
)
254 # Normal case: have two GuidObject, one help goes to generic help,
255 # the other go into usage comment
257 def testNormalCase3(self
):
263 GuidType
= 'UNDEFINED'
265 HelpStr
= 'Generic comment'
266 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
267 VariableName
, HelpStr
)
268 GuidList
.append(Guid1
)
275 HelpStr
= 'Usage comment line 1'
276 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
277 VariableName
, HelpStr
)
278 GuidList
.append(Guid1
)
280 Result
= GenGuidSections(GuidList
)
281 Expected
= '''[Guids]
283 ## PRODUCES ## Event # Usage comment line 1
286 self
.assertEqual(Result
.strip(), Expected
)
289 # Normal case: have one GuidObject, generic comment multiple lines
291 def testNormalCase5(self
):
297 GuidType
= 'UNDEFINED'
299 HelpStr
= 'Generic comment line1 \n generic comment line 2'
300 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
301 VariableName
, HelpStr
)
302 GuidList
.append(Guid1
)
304 Result
= GenGuidSections(GuidList
)
305 Expected
= '''[Guids]
306 # Generic comment line1
307 # generic comment line 2
310 self
.assertEqual(Result
.strip(), Expected
)
313 # Normal case: have one GuidObject, usage comment multiple lines
315 def testNormalCase6(self
):
323 HelpStr
= 'Usage comment line 1\n Usage comment line 2'
324 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
325 VariableName
, HelpStr
)
326 GuidList
.append(Guid1
)
328 Result
= GenGuidSections(GuidList
)
329 Expected
= '''[Guids]
330 Guid1|FFE1 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
332 self
.assertEqual(Result
.strip(), Expected
.strip())
335 # Normal case: have one GuidObject, usage comment one line
337 def testNormalCase7(self
):
343 GuidType
= 'UNDEFINED'
345 HelpStr
= 'Usage comment line 1'
346 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
347 VariableName
, HelpStr
)
348 GuidList
.append(Guid1
)
350 Result
= GenGuidSections(GuidList
)
351 Expected
= '''[Guids]
352 Guid1|FFE1 # Usage comment line 1
354 self
.assertEqual(Result
.strip(), Expected
.strip())
357 # Normal case: have two GuidObject
359 def testNormalCase8(self
):
367 HelpStr
= 'Usage comment line 1\n Usage comment line 2'
368 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
369 VariableName
, HelpStr
)
370 GuidList
.append(Guid1
)
377 HelpStr
= 'Usage comment line 3'
378 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
379 VariableName
, HelpStr
)
380 GuidList
.append(Guid1
)
382 Result
= GenGuidSections(GuidList
)
383 Expected
= '''[Guids]
384 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
385 ## PRODUCES ## Event # Usage comment line 3
388 self
.assertEqual(Result
.strip(), Expected
.strip())
391 # Normal case: have no GuidObject
393 def testNormalCase9(self
):
396 Result
= GenGuidSections(GuidList
)
398 self
.assertEqual(Result
.strip(), Expected
.strip())
401 # Normal case: have one GuidObject with no comment generated
403 def testNormalCase10(self
):
409 GuidType
= 'UNDEFINED'
412 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
413 VariableName
, HelpStr
)
414 GuidList
.append(Guid1
)
416 Result
= GenGuidSections(GuidList
)
417 Expected
= '''[Guids]
420 self
.assertEqual(Result
.strip(), Expected
.strip())
423 # Normal case: have three GuidObject
425 def testNormalCase11(self
):
431 GuidType
= 'UNDEFINED'
433 HelpStr
= 'general comment line 1'
434 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
435 VariableName
, HelpStr
)
436 GuidList
.append(Guid1
)
443 HelpStr
= 'Usage comment line 3'
444 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
445 VariableName
, HelpStr
)
446 GuidList
.append(Guid1
)
451 GuidType
= 'UNDEFINED'
453 HelpStr
= 'general comment line 2'
454 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
455 VariableName
, HelpStr
)
456 GuidList
.append(Guid1
)
458 Result
= GenGuidSections(GuidList
)
459 Expected
= '''[Guids]
460 # general comment line 1
461 ## PRODUCES ## Event # Usage comment line 3
462 # general comment line 2
465 self
.assertEqual(Result
.strip(), Expected
.strip())
468 # Normal case: have three GuidObject, with Usage/Type and no help
470 def testNormalCase12(self
):
479 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
480 VariableName
, HelpStr
)
481 GuidList
.append(Guid1
)
489 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
490 VariableName
, HelpStr
)
491 GuidList
.append(Guid1
)
499 Guid1
= self
.GuidFactory(CName
, FFE
, Usage
, GuidType
,
500 VariableName
, HelpStr
)
501 GuidList
.append(Guid1
)
503 Result
= GenGuidSections(GuidList
)
504 Expected
= '''[Guids]
510 self
.assertEqual(Result
.strip(), Expected
.strip())
513 # Test GenProtocolPPiSections
515 class GenProtocolPPiSectionsTest(unittest
.TestCase
):
523 # This is the API to generate Protocol/Ppi Object to help UnitTest
525 def ObjectFactory(self
, CName
, FFE
, Usage
, Notify
, HelpStr
, IsProtocol
):
527 Object
= ProtocolObject()
531 Object
.SetCName(CName
)
532 Object
.SetFeatureFlag(FFE
)
533 Object
.SetUsage(Usage
)
534 Object
.SetNotify(Notify
)
536 HelpTextObj
= TextObject()
537 HelpTextObj
.SetLang('')
538 HelpTextObj
.SetString(HelpStr
)
539 Object
.SetHelpTextList([HelpTextObj
])
543 # Usage Notify Help INF Comment
544 #1 UNDEFINED true Present ## UNDEFINED ## NOTIFY # Help
545 #2 UNDEFINED true Not Present ## UNDEFINED ## NOTIFY
546 #3 UNDEFINED false Present ## UNDEFINED # Help
547 #4 UNDEFINED false Not Present ## UNDEFINED
548 #5 UNDEFINED Not Present Present # Help
549 #6 UNDEFINED Not Present Not Present <empty>
550 #7 Other true Present ## Other ## NOTIFY # Help
551 #8 Other true Not Present ## Other ## NOTIFY
552 #9 Other false Present ## Other # Help
553 #A Other false Not Present ## Other
554 #B Other Not Present Present ## Other # Help
555 #C Other Not Present Not Present ## Other
557 def testNormalCase1(self
):
567 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
569 ObjectList
.append(Object
)
572 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
573 Expected
= '''[Protocols]
574 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
575 self
.assertEqual(Result
.strip(), Expected
)
579 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
581 ObjectList
.append(Object
)
584 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
586 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
587 self
.assertEqual(Result
.strip(), Expected
)
589 def testNormalCase2(self
):
599 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
601 ObjectList
.append(Object
)
604 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
605 Expected
= '''[Protocols]
606 Guid1|FFE1 ## UNDEFINED ## NOTIFY'''
607 self
.assertEqual(Result
.strip(), Expected
)
609 def testNormalCase3(self
):
619 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
621 ObjectList
.append(Object
)
624 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
625 Expected
= '''[Protocols]
626 Guid1|FFE1 ## UNDEFINED # Help'''
627 self
.assertEqual(Result
.strip(), Expected
)
629 def testNormalCase4(self
):
639 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
641 ObjectList
.append(Object
)
644 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
645 Expected
= '''[Protocols]
646 Guid1|FFE1 ## UNDEFINED'''
647 self
.assertEqual(Result
.strip(), Expected
)
649 def testNormalCase5(self
):
659 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
661 ObjectList
.append(Object
)
664 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
665 Expected
= '''[Protocols]
667 self
.assertEqual(Result
.strip(), Expected
)
669 def testNormalCase6(self
):
679 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
681 ObjectList
.append(Object
)
684 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
685 Expected
= '''[Protocols]
687 self
.assertEqual(Result
.strip(), Expected
)
689 def testNormalCase7(self
):
699 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
701 ObjectList
.append(Object
)
704 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
705 Expected
= '''[Protocols]
706 Guid1|FFE1 ## PRODUCES ## NOTIFY # Help'''
707 self
.assertEqual(Result
.strip(), Expected
)
709 def testNormalCase8(self
):
719 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
721 ObjectList
.append(Object
)
724 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
725 Expected
= '''[Protocols]
726 Guid1|FFE1 ## PRODUCES ## NOTIFY'''
727 self
.assertEqual(Result
.strip(), Expected
)
729 def testNormalCase9(self
):
739 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
741 ObjectList
.append(Object
)
744 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
745 Expected
= '''[Protocols]
746 Guid1|FFE1 ## PRODUCES # Help'''
747 self
.assertEqual(Result
.strip(), Expected
)
749 def testNormalCaseA(self
):
759 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
761 ObjectList
.append(Object
)
764 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
765 Expected
= '''[Protocols]
766 Guid1|FFE1 ## PRODUCES'''
767 self
.assertEqual(Result
.strip(), Expected
)
769 def testNormalCaseB(self
):
779 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
781 ObjectList
.append(Object
)
784 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
785 Expected
= '''[Protocols]
786 Guid1|FFE1 ## PRODUCES # Help'''
787 self
.assertEqual(Result
.strip(), Expected
)
789 def testNormalCaseC(self
):
799 Object
= self
.ObjectFactory(CName
, FFE
, Usage
, Notify
,
801 ObjectList
.append(Object
)
804 Result
= GenProtocolPPiSections(ObjectList
, IsProtocol
)
805 Expected
= '''[Protocols]
806 Guid1|FFE1 ## PRODUCES'''
807 self
.assertEqual(Result
.strip(), Expected
)
810 # Test GenPcdSections
812 class GenPcdSectionsTest(unittest
.TestCase
):
820 # This is the API to generate Pcd Object to help UnitTest
822 def ObjectFactory(self
, ItemType
, TSCName
, CName
, DValue
, FFE
, Usage
, Str
):
826 Object
.SetItemType(ItemType
)
827 Object
.SetTokenSpaceGuidCName(TSCName
)
828 Object
.SetCName(CName
)
829 Object
.SetDefaultValue(DValue
)
830 Object
.SetFeatureFlag(FFE
)
831 Object
.SetValidUsage(Usage
)
833 HelpTextObj
= TextObject()
834 HelpTextObj
.SetLang('')
835 HelpTextObj
.SetString(HelpStr
)
836 Object
.SetHelpTextList([HelpTextObj
])
841 # Usage Help INF Comment
842 #1 UNDEFINED Present # Help
843 #2 UNDEFINED Not Present <empty>
844 #3 Other Present ## Other # Help
845 #4 Other Not Present ## Other
847 def testNormalCase1(self
):
858 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
860 ObjectList
.append(Object
)
862 Result
= GenPcdSections(ObjectList
)
865 'TSCName.CName|DValue|FFE # Help'
866 self
.assertEqual(Result
.strip(), Expected
)
868 def testNormalCase2(self
):
879 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
881 ObjectList
.append(Object
)
883 Result
= GenPcdSections(ObjectList
)
884 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE'
885 self
.assertEqual(Result
.strip(), Expected
)
887 def testNormalCase3(self
):
898 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
900 ObjectList
.append(Object
)
902 Result
= GenPcdSections(ObjectList
)
903 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES # Help'
904 self
.assertEqual(Result
.strip(), Expected
)
906 def testNormalCase4(self
):
917 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
919 ObjectList
.append(Object
)
921 Result
= GenPcdSections(ObjectList
)
922 Expected
= '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES'
923 self
.assertEqual(Result
.strip(), Expected
)
926 # multiple lines for normal usage
928 def testNormalCase5(self
):
937 Str
= 'commment line 1\ncomment line 2'
938 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
940 ObjectList
.append(Object
)
942 Result
= GenPcdSections(ObjectList
)
944 TSCName.CName|DValue|FFE ## CONSUMES # commment line 1 comment line 2'''
945 self
.assertEqual(Result
.strip(), Expected
)
948 # multiple lines for UNDEFINED usage
950 def testNormalCase6(self
):
959 Str
= 'commment line 1\ncomment line 2'
960 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
962 ObjectList
.append(Object
)
965 Str
= 'commment line 3'
966 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
968 ObjectList
.append(Object
)
970 Result
= GenPcdSections(ObjectList
)
975 TSCName.CName|DValue|FFE'''
976 self
.assertEqual(Result
.strip(), Expected
)
979 # multiple lines for UNDEFINED and normal usage
981 def testNormalCase7(self
):
990 Str
= 'commment line 1\ncomment line 2'
991 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
993 ObjectList
.append(Object
)
997 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
999 ObjectList
.append(Object
)
1002 Str
= 'commment line 3'
1003 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1005 ObjectList
.append(Object
)
1007 Result
= GenPcdSections(ObjectList
)
1013 TSCName.CName|DValue|FFE'''
1014 self
.assertEqual(Result
.strip(), Expected
)
1016 # Usage Help INF Comment
1017 # CONSUMES Present # Help (keep <EOL> and insert '#' at beginning of each new line)
1018 # CONSUMES Not Present <empty>
1021 # TAB_INF_FEATURE_PCD
1023 def testNormalCase8(self
):
1025 ItemType
= TAB_INF_FEATURE_PCD
1032 Str
= 'commment line 1\ncomment line 2'
1033 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1035 ObjectList
.append(Object
)
1037 Result
= GenPcdSections(ObjectList
)
1038 Expected
= '''[FeaturePcd]
1041 TSCName.CName|DValue|FFE'''
1042 self
.assertEqual(Result
.strip(), Expected
)
1045 # TAB_INF_FEATURE_PCD
1047 def testNormalCase9(self
):
1049 ItemType
= TAB_INF_FEATURE_PCD
1057 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1059 ObjectList
.append(Object
)
1061 Result
= GenPcdSections(ObjectList
)
1062 Expected
= '''[FeaturePcd]
1063 TSCName.CName|DValue|FFE'''
1064 self
.assertEqual(Result
.strip(), Expected
)
1067 # TAB_INF_FEATURE_PCD
1069 def testNormalCase10(self
):
1071 ItemType
= TAB_INF_FEATURE_PCD
1078 Str
= 'commment line 1\ncomment line 2'
1079 Object
= self
.ObjectFactory(ItemType
, TSCName
, CName
, DValue
, FFE
,
1081 ObjectList
.append(Object
)
1083 Result
= GenPcdSections(ObjectList
)
1089 TSCName.CName|DValue|FFE
1091 self
.assertEqual(Result
, Expected
)
1095 # Test GenSpecialSections of Hob
1097 class GenHobSectionsTest(unittest
.TestCase
):
1105 # This is the API to generate Event Object to help UnitTest
1107 def ObjectFactory(self
, SupArchList
, Type
, Usage
, Str
):
1108 Object
= HobObject()
1111 Object
.SetHobType(Type
)
1112 Object
.SetUsage(Usage
)
1113 Object
.SetSupArchList(SupArchList
)
1115 HelpTextObj
= TextObject()
1116 HelpTextObj
.SetLang('')
1117 HelpTextObj
.SetString(HelpStr
)
1118 Object
.SetHelpTextList([HelpTextObj
])
1122 def testNormalCase1(self
):
1124 SupArchList
= ['X64']
1129 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1130 ObjectList
.append(Object
)
1132 Result
= GenSpecialSections(ObjectList
, 'Hob')
1133 Expected
= '''# [Hob.X64]
1141 self
.assertEqual(Result
, Expected
)
1143 def testNormalCase2(self
):
1150 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1151 ObjectList
.append(Object
)
1153 Result
= GenSpecialSections(ObjectList
, 'Hob')
1154 Expected
= '''# [Hob]
1162 self
.assertEqual(Result
, Expected
)
1164 def testNormalCase3(self
):
1166 SupArchList
= ['X64']
1169 Str
= '\nComment Line 1\n\n'
1171 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1172 ObjectList
.append(Object
)
1174 Result
= GenSpecialSections(ObjectList
, 'Hob')
1175 Expected
= '''# [Hob.X64]
1183 self
.assertEqual(Result
, Expected
)
1185 def testNormalCase4(self
):
1187 SupArchList
= ['X64']
1190 Str
= '\nComment Line 1\n'
1192 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1193 ObjectList
.append(Object
)
1195 Result
= GenSpecialSections(ObjectList
, 'Hob')
1196 Expected
= '''# [Hob.X64]
1204 self
.assertEqual(Result
, Expected
)
1206 def testNormalCase5(self
):
1208 SupArchList
= ['X64']
1211 Str
= 'Comment Line 1\n\n'
1213 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1214 ObjectList
.append(Object
)
1216 Result
= GenSpecialSections(ObjectList
, 'Hob')
1217 Expected
= '''# [Hob.X64]
1225 self
.assertEqual(Result
, Expected
)
1227 def testNormalCase6(self
):
1229 SupArchList
= ['X64']
1234 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1235 ObjectList
.append(Object
)
1237 Result
= GenSpecialSections(ObjectList
, 'Hob')
1238 Expected
= '''# [Hob.X64]
1243 self
.assertEqual(Result
, Expected
)
1245 def testNormalCase7(self
):
1247 SupArchList
= ['X64']
1250 Str
= '\nNew Stack HoB'
1253 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1254 ObjectList
.append(Object
)
1256 Result
= GenSpecialSections(ObjectList
, 'Hob')
1257 Expected
= '''# [Hob.X64]
1265 self
.assertEqual(Result
, Expected
)
1267 def testNormalCase8(self
):
1269 SupArchList
= ['X64']
1272 Str
= '\nNew Stack HoB\n\nTail Comment'
1275 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1276 ObjectList
.append(Object
)
1278 Result
= GenSpecialSections(ObjectList
, 'Hob')
1279 Expected
= '''# [Hob.X64]
1289 self
.assertEqual(Result
, Expected
)
1291 def testNormalCase9(self
):
1293 SupArchList
= ['X64']
1299 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1300 ObjectList
.append(Object
)
1302 Result
= GenSpecialSections(ObjectList
, 'Hob')
1303 Expected
= '''# [Hob.X64]
1311 self
.assertEqual(Result
, Expected
)
1313 def testNormalCase10(self
):
1315 SupArchList
= ['X64']
1320 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1321 ObjectList
.append(Object
)
1323 Result
= GenSpecialSections(ObjectList
, 'Hob')
1324 Expected
= '''# [Hob.X64]
1332 self
.assertEqual(Result
, Expected
)
1334 def testNormalCase11(self
):
1336 SupArchList
= ['X64']
1341 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1342 ObjectList
.append(Object
)
1344 Result
= GenSpecialSections(ObjectList
, 'Hob')
1345 Expected
= '''# [Hob.X64]
1353 self
.assertEqual(Result
, Expected
)
1355 def testNormalCase12(self
):
1357 SupArchList
= ['X64']
1362 Object
= self
.ObjectFactory(SupArchList
, Type
, Usage
, Str
)
1363 ObjectList
.append(Object
)
1365 Result
= GenSpecialSections(ObjectList
, 'Hob')
1366 Expected
= '''# [Hob.X64]
1375 self
.assertEqual(Result
, Expected
)
1378 # Test GenGenericCommentF
1380 class GenGenericCommentFTest(unittest
.TestCase
):
1387 def testNormalCase1(self
):
1388 CommentLines
= 'Comment Line 1'
1389 Result
= GenGenericCommentF(CommentLines
)
1390 Expected
= '# Comment Line 1\n'
1391 self
.assertEqual(Result
, Expected
)
1393 def testNormalCase2(self
):
1395 Result
= GenGenericCommentF(CommentLines
)
1397 self
.assertEqual(Result
, Expected
)
1399 def testNormalCase3(self
):
1400 CommentLines
= '\n\n\n'
1401 Result
= GenGenericCommentF(CommentLines
)
1402 Expected
= '#\n#\n#\n'
1403 self
.assertEqual(Result
, Expected
)
1405 def testNormalCase4(self
):
1406 CommentLines
= 'coment line 1\n'
1407 Result
= GenGenericCommentF(CommentLines
)
1408 Expected
= '# coment line 1\n'
1409 self
.assertEqual(Result
, Expected
)
1411 def testNormalCase5(self
):
1412 CommentLines
= 'coment line 1\n coment line 2\n'
1413 Result
= GenGenericCommentF(CommentLines
)
1414 Expected
= '# coment line 1\n# coment line 2\n'
1415 self
.assertEqual(Result
, Expected
)
1417 if __name__
== '__main__':