IdTestCmdTCPClient.pas 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. unit IdTestCmdTCPClient;
  2. interface
  3. uses
  4. IdTest,
  5. IdGlobal,
  6. IdCmdTCPClient,
  7. IdCmdTCPServer,
  8. IdSys;
  9. type
  10. TIdSafeCmdTCPClient = class(TIdCmdTCPClient)
  11. public
  12. AllowFree:Boolean;
  13. destructor Destroy; override;
  14. end;
  15. TIdTestCmdTCPClient = class(TIdTest)
  16. published
  17. procedure TestFree;
  18. end;
  19. implementation
  20. procedure TIdTestCmdTCPClient.TestFree;
  21. //this is to make sure a bug doesnt reappear. at one point, the
  22. //TIdCmdTCPClientListeningThread freed its owner.
  23. var
  24. aClient:TIdSafeCmdTCPClient;
  25. aServer:TIdCmdTCPServer;
  26. const
  27. cTestPort=20202;
  28. begin
  29. aClient:=TIdSafeCmdTCPClient.Create(nil);
  30. aServer:=TIdCmdTCPServer.Create(nil);
  31. try
  32. aServer.DefaultPort:=cTestPort;
  33. aServer.Active:=True;
  34. aClient.AllowFree:=False;
  35. aClient.Port:=cTestPort;
  36. aClient.Host:='127.0.0.1';
  37. aClient.Connect;
  38. aClient.Disconnect;
  39. finally
  40. aClient.AllowFree:=True;
  41. Sys.FreeAndNil(aClient);
  42. Sys.FreeAndNil(aServer);
  43. end;
  44. end;
  45. destructor TIdSafeCmdTCPClient.Destroy;
  46. begin
  47. Assert(AllowFree);
  48. inherited;
  49. end;
  50. initialization
  51. TIdTest.RegisterTest(TIdTestCmdTCPClient);
  52. end.