77 lines
1.9 KiB
ObjectPascal
77 lines
1.9 KiB
ObjectPascal
unit Unit1;
|
|
|
|
interface
|
|
|
|
uses
|
|
System.SysUtils,DUnitX.TestFramework,RuntimeBuilder,RuntimeBuilder.Fasm;
|
|
|
|
type
|
|
[TestFixture]
|
|
TRuntimeBuilderTestObject=class(TObject)
|
|
public
|
|
[TestCase]
|
|
procedure Test1();
|
|
[TestCase]
|
|
procedure Test2();
|
|
end;
|
|
|
|
implementation
|
|
|
|
procedure TRuntimeBuilderTestObject.Test1();
|
|
var
|
|
Fasm:TRTBFasmCompiler;
|
|
Src:TRTBSource;
|
|
Module:TRTBModule;
|
|
Func1,Func2:TRTBFunc;
|
|
Var1:TRTBVar;
|
|
begin
|
|
Fasm:=TRTBFasmCompiler.Create('..\..\..\lib\FasmOnDelphi\fasmw172\fasm');
|
|
Src:=Fasm.GenNewSrc;
|
|
Src.Text:='use32'+sLineBreak+'main:'+sLineBreak+'pop ecx'+sLineBreak+'pop eax'+sLineBreak+'jmp ecx'+sLineBreak+'Pmain dd 0'+
|
|
sLineBreak+'varmain:'+sLineBreak+'mov eax,[Pmain]'+sLineBreak+'ret';
|
|
Src.RegisterFunction('','main');
|
|
Src.RegisterFunction('','varmain');
|
|
Src.Register('','Pmain',TypeInfo(integer));
|
|
Module:=Src.Compilate;
|
|
Func1:=Module.Funtion['main'];
|
|
Func2:=Module.Funtion['varmain'];
|
|
if 454<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then
|
|
begin
|
|
raise Exception.Create('Error in test1');
|
|
end;
|
|
Var1:=Module.&Var['Pmain'];
|
|
Var1.Val:=454;
|
|
if 454<>Func2.Call(TypeInfo(integer),[],CRTBCallTypeStdCall).AsInteger then
|
|
begin
|
|
raise Exception.Create('Error in test1');
|
|
end;
|
|
FreeAndNil(Func1);
|
|
FreeAndNil(Src);
|
|
FreeAndNil(Fasm);
|
|
end;
|
|
|
|
procedure TRuntimeBuilderTestObject.Test2();
|
|
var
|
|
Fasm:TRTBFasmCompiler;
|
|
Src:TRTBSource;
|
|
Func1:TRTBFunc;
|
|
begin
|
|
{Fasm:=TRTBFasmCompiler.Create('..\..\..\FasmOnDelphi\fasmw172\fasm');
|
|
Src:=Fasm.GenNewSrc;
|
|
Src.LoadFromFile('..\..\testlib.fasm');
|
|
Fasm.LoadLib('W:\RuntimeBuilder\FasmOnDelphi\fasmw172\INCLUDE\win32a.inc');
|
|
lib:=Src.CompilateAsLib;
|
|
Func1:=lib.Funtion['MyEcho'];
|
|
if 234665<>Func1.Call(TypeInfo(integer),[234665],CRTBCallTypeStdCall).AsInteger then
|
|
begin
|
|
raise Exception.Create('Error in test2');
|
|
end;
|
|
FreeAndNil(Func1);
|
|
FreeAndNil(Src);
|
|
FreeAndNil(Fasm);}
|
|
end;
|
|
|
|
initialization
|
|
TDUnitX.RegisterTestFixture(TRuntimeBuilderTestObject);
|
|
end.
|