Changeset 8 for trunk


Ignore:
Timestamp:
Aug 20, 2022, 8:22:00 AM (2 years ago)
Author:
chronos
Message:
  • Added: Update multiple test.
  • Modified: Simplified tests structure.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SVNZero.lpr

    r7 r8  
    3131    with TTestCases.Create do
    3232    try
    33 {      AddNew('Add', TTestCaseAdd);
     33      AddNew('Add', TTestCaseAdd);
    3434      AddNew('Update', TTestCaseUpdate);
    3535      AddNew('Modify', TTestCaseModify);
    3636      AddNew('Delete', TTestCaseDelete);
    37  }     AddNew('Merge', TTestCaseMerge);
     37      AddNew('Merge', TTestCaseMerge);
     38      AddNew('Update multiple', TTestCaseUpdateMultiple);
    3839      Run;
    3940    finally
  • trunk/USvnZero.pas

    r5 r8  
    1010  { TSvnZero }
    1111
    12   TSvnZero = class(TExecute)
     12  TSvnZero = class(TSubversion)
    1313  private
    1414    Subversion: TSubversion;
  • trunk/UTest.pas

    r7 r8  
    44
    55uses
    6   Classes, SysUtils, USubversion, FileUtil, Generics.Collections;
     6  Classes, SysUtils, FileUtil, Generics.Collections;
    77
    88type
     
    1616    TestResult: TTestResult;
    1717    Log: string;
     18    procedure Initialize; virtual;
    1819    procedure Run; virtual;
     20    procedure Finalize; virtual;
    1921    procedure Evaluate(Passed: Boolean);
    2022    procedure Pass;
     
    3234  end;
    3335
    34   { TTestCaseSvn }
    35 
    36   TTestCaseSvn = class(TTestCase)
    37   private
    38     Subversion: TExecute;
    39     SubversionAdmin: TSubversionAdmin;
    40     function CheckError(Text: string): Boolean;
    41   protected
    42     RepoDir: string;
    43     WorkDir: string;
    44     TestDir: string;
    45     procedure Svn(Parameters: array of string);
    46     procedure SvnAdmin(Parameters: array of string);
    47   public
    48     procedure Run; override;
    49     constructor Create; override;
    50     destructor Destroy; override;
    51   end;
    5236
    5337resourcestring
     
    6448
    6549implementation
    66 
    67 uses
    68   USvnZero;
    6950
    7051procedure Translate;
     
    9172{ TTestCase }
    9273
     74procedure TTestCase.Initialize;
     75begin
     76end;
     77
    9378procedure TTestCase.Run;
     79begin
     80end;
     81
     82procedure TTestCase.Finalize;
    9483begin
    9584end;
     
    129118  Passed: Integer;
    130119  Failed: Integer;
    131   LastDir: string;
    132120begin
    133121  for I := 0 to Count - 1 do
    134122  with Items[I] do begin
    135123    WriteLn('== ' + Name + ' ======= ');
    136     LastDir := GetCurrentDir;
     124    Initialize;
    137125    Run;
    138     ChDir(LastDir);
     126    Finalize;
    139127  end;
    140128
     
    151139end;
    152140
    153 { TTestCaseSvn }
    154 
    155 procedure TTestCaseSvn.Svn(Parameters: array of string);
    156 begin
    157   Subversion.ExecuteOutput(Parameters);
    158   if CheckError(Subversion.ErrorOutput) then
    159     TestResult := trFailed;
    160 end;
    161 
    162 procedure TTestCaseSvn.SvnAdmin(Parameters: array of string);
    163 begin
    164   SubversionAdmin.ExecuteOutput(Parameters);
    165   if CheckError(SubversionAdmin.ErrorOutput) then
    166     TestResult := trFailed;
    167 end;
    168 
    169 function TTestCaseSvn.CheckError(Text: string): Boolean;
    170 begin
    171   Result := Pos('svn: E', Text) > 0;
    172 end;
    173 
    174 procedure TTestCaseSvn.Run;
    175 begin
    176   ChDir(TestDir);
    177 end;
    178 
    179 constructor TTestCaseSvn.Create;
    180 begin
    181   TestDir := GetTempDir(False) + 'SVNZero';
    182   ForceDirectories(TestDir);
    183   RepoDir := TestDir + DirectorySeparator + 'Repo';
    184   WorkDir := TestDir + DirectorySeparator + 'Work';
    185   //Subversion := TSubversion.Create;
    186   Subversion := TSvnZero.Create;
    187   SubversionAdmin := TSubversionAdmin.Create;
    188 end;
    189 
    190 destructor TTestCaseSvn.Destroy;
    191 begin
    192   FreeAndNil(SubversionAdmin);
    193   FreeAndNil(Subversion);
    194   inherited;
    195 end;
    196 
    197141end.
    198142
  • trunk/UTestCases.pas

    r7 r8  
    44
    55uses
    6   Classes, SysUtils, FileUtil, UTest;
     6  Classes, SysUtils, FileUtil, UTest, USubversion;
    77
    88type
     9  { TTestCaseSvn }
     10
     11  TTestCaseSvn = class(TTestCase)
     12  private
     13    Subversion: TExecute;
     14    SubversionAdmin: TSubversionAdmin;
     15    function CheckError(Text: string): Boolean;
     16  protected
     17    LastDir: string;
     18    RepoDir: string;
     19    WorkDir: string;
     20    TestDir: string;
     21    procedure Svn(Parameters: array of string);
     22    procedure SvnAdmin(Parameters: array of string);
     23  public
     24    procedure Initialize; override;
     25    procedure Run; override;
     26    procedure Finalize; override;
     27    constructor Create; override;
     28    destructor Destroy; override;
     29  end;
     30
     31  { TTestCaseAdd }
     32
    933  TTestCaseAdd = class(TTestCaseSvn)
    1034    procedure Run; override;
    1135  end;
    1236
     37  { TTestCaseModify }
     38
    1339  TTestCaseModify = class(TTestCaseSvn)
    1440    procedure Run; override;
    1541  end;
    1642
     43  { TTestCaseUpdate }
     44
    1745  TTestCaseUpdate = class(TTestCaseSvn)
    1846    procedure Run; override;
    1947  end;
    2048
     49  { TTestCaseDelete }
     50
    2151  TTestCaseDelete = class(TTestCaseSvn)
    2252    procedure Run; override;
     
    2959  end;
    3060
     61  { TTestCaseUpdateMultiple }
     62
     63  TTestCaseUpdateMultiple = class(TTestCaseSvn)
     64    procedure Run; override;
     65  end;
    3166
    3267implementation
    3368
    34 { TTestCaseMerge }
    35 
    36 procedure TTestCaseMerge.Run;
    37 var
    38   TestFile: string;
    39 begin
    40   TestFile := 'TestFile.txt';
     69uses
     70  USvnZero;
     71
     72{ TTestCaseSvn }
     73
     74procedure TTestCaseSvn.Svn(Parameters: array of string);
     75begin
     76  Subversion.ExecuteOutput(Parameters);
     77  if CheckError(Subversion.ErrorOutput) then
     78    TestResult := trFailed;
     79end;
     80
     81procedure TTestCaseSvn.SvnAdmin(Parameters: array of string);
     82begin
     83  SubversionAdmin.ExecuteOutput(Parameters);
     84  if CheckError(SubversionAdmin.ErrorOutput) then
     85    TestResult := trFailed;
     86end;
     87
     88procedure TTestCaseSvn.Initialize;
     89begin
     90  inherited;
     91  LastDir := GetCurrentDir;
     92  ChDir(TestDir);
    4193  SvnAdmin(['create', RepoDir]);
    4294  Svn(['checkout', 'file:///' + RepoDir, WorkDir]);
    4395  ChDir(WorkDir);
     96end;
     97
     98function TTestCaseSvn.CheckError(Text: string): Boolean;
     99begin
     100  Result := Pos('svn: E', Text) > 0;
     101end;
     102
     103procedure TTestCaseSvn.Run;
     104begin
     105end;
     106
     107procedure TTestCaseSvn.Finalize;
     108begin
     109  ChDir(LastDir);
     110  DeleteDirectory(WorkDir, False);
     111  DeleteDirectory(RepoDir, False);
     112  inherited;
     113end;
     114
     115constructor TTestCaseSvn.Create;
     116begin
     117  TestDir := GetTempDir(False) + 'SVNZero';
     118  ForceDirectories(TestDir);
     119  RepoDir := TestDir + DirectorySeparator + 'Repo';
     120  WorkDir := TestDir + DirectorySeparator + 'Work';
     121  //Subversion := TSubversion.Create;
     122  Subversion := TSvnZero.Create;
     123  SubversionAdmin := TSubversionAdmin.Create;
     124end;
     125
     126destructor TTestCaseSvn.Destroy;
     127begin
     128  FreeAndNil(SubversionAdmin);
     129  FreeAndNil(Subversion);
     130  inherited;
     131end;
     132
     133{ TTestCaseMerge }
     134
     135procedure TTestCaseMerge.Run;
     136var
     137  TestFile: string;
     138begin
     139  TestFile := 'TestFile.txt';
    44140  SaveStringToFile('First line' + LineEnding + 'Second line' + LineEnding + 'Third line', TestFile);
    45141  Svn(['add', TestFile]);
     
    51147  Svn(['update', TestFile]);
    52148  Svn(['commit', '-m', '"Commit message 3"']);
    53   DeleteDirectory(WorkDir, False);
    54   DeleteDirectory(RepoDir, False);
    55149  Evaluate(True);
    56150end;
     
    61155begin
    62156  TestFile := 'TestFile.txt';
    63   SvnAdmin(['create', RepoDir]);
    64   Svn(['checkout', 'file:///' + RepoDir, WorkDir]);
    65   ChDir(WorkDir);
    66   SaveStringToFile('Some text', TestFile);
    67   Svn(['add', TestFile]);
    68   Svn(['commit', '-m', '"Commit message"']);
    69   DeleteDirectory(WorkDir, False);
    70   DeleteDirectory(RepoDir, False);
     157  SaveStringToFile('Some text', TestFile);
     158  Svn(['add', TestFile]);
     159  Svn(['commit', '-m', '"Commit message"']);
    71160  Evaluate(True);
    72161end;
     
    77166begin
    78167  TestFile := 'TestFile.txt';
    79   SvnAdmin(['create', RepoDir]);
    80   Svn(['checkout', 'file:///' + RepoDir, WorkDir]);
    81   ChDir(WorkDir);
    82168  SaveStringToFile('Some text', TestFile);
    83169  Svn(['add', TestFile]);
     
    85171  SaveStringToFile('Different text', TestFile);
    86172  Svn(['commit', '-m', '"Commit message 2"']);
    87   DeleteDirectory(WorkDir, False);
    88   DeleteDirectory(RepoDir, False);
    89173  Evaluate(True);
    90174end;
     
    95179begin
    96180  TestFile := 'TestFile.txt';
    97   SvnAdmin(['create', RepoDir]);
    98   Svn(['checkout', 'file:///' + RepoDir, WorkDir]);
    99   ChDir(WorkDir);
    100181  SaveStringToFile('Some text', TestFile);
    101182  Svn(['add', TestFile]);
     
    104185  Svn(['commit', '-m', '"Commit message 2"']);
    105186  Svn(['update', '-r', '1', TestFile]);
     187  Svn(['update', '-r', '2', TestFile]);
    106188  Svn(['update']);
    107   DeleteDirectory(WorkDir, False);
    108   DeleteDirectory(RepoDir, False);
    109189  Evaluate(True);
    110190end;
     
    115195begin
    116196  TestFile := 'TestFile.txt';
    117   SvnAdmin(['create', RepoDir]);
    118   Svn(['checkout', 'file:///' + RepoDir, WorkDir]);
    119   ChDir(WorkDir);
    120197  SaveStringToFile('Some text', TestFile);
    121198  Svn(['add', TestFile]);
     
    123200  Svn(['delete', TestFile]);
    124201  Svn(['commit', '-m', '"Commit message 2"']);
    125   DeleteDirectory(WorkDir, False);
    126   DeleteDirectory(RepoDir, False);
    127   Evaluate(True);
    128 end;
    129 
     202  Evaluate(True);
     203end;
     204
     205procedure TTestCaseUpdateMultiple.Run;
     206var
     207  I: Integer;
     208const
     209  Count = 20;
     210begin
     211  for I := 0 to Count - 1 do begin
     212    SaveStringToFile('Some text', 'TestFile' + IntToStr(I) + '.txt');
     213    Svn(['add', 'TestFile' + IntToStr(I) + '.txt']);
     214  end;
     215  Svn(['commit', '-m', '"Commit message"']);
     216  for I := 0 to Count - 1 do
     217    SaveStringToFile('Different text', 'TestFile' + IntToStr(I) + '.txt');
     218  Svn(['commit', '-m', '"Commit message 2"']);
     219  Svn(['update', '-r', '1']);
     220  Svn(['update', '-r', '2']);
     221  Svn(['update']);
     222  Evaluate(True);
     223end;
    130224
    131225end.
Note: See TracChangeset for help on using the changeset viewer.