Changeset 94 for trunk


Ignore:
Timestamp:
Feb 3, 2022, 10:53:30 PM (3 years ago)
Author:
chronos
Message:
  • Added: Validation tests for contact properties.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormTest.pas

    r92 r94  
    115115
    116116procedure TFormTest.FormCreate(Sender: TObject);
     117const
     118  VCardVersion = 'VERSION:2.1';
    117119begin
    118120  TestCases := TTestCases.Create;
     
    120122    with TTestCaseLoadSave(AddNew('Load and save', TTestCaseLoadSave)) do begin
    121123      Input := VCardBegin + LineEnding +
    122         'VERSION:2.1' + LineEnding +
     124        VCardVersion + LineEnding +
    123125        'N:Surname;Name' + LineEnding +
    124126        'FN:Name Surname' + LineEnding +
     
    128130    with TTestCaseLoadSave(AddNew('Long text', TTestCaseLoadSave)) do begin
    129131      Input := VCardBegin + LineEnding +
    130         'VERSION:2.1' + LineEnding +
     132        VCardVersion + LineEnding +
    131133        'NOTE:This is some long test which is really multi-lined each line is on d' + LineEnding +
    132134        ' ifferent line so it is on multiple lines.' + LineEnding +
     
    136138    with TTestCaseLoadSave(AddNew('Multi-line', TTestCaseLoadSave)) do begin
    137139      Input := VCardBegin + LineEnding +
    138         'VERSION:2.1' + LineEnding +
     140        VCardVersion + LineEnding +
    139141        'NOTE:First line\nsecond line\nempty line\n\nlast line' + LineEnding +
    140142        VCardEnd + LineEnding;
    141143      Output := Input;
    142144    end;
    143     AddNew('Encoding base64', TTestCaseLoadSave);
    144     AddNew('Encoding quoted-printable', TTestCaseLoadSave);
    145     AddNew('Image format', TTestCaseLoadSave);
     145    //AddNew('Encoding base64', TTestCaseLoadSave);
     146    //AddNew('Encoding quoted-printable', TTestCaseLoadSave);
     147    //AddNew('Image format', TTestCaseLoadSave);
    146148    with TTestCaseLoadSave(AddNew('Empty', TTestCaseLoadSave)) do begin
    147149      Input := '';
     
    154156    with TTestCaseLoadSave(AddNew('Missing end', TTestCaseLoadSave)) do begin
    155157      Input := VCardBegin + LineEnding +
    156         'VERSION:2.1' + LineEnding +
     158        VCardVersion + LineEnding +
    157159        'N:Surname;Name' + LineEnding +
    158160        'FN:Name Surname' + LineEnding;
     
    160162    end;
    161163    with TTestCaseLoadSave(AddNew('Missing start', TTestCaseLoadSave)) do begin
    162       Input := 'VERSION:2.1' + LineEnding +
     164      Input := VCardVersion + LineEnding +
    163165        'N:Surname;Name' + LineEnding +
    164166        'FN:Name Surname' + LineEnding +
    165167        VCardEnd + LineEnding;
    166168      Output := '';
     169    end;
     170    with TTestCaseCheckProperty(AddNew('Propery FN', TTestCaseCheckProperty)) do begin
     171      Index := cfFullName;
     172      Value := 'Name Surname';
     173      Input := VCardBegin + LineEnding +
     174        VCardVersion + LineEnding +
     175        'FN:' + Value + LineEnding +
     176        VCardEnd + LineEnding;
     177    end;
     178    with TTestCaseCheckProperty(AddNew('Escaped new lines in text', TTestCaseCheckProperty)) do begin
     179      Index := cfNote;
     180      Value := 'Line' + #13#10 + 'Line';
     181      Input := VCardBegin + LineEnding +
     182        VCardVersion + LineEnding +
     183        'NOTE:Line\nLine' + LineEnding +
     184        VCardEnd + LineEnding;
     185    end;
     186    with TTestCaseCheckProperty(AddNew('Compound value', TTestCaseCheckProperty)) do begin
     187      Index := cfFirstName;
     188      Value := 'FirstName';
     189      Input := VCardBegin + LineEnding +
     190        VCardVersion + LineEnding +
     191        'N:Surname;FirstName;;;' + LineEnding +
     192        VCardEnd + LineEnding;
    167193    end;
    168194  end;
  • trunk/UTest.pas

    r91 r94  
    66
    77uses
    8   Classes, SysUtils, fgl;
     8  Classes, SysUtils, fgl, UContact;
    99
    1010type
     
    1919    Log: string;
    2020    procedure Run; virtual;
     21    procedure Evaluate(Passed: Boolean);
     22    procedure Pass;
     23    procedure Fail;
    2124  end;
    2225
     
    3538    Output: string;
    3639    procedure Run; override;
    37     procedure Evaluate(Passed: Boolean);
     40  end;
     41
     42  { TTestCaseCheckProperty }
     43
     44  TTestCaseCheckProperty = class(TTestCase)
     45    Input: string;
     46    ContactIndex: Integer;
     47    Index: TContactFieldIndex;
     48    Value: string;
     49    procedure Run; override;
    3850  end;
    3951
     
    4456implementation
    4557
    46 uses
    47   UContact;
     58{ TTestCaseCheckProperty }
     59
     60procedure TTestCaseCheckProperty.Run;
     61var
     62  Lines: TStringList;
     63  PropertyValue: string;
     64begin
     65  Lines := TStringList.Create;
     66  try
     67    with TContactsFile.Create do
     68    try
     69      Lines.Text := Input;
     70      LoadFromStrings(Lines);
     71      if ContactIndex < Contacts.Count then begin
     72        PropertyValue := Contacts[ContactIndex].Fields[Index];
     73        Evaluate(PropertyValue = Value);
     74      end else Fail;
     75      Log := 'Expected:' + LineEnding +
     76        '"' + Value + '"' + LineEnding + LineEnding +
     77        'Output:' + LineEnding +
     78        '"' + PropertyValue + '"';
     79    finally
     80      Free;
     81    end;
     82  finally
     83    Lines.Free;
     84  end;
     85end;
    4886
    4987{ TTestCaseLoadSave }
     
    62100      SaveToStrings(Lines);
    63101      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;
     102      Log := 'Expected:' + LineEnding +
     103        '"' + Output + '"' + LineEnding + LineEnding +
     104        'Output:' + LineEnding +
     105        '"' + Lines.Text + '"';
    70106    finally
    71107      Free;
     
    76112end;
    77113
    78 procedure TTestCaseLoadSave.Evaluate(Passed: Boolean);
     114{ TTestCase }
     115
     116procedure TTestCase.Run;
     117begin
     118end;
     119
     120procedure TTestCase.Evaluate(Passed: Boolean);
    79121begin
    80122  if Passed then Result := trPassed
     
    82124end;
    83125
    84 { TTestCase }
     126procedure TTestCase.Pass;
     127begin
     128  Result := trPassed;
     129end;
    85130
    86 procedure TTestCase.Run;
     131procedure TTestCase.Fail;
    87132begin
    88 
     133  Result := trFailed;
    89134end;
    90135
Note: See TracChangeset for help on using the changeset viewer.