testbs.pp 1.9 KB

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