Changeset 8 for trunk/UTestCases.pas


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

Legend:

Unmodified
Added
Removed
  • 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.