2 # -*- coding: utf-8 -*-
5 # Gerald Combs <gerald@wireshark.org>
6 # Gilbert Ramirez <gram [AT] alumni.rice.edu>
8 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
10 # SPDX-License-Identifier: GPL-2.0-or-later
22 class case_unittests(subprocesstest.SubprocessTestCase):
23 def test_unit_exntest(self):
25 self.assertRun(os.path.join(config.program_path, 'exntest'))
27 def test_unit_oids_test(self):
29 self.assertRun(os.path.join(config.program_path, 'oids_test'))
31 def test_unit_reassemble_test(self):
33 self.assertRun(os.path.join(config.program_path, 'reassemble_test'))
35 def test_unit_tvbtest(self):
37 self.assertRun(os.path.join(config.program_path, 'tvbtest'))
39 def test_unit_wmem_test(self):
41 self.assertRun((os.path.join(config.program_path, 'wmem_test'),
45 def test_unit_wmem_test(self):
47 self.assertRun((os.path.join(config.program_path, 'wmem_test'),
51 def test_unit_fieldcount(self):
53 self.assertRun((config.cmd_tshark, '-G', 'fieldcount'))
55 def test_unit_ctest_coverage(self):
56 '''Make sure CTest runs all of our tests.'''
57 with open(os.path.join(config.this_dir, '..', 'CMakeLists.txt')) as cml_fd:
58 group_re = re.compile('set *\( *_test_group_list')
61 for cml_line in cml_fd:
62 if group_re.search(cml_line):
68 cml_groups.append(cml_line.strip())
70 if not config.all_groups == cml_groups:
71 diff = '\n'.join(list(difflib.unified_diff(config.all_groups, cml_groups, 'all test groups', 'CMakeLists.txt test groups')))
72 self.fail("CMakeLists.txt doesn't test all available groups:\n" + diff)
76 """Data for a protocol."""
77 def __init__(self, line):
78 data = line.split("\t")
79 assert len(data) == 3, "expected 3 columns in %s" % data
85 """Data for a field."""
86 def __init__(self, line):
87 data = line.split("\t")
88 assert len(data) == 8, "expected 8 columns in %s" % data
95 self.bitmask = int(data[6],0)
98 class case_unit_ftsanity(subprocesstest.SubprocessTestCase):
99 def test_unit_ftsanity(self):
100 """Looks for problems in field type definitions."""
101 tshark_proc = self.assertRun((config.cmd_tshark, "-G", "fields"))
103 lines = tshark_proc.stdout_str.splitlines()
104 # XXX We don't currently check protos.
105 protos = [Proto(x) for x in lines if x[0] == "P"]
106 fields = [Field(x) for x in lines if x[0] == "F"]
110 if field.bitmask != 0:
111 if field.ftype.find("FT_UINT") != 0 and \
112 field.ftype.find("FT_INT") != 0 and \
113 field.ftype != "FT_BOOLEAN" and \
114 field.ftype != "FT_CHAR":
115 err_list.append("%s has a bitmask 0x%x but is type %s" % \
116 (field.abbrev, field.bitmask, field.ftype))
118 self.assertEqual(len(err_list), 0, 'Found field type errors: \n' + '\n'.join(err_list))