| 1 |
# Copyright 2013 Red Hat, Inc. |
| 2 |
# |
| 3 |
# This library is free software; you can redistribute it and/or |
| 4 |
# modify it under the terms of the GNU Lesser General Public |
| 5 |
# License as published by the Free Software Foundation; either |
| 6 |
# version 2.1 of the License, or (at your option) any later version. |
| 7 |
# |
| 8 |
# This library is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
# Lesser General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU Lesser General Public |
| 14 |
# License along with this library; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 16 |
# USA |
| 17 |
|
| 18 |
import os |
| 19 |
import unittest |
| 20 |
|
| 21 |
from firehose.model import Issue, Failure |
| 22 |
|
| 23 |
from firehose.parsers.cppcheck import parse_file |
| 24 |
|
| 25 |
class TestParseXml(unittest.TestCase): |
| 26 |
def parse_example(self, filename): |
| 27 |
a = parse_file(os.path.join(os.path.dirname(__file__), |
| 28 |
'example-output', |
| 29 |
'cppcheck-xml-v2', |
| 30 |
filename)) |
| 31 |
return a |
| 32 |
|
| 33 |
def test_example_001(self): |
| 34 |
a = self.parse_example('example-001.xml') |
| 35 |
self.assertEqual(a.metadata.generator.name, 'cppcheck') |
| 36 |
self.assertEqual(a.metadata.generator.version, '1.57') |
| 37 |
self.assertEqual(a.metadata.sut, None) |
| 38 |
self.assertEqual(a.metadata.file_, None) |
| 39 |
self.assertEqual(a.metadata.stats, None) |
| 40 |
self.assertEqual(len(a.results), 7) |
| 41 |
r0 = a.results[0] |
| 42 |
self.assertIsInstance(r0, Issue) |
| 43 |
self.assertEqual(r0.cwe, None) |
| 44 |
self.assertEqual(r0.testid, 'uninitvar') |
| 45 |
self.assertEqual(r0.message.text, 'Uninitialized variable: ret') |
| 46 |
self.assertEqual(r0.notes, None) |
| 47 |
self.assertEqual(r0.location.file.givenpath, |
| 48 |
'python-ethtool/etherinfo_obj.c') |
| 49 |
self.assertEqual(r0.location.file.abspath, None) |
| 50 |
self.assertEqual(r0.location.function, None) |
| 51 |
self.assertEqual(r0.location.line, 185) |
| 52 |
self.assertEqual(r0.trace, None) |
| 53 |
self.assertEqual(r0.severity, 'error') |
| 54 |
|
| 55 |
def test_example_002(self): |
| 56 |
a = self.parse_example('example-002.xml') |
| 57 |
self.assertEqual(a.metadata.generator.name, 'cppcheck') |
| 58 |
self.assertEqual(a.metadata.generator.version, '1.58') |
| 59 |
self.assertEqual(a.metadata.sut, None) |
| 60 |
self.assertEqual(a.metadata.file_, None) |
| 61 |
self.assertEqual(a.metadata.stats, None) |
| 62 |
self.assertEqual(len(a.results), 1) |
| 63 |
r0 = a.results[0] |
| 64 |
self.assertIsInstance(r0, Failure) |
| 65 |
self.assertEqual(r0.failureid, 'toomanyconfigs') |
| 66 |
self.assertEqual(r0.location, None) |
| 67 |
self.assertEqual(r0.message.text, |
| 68 |
('Too many #ifdef configurations - cppcheck only' |
| 69 |
' checks 12 configurations. Use --force to check' |
| 70 |
' all configurations. For more details, use' |
| 71 |
' --enable=information.')) |
| 72 |
self.assertEqual(r0.customfields['verbose'], |
| 73 |
('The checking of the file will be interrupted because' |
| 74 |
' there are too many #ifdef configurations. Checking of' |
| 75 |
' all #ifdef configurations can be forced by --force' |
| 76 |
' command line option or from GUI preferences. However' |
| 77 |
' that may increase the checking time. For more details,' |
| 78 |
' use --enable=information.')) |