testbs.pp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. {
  2. $Id$
  3. This file is part of the Free Component Library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Test for TBufstream.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. {$H+}
  14. program testbs;
  15. uses
  16. Classes, SysUtils
  17. { add your units here }, bufstream;
  18. Var
  19. MBSize : Integer = 1024*100;
  20. SBCapacity : Integer = 1024*16;
  21. procedure TestRead(Buffer : PChar; ACapacity : Integer);
  22. Var
  23. F2 : TFileStream;
  24. B : TReadBufSTream;
  25. C : Integer;
  26. begin
  27. B:=TReadBufStream.Create(TFileStream.Create(PAramStr(0),fmOpenRead),ACapacity);
  28. Try
  29. B.SourceOwner:=True;
  30. F2:=TFileStream.Create(ChangeFileExt(PAramStr(0),'.tr'),fmCreate);
  31. Try
  32. Repeat
  33. C:=B.Read(Buffer^,MBSize);
  34. F2.Write(Buffer^,C);
  35. Until (C<MBSize);
  36. Finally
  37. F2.Free;
  38. end;
  39. finally
  40. B.Free;
  41. end;
  42. end;
  43. procedure TestWrite(Buffer : PChar; ACapacity : Integer);
  44. Var
  45. F : TFileStream;
  46. B : TWriteBufSTream;
  47. C : Integer;
  48. begin
  49. F:=TFileStream.Create(PAramStr(0),fmOpenRead);
  50. Try
  51. B:=TWriteBufStream.Create(TFileStream.Create(ChangeFileExt(PAramStr(0),'.tw'),fmCreate),ACapacity);
  52. Try
  53. B.SourceOwner:=True;
  54. Repeat
  55. C:=F.Read(Buffer^,MBSize);
  56. B.Write(Buffer^,C);
  57. Until (C<MBSize);
  58. Finally
  59. B.Free;
  60. end;
  61. finally
  62. F.Free;
  63. end;
  64. end;
  65. Var
  66. Buffer : PChar;
  67. begin
  68. If ParamCount>0 then
  69. MBSize:=StrToIntDef(ParamStr(1),MBSize);
  70. If ParamCount>1 then
  71. SBCapacity:=StrToIntDef(ParamStr(2),SBCapacity);
  72. GetMem(Buffer,MBSize);
  73. Try
  74. TestRead(Buffer,SBCapacity);
  75. TestWrite(Buffer,SBCapacity);
  76. Finally
  77. FreeMem(Buffer);
  78. end;
  79. end.