понедельник, 16 марта 2015 г.

GUI-testing 11. GUI-testing "in the spoken style". How this thing is organised №2

Original in Russian: http://18delphi.blogspot.ru/2013/11/gui-2.html

GUI-testing. Table of contents

Now I’d like to tell about how TscriptCode and TscriptContext are organised.

For that we should recollect the following:

Reference counting and TRefcounted:
http://18delphi.blogspot.com/2015/02/containers-1-implementation-of.html

Abstract containers:
http://18delphi.blogspot.com/2015/02/containers-6-abstract-containers.html.
http://18delphi.blogspot.com/2015/02/containers-7-abstract-containers-part-2.html.

The “lucky owners” of ARC and generic's are happy. They can do it in a different way. But this thing (as said Feynman (https://en.wikipedia.org/wiki/Richard_Feynman) the readers can do on their own.

On the one hand, TscriptCode is a descendant of TRefcounted and, on the other hand, adds itself to the list of the references on TscriptKeyWord.

So:

interface
 
  TscriptKeyWord = class(TRefcounted)
   procedure DoIt(aContext: TscriptContext); virtual; abstract;
    {* - code of the word execution.}
  end;//TscriptKeyWord
 
  _ItemType_ = TscriptKeyWord;
  _List_Parent_ = TRefcounted;
 
  {$Include _List_.imp.pas}
 
  TscriptCode = class(_List_)
   procedure CompileInteger(aValue: Integer);
   procedure CompileString(const aValue: String);
   procedure CompileKeyWord(aValue: TscriptKeyWord);
   procedure Run; // - executes the compiled code
   procedure RunInContext(aContext: TscriptContext); // - executes the compiled code in the specified context
   ...
  end;//TscriptCode
 
implementation
 
function IsSame(const A: _ItemType_;
  const B: _ItemType_): Boolean;
begin
 Result := (A = B);
end;//IsSame
 
procedure FreeItem(var thePlace: _ItemType_);
begin
 FreeAndNil(thePlace);
end;//FreeItem
  
procedure FillItem(var thePlace: _ItemType_;
  const aFrom: _ItemType_);
begin
 thePlace := aFrom.Use;
end;//FillItem
 
{$Include List.imp.pas}
 
procedure TscriptCode.CompileKeyWord(aValue: TscriptKeyWord);
begin
 Self.Add(aValue);
end;
 
procedure TscriptCode.Run;
var
 l_Context: TscriptContext;
begin
 l_Context := TscriptContext.Create;
 try
  RunInContext(l_Context);
 finally
  FreeAndNil(l_Context);
 end;//try..finally
end;
 
procedure TscriptCode.RunInContext(aContext: TscriptContext);
var
 l_Index : Integer;
begin
 for l_Index := 0 to Pred(Self.Count) do
  Self.Items[l_Index].DoIt(aContext); // - we execute every compiled word
end;
 
type
 TkwInteger = class(TscriptKeyWord)
  private
   f_Value : Integer;
  protected
   procedure DoIt(aContext: TscriptContext); override;
  public
   constructor Create(aValue : Integer);
 end;//TkwInteger
 
procedure TkwInteger.DoIt(aContext: TscriptContext);
begin
 aContext.PushInteger(f_Value);
end;
 
constructor TkwIntegerCreate(aValue : Integer);
begin
 inherited Create;
 f_Value := aValue;
end;
 
procedure TscriptCode.CompileInteger(aValue: Integer);
var
 l_Integer : TkwInteger;
begin
 l_Integer := TkwInteger.Create(aValue);
 try
  CompileKeyWord(l_Integer);
 finally
  FreeAndNil(l_Integer);
 end;//try..finally
end;
 
type
 TkwString = class(TscriptKeyWord)
  private
   f_Value : String;
  protected
   procedure DoIt(aContext: TscriptContext); override;
  public
   constructor Create(const aValue : String);
 end;//TkwString
 
procedure TkwString.DoIt(aContext: TscriptContext);
begin
 aContext.PushString(f_Value);
end;
 
constructor TkwString.Create(const aValue : String);
begin
 inherited Create;
 f_Value := aValue;
end;
 
procedure TscriptCode.CompileString(const aValue: String);
var
 l_String : TkwString;
begin
 l_String := TkwString.Create(aValue);
 try
  CompileKeyWord(l_String);
 finally
  FreeAndNil(l_String);
 end;//try..finally
end;

I’m all done and can’t write about TscriptContext. I’ve been distracted by RTTI. It is late hour…

I’ll continue to tell about TscriptContext in the next series. Actually, it is banal, of course. “The stack”. But – not exactly…

Комментариев нет:

Отправить комментарий