]>
git.zerfleddert.de Git - proxmark3-svn/blob - tools/findbits_test.py
3 from itertools
import imap
4 import unittest
, sys
, findbits
6 class TestFindBits(unittest
.TestCase
):
8 self
.old_stdout
= sys
.stdout
9 sys
.stdout
= OutputBuffer()
12 sys
.stdout
= self
.old_stdout
18 def test_invert(self
):
19 self
.commutative_test(findbits
.invert
, self
.INVERT_CASES
)
22 ('1111', '10111101', ['Match at bit 2', '0<1111>0']),
23 ('00', '10111101', ['Not found']),
25 def test_search(self
):
26 for target
, data
, expected_fragments
in self
.SEARCH_CASES
:
27 sys
.stdout
.clear_buffer()
28 findbits
.search(target
, data
)
29 for fragment
in expected_fragments
:
30 self
.assertIn(fragment
, sys
.stdout
.content
)
37 def test_binstring(self
):
38 self
.unary_operation_test(findbits
.binstring
, self
.BINSTRING_CASES
)
44 def test_stringreverse(self
):
45 self
.commutative_test(findbits
.stringreverse
, self
.REVERSE_CASES
)
47 def commutative_test(self
, operation
, cases
):
48 self
.unary_operation_test(operation
, cases
)
49 self
.unary_operation_test(operation
, imap(reversed, cases
))
51 def unary_operation_test(self
, operation
, cases
):
52 for case_in
, case_out
in cases
:
53 self
.assertEqual(operation(case_in
), case_out
)
56 class OutputBuffer(object):
60 def clear_buffer(self
):
63 def write(self
, data
):
67 if __name__
== '__main__':