From 9303454bbfb934017c1054f668f3083c75b2d61c Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Mon, 23 Feb 2015 17:21:05 +0100 Subject: Core: Introduce BoundedDict and its regression test --- test/core/utils.py | 41 +++++++++++++++++++++++++++++++++++++++++ test/test_all.py | 1 + 2 files changed, 42 insertions(+) create mode 100644 test/core/utils.py (limited to 'test') diff --git a/test/core/utils.py b/test/core/utils.py new file mode 100644 index 00000000..bf14df68 --- /dev/null +++ b/test/core/utils.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +import unittest + + +class TestUtils(unittest.TestCase): + + def test_boundedDict(self): + from miasm2.core.utils import BoundedDict + + # Use a callback + def logger(key): + print "DELETE", key + + # Create a 5/2 dictionnary + bd = BoundedDict(5, 2, initialdata={"element": "value"}, + delete_cb=logger) + bd["element2"] = "value2" + assert("element" in bd) + assert("element2" in bd) + self.assertEqual(bd["element"], "value") + self.assertEqual(bd["element2"], "value2") + + # Increase 'element2' use + _ = bd["element2"] + + for i in xrange(6): + bd[i] = i + print "Insert %d -> %s" % (i, bd) + + assert(len(bd) == 2) + + assert("element2" in bd) + self.assertEqual(bd["element2"], "value2") + + +if __name__ == '__main__': + testsuite = unittest.TestLoader().loadTestsFromTestCase(TestUtils) + report = unittest.TextTestRunner(verbosity=2).run(testsuite) + exit(len(report.errors + report.failures)) diff --git a/test/test_all.py b/test/test_all.py index 0ecc677f..8d759053 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -100,6 +100,7 @@ testset += SemanticTestExec("x86_32", "PE", 0x401000, ["bsr_bsf"], for script in ["interval.py", "graph.py", "parse_asm.py", + "utils.py", ]: testset += RegressionTest([script], base_dir="core") ## Expression -- cgit 1.4.1