| 1 | unit Test;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, TestCase, Project;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TTestCaseActionKind = (akCheckout, akCreate, akUpdate, akCommit, akAddFile,
|
|---|
| 10 | akRemoveFile);
|
|---|
| 11 |
|
|---|
| 12 | { TTestCaseLoadSave }
|
|---|
| 13 |
|
|---|
| 14 | { TTestCaseBasic }
|
|---|
| 15 |
|
|---|
| 16 | TTestCaseBasic = class(TTestCase)
|
|---|
| 17 | Input: string;
|
|---|
| 18 | ExpectedOutput: string;
|
|---|
| 19 | Action: TTestCaseActionKind;
|
|---|
| 20 | Project: TProject;
|
|---|
| 21 | TestDir: string;
|
|---|
| 22 | TestFile: string;
|
|---|
| 23 | procedure Run; override;
|
|---|
| 24 | constructor Create; override;
|
|---|
| 25 | destructor Destroy; override;
|
|---|
| 26 | end;
|
|---|
| 27 |
|
|---|
| 28 | function InitTestCases: TTestCases;
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | implementation
|
|---|
| 32 |
|
|---|
| 33 | uses
|
|---|
| 34 | Subversion, Core, VCS;
|
|---|
| 35 |
|
|---|
| 36 | resourcestring
|
|---|
| 37 | SExpected = 'Expected:';
|
|---|
| 38 | SOutput = 'Output:';
|
|---|
| 39 | SExport = 'Export:';
|
|---|
| 40 |
|
|---|
| 41 | function InitTestCases: TTestCases;
|
|---|
| 42 | begin
|
|---|
| 43 | Result := TTestCases.Create;
|
|---|
| 44 | with Result do begin
|
|---|
| 45 | with TTestCaseBasic(AddNew('Create repository', TTestCaseBasic)) do begin
|
|---|
| 46 | Action := akCreate;
|
|---|
| 47 | ExpectedOutput := LineEnding;
|
|---|
| 48 | end;
|
|---|
| 49 | with TTestCaseBasic(AddNew('Checkout working copy', TTestCaseBasic)) do begin
|
|---|
| 50 | Action := akCheckout;
|
|---|
| 51 | ExpectedOutput := 'Checked out revision 0.' + LineEnding + LineEnding;
|
|---|
| 52 | end;
|
|---|
| 53 | with TTestCaseBasic(AddNew('Update from remote server', TTestCaseBasic)) do begin
|
|---|
| 54 | Action := akUpdate;
|
|---|
| 55 | ExpectedOutput := 'Updating ''.'':' + LineEnding +
|
|---|
| 56 | 'At revision 0.' + LineEnding + LineEnding;
|
|---|
| 57 | end;
|
|---|
| 58 | with TTestCaseBasic(AddNew('Add new file', TTestCaseBasic)) do begin
|
|---|
| 59 | Action := akAddFile;
|
|---|
| 60 | ExpectedOutput := 'A (bin) ' + TestFile + LineEnding + LineEnding;
|
|---|
| 61 | end;
|
|---|
| 62 | with TTestCaseBasic(AddNew('Commit', TTestCaseBasic)) do begin
|
|---|
| 63 | Action := akCommit;
|
|---|
| 64 | ExpectedOutput := 'Adding (bin) ' + TestFile + LineEnding +
|
|---|
| 65 | 'Transmitting file data .done' + LineEnding +
|
|---|
| 66 | 'Committing transaction...' + LineEnding +
|
|---|
| 67 | 'Committed revision 1.' + LineEnding + LineEnding;
|
|---|
| 68 | end;
|
|---|
| 69 | with TTestCaseBasic(AddNew('Remove', TTestCaseBasic)) do begin
|
|---|
| 70 | Action := akRemoveFile;
|
|---|
| 71 | ExpectedOutput := 'Deleting ' + TestFile + LineEnding +
|
|---|
| 72 | 'Committing transaction...' + LineEnding +
|
|---|
| 73 | 'Committed revision 2.' + LineEnding + LineEnding;
|
|---|
| 74 | end;
|
|---|
| 75 | end;
|
|---|
| 76 | end;
|
|---|
| 77 |
|
|---|
| 78 | { TTestCaseBasic }
|
|---|
| 79 |
|
|---|
| 80 | procedure TTestCaseBasic.Run;
|
|---|
| 81 | var
|
|---|
| 82 | NewFile: TFileStream;
|
|---|
| 83 | Output: string;
|
|---|
| 84 | begin
|
|---|
| 85 | //RemoveDir(TestDir);
|
|---|
| 86 | //RemoveDir(Project.Directory);
|
|---|
| 87 |
|
|---|
| 88 | if Action = akCreate then begin
|
|---|
| 89 | Project.RepositoryURL := TestDir + DirectorySeparator + 'repo';
|
|---|
| 90 | Project.Repository.Init;
|
|---|
| 91 | Output := Project.Repository.ExecutionOutput.Text;
|
|---|
| 92 | end else
|
|---|
| 93 | if Action = akCheckout then begin
|
|---|
| 94 | Project.RepositoryURL := URLFromDirectory(TestDir + DirectorySeparator + 'repo', False);
|
|---|
| 95 | Project.WorkingCopy.Checkout;
|
|---|
| 96 | Output := Project.WorkingCopy.ExecutionOutput.Text;
|
|---|
| 97 | end else
|
|---|
| 98 | if Action = akUpdate then begin
|
|---|
| 99 | Project.WorkingCopy.Update;
|
|---|
| 100 | Output := Project.WorkingCopy.ExecutionOutput.Text;
|
|---|
| 101 | end else
|
|---|
| 102 | if Action = akAddFile then begin
|
|---|
| 103 | NewFile := TFileStream.Create(TestDir + DirectorySeparator + 'work' + DirectorySeparator + TestFile, fmCreate);
|
|---|
| 104 | NewFile.Size := 10000;
|
|---|
| 105 | NewFile.Free;
|
|---|
| 106 | Project.WorkingCopy.Add(TestFile);
|
|---|
| 107 | Output := Project.WorkingCopy.ExecutionOutput.Text;
|
|---|
| 108 | end else
|
|---|
| 109 | if Action = akCommit then begin
|
|---|
| 110 | Project.WorkingCopy.Commit('Test commit message');
|
|---|
| 111 | Output := Project.WorkingCopy.ExecutionOutput.Text;
|
|---|
| 112 | end else
|
|---|
| 113 | if Action = akRemoveFile then begin
|
|---|
| 114 | Project.WorkingCopy.Remove(TestFile);
|
|---|
| 115 | Project.WorkingCopy.Commit('Test commit message 2');
|
|---|
| 116 | Output := Project.WorkingCopy.ExecutionOutput.Text;
|
|---|
| 117 | end else
|
|---|
| 118 | raise Exception.Create('Unsupported test case action');
|
|---|
| 119 |
|
|---|
| 120 | Evaluate(Output = ExpectedOutput);
|
|---|
| 121 | Log := SExpected + LineEnding +
|
|---|
| 122 | '"' + ExpectedOutput + '"' + LineEnding + LineEnding +
|
|---|
| 123 | SOutput + LineEnding +
|
|---|
| 124 | '"' + Output + '"';
|
|---|
| 125 | end;
|
|---|
| 126 |
|
|---|
| 127 | constructor TTestCaseBasic.Create;
|
|---|
| 128 | begin
|
|---|
| 129 | inherited;
|
|---|
| 130 | Project := TProject.Create;
|
|---|
| 131 | Project.Backend := TBackendSubversion.Create;
|
|---|
| 132 | TestDir := GetTempDir(False);
|
|---|
| 133 | if not TestDir.EndsWith(DirectorySeparator) then TestDir := TestDir + DirectorySeparator;
|
|---|
| 134 | TestDir := TestDir + 'Test' + DirectorySeparator + Project.Backend.Name;
|
|---|
| 135 | Project.WorkingCopy.UserName := Core.Core.UserName;
|
|---|
| 136 | Project.WorkingCopy.Email := Core.Core.Email;
|
|---|
| 137 | Project.Repository.SilentExecution := True;
|
|---|
| 138 | Project.WorkingCopy.SilentExecution := True;
|
|---|
| 139 | Project.Directory := TestDir + DirectorySeparator + 'work';
|
|---|
| 140 | ForceDirectories(Project.Directory);
|
|---|
| 141 | ForceDirectories(TestDir);
|
|---|
| 142 | TestFile := 'TestFile.bin';
|
|---|
| 143 | end;
|
|---|
| 144 |
|
|---|
| 145 | destructor TTestCaseBasic.Destroy;
|
|---|
| 146 | begin
|
|---|
| 147 | FreeAndNil(Project);
|
|---|
| 148 | inherited;
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | end.
|
|---|
| 152 |
|
|---|