Mocking TRttiProperty results in AV

Issue #23 resolved
Former user created an issue

Hi folks,

I am trying to mock TRttiProperty, but the setup fails when I try to mock properties like Name, Visibility or IsReadable and results in an AccessViolation.

I am totally clueless what went wrong. Maybe someone is able to catch what I am doing wrong here, I attached a sample Project using DUnitX (latest master) and DSharp (latest master).

Thanks in advance & Kind Regards, Aleks

Comments (4)

  1. Former user Account Deleted

    Using Delphi-Mocks helped me out, there I get an "Abstract Error" because the getters of the properties I tried to mock are abstract (what I did not recognize). Maybe its possible in DSharp to throw such an exception as well?

  2. Stefan Glienke repo owner

    The issue is that the calculation of how many virtual methods the class has was wrong because all of them are private. Abstract methods can be mocked just fine if they contain RTTI (which is not the case for private and protected methods unless specified otherwise which is not possible for RTL classes unless you recompile them).

    There might be a way to make private virtual getters and setters mockable though given they have a "known" signature. But that requires some more investigation.

  3. Log in to comment