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