ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test11.pas
Revision: 380
Committed: Mon Jan 10 10:13:17 2022 UTC (2 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 3981 byte(s)
Log Message:
propset for eol-style

File Contents

# Content
1 (*
2 * IBX Test suite. This program is used to test the IBX non-visual
3 * components and provides a semi-automated pass/fail check for each test.
4 *
5 * The contents of this file are subject to the Initial Developer's
6 * Public License Version 1.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain a copy
8 * of the License here:
9 *
10 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
11 *
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing rights
15 * and limitations under the License.
16 *
17 * The Initial Developer of the Original Code is Tony Whyman.
18 *
19 * The Original Code is (C) 2021 Tony Whyman, MWA Software
20 * (http://www.mwasoftware.co.uk).
21 *
22 * All Rights Reserved.
23 *
24 * Contributor(s): ______________________________________.
25 *
26 *)
27 unit Test11;
28
29 {$mode objfpc}{$H+}
30
31 {Test 11: Event Handling}
32
33 { This tests calling an event handler in response to a database event.
34 A simple database is used consisting of a stored procedure only.
35 Two cases are tested: event registration before and after DB Open.
36 }
37
38 interface
39
40 uses
41 Classes, SysUtils, TestApplication, IBXTestBase, IB, IBEvents,
42 IBStoredProc;
43
44 const
45 aTestID = '11';
46 aTestTitle = 'Event Handling';
47
48 type
49
50 { TTest11 }
51
52 TTest11 = class(TIBXTestBase)
53 private
54 FEvents: TIBEvents;
55 FExecProc: TIBStoredProc;
56 procedure EventHandler( Sender: TObject; EventName: string; EventCount: longint;
57 var CancelAlerts: Boolean);
58 protected
59 procedure CreateObjects(Application: TTestApplication); override;
60 function GetTestID: AnsiString; override;
61 function GetTestTitle: AnsiString; override;
62 procedure InitTest; override;
63 public
64 procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
65 end;
66
67
68 implementation
69
70 { TTest11 }
71
72 procedure TTest11.EventHandler(Sender: TObject; EventName: string;
73 EventCount: longint; var CancelAlerts: Boolean);
74 begin
75 writeln(OutFile,'Event Handled: ',EventName, ', Count = ',EventCount);
76 end;
77
78 procedure TTest11.CreateObjects(Application: TTestApplication);
79 begin
80 inherited CreateObjects(Application);
81 FEvents := TIBEvents.Create(Application);
82 FEvents.Database := IBDatabase;
83 FEvents.OnEventAlert := @EventHandler;
84 FEvents.Events.Add('EVENT1');
85 FEvents.Events.Add('EVENT2');
86 FExecProc := TIBStoredProc.Create(Application);
87 FExecProc.Database := IBDatabase;
88 end;
89
90 function TTest11.GetTestID: AnsiString;
91 begin
92 Result := aTestID;
93 end;
94
95 function TTest11.GetTestTitle: AnsiString;
96 begin
97 Result := aTestTitle;
98 end;
99
100 procedure TTest11.InitTest;
101 begin
102 IBDatabase.DatabaseName := Owner.GetNewDatabaseName;
103 IBDatabase.CreateIfNotExists := true;
104 ReadWriteTransaction;
105 end;
106
107 procedure TTest11.RunTest(CharSet: AnsiString; SQLDialect: integer);
108 begin
109 writeln(OutFile,'Case #1: Deferred Event Registration');
110 FEvents.DeferredRegister := true;
111 IBDatabase.Connected := true;
112 try
113 IBTransaction.Active := true;
114 CheckSynchronize(1);
115 FExecProc.StoredProcName := 'CALLEVENT';
116 FExecProc.Prepare;
117 FExecProc.Params[0].AsString := 'EVENT1';
118 FExecProc.ExecProc;
119 writeln(OutFile,'Event Called');
120 IBTransaction.Commit;
121 CheckSynchronize(5);
122 finally
123 IBDatabase.DropDatabase;
124 end;
125 writeln(OutFile,'Case #2: Event Registration after DB Open');
126 IBDatabase.Connected := true;
127 try
128 FEvents.Registered := true;
129 IBTransaction.Active := true;
130 CheckSynchronize(1);
131 FExecProc.StoredProcName := 'CALLEVENT';
132 FExecProc.Prepare;
133 FExecProc.Params[0].AsString := 'EVENT2';
134 FExecProc.ExecProc;
135 writeln(OutFile,'Event Called');
136 IBTransaction.Commit;
137 CheckSynchronize(5);
138 Sleep(1000);
139 FEvents.UnRegisterEvents;
140 finally
141 IBDatabase.DropDatabase;
142 end;
143 end;
144
145 initialization
146 RegisterTest(TTest11);
147
148 end.
149

Properties

Name Value
svn:eol-style native