diff options
Diffstat (limited to 'tests/format')
-rw-r--r-- | tests/format/strsym.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/format/strsym.py b/tests/format/strsym.py new file mode 100644 index 0000000..ba1d92f --- /dev/null +++ b/tests/format/strsym.py @@ -0,0 +1,33 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.analysis import BinContent +from pychrysalide.analysis.contents import MemoryContent +from pychrysalide.arch import vmpa, mrange +from pychrysalide.format import FlatFormat, StrSymbol + + +class TestBinarySymbols(ChrysalideTestCase): + """TestCase for format.StrSymbol.""" + + def testStringSymbolConstructors(self): + """Build string symbols.""" + + data = b'ABCD1234' + + cnt = MemoryContent(data) + fmt = FlatFormat(cnt, 'xxx', BinContent.SourceEndian.LITTLE) + + saddr = vmpa(0x0, vmpa.VmpaSpecialValue.NO_VIRTUAL) + srange = mrange(saddr, 0x5) + + symbol = StrSymbol(StrSymbol.StringEncodingType.GUESS, fmt, srange) + + self.assertEqual(symbol.raw, b'ABCD1') + self.assertEqual(symbol.utf8, 'ABCD1') + self.assertEqual(symbol.encoding, StrSymbol.StringEncodingType.ASCII) + + symbol = StrSymbol(StrSymbol.StringEncodingType.GUESS, string='abcdef', addr=saddr) + + self.assertEqual(symbol.raw, b'abcdef') + self.assertEqual(symbol.utf8, 'abcdef') + self.assertEqual(symbol.encoding, StrSymbol.StringEncodingType.ASCII) |