IdHL7Tests.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 11263: IdHL7Tests.pas
  11. {
  12. { Rev 1.0 11/12/2002 09:18:56 PM JPMugaas
  13. { Initial check in. Import from FTP VC.
  14. }
  15. unit IdHL7Tests;
  16. interface
  17. uses
  18. TestFramework,
  19. IdHL7;
  20. type
  21. TIdHL7Tests = class(TTestCase)
  22. Private
  23. procedure MessageReply(Sender: TObject; Msg: String; var VHandled: Boolean; var Reply: String);
  24. Published
  25. procedure TestConnection;
  26. procedure TestConnectionLimit;
  27. procedure TestSyncForwards;
  28. procedure TestSyncBackwards;
  29. procedure TestSyncForwards1000;
  30. procedure TestSyncBackwards1000;
  31. end;
  32. implementation
  33. uses windows, sysutils;
  34. const
  35. TEST_PORT = 20032; // err, we hope that this is unused
  36. { TIdHL7Tests }
  37. procedure TIdHL7Tests.MessageReply(Sender: TObject; Msg: String; var VHandled: Boolean; var Reply: String);
  38. begin
  39. VHandled := True;
  40. reply := Msg + 'Return';
  41. end;
  42. procedure TIdHL7Tests.TestConnection;
  43. var
  44. FIn: TIdHL7;
  45. FOut: TIdHL7;
  46. begin
  47. FIn := TIdHL7.Create(NIL);
  48. try
  49. FIn.CommunicationMode := cmSynchronous;
  50. FIn.Port := TEST_PORT;
  51. FIn.IsListener := True;
  52. FIn.OnReceiveMessage := MessageReply;
  53. FIn.Start;
  54. FOut := TIdHL7.Create(NIL);
  55. try
  56. FOut.CommunicationMode := cmSynchronous;
  57. FOut.IsListener := False;
  58. FOut.Address := 'localhost';
  59. FOut.Port := TEST_PORT;
  60. FOut.Start;
  61. sleep(500);
  62. Check(FIn.Connected and FOut.Connected);
  63. FOut.PreStop;
  64. FOut.Stop;
  65. finally
  66. FOut.Free;
  67. end;
  68. FIn.PreStop;
  69. FIn.Stop;
  70. finally
  71. FIn.Free;
  72. end;
  73. end;
  74. procedure TIdHL7Tests.TestConnectionLimit;
  75. var
  76. FIn: TIdHL7;
  77. FOut, FOut2: TIdHL7;
  78. begin
  79. FIn := TIdHL7.Create(NIL);
  80. try
  81. FIn.CommunicationMode := cmSynchronous;
  82. FIn.ConnectionLimit := 1;
  83. FIn.Port := TEST_PORT;
  84. FIn.IsListener := True;
  85. FIn.OnReceiveMessage := MessageReply;
  86. FIn.Start;
  87. FOut := TIdHL7.Create(NIL);
  88. try
  89. FOut.CommunicationMode := cmSynchronous;
  90. FOut.Address := 'localhost';
  91. FOut.Port := TEST_PORT;
  92. FOut.IsListener := False;
  93. FOut.Start;
  94. sleep(500);
  95. FOut2 := TIdHL7.Create(NIL);
  96. try
  97. FOut2.CommunicationMode := cmSynchronous;
  98. FOut2.Address := 'localhost';
  99. FOut2.Port := TEST_PORT;
  100. FOut2.IsListener := False;
  101. FOut2.Start;
  102. sleep(500);
  103. Check(FIn.Connected and FOut.Connected and not FOut2.connected);
  104. FOut2.PreStop;
  105. FOut2.Stop;
  106. finally
  107. FOut2.Free;
  108. end;
  109. FOut.PreStop;
  110. FOut.Stop;
  111. finally
  112. FOut.Free;
  113. end;
  114. FIn.PreStop;
  115. FIn.Stop;
  116. finally
  117. FIn.Free;
  118. end;
  119. end;
  120. procedure TIdHL7Tests.TestSyncForwards;
  121. var
  122. FIn: TIdHL7;
  123. FOut: TIdHL7;
  124. FMsg: String;
  125. begin
  126. FIn := TIdHL7.Create(NIL);
  127. try
  128. FIn.CommunicationMode := cmSynchronous;
  129. FIn.Port := TEST_PORT;
  130. FIn.OnReceiveMessage := MessageReply;
  131. FIn.IsListener := True;
  132. FIn.Start;
  133. FOut := TIdHL7.Create(NIL);
  134. try
  135. FOut.CommunicationMode := cmSynchronous;
  136. FOut.IsListener := False;
  137. FOut.Address := 'localhost';
  138. FOut.Port := TEST_PORT;
  139. FOut.Start;
  140. sleep(500);
  141. check(FOut.SynchronousSend('test', FMsg) = srOK);
  142. check(FMsg = 'testReturn');
  143. FOut.PreStop;
  144. FOut.Stop;
  145. finally
  146. FOut.Free;
  147. end;
  148. FIn.PreStop;
  149. FIn.Stop;
  150. finally
  151. FIn.Free;
  152. end;
  153. end;
  154. procedure TIdHL7Tests.TestSyncBackwards;
  155. var
  156. FIn: TIdHL7;
  157. FOut: TIdHL7;
  158. FMsg: String;
  159. begin
  160. FIn := TIdHL7.Create(NIL);
  161. try
  162. FIn.CommunicationMode := cmSynchronous;
  163. FIn.Address := 'localhost';
  164. FIn.Port := TEST_PORT;
  165. FIn.IsListener := True;
  166. FIn.OnReceiveMessage := MessageReply;
  167. FIn.Start;
  168. FOut := TIdHL7.Create(NIL);
  169. try
  170. FOut.CommunicationMode := cmSynchronous;
  171. FOut.IsListener := False;
  172. FOut.Port := TEST_PORT;
  173. FOut.Start;
  174. sleep(500);
  175. check(FOut.SynchronousSend('test', FMsg) = srOK);
  176. check(FMsg = 'testReturn');
  177. FOut.PreStop;
  178. FOut.Stop;
  179. finally
  180. FOut.Free;
  181. end;
  182. FIn.PreStop;
  183. FIn.Stop;
  184. finally
  185. FIn.Free;
  186. end;
  187. end;
  188. procedure TIdHL7Tests.TestSyncForwards1000;
  189. var
  190. FIn: TIdHL7;
  191. FOut: TIdHL7;
  192. FMsg: String;
  193. i: Integer;
  194. begin
  195. FIn := TIdHL7.Create(NIL);
  196. try
  197. FIn.CommunicationMode := cmSynchronous;
  198. FIn.Port := TEST_PORT;
  199. FIn.OnReceiveMessage := MessageReply;
  200. FIn.IsListener := True;
  201. FIn.Start;
  202. FOut := TIdHL7.Create(NIL);
  203. try
  204. FOut.CommunicationMode := cmSynchronous;
  205. FOut.IsListener := False;
  206. FOut.Address := 'localhost';
  207. FOut.Port := TEST_PORT;
  208. FOut.Start;
  209. sleep(500);
  210. for i := 0 to 1000 do
  211. begin
  212. check(FOut.SynchronousSend('test' + IntToStr(i), FMsg) = srOK);
  213. check(FMsg = 'test' + IntToStr(i) + 'Return');
  214. end;
  215. FOut.PreStop;
  216. FOut.Stop;
  217. finally
  218. FOut.Free;
  219. end;
  220. FIn.PreStop;
  221. FIn.Stop;
  222. finally
  223. FIn.Free;
  224. end;
  225. end;
  226. procedure TIdHL7Tests.TestSyncBackwards1000;
  227. var
  228. FIn: TIdHL7;
  229. FOut: TIdHL7;
  230. FMsg: String;
  231. i: Integer;
  232. begin
  233. FIn := TIdHL7.Create(NIL);
  234. try
  235. FIn.CommunicationMode := cmSynchronous;
  236. FIn.Address := 'localhost';
  237. FIn.Port := TEST_PORT;
  238. FIn.IsListener := True;
  239. FIn.OnReceiveMessage := MessageReply;
  240. FIn.Start;
  241. FOut := TIdHL7.Create(NIL);
  242. try
  243. FOut.CommunicationMode := cmSynchronous;
  244. FOut.IsListener := False;
  245. FOut.Port := TEST_PORT;
  246. FOut.Start;
  247. sleep(500);
  248. for i := 0 to 1000 do
  249. begin
  250. check(FOut.SynchronousSend('test' + IntToStr(i), FMsg) = srOK);
  251. check(FMsg = 'test' + IntToStr(i) + 'Return');
  252. end;
  253. FOut.PreStop;
  254. FOut.Stop;
  255. finally
  256. FOut.Free;
  257. end;
  258. FIn.PreStop;
  259. FIn.Stop;
  260. finally
  261. FIn.Free;
  262. end;
  263. end;
  264. Initialization
  265. TestFramework.RegisterTest(TIdHL7Tests.Suite);
  266. end.