]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/UnitTest/CommentParsingUnitTest.py
BaseTools: Clean up source files
[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
64285f15 4# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c 5#\r
f7496d71
LG
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
4234283c
LG
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
64285f15 22from Library.StringUtils import GetSplitValueList\r
4234283c 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
f7496d71 35\r
4234283c
LG
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
f7496d71
LG
45 # example abstract\r
46 #\r
4234283c 47 # example description\r
f7496d71
LG
48 #\r
49 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
50 #\r
51 # License3\r
4234283c 52 #'''\r
f7496d71 53\r
4234283c
LG
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
f7496d71 60\r
4234283c
LG
61 Abstract, Description, Copyright, License = \\r
62 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 63\r
4234283c
LG
64 ExpectedAbstract = 'example abstract'\r
65 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 66\r
4234283c
LG
67 ExpectedDescription = 'example description'\r
68 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 69\r
4234283c
LG
70 ExpectedCopyright = \\r
71 'Copyright (c) 2007 - 2010,'\\r
72 ' Intel Corporation. All rights reserved.<BR>'\r
73 self.assertEqual(Copyright, ExpectedCopyright)\r
f7496d71 74\r
4234283c
LG
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
f7496d71
LG
87 # example abstract\r
88 #\r
4234283c
LG
89 # example description\r
90 #\r
f7496d71 91 #Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
92 #\r
93 ##'''\r
f7496d71 94\r
4234283c
LG
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
f7496d71 101\r
4234283c
LG
102 Abstract, Description, Copyright, License = \\r
103 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 104\r
4234283c
LG
105 ExpectedAbstract = 'example abstract'\r
106 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 107\r
4234283c
LG
108 ExpectedDescription = 'example description'\r
109 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 110\r
4234283c 111 ExpectedCopyright = \\r
f7496d71 112 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c
LG
113 ' All rights reserved.<BR>'\r
114 self.assertEqual(Copyright, ExpectedCopyright)\r
f7496d71 115\r
4234283c
LG
116 ExpectedLicense = 'License1\nLicense2'\r
117 self.assertEqual(License, ExpectedLicense)\r
f7496d71 118\r
4234283c
LG
119\r
120 #\r
f7496d71 121 # Normal case2: have license/copyright/license above @file,\r
4234283c
LG
122 # but no abstract/description\r
123 #\r
124 def testNormalCase3(self):\r
125 TestCommentLines3 = \\r
126 ''' # License1\r
127 # License2\r
128 #\r
f7496d71
LG
129 ## @file\r
130 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
131 #\r
132 # License3 Line1\r
133 # License3 Line2\r
134 ##'''\r
f7496d71 135\r
4234283c
LG
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
f7496d71 142\r
4234283c
LG
143 Abstract, Description, Copyright, License = \\r
144 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 145\r
4234283c
LG
146 ExpectedAbstract = ''\r
147 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 148\r
4234283c
LG
149 ExpectedDescription = ''\r
150 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 151\r
4234283c
LG
152 ExpectedCopyright = \\r
153 'Copyright (c) 2007 - 2010,'\\r
154 ' Intel Corporation. All rights reserved.<BR>'\r
155 self.assertEqual(Copyright, ExpectedCopyright)\r
f7496d71 156\r
4234283c
LG
157 ExpectedLicense = \\r
158 'License1\n' \\r
159 'License2\n\n' \\r
160 'License3 Line1\n' \\r
161 'License3 Line2'\r
f7496d71
LG
162 self.assertEqual(License, ExpectedLicense)\r
163\r
4234283c
LG
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
f7496d71 175 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
176 #\r
177 # License\r
178 #\r
179 ##'''\r
f7496d71 180\r
4234283c
LG
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
f7496d71 187\r
4234283c
LG
188 Abstract, Description, Copyright, License = \\r
189 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 190\r
4234283c
LG
191 ExpectedAbstract = 'Abstract'\r
192 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 193\r
4234283c
LG
194 ExpectedDescription = 'Description'\r
195 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 196\r
4234283c 197 ExpectedCopyright = \\r
f7496d71 198 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c
LG
199 ' All rights reserved.<BR>'\r
200 self.assertEqual(Copyright, ExpectedCopyright)\r
f7496d71 201\r
4234283c
LG
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
f7496d71
LG
217 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
218 # other line\r
219 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
220 #\r
221 # License\r
222 #\r
223 ##'''\r
f7496d71 224\r
4234283c
LG
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
f7496d71 231\r
4234283c
LG
232 Abstract, Description, Copyright, License = \\r
233 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 234\r
4234283c
LG
235 ExpectedAbstract = 'Abstract'\r
236 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 237\r
4234283c
LG
238 ExpectedDescription = 'Description'\r
239 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 240\r
4234283c 241 ExpectedCopyright = \\r
f7496d71 242 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c 243 ' All rights reserved.<BR>\n'\\r
f7496d71 244 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c
LG
245 ' All rights reserved.<BR>'\r
246 self.assertEqual(Copyright, ExpectedCopyright)\r
f7496d71 247\r
4234283c
LG
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
f7496d71
LG
263 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
264 # Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR>\r
4234283c
LG
265 # Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR>\r
266 #\r
267 # License\r
268 #\r
269 ##'''\r
f7496d71 270\r
4234283c
LG
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
f7496d71 277\r
4234283c
LG
278 Abstract, Description, Copyright, License = \\r
279 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 280\r
4234283c
LG
281 ExpectedAbstract = 'Abstract'\r
282 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 283\r
4234283c
LG
284 ExpectedDescription = 'Description'\r
285 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 286\r
4234283c 287 ExpectedCopyright = \\r
f7496d71 288 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c
LG
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
f7496d71 295\r
4234283c
LG
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
f7496d71
LG
310 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
311 # Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR>\r
4234283c
LG
312 # Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR>\r
313 #\r
314 # License\r
315 #\r
316 ##'''\r
f7496d71 317\r
4234283c
LG
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
f7496d71 324\r
4234283c
LG
325 Abstract, Description, Copyright, License = \\r
326 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 327\r
4234283c
LG
328 ExpectedAbstract = ''\r
329 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 330\r
4234283c
LG
331 ExpectedDescription = 'Description'\r
332 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 333\r
4234283c 334 ExpectedCopyright = \\r
f7496d71 335 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c
LG
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
f7496d71 342\r
4234283c
LG
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
f7496d71 356 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
357 #\r
358 # License\r
359 #\r
360 ##'''\r
f7496d71 361\r
4234283c
LG
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
f7496d71 368\r
4234283c
LG
369 Abstract, Description, Copyright, License = \\r
370 ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile")\r
f7496d71 371\r
4234283c
LG
372 ExpectedAbstract = 'Abstact'\r
373 self.assertEqual(Abstract, ExpectedAbstract)\r
f7496d71 374\r
4234283c
LG
375 ExpectedDescription = ''\r
376 self.assertEqual(Description, ExpectedDescription)\r
f7496d71 377\r
4234283c 378 ExpectedCopyright = \\r
f7496d71 379 'Copyright (c) 2007 - 2018, Intel Corporation.'\\r
4234283c
LG
380 ' All rights reserved.<BR>'\r
381 self.assertEqual(Copyright, ExpectedCopyright)\r
f7496d71 382\r
4234283c
LG
383 ExpectedLicense = \\r
384 'License'\r
385 self.assertEqual(License, ExpectedLicense)\r
f7496d71 386\r
4234283c
LG
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
f7496d71 401\r
4234283c
LG
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
f7496d71
LG
408\r
409 self.assertRaises(Logger.FatalError,\r
410 ParseHeaderCommentSection,\r
4234283c 411 TestCommentLinesList,\r
f7496d71 412 "PhonyFile")\r
4234283c
LG
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
f7496d71 426 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
427 # License\r
428 #\r
429 ##'''\r
f7496d71 430\r
4234283c
LG
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
f7496d71
LG
437\r
438 self.assertRaises(Logger.FatalError,\r
439 ParseHeaderCommentSection,\r
4234283c 440 TestCommentLinesList,\r
f7496d71 441 "PhonyFile")\r
4234283c
LG
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
f7496d71 452\r
4234283c
LG
453 #\r
454 # Normal case1: one line of comment\r
455 #\r
456 def testNormalCase1(self):\r
457 TestCommentLines = \\r
458 '''# hello world'''\r
f7496d71 459\r
4234283c
LG
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
f7496d71 479\r
4234283c
LG
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
f7496d71 486\r
4234283c
LG
487 HelptxtObj = ParseGenericComment(TestCommentLinesList, 'testNormalCase2')\r
488 self.failIf(not HelptxtObj)\r
f7496d71 489 self.assertEqual(HelptxtObj.GetString(),\r
4234283c 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
f7496d71 500\r
4234283c
LG
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
f7496d71 507\r
4234283c
LG
508 HelptxtObj = ParseGenericComment(TestCommentLinesList, 'testNormalCase3')\r
509 self.failIf(not HelptxtObj)\r
f7496d71 510 self.assertEqual(HelptxtObj.GetString(),\r
4234283c 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
f7496d71 523\r
4234283c
LG
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
f7496d71 531\r
4234283c
LG
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
f7496d71 538\r
4234283c
LG
539 (HelpTxt, PcdErr) = \\r
540 ParseDecPcdGenericComment(TestCommentLinesList, 'testNormalCase1')\r
541 self.failIf(not HelpTxt)\r
542 self.failIf(PcdErr)\r
f7496d71 543 self.assertEqual(HelpTxt,\r
4234283c 544 'hello world\n' + 'second line')\r
f7496d71
LG
545\r
546\r
4234283c
LG
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
f7496d71 556\r
4234283c
LG
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
f7496d71 563\r
4234283c
LG
564 (HelpTxt, PcdErr) = \\r
565 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')\r
566 self.failIf(not HelpTxt)\r
567 self.failIf(not PcdErr)\r
f7496d71 568 self.assertEqual(HelpTxt,\r
4234283c
LG
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
f7496d71 586\r
4234283c
LG
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
f7496d71 593\r
4234283c
LG
594 (HelpTxt, PcdErr) = \\r
595 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')\r
596 self.failIf(not HelpTxt)\r
597 self.failIf(not PcdErr)\r
f7496d71 598 self.assertEqual(HelpTxt,\r
4234283c
LG
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
f7496d71 613\r
4234283c
LG
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
f7496d71 620\r
4234283c
LG
621 (HelpTxt, PcdErr) = \\r
622 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')\r
623 self.failIf(not HelpTxt)\r
624 self.failIf(not PcdErr)\r
f7496d71 625 self.assertEqual(HelpTxt,\r
4234283c
LG
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
f7496d71 637\r
4234283c
LG
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
f7496d71 644\r
4234283c
LG
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
f7496d71 652\r
4234283c
LG
653 #\r
654 # Normal case6: comments with only generic help text\r
655 #\r
656 def testNormalCase6(self):\r
657 TestCommentLines = \\r
658 '''#'''\r
f7496d71 659\r
4234283c
LG
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
f7496d71 666\r
4234283c
LG
667 (HelpTxt, PcdErr) = \\r
668 ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')\r
669 self.assertEqual(HelpTxt, '\n')\r
670 self.failIf(PcdErr)\r
671\r
f7496d71
LG
672\r
673\r
4234283c
LG
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
f7496d71 682 # @ValidList 1, 2, 3\r
4234283c
LG
683 # @Expression LT 1 AND GT 2\r
684 # other line'''\r
f7496d71 685\r
4234283c
LG
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
f7496d71 692\r
4234283c
LG
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
f7496d71 707\r
4234283c
LG
708 #\r
709 # Normal case1: comments with no SupModeList\r
710 #\r
711 def testNormalCase1(self):\r
712 TestCommentLines = \\r
713 '''## #hello world'''\r
f7496d71 714\r
4234283c
LG
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
f7496d71 721\r
4234283c
LG
722 (SupModeList, HelpStr) = \\r
723 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')\r
724 self.failIf(not HelpStr)\r
725 self.failIf(SupModeList)\r
f7496d71 726 self.assertEqual(HelpStr,\r
4234283c
LG
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
f7496d71 735\r
4234283c
LG
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
f7496d71 742\r
4234283c
LG
743 (SupModeList, HelpStr) = \\r
744 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')\r
745 self.failIf(not HelpStr)\r
746 self.failIf(not SupModeList)\r
f7496d71 747 self.assertEqual(HelpStr,\r
4234283c 748 'hello world')\r
f7496d71 749 self.assertEqual(SupModeList,\r
4234283c 750 ['BASE'])\r
f7496d71 751\r
4234283c
LG
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
f7496d71 758\r
4234283c
LG
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
f7496d71 765\r
4234283c
LG
766 (SupModeList, HelpStr) = \\r
767 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')\r
768 self.failIf(not HelpStr)\r
769 self.failIf(not SupModeList)\r
f7496d71 770 self.assertEqual(HelpStr,\r
4234283c 771 'hello world')\r
f7496d71 772 self.assertEqual(SupModeList,\r
4234283c
LG
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
f7496d71 781\r
4234283c
LG
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
f7496d71 788\r
4234283c
LG
789 (SupModeList, HelpStr) = \\r
790 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')\r
791 self.failIf(HelpStr)\r
792 self.failIf(not SupModeList)\r
f7496d71 793 self.assertEqual(SupModeList,\r
4234283c
LG
794 ['BASE', 'UEFI_APPLICATION'])\r
795\r
796 #\r
f7496d71 797 # Normal case5: general comments with no supModList, extract from real case\r
4234283c
LG
798 #\r
799 def testNormalCase5(self):\r
800 TestCommentLines = \\r
801 ''' # 1 = 128MB, 2 = 256MB, 3 = MAX'''\r
f7496d71 802\r
4234283c
LG
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
f7496d71 809\r
4234283c
LG
810 (SupModeList, HelpStr) = \\r
811 ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest')\r
812 self.failIf(not HelpStr)\r
f7496d71 813 self.assertEqual(HelpStr,\r
4234283c
LG
814 '1 = 128MB, 2 = 256MB, 3 = MAX')\r
815 self.failIf(SupModeList)\r
f7496d71 816\r
4234283c
LG
817\r
818 #\r
f7496d71 819 # Error case2: comments with supModList contains valid and invalid\r
4234283c
LG
820 # module type\r
821 #\r
822 def testErrorCase2(self):\r
823 TestCommentLines = \\r
824 '''## BASE INVALID_MODULE_TYPE #hello world'''\r
f7496d71 825\r
4234283c
LG
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
f7496d71 832\r
4234283c
LG
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
f7496d71 872\r
4234283c
LG
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
f7496d71 920\r
4234283c
LG
921if __name__ == '__main__':\r
922 Logger.Initialize()\r
f7496d71 923 unittest.main()\r