diff options
Diffstat (limited to 'tests/analysis')
-rw-r--r-- | tests/analysis/type.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/analysis/type.py b/tests/analysis/type.py new file mode 100644 index 0000000..5106cbc --- /dev/null +++ b/tests/analysis/type.py @@ -0,0 +1,92 @@ +#!/usr/bin/python3-dbg +# -*- coding: utf-8 -*- + + +from chrysacase import ChrysalideTestCase +from pychrysalide.analysis import DataType + + +class TestDataType(ChrysalideTestCase): + """TestCase for analysis.DataType.""" + + + def testTypeSubclassing(self): + """Verify the data type subclassing is working.""" + + class MyType(DataType): + + def __init__(self, num): + super(MyType, self).__init__() + self._num = num + + def _to_string(self, include): + return '%x' % self._num + + def _dup(self): + return MyType(self._num) + + tp = MyType(0x123) + + self.assertEqual(str(tp), '123') + + tp2 = tp.dup() + + self.assertEqual(str(tp), str(tp2)) + + + def testTypeDefaultProperties(self): + """Check for default values of some type properties.""" + + class MyPropType(DataType): + pass + + tp = MyPropType() + + self.assertTrue(tp.handle_namespaces) + + self.assertFalse(tp.is_pointer) + + self.assertFalse(tp.is_reference) + + class MyPropType2(DataType): + + def _handle_namespaces(self): + return True + + def _is_pointer(self): + return 123 < 1234 + + def _is_reference(self): + return False + + tp2 = MyPropType2() + + self.assertTrue(tp.handle_namespaces) + + self.assertTrue(tp2.is_pointer) + + self.assertFalse(tp2.is_reference) + + + def testTypeNamespaces(self): + """Test the type namespace property.""" + + class MyNSType(DataType): + + def __init__(self, name): + super(MyNSType, self).__init__() + self._name = name + + def _to_string(self, include): + return self._name + + tp = MyNSType('TP') + ns = MyNSType('NS') + + self.assertIsNone(tp.namespace) + + tp.namespace = (ns, '.') + + self.assertEqual(str(tp), 'NS.TP') + + self.assertEqual(tp.namespace, (ns, '.')) |