Permalink
Browse files

Major rework of implements functionality. Some tests not working, don…

…'t merge into upstream yet.

The main issue with the previous implementation was that it fought with Delphi's Generics implementation too much. There is a major need for interface generic methods in the way I previously worked this.
Now this has been simplified so that the proxy does not know how to create its child proxies, its just given them. Its the TMock<T> record which knows how to achieve adding new proxies.

There are some access violations in some tests due to this change. Pushing to code to another branch so that I can work on it later.
  • Loading branch information...
staticcat committed Jul 11, 2014
1 parent 6b84025 commit a6d838ab52ec61619bd9110618b1ddc1b1d1b4cc
View
@@ -68,6 +68,7 @@ TValueHelper = record helper for TValue
TRttiTypeHelper = class helper for TRttiType
function TryGetMethod(const AName: string; out AMethod: TRttiMethod): Boolean;
function FindConstructor : TRttiMethod;
end;
function CompareValue(const Left, Right: TValue): Integer;
@@ -342,6 +343,21 @@ function TValueHelper.IsWord: Boolean;
{ TRttiTypeHelper }
function TRttiTypeHelper.FindConstructor: TRttiMethod;
var
candidateCtor: TRttiMethod;
begin
Result := nil;
for candidateCtor in GetMethods('Create') do
begin
if Length(candidateCtor.GetParameters) = 0 then
begin
Result := candidateCtor;
Break;
end;
end;
end;
function TRttiTypeHelper.TryGetMethod(const AName: string; out AMethod: TRttiMethod): Boolean;
begin
AMethod := GetMethod(AName);

This file was deleted.

Oops, something went wrong.
@@ -34,27 +34,27 @@ interface
Generics.Collections,
Delphi.Mocks,
Delphi.Mocks.Interfaces,
Delphi.Mocks.ProxyBase,
Delphi.Mocks.Proxy,
Delphi.Mocks.VirtualMethodInterceptor;
type
TObjectProxy<T> = class(TBaseProxy<T>)
TObjectProxy<T> = class(TProxy<T>)
private
FInstance : T;
FVMInterceptor : TVirtualMethodInterceptor;
function FindConstructor(ARttiType: TRttiType): TRttiMethod;
protected
procedure DoBefore(Instance: TObject; Method: TRttiMethod; const Args: TArray<TValue>; out DoInvoke: Boolean; out Result: TValue);
function Proxy : T; override;
procedure Implements(const ATypeInfo: PTypeInfo); override;
procedure DoBefore(Instance: TObject; Method: TRttiMethod; const Args: TArray<TValue>; out DoInvoke: Boolean; out Result: TValue);
function Proxy : T; override;
public
constructor Create(const AIsStubOnly : boolean = false);override;
destructor Destroy;override;
constructor Create(const AIsStubOnly : boolean = false); override;
destructor Destroy; override;
end;
implementation
uses
Delphi.Mocks.Helpers;
{ TObjectProxy<T> }
constructor TObjectProxy<T>.Create(const AIsStubOnly : boolean);
@@ -70,7 +70,7 @@ constructor TObjectProxy<T>.Create(const AIsStubOnly : boolean);
if rType = nil then
raise EMockNoRTTIException.Create('No TypeInfo found for T');
ctor := FindConstructor(rType);
ctor := rType.FindConstructor;
if ctor = nil then
raise EMockException.Create('Could not find constructor Create on type ' + rType.Name);
@@ -120,28 +120,6 @@ procedure TObjectProxy<T>.DoBefore(Instance: TObject; Method: TRttiMethod; const
end;
end;
function TObjectProxy<T>.FindConstructor(ARttiType: TRttiType): TRttiMethod;
var
candidateCtor: TRttiMethod;
begin
Result := nil;
for candidateCtor in ARttiType.GetMethods('Create') do
begin
if Length(candidateCtor.GetParameters) = 0 then
begin
Result := candidateCtor;
Break;
end;
end;
end;
procedure TObjectProxy<T>.Implements(const ATypeInfo: PTypeInfo);
begin
inherited;
{$Message 'TODO: Need to implement mock objects also implementing interfaces'}
raise ENotImplemented.Create('Mock Objects Implementing Interfaces has not been implemented.');
end;
function TObjectProxy<T>.Proxy: T;
begin
result := FInstance;
Oops, something went wrong.

0 comments on commit a6d838a

Please sign in to comment.