ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/testsuite/Test10.pas
(Generate patch)

Comparing:
ibx/trunk/fbintf/testsuite/Test10.pas (file contents), Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
ibx/branches/udr/testsuite/Test10.pas (file contents), Revision 396 by tony, Thu Feb 17 11:57:23 2022 UTC

# Line 1 | Line 1
1 + (*
2 + *  Firebird Interface (fbintf) Test suite. This program is used to
3 + *  test the Firebird Pascal Interface and provide a semi-automated
4 + *  pass/fail check for each test.
5 + *
6 + *  The contents of this file are subject to the Initial Developer's
7 + *  Public License Version 1.0 (the "License"); you may not use this
8 + *  file except in compliance with the License. You may obtain a copy
9 + *  of the License here:
10 + *
11 + *    http://www.firebirdsql.org/index.php?op=doc&id=idpl
12 + *
13 + *  Software distributed under the License is distributed on an "AS
14 + *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 + *  implied. See the License for the specific language governing rights
16 + *  and limitations under the License.
17 + *
18 + *  The Initial Developer of the Original Code is Tony Whyman.
19 + *
20 + *  The Original Code is (C) 2016 Tony Whyman, MWA Software
21 + *  (http://www.mwasoftware.co.uk).
22 + *
23 + *  All Rights Reserved.
24 + *
25 + *  Contributor(s): ______________________________________.
26 + *
27 + *)
28 +
29   unit Test10;
30 + {$IFDEF MSWINDOWS}
31 + {$DEFINE WINDOWS}
32 + {$ENDIF}
33  
34 < {$mode objfpc}{$H+}
34 > {$IFDEF FPC}
35 > {$mode delphi}
36   {$codepage utf8}
37 + {$ENDIF}
38  
39   {Test 10: Event Handling}
40  
# Line 25 | Line 58 | unit Test10;
58   interface
59  
60   uses
61 <  Classes, SysUtils, TestManager, IB;
61 >  Classes, SysUtils, TestApplication, FBTestApp, IB;
62  
63   type
64  
65   { TTest10 }
66  
67 <  TTest10 = class(TTestBase)
67 >  TTest10 = class(TFBTestBase)
68    private
69      FEventSignalled: boolean;
70      procedure EventsTest(Attachment: IAttachment);
71      procedure EventReport(Sender: IEvents);
72 +    procedure ShowEventReport;
73 +    procedure ShowEventCounts(Intf: IEvents);
74    public
75 <    function TestTitle: string; override;
76 <    procedure RunTest(CharSet: string; SQLDialect: integer); override;
75 >    function TestTitle: AnsiString; override;
76 >    procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
77    end;
78  
79  
# Line 51 | Line 86 | const
86  
87   procedure TTest10.EventsTest(Attachment: IAttachment);
88   var EventHandler: IEvents;
54    EventCounts: TEventCounts;
55    i: integer;
89      WaitCount: integer;
90   begin
91 +  FEventSignalled := false;
92    EventHandler := Attachment.GetEventHandler('TESTEVENT');
93    writeln(OutFile,'Call Async Wait');
94 <  EventHandler.AsyncWaitForEvent(@EventReport);
94 >  EventHandler.AsyncWaitForEvent(EventReport);
95    writeln(OutFile,'Async Wait Called');
96 <
96 >  sleep(500);
97 >  CheckSynchronize;
98 >  if FEventSignalled then
99 >  begin
100 >    writeln(OutFile,'First Event - usually ignored');
101 >    FEventSignalled := false;
102 >    EventHandler.AsyncWaitForEvent(EventReport);
103 >    sleep(100);
104 >    CheckSynchronize;
105 >    if FEventSignalled then
106 >    begin
107 >      writeln(OutFile,'Unexpected Event 1');
108 >      Exit;
109 >    end;
110 >  end;
111    writeln(OutFile,'Signal Event');
112    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
113 <  while not FEventSignalled do;
114 <  writeln(OutFile,'Event Signalled');
115 <  EventCounts := EventHandler.ExtractEventCounts;
116 <  for i := 0 to length(EventCounts) - 1 do
117 <    writeln(OutFile,'Event: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
113 >  while not FEventSignalled do
114 >  begin
115 >    Sleep(50);
116 >    CheckSynchronize;
117 >  end;
118 >  ShowEventCounts(EventHandler);
119    FEventSignalled := false;
120  
121    writeln(OutFile,'Two more events');
122    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
123    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
124 +  if FEventSignalled then
125 +  begin
126 +    writeln(OutFile,'Unexpected Event 2');
127 +    FEventSignalled := false
128 +  end;
129    writeln(OutFile,'Call Async Wait');
130 <  EventHandler.AsyncWaitForEvent(@EventReport);
130 >  EventHandler.AsyncWaitForEvent(EventReport);
131    writeln(OutFile,'Async Wait Called');
132 +  sleep(500);
133 +  CheckSynchronize;
134 +  if FEventSignalled then
135 +  begin
136 +    writeln(OutFile,'Deferred Events Caught');
137 +    ShowEventCounts(EventHandler);
138 +    FEventSignalled := false;
139 +    EventHandler.AsyncWaitForEvent(EventReport);
140 +    CheckSynchronize;
141 +    sleep(100);
142 +    if FEventSignalled then
143 +      writeln(OutFile,'Unexpected Event 3');
144 +  end;
145    writeln(OutFile,'Signal Event');
146    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
147    while not FEventSignalled do;
148 <  writeln(OutFile,'Event Signalled');
82 <  EventCounts := EventHandler.ExtractEventCounts;
83 <  for i := 0 to length(EventCounts) - 1 do
84 <    writeln(OutFile,'Event: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
148 >  ShowEventCounts(EventHandler);
149  
150    FEventSignalled := false;
151    writeln(OutFile,'Async Wait: Test Cancel');
152 <  EventHandler.AsyncWaitForEvent(@EventReport);
152 >  EventHandler.AsyncWaitForEvent(EventReport);
153 >  CheckSynchronize;
154    writeln(OutFile,'Async Wait Called');
155    EventHandler.Cancel;
156 +  writeln(OutFile,'Event Cancelled');
157 +  FEventSignalled := false;
158    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
159    WaitCount := 100000000;
160    while not FEventSignalled and (WaitCount > 0) do Dec(WaitCount);
# Line 96 | Line 163 | begin
163      writeln(OutFile,'Event called - so Cancel failed');
164  
165    writeln(OutFile,'Sync wait');
166 +  CheckSynchronize;
167    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
168    EventHandler.WaitForEvent;
169    writeln(OutFile,'Event Signalled');
170 <  EventCounts := EventHandler.ExtractEventCounts;
171 <  for i := 0 to length(EventCounts) - 1 do
172 <    writeln(OutFile,'Event: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
170 >  ShowEventCounts(EventHandler);
171 >  EventHandler := nil;
172 >  CheckSynchronize;
173   end;
174  
175   procedure TTest10.EventReport(Sender: IEvents);
176   begin
177    FEventSignalled := true;
178 +  TThread.Synchronize(nil,ShowEventReport);
179 + end;
180 +
181 + procedure TTest10.ShowEventReport;
182 + begin
183 +  writeln(OutFile,'Event Signalled');
184 + end;
185 +
186 + procedure TTest10.ShowEventCounts(Intf: IEvents);
187 + var
188 +  i: integer;
189 +  EventCounts: TEventCounts;
190 + begin
191 +  EventCounts := Intf.ExtractEventCounts;
192 +  for i := 0 to length(EventCounts) - 1 do
193 +    writeln(OutFile,'Event Counts: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
194   end;
195  
196 < function TTest10.TestTitle: string;
196 > function TTest10.TestTitle: AnsiString;
197   begin
198    Result := 'Test 10: Event Handling';
199   end;
200  
201 < procedure TTest10.RunTest(CharSet: string; SQLDialect: integer);
201 > procedure TTest10.RunTest(CharSet: AnsiString; SQLDialect: integer);
202   var Attachment: IAttachment;
203      DPB: IDPB;
204   begin
# Line 122 | Line 206 | begin
206    DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
207    DPB.Add(isc_dpb_password).setAsString(' ');
208    DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
125  DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
209    DPB.Find(isc_dpb_password).setAsString(Owner.GetPassword);
210    Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
211    EventsTest(Attachment);

Comparing:
ibx/trunk/fbintf/testsuite/Test10.pas (property svn:eol-style), Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
ibx/branches/udr/testsuite/Test10.pas (property svn:eol-style), Revision 396 by tony, Thu Feb 17 11:57:23 2022 UTC

# Line 0 | Line 1
1 + native

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines