unit Test; interface uses Classes, SysUtils, TestCase, Project; type TTestCaseActionKind = (akCheckout, akCreate, akUpdate, akCommit, akAddFile, akRemoveFile); { TTestCaseLoadSave } { TTestCaseBasic } TTestCaseBasic = class(TTestCase) Input: string; ExpectedOutput: string; Action: TTestCaseActionKind; Project: TProject; TestDir: string; TestFile: string; procedure Run; override; constructor Create; override; destructor Destroy; override; end; function InitTestCases: TTestCases; implementation uses Subversion, Core, VCS; resourcestring SExpected = 'Expected:'; SOutput = 'Output:'; SExport = 'Export:'; function InitTestCases: TTestCases; begin Result := TTestCases.Create; with Result do begin with TTestCaseBasic(AddNew('Create repository', TTestCaseBasic)) do begin Action := akCreate; ExpectedOutput := LineEnding; end; with TTestCaseBasic(AddNew('Checkout working copy', TTestCaseBasic)) do begin Action := akCheckout; ExpectedOutput := 'Checked out revision 0.' + LineEnding + LineEnding; end; with TTestCaseBasic(AddNew('Update from remote server', TTestCaseBasic)) do begin Action := akUpdate; ExpectedOutput := 'Updating ''.'':' + LineEnding + 'At revision 0.' + LineEnding + LineEnding; end; with TTestCaseBasic(AddNew('Add new file', TTestCaseBasic)) do begin Action := akAddFile; ExpectedOutput := 'A (bin) ' + TestFile + LineEnding + LineEnding; end; with TTestCaseBasic(AddNew('Commit', TTestCaseBasic)) do begin Action := akCommit; ExpectedOutput := 'Adding (bin) ' + TestFile + LineEnding + 'Transmitting file data .done' + LineEnding + 'Committing transaction...' + LineEnding + 'Committed revision 1.' + LineEnding + LineEnding; end; with TTestCaseBasic(AddNew('Remove', TTestCaseBasic)) do begin Action := akRemoveFile; ExpectedOutput := 'Deleting ' + TestFile + LineEnding + 'Committing transaction...' + LineEnding + 'Committed revision 2.' + LineEnding + LineEnding; end; end; end; { TTestCaseBasic } procedure TTestCaseBasic.Run; var NewFile: TFileStream; Output: string; begin //RemoveDir(TestDir); //RemoveDir(Project.Directory); if Action = akCreate then begin Project.RepositoryURL := TestDir + DirectorySeparator + 'repo'; Project.Repository.Init; Output := Project.Repository.ExecutionOutput.Text; end else if Action = akCheckout then begin Project.RepositoryURL := URLFromDirectory(TestDir + DirectorySeparator + 'repo', False); Project.WorkingCopy.Checkout; Output := Project.WorkingCopy.ExecutionOutput.Text; end else if Action = akUpdate then begin Project.WorkingCopy.Update; Output := Project.WorkingCopy.ExecutionOutput.Text; end else if Action = akAddFile then begin NewFile := TFileStream.Create(TestDir + DirectorySeparator + 'work' + DirectorySeparator + TestFile, fmCreate); NewFile.Size := 10000; NewFile.Free; Project.WorkingCopy.Add(TestFile); Output := Project.WorkingCopy.ExecutionOutput.Text; end else if Action = akCommit then begin Project.WorkingCopy.Commit('Test commit message'); Output := Project.WorkingCopy.ExecutionOutput.Text; end else if Action = akRemoveFile then begin Project.WorkingCopy.Remove(TestFile); Project.WorkingCopy.Commit('Test commit message 2'); Output := Project.WorkingCopy.ExecutionOutput.Text; end else raise Exception.Create('Unsupported test case action'); Evaluate(Output = ExpectedOutput); Log := SExpected + LineEnding + '"' + ExpectedOutput + '"' + LineEnding + LineEnding + SOutput + LineEnding + '"' + Output + '"'; end; constructor TTestCaseBasic.Create; begin inherited; Project := TProject.Create; Project.Backend := TBackendSubversion.Create; TestDir := GetTempDir(False); if not TestDir.EndsWith(DirectorySeparator) then TestDir := TestDir + DirectorySeparator; TestDir := TestDir + 'Test' + DirectorySeparator + Project.Backend.Name; Project.WorkingCopy.UserName := Core.Core.UserName; Project.WorkingCopy.Email := Core.Core.Email; Project.Repository.SilentExecution := True; Project.WorkingCopy.SilentExecution := True; Project.Directory := TestDir + DirectorySeparator + 'work'; ForceDirectories(Project.Directory); ForceDirectories(TestDir); TestFile := 'TestFile.bin'; end; destructor TTestCaseBasic.Destroy; begin FreeAndNil(Project); inherited; end; end.