FTPListBox.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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: 11249: FTPListBox.pas
  11. {
  12. { Rev 1.0 11/12/2002 09:17:44 PM JPMugaas
  13. { Initial check in. Import from FTP VC.
  14. }
  15. unit FTPListBox;
  16. {.$define WriteFiles} // define this to create te reference files.
  17. // only do this if you are sure this ftp-lists work correct.
  18. interface
  19. uses
  20. IndyBox;
  21. type
  22. TFTPListBox = class( TIndyBox )
  23. public
  24. function TestFile( const FileName: string ) : boolean;
  25. procedure TestSystem( const system: string ) ;
  26. procedure Test; override;
  27. end;
  28. implementation
  29. uses
  30. IdFTPList, Classes,
  31. SysUtils;
  32. { TFTPListBox }
  33. function MyDateTimeToStr(const d:tdatetime):string;
  34. {this is a nice one}
  35. begin
  36. if (d-trunc(d))*(60*60*24)>=1 then
  37. DateTimeToString( Result,'M-d-yyyy h:mm:ss',d)
  38. else
  39. DateTimeToString( Result,'M-d-yyyy',d)
  40. end;
  41. function TFTPListBox.TestFile( const FileName: string ) : boolean;
  42. var
  43. s: TStrings;
  44. i: Integer;
  45. LDirectoryListing: TIdFTPListItems;
  46. Expected: TStrings;
  47. ExpectedPos: integer;
  48. function Test( const str: string ) : boolean;
  49. begin
  50. {$ifndef WriteFiles}
  51. result := Expected.strings[ExpectedPos] = str;
  52. inc( ExpectedPos ) ;
  53. {$else}
  54. Expected.add(str);
  55. result:=true;
  56. {$endif}
  57. end;
  58. begin
  59. result := true;
  60. LDirectoryListing := TIdFTPListItems.Create;
  61. try
  62. s := TStringList.Create;
  63. Expected := TStringList.Create;
  64. ExpectedPos := 0;
  65. {$ifndef WriteFiles}
  66. Expected.LoadFromfile( filename + '.expected' ) ;
  67. {$endif}
  68. try
  69. s.LoadFromFile( Filename ) ;
  70. for i := s.Count -1 downto 0 do
  71. begin
  72. if (s[i]<>'') and (s[i][1] = '#') then
  73. begin
  74. s.Delete(i);
  75. end;
  76. end;
  77. // Parse directory listing
  78. if s.Count > 0 then
  79. begin
  80. //we have to skip blank lines because VMS returns those
  81. //throwing off the Indy code.
  82. for i := 0 to s.Count - 1 do
  83. begin
  84. if ( s[i] <> '' ) and ( Pos( 'TOTAL', UpperCase( s[i] ) ) <> 1 ) then
  85. begin
  86. LDirectoryListing.ListFormat := LDirectoryListing.CheckListFormat( s[i], TRUE ) ; //APR: TRUE for IndyCheck, else always Unknown
  87. Break;
  88. end;
  89. end;
  90. LDirectoryListing.LoadList( s ) ;
  91. end;
  92. for i := 0 to LDirectoryListing.Count - 1 do
  93. begin
  94. result := result and test( LDirectoryListing[i].FileName ) ;
  95. result := result and test( LDirectoryListing[i].OwnerName ) ;
  96. result := result and test( IntToStr( LDirectoryListing[i].Size ) ) ;
  97. case LDirectoryListing[i].ItemType of
  98. ditDirectory: result := result and test( 'Directory' ) ;
  99. ditFile: result := result and test( 'File' ) ;
  100. ditSymbolicLink: result := result and test( 'Symbolic Link' ) ;
  101. end;
  102. result := result and test( IntToStr( LDirectoryListing[i].RecLength ) ) ;
  103. result := result and test( IntToStr( LDirectoryListing[i].NumberRecs ) ) ;
  104. // result := result and test( FormatDateTime('M-d-yyyy h:mm:ss',LDirectoryListing[i].ModifiedDate));
  105. result := result and test( MyDateTimeToStr( LDirectoryListing[i].ModifiedDate ) ) ;
  106. test( '' ) ;
  107. end;
  108. finally
  109. FreeAndNil( s ) ;
  110. {$ifdef WriteFiles}
  111. Expected.savetofile(filename+'.expected');
  112. {$endif}
  113. FreeAndNil( Expected ) ;
  114. end;
  115. finally
  116. FreeAndNil( LDirectoryListing ) ;
  117. end;
  118. end;
  119. procedure TFTPListBox.TestSystem( const system: string ) ;
  120. var
  121. f: TSearchRec; a: integer;
  122. begin
  123. Status( 'Testing ' + system ) ;
  124. a := FindFirst( GetDataDir + system + '-*.txt', faAnyFile - faDirectory, f ) ;
  125. while a = 0 do
  126. begin
  127. check( TestFile( GetDataDir + f.name ) , f.name + ' goes wrong' ) ;
  128. a := FindNext( f ) ;
  129. end;
  130. findclose( f )
  131. end;
  132. procedure TFTPListBox.Test;
  133. begin
  134. TestSystem( 'MS-Dos' ) ;
  135. TestSystem( 'Novel-Netware' ) ;
  136. TestSystem( 'Unix' ) ;
  137. TestSystem( 'VM' ) ;
  138. TestSystem( 'VMS' ) ;
  139. TestSystem( 'MVS' ) ;
  140. TestSystem( 'MVS_PDS' ) ;
  141. TestSystem( 'Mac-NetPresenz' ) ;
  142. end;
  143. initialization
  144. TIndyBox.RegisterBox( TFTPListBox, 'FTP Lists', 'Misc' ) ;
  145. end.