ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/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 56 by tony, Mon Mar 6 10:20:02 2017 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 ShowEventCounts(Intf: IEvents);
45    public
46 <    function TestTitle: string; override;
47 <    procedure RunTest(CharSet: string; SQLDialect: integer); override;
46 >    function TestTitle: AnsiString; override;
47 >    procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
48    end;
49  
50  
# Line 51 | Line 57 | const
57  
58   procedure TTest10.EventsTest(Attachment: IAttachment);
59   var EventHandler: IEvents;
54    EventCounts: TEventCounts;
60      i: integer;
61      WaitCount: integer;
62   begin
63 +  FEventSignalled := false;
64    EventHandler := Attachment.GetEventHandler('TESTEVENT');
65    writeln(OutFile,'Call Async Wait');
66 <  EventHandler.AsyncWaitForEvent(@EventReport);
66 >  EventHandler.AsyncWaitForEvent(EventReport);
67    writeln(OutFile,'Async Wait Called');
68 <
68 >  sleep(500);
69 >  if FEventSignalled then
70 >  begin
71 >    writeln(OutFile,'First Event - usually ignored');
72 >    FEventSignalled := false;
73 >    EventHandler.AsyncWaitForEvent(EventReport);
74 >    sleep(100);
75 >    if FEventSignalled then
76 >    begin
77 >      writeln(OutFile,'Unexpected Event 1');
78 >      Exit;
79 >    end;
80 >  end;
81    writeln(OutFile,'Signal Event');
82    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
83 <  while not FEventSignalled do;
84 <  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);
83 >  while not FEventSignalled do Sleep(50);
84 >  ShowEventCounts(EventHandler);
85    FEventSignalled := false;
86  
87    writeln(OutFile,'Two more events');
88    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
89    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
90 +  if FEventSignalled then
91 +  begin
92 +    writeln(OutFile,'Unexpected Event 2');
93 +    FEventSignalled := false
94 +  end;
95    writeln(OutFile,'Call Async Wait');
96 <  EventHandler.AsyncWaitForEvent(@EventReport);
96 >  EventHandler.AsyncWaitForEvent(EventReport);
97    writeln(OutFile,'Async Wait Called');
98 +  sleep(500);
99 +  if FEventSignalled then
100 +  begin
101 +    writeln(OutFile,'Deferred Events Caught');
102 +    ShowEventCounts(EventHandler);
103 +    FEventSignalled := false;
104 +    EventHandler.AsyncWaitForEvent(EventReport);
105 +    sleep(100);
106 +    if FEventSignalled then
107 +      writeln(OutFile,'Unexpected Event 3');
108 +  end;
109    writeln(OutFile,'Signal Event');
110    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
111    while not FEventSignalled do;
112 <  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);
112 >  ShowEventCounts(EventHandler);
113  
114    FEventSignalled := false;
115    writeln(OutFile,'Async Wait: Test Cancel');
116 <  EventHandler.AsyncWaitForEvent(@EventReport);
116 >  EventHandler.AsyncWaitForEvent(EventReport);
117    writeln(OutFile,'Async Wait Called');
118    EventHandler.Cancel;
119 +  writeln(OutFile,'Event Cancelled');
120 +  FEventSignalled := false;
121    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
122    WaitCount := 100000000;
123    while not FEventSignalled and (WaitCount > 0) do Dec(WaitCount);
# Line 99 | Line 129 | begin
129    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],sqlEvent);
130    EventHandler.WaitForEvent;
131    writeln(OutFile,'Event Signalled');
132 <  EventCounts := EventHandler.ExtractEventCounts;
133 <  for i := 0 to length(EventCounts) - 1 do
104 <    writeln(OutFile,'Event: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
132 >  ShowEventCounts(EventHandler);
133 >  EventHandler := nil;
134   end;
135  
136   procedure TTest10.EventReport(Sender: IEvents);
137   begin
138    FEventSignalled := true;
139 +  writeln(OutFile,'Event Signalled');
140 + end;
141 +
142 + procedure TTest10.ShowEventCounts(Intf: IEvents);
143 + var
144 +  i: integer;
145 +  EventCounts: TEventCounts;
146 + begin
147 +  EventCounts := Intf.ExtractEventCounts;
148 +  for i := 0 to length(EventCounts) - 1 do
149 +    writeln(OutFile,'Event Counts: ',EventCounts[i].EventName,', Count = ',EventCounts[i].Count);
150   end;
151  
152 < function TTest10.TestTitle: string;
152 > function TTest10.TestTitle: AnsiString;
153   begin
154    Result := 'Test 10: Event Handling';
155   end;
156  
157 < procedure TTest10.RunTest(CharSet: string; SQLDialect: integer);
157 > procedure TTest10.RunTest(CharSet: AnsiString; SQLDialect: integer);
158   var Attachment: IAttachment;
159      DPB: IDPB;
160   begin

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines