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
21 @fixtures.uses_fixtures
22 class case_unittests(subprocesstest.SubprocessTestCase):
23 def test_unit_exntest(self, program, base_env):
25 self.assertRun(program('exntest'), env=base_env)
27 def test_unit_oids_test(self, program, base_env):
29 self.assertRun(program('oids_test'), env=base_env)
31 def test_unit_reassemble_test(self, program, base_env):
33 self.assertRun(program('reassemble_test'), env=base_env)
35 def test_unit_tvbtest(self, program, base_env):
37 self.assertRun(program('tvbtest'), env=base_env)
39 def test_unit_wmem_test(self, program, base_env):
41 self.assertRun((program('wmem_test'),
45 def test_unit_wmem_test(self, program, base_env):
47 self.assertRun((program('wmem_test'),
51 def test_unit_fieldcount(self, cmd_tshark, test_env):
53 self.assertRun((cmd_tshark, '-G', 'fieldcount'), env=test_env)
55 def test_unit_ctest_coverage(self, all_test_groups):
56 '''Make sure CTest runs all of our tests.'''
57 with open(os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt')) as cml_fd:
58 group_re = re.compile(r'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 all_test_groups == cml_groups:
71 diff = '\n'.join(list(difflib.unified_diff(all_test_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)
99 @fixtures.uses_fixtures
100 class case_unit_ftsanity(subprocesstest.SubprocessTestCase):
101 def test_unit_ftsanity(self, cmd_tshark, base_env):
102 """Looks for problems in field type definitions."""
103 tshark_proc = self.assertRun((cmd_tshark, "-G", "fields"), env=base_env)
105 lines = tshark_proc.stdout_str.splitlines()
106 # XXX We don't currently check protos.
107 protos = [Proto(x) for x in lines if x[0] == "P"]
108 fields = [Field(x) for x in lines if x[0] == "F"]
112 if field.bitmask != 0:
113 if field.ftype.find("FT_UINT") != 0 and \
114 field.ftype.find("FT_INT") != 0 and \
115 field.ftype != "FT_BOOLEAN" and \
116 field.ftype != "FT_CHAR":
117 err_list.append("%s has a bitmask 0x%x but is type %s" % \
118 (field.abbrev, field.bitmask, field.ftype))
120 self.assertEqual(len(err_list), 0, 'Found field type errors: \n' + '\n'.join(err_list))