]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/UnitTest/CommentParsingUnitTest.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / UPT / UnitTest / CommentParsingUnitTest.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 # 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 unittest
15
16 import Logger.Log as Logger
17 from Library.CommentParsing import ParseHeaderCommentSection, \
18 ParseGenericComment, \
19 ParseDecPcdGenericComment, \
20 ParseDecPcdTailComment
21 from Library.CommentParsing import _IsCopyrightLine
22 from Library.StringUtils import GetSplitValueList
23 from Library.DataType import TAB_SPACE_SPLIT
24 from Library.DataType import TAB_LANGUAGE_EN_US
25
26 #
27 # Test ParseHeaderCommentSection
28 #
29 class ParseHeaderCommentSectionTest(unittest.TestCase):
30 def setUp(self):
31 pass
32
33 def tearDown(self):
34 pass
35
36 #
37 # Normal case1: have license/copyright/license above @file
38 #
39 def testNormalCase1(self):
40 TestCommentLines1 = \
41 '''# License1
42 # License2
43 #
44 ## @file
45 # example abstract
46 #
47 # example description
48 #
49 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
50 #
51 # License3
52 #'''
53
54 CommentList = GetSplitValueList(TestCommentLines1, "\n")
55 LineNum = 0
56 TestCommentLinesList = []
57 for Comment in CommentList:
58 LineNum += 1
59 TestCommentLinesList.append((Comment, LineNum))
60
61 Abstract, Description, Copyright, License = \
62 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
63
64 ExpectedAbstract = 'example abstract'
65 self.assertEqual(Abstract, ExpectedAbstract)
66
67 ExpectedDescription = 'example description'
68 self.assertEqual(Description, ExpectedDescription)
69
70 ExpectedCopyright = \
71 'Copyright (c) 2007 - 2010,'\
72 ' Intel Corporation. All rights reserved.<BR>'
73 self.assertEqual(Copyright, ExpectedCopyright)
74
75 ExpectedLicense = 'License1\nLicense2\n\nLicense3'
76 self.assertEqual(License, ExpectedLicense)
77
78 #
79 # Normal case2: have license/copyright above @file, but no copyright after
80 #
81 def testNormalCase2(self):
82 TestCommentLines2 = \
83 ''' # License1
84 # License2
85 #
86 ## @file
87 # example abstract
88 #
89 # example description
90 #
91 #Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
92 #
93 ##'''
94
95 CommentList = GetSplitValueList(TestCommentLines2, "\n")
96 LineNum = 0
97 TestCommentLinesList = []
98 for Comment in CommentList:
99 LineNum += 1
100 TestCommentLinesList.append((Comment, LineNum))
101
102 Abstract, Description, Copyright, License = \
103 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
104
105 ExpectedAbstract = 'example abstract'
106 self.assertEqual(Abstract, ExpectedAbstract)
107
108 ExpectedDescription = 'example description'
109 self.assertEqual(Description, ExpectedDescription)
110
111 ExpectedCopyright = \
112 'Copyright (c) 2007 - 2018, Intel Corporation.'\
113 ' All rights reserved.<BR>'
114 self.assertEqual(Copyright, ExpectedCopyright)
115
116 ExpectedLicense = 'License1\nLicense2'
117 self.assertEqual(License, ExpectedLicense)
118
119
120 #
121 # Normal case2: have license/copyright/license above @file,
122 # but no abstract/description
123 #
124 def testNormalCase3(self):
125 TestCommentLines3 = \
126 ''' # License1
127 # License2
128 #
129 ## @file
130 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
131 #
132 # License3 Line1
133 # License3 Line2
134 ##'''
135
136 CommentList = GetSplitValueList(TestCommentLines3, "\n")
137 LineNum = 0
138 TestCommentLinesList = []
139 for Comment in CommentList:
140 LineNum += 1
141 TestCommentLinesList.append((Comment, LineNum))
142
143 Abstract, Description, Copyright, License = \
144 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
145
146 ExpectedAbstract = ''
147 self.assertEqual(Abstract, ExpectedAbstract)
148
149 ExpectedDescription = ''
150 self.assertEqual(Description, ExpectedDescription)
151
152 ExpectedCopyright = \
153 'Copyright (c) 2007 - 2010,'\
154 ' Intel Corporation. All rights reserved.<BR>'
155 self.assertEqual(Copyright, ExpectedCopyright)
156
157 ExpectedLicense = \
158 'License1\n' \
159 'License2\n\n' \
160 'License3 Line1\n' \
161 'License3 Line2'
162 self.assertEqual(License, ExpectedLicense)
163
164 #
165 # Normal case4: format example in spec
166 #
167 def testNormalCase4(self):
168 TestCommentLines = \
169 '''
170 ## @file
171 # Abstract
172 #
173 # Description
174 #
175 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
176 #
177 # License
178 #
179 ##'''
180
181 CommentList = GetSplitValueList(TestCommentLines, "\n")
182 LineNum = 0
183 TestCommentLinesList = []
184 for Comment in CommentList:
185 LineNum += 1
186 TestCommentLinesList.append((Comment, LineNum))
187
188 Abstract, Description, Copyright, License = \
189 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
190
191 ExpectedAbstract = 'Abstract'
192 self.assertEqual(Abstract, ExpectedAbstract)
193
194 ExpectedDescription = 'Description'
195 self.assertEqual(Description, ExpectedDescription)
196
197 ExpectedCopyright = \
198 'Copyright (c) 2007 - 2018, Intel Corporation.'\
199 ' All rights reserved.<BR>'
200 self.assertEqual(Copyright, ExpectedCopyright)
201
202 ExpectedLicense = \
203 'License'
204 self.assertEqual(License, ExpectedLicense)
205
206 #
207 # Normal case5: other line between copyright
208 #
209 def testNormalCase5(self):
210 TestCommentLines = \
211 '''
212 ## @file
213 # Abstract
214 #
215 # Description
216 #
217 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
218 # other line
219 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
220 #
221 # License
222 #
223 ##'''
224
225 CommentList = GetSplitValueList(TestCommentLines, "\n")
226 LineNum = 0
227 TestCommentLinesList = []
228 for Comment in CommentList:
229 LineNum += 1
230 TestCommentLinesList.append((Comment, LineNum))
231
232 Abstract, Description, Copyright, License = \
233 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
234
235 ExpectedAbstract = 'Abstract'
236 self.assertEqual(Abstract, ExpectedAbstract)
237
238 ExpectedDescription = 'Description'
239 self.assertEqual(Description, ExpectedDescription)
240
241 ExpectedCopyright = \
242 'Copyright (c) 2007 - 2018, Intel Corporation.'\
243 ' All rights reserved.<BR>\n'\
244 'Copyright (c) 2007 - 2018, Intel Corporation.'\
245 ' All rights reserved.<BR>'
246 self.assertEqual(Copyright, ExpectedCopyright)
247
248 ExpectedLicense = \
249 'License'
250 self.assertEqual(License, ExpectedLicense)
251
252 #
253 # Normal case6: multiple lines of copyright
254 #
255 def testNormalCase6(self):
256 TestCommentLines = \
257 '''
258 ## @file
259 # Abstract
260 #
261 # Description
262 #
263 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
264 # Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR>
265 # Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR>
266 #
267 # License
268 #
269 ##'''
270
271 CommentList = GetSplitValueList(TestCommentLines, "\n")
272 LineNum = 0
273 TestCommentLinesList = []
274 for Comment in CommentList:
275 LineNum += 1
276 TestCommentLinesList.append((Comment, LineNum))
277
278 Abstract, Description, Copyright, License = \
279 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
280
281 ExpectedAbstract = 'Abstract'
282 self.assertEqual(Abstract, ExpectedAbstract)
283
284 ExpectedDescription = 'Description'
285 self.assertEqual(Description, ExpectedDescription)
286
287 ExpectedCopyright = \
288 'Copyright (c) 2007 - 2018, Intel Corporation.'\
289 ' All rights reserved.<BR>\n'\
290 'Copyright (c) 2007 - 2010, FOO1 Corporation.'\
291 ' All rights reserved.<BR>\n'\
292 'Copyright (c) 2007 - 2010, FOO2 Corporation.'\
293 ' All rights reserved.<BR>'
294 self.assertEqual(Copyright, ExpectedCopyright)
295
296 ExpectedLicense = \
297 'License'
298 self.assertEqual(License, ExpectedLicense)
299
300 #
301 # Normal case7: Abstract not present
302 #
303 def testNormalCase7(self):
304 TestCommentLines = \
305 '''
306 ## @file
307 #
308 # Description
309 #
310 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
311 # Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR>
312 # Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR>
313 #
314 # License
315 #
316 ##'''
317
318 CommentList = GetSplitValueList(TestCommentLines, "\n")
319 LineNum = 0
320 TestCommentLinesList = []
321 for Comment in CommentList:
322 LineNum += 1
323 TestCommentLinesList.append((Comment, LineNum))
324
325 Abstract, Description, Copyright, License = \
326 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
327
328 ExpectedAbstract = ''
329 self.assertEqual(Abstract, ExpectedAbstract)
330
331 ExpectedDescription = 'Description'
332 self.assertEqual(Description, ExpectedDescription)
333
334 ExpectedCopyright = \
335 'Copyright (c) 2007 - 2018, Intel Corporation.'\
336 ' All rights reserved.<BR>\n'\
337 'Copyright (c) 2007 - 2010, FOO1 Corporation.'\
338 ' All rights reserved.<BR>\n'\
339 'Copyright (c) 2007 - 2010, FOO2 Corporation.'\
340 ' All rights reserved.<BR>'
341 self.assertEqual(Copyright, ExpectedCopyright)
342
343 ExpectedLicense = \
344 'License'
345 self.assertEqual(License, ExpectedLicense)
346
347 #
348 # Normal case8: Description not present
349 #
350 def testNormalCase8(self):
351 TestCommentLines = \
352 '''
353 ## @file
354 # Abstact
355 #
356 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
357 #
358 # License
359 #
360 ##'''
361
362 CommentList = GetSplitValueList(TestCommentLines, "\n")
363 LineNum = 0
364 TestCommentLinesList = []
365 for Comment in CommentList:
366 LineNum += 1
367 TestCommentLinesList.append((Comment, LineNum))
368
369 Abstract, Description, Copyright, License = \
370 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")
371
372 ExpectedAbstract = 'Abstact'
373 self.assertEqual(Abstract, ExpectedAbstract)
374
375 ExpectedDescription = ''
376 self.assertEqual(Description, ExpectedDescription)
377
378 ExpectedCopyright = \
379 'Copyright (c) 2007 - 2018, Intel Corporation.'\
380 ' All rights reserved.<BR>'
381 self.assertEqual(Copyright, ExpectedCopyright)
382
383 ExpectedLicense = \
384 'License'
385 self.assertEqual(License, ExpectedLicense)
386
387 #
388 # Error case1: No copyright found
389 #
390 def testErrorCase1(self):
391 TestCommentLines = \
392 '''
393 ## @file
394 # Abstract
395 #
396 # Description
397 #
398 # License
399 #
400 ##'''
401
402 CommentList = GetSplitValueList(TestCommentLines, "\n")
403 LineNum = 0
404 TestCommentLinesList = []
405 for Comment in CommentList:
406 LineNum += 1
407 TestCommentLinesList.append((Comment, LineNum))
408
409 self.assertRaises(Logger.FatalError,
410 ParseHeaderCommentSection,
411 TestCommentLinesList,
412 "PhonyFile")
413
414 #
415 # Error case2: non-empty non-comment lines passed in
416 #
417 def testErrorCase2(self):
418 TestCommentLines = \
419 '''
420 ## @file
421 # Abstract
422 #
423 this is invalid line
424 # Description
425 #
426 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
427 # License
428 #
429 ##'''
430
431 CommentList = GetSplitValueList(TestCommentLines, "\n")
432 LineNum = 0
433 TestCommentLinesList = []
434 for Comment in CommentList:
435 LineNum += 1
436 TestCommentLinesList.append((Comment, LineNum))
437
438 self.assertRaises(Logger.FatalError,
439 ParseHeaderCommentSection,
440 TestCommentLinesList,
441 "PhonyFile")
442
443 #
444 # Test ParseGenericComment
445 #
446 class ParseGenericCommentTest(unittest.TestCase):
447 def setUp(self):
448 pass
449
450 def tearDown(self):
451 pass
452
453 #
454 # Normal case1: one line of comment
455 #
456 def testNormalCase1(self):
457 TestCommentLines = \
458 '''# hello world'''
459
460 CommentList = GetSplitValueList(TestCommentLines, "\n")
461 LineNum = 0
462 TestCommentLinesList = []
463 for Comment in CommentList:
464 LineNum += 1
465 TestCommentLinesList.append((Comment, LineNum))
466
467 HelptxtObj = ParseGenericComment(TestCommentLinesList, 'testNormalCase1')
468 self.failIf(not HelptxtObj)
469 self.assertEqual(HelptxtObj.GetString(), 'hello world')
470 self.assertEqual(HelptxtObj.GetLang(), TAB_LANGUAGE_EN_US)
471
472 #
473 # Normal case2: multiple lines of comment
474 #
475 def testNormalCase2(self):
476 TestCommentLines = \
477 '''## hello world
478 # second line'''
479
480 CommentList = GetSplitValueList(TestCommentLines, "\n")
481 LineNum = 0
482 TestCommentLinesList = []
483 for Comment in CommentList:
484 LineNum += 1
485 TestCommentLinesList.append((Comment, LineNum))
486
487 HelptxtObj = ParseGenericComment(TestCommentLinesList, 'testNormalCase2')
488 self.failIf(not HelptxtObj)
489 self.assertEqual(HelptxtObj.GetString(),
490 'hello world\n' + 'second line')
491 self.assertEqual(HelptxtObj.GetLang(), TAB_LANGUAGE_EN_US)
492
493 #
494 # Normal case3: multiple lines of comment, non comment lines will be skipped
495 #
496 def testNormalCase3(self):
497 TestCommentLines = \
498 '''## hello world
499 This is not comment line'''
500
501 CommentList = GetSplitValueList(TestCommentLines, "\n")
502 LineNum = 0
503 TestCommentLinesList = []
504 for Comment in CommentList:
505 LineNum += 1
506 TestCommentLinesList.append((Comment, LineNum))
507
508 HelptxtObj = ParseGenericComment(TestCommentLinesList, 'testNormalCase3')
509 self.failIf(not HelptxtObj)
510 self.assertEqual(HelptxtObj.GetString(),
511 'hello world\n\n')
512 self.assertEqual(HelptxtObj.GetLang(), TAB_LANGUAGE_EN_US)
513
514 #
515 # Test ParseDecPcdGenericComment
516 #
517 class ParseDecPcdGenericCommentTest(unittest.TestCase):
518 def setUp(self):
519 pass
520
521 def tearDown(self):
522 pass
523
524 #
525 # Normal case1: comments with no special comment
526 #
527 def testNormalCase1(self):
528 TestCommentLines = \
529 '''## hello world
530 # second line'''
531
532 CommentList = GetSplitValueList(TestCommentLines, "\n")
533 LineNum = 0
534 TestCommentLinesList = []
535 for Comment in CommentList:
536 LineNum += 1
537 TestCommentLinesList.append((Comment, LineNum))
538
539 (HelpTxt, PcdErr) = \
540 ParseDecPcdGenericComment(TestCommentLinesList, 'testNormalCase1')
541 self.failIf(not HelpTxt)
542 self.failIf(PcdErr)
543 self.assertEqual(HelpTxt,
544 'hello world\n' + 'second line')
545
546
547 #
548 # Normal case2: comments with valid list
549 #
550 def testNormalCase2(self):
551 TestCommentLines = \
552 '''## hello world
553 # second line
554 # @ValidList 1, 2, 3
555 # other line'''
556
557 CommentList = GetSplitValueList(TestCommentLines, "\n")
558 LineNum = 0
559 TestCommentLinesList = []
560 for Comment in CommentList:
561 LineNum += 1
562 TestCommentLinesList.append((Comment, LineNum))
563
564 (HelpTxt, PcdErr) = \
565 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
566 self.failIf(not HelpTxt)
567 self.failIf(not PcdErr)
568 self.assertEqual(HelpTxt,
569 'hello world\n' + 'second line\n' + 'other line')
570 ExpectedList = GetSplitValueList('1 2 3', TAB_SPACE_SPLIT)
571 ActualList = [item for item in \
572 GetSplitValueList(PcdErr.GetValidValue(), TAB_SPACE_SPLIT) if item]
573 self.assertEqual(ExpectedList, ActualList)
574 self.failIf(PcdErr.GetExpression())
575 self.failIf(PcdErr.GetValidValueRange())
576
577 #
578 # Normal case3: comments with valid range
579 #
580 def testNormalCase3(self):
581 TestCommentLines = \
582 '''## hello world
583 # second line
584 # @ValidRange LT 1 AND GT 2
585 # other line'''
586
587 CommentList = GetSplitValueList(TestCommentLines, "\n")
588 LineNum = 0
589 TestCommentLinesList = []
590 for Comment in CommentList:
591 LineNum += 1
592 TestCommentLinesList.append((Comment, LineNum))
593
594 (HelpTxt, PcdErr) = \
595 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
596 self.failIf(not HelpTxt)
597 self.failIf(not PcdErr)
598 self.assertEqual(HelpTxt,
599 'hello world\n' + 'second line\n' + 'other line')
600 self.assertEqual(PcdErr.GetValidValueRange().strip(), 'LT 1 AND GT 2')
601 self.failIf(PcdErr.GetExpression())
602 self.failIf(PcdErr.GetValidValue())
603
604 #
605 # Normal case4: comments with valid expression
606 #
607 def testNormalCase4(self):
608 TestCommentLines = \
609 '''## hello world
610 # second line
611 # @Expression LT 1 AND GT 2
612 # other line'''
613
614 CommentList = GetSplitValueList(TestCommentLines, "\n")
615 LineNum = 0
616 TestCommentLinesList = []
617 for Comment in CommentList:
618 LineNum += 1
619 TestCommentLinesList.append((Comment, LineNum))
620
621 (HelpTxt, PcdErr) = \
622 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
623 self.failIf(not HelpTxt)
624 self.failIf(not PcdErr)
625 self.assertEqual(HelpTxt,
626 'hello world\n' + 'second line\n' + 'other line')
627 self.assertEqual(PcdErr.GetExpression().strip(), 'LT 1 AND GT 2')
628 self.failIf(PcdErr.GetValidValueRange())
629 self.failIf(PcdErr.GetValidValue())
630
631 #
632 # Normal case5: comments with valid expression and no generic comment
633 #
634 def testNormalCase5(self):
635 TestCommentLines = \
636 '''# @Expression LT 1 AND GT 2'''
637
638 CommentList = GetSplitValueList(TestCommentLines, "\n")
639 LineNum = 0
640 TestCommentLinesList = []
641 for Comment in CommentList:
642 LineNum += 1
643 TestCommentLinesList.append((Comment, LineNum))
644
645 (HelpTxt, PcdErr) = \
646 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
647 self.failIf(HelpTxt)
648 self.failIf(not PcdErr)
649 self.assertEqual(PcdErr.GetExpression().strip(), 'LT 1 AND GT 2')
650 self.failIf(PcdErr.GetValidValueRange())
651 self.failIf(PcdErr.GetValidValue())
652
653 #
654 # Normal case6: comments with only generic help text
655 #
656 def testNormalCase6(self):
657 TestCommentLines = \
658 '''#'''
659
660 CommentList = GetSplitValueList(TestCommentLines, "\n")
661 LineNum = 0
662 TestCommentLinesList = []
663 for Comment in CommentList:
664 LineNum += 1
665 TestCommentLinesList.append((Comment, LineNum))
666
667 (HelpTxt, PcdErr) = \
668 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
669 self.assertEqual(HelpTxt, '\n')
670 self.failIf(PcdErr)
671
672
673
674 #
675 # Error case1: comments with both expression and valid list, use later
676 # ignore the former and with a warning message
677 #
678 def testErrorCase1(self):
679 TestCommentLines = \
680 '''## hello world
681 # second line
682 # @ValidList 1, 2, 3
683 # @Expression LT 1 AND GT 2
684 # other line'''
685
686 CommentList = GetSplitValueList(TestCommentLines, "\n")
687 LineNum = 0
688 TestCommentLinesList = []
689 for Comment in CommentList:
690 LineNum += 1
691 TestCommentLinesList.append((Comment, LineNum))
692
693 try:
694 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
695 except Logger.FatalError:
696 pass
697
698 #
699 # Test ParseDecPcdTailComment
700 #
701 class ParseDecPcdTailCommentTest(unittest.TestCase):
702 def setUp(self):
703 pass
704
705 def tearDown(self):
706 pass
707
708 #
709 # Normal case1: comments with no SupModeList
710 #
711 def testNormalCase1(self):
712 TestCommentLines = \
713 '''## #hello world'''
714
715 CommentList = GetSplitValueList(TestCommentLines, "\n")
716 LineNum = 0
717 TestCommentLinesList = []
718 for Comment in CommentList:
719 LineNum += 1
720 TestCommentLinesList.append((Comment, LineNum))
721
722 (SupModeList, HelpStr) = \
723 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')
724 self.failIf(not HelpStr)
725 self.failIf(SupModeList)
726 self.assertEqual(HelpStr,
727 'hello world')
728
729 #
730 # Normal case2: comments with one SupMode
731 #
732 def testNormalCase2(self):
733 TestCommentLines = \
734 '''## BASE #hello world'''
735
736 CommentList = GetSplitValueList(TestCommentLines, "\n")
737 LineNum = 0
738 TestCommentLinesList = []
739 for Comment in CommentList:
740 LineNum += 1
741 TestCommentLinesList.append((Comment, LineNum))
742
743 (SupModeList, HelpStr) = \
744 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')
745 self.failIf(not HelpStr)
746 self.failIf(not SupModeList)
747 self.assertEqual(HelpStr,
748 'hello world')
749 self.assertEqual(SupModeList,
750 ['BASE'])
751
752 #
753 # Normal case3: comments with more than one SupMode
754 #
755 def testNormalCase3(self):
756 TestCommentLines = \
757 '''## BASE UEFI_APPLICATION #hello world'''
758
759 CommentList = GetSplitValueList(TestCommentLines, "\n")
760 LineNum = 0
761 TestCommentLinesList = []
762 for Comment in CommentList:
763 LineNum += 1
764 TestCommentLinesList.append((Comment, LineNum))
765
766 (SupModeList, HelpStr) = \
767 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')
768 self.failIf(not HelpStr)
769 self.failIf(not SupModeList)
770 self.assertEqual(HelpStr,
771 'hello world')
772 self.assertEqual(SupModeList,
773 ['BASE', 'UEFI_APPLICATION'])
774
775 #
776 # Normal case4: comments with more than one SupMode, no help text
777 #
778 def testNormalCase4(self):
779 TestCommentLines = \
780 '''## BASE UEFI_APPLICATION'''
781
782 CommentList = GetSplitValueList(TestCommentLines, "\n")
783 LineNum = 0
784 TestCommentLinesList = []
785 for Comment in CommentList:
786 LineNum += 1
787 TestCommentLinesList.append((Comment, LineNum))
788
789 (SupModeList, HelpStr) = \
790 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')
791 self.failIf(HelpStr)
792 self.failIf(not SupModeList)
793 self.assertEqual(SupModeList,
794 ['BASE', 'UEFI_APPLICATION'])
795
796 #
797 # Normal case5: general comments with no supModList, extract from real case
798 #
799 def testNormalCase5(self):
800 TestCommentLines = \
801 ''' # 1 = 128MB, 2 = 256MB, 3 = MAX'''
802
803 CommentList = GetSplitValueList(TestCommentLines, "\n")
804 LineNum = 0
805 TestCommentLinesList = []
806 for Comment in CommentList:
807 LineNum += 1
808 TestCommentLinesList.append((Comment, LineNum))
809
810 (SupModeList, HelpStr) = \
811 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')
812 self.failIf(not HelpStr)
813 self.assertEqual(HelpStr,
814 '1 = 128MB, 2 = 256MB, 3 = MAX')
815 self.failIf(SupModeList)
816
817
818 #
819 # Error case2: comments with supModList contains valid and invalid
820 # module type
821 #
822 def testErrorCase2(self):
823 TestCommentLines = \
824 '''## BASE INVALID_MODULE_TYPE #hello world'''
825
826 CommentList = GetSplitValueList(TestCommentLines, "\n")
827 LineNum = 0
828 TestCommentLinesList = []
829 for Comment in CommentList:
830 LineNum += 1
831 TestCommentLinesList.append((Comment, LineNum))
832
833 try:
834 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')
835 except Logger.FatalError:
836 pass
837
838
839 #
840 # Test _IsCopyrightLine
841 #
842 class _IsCopyrightLineTest(unittest.TestCase):
843 def setUp(self):
844 pass
845
846 def tearDown(self):
847 pass
848
849 #
850 # Normal case
851 #
852 def testCase1(self):
853 Line = 'this is a copyright ( line'
854 Result = _IsCopyrightLine(Line)
855 self.failIf(not Result)
856
857 #
858 # Normal case
859 #
860 def testCase2(self):
861 Line = 'this is a Copyright ( line'
862 Result = _IsCopyrightLine(Line)
863 self.failIf(not Result)
864
865 #
866 # Normal case
867 #
868 def testCase3(self):
869 Line = 'this is not aCopyright ( line'
870 Result = _IsCopyrightLine(Line)
871 self.failIf(Result)
872
873 #
874 # Normal case
875 #
876 def testCase4(self):
877 Line = 'this is Copyright( line'
878 Result = _IsCopyrightLine(Line)
879 self.failIf(not Result)
880
881 #
882 # Normal case
883 #
884 def testCase5(self):
885 Line = 'this is Copyright (line'
886 Result = _IsCopyrightLine(Line)
887 self.failIf(not Result)
888
889 #
890 # Normal case
891 #
892 def testCase6(self):
893 Line = 'this is not Copyright line'
894 Result = _IsCopyrightLine(Line)
895 self.failIf(Result)
896
897 #
898 # Normal case
899 #
900 def testCase7(self):
901 Line = 'Copyright (c) line'
902 Result = _IsCopyrightLine(Line)
903 self.failIf(not Result)
904
905 #
906 # Normal case
907 #
908 def testCase8(self):
909 Line = ' Copyright (c) line'
910 Result = _IsCopyrightLine(Line)
911 self.failIf(not Result)
912
913 #
914 # Normal case
915 #
916 def testCase9(self):
917 Line = 'not a Copyright '
918 Result = _IsCopyrightLine(Line)
919 self.failIf(Result)
920
921 if __name__ == '__main__':
922 Logger.Initialize()
923 unittest.main()