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.
Revision 217 by tony, Fri Mar 16 10:27:26 2018 UTC

# Line 1 | Line 1
1   unit Test10;
2 + {$IFDEF MSWINDOWS}
3 + {$DEFINE WINDOWS}
4 + {$ENDIF}
5  
6 < {$mode objfpc}{$H+}
6 > {$IFDEF FPC}
7 > {$mode delphi}
8   {$codepage utf8}
9 + {$ENDIF}
10  
11   {Test 10: Event Handling}
12  
# Line 36 | Line 41 | type
41      FEventSignalled: boolean;
42      procedure EventsTest(Attachment: IAttachment);
43      procedure EventReport(Sender: IEvents);
44 +    procedure ShowEventReport;
45 +    procedure ShowEventCounts(Intf: IEvents);
46    public
47 <    function TestTitle: string; override;
48 <    procedure RunTest(CharSet: string; SQLDialect: integer); override;
47 >    function TestTitle: AnsiString; override;
48 >    procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
49    end;
50  
51  
# Line 51 | Line 58 | const
58  
59   procedure TTest10.EventsTest(Attachment: IAttachment);
60   var EventHandler: IEvents;
54    EventCounts: TEventCounts;
61      i: integer;
62      WaitCount: integer;
63   begin
64 +  FEventSignalled := false;
65    EventHandler := Attachment.GetEventHandler('TESTEVENT');
66    writeln(OutFile,'Call Async Wait');
67 <  EventHandler.AsyncWaitForEvent(@EventReport);
67 >  EventHandler.AsyncWaitForEvent(EventReport);
68    writeln(OutFile,'Async Wait Called');
69 <
69 >  sleep(500);
70 >  CheckSynchronize;
71 >  if FEventSignalled then
72 >  begin
73 >    writeln(OutFile,'First Event - usually ignored');
74 >    FEventSignalled := false;
75 >    EventHandler.AsyncWaitForEvent(EventReport);
76 >    sleep(100);
77 >    CheckSynchronize;
78 >    if FEventSignalled then
79 >    begin
80 >      writeln(OutFile,'Unexpected Event 1');
81 >      Exit;
82 >    end;
83 >  end;
84    writeln(OutFile,'Signal Event');
85    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
86 <  while not FEventSignalled do;
87 <  writeln(OutFile,'Event Signalled');
67 <  EventCounts := EventHandler.ExtractEventCounts;
68 <  for i := 0 to length(EventCounts) - 1 do
69 <    writeln(OutFile,'Event: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
86 >  while not FEventSignalled do Sleep(50);
87 >  ShowEventCounts(EventHandler);
88    FEventSignalled := false;
89  
90    writeln(OutFile,'Two more events');
91    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
92    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
93 +  if FEventSignalled then
94 +  begin
95 +    writeln(OutFile,'Unexpected Event 2');
96 +    FEventSignalled := false
97 +  end;
98    writeln(OutFile,'Call Async Wait');
99 <  EventHandler.AsyncWaitForEvent(@EventReport);
99 >  EventHandler.AsyncWaitForEvent(EventReport);
100    writeln(OutFile,'Async Wait Called');
101 +  sleep(500);
102 +  CheckSynchronize;
103 +  if FEventSignalled then
104 +  begin
105 +    writeln(OutFile,'Deferred Events Caught');
106 +    ShowEventCounts(EventHandler);
107 +    FEventSignalled := false;
108 +    EventHandler.AsyncWaitForEvent(EventReport);
109 +    sleep(100);
110 +    if FEventSignalled then
111 +      writeln(OutFile,'Unexpected Event 3');
112 +  end;
113    writeln(OutFile,'Signal Event');
114    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
115    while not FEventSignalled do;
116 <  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);
116 >  ShowEventCounts(EventHandler);
117  
118    FEventSignalled := false;
119    writeln(OutFile,'Async Wait: Test Cancel');
120 <  EventHandler.AsyncWaitForEvent(@EventReport);
120 >  EventHandler.AsyncWaitForEvent(EventReport);
121 >  CheckSynchronize;
122    writeln(OutFile,'Async Wait Called');
123    EventHandler.Cancel;
124 +  writeln(OutFile,'Event Cancelled');
125 +  FEventSignalled := false;
126    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
127    WaitCount := 100000000;
128    while not FEventSignalled and (WaitCount > 0) do Dec(WaitCount);
# Line 96 | Line 131 | begin
131      writeln(OutFile,'Event called - so Cancel failed');
132  
133    writeln(OutFile,'Sync wait');
134 +  CheckSynchronize;
135    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
136    EventHandler.WaitForEvent;
137    writeln(OutFile,'Event Signalled');
138 <  EventCounts := EventHandler.ExtractEventCounts;
139 <  for i := 0 to length(EventCounts) - 1 do
140 <    writeln(OutFile,'Event: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
138 >  ShowEventCounts(EventHandler);
139 >  EventHandler := nil;
140 >  CheckSynchronize;
141   end;
142  
143   procedure TTest10.EventReport(Sender: IEvents);
144   begin
145    FEventSignalled := true;
146 +  TThread.Synchronize(nil,ShowEventReport);
147 + end;
148 +
149 + procedure TTest10.ShowEventReport;
150 + begin
151 +  writeln(OutFile,'Event Signalled');
152 + end;
153 +
154 + procedure TTest10.ShowEventCounts(Intf: IEvents);
155 + var
156 +  i: integer;
157 +  EventCounts: TEventCounts;
158 + begin
159 +  EventCounts := Intf.ExtractEventCounts;
160 +  for i := 0 to length(EventCounts) - 1 do
161 +    writeln(OutFile,'Event Counts: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
162   end;
163  
164 < function TTest10.TestTitle: string;
164 > function TTest10.TestTitle: AnsiString;
165   begin
166    Result := 'Test 10: Event Handling';
167   end;
168  
169 < procedure TTest10.RunTest(CharSet: string; SQLDialect: integer);
169 > procedure TTest10.RunTest(CharSet: AnsiString; SQLDialect: integer);
170   var Attachment: IAttachment;
171      DPB: IDPB;
172   begin

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines