diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-02-23 17:21:05 +0100 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-02-23 17:54:59 +0100 |
| commit | 9303454bbfb934017c1054f668f3083c75b2d61c (patch) | |
| tree | 2d1cbeaf42338603556e00241b36afa2842283e8 /test | |
| parent | 4713279e25625b33b8867c35d7da686781b8b9a7 (diff) | |
| download | miasm-9303454bbfb934017c1054f668f3083c75b2d61c.tar.gz miasm-9303454bbfb934017c1054f668f3083c75b2d61c.zip | |
Core: Introduce BoundedDict and its regression test
Diffstat (limited to 'test')
| -rw-r--r-- | test/core/utils.py | 41 | ||||
| -rw-r--r-- | test/test_all.py | 1 |
2 files changed, 42 insertions, 0 deletions
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 |