FTPListTests.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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: 22776: FTPListTests.pas
  11. {
  12. { Rev 1.6 10/3/2003 05:47:54 PM JPMugaas
  13. { OS/2 tests.
  14. }
  15. {
  16. { Rev 1.5 9/28/2003 03:38:54 PM JPMugaas
  17. { Fixed a bad test case.
  18. }
  19. {
  20. { Rev 1.4 9/28/2003 03:03:22 AM JPMugaas
  21. { Added tests for nonstandard Unix dates.
  22. }
  23. {
  24. { Rev 1.3 9/27/2003 10:44:58 PM JPMugaas
  25. { Added a test for MS-DOS formats.
  26. }
  27. {
  28. { Rev 1.2 9/3/2003 07:36:16 PM JPMugaas
  29. { More parsing test cases.
  30. }
  31. {
  32. { Rev 1.1 9/3/2003 04:01:14 AM JPMugaas
  33. { Added some preliminary tests.
  34. }
  35. {
  36. { Rev 1.0 9/2/2003 02:27:46 AM JPMugaas
  37. { Skeliton for new FTP list test. The test is in development now.
  38. }
  39. unit FTPListTests;
  40. interface
  41. uses
  42. SysUtils, Classes, BXBubble, BXCategory;
  43. type
  44. TFTPTestItem = class(TObject)
  45. protected
  46. FTestItem : String;
  47. FFoundParser : String;
  48. FExpectedParser : String;
  49. //note that the Unix servers can normally only report either a year
  50. //or a time. This can cause ambiguity because the year is interpretted
  51. //according to the current or previous year if the date has passed or arrived. But
  52. //because we can't know the local time zone, there can be a 24 hour window
  53. //of time. E.g. Sept 8 10:00am 2003 can be interpretted as either Sept 8 10:00am 2003 or
  54. //Sept 8, 2002 if in the window of Sept 7 10:00am or Sept 9 10:00am.
  55. //Otherwise, a date such as Sept 8: 10:00am can be interpretted differently at different
  56. //times of the year (when the window period has passed - 2002 or before the window 2003.
  57. FEvaluateTime : Boolean;
  58. FEvaluateYear : Boolean;
  59. //Note that with the BSD -T switch, a time can be returned with seconds
  60. FFoundYear, FFoundMonth, FFoundDay, FFoundHour, FFoundMin, FFoundSec : Word;
  61. FExpectedYear, FExpectedMonth, FExpectedDay, FExpectedHour, FExpectedMin, FExpectedSec : Word;
  62. FFoundOwner : String;
  63. FExpectedOwner : String;
  64. FFoundGroup : String;
  65. FExpectedGroup : String;
  66. FFoundFileName : String;
  67. FExpectedFileName : String;
  68. FFoundFileSize : Integer;
  69. FExpectedFileSize : Integer;
  70. public
  71. procedure Clear;
  72. property TestItem : String read FTestItem write FTestItem;
  73. property FoundParser : String read FFoundParser write FFoundParser;
  74. property ExpectedParser : String read FExpectedParser write FExpectedParser;
  75. property EvaluateTime : Boolean read FEvaluateTime write FEvaluateTime;
  76. property EvaluateYear : Boolean read FEvaluateYear write FEvaluateYear;
  77. //Note that with the BSD -T switch, a time can be returned with seconds
  78. property FoundYear : Word read FFoundYear write FFoundYear;
  79. property FoundMonth : Word read FFoundMonth write FFoundMonth;
  80. property FoundDay : Word read FFoundDay write FFoundDay;
  81. property FoundHour : Word read FFoundHour write FFoundHour;
  82. property FoundMin : Word read FFoundMin write FFoundMin;
  83. property FoundSec : Word read FFoundSec write FFoundSec;
  84. property ExpectedYear : Word read FExpectedYear write FExpectedYear;
  85. property ExpectedMonth : Word read FExpectedMonth write FExpectedMonth;
  86. property ExpectedDay : Word read FExpectedDay write FExpectedDay;
  87. property ExpectedHour : Word read FExpectedHour write FExpectedHour;
  88. property ExpectedMin : Word read FExpectedMin write FExpectedMin;
  89. property ExpectedSec : Word read FExpectedSec write FExpectedSec;
  90. property FoundOwner : String read FFoundOwner write FFoundOwner;
  91. property ExpectedOwner : String read FExpectedOwner write FExpectedOwner;
  92. property FoundGroup : String read FFoundGroup write FFoundGroup;
  93. property ExpectedGroup : String read FExpectedGroup write FExpectedGroup;
  94. property FoundFileName : String read FFoundFileName write FFoundFileName;
  95. property ExpectedFileName : String read FExpectedFileName write FExpectedFileName;
  96. property FoundFileSize : Integer read FFoundFileSize write FFoundFileSize;
  97. property ExpectedFileSize : Integer read FExpectedFileSize write FExpectedFileSize;
  98. end;
  99. TdmFTPListTest = class(TDataModule)
  100. bxUnixLSandSimilar: TBXBubble;
  101. bxWin32IISForms: TBXBubble;
  102. bxSterlingComTests: TBXBubble;
  103. bxOS2Test: TBXBubble;
  104. procedure bxUnixLSandSimilarTest(Sender: TBXBubble);
  105. procedure bxWin32IISFormsTest(Sender: TBXBubble);
  106. procedure bxSterlingComTestsTest(Sender: TBXBubble);
  107. procedure bxOS2TestTest(Sender: TBXBubble);
  108. private
  109. { Private declarations }
  110. protected
  111. procedure ReportItem(AItem : TFTPTestItem);
  112. //this is for MS-DOS (Win32 style Dir lists where there's no
  113. //owner or group and where the time and date are supplied
  114. procedure TestItem(
  115. ATestItem,
  116. AExpectedParser,
  117. AExpectedFileName : String;
  118. AExpectedFileSize : Integer;
  119. AExpectedYear,
  120. AExpectedMonth,
  121. AExpectedDay,
  122. AExpectedHour,
  123. AExpectedMin,
  124. AExpectedSec : Word); overload;
  125. //for FreeBSD -T /bin/ls variation and Novell Netware Print Services for Unix (NFS Namespace)
  126. procedure TestItem(
  127. ATestItem,
  128. AExpectedParser,
  129. AExpectedOwner,
  130. AExpectedGroup,
  131. AExpectedFileName : String;
  132. AExpectedFileSize : Integer;
  133. AExpectedYear,
  134. AExpectedMonth,
  135. AExpectedDay,
  136. AExpectedHour,
  137. AExpectedMin,
  138. AExpectedSec : Word); overload;
  139. //for /bin/ls with a date within 6 monthes
  140. procedure TestItem(
  141. ATestItem,
  142. AExpectedParser,
  143. AExpectedOwner,
  144. AExpectedGroup,
  145. AExpectedFileName : String;
  146. AExpectedFileSize : Integer;
  147. AExpectedMonth,
  148. AExpectedDay,
  149. AExpectedHour,
  150. AExpectedMin,
  151. AExpectedSec : Word); overload;
  152. //for /bin/ls with a date greater than 6 monthes
  153. procedure TestItem(
  154. ATestItem,
  155. AExpectedParser,
  156. AExpectedOwner,
  157. AExpectedGroup,
  158. AExpectedFileName : String;
  159. AExpectedFileSize : Integer;
  160. AExpectedYear,
  161. AExpectedMonth,
  162. AExpectedDay : Word); overload;
  163. public
  164. { Public declarations }
  165. end;
  166. var
  167. dmFTPListTest: TdmFTPListTest;
  168. implementation
  169. uses IdCoreGlobal, IdAllFTPListParsers, IdFTPList, IdFTPListParseNovellNetwarePSU,
  170. IdFTPListParseUnix,
  171. IdFTPListParseBase, IdFTPListParseWindowsNT, IdFTPListParseStercomUnixEnt,
  172. IdFTPListParseStercomOS390Exp, IdFTPListParseOS2;
  173. {$R *.dfm}
  174. procedure TdmFTPListTest.bxUnixLSandSimilarTest(Sender: TBXBubble);
  175. begin
  176. //drwxrwxrwx 1 user group 0 Mar 3 04:49:59 2003 upload
  177. //FreeBSD /bin/ls -T format
  178. TestItem('drwxrwxrwx 1 user group 0 Mar 3 04:49:59 2003 upload',
  179. UNIX,
  180. 'user',
  181. 'group',
  182. 'upload',
  183. 0,
  184. 2003,
  185. 3,
  186. 3,
  187. 4,
  188. 49,
  189. 59
  190. );
  191. //-rw------- 1 root wheel 512 Oct 14, 99 8:45 pm deleted.sav
  192. //Novell Netware Print Services for Unix FTP Deamon
  193. TestItem('-rw------- 1 root wheel 512 Oct 14, 99 8:45 pm deleted.sav',
  194. NOVELLNETWAREPSU + 'NFS Namespace',
  195. 'root',
  196. 'wheel',
  197. 'deleted.sav',
  198. 512,
  199. 1999,
  200. 10,
  201. 14,
  202. 20,
  203. 45,
  204. 0);
  205. //Normal Unix item with time
  206. TestItem('drwxrwxrwx 1 owner group 0 Sep 23 21:58 drdos',
  207. UNIX,
  208. 'owner',
  209. 'group',
  210. 'drdos',
  211. 0,
  212. 9,
  213. 23,
  214. 21,
  215. 58,
  216. 0);
  217. //drwxr-xr-x 4 ftpuser ftpusers 512 Jul 23 2001 about
  218. //Normal Unix item with year
  219. TestItem('drwxr-xr-x 4 ftpuser ftpusers 512 Jul 23 2001 about',
  220. UNIX,
  221. 'ftpuser',
  222. 'ftpusers',
  223. 'about',
  224. 512,
  225. 2001,
  226. 7,
  227. 23);
  228. // -rw------- 1 strauss staff DK adams 39 Feb 18 11:23 file2
  229. // Unitree with Time
  230. TestItem('-rw------- 1 strauss staff DK adams 39 Feb 18 11:23 file2',
  231. UNITREE,
  232. 'strauss',
  233. 'staff',
  234. 'file2',
  235. 39,
  236. 2,
  237. 18,
  238. 11,
  239. 23,
  240. 0);
  241. //Unitree with Date
  242. TestItem('drwxr-xr-x 2 se2nl g664 DK common 8192 Dec 29 1993 encytemp (Empty)',
  243. UNITREE,
  244. 'se2nl',
  245. 'g664',
  246. 'encytemp (Empty)',
  247. 8192,
  248. 1993,
  249. 12,
  250. 29);
  251. TestItem('drwxr-xr-x 2 root 110 4096 Sep 27 2000 oracle',
  252. UNIX,
  253. 'root',
  254. '110',
  255. 'oracle',
  256. 4096,
  257. 2000,
  258. 9,
  259. 27);
  260. TestItem('-r--r--r-- 1 0 1 351 Aug 8 2000 Welcome',
  261. UNIX,
  262. '0',
  263. '1',
  264. 'Welcome',
  265. 351,
  266. 2000,
  267. 8,
  268. 8);
  269. //-go switches
  270. TestItem('-r--r--r-- 1 351 Aug 8 2000 Welcome',
  271. UNIX,
  272. '',
  273. '',
  274. 'Welcome',
  275. 351,
  276. 2000,
  277. 8,
  278. 8 );
  279. //-g switch
  280. TestItem('-r--r--r-- 1 1 351 Aug 8 2000 Welcome',
  281. UNIX,
  282. '',
  283. '1',
  284. 'Welcome',
  285. 351,
  286. 2000,
  287. 8,
  288. 8);
  289. TestItem('-r--r--r-- 1 0 351 Aug 8 2000 Welcome',
  290. UNIX,
  291. '',
  292. '0', //really the owner but for coding, it's the group because
  293. //you can't desinguish a group and owner with one value and on
  294. //a server, you can't make an API call.
  295. 'Welcome',
  296. 351,
  297. 2000,
  298. 8,
  299. 8);
  300. //-i switch
  301. TestItem(' 33025 -r--r--r-- 1 root other 351 Aug 8 2000 Welcome',
  302. UNIX,
  303. 'root',
  304. 'other',
  305. 'Welcome',
  306. 351,
  307. 2000,
  308. 8,
  309. 8);
  310. //-s switch
  311. TestItem(' 16 -r--r--r-- 1 root other 351 Aug 8 2000 Welcome',
  312. UNIX,
  313. 'root',
  314. 'other',
  315. 'Welcome',
  316. 351,
  317. 2000,
  318. 8,
  319. 8);
  320. //-is switches
  321. TestItem(' 33025 16 -r--r--r-- 1 root other 351 Aug 8 2000 Welcome',
  322. UNIX,
  323. 'root',
  324. 'other',
  325. 'Welcome',
  326. 351,
  327. 2000,
  328. 8,
  329. 8);
  330. TestItem('1008201 33 -rw-r--r-- 1 204 wheel 32871 Mar 4 16:45:27 1999 nl-ftp',
  331. UNIX,
  332. '204',
  333. 'wheel',
  334. 'nl-ftp',
  335. 32871,
  336. 1999,
  337. 3,
  338. 4,
  339. 16,
  340. 45,
  341. 27);
  342. //char devices
  343. TestItem('crw-rw-rw- 1 0 1 11, 42 Aug 8 2000 tcp',
  344. UNIX,
  345. '0',
  346. '1',
  347. 'tcp',
  348. 0,
  349. 2000,
  350. 8,
  351. 8);
  352. TestItem('crw-rw-rw- 1 0 1 105, 1 Aug 8 2000 ticotsord',
  353. UNIX,
  354. '0',
  355. '1',
  356. 'ticotsord',
  357. 0,
  358. 2000,
  359. 8,
  360. 8);
  361. // a /bin/ls form with a ACL.
  362. TestItem('drwx------+ 7 Administ mkpasswd 86016 Feb 9 18:04 bin',
  363. UNIX,
  364. 'Administ',
  365. 'mkpasswd',
  366. 'bin',
  367. 86016,
  368. 2,
  369. 9,
  370. 18,
  371. 4,
  372. 0);
  373. //Note that this is problematic and I doubt we can ever fix for this one without
  374. //introducing other problems.
  375. { TestItem('-rw-r--r-- 1 J. Peter Mugaas None 862979 Apr 8 2002 kftp.exe',
  376. UNIX,
  377. 'J. Peter Mugaas',
  378. 'None',
  379. 'kftp.exe',
  380. 862979,
  381. 2002,
  382. 4,
  383. 8); }
  384. //taken from remarks in the FileZilla GNU Source-code - note that non of that
  385. //code is used at all
  386. // /* Some listings with uncommon date/time format: */
  387. // "-rw-r--r-- 1 root other 531 09-26 2000 README2",
  388. TestItem('-rw-r--r-- 1 root other 531 09-26 2000 README2',
  389. UNIX,
  390. 'root',
  391. 'other',
  392. 'README2',
  393. 531,
  394. 2000,
  395. 9,
  396. 26);
  397. // "-rw-r--r-- 1 root other 531 09-26 13:45 README3",
  398. TestItem('-rw-r--r-- 1 root other 531 09-26 13:45 README3',
  399. UNIX,
  400. 'root',
  401. 'other',
  402. 'README3',
  403. 531,
  404. 9,
  405. 26,
  406. 13,
  407. 45,
  408. 0);
  409. // "-rw-r--r-- 1 root other 531 2005-06-07 21:22 README4
  410. TestItem('-rw-r--r-- 1 root other 531 2005-06-07 21:22 README4',
  411. UNIX,
  412. 'root',
  413. 'other',
  414. 'README4',
  415. 2005,
  416. 6,
  417. 7,
  418. 21,
  419. 22,
  420. 0);
  421. TestItem('---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z',
  422. UNIX,
  423. 'owner',
  424. 'group',
  425. 'ls-lR.Z',
  426. 1803128,
  427. 7,
  428. 10,
  429. 10,
  430. 18,
  431. 0);
  432. TestItem('d--------- 1 owner group 0 May 9 19:45 Softlib',
  433. UNIX,
  434. 'owner',
  435. 'group',
  436. 'Softlib',
  437. 0,
  438. 5,
  439. 9,
  440. 19,
  441. 45,
  442. 0);
  443. // CONNECT:Enterprise for UNIX login ok,
  444. TestItem('-r--r--r-- 1 connect 3444 910368 Sep 24 16:36 c3957010.zip.001',
  445. UNIX,
  446. 'connect',
  447. '3444',
  448. 'c3957010.zip.001',
  449. 910368,
  450. 9,
  451. 24,
  452. 16,
  453. 36,
  454. 0);
  455. TestItem('-r--r--r-- 1 connect 2755 6669222 Sep 26 08:11 3963338.fix.000',
  456. UNIX,
  457. 'connect',
  458. '2755',
  459. '3963338.fix.000',
  460. 6669222,
  461. 9,
  462. 26,
  463. 8,
  464. 11,
  465. 0);
  466. TestItem('-r--r--r-- 1 connect 3188 6669222 Sep 26 13:12 c3963338.zip',
  467. UNIX,
  468. 'connect',
  469. '3188',
  470. 'c3963338.zip',
  471. 6669222,
  472. 9,
  473. 26,
  474. 13,
  475. 12,
  476. 0);
  477. end;
  478. procedure TdmFTPListTest.ReportItem(AItem: TFTPTestItem);
  479. var LStatus : String;
  480. begin
  481. bxUnixLSandSimilar.Status('Item: ');
  482. bxUnixLSandSimilar.Status(AItem.TestItem);
  483. //filename
  484. LStatus :=
  485. 'Obtained File name: '+ AItem.FoundFileName + EOL +'Expected name: '+AItem.ExpectedFileName ;
  486. bxUnixLSandSimilar.Status(LStatus);
  487. bxUnixLSandSimilar.Check(AItem.FoundFileName=AItem.ExpectedFileName, LSTatus);
  488. //parserID
  489. LStatus := 'Obtained Parser ID: '+ AItem.FoundParser +EOL+
  490. 'Expected Parser ID: '+ AItem.ExpectedParser;
  491. bxUnixLSandSimilar.Status(LStatus);
  492. bxUnixLSandSimilar.Check(AItem.FoundFileName=AItem.ExpectedFileName,LStatus);
  493. //Owner
  494. LStatus := 'Obtained Owner: '+ AItem.FoundOwner +EOL+'Expected Owner: '+ AItem.ExpectedOwner;
  495. bxUnixLSandSimilar.Status(LStatus);
  496. bxUnixLSandSimilar.Check(AItem.FoundOwner =AItem.ExpectedOwner, LStatus );
  497. //Group
  498. LStatus :='Obtained Group: '+ AItem.FoundGroup +EOL+'Expected Group: '+ AItem.ExpectedGroup;
  499. bxUnixLSandSimilar.Status(LStatus);
  500. bxUnixLSandSimilar.Check(AItem.FoundGroup =AItem.ExpectedGroup,LStatus );
  501. //Date
  502. // Year - note that this may skipped in some cases as explained above
  503. if AItem.FEvaluateYear then
  504. begin
  505. LStatus := 'Obtained Year: '+ IntToStr(AItem.FFoundYear ) +EOL+'Expected Year: '+ IntToStr(AItem.ExpectedYear );
  506. bxUnixLSandSimilar.Status(LStatus);
  507. bxUnixLSandSimilar.Check(AItem.FoundYear =AItem.ExpectedYear,LStatus );
  508. end;
  509. //month
  510. LStatus := 'Obtained Month: '+ IntToStr(AItem.FoundMonth) +EOL+'Expected Month: '+ IntToStr(AItem.ExpectedMonth);
  511. bxUnixLSandSimilar.Status(LStatus);
  512. bxUnixLSandSimilar.Check(AItem.FoundMonth =AItem.ExpectedMonth,LStatus );
  513. //day
  514. LStatus :='Obtained Day: '+ IntToStr(AItem.FoundDay) +EOL+'Expected Day: '+ IntToStr(AItem.ExpectedDay);
  515. bxUnixLSandSimilar.Status(LStatus);
  516. bxUnixLSandSimilar.Check(AItem.FoundDay =AItem.ExpectedDay,LStatus );
  517. //time
  518. if AItem.EvaluateTime then
  519. begin
  520. //Hour
  521. LStatus := 'Obtained Hour: '+ IntToStr(AItem.FoundHour) +EOL+'Expected Hour: '+ IntToStr(AItem.ExpectedHour);
  522. bxUnixLSandSimilar.Status(LStatus);
  523. bxUnixLSandSimilar.Check(AItem.FoundHour =AItem.ExpectedHour, LStatus );
  524. //Minute
  525. LStatus := 'Obtained Minute: '+ IntToStr(AItem.FoundMin) +EOL+'Expected Minute: '+ IntToStr(AItem.ExpectedMin);
  526. bxUnixLSandSimilar.Status(LStatus);
  527. bxUnixLSandSimilar.Check(AItem.FoundMin =AItem.ExpectedMin, LStatus);
  528. //Sec
  529. LStatus := 'Obtained Second: '+ IntToStr(AItem.FoundSec) +EOL+'Expected Second: '+ IntToStr(AItem.ExpectedSec);
  530. bxUnixLSandSimilar.Status(LStatus);
  531. bxUnixLSandSimilar.Check(AItem.FoundSec =AItem.ExpectedSec, LStatus );
  532. end;
  533. //Size
  534. LStatus := 'Obtained Size: '+ IntToStr(AItem.FoundFileSize ) +EOL+'Expected Size: '+ IntToStr(AItem.ExpectedFileSize ) ;
  535. bxUnixLSandSimilar.Status(LStatus);
  536. bxUnixLSandSimilar.Check(AItem.FoundSec =AItem.ExpectedSec, LStatus );
  537. end;
  538. { TFTPTestItem }
  539. procedure TFTPTestItem.Clear;
  540. begin
  541. FTestItem := '';
  542. FFoundParser := '';
  543. FExpectedParser := '';
  544. //note that the Unix servers can normally only report either a year
  545. //or a time. This can cause ambiguity because the year is interpretted
  546. //according to the current or previous year if the date has passed or arrived. But
  547. //because we can't know the local time zone, there can be a 24 hour window
  548. //of time. E.g. Sept 8 10:00am 2003 can be interpretted as either Sept 8 10:00am 2003 or
  549. //Sept 8, 2002 if in the window of Sept 7 10:00am or Sept 9 10:00am.
  550. //Otherwise, a date such as Sept 8: 10:00am can be interpretted differently at different
  551. //times of the year (when the window period has passed - 2002 or before the window 2003.
  552. FEvaluateTime := True;
  553. FEvaluateYear := True;
  554. //Note that with the BSD -T switch, a time can be returned with seconds
  555. FFoundYear := 0;
  556. FExpectedYear := 0;
  557. FFoundMonth := 0;
  558. FFoundDay := 0;
  559. FFoundHour := 0;
  560. FFoundMin := 0;
  561. FFoundSec := 0;
  562. FExpectedMonth := 0;
  563. FExpectedDay := 0;
  564. FExpectedHour := 0;
  565. FExpectedMin := 0;
  566. FExpectedSec := 0;
  567. FFoundOwner := '';
  568. FExpectedOwner := '';
  569. FFoundGroup := '';
  570. FExpectedGroup := '';
  571. FFoundFileName := '';
  572. FExpectedFileName := '';
  573. FFoundFileSize := 0;
  574. FExpectedFileSize := 0;
  575. end;
  576. procedure TdmFTPListTest.TestItem(ATestItem, AExpectedParser,
  577. AExpectedFileName: String; AExpectedFileSize: Integer; AExpectedYear,
  578. AExpectedMonth, AExpectedDay, AExpectedHour, AExpectedMin,
  579. AExpectedSec: Word);
  580. begin
  581. TestItem(ATestItem,AExpectedParser,'','',AExpectedFileName,AExpectedFileSize,AExpectedYear,AExpectedMonth,AExpectedDay,AExpectedHour,AExpectedMin,AExpectedSec);
  582. end;
  583. procedure TdmFTPListTest.TestItem(ATestItem, AExpectedParser,
  584. AExpectedOwner, AExpectedGroup, AExpectedFileName: String;
  585. AExpectedFileSize: Integer; AExpectedYear, AExpectedMonth, AExpectedDay,
  586. AExpectedHour, AExpectedMin, AExpectedSec: Word);
  587. var LT : TFTPTestItem;
  588. LDir : TStrings;
  589. LDirItems : TIdFTPListItems;
  590. LFormat : String;
  591. LFTPDir : TFTPTestItem;
  592. LI : TIdFTPListItem;
  593. LDummy : Word;
  594. begin
  595. LT := TFTPTestItem.Create;
  596. try
  597. LDir := TStringList.Create;
  598. LDirItems := TIdFTPListItems.Create;
  599. LDir.Add(ATestItem);
  600. LFTPDir := TFTPTestItem.Create;
  601. LFTPDir.TestItem := ATestItem;
  602. CheckListParse(LDir,LDirItems,LFormat);
  603. LFTPDir.EvaluateYear := True;
  604. LFTPDir.EvaluateTime := True;
  605. LFTPDir.FoundParser := LFormat;
  606. LFTPDir.ExpectedParser := AExpectedParser;
  607. if LDirItems.Count <> 1 then
  608. begin
  609. raise Exception.Create('Only 1 item from the parser is expected');
  610. end
  611. else
  612. begin
  613. LI := LDirItems[0];
  614. end;
  615. DecodeDate( LI.ModifiedDate,LFTPDir.FFoundYear,LFTPDir.FFoundMonth,LFTPDir.FFoundDay);
  616. DecodeTime( LI.ModifiedDate,LFTPDir.FFoundHour,LFTPDir.FFoundMin,LFTPDir.FFoundSec,LDummy);
  617. LFTPDir.FoundOwner := LI.OwnerName;
  618. LFTPDir.FoundGroup := LI.GroupName;
  619. LFTPDir.FoundFileName := LI.FileName;
  620. LFTPDir.FoundFileSize := LI.Size;
  621. LFTPDir.ExpectedYear := AExpectedYear;
  622. LFTPDir.ExpectedMonth := AExpectedMonth;
  623. LFTPDir.ExpectedDay := AExpectedDay;
  624. LFTPDir.ExpectedHour := AExpectedHour;
  625. LFTPDir.ExpectedMin := AExpectedMin;
  626. LFTPDir.ExpectedSec := AExpectedSec;
  627. LFTPDir.ExpectedOwner := AExpectedOwner;
  628. LFTPDir.ExpectedGroup := AExpectedGroup;
  629. LFTPDir.ExpectedFileName := AExpectedFileName;
  630. LFTPDir.ExpectedFileSize := AExpectedFileSize;
  631. ReportItem(LFTPDir);
  632. finally
  633. FreeAndNil(LFTPDir);
  634. FreeAndNil(LDirItems);
  635. FreeAndNil(LDir);
  636. FreeAndNil(LT);
  637. end;
  638. end;
  639. procedure TdmFTPListTest.TestItem(ATestItem, AExpectedParser,
  640. AExpectedOwner, AExpectedGroup, AExpectedFileName: String;
  641. AExpectedFileSize: Integer; AExpectedMonth, AExpectedDay, AExpectedHour,
  642. AExpectedMin, AExpectedSec: Word);
  643. var LT : TFTPTestItem;
  644. LDir : TStrings;
  645. LDirItems : TIdFTPListItems;
  646. LFormat : String;
  647. LFTPDir : TFTPTestItem;
  648. LI : TIdFTPListItem;
  649. LDummy : Word;
  650. begin
  651. LT := TFTPTestItem.Create;
  652. try
  653. LDir := TStringList.Create;
  654. LDirItems := TIdFTPListItems.Create;
  655. LDir.Add(ATestItem);
  656. LFTPDir := TFTPTestItem.Create;
  657. LFTPDir.TestItem := ATestItem;
  658. CheckListParse(LDir,LDirItems,LFormat);
  659. LFTPDir.EvaluateYear := False;
  660. LFTPDir.EvaluateTime := True;
  661. LFTPDir.FoundParser := LFormat;
  662. LFTPDir.ExpectedParser := AExpectedParser;
  663. if LDirItems.Count <> 1 then
  664. begin
  665. raise Exception.Create('Only 1 item from the parser is expected');
  666. end
  667. else
  668. begin
  669. LI := LDirItems[0];
  670. end;
  671. DecodeDate( LI.ModifiedDate,LFTPDir.FFoundYear,LFTPDir.FFoundMonth,LFTPDir.FFoundDay);
  672. DecodeTime( LI.ModifiedDate,LFTPDir.FFoundHour,LFTPDir.FFoundMin,LFTPDir.FFoundSec,LDummy);
  673. LFTPDir.FoundOwner := LI.OwnerName;
  674. LFTPDir.FoundGroup := LI.GroupName;
  675. LFTPDir.FoundFileName := LI.FileName;
  676. LFTPDir.FoundFileSize := LI.Size;
  677. LFTPDir.ExpectedMonth := AExpectedMonth;
  678. LFTPDir.ExpectedDay := AExpectedDay;
  679. LFTPDir.ExpectedHour := AExpectedHour;
  680. LFTPDir.ExpectedMin := AExpectedMin;
  681. LFTPDir.ExpectedSec := AExpectedSec;
  682. LFTPDir.ExpectedOwner := AExpectedOwner;
  683. LFTPDir.ExpectedGroup := AExpectedGroup;
  684. LFTPDir.ExpectedFileName := AExpectedFileName;
  685. LFTPDir.ExpectedFileSize := AExpectedFileSize;
  686. ReportItem(LFTPDir);
  687. finally
  688. FreeAndNil(LFTPDir);
  689. FreeAndNil(LDirItems);
  690. FreeAndNil(LDir);
  691. FreeAndNil(LT);
  692. end;
  693. end;
  694. procedure TdmFTPListTest.TestItem(ATestItem, AExpectedParser,
  695. AExpectedOwner, AExpectedGroup, AExpectedFileName: String;
  696. AExpectedFileSize: Integer; AExpectedYear, AExpectedMonth, AExpectedDay : Word);
  697. var LT : TFTPTestItem;
  698. LDir : TStrings;
  699. LDirItems : TIdFTPListItems;
  700. LFormat : String;
  701. LFTPDir : TFTPTestItem;
  702. LI : TIdFTPListItem;
  703. LDummy : Word;
  704. begin
  705. LT := TFTPTestItem.Create;
  706. try
  707. LDir := TStringList.Create;
  708. LDirItems := TIdFTPListItems.Create;
  709. LDir.Add(ATestItem);
  710. LFTPDir := TFTPTestItem.Create;
  711. LFTPDir.TestItem := ATestItem;
  712. CheckListParse(LDir,LDirItems,LFormat);
  713. LFTPDir.EvaluateYear := True;
  714. LFTPDir.EvaluateTime := False;
  715. LFTPDir.FoundParser := LFormat;
  716. LFTPDir.ExpectedParser := AExpectedParser;
  717. if LDirItems.Count <> 1 then
  718. begin
  719. raise Exception.Create('Only 1 item from the parser is expected');
  720. end
  721. else
  722. begin
  723. LI := LDirItems[0];
  724. end;
  725. DecodeDate( LI.ModifiedDate,LFTPDir.FFoundYear,LFTPDir.FFoundMonth,LFTPDir.FFoundDay);
  726. DecodeTime( LI.ModifiedDate,LFTPDir.FFoundHour,LFTPDir.FFoundMin,LFTPDir.FFoundSec,LDummy);
  727. LFTPDir.FoundOwner := LI.OwnerName;
  728. LFTPDir.FoundGroup := LI.GroupName;
  729. LFTPDir.FoundFileName := LI.FileName;
  730. LFTPDir.FoundFileSize := LI.Size;
  731. LFTPDir.ExpectedYear := AExpectedYear;
  732. LFTPDir.ExpectedMonth := AExpectedMonth;
  733. LFTPDir.ExpectedDay := AExpectedDay;
  734. LFTPDir.ExpectedOwner := AExpectedOwner;
  735. LFTPDir.ExpectedGroup := AExpectedGroup;
  736. LFTPDir.ExpectedFileName := AExpectedFileName;
  737. LFTPDir.ExpectedFileSize := AExpectedFileSize;
  738. ReportItem(LFTPDir);
  739. finally
  740. FreeAndNil(LFTPDir);
  741. FreeAndNil(LDirItems);
  742. FreeAndNil(LDir);
  743. FreeAndNil(LT);
  744. end;
  745. end;
  746. procedure TdmFTPListTest.bxWin32IISFormsTest(Sender: TBXBubble);
  747. begin
  748. {Note that these were taken from comments in the FileZilla source-code.
  749. Note that no GNU source-code from that program was used in source-code.
  750. }
  751. //04-27-00 09:09PM <DIR> DOS dir 1
  752. TestItem(
  753. '04-27-00 09:09PM <DIR> DOS dir 1',
  754. WINNTID,
  755. 'DOS dir 1',
  756. 0,
  757. 2000,
  758. 4,
  759. 27,
  760. 21,
  761. 9,
  762. 0);
  763. //04-14-00 03:47PM 589 DOS file 1
  764. // procedure TestItem(
  765. // ATestItem,
  766. // AExpectedParser,
  767. // AExpectedFileName : String;
  768. // AExpectedFileSize : Integer;
  769. // AExpectedYear,
  770. // AExpectedMonth,
  771. // AExpectedDay,
  772. // AExpectedHour,
  773. // AExpectedMin,
  774. // AExpectedSec : Word); overload;
  775. //Microsoft IIS using Unix format
  776. TestItem(
  777. '04-14-00 03:47PM 589 DOS file 1',
  778. WINNTID,
  779. 'DOS file 1',
  780. 589,
  781. 2000,
  782. 4,
  783. 14,
  784. 15,
  785. 47,
  786. 0);
  787. //2002-09-02 18:48 <DIR> DOS dir 2
  788. TestItem(
  789. '2002-09-02 18:48 <DIR> DOS dir 2',
  790. WINNTID,
  791. 'DOS dir 2',
  792. 0,
  793. 2002,
  794. 9,
  795. 2,
  796. 18,
  797. 48,
  798. 0);
  799. //2002-09-02 19:06 9,730 DOS file 2
  800. TestItem(
  801. '2002-09-02 19:06 9,730 DOS file 2',
  802. WINNTID,
  803. 'DOS file 2',
  804. 9730,
  805. 2002,
  806. 9,
  807. 2,
  808. 19,
  809. 6,
  810. 0);
  811. end;
  812. procedure TdmFTPListTest.bxSterlingComTestsTest(Sender: TBXBubble);
  813. begin
  814. TestItem(
  815. '-C--E-----FTP B QUA1I1 18128 41 Aug 12 13:56 QUADTEST',
  816. STIRCOMUNIX,
  817. 'QUA1I1',
  818. '',
  819. 'QUADTEST',
  820. 41,
  821. 8,
  822. 12,
  823. 13,
  824. 56,
  825. 0);
  826. TestItem(
  827. '-C--E-----FTP A QUA1I1 18128 41 Aug 12 13:56 QUADTEST2',
  828. STIRCOMUNIX,
  829. 'QUA1I1',
  830. '',
  831. 'QUADTEST2',
  832. 41,
  833. 8,
  834. 12,
  835. 13,
  836. 56,
  837. 0);
  838. TestItem(
  839. '-ARTE-----TCP A cbeodm 22159 629629 Aug 06 05:47 PSEUDOFILENAME',
  840. STIRCOMUNIX,
  841. 'cbeodm',
  842. '',
  843. 'PSEUDOFILENAME',
  844. 629629,
  845. 8,
  846. 6,
  847. 5,
  848. 47,
  849. 0);
  850. TestItem(
  851. 'solution 00003444 00910368 <c3957010.zip.001> 030924-1636 A R TCP BIN',
  852. STIRCOMUNIXNS,
  853. 'solution',
  854. '',
  855. 'c3957010.zip.001',
  856. 00910368,
  857. 2003,
  858. 9,
  859. 24,
  860. 16,
  861. 36,
  862. 0);
  863. TestItem('solution 00003048 00007341 <POST1202.P1182069.R>+ 030926-0832 A RT TCP ASC',
  864. STIRCOMUNIXNS,
  865. 'solution',
  866. '',
  867. 'POST1202.P1182069.R', //filename was truncated by the dir format
  868. 00007341,
  869. 2003,
  870. 9,
  871. 26,
  872. 8,
  873. 32,
  874. 0);
  875. {
  876. From:
  877. "Connect:Enterprise® UNIX Remote User’s Guide Version 2.1 " Copyright
  878. 1999, 2002, 2003 Sterling Commerce, Inc.
  879. ==
  880. -C--E-----FTP A steve 2 41 Sep 02 13:47 test.c
  881. -SR--M------- A steve 1 369 Sep 02 13:47 <<ACTIVITY LOG>>
  882. Total number of batches listed: 2
  883. ==
  884. }
  885. TestItem('-C--E-----FTP A steve 2 41 Sep 02 13:47 test.c',
  886. STIRCOMUNIX,
  887. 'steve',
  888. '',
  889. 'test.c',
  890. 41,
  891. 9,
  892. 2,
  893. 13,
  894. 47,
  895. 0);
  896. TestItem('-SR--M------- A steve 1 369 Sep 02 13:47 <<ACTIVITY LOG>>',
  897. STIRCOMUNIX,
  898. 'steve',
  899. '',
  900. '<<ACTIVITY LOG>>',
  901. 369,
  902. 9,
  903. 2,
  904. 13,
  905. 47,
  906. 0);
  907. {The proper parser is incapable of returning a date}
  908. TestItem('d - - - - - - - steve',
  909. STIRCOMUNIXROOT,
  910. '',
  911. '',
  912. 'steve',
  913. 0,
  914. 12,
  915. 30,
  916. 0,
  917. 0,
  918. 0);
  919. {Sterling Commerce Express for OS/390 tests}
  920. TestItem('-D 2 T VB 00244 18000 FTPGDG!PSR$TST.GDG.TSTGDG0(+01)',
  921. STIRCOMEXPOS390,
  922. '',
  923. '',
  924. 'FTPGDG!PSR$TST.GDG.TSTGDG0(+01)',
  925. 0,
  926. 12,
  927. 30,
  928. 0,
  929. 0,
  930. 0);
  931. TestItem('-D 2 * VB 00244 27800 FTPV!PSR$TST.A.VVV.&REQNUMB',
  932. STIRCOMEXPOS390,
  933. '',
  934. '',
  935. 'FTPV!PSR$TST.A.VVV.&REQNUMB',
  936. 0,
  937. 12,
  938. 30,
  939. 0,
  940. 0,
  941. 0);
  942. TestItem('-F 1 R - - - FTPVAL1!PSR$TST.A.VVV',
  943. STIRCOMEXPOS390,
  944. '',
  945. '',
  946. 'FTPVAL1!PSR$TST.A.VVV',
  947. 0,
  948. 12,
  949. 30,
  950. 0,
  951. 0,
  952. 0);
  953. end;
  954. procedure TdmFTPListTest.bxOS2TestTest(Sender: TBXBubble);
  955. { From: Jakarta Apache project's test suite.
  956. " 0 DIR 12-30-97 12:32 jbrekke",
  957. " 0 DIR 11-25-97 09:42 junk",
  958. " 0 DIR 05-12-97 16:44 LANGUAGE",
  959. " 0 DIR 05-19-97 12:56 local",
  960. " 0 DIR 05-12-97 16:52 Maintenance Desktop",
  961. " 0 DIR 05-13-97 10:49 MPTN",
  962. "587823 RSA DIR 01-08-97 13:58 OS2KRNL",
  963. " 33280 A 02-09-97 13:49 OS2LDR",
  964. " 0 DIR 11-28-97 09:42 PC",
  965. "149473 A 11-17-98 16:07 POPUPLOG.OS2",
  966. " 0 DIR 05-12-97 16:44 PSFONTS"
  967. }
  968. begin
  969. {note that some of servers are probably NOT Y2K complient}
  970. TestItem(
  971. ' 0 DIR 12-30-97 12:32 jbrekke',
  972. OS2PARSER,
  973. 'jbrekke',
  974. 0,
  975. 1997,
  976. 12,
  977. 30,
  978. 12,
  979. 32,
  980. 0);
  981. TestItem(
  982. ' 73098 A 04-06-97 15:15 ds0.internic.net1996052434624.txt',
  983. OS2PARSER,
  984. 'ds0.internic.net1996052434624.txt',
  985. 73098,
  986. 1997,
  987. 4,
  988. 6,
  989. 15,
  990. 15,
  991. 0);
  992. {
  993. taken from the FileZilla source-code comments
  994. " 0 DIR 05-12-97 16:44 PSFONTS"
  995. "36611 A 04-23-103 10:57 OS2 test1.file"
  996. " 1123 A 07-14-99 12:37 OS2 test2.file"
  997. " 0 DIR 02-11-103 16:15 OS2 test1.dir"
  998. " 1123 DIR A 10-05-100 23:38 OS2 test2.dir"
  999. }
  1000. TestItem(
  1001. ' 0 DIR 05-12-97 16:44 PSFONTS',
  1002. OS2PARSER,
  1003. 'PSFONTS',
  1004. 0,
  1005. 1997,
  1006. 5,
  1007. 12,
  1008. 16,
  1009. 44,
  1010. 0);
  1011. TestItem(
  1012. '36611 A 04-23-103 10:57 OS2 test1.file',
  1013. OS2PARSER,
  1014. 'OS2 test1.file',
  1015. 36611,
  1016. 2003,
  1017. 4,
  1018. 23,
  1019. 10,
  1020. 57,
  1021. 0);
  1022. TestItem(
  1023. ' 1123 A 07-14-99 12:37 OS2 test2.file',
  1024. OS2PARSER,
  1025. 'OS2 test2.file',
  1026. 1123,
  1027. 1999,
  1028. 7,
  1029. 14,
  1030. 12,
  1031. 37,
  1032. 0);
  1033. TestItem(
  1034. ' 0 DIR 02-11-103 16:15 OS2 test1.dir',
  1035. OS2PARSER,
  1036. 'OS2 test1.dir',
  1037. 0,
  1038. 2003,
  1039. 2,
  1040. 11,
  1041. 16,
  1042. 15,
  1043. 0);
  1044. TestItem(
  1045. ' 1123 DIR A 10-05-100 23:38 OS2 test2.dir',
  1046. OS2PARSER,
  1047. 'OS2 test2.dir',
  1048. 1123,
  1049. 2000,
  1050. 10,
  1051. 5,
  1052. 23,
  1053. 38,
  1054. 0);
  1055. end;
  1056. end.