Changeset 91 for trunk/UTest.pas


Ignore:
Timestamp:
Feb 2, 2022, 4:33:25 PM (3 years ago)
Author:
chronos
Message:
  • Added: A windows for showing log output for selected test case.
  • Added: Various load-save tests.
  • Modified: Improved parsing vCard format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTest.pas

    r90 r91  
    1414
    1515  TTestCase = class
     16  public
    1617    Name: string;
    1718    Result: TTestResult;
    18     procedure Run;
     19    Log: string;
     20    procedure Run; virtual;
    1921  end;
     22
     23  TTestCaseClass = class of TTestCase;
    2024
    2125  { TTestCases }
    2226
    2327  TTestCases = class(TFPGObjectList<TTestCase>)
    24     function AddNew(Name: string): TTestCase;
     28    function AddNew(Name: string; TestClass: TTestCaseClass): TTestCase;
    2529  end;
    2630
     31  { TTestCaseLoadSave }
     32
     33  TTestCaseLoadSave = class(TTestCase)
     34    Input: string;
     35    Output: string;
     36    procedure Run; override;
     37    procedure Evaluate(Passed: Boolean);
     38  end;
     39
     40const
     41  ResultText: array[TTestResult] of string = ('None', 'Passed', 'Failed');
     42
     43
    2744implementation
     45
     46uses
     47  UContact;
     48
     49{ TTestCaseLoadSave }
     50
     51procedure TTestCaseLoadSave.Run;
     52var
     53  Lines: TStringList;
     54begin
     55  Lines := TStringList.Create;
     56  try
     57    with TContactsFile.Create do
     58    try
     59      Lines.Text := Input;
     60      LoadFromStrings(Lines);
     61      Lines.Text := '';
     62      SaveToStrings(Lines);
     63      Evaluate(Lines.Text = Output);
     64      if Result <> trPassed then begin
     65        Log := 'Expected:' + LineEnding +
     66          '"' + Output + '"' + LineEnding + LineEnding +
     67          'Output:' + LineEnding +
     68          '"' + Lines.Text + '"';
     69      end;
     70    finally
     71      Free;
     72    end;
     73  finally
     74    Lines.Free;
     75  end;
     76end;
     77
     78procedure TTestCaseLoadSave.Evaluate(Passed: Boolean);
     79begin
     80  if Passed then Result := trPassed
     81    else Result := trFailed;
     82end;
    2883
    2984{ TTestCase }
     
    3691{ TTestCases }
    3792
    38 function TTestCases.AddNew(Name: string): TTestCase;
     93function TTestCases.AddNew(Name: string; TestClass: TTestCaseClass): TTestCase;
    3994begin
    40   Result := TTestCase.Create;
     95  Result := TestClass.Create;
    4196  Result.Name := Name;
    4297  Add(Result);
Note: See TracChangeset for help on using the changeset viewer.