# Path: mozz/test.py
# def run_test_module(name, file):
# 	outputfile = mozz.util.python_path_basename(file) + '.out'
# 
# 	m = sys.modules[name]
# 	ldr = unittest.loader.defaultTestLoader
# 	tests = ldr.loadTestsFromModule(m)
# 
# 	with open(outputfile, 'w') as f:
# 		duper = mozz.util.IOWriteDuplicator(
# 			sys.stderr, f
# 		)
# 		unittest.runner.TextTestRunner(
# 			verbosity = 2,
# 			stream = duper
# 		).run(tests)
# 
# def abs_path(base_file, rel_path):
# 	return os.path.join(
# 		os.path.dirname(os.path.abspath(base_file)),
# 		rel_path
# 	)


import unittest
import mozz
from mozz.test import run_test_module, abs_path
class Test(unittest.TestCase):

	def test_mockup_jump(self):
		s = mozz.Session(abs_path(__file__, "mockup_basic_test.bin"))

		d = {
			'got_sig':       False,
			'got_mockup':    0,
			'goal_fn_execd': 0
		}

		@s.on_signal_default()
		def sig_default(host, sig):
			d['got_sig'] = True

		@s.mockup(0x4006f4, 0x400786)
		def skip_file_stuff(host):
			self.assertEqual(host.inferior().reg_pc(), 0x4006f4)
			d['got_mockup'] += 1

		@s.at_addr("try_to_get_here")
		def goal_fn(host):
			d['goal_fn_execd'] += 1

		mozz.run_session(s)
		self.assertFalse(d['got_sig'])
		self.assertEqual(d['got_mockup'], 1)
		self.assertEqual(d['goal_fn_execd'], 1)

	def test_mockup_modify(self):

# Path: mozz/test.py
# def run_test_module(name, file):
# 	outputfile = mozz.util.python_path_basename(file) + '.out'
# 
# 	m = sys.modules[name]
# 	ldr = unittest.loader.defaultTestLoader
# 	tests = ldr.loadTestsFromModule(m)
# 
# 	with open(outputfile, 'w') as f:
# 		duper = mozz.util.IOWriteDuplicator(
# 			sys.stderr, f
# 		)
# 		unittest.runner.TextTestRunner(
# 			verbosity = 2,
# 			stream = duper
# 		).run(tests)
# 
# def abs_path(base_file, rel_path):
# 	return os.path.join(
# 		os.path.dirname(os.path.abspath(base_file)),
# 		rel_path
# 	)


# Path: test/mockup_basic_test.py
import unittest
import mozz
from mozz.test import run_test_module, abs_path

class Test(unittest.TestCase):

	def test_mockup_jump(self):
		s = mozz.Session(abs_path(__file__, "mockup_basic_test.bin"))

		d = {
			'got_sig':       False,
			'got_mockup':    0,
			'goal_fn_execd': 0
		}

		@s.on_signal_default()
		def sig_default(host, sig):
			d['got_sig'] = True

		@s.mockup(0x4006f4, 0x400786)
		def skip_file_stuff(host):
			self.assertEqual(host.inferior().reg_pc(), 0x4006f4)
			d['got_mockup'] += 1

		@s.at_addr("try_to_get_here")
		def goal_fn(host):
			d['goal_fn_execd'] += 1

		mozz.run_session(s)
		self.assertFalse(d['got_sig'])
		self.assertEqual(d['got_mockup'], 1)
		self.assertEqual(d['goal_fn_execd'], 1)

	def test_mockup_modify(self):

		s = mozz.Session(abs_path(__file__, "mockup_basic_test.bin"))