123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import itertools
- from typing import Iterable
- import itanium_demangler as dm
- import pytest
- import smgdc.demangler_helpers as dh
- @pytest.mark.parametrize(
- "input_vtsym,input_fnsym,expected",
- [
- (
-
- "_ZTV14CEntityFactoryI10CGunTargetE",
- "_ZN14CEntityFactoryI10CGunTargetE6CreateEPKc",
- True,
- ),
- (
-
- "_ZTVN6google8protobuf10TextFormat6Parser10ParserImpl20ParserErrorCollectorE",
- "_ZN6google8protobuf10TextFormat6Parser10ParserImpl20ParserErrorCollector8AddErrorEiiRKSs",
- True,
- ),
- (
-
- "_ZTV13CTFBaseRocket",
- "_Z13GetScriptDescI11CBasePlayerEP17ScriptClassDesc_tPT_",
- False,
- ),
- (
-
- "_ZTVN6google8protobuf10TextFormat17FieldValuePrinterE",
- "_ZN6google8protobuf10TextFormat6Parser10ParserImpl20ParserErrorCollector10AddWarningEiiRKSs",
- False,
- ),
- (
-
- "_ZTV14CEntityFactoryI19CTFProjectile_FlareE",
- "_ZN19CTFProjectile_Flare14GetDataDescMapEv",
- False,
- ),
- ],
- )
- def test_function_in_virtual_class(input_vtsym: str, input_fnsym: str, expected: bool):
- """
- Checks if the function is for the vtable's class.
- Note that, obviously, this does not check that the function is actually in the vtable.
- """
- node_vtsym, node_fnsym = map(dm.parse, (input_vtsym, input_fnsym))
- vtable_typename = dh.extract_vtable_typename(node_vtsym)
- function_qualname = dh.extract_function_name(node_fnsym)
- assert (vtable_typename == function_qualname[: len(vtable_typename)]) == expected
- @pytest.mark.parametrize(
- "fnsym_a,fnsym_b,expected",
- [
- (
-
- "_ZN11CBaseEntity10ChangeTeamEi",
- "_ZN9CTFPlayer10ChangeTeamEi",
- True,
- ),
- (
-
- "_ZN9CTFPlayer16GetAttributeListEv",
- "_ZThn4764_N9CTFPlayer16GetAttributeListEv",
- True,
- ),
- (
-
- "_ZN9CTFPlayer10ChangeTeamEi",
- "_ZN9CTFPlayer10ChangeTeamEibbb",
- False,
- ),
- (
-
- "_ZN12CTFGameRules27TrackWorkshopMapsInMapCycleEv",
- "_ZN12CTFGameRules16LoadMapCycleFileEv",
- False,
- ),
- (
-
- "_Z11DataMapInitI14SoundCommand_tEP9datamap_tPT_",
- "_Z11DataMapInitI10CKothLogicEP9datamap_tPT_",
- False,
- ),
- ],
- )
- def test_function_match_signature(fnsym_a: str, fnsym_b: str, expected: bool):
- sig_a, sig_b = map(dh.extract_method_signature, map(dm.parse, (fnsym_a, fnsym_b)))
- assert expected == (sig_a == sig_b)
- @pytest.mark.parametrize(
- "fnsyms,expected",
- [
- (
-
- (
- "_ZN11CBaseEntity8KeyValueEPKcS1_",
- "_ZN11CBaseEntity8KeyValueEPKcf",
- "_ZN11CBaseEntity8KeyValueEPKcRK6Vector",
- ),
- True,
- ),
- (
-
- (
- "_ZN24CTFWeaponBaseGrenadeProj11InitGrenadeERK6VectorS2_P20CBaseCombatCharacterRK13CTFWeaponInfo",
- "_ZN24CTFWeaponBaseGrenadeProj11InitGrenadeERK6VectorS2_P20CBaseCombatCharacterif",
- ),
- True,
- ),
- (
-
- (
- "_ZN20CBaseCombatCharacter8FVisibleEP11CBaseEntityiPS1_",
- "_ZN11CBaseEntity8FVisibleERK6VectoriPPS_",
- ),
- True,
- ),
- ],
- )
- def test_function_overloaded(fnsyms: Iterable[str], expected: bool):
- """
- Tests that all the given symbols are overloads of the same name.
- Of course, this is only inference based on symbol name.
- """
- node_syms = map(dh.extract_method_fname, map(dm.parse, fnsyms))
- assert all(a == b for a, b in itertools.permutations(node_syms, 2))
|