]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/UnitTest/CommentGeneratingUnitTest.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / UnitTest / CommentGeneratingUnitTest.py
1 ## @file
2 # This file contain unit test for CommentParsing
3 #
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 import os
9 import unittest
10
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
24
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
33
34 #
35 # Test _GetHelpStr
36 #
37 class _GetHelpStrTest(unittest.TestCase):
38 def setUp(self):
39 pass
40
41 def tearDown(self):
42 pass
43
44 #
45 # Normal case1: have one help text object with Lang = 'en-US'
46 #
47 def testNormalCase1(self):
48 HelpStr = 'Hello world'
49 HelpTextObj = TextObject()
50 HelpTextObj.SetLang(TAB_LANGUAGE_EN_US)
51 HelpTextObj.SetString(HelpStr)
52
53 HelpTextList = [HelpTextObj]
54 Result = _GetHelpStr(HelpTextList)
55 self.assertEqual(Result, HelpStr)
56
57 #
58 # Normal case2: have two help text object with Lang = 'en-US' and other
59 #
60 def testNormalCase2(self):
61 HelpStr = 'Hello world'
62 HelpTextObj = TextObject()
63 HelpTextObj.SetLang(TAB_LANGUAGE_ENG)
64 HelpTextObj.SetString(HelpStr)
65
66 HelpTextList = [HelpTextObj]
67
68 ExpectedStr = 'Hello world1'
69 HelpTextObj = TextObject()
70 HelpTextObj.SetLang(TAB_LANGUAGE_EN_US)
71 HelpTextObj.SetString(ExpectedStr)
72
73 HelpTextList.append(HelpTextObj)
74
75 Result = _GetHelpStr(HelpTextList)
76 self.assertEqual(Result, ExpectedStr)
77
78 #
79 # Normal case3: have two help text object with Lang = '' and 'eng'
80 #
81 def testNormalCase3(self):
82 HelpStr = 'Hello world'
83 HelpTextObj = TextObject()
84 HelpTextObj.SetLang('')
85 HelpTextObj.SetString(HelpStr)
86
87 HelpTextList = [HelpTextObj]
88
89 ExpectedStr = 'Hello world1'
90 HelpTextObj = TextObject()
91 HelpTextObj.SetLang(TAB_LANGUAGE_ENG)
92 HelpTextObj.SetString(ExpectedStr)
93
94 HelpTextList.append(HelpTextObj)
95
96 Result = _GetHelpStr(HelpTextList)
97 self.assertEqual(Result, ExpectedStr)
98
99 #
100 # Normal case4: have two help text object with Lang = '' and ''
101 #
102 def testNormalCase4(self):
103
104 ExpectedStr = 'Hello world1'
105 HelpTextObj = TextObject()
106 HelpTextObj.SetLang(TAB_LANGUAGE_ENG)
107 HelpTextObj.SetString(ExpectedStr)
108 HelpTextList = [HelpTextObj]
109
110 HelpStr = 'Hello world'
111 HelpTextObj = TextObject()
112 HelpTextObj.SetLang('')
113 HelpTextObj.SetString(HelpStr)
114 HelpTextList.append(HelpTextObj)
115
116 Result = _GetHelpStr(HelpTextList)
117 self.assertEqual(Result, ExpectedStr)
118
119 #
120 # Normal case: have three help text object with Lang = '','en', 'en-US'
121 #
122 def testNormalCase5(self):
123
124 ExpectedStr = 'Hello world1'
125 HelpTextObj = TextObject()
126 HelpTextObj.SetLang(TAB_LANGUAGE_EN_US)
127 HelpTextObj.SetString(ExpectedStr)
128 HelpTextList = [HelpTextObj]
129
130 HelpStr = 'Hello unknown world'
131 HelpTextObj = TextObject()
132 HelpTextObj.SetLang('')
133 HelpTextObj.SetString(HelpStr)
134 HelpTextList.append(HelpTextObj)
135
136 HelpStr = 'Hello mysterious world'
137 HelpTextObj = TextObject()
138 HelpTextObj.SetLang('')
139 HelpTextObj.SetString(HelpStr)
140 HelpTextList.append(HelpTextObj)
141
142 Result = _GetHelpStr(HelpTextList)
143 self.assertEqual(Result, ExpectedStr)
144
145 HelpTextList.sort()
146 self.assertEqual(Result, ExpectedStr)
147
148 HelpTextList.sort(reverse=True)
149 self.assertEqual(Result, ExpectedStr)
150
151
152 #
153 # Test GenGuidSections
154 #
155 class GenGuidSectionsTest(unittest.TestCase):
156 def setUp(self):
157 pass
158
159 def tearDown(self):
160 pass
161
162 #
163 # This is the API to generate Guid Object to help UnitTest
164 #
165 def GuidFactory(self, CName, FFE, Usage, GuidType, VariableName, HelpStr):
166 Guid = GuidObject()
167 Guid.SetCName(CName)
168 Guid.SetFeatureFlag(FFE)
169 Guid.SetGuidTypeList([GuidType])
170 Guid.SetUsage(Usage)
171 Guid.SetVariableName(VariableName)
172
173 HelpTextObj = TextObject()
174 HelpTextObj.SetLang('')
175 HelpTextObj.SetString(HelpStr)
176 Guid.SetHelpTextList([HelpTextObj])
177
178 return Guid
179
180 #
181 # Normal case: have two GuidObject
182 #
183 def testNormalCase1(self):
184 GuidList = []
185
186 CName = 'Guid1'
187 FFE = 'FFE1'
188 Usage = 'PRODUCES'
189 GuidType = 'Event'
190 VariableName = ''
191 HelpStr = 'Usage comment line 1'
192 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
193 VariableName, HelpStr)
194 GuidList.append(Guid1)
195
196 CName = 'Guid1'
197 FFE = 'FFE1'
198 Usage = 'CONSUMES'
199 GuidType = 'Variable'
200 VariableName = ''
201 HelpStr = 'Usage comment line 2'
202 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
203 VariableName, HelpStr)
204 GuidList.append(Guid1)
205
206 Result = GenGuidSections(GuidList)
207 Expected = '''[Guids]
208 ## PRODUCES ## Event # Usage comment line 1
209 ## CONSUMES ## Variable: # Usage comment line 2
210 Guid1|FFE1'''
211 self.assertEqual(Result.strip(), Expected)
212
213 #
214 # Normal case: have two GuidObject
215 #
216 def testNormalCase2(self):
217 GuidList = []
218
219 CName = 'Guid1'
220 FFE = 'FFE1'
221 Usage = 'PRODUCES'
222 GuidType = 'Event'
223 VariableName = ''
224 HelpStr = 'Usage comment line 1'
225 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
226 VariableName, HelpStr)
227 GuidList.append(Guid1)
228
229 CName = 'Guid1'
230 FFE = 'FFE1'
231 Usage = 'UNDEFINED'
232 GuidType = 'UNDEFINED'
233 VariableName = ''
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)
238
239 Result = GenGuidSections(GuidList)
240 Expected = '''[Guids]
241 ## PRODUCES ## Event # Usage comment line 1
242 # Generic comment line 1
243 # Generic comment line 2
244 Guid1|FFE1'''
245
246 self.assertEqual(Result.strip(), Expected)
247
248 #
249 # Normal case: have two GuidObject, one help goes to generic help,
250 # the other go into usage comment
251 #
252 def testNormalCase3(self):
253 GuidList = []
254
255 CName = 'Guid1'
256 FFE = 'FFE1'
257 Usage = 'UNDEFINED'
258 GuidType = 'UNDEFINED'
259 VariableName = ''
260 HelpStr = 'Generic comment'
261 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
262 VariableName, HelpStr)
263 GuidList.append(Guid1)
264
265 CName = 'Guid1'
266 FFE = 'FFE1'
267 Usage = 'PRODUCES'
268 GuidType = 'Event'
269 VariableName = ''
270 HelpStr = 'Usage comment line 1'
271 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
272 VariableName, HelpStr)
273 GuidList.append(Guid1)
274
275 Result = GenGuidSections(GuidList)
276 Expected = '''[Guids]
277 # Generic comment
278 ## PRODUCES ## Event # Usage comment line 1
279 Guid1|FFE1'''
280
281 self.assertEqual(Result.strip(), Expected)
282
283 #
284 # Normal case: have one GuidObject, generic comment multiple lines
285 #
286 def testNormalCase5(self):
287 GuidList = []
288
289 CName = 'Guid1'
290 FFE = 'FFE1'
291 Usage = 'UNDEFINED'
292 GuidType = 'UNDEFINED'
293 VariableName = ''
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)
298
299 Result = GenGuidSections(GuidList)
300 Expected = '''[Guids]
301 # Generic comment line1
302 # generic comment line 2
303 Guid1|FFE1'''
304
305 self.assertEqual(Result.strip(), Expected)
306
307 #
308 # Normal case: have one GuidObject, usage comment multiple lines
309 #
310 def testNormalCase6(self):
311 GuidList = []
312
313 CName = 'Guid1'
314 FFE = 'FFE1'
315 Usage = 'PRODUCES'
316 GuidType = 'Event'
317 VariableName = ''
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)
322
323 Result = GenGuidSections(GuidList)
324 Expected = '''[Guids]
325 Guid1|FFE1 ## PRODUCES ## Event # Usage comment line 1 Usage comment line 2
326 '''
327 self.assertEqual(Result.strip(), Expected.strip())
328
329 #
330 # Normal case: have one GuidObject, usage comment one line
331 #
332 def testNormalCase7(self):
333 GuidList = []
334
335 CName = 'Guid1'
336 FFE = 'FFE1'
337 Usage = 'UNDEFINED'
338 GuidType = 'UNDEFINED'
339 VariableName = ''
340 HelpStr = 'Usage comment line 1'
341 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
342 VariableName, HelpStr)
343 GuidList.append(Guid1)
344
345 Result = GenGuidSections(GuidList)
346 Expected = '''[Guids]
347 Guid1|FFE1 # Usage comment line 1
348 '''
349 self.assertEqual(Result.strip(), Expected.strip())
350
351 #
352 # Normal case: have two GuidObject
353 #
354 def testNormalCase8(self):
355 GuidList = []
356
357 CName = 'Guid1'
358 FFE = 'FFE1'
359 Usage = 'PRODUCES'
360 GuidType = 'Event'
361 VariableName = ''
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)
366
367 CName = 'Guid1'
368 FFE = 'FFE1'
369 Usage = 'PRODUCES'
370 GuidType = 'Event'
371 VariableName = ''
372 HelpStr = 'Usage comment line 3'
373 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
374 VariableName, HelpStr)
375 GuidList.append(Guid1)
376
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
381 Guid1|FFE1
382 '''
383 self.assertEqual(Result.strip(), Expected.strip())
384
385 #
386 # Normal case: have no GuidObject
387 #
388 def testNormalCase9(self):
389 GuidList = []
390
391 Result = GenGuidSections(GuidList)
392 Expected = ''
393 self.assertEqual(Result.strip(), Expected.strip())
394
395 #
396 # Normal case: have one GuidObject with no comment generated
397 #
398 def testNormalCase10(self):
399 GuidList = []
400
401 CName = 'Guid1'
402 FFE = 'FFE1'
403 Usage = 'UNDEFINED'
404 GuidType = 'UNDEFINED'
405 VariableName = ''
406 HelpStr = ''
407 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
408 VariableName, HelpStr)
409 GuidList.append(Guid1)
410
411 Result = GenGuidSections(GuidList)
412 Expected = '''[Guids]
413 Guid1|FFE1
414 '''
415 self.assertEqual(Result.strip(), Expected.strip())
416
417 #
418 # Normal case: have three GuidObject
419 #
420 def testNormalCase11(self):
421 GuidList = []
422
423 CName = 'Guid1'
424 FFE = 'FFE1'
425 Usage = 'UNDEFINED'
426 GuidType = 'UNDEFINED'
427 VariableName = ''
428 HelpStr = 'general comment line 1'
429 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
430 VariableName, HelpStr)
431 GuidList.append(Guid1)
432
433 CName = 'Guid1'
434 FFE = 'FFE1'
435 Usage = 'PRODUCES'
436 GuidType = 'Event'
437 VariableName = ''
438 HelpStr = 'Usage comment line 3'
439 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
440 VariableName, HelpStr)
441 GuidList.append(Guid1)
442
443 CName = 'Guid1'
444 FFE = 'FFE1'
445 Usage = 'UNDEFINED'
446 GuidType = 'UNDEFINED'
447 VariableName = ''
448 HelpStr = 'general comment line 2'
449 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
450 VariableName, HelpStr)
451 GuidList.append(Guid1)
452
453 Result = GenGuidSections(GuidList)
454 Expected = '''[Guids]
455 # general comment line 1
456 ## PRODUCES ## Event # Usage comment line 3
457 # general comment line 2
458 Guid1|FFE1
459 '''
460 self.assertEqual(Result.strip(), Expected.strip())
461
462 #
463 # Normal case: have three GuidObject, with Usage/Type and no help
464 #
465 def testNormalCase12(self):
466 GuidList = []
467
468 CName = 'Guid1'
469 FFE = 'FFE1'
470 Usage = 'PRODUCES'
471 GuidType = 'GUID'
472 VariableName = ''
473 HelpStr = ''
474 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
475 VariableName, HelpStr)
476 GuidList.append(Guid1)
477
478 CName = 'Guid1'
479 FFE = 'FFE1'
480 Usage = 'PRODUCES'
481 GuidType = 'Event'
482 VariableName = ''
483 HelpStr = ''
484 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
485 VariableName, HelpStr)
486 GuidList.append(Guid1)
487
488 CName = 'Guid1'
489 FFE = 'FFE1'
490 Usage = 'CONSUMES'
491 GuidType = 'Event'
492 VariableName = ''
493 HelpStr = ''
494 Guid1 = self.GuidFactory(CName, FFE, Usage, GuidType,
495 VariableName, HelpStr)
496 GuidList.append(Guid1)
497
498 Result = GenGuidSections(GuidList)
499 Expected = '''[Guids]
500 ## PRODUCES ## GUID
501 ## PRODUCES ## Event
502 ## CONSUMES ## Event
503 Guid1|FFE1
504 '''
505 self.assertEqual(Result.strip(), Expected.strip())
506
507 #
508 # Test GenProtocolPPiSections
509 #
510 class GenProtocolPPiSectionsTest(unittest.TestCase):
511 def setUp(self):
512 pass
513
514 def tearDown(self):
515 pass
516
517 #
518 # This is the API to generate Protocol/Ppi Object to help UnitTest
519 #
520 def ObjectFactory(self, CName, FFE, Usage, Notify, HelpStr, IsProtocol):
521 if IsProtocol:
522 Object = ProtocolObject()
523 else:
524 Object = PpiObject()
525
526 Object.SetCName(CName)
527 Object.SetFeatureFlag(FFE)
528 Object.SetUsage(Usage)
529 Object.SetNotify(Notify)
530
531 HelpTextObj = TextObject()
532 HelpTextObj.SetLang('')
533 HelpTextObj.SetString(HelpStr)
534 Object.SetHelpTextList([HelpTextObj])
535
536 return Object
537
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
551
552 def testNormalCase1(self):
553 ObjectList = []
554
555 CName = 'Guid1'
556 FFE = 'FFE1'
557
558 Usage = 'UNDEFINED'
559 Notify = True
560 HelpStr = 'Help'
561 IsProtocol = True
562 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
563 HelpStr, IsProtocol)
564 ObjectList.append(Object)
565
566
567 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
568 Expected = '''[Protocols]
569 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
570 self.assertEqual(Result.strip(), Expected)
571
572 IsProtocol = False
573 ObjectList = []
574 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
575 HelpStr, IsProtocol)
576 ObjectList.append(Object)
577
578
579 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
580 Expected = '''[Ppis]
581 Guid1|FFE1 ## UNDEFINED ## NOTIFY # Help'''
582 self.assertEqual(Result.strip(), Expected)
583
584 def testNormalCase2(self):
585 ObjectList = []
586
587 CName = 'Guid1'
588 FFE = 'FFE1'
589
590 Usage = 'UNDEFINED'
591 Notify = True
592 HelpStr = ''
593 IsProtocol = True
594 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
595 HelpStr, IsProtocol)
596 ObjectList.append(Object)
597
598
599 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
600 Expected = '''[Protocols]
601 Guid1|FFE1 ## UNDEFINED ## NOTIFY'''
602 self.assertEqual(Result.strip(), Expected)
603
604 def testNormalCase3(self):
605 ObjectList = []
606
607 CName = 'Guid1'
608 FFE = 'FFE1'
609
610 Usage = 'UNDEFINED'
611 Notify = False
612 HelpStr = 'Help'
613 IsProtocol = True
614 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
615 HelpStr, IsProtocol)
616 ObjectList.append(Object)
617
618
619 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
620 Expected = '''[Protocols]
621 Guid1|FFE1 ## UNDEFINED # Help'''
622 self.assertEqual(Result.strip(), Expected)
623
624 def testNormalCase4(self):
625 ObjectList = []
626
627 CName = 'Guid1'
628 FFE = 'FFE1'
629
630 Usage = 'UNDEFINED'
631 Notify = False
632 HelpStr = ''
633 IsProtocol = True
634 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
635 HelpStr, IsProtocol)
636 ObjectList.append(Object)
637
638
639 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
640 Expected = '''[Protocols]
641 Guid1|FFE1 ## UNDEFINED'''
642 self.assertEqual(Result.strip(), Expected)
643
644 def testNormalCase5(self):
645 ObjectList = []
646
647 CName = 'Guid1'
648 FFE = 'FFE1'
649
650 Usage = 'UNDEFINED'
651 Notify = ''
652 HelpStr = 'Help'
653 IsProtocol = True
654 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
655 HelpStr, IsProtocol)
656 ObjectList.append(Object)
657
658
659 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
660 Expected = '''[Protocols]
661 Guid1|FFE1 # Help'''
662 self.assertEqual(Result.strip(), Expected)
663
664 def testNormalCase6(self):
665 ObjectList = []
666
667 CName = 'Guid1'
668 FFE = 'FFE1'
669
670 Usage = 'UNDEFINED'
671 Notify = ''
672 HelpStr = ''
673 IsProtocol = True
674 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
675 HelpStr, IsProtocol)
676 ObjectList.append(Object)
677
678
679 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
680 Expected = '''[Protocols]
681 Guid1|FFE1'''
682 self.assertEqual(Result.strip(), Expected)
683
684 def testNormalCase7(self):
685 ObjectList = []
686
687 CName = 'Guid1'
688 FFE = 'FFE1'
689
690 Usage = 'PRODUCES'
691 Notify = True
692 HelpStr = 'Help'
693 IsProtocol = True
694 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
695 HelpStr, IsProtocol)
696 ObjectList.append(Object)
697
698
699 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
700 Expected = '''[Protocols]
701 Guid1|FFE1 ## PRODUCES ## NOTIFY # Help'''
702 self.assertEqual(Result.strip(), Expected)
703
704 def testNormalCase8(self):
705 ObjectList = []
706
707 CName = 'Guid1'
708 FFE = 'FFE1'
709
710 Usage = 'PRODUCES'
711 Notify = True
712 HelpStr = ''
713 IsProtocol = True
714 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
715 HelpStr, IsProtocol)
716 ObjectList.append(Object)
717
718
719 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
720 Expected = '''[Protocols]
721 Guid1|FFE1 ## PRODUCES ## NOTIFY'''
722 self.assertEqual(Result.strip(), Expected)
723
724 def testNormalCase9(self):
725 ObjectList = []
726
727 CName = 'Guid1'
728 FFE = 'FFE1'
729
730 Usage = 'PRODUCES'
731 Notify = False
732 HelpStr = 'Help'
733 IsProtocol = True
734 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
735 HelpStr, IsProtocol)
736 ObjectList.append(Object)
737
738
739 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
740 Expected = '''[Protocols]
741 Guid1|FFE1 ## PRODUCES # Help'''
742 self.assertEqual(Result.strip(), Expected)
743
744 def testNormalCaseA(self):
745 ObjectList = []
746
747 CName = 'Guid1'
748 FFE = 'FFE1'
749
750 Usage = 'PRODUCES'
751 Notify = False
752 HelpStr = ''
753 IsProtocol = True
754 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
755 HelpStr, IsProtocol)
756 ObjectList.append(Object)
757
758
759 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
760 Expected = '''[Protocols]
761 Guid1|FFE1 ## PRODUCES'''
762 self.assertEqual(Result.strip(), Expected)
763
764 def testNormalCaseB(self):
765 ObjectList = []
766
767 CName = 'Guid1'
768 FFE = 'FFE1'
769
770 Usage = 'PRODUCES'
771 Notify = ''
772 HelpStr = 'Help'
773 IsProtocol = True
774 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
775 HelpStr, IsProtocol)
776 ObjectList.append(Object)
777
778
779 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
780 Expected = '''[Protocols]
781 Guid1|FFE1 ## PRODUCES # Help'''
782 self.assertEqual(Result.strip(), Expected)
783
784 def testNormalCaseC(self):
785 ObjectList = []
786
787 CName = 'Guid1'
788 FFE = 'FFE1'
789
790 Usage = 'PRODUCES'
791 Notify = ''
792 HelpStr = ''
793 IsProtocol = True
794 Object = self.ObjectFactory(CName, FFE, Usage, Notify,
795 HelpStr, IsProtocol)
796 ObjectList.append(Object)
797
798
799 Result = GenProtocolPPiSections(ObjectList, IsProtocol)
800 Expected = '''[Protocols]
801 Guid1|FFE1 ## PRODUCES'''
802 self.assertEqual(Result.strip(), Expected)
803
804 #
805 # Test GenPcdSections
806 #
807 class GenPcdSectionsTest(unittest.TestCase):
808 def setUp(self):
809 pass
810
811 def tearDown(self):
812 pass
813
814 #
815 # This is the API to generate Pcd Object to help UnitTest
816 #
817 def ObjectFactory(self, ItemType, TSCName, CName, DValue, FFE, Usage, Str):
818 Object = PcdObject()
819 HelpStr = Str
820
821 Object.SetItemType(ItemType)
822 Object.SetTokenSpaceGuidCName(TSCName)
823 Object.SetCName(CName)
824 Object.SetDefaultValue(DValue)
825 Object.SetFeatureFlag(FFE)
826 Object.SetValidUsage(Usage)
827
828 HelpTextObj = TextObject()
829 HelpTextObj.SetLang('')
830 HelpTextObj.SetString(HelpStr)
831 Object.SetHelpTextList([HelpTextObj])
832
833 return Object
834
835
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
841
842 def testNormalCase1(self):
843 ObjectList = []
844 ItemType = 'Pcd'
845 TSCName = 'TSCName'
846 CName = 'CName'
847 DValue = 'DValue'
848 FFE = 'FFE'
849
850 Usage = 'UNDEFINED'
851 Str = 'Help'
852
853 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
854 Usage, Str)
855 ObjectList.append(Object)
856
857 Result = GenPcdSections(ObjectList)
858 Expected = \
859 '[Pcd]\n' + \
860 'TSCName.CName|DValue|FFE # Help'
861 self.assertEqual(Result.strip(), Expected)
862
863 def testNormalCase2(self):
864 ObjectList = []
865 ItemType = 'Pcd'
866 TSCName = 'TSCName'
867 CName = 'CName'
868 DValue = 'DValue'
869 FFE = 'FFE'
870
871 Usage = 'UNDEFINED'
872 Str = ''
873
874 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
875 Usage, Str)
876 ObjectList.append(Object)
877
878 Result = GenPcdSections(ObjectList)
879 Expected = '[Pcd]\nTSCName.CName|DValue|FFE'
880 self.assertEqual(Result.strip(), Expected)
881
882 def testNormalCase3(self):
883 ObjectList = []
884 ItemType = 'Pcd'
885 TSCName = 'TSCName'
886 CName = 'CName'
887 DValue = 'DValue'
888 FFE = 'FFE'
889
890 Usage = 'CONSUMES'
891 Str = 'Help'
892
893 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
894 Usage, Str)
895 ObjectList.append(Object)
896
897 Result = GenPcdSections(ObjectList)
898 Expected = '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES # Help'
899 self.assertEqual(Result.strip(), Expected)
900
901 def testNormalCase4(self):
902 ObjectList = []
903 ItemType = 'Pcd'
904 TSCName = 'TSCName'
905 CName = 'CName'
906 DValue = 'DValue'
907 FFE = 'FFE'
908
909 Usage = 'CONSUMES'
910 Str = ''
911
912 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
913 Usage, Str)
914 ObjectList.append(Object)
915
916 Result = GenPcdSections(ObjectList)
917 Expected = '[Pcd]\nTSCName.CName|DValue|FFE ## CONSUMES'
918 self.assertEqual(Result.strip(), Expected)
919
920 #
921 # multiple lines for normal usage
922 #
923 def testNormalCase5(self):
924 ObjectList = []
925 ItemType = 'Pcd'
926 TSCName = 'TSCName'
927 CName = 'CName'
928 DValue = 'DValue'
929 FFE = 'FFE'
930
931 Usage = 'CONSUMES'
932 Str = 'commment line 1\ncomment line 2'
933 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
934 Usage, Str)
935 ObjectList.append(Object)
936
937 Result = GenPcdSections(ObjectList)
938 Expected = '''[Pcd]
939 TSCName.CName|DValue|FFE ## CONSUMES # commment line 1 comment line 2'''
940 self.assertEqual(Result.strip(), Expected)
941
942 #
943 # multiple lines for UNDEFINED usage
944 #
945 def testNormalCase6(self):
946 ObjectList = []
947 ItemType = 'Pcd'
948 TSCName = 'TSCName'
949 CName = 'CName'
950 DValue = 'DValue'
951 FFE = 'FFE'
952
953 Usage = 'UNDEFINED'
954 Str = 'commment line 1\ncomment line 2'
955 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
956 Usage, Str)
957 ObjectList.append(Object)
958
959 Usage = 'UNDEFINED'
960 Str = 'commment line 3'
961 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
962 Usage, Str)
963 ObjectList.append(Object)
964
965 Result = GenPcdSections(ObjectList)
966 Expected = '''[Pcd]
967 # commment line 1
968 # comment line 2
969 # commment line 3
970 TSCName.CName|DValue|FFE'''
971 self.assertEqual(Result.strip(), Expected)
972
973 #
974 # multiple lines for UNDEFINED and normal usage
975 #
976 def testNormalCase7(self):
977 ObjectList = []
978 ItemType = 'Pcd'
979 TSCName = 'TSCName'
980 CName = 'CName'
981 DValue = 'DValue'
982 FFE = 'FFE'
983
984 Usage = 'UNDEFINED'
985 Str = 'commment line 1\ncomment line 2'
986 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
987 Usage, Str)
988 ObjectList.append(Object)
989
990 Usage = 'CONSUMES'
991 Str = 'Foo'
992 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
993 Usage, Str)
994 ObjectList.append(Object)
995
996 Usage = 'UNDEFINED'
997 Str = 'commment line 3'
998 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
999 Usage, Str)
1000 ObjectList.append(Object)
1001
1002 Result = GenPcdSections(ObjectList)
1003 Expected = '''[Pcd]
1004 # commment line 1
1005 # comment line 2
1006 ## CONSUMES # Foo
1007 # commment line 3
1008 TSCName.CName|DValue|FFE'''
1009 self.assertEqual(Result.strip(), Expected)
1010
1011 # Usage Help INF Comment
1012 # CONSUMES Present # Help (keep <EOL> and insert '#' at beginning of each new line)
1013 # CONSUMES Not Present <empty>
1014
1015 #
1016 # TAB_INF_FEATURE_PCD
1017 #
1018 def testNormalCase8(self):
1019 ObjectList = []
1020 ItemType = TAB_INF_FEATURE_PCD
1021 TSCName = 'TSCName'
1022 CName = 'CName'
1023 DValue = 'DValue'
1024 FFE = 'FFE'
1025
1026 Usage = 'CONSUMES'
1027 Str = 'commment line 1\ncomment line 2'
1028 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
1029 Usage, Str)
1030 ObjectList.append(Object)
1031
1032 Result = GenPcdSections(ObjectList)
1033 Expected = '''[FeaturePcd]
1034 # commment line 1
1035 # comment line 2
1036 TSCName.CName|DValue|FFE'''
1037 self.assertEqual(Result.strip(), Expected)
1038
1039 #
1040 # TAB_INF_FEATURE_PCD
1041 #
1042 def testNormalCase9(self):
1043 ObjectList = []
1044 ItemType = TAB_INF_FEATURE_PCD
1045 TSCName = 'TSCName'
1046 CName = 'CName'
1047 DValue = 'DValue'
1048 FFE = 'FFE'
1049
1050 Usage = 'CONSUMES'
1051 Str = ''
1052 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
1053 Usage, Str)
1054 ObjectList.append(Object)
1055
1056 Result = GenPcdSections(ObjectList)
1057 Expected = '''[FeaturePcd]
1058 TSCName.CName|DValue|FFE'''
1059 self.assertEqual(Result.strip(), Expected)
1060
1061 #
1062 # TAB_INF_FEATURE_PCD
1063 #
1064 def testNormalCase10(self):
1065 ObjectList = []
1066 ItemType = TAB_INF_FEATURE_PCD
1067 TSCName = 'TSCName'
1068 CName = 'CName'
1069 DValue = 'DValue'
1070 FFE = 'FFE'
1071
1072 Usage = 'PRODUCES'
1073 Str = 'commment line 1\ncomment line 2'
1074 Object = self.ObjectFactory(ItemType, TSCName, CName, DValue, FFE,
1075 Usage, Str)
1076 ObjectList.append(Object)
1077
1078 Result = GenPcdSections(ObjectList)
1079 Expected = '''
1080
1081 [FeaturePcd]
1082 # commment line 1
1083 # comment line 2
1084 TSCName.CName|DValue|FFE
1085 '''
1086 self.assertEqual(Result, Expected)
1087
1088
1089 #
1090 # Test GenSpecialSections of Hob
1091 #
1092 class GenHobSectionsTest(unittest.TestCase):
1093 def setUp(self):
1094 pass
1095
1096 def tearDown(self):
1097 pass
1098
1099 #
1100 # This is the API to generate Event Object to help UnitTest
1101 #
1102 def ObjectFactory(self, SupArchList, Type, Usage, Str):
1103 Object = HobObject()
1104 HelpStr = Str
1105
1106 Object.SetHobType(Type)
1107 Object.SetUsage(Usage)
1108 Object.SetSupArchList(SupArchList)
1109
1110 HelpTextObj = TextObject()
1111 HelpTextObj.SetLang('')
1112 HelpTextObj.SetString(HelpStr)
1113 Object.SetHelpTextList([HelpTextObj])
1114
1115 return Object
1116
1117 def testNormalCase1(self):
1118 ObjectList = []
1119 SupArchList = ['X64']
1120 Type = 'Foo'
1121 Usage = 'UNDEFINED'
1122 Str = 'Help'
1123
1124 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1125 ObjectList.append(Object)
1126
1127 Result = GenSpecialSections(ObjectList, 'Hob')
1128 Expected = '''# [Hob.X64]
1129 # ##
1130 # # Help
1131 # #
1132 # Foo ## UNDEFINED
1133 #
1134 #
1135 '''
1136 self.assertEqual(Result, Expected)
1137
1138 def testNormalCase2(self):
1139 ObjectList = []
1140 SupArchList = []
1141 Type = 'Foo'
1142 Usage = 'UNDEFINED'
1143 Str = 'Help'
1144
1145 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1146 ObjectList.append(Object)
1147
1148 Result = GenSpecialSections(ObjectList, 'Hob')
1149 Expected = '''# [Hob]
1150 # ##
1151 # # Help
1152 # #
1153 # Foo ## UNDEFINED
1154 #
1155 #
1156 '''
1157 self.assertEqual(Result, Expected)
1158
1159 def testNormalCase3(self):
1160 ObjectList = []
1161 SupArchList = ['X64']
1162 Type = 'Foo'
1163 Usage = 'UNDEFINED'
1164 Str = '\nComment Line 1\n\n'
1165
1166 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1167 ObjectList.append(Object)
1168
1169 Result = GenSpecialSections(ObjectList, 'Hob')
1170 Expected = '''# [Hob.X64]
1171 # ##
1172 # # Comment Line 1
1173 # #
1174 # Foo ## UNDEFINED
1175 #
1176 #
1177 '''
1178 self.assertEqual(Result, Expected)
1179
1180 def testNormalCase4(self):
1181 ObjectList = []
1182 SupArchList = ['X64']
1183 Type = 'Foo'
1184 Usage = 'UNDEFINED'
1185 Str = '\nComment Line 1\n'
1186
1187 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1188 ObjectList.append(Object)
1189
1190 Result = GenSpecialSections(ObjectList, 'Hob')
1191 Expected = '''# [Hob.X64]
1192 # ##
1193 # # Comment Line 1
1194 # #
1195 # Foo ## UNDEFINED
1196 #
1197 #
1198 '''
1199 self.assertEqual(Result, Expected)
1200
1201 def testNormalCase5(self):
1202 ObjectList = []
1203 SupArchList = ['X64']
1204 Type = 'Foo'
1205 Usage = 'UNDEFINED'
1206 Str = 'Comment Line 1\n\n'
1207
1208 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1209 ObjectList.append(Object)
1210
1211 Result = GenSpecialSections(ObjectList, 'Hob')
1212 Expected = '''# [Hob.X64]
1213 # ##
1214 # # Comment Line 1
1215 # #
1216 # Foo ## UNDEFINED
1217 #
1218 #
1219 '''
1220 self.assertEqual(Result, Expected)
1221
1222 def testNormalCase6(self):
1223 ObjectList = []
1224 SupArchList = ['X64']
1225 Type = 'Foo'
1226 Usage = 'UNDEFINED'
1227 Str = ''
1228
1229 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1230 ObjectList.append(Object)
1231
1232 Result = GenSpecialSections(ObjectList, 'Hob')
1233 Expected = '''# [Hob.X64]
1234 # Foo ## UNDEFINED
1235 #
1236 #
1237 '''
1238 self.assertEqual(Result, Expected)
1239
1240 def testNormalCase7(self):
1241 ObjectList = []
1242 SupArchList = ['X64']
1243 Type = 'Foo'
1244 Usage = 'UNDEFINED'
1245 Str = '\nNew Stack HoB'
1246
1247
1248 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1249 ObjectList.append(Object)
1250
1251 Result = GenSpecialSections(ObjectList, 'Hob')
1252 Expected = '''# [Hob.X64]
1253 # ##
1254 # # New Stack HoB
1255 # #
1256 # Foo ## UNDEFINED
1257 #
1258 #
1259 '''
1260 self.assertEqual(Result, Expected)
1261
1262 def testNormalCase8(self):
1263 ObjectList = []
1264 SupArchList = ['X64']
1265 Type = 'Foo'
1266 Usage = 'UNDEFINED'
1267 Str = '\nNew Stack HoB\n\nTail Comment'
1268
1269
1270 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1271 ObjectList.append(Object)
1272
1273 Result = GenSpecialSections(ObjectList, 'Hob')
1274 Expected = '''# [Hob.X64]
1275 # ##
1276 # # New Stack HoB
1277 # #
1278 # # Tail Comment
1279 # #
1280 # Foo ## UNDEFINED
1281 #
1282 #
1283 '''
1284 self.assertEqual(Result, Expected)
1285
1286 def testNormalCase9(self):
1287 ObjectList = []
1288 SupArchList = ['X64']
1289 Type = 'Foo'
1290 Usage = 'UNDEFINED'
1291 Str = '\n\n'
1292
1293
1294 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1295 ObjectList.append(Object)
1296
1297 Result = GenSpecialSections(ObjectList, 'Hob')
1298 Expected = '''# [Hob.X64]
1299 # ##
1300 # #
1301 # #
1302 # Foo ## UNDEFINED
1303 #
1304 #
1305 '''
1306 self.assertEqual(Result, Expected)
1307
1308 def testNormalCase10(self):
1309 ObjectList = []
1310 SupArchList = ['X64']
1311 Type = 'Foo'
1312 Usage = 'UNDEFINED'
1313 Str = '\n'
1314
1315 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1316 ObjectList.append(Object)
1317
1318 Result = GenSpecialSections(ObjectList, 'Hob')
1319 Expected = '''# [Hob.X64]
1320 # ##
1321 # #
1322 # #
1323 # Foo ## UNDEFINED
1324 #
1325 #
1326 '''
1327 self.assertEqual(Result, Expected)
1328
1329 def testNormalCase11(self):
1330 ObjectList = []
1331 SupArchList = ['X64']
1332 Type = 'Foo'
1333 Usage = 'UNDEFINED'
1334 Str = '\n\n\n'
1335
1336 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1337 ObjectList.append(Object)
1338
1339 Result = GenSpecialSections(ObjectList, 'Hob')
1340 Expected = '''# [Hob.X64]
1341 # ##
1342 # #
1343 # #
1344 # Foo ## UNDEFINED
1345 #
1346 #
1347 '''
1348 self.assertEqual(Result, Expected)
1349
1350 def testNormalCase12(self):
1351 ObjectList = []
1352 SupArchList = ['X64']
1353 Type = 'Foo'
1354 Usage = 'UNDEFINED'
1355 Str = '\n\n\n\n'
1356
1357 Object = self.ObjectFactory(SupArchList, Type, Usage, Str)
1358 ObjectList.append(Object)
1359
1360 Result = GenSpecialSections(ObjectList, 'Hob')
1361 Expected = '''# [Hob.X64]
1362 # ##
1363 # #
1364 # #
1365 # #
1366 # Foo ## UNDEFINED
1367 #
1368 #
1369 '''
1370 self.assertEqual(Result, Expected)
1371
1372 #
1373 # Test GenGenericCommentF
1374 #
1375 class GenGenericCommentFTest(unittest.TestCase):
1376 def setUp(self):
1377 pass
1378
1379 def tearDown(self):
1380 pass
1381
1382 def testNormalCase1(self):
1383 CommentLines = 'Comment Line 1'
1384 Result = GenGenericCommentF(CommentLines)
1385 Expected = '# Comment Line 1\n'
1386 self.assertEqual(Result, Expected)
1387
1388 def testNormalCase2(self):
1389 CommentLines = '\n'
1390 Result = GenGenericCommentF(CommentLines)
1391 Expected = '#\n'
1392 self.assertEqual(Result, Expected)
1393
1394 def testNormalCase3(self):
1395 CommentLines = '\n\n\n'
1396 Result = GenGenericCommentF(CommentLines)
1397 Expected = '#\n#\n#\n'
1398 self.assertEqual(Result, Expected)
1399
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)
1405
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)
1411
1412 if __name__ == '__main__':
1413 Logger.Initialize()
1414 unittest.main()