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