tests: added test for cfgscript lcl

git-svn-id: trunk@40754 -
This commit is contained in:
mattias 2013-04-08 22:07:00 +00:00
parent c0f42ef5b4
commit 92fd214b1a

View File

@ -1,7 +1,8 @@
{
Test with:
./runtests --format=plain --suite=TTestCodetoolsCfgScript
./runtests --format=plain --suite=TestCfgScript
./runtests --format=plain --suite=TestCfgScriptBase
./runtests --format=plain --suite=TestCfgScriptLCL
}
unit TestCfgScript;
@ -21,17 +22,19 @@ type
TTestCodetoolsCfgScript = class(TTestCase)
protected
procedure TestResult(Script, ExpectedResult: string);
procedure TestResult(Script, ExpectedResult: string; Vars: PCTCfgScriptVariables = nil);
procedure TestSyntaxError(Script, ExpectedError: string);
published
procedure TestCfgScript;
procedure TestCfgScriptBase;
procedure TestCfgScriptLCL;
end;
implementation
{ TTestCodetoolsCfgScript }
procedure TTestCodetoolsCfgScript.TestResult(Script, ExpectedResult: string);
procedure TTestCodetoolsCfgScript.TestResult(Script, ExpectedResult: string;
Vars: PCTCfgScriptVariables);
var
Engine: TCTConfigScriptEngine;
ScriptResult: String;
@ -40,6 +43,8 @@ begin
Engine:=TCTConfigScriptEngine.Create;
try
Engine.MaxErrorCount:=1;
if Vars<>nil then
Engine.Variables.Assign(Vars^);
if not Engine.Execute(Script) then begin
writeln('Script failed to run:');
for i:=0 to Engine.ErrorCount-1 do
@ -51,6 +56,8 @@ begin
Engine.Variables.WriteDebugReport('Variables');
AssertEquals(Script,ExpectedResult,ScriptResult);
end;
if Vars<>nil then
Vars^.Assign(Engine.Variables);
finally
Engine.Free;
end;
@ -75,7 +82,7 @@ begin
end;
end;
procedure TTestCodetoolsCfgScript.TestCfgScript;
procedure TTestCodetoolsCfgScript.TestCfgScriptBase;
begin
TestResult('Result:=2;','2');
TestResult('a:=2; b:=a; Result:=b;','2');
@ -89,6 +96,44 @@ begin
TestSyntaxError('{invalid operator * }Result:=2*3;','expected ; of statement, but found *');
end;
procedure TTestCodetoolsCfgScript.TestCfgScriptLCL;
var
Vars: TCTCfgScriptVariables;
begin
Vars:=TCTCfgScriptVariables.Create;
try
Vars['TargetOS']:='wince';
Vars['TargetCPU']:='arm';
Vars['SrcOS2']:='';
Vars['SrcOS']:='win';
TestResult(
'// LCLWidgetType'#10
+'if undefined(LCLWidgetType) then begin'#10
+' //if GetIDEValue(''OS'')=TargetOS then begin'#10
+' // use the same widgettype as the IDE'#10
+' //LCLWidgetType := GetIDEValue(''LCLWidgetType'');'#10
+' //if LCLWidgetType=''nogui'' then'#10
+' //LCLWidgetType:='''';'#10
+' //end;'#10
+' if (LCLWidgetType='''') or undefined(LCLWidgetType) then begin'#10
+' if (TargetOS=''win32'') or (TargetOS=''win64'') then'#10
+' LCLWidgetType := ''win32'''#10
+' else if TargetOS=''wince'' then'#10
+' LCLWidgetType := ''wince'''#10
+' else if TargetOS=''darwin'' then'#10
+' LCLWidgetType := ''carbon'''#10
+' else'#10
+' LCLWidgetType:=''gtk2'';'#10
+' end;'#10
+'end;'#10
,'',@Vars);
//Vars.WriteDebugReport('LCL',' ');
AssertEquals('LCLWidgetType','wince',Vars['LCLWidgetType']);
finally
Vars.Free;
end;
end;
initialization
AddToCodetoolsTestSuite(TTestCodetoolsCfgScript);