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