1 | unit FormTests;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
|
---|
7 | ActnList, Menus, TestCase, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormTests }
|
---|
12 |
|
---|
13 | TFormTests = class(TFormEx)
|
---|
14 | ARun: TAction;
|
---|
15 | AShow: TAction;
|
---|
16 | ActionList1: TActionList;
|
---|
17 | ButtonRun: TButton;
|
---|
18 | LabelResult: TLabel;
|
---|
19 | ListViewTestCases: TListView;
|
---|
20 | MenuItem1: TMenuItem;
|
---|
21 | MenuItem2: TMenuItem;
|
---|
22 | PopupMenuTest: TPopupMenu;
|
---|
23 | procedure ARunExecute(Sender: TObject);
|
---|
24 | procedure AShowExecute(Sender: TObject);
|
---|
25 | procedure ButtonRunClick(Sender: TObject);
|
---|
26 | procedure FormShow(Sender: TObject);
|
---|
27 | procedure ListViewTestCasesData(Sender: TObject; Item: TListItem);
|
---|
28 | procedure ListViewTestCasesSelectItem(Sender: TObject; Item: TListItem;
|
---|
29 | Selected: Boolean);
|
---|
30 | private
|
---|
31 | FTestCases: TTestCases;
|
---|
32 | procedure ReloadList;
|
---|
33 | procedure SetTestCases(AValue: TTestCases);
|
---|
34 | procedure UpdateInterface;
|
---|
35 | public
|
---|
36 | property TestCases: TTestCases read FTestCases write SetTestCases;
|
---|
37 | end;
|
---|
38 |
|
---|
39 |
|
---|
40 | implementation
|
---|
41 |
|
---|
42 | {$R *.lfm}
|
---|
43 |
|
---|
44 | uses
|
---|
45 | FormTest;
|
---|
46 |
|
---|
47 | { TFormTests }
|
---|
48 |
|
---|
49 | procedure TFormTests.ListViewTestCasesData(Sender: TObject; Item: TListItem);
|
---|
50 | begin
|
---|
51 | if Item.Index < TestCases.Count then
|
---|
52 | with TestCases[Item.Index] do begin
|
---|
53 | Item.Caption := Name;
|
---|
54 | Item.Data := TestCases[Item.Index];
|
---|
55 | Item.SubItems.Add(ResultText[TestResult]);
|
---|
56 | end;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TFormTests.ListViewTestCasesSelectItem(Sender: TObject;
|
---|
60 | Item: TListItem; Selected: Boolean);
|
---|
61 | begin
|
---|
62 | UpdateInterface;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | procedure TFormTests.ReloadList;
|
---|
66 | begin
|
---|
67 | if Assigned(TestCases) then
|
---|
68 | ListViewTestCases.Items.Count := TestCases.Count
|
---|
69 | else ListViewTestCases.Items.Count := 0;
|
---|
70 | ListViewTestCases.Refresh;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | procedure TFormTests.SetTestCases(AValue: TTestCases);
|
---|
74 | begin
|
---|
75 | if FTestCases = AValue then Exit;
|
---|
76 | FTestCases := AValue;
|
---|
77 | ReloadList;
|
---|
78 | UpdateInterface;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | procedure TFormTests.UpdateInterface;
|
---|
82 | var
|
---|
83 | Selected: Boolean;
|
---|
84 | Passed: Integer;
|
---|
85 | Failed: Integer;
|
---|
86 | I: Integer;
|
---|
87 | begin
|
---|
88 | Selected := Assigned(ListViewTestCases.Selected);
|
---|
89 | ARun.Enabled := Selected;
|
---|
90 | AShow.Enabled := Selected;
|
---|
91 | ButtonRun.Enabled := Assigned(TestCases);
|
---|
92 |
|
---|
93 | Passed := 0;
|
---|
94 | Failed := 0;
|
---|
95 | if Assigned(TestCases) then
|
---|
96 | for I := 0 to TestCases.Count - 1 do begin
|
---|
97 | case TestCases[I].TestResult of
|
---|
98 | trPassed: Inc(Passed);
|
---|
99 | trFailed: Inc(Failed);
|
---|
100 | end;
|
---|
101 | end;
|
---|
102 | LabelResult.Caption := SPassed + ' ' + IntToStr(Passed) + ', ' +
|
---|
103 | SFailed + ' ' + IntToStr(Failed);
|
---|
104 | end;
|
---|
105 |
|
---|
106 | procedure TFormTests.ButtonRunClick(Sender: TObject);
|
---|
107 | var
|
---|
108 | I: Integer;
|
---|
109 | begin
|
---|
110 | for I := 0 to TestCases.Count - 1 do
|
---|
111 | TestCases[I].Run;
|
---|
112 | ReloadList;
|
---|
113 | UpdateInterface;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TFormTests.AShowExecute(Sender: TObject);
|
---|
117 | begin
|
---|
118 | if Assigned(ListViewTestCases.Selected) then
|
---|
119 | with TFormTest.Create(nil) do
|
---|
120 | try
|
---|
121 | MemoLog.Text := TTestCase(ListViewTestCases.Selected.Data).Log;
|
---|
122 | ShowModal;
|
---|
123 | finally
|
---|
124 | Free;
|
---|
125 | end;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TFormTests.ARunExecute(Sender: TObject);
|
---|
129 | begin
|
---|
130 | if Assigned(ListViewTestCases.Selected) then begin
|
---|
131 | TTestCase(ListViewTestCases.Selected.Data).Run;
|
---|
132 | ReloadList;
|
---|
133 | UpdateInterface;
|
---|
134 | end;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TFormTests.FormShow(Sender: TObject);
|
---|
138 | begin
|
---|
139 | ReloadList;
|
---|
140 | UpdateInterface;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | end.
|
---|
144 |
|
---|