Skip to content
Snippets Groups Projects
Commit e2f44c06 authored by pompolic's avatar pompolic
Browse files

Test for .read_member() including HParsedToken* type lookup

parent 52195f66
No related branches found
No related tags found
No related merge requests found
...@@ -47,13 +47,9 @@ class HParseResultCreation(unittest.TestCase): ...@@ -47,13 +47,9 @@ class HParseResultCreation(unittest.TestCase):
hpr_pointer_type_patcher = unittest.mock.patch.object(HParseResult, 'HParseResult_t_p', spec=gdb.Type) hpr_pointer_type_patcher = unittest.mock.patch.object(HParseResult, 'HParseResult_t_p', spec=gdb.Type)
gdbv_patcher = unittest.mock.patch('gdb.Value', autospec=True) gdbv_patcher = unittest.mock.patch('gdb.Value', autospec=True)
gdb_lookup_type_patcher = unittest.mock.patch.object(gdb, 'lookup_type') gdb_lookup_type_patcher = unittest.mock.patch.object(gdb, 'lookup_type')
hpr_ast_not_null_patcher = unittest.mock.patch.object(HParseResult, 'read_AST_not_null', return_value=True)
hpr_make_hparsedtoken_patcher = unittest.mock.patch.object(HParseResult, 'make_HParsedToken', spec=HParsedToken)
init_patcher = unittest.mock.patch.object(HParseResult, '__init__', return_value=None) init_patcher = unittest.mock.patch.object(HParseResult, '__init__', return_value=None)
hpr_pointer_type_patcher.start() hpr_pointer_type_patcher.start()
#hpr_ast_not_null_patcher.start()
#hpr_make_hparsedtoken_patcher.start()
gdbv_mock_object = gdbv_patcher.start() gdbv_mock_object = gdbv_patcher.start()
gdb_lookup_type_mock_object = gdb_lookup_type_patcher.start() gdb_lookup_type_mock_object = gdb_lookup_type_patcher.start()
init_patcher.start() init_patcher.start()
...@@ -62,6 +58,11 @@ class HParseResultCreation(unittest.TestCase): ...@@ -62,6 +58,11 @@ class HParseResultCreation(unittest.TestCase):
result.address = 0xdeadbeef result.address = 0xdeadbeef
member = result.read_member('ast') member = result.read_member('ast')
init_patcher.stop()
gdb_lookup_type_patcher.stop()
gdbv_patcher.stop()
hpr_pointer_type_patcher.stop()
# Check that struct being indexed is at self.address # Check that struct being indexed is at self.address
self.assertEqual(gdbv_mock_object.mock_calls[0], unittest.mock.call(0xdeadbeef)) self.assertEqual(gdbv_mock_object.mock_calls[0], unittest.mock.call(0xdeadbeef))
# Check that the value returned is parse_result_gdb_value['foo'] # Check that the value returned is parse_result_gdb_value['foo']
...@@ -71,7 +72,30 @@ class HParseResultCreation(unittest.TestCase): ...@@ -71,7 +72,30 @@ class HParseResultCreation(unittest.TestCase):
def test_read_member_with_type_lookup(self): def test_read_member_with_type_lookup(self):
gdb_lookup_type_patcher = unittest.mock.patch.object(gdb, 'lookup_type') gdb_lookup_type_patcher = unittest.mock.patch.object(gdb, 'lookup_type')
raise Exception("Not implemented") gdbv_patcher = unittest.mock.patch('gdb.Value', autospec=True)
init_patcher = unittest.mock.patch.object(HParseResult, '__init__', return_value=None)
# This is cached in the class the first time read_member() or read_AST_not_null() is called
# To test the case where it's not yet cached, we explicitly set it to None
HParseResult.HParseResult_t_p = None
gdb_lookup_type_mock_object = gdb_lookup_type_patcher.start()
gdbv_mock_object = gdbv_patcher.start()
init_patcher.start()
result = HParseResult(0xdeadbeef)
result.address = 0xdeadbeef
member = result.read_member('ast')
init_patcher.stop()
gdbv_patcher.stop()
gdb_lookup_type_patcher.stop()
# Check that HParseResult* has been looked up
self.assertEqual(gdb_lookup_type_mock_object.mock_calls, [unittest.mock.call('HParseResult'), unittest.mock.call().pointer()])
# Check that the struct being indexed is at self.address
self.assertEqual(gdbv_mock_object.mock_calls[0], unittest.mock.call(0xdeadbeef))
# Check that the value returned is parse_result_gdb_value['foo']
self.assertEqual(gdbv_mock_object.mock_calls[-1], unittest.mock.call().cast().__getitem__('ast'))
# TODO: should read_member employ a whitelist for member_name, or should this trigger an exeption? # TODO: should read_member employ a whitelist for member_name, or should this trigger an exeption?
def test_read_member_invalid_param(self): def test_read_member_invalid_param(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment