diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mangling/itanium.py | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/mangling/itanium.py b/tests/mangling/itanium.py new file mode 100644 index 0000000..6bb49d3 --- /dev/null +++ b/tests/mangling/itanium.py @@ -0,0 +1,111 @@ +#!/usr/bin/python3-dbg +# -*- coding: utf-8 -*- + + +# Tests validant le décodage des types et des routines pour le format Itanium + + +from chrysacase import ChrysalideTestCase +from pychrysalide.mangling import ItaniumDemangler + + +class TestItaniumMangling(ChrysalideTestCase): + """TestCase for pychrysalide.mangling.ItaniumDemangler.""" + + def check_demangling(self, got, expected): + """Check a given demangling result.""" + + self.assertEqual(str(got), expected) + + + def testItaniumTypeMangling(self): + """Check Itanium type demangling with specifications samples.""" + + # https://itanium-cxx-abi.github.io/cxx-abi/abi-examples.html#mangling + + demangler = ItaniumDemangler() + + demangled = demangler.decode_type('_ZN3FooIA4_iE3barE') + self.check_demangling(demangled, 'Foo<int[4]>::bar') + + demangled = demangler.decode_type('_ZN1N1fE') + self.check_demangling(demangled, 'N::f') + + demangled = demangler.decode_type('_ZN5Arena5levelE') + self.check_demangling(demangled, 'Arena::level') + + demangled = demangler.decode_type('_ZN5StackIiiE5levelE') + self.check_demangling(demangled, 'Stack<int, int>::level') + + + def testItaniumRoutineMangling(self): + """Check Itanium routine demangling with specifications samples.""" + + # https://itanium-cxx-abi.github.io/cxx-abi/abi-examples.html#mangling + + demangler = ItaniumDemangler() + + demangled = demangler.decode_routine('_Z1fv') + self.check_demangling(demangled, '??? f(void)') + + demangled = demangler.decode_routine('_Z1fi') + self.check_demangling(demangled, '??? f(int)') + + demangled = demangler.decode_routine('_Z3foo3bar') + self.check_demangling(demangled, '??? foo(bar)') + + demangled = demangler.decode_routine('_Zrm1XS_') + self.check_demangling(demangled, '??? operator%(X, X)') + + demangled = demangler.decode_routine('_ZplR1XS0_') + self.check_demangling(demangled, '??? operator+(X &, X &)') + + demangled = demangler.decode_routine('_ZlsRK1XS1_') + self.check_demangling(demangled, '??? operator<<(const X &, const X &)') + + demangled = demangler.decode_routine('_Z1fIiEvi') + self.check_demangling(demangled, 'void f<int>(int)') + + demangled = demangler.decode_routine('_Z5firstI3DuoEvS0_') + self.check_demangling(demangled, 'void first<Duo>(Duo)') + + demangled = demangler.decode_routine('_Z5firstI3DuoEvT_') + self.check_demangling(demangled, 'void first<Duo>(Duo)') + + demangled = demangler.decode_routine('_Z3fooIiPFidEiEvv') + self.check_demangling(demangled, 'void foo<int, int (*) (double), int>(void)') + + demangled = demangler.decode_routine('_ZN6System5Sound4beepEv') + self.check_demangling(demangled, '??? System::Sound::beep(void)') + + demangled = demangler.decode_routine('_Z1fI1XEvPVN1AIT_E1TE') + self.check_demangling(demangled, 'void f<X>(volatile A<X>::T *)') + + demangled = demangler.decode_routine('_ZngILi42EEvN1AIXplT_Li2EEE1TE') + self.check_demangling(demangled, 'void operator-<42>(A<42+2>::T)') + + demangled = demangler.decode_routine('_Z4makeI7FactoryiET_IT0_Ev') + self.check_demangling(demangled, 'Factory<int> make<Factory, int>(void)') + + demangled = demangler.decode_routine('_Z3foo5Hello5WorldS0_S_') + self.check_demangling(demangled, '??? foo(Hello, World, World, Hello)') + + demangled = demangler.decode_routine('_ZlsRSoRKSs') + self.check_demangling(demangled, '??? operator<<(std::ostream &, const std::string &)') + + + def testItaniumRoutineManglingInside(self): + """Check Itanium routine demangling examples within the specifications.""" + + # http://refspecs.linuxbase.org/cxxabi-1.83.html#linkage + + demangler = ItaniumDemangler() + + demangled = demangler.decode_routine('_Z1fM1AKFvvE') + self.check_demangling(demangled, '??? f(const void (A::*) (void))') + + demangled = demangler.decode_routine('_Z1fPFvvEM1SFvvE') + self.check_demangling(demangled, '??? f(void (*) (void), void (S::*) (void))') + + demangled = demangler.decode_routine('_ZN1N1TIiiE2mfES0_IddE') + self.check_demangling(demangled, '??? N::T<int, int>::mf(N::T<double, double>)') |