diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arch/operands/immediate.py (renamed from tests/arch/immediate.py) | 0 | ||||
-rw-r--r-- | tests/format/program.py | 9 | ||||
-rw-r--r-- | tests/glibext/objhole.py | 31 | ||||
-rw-r--r-- | tests/glibext/strbuilder.py | 44 | ||||
-rw-r--r-- | tests/plugins/plugin.py | 219 | ||||
-rw-r--r-- | tests/plugins/python.py | 27 |
6 files changed, 155 insertions, 175 deletions
diff --git a/tests/arch/immediate.py b/tests/arch/operands/immediate.py index 74b8069..74b8069 100644 --- a/tests/arch/immediate.py +++ b/tests/arch/operands/immediate.py diff --git a/tests/format/program.py b/tests/format/program.py index 7a649b8..7027cdf 100644 --- a/tests/format/program.py +++ b/tests/format/program.py @@ -1,6 +1,7 @@ from chrysacase import ChrysalideTestCase from pychrysalide import SourceEndian +from pychrysalide.analysis.contents import MemoryContent #from pychrysalide.arch import vmpa, mrange from pychrysalide.format import ProgramFormat #from pychrysalide.format import BinSymbol @@ -17,12 +18,16 @@ class TestProgramFormat(ChrysalideTestCase): def testCustomInstance(self): """Validate a full custom ProgramFormat implementation.""" + data = b'\x00\x00\x00\xef' + cnt = MemoryContent(data) + + class CustomFormat(ProgramFormat): def _get_endianness(self): return SourceEndian.BIG - cf = CustomFormat() + cf = CustomFormat(cnt) self.assertEqual(cf.endianness, SourceEndian.BIG) @@ -30,7 +35,7 @@ class TestProgramFormat(ChrysalideTestCase): class EmptyCustomFormat(ProgramFormat): pass - cf = EmptyCustomFormat() + cf = EmptyCustomFormat(cnt) self.assertEqual(cf.endianness, SourceEndian.LITTLE) diff --git a/tests/glibext/objhole.py b/tests/glibext/objhole.py new file mode 100644 index 0000000..6a7c2e8 --- /dev/null +++ b/tests/glibext/objhole.py @@ -0,0 +1,31 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.glibext import ThickObject + + +class TestWorks(ChrysalideTestCase): + """TestCase for pychrysalide.glibext.BinaryPortion""" + + def testExtraAccess(self): + """Access to various definitions of the extra data for ThickObject.""" + + obj = ThickObject() + + self.assertEqual(obj.extra, 0) + + obj.extra = 0xffffffe0 + + self.assertEqual(obj.extra, 0xffffffe0) + + obj.extra = 0x00123000 + + self.assertEqual(obj.extra, 0x00123000) + + + def testRservedBits(self): + """Check space leaved as available by the GLib.""" + + obj = ThickObject() + + self.assertTrue(obj._GOBJECT_RESERVED_EXTRA_BITS > 0) + self.assertTrue(obj._GOBJECT_RESERVED_EXTRA_BITS < 32) diff --git a/tests/glibext/strbuilder.py b/tests/glibext/strbuilder.py new file mode 100644 index 0000000..ced405e --- /dev/null +++ b/tests/glibext/strbuilder.py @@ -0,0 +1,44 @@ + +from chrysacase import ChrysalideTestCase +from gi.repository import GObject +from pychrysalide.glibext import StringBuilder + + +class TestStringBuilder(ChrysalideTestCase): + """Test cases for pychrysalide.glibext.StringBuilder.""" + + + def testStringBuilderCreation(self): + """Create objects with StringBuilder interface.""" + + with self.assertRaisesRegex(NotImplementedError, 'StringBuilder can not be constructed'): + + sc = StringBuilder() + + class NewStringBuilderImplem(GObject.Object, StringBuilder): + pass + + nsi = NewStringBuilderImplem() + + self.assertIsNotNone(nsi) + + + def testStringBuilderMethods(self): + """Test the StringBuilder methods.""" + + class BasicStringBuilderImplem(GObject.Object, StringBuilder): + + def __init__(self, desc): + super().__init__() + self._desc = desc + + def _to_string(self, flags=0): + return self._desc + + desc = 'simple_desc' + + sb = BasicStringBuilderImplem(desc) + + self.assertEqual(sb.to_string(), desc) + self.assertEqual(str(sb), desc) + self.assertEqual(f'{sb}', desc) diff --git a/tests/plugins/plugin.py b/tests/plugins/plugin.py index 6409975..9015409 100644 --- a/tests/plugins/plugin.py +++ b/tests/plugins/plugin.py @@ -1,223 +1,96 @@ -#!/usr/bin/python3-dbg -# -*- coding: utf-8 -*- - from chrysacase import ChrysalideTestCase -from pychrysalide import PluginModule -import gc +from pychrysalide.plugins import PluginModule class TestPlugin(ChrysalideTestCase): """TestCase for GPluginModule.""" - def testGarbageCollecting(self): - """Ensure the garbarge collector is working for plugin modules.""" - + def testPluginInfoImplementations(self): + """Retrieve plugin basic information provided by __init__().""" - class MyPG_1(PluginModule): + class MyPlugin(PluginModule): def __init__(self): + super().__init__('custom-name', desc='custom-desc', url='custom-url', version='0.0.1') - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } + my = MyPlugin() - super(MyPG_1, self).__init__(**interface) + self.assertEqual(my.name, 'custom-name') + self.assertEqual(my.desc, 'custom-desc') + self.assertEqual(my.version, '0.0.1') + self.assertEqual(my.url, 'custom-url') - pg = MyPG_1() - self.assertIsNotNone(pg) + def testPluginMethodImplementations(self): + """Ensure required plugins abstract methods can be implemented.""" - - class MyPG_2(PluginModule): + class MyWrongPlugin(PluginModule): def __init__(self): + super().__init__('pg-name') - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } - - super(MyPG_2, self).__init__(**interface) + my = MyWrongPlugin() + with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_filename'"): + print(my.filename) - pg = MyPG_2() - self.assertIsNotNone(pg) + with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_modname'"): + print(my.modname) - class MyPG_3(PluginModule): + class MyPlugin(PluginModule): def __init__(self): + super().__init__('pg-name') - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } + def _get_filename(self): + return 'file-name' - super(MyPG_3, self).__init__(**interface) + def _get_modname(self): + return 'mod-name' + my = MyPlugin() - pg = MyPG_3() - self.assertIsNotNone(pg) + self.assertEqual(my.filename, 'file-name') + self.assertEqual(my.modname, 'mod-name') - class MyPG_4(PluginModule): - - def __init__(self): - - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } - super(MyPG_4, self).__init__(**interface) + def testPluginRequirementIncludePython(self): + """Ensure that plugin requirements include the Python bindings.""" - - pg = MyPG_4() - self.assertIsNotNone(pg) - - - class MyPG_5(PluginModule): + class MyPlugin(PluginModule): def __init__(self): + super().__init__('pg-name') - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } - - super(MyPG_5, self).__init__(**interface) - - - pg = MyPG_5() - self.assertIsNotNone(pg) + my = MyPlugin() + self.assertEqual(len(my.requirements), 1) + self.assertEqual(my.requirements[0], 'PyChrysalide') - gc.collect() + def testPluginRequirementUniqueness(self): + """Ensure that plugin requirements are unique.""" - def testCreation(self): - """Validate PluginModule creation from Python.""" - - - class MyPG_0(PluginModule): - pass - - - # TypeError: Required argument 'name' (pos 1) not found - with self.assertRaises(TypeError): - pg = MyPG_0() - - - class MyPG_1(PluginModule): + class MyPlugin(PluginModule): def __init__(self): + super().__init__('pg-name', required=[ 'PyChrysalide' ]) - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } - - super(MyPG_1, self).__init__(**interface) + my = MyPlugin() + self.assertEqual(my.requirements.count('PyChrysalide'), 1) - pg = MyPG_1() - self.assertIsNotNone(pg) - - class MyPG_2(PluginModule): + class MyPlugin2(PluginModule): def __init__(self): + super().__init__('pg-name2', required=[ 'AA', 'BB', 'AA' ]) - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( 'ABC', ) - } - - super(MyPG_2, self).__init__(**interface) - - - # TypeError: Invalid type for plugin action. - with self.assertRaises(TypeError): - pg = MyPG_2() - - - class MyPG_3(PluginModule): - - def __init__(self): - - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( PluginModule.PGA_CONTENT_EXPLORER, ) - } - - super(MyPG_3, self).__init__(**interface) - - - # TypeError: missing features for the declared actions. - with self.assertRaises(TypeError): - pg = MyPG_3() - - - class MyPG_4(PluginModule): - - def __init__(self): - - interface = { - 'name' : 'some_name4', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( PluginModule.PGA_CONTENT_EXPLORER, ) - } - - super(MyPG_4, self).__init__(**interface) - - def handle_binary_content(self, action, content, wid, status): - pass - - - pg = MyPG_4() - self.assertIsNotNone(pg) - - - def testDoubleUsage(self): - """Validate PluginModule double usage in Python.""" - - - class MyPG(PluginModule): - - def __init__(self): - - interface = { - 'name' : 'some_name', - 'desc' : 'Provide some information about the useless plugin', - 'version' : '0.1', - 'actions' : ( ) - } - - super(MyPG, self).__init__(**interface) - - - pg1 = MyPG() - self.assertIsNotNone(pg1) + my = MyPlugin2() - pg2 = MyPG() - self.assertIsNotNone(pg2) + self.assertEqual(my.requirements.count('AA'), 1) + self.assertEqual(my.requirements.count('PyChrysalide'), 1) diff --git a/tests/plugins/python.py b/tests/plugins/python.py new file mode 100644 index 0000000..1a3dd97 --- /dev/null +++ b/tests/plugins/python.py @@ -0,0 +1,27 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.plugins import PythonPlugin + + +class TestPlugin(ChrysalideTestCase): + """TestCase for GPythonPlugin.""" + + + def testPluginInfoImplementations(self): + """Retrieve plugin basic information provided by __init__().""" + + class MyPlugin(PythonPlugin): + """Custom description.""" + + def __init__(self): + super().__init__(__file__, '0.0.1', 'custom-url') + + my = MyPlugin() + + self.assertEqual(my.name, 'MyPlugin') + self.assertEqual(my.desc, 'Custom description.') + self.assertEqual(my.version, '0.0.1') + self.assertEqual(my.url, 'custom-url') + + self.assertEqual(my.filename, __file__) + self.assertEqual(my.modname, 'python') |