source: trunk/Forms/UFormTest.pas

Last change on this file was 19, checked in by chronos, 7 years ago
  • Fixed: Build under Lazarus 1.8.0.
  • Modified: Updated Common package.
File size: 3.1 KB
Line 
1unit UFormTest;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 StdCtrls, LazFileUtils;
10
11type
12 { TFormTest }
13
14 TFormTest = class(TForm)
15 ButtonStart: TButton;
16 ComboBox1: TComboBox;
17 Label1: TLabel;
18 ListView1: TListView;
19 procedure ButtonStartClick(Sender: TObject);
20 procedure FormShow(Sender: TObject);
21 private
22 OperationItem: TListItem;
23 OperationTimeStart: TDateTime;
24 procedure OperationStart(Name: string);
25 procedure OperationStop;
26 public
27 { public declarations }
28 end;
29
30var
31 FormTest: TFormTest;
32
33implementation
34
35{$R *.lfm}
36
37uses
38 UCore, UBackend, UProject, UVCS;
39
40{ TFormTest }
41
42procedure TFormTest.FormShow(Sender: TObject);
43var
44 I: Integer;
45begin
46 ComboBox1.Clear;
47 for I := 0 to Core.Backends.Count - 1 do
48 ComboBox1.AddItem(TBackend(Core.Backends[I]).Name, Core.Backends[I]);
49 if ComboBox1.Items.Count > 0 then
50 ComboBox1.ItemIndex := 0;
51
52end;
53
54procedure TFormTest.OperationStart(Name: string);
55begin
56 OperationItem := ListView1.Items.Add;
57 OperationItem.Caption := Name;
58 OperationTimeStart := Now;
59end;
60
61procedure TFormTest.OperationStop;
62begin
63 OperationItem.SubItems.Add(TimeToStr(Now - OperationTimeStart));
64 OperationItem := nil;
65end;
66
67procedure TFormTest.ButtonStartClick(Sender: TObject);
68var
69 Project: TProject;
70 TestDir: string;
71 TestFile: string;
72 NewFile: TFileStream;
73 Comment: TStringList;
74begin
75 ListView1.Items.Clear;
76 Project := TProject.Create;
77 Project.Backend := TBackend(Core.Backends[ComboBox1.ItemIndex]);
78 Project.WorkingCopy.UserName := Core.UserName;
79 Project.WorkingCopy.Email := Core.Email;
80 try
81 //RemoveDir(TestDir);
82
83 TestDir := TestDir + DirectorySeparator + Project.Backend.Name;
84 ForceDirectoriesUTF8(TestDir);
85
86 OperationStart('Create repository');
87 Project.RepositoryURL := TestDir + DirectorySeparator + 'repo';
88 Project.Repository.Init;
89 OperationStop;
90
91 OperationStart('Checkout working copy');
92 Project.Directory := TestDir + DirectorySeparator + 'work';
93 Project.RepositoryURL := URLFromDirectory(TestDir + DirectorySeparator + 'repo', True);
94 Project.WorkingCopy.Checkout;
95 OperationStop;
96
97 OperationStart('Update working copy');
98 Project.WorkingCopy.Update;
99 OperationStop;
100
101 OperationStart('Add file');
102 ForceDirectoriesUTF8(TestDir + DirectorySeparator + 'work');
103 TestFile := 'TestFile.bin';
104 NewFile := TFileStream.Create(TestDir + DirectorySeparator + 'work' + DirectorySeparator + TestFile, fmCreate);
105 NewFile.Size := 10000;
106 NewFile.Free;
107 Project.WorkingCopy.Add(TestFile);
108 OperationStop;
109
110 OperationStart('Commit working copy');
111 Comment := TStringList.Create;
112 Comment.Text := 'Test commit message';
113 Project.WorkingCopy.Commit(Comment);
114 Comment.Free;
115 OperationStop;
116
117 OperationStart('Remove file');
118 Project.WorkingCopy.Remove(TestFile);
119 OperationStop;
120
121 OperationStart('Commit working copy');
122 Comment := TStringList.Create;
123 Comment.Text := 'Test commit message 2';
124 Project.WorkingCopy.Commit(Comment);
125 Comment.Free;
126 OperationStop;
127 finally
128 Project.Free;
129 end;
130end;
131
132end.
133
Note: See TracBrowser for help on using the repository browser.