forked from VSoftTechnologies/Delphi-Mocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Delphi.Mocks.Validation.pas
53 lines (41 loc) · 1.61 KB
/
Delphi.Mocks.Validation.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
unit Delphi.Mocks.Validation;
interface
uses
typInfo;
type
TMocksValidation = class(TObject)
class procedure CheckMockType(const ATypeInfo : PTypeInfo); static;
class procedure CheckMockInterface(const ATypeInfo : PTypeInfo); static;
class procedure CheckMockObject(const ATypeInfo : PTypeInfo); static;
end;
implementation
uses
Delphi.Mocks.Utils,
Delphi.Mocks;
{ MocksValidation }
class procedure TMocksValidation.CheckMockInterface(const ATypeInfo : PTypeInfo);
begin
//Check to make sure we have
if not CheckInterfaceHasRTTI(ATypeInfo) then
raise EMockNoRTTIException.Create(ATypeInfo.NameStr + ' does not have RTTI, specify {$M+} for the interface to enabled RTTI');
end;
class procedure TMocksValidation.CheckMockObject(const ATypeInfo: PTypeInfo);
begin
//Check to make sure we have
if not CheckClassHasRTTI(ATypeInfo) then
raise EMockNoRTTIException.Create(ATypeInfo.NameStr + ' does not have RTTI, specify {$M+} for the object to enabled RTTI');
end;
class procedure TMocksValidation.CheckMockType(const ATypeInfo: PTypeInfo);
begin
if not (ATypeInfo.Kind in [tkInterface,tkClass]) then
raise EMockException.Create(ATypeInfo.NameStr + ' is not an Interface or Class. TMock<T> supports interfaces and classes only');
case ATypeInfo.Kind of
//NOTE: We have a weaker requirement for an object proxy opposed to an interface proxy.
//NOTE: Object proxy doesn't require more than zero methods on the object.
tkClass : CheckMockObject(ATypeInfo);
tkInterface : CheckMockInterface(ATypeInfo);
else
raise EMockException.Create('Invalid type kind T');
end;
end;
end.