From 22f6f6f5dd71ce088ca733a86fbb021fbf585637 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Tue, 19 Apr 2022 18:28:56 +0200
Subject: [PATCH] Tests for parser virtual breakpoints in BreakpointManager

---
 gdb-port/tests/unit/breakpoint-manager.py | 24 +++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gdb-port/tests/unit/breakpoint-manager.py b/gdb-port/tests/unit/breakpoint-manager.py
index 446de0b..2bce7c2 100644
--- a/gdb-port/tests/unit/breakpoint-manager.py
+++ b/gdb-port/tests/unit/breakpoint-manager.py
@@ -35,11 +35,14 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase):
 		self.plprbp_mock_object = self.plprbp_patcher.start()
 		self.hpprbp_patcher = unittest.mock.patch('__main__.HPackratParseRetBreakpoint')
 		self.hpprbp_mock_object = self.hpprbp_patcher.start()
+		self.pvbp_patcher = unittest.mock.patch('__main__.ParserVirtualBreakpoint')
+		self.pvbp_mock_object = self.pvbp_patcher.start()
 
 	def tearDown(self):
 		self.hpprbp_patcher.stop()
 		self.plprbp_patcher.stop()
 		self.hrbp_patcher.stop()
+		self.pvbp_patcher.stop()
 
 # TODO: mock breakpoints, assert on arguments to constructor
 	def test_set_h_rule_breakpoints(self):
@@ -73,6 +76,27 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase):
 		#bps_valid = [ bp.is_valid() for bp in bps]
 		#self.assertEqual(bps_valid, 2 * [False])
 
+	@unittest.skip("Need to make a mock binary to find RETQs in for this one")
+	def test_locate_retqs(self):
+		self.fail("Not implemented yet")
+
+	@unittest.skip("Need to make a mock binary to find RETQs in for this one")
+	def test_locate_retq(self):
+		self.fail("Not implemented yet")
+
+	def test_set_parser_virtual_breakpoints(self):
+		self.bpm.set_parser_virtual_breakpoints()
+		virt_bps = [ self.bpm.__getattribute__(a) for a in dir(self.bpm) if a.startswith("parse_")]
+		for bp in virt_bps:
+			self.assertTrue(self.pvbp_mock_object.call_count == len(virt_bps))
+
+	def test_del_parser_virtual_breakpoints(self):
+		self.bpm.set_parser_virtual_breakpoints()
+		virt_bps = [ self.bpm.__getattribute__(a) for a in dir(self.bpm) if a.startswith("parse_")]
+		self.bpm.del_parser_virtual_breakpoints()
+		for bp in virt_bps:
+			self.assertTrue(bp.delete.called)
+
 	# TODO
 	#def tearDown(self):
 		#self.bpm.delete
-- 
GitLab