tdos2.pp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. { %INTERACTIVE }
  2. {******************************************}
  3. { Used to check the DOS unit }
  4. {------------------------------------------}
  5. { Requirements for this unit can be }
  6. { found in testdos.htm }
  7. {******************************************}
  8. Program TestDos;
  9. Uses Dos;
  10. {**********************************************************************}
  11. { Some specific OS verifications : }
  12. { Mainly for file attributes: }
  13. { Read-Only }
  14. { Hidden }
  15. { System File }
  16. { only work on Win32, OS/2 and DOS }
  17. {$IFDEF MSDOS}
  18. {$DEFINE EXTATTR}
  19. {$ENDIF}
  20. {$IFDEF DPMI}
  21. {$DEFINE EXTATTR}
  22. {$ENDIF}
  23. {$IFDEF GO32V1}
  24. {$DEFINE EXTATTR}
  25. {$ENDIF}
  26. {$IFDEF GO32V2}
  27. {$DEFINE EXTATTR}
  28. {$ENDIF}
  29. {$IFDEF OS2}
  30. {$DEFINE EXTATTR}
  31. {$ENDIF}
  32. {$IFDEF WIN32}
  33. {$DEFINE EXTATTR}
  34. {$ENDIF}
  35. {$IFDEF TOS}
  36. {$DEFINE EXTATTR}
  37. {$ENDIF}
  38. {$IFNDEF UNIX}
  39. {$IFDEF LINUX}
  40. {$DEFINE UNIX}
  41. {$ENDIF}
  42. {$IFDEF QNX}
  43. {$DEFINE UNIX}
  44. {$ENDIF}
  45. {$IFDEF SOLARIS}
  46. {$DEFINE UNIX}
  47. {$ENDIF}
  48. {$IFDEF FREEBSD}
  49. {$DEFINE UNIX}
  50. {$ENDIF}
  51. {$IFDEF BEOS}
  52. {$DEFINE UNIX}
  53. {$ENDIF}
  54. {$ENDIF}
  55. {**********************************************************************}
  56. CONST
  57. { what is the root path }
  58. {$IFDEF EXTATTR}
  59. RootPath = 'C:\';
  60. {$ENDIF}
  61. {$IFDEF UNIX}
  62. RootPath = '/';
  63. {$ENDIF}
  64. Week:Array[0..6] of String =
  65. ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  66. TestFName = 'TESTDOS.DAT'; { CASE SENSITIVE DON'T TOUCH! }
  67. TestFName1 = 'TESTFILE'; { CASE SENSITIVE DON'T TOUCH! }
  68. TestDir = 'MYDIR'; { CASE SENSITIVE DON'T TOUCH! }
  69. TestExt = 'DAT';
  70. Procedure PauseScreen;
  71. var
  72. ch: char;
  73. Begin
  74. WriteLn('-- Press any key --');
  75. ReadLn;
  76. end;
  77. { verifies that the DOSError variable is equal to }
  78. { the value requested. }
  79. Procedure CheckDosError(err: Integer);
  80. var
  81. x : integer;
  82. s :string;
  83. Begin
  84. Write('Verifying value of DOS Error...');
  85. x := DosError;
  86. case x of
  87. 0 : s := '(0): No Error.';
  88. 2 : s := '(2): File not found.';
  89. 3 : s := '(3): Path not found.';
  90. 5 : s := '(5): Access Denied.';
  91. 6 : s := '(6): Invalid File Handle.';
  92. 8 : s := '(8): Not enough memory.';
  93. 10 : s := '(10) : Invalid Environment.';
  94. 11 : s := '(11) : Invalid format.';
  95. 18 : s := '(18) : No more files.';
  96. else
  97. s := 'INVALID DOSERROR';
  98. end;
  99. if err <> x then
  100. Begin
  101. WriteLn('FAILURE. (Value should be ',err,' '+s+')');
  102. end
  103. else
  104. WriteLn('Success.');
  105. end;
  106. Procedure TestdiskSize;
  107. Var
  108. i : Integer;
  109. Begin
  110. WriteLn('----------------------------------------------------------------------');
  111. WriteLn(' DISKSIZE/DISKFREE ');
  112. WriteLn('----------------------------------------------------------------------');
  113. WriteLn(' Note: Should return -1 on both functions if device is not ready. ');
  114. WriteLn('----------------------------------------------------------------------');
  115. CheckDosError(0);
  116. { Check Disksize / DiskFree routines }
  117. for I:=0 to 20 do
  118. Begin
  119. Write('Disk unit ',i:2,' free size : ',DiskFree(i):10, ' Total Size: ',DiskSize(i):10);
  120. WriteLn(' bytes.');
  121. end;
  122. CheckDosError(0);
  123. PauseScreen;
  124. end;
  125. Procedure TestDosVersion;
  126. Begin
  127. WriteLn('----------------------------------------------------------------------');
  128. WriteLn(' DOSVERSION ');
  129. WriteLn('----------------------------------------------------------------------');
  130. WriteLn(' Note: Number should be major version followed by minor version. ');
  131. WriteLn('----------------------------------------------------------------------');
  132. CheckDosError(0);
  133. {*------------------------- NOTE -------------------------------------*}
  134. {* This is OS specific. LO -> Major revision, HI -> Minor Revision *}
  135. {*--------------------------------------------------------------------*}
  136. WriteLn('Operating system Version :',Lo(DosVersion),'.',Hi(DosVersion));
  137. CheckDosError(0);
  138. PauseScreen;
  139. end;
  140. Procedure TestEnvCount;
  141. Var
  142. I: Integer;
  143. Begin
  144. WriteLn('----------------------------------------------------------------------');
  145. WriteLn(' ENVCOUNT/ENVSTR ');
  146. WriteLn('----------------------------------------------------------------------');
  147. WriteLn(' Note: Environment variables should be of the form VAR=VALUE ');
  148. WriteLn(' Note: Non valid indexes should return empty strings. ');
  149. WriteLn(' Note: Index 0 points to an empty string ');
  150. WriteLn('----------------------------------------------------------------------');
  151. CheckDosError(0);
  152. PauseScreen;
  153. {*------------------------- NOTE -------------------------------------*}
  154. {* Variables should be of the form VAR=VALUE *}
  155. {*--------------------------------------------------------------------*}
  156. WriteLn('Number of environment variables : ',EnvCount);
  157. WriteLn('CURRENT ENVIRONMENT');
  158. For I:=1 to EnvCount do
  159. WriteLn(EnvStr(i));
  160. CheckDosError(0);
  161. WriteLn('----------------------------------------------------------------------');
  162. WriteLn(' Note: The next few lines should be empty strings, as they are ');
  163. WriteLn(' invalid environment indexes. ');
  164. WriteLn('----------------------------------------------------------------------');
  165. For i:=-5 to 0 do
  166. WriteLn(EnvStr(i));
  167. CheckDosError(0);
  168. For i:=20000 to 20002 do
  169. WriteLn(EnvStr(i));
  170. CheckDosError(0);
  171. PauseScreen;
  172. end;
  173. Procedure TestVerify;
  174. Var
  175. B: Boolean;
  176. s: string;
  177. Begin
  178. WriteLn('----------------------------------------------------------------------');
  179. WriteLn(' GETVERIFY/SETVERIFY ');
  180. WriteLn('----------------------------------------------------------------------');
  181. CheckDosError(0);
  182. s:='Testing GetVerify...';
  183. SetVerify(TRUE);
  184. CheckDosError(0);
  185. GetVerify(b);
  186. CheckDosError(0);
  187. if b then
  188. WriteLn(s+'Success.')
  189. else
  190. Begin
  191. WriteLn(s+'FAILURE.');
  192. end;
  193. s:='Testing GetVerify...';
  194. SetVerify(FALSE);
  195. CheckDosError(0);
  196. GetVerify(b);
  197. CheckDosError(0);
  198. { verify actually only works under dos }
  199. { and always returns TRUE on other platforms }
  200. {$ifdef go32v2}
  201. if NOT b then
  202. WriteLn(s+'Success.')
  203. else
  204. Begin
  205. WriteLn(s+'FAILURE.');
  206. end;
  207. {$else}
  208. if b then
  209. WriteLn(s+'Success.')
  210. else
  211. Begin
  212. WriteLn(s+'FAILURE.');
  213. end;
  214. {$endif}
  215. PauseScreen;
  216. end;
  217. Procedure TestCBreak;
  218. Var
  219. B: Boolean;
  220. s: string;
  221. Begin
  222. WriteLn('----------------------------------------------------------------------');
  223. WriteLn(' GETCBREAK/SETCBREAK ');
  224. WriteLn('----------------------------------------------------------------------');
  225. CheckDosError(0);
  226. s:='Testing GetCBreak...';
  227. SetCBreak(TRUE);
  228. CheckDosError(0);
  229. GetCBreak(b);
  230. CheckDosError(0);
  231. if b then
  232. WriteLn(s+'Success.')
  233. else
  234. Begin
  235. WriteLn(s+'FAILURE.');
  236. end;
  237. { actually setting Ctrl-C only works under DOS }
  238. {$ifdef go32v2}
  239. s:='Testing GetCBreak...';
  240. SetCBreak(FALSE);
  241. CheckDosError(0);
  242. GetCBreak(b);
  243. CheckDosError(0);
  244. if NOT b then
  245. WriteLn(s+'Success.')
  246. else
  247. Begin
  248. WriteLn(s+'FAILURE.');
  249. end;
  250. {$endif}
  251. PauseScreen;
  252. end;
  253. Procedure TestSystemDate;
  254. var
  255. Year,Month, DayOfWeek, Day: Word;
  256. Year1,Month1, DayOfWeek1, Day1: Word;
  257. s: string;
  258. Begin
  259. WriteLn('----------------------------------------------------------------------');
  260. WriteLn(' GETDATE ');
  261. WriteLn('----------------------------------------------------------------------');
  262. WriteLn(' Note: Number of week should be consistent (0 = Sunday) ');
  263. WriteLn(' Note: Year should contain full four digits. ');
  264. WriteLn('----------------------------------------------------------------------');
  265. CheckDosError(0);
  266. Month:=0;
  267. Day:=0;
  268. DayOfWeek:=0;
  269. Year:=0;
  270. GetDate(Year,Month,Day,DayOfWeek);
  271. CheckDosError(0);
  272. Write('DD-MM-YYYY : ',Day,'-',Month,'-',Year);
  273. WriteLn(' (',Week[DayOfWeek],')');
  274. PauseScreen;
  275. WriteLn('----------------------------------------------------------------------');
  276. WriteLn(' SETDATE ');
  277. WriteLn('----------------------------------------------------------------------');
  278. { normal call }
  279. SetDate(Year,Month,Day);
  280. CheckDosError(0);
  281. { setdate and settime is not supported on most platforms }
  282. {$ifdef go32v2}
  283. s:='Testing with invalid year....';
  284. SetDate(98,Month,Day);
  285. CheckDosError(0);
  286. GetDate(Year1,Month1,Day1,DayOfWeek1);
  287. CheckDosError(0);
  288. if (Year1 <> Year) or (Month1 <> month) or (Day1 <> Day) then
  289. Begin
  290. WriteLn(s+'FAILURE.');
  291. end
  292. else
  293. WriteLn(s+'Success.');
  294. SetDate(Year,Month,255);
  295. CheckDosError(0);
  296. s:='Testing with invalid day.....';
  297. GetDate(Year1,Month1,Day1,DayOfWeek1);
  298. CheckDosError(0);
  299. if (Year1 <> Year) or (Month1 <> month) or (Day1 <> Day) then
  300. Begin
  301. WriteLn(s+'FAILURE.');
  302. end
  303. else
  304. WriteLn(s+'Success.');
  305. SetDate(Year,13,Day);
  306. CheckDosError(0);
  307. s:='Testing with invalid month...';
  308. GetDate(Year1,Month1,Day1,DayOfWeek1);
  309. CheckDosError(0);
  310. if (Year1 <> Year) or (Month1 <> month) or (Day1 <> Day) then
  311. Begin
  312. WriteLn(s+'FAILURE.');
  313. end
  314. else
  315. WriteLn(s+'Success.');
  316. WriteLn('----------------------------------------------------------------------');
  317. WriteLn(' Note: Date should be 01-01-1998 ');
  318. WriteLn('----------------------------------------------------------------------');
  319. SetDate(1998,01,01);
  320. CheckDosError(0);
  321. GetDate(Year1,Month1,Day1,DayOfWeek1);
  322. CheckDosError(0);
  323. WriteLn('DD-MM-YYYY : ',Day1,'-',Month1,'-',Year1);
  324. SetDate(Year,Month,Day);
  325. CheckDosError(0);
  326. WriteLn('----------------------------------------------------------------------');
  327. WriteLn(' Note: Date should be restored to previous value ');
  328. WriteLn('----------------------------------------------------------------------');
  329. GetDate(Year1,Month1,Day1,DayOfWeek1);
  330. CheckDosError(0);
  331. WriteLn('DD-MM-YYYY : ',Day1,'-',Month1,'-',Year1);
  332. PauseScreen;
  333. {$endif}
  334. end;
  335. Procedure TestsystemTime;
  336. Var
  337. Hour, Minute, Second, Sec100: word;
  338. Hour1, Minute1, Second1, Sec1001: word;
  339. Begin
  340. WriteLn('----------------------------------------------------------------------');
  341. WriteLn(' GETTIME ');
  342. WriteLn('----------------------------------------------------------------------');
  343. WriteLn(' Note: Hours should be in military format (0..23), and MSec in 0..100 ');
  344. WriteLn('----------------------------------------------------------------------');
  345. CheckDosError(0);
  346. Hour:=0;
  347. Minute:=0;
  348. Second:=0;
  349. Sec100:=0;
  350. GetTime(Hour,Minute,Second,Sec100);
  351. CheckDosError(0);
  352. WriteLn('HH:MIN:SEC (MS): ',Hour,':',Minute,':',Second,' (',Sec100,')');
  353. WriteLn('----------------------------------------------------------------------');
  354. WriteLn(' SETTIME ');
  355. WriteLn('----------------------------------------------------------------------');
  356. WriteLn(' Note: GetTime should return the same value as the previous test. ');
  357. WriteLn('----------------------------------------------------------------------');
  358. SetTime(36,Minute,Second,Sec100);
  359. CheckDosError(0);
  360. GetTime(Hour1,Minute1,Second1,Sec1001);
  361. CheckDosError(0);
  362. WriteLn('HH:MIN:SEC ',Hour1,':',Minute1,':',Second1);
  363. { actual settime is only supported under DOS }
  364. {$ifdef go32v2}
  365. SetTime(Hour,32000,Second,Sec100);
  366. CheckDosError(0);
  367. GetTime(Hour1,Minute1,Second1,Sec1001);
  368. CheckDosError(0);
  369. WriteLn('HH:MIN:SEC ',Hour1,':',Minute1,':',Second1);
  370. WriteLn('----------------------------------------------------------------------');
  371. WriteLn(' Note: GetTime should return 0:0:0 ');
  372. WriteLn('----------------------------------------------------------------------');
  373. SetTime(0,0,0,0);
  374. CheckDosError(0);
  375. GetTime(Hour1,Minute1,Second1,Sec1001);
  376. CheckDosError(0);
  377. WriteLn('HH:MIN:SEC ',Hour1,':',Minute1,':',Second1);
  378. WriteLn('----------------------------------------------------------------------');
  379. WriteLn(' Note: GetTime should return approximately the original time ');
  380. WriteLn('----------------------------------------------------------------------');
  381. SetTime(Hour,Minute,Second,Sec1001);
  382. CheckDosError(0);
  383. GetTime(Hour1,Minute1,Second1,Sec1001);
  384. CheckDosError(0);
  385. WriteLn('HH:MIN:SEC ',Hour1,':',Minute1,':',Second1);
  386. {$endif}
  387. end;
  388. Procedure TestFAttr;
  389. Var
  390. F: File;
  391. Attr: Word;
  392. s: string;
  393. Begin
  394. PauseScreen;
  395. WriteLn('----------------------------------------------------------------------');
  396. WriteLn(' GETFATTR / SETFATTR ');
  397. WriteLn('----------------------------------------------------------------------');
  398. CheckDosError(0);
  399. WriteLn('Opening an invalid file...Success.');
  400. Assign(f,'');
  401. GetFAttr(f,Attr);
  402. CheckDosError(3);
  403. Assign(f,TestFName);
  404. WriteLn('Trying to open a valid file..Success.');
  405. GetFAttr(f,Attr);
  406. CheckDosError(0);
  407. {----------------------------------------------------------------}
  408. { This routine causes problems, because it all depends on the }
  409. { operating system. It is assumed here that HIDDEN is available }
  410. { to all operating systems. }
  411. {----------------------------------------------------------------}
  412. s:='Setting read-only attribute on '+TestFName+'...';
  413. SetFAttr(f,ReadOnly);
  414. CheckDosError(0);
  415. {$IFDEF EXTATTR}
  416. GetFAttr(f,Attr);
  417. CheckDosError(0);
  418. if Attr and ReadOnly<> 0 then
  419. WriteLn(s+'Success.')
  420. else
  421. Begin
  422. WriteLn(s+'FAILURE. Read-only attribute not set.');
  423. end;
  424. { file should no longer be read only }
  425. s:='Removing read-only attribute...';
  426. SetFAttr(f,Archive);
  427. CheckDosError(0);
  428. GetFAttr(f,Attr);
  429. CheckDosError(0);
  430. if Attr and ReadOnly<> 0 then
  431. Begin
  432. WriteLn(s+'FAILURE. Read-only attribute still set.');
  433. end
  434. else
  435. WriteLn(s+'Success.');
  436. {$ENDIF}
  437. s:='Setting hidden attribute on '+TestFName+'...';
  438. SetFAttr(f,Hidden);
  439. CheckDosError(0);
  440. {$IFDEF EXTATTR}
  441. GetFAttr(f,Attr);
  442. CheckDosError(0);
  443. if Attr and Hidden<> 0 then
  444. WriteLn(s+'Success.')
  445. else
  446. Begin
  447. WriteLn(s+'FAILURE. Hidden attribute not set.');
  448. end;
  449. { file should no longer be read only }
  450. s:='Removing hidden attribute...';
  451. SetFAttr(f,Archive);
  452. CheckDosError(0);
  453. GetFAttr(f,Attr);
  454. CheckDosError(0);
  455. if Attr and Hidden<> 0 then
  456. Begin
  457. WriteLn(s+'FAILURE. Hidden attribute still set.');
  458. end
  459. else
  460. WriteLn(s+'Success.');
  461. {$ENDIF}
  462. s:='Setting system attribute on '+TestFName+'...';
  463. SetFAttr(f,SysFile);
  464. CheckDosError(0);
  465. {$IFDEF EXTATTR}
  466. GetFAttr(f,Attr);
  467. CheckDosError(0);
  468. if Attr and SysFile<> 0 then
  469. WriteLn(s+'Success.')
  470. else
  471. Begin
  472. WriteLn(s+'FAILURE. SysFile attribute not set.');
  473. end;
  474. { file should no longer be read only }
  475. s:='Removing read-only attribute...';
  476. SetFAttr(f,Archive);
  477. CheckDosError(0);
  478. GetFAttr(f,Attr);
  479. CheckDosError(0);
  480. if Attr and Sysfile<> 0 then
  481. Begin
  482. WriteLn(s+'FAILURE. SysFile attribute still set.');
  483. end
  484. else
  485. WriteLn(s+'Success.');
  486. {$ENDIF}
  487. s:='Setting Directory attribute on '+TestFName+'...';
  488. SetFAttr(f,Directory);
  489. CheckDosError(5);
  490. GetFAttr(f,Attr);
  491. CheckDosError(0);
  492. if Attr and Directory<> 0 then
  493. Begin
  494. WriteLn(s+'FAILURE. Directory Attribute set.');
  495. end
  496. else
  497. WriteLn(s+'Success.');
  498. {**********************************************************************}
  499. {********************** TURBO PASCAL BUG ******************************}
  500. { The File is not a volume name, and DosError = 0, which is incorrect }
  501. { it shoulf not be so in FPC. }
  502. {**********************************************************************}
  503. {********************** TURBO PASCAL BUG ******************************}
  504. s:='Setting Volume attribute on '+TestFName+'...';
  505. SetFAttr(f,VolumeID);
  506. CheckDosError(5);
  507. GetFAttr(f,Attr);
  508. CheckDosError(0);
  509. if Attr and VolumeID<> 0 then
  510. Begin
  511. WriteLn(s+'FAILURE. Volume Attribute set.');
  512. end
  513. else
  514. WriteLn(s+'Success.');
  515. PauseScreen;
  516. end;
  517. Procedure TestFTime;
  518. var
  519. s : string;
  520. F: File;
  521. Time: Longint;
  522. DT: DateTime;
  523. DT1 : Datetime; { saved values }
  524. Begin
  525. WriteLn('----------------------------------------------------------------------');
  526. WriteLn(' GETFTIME / SETFTIME ');
  527. WriteLn('----------------------------------------------------------------------');
  528. CheckDosError(0);
  529. {**********************************************************************}
  530. {********************** TURBO PASCAL BUG ******************************}
  531. { The File is not Open and DosError is still zero! THIS SHOULD NOT BE }
  532. { SO IN FPC! }
  533. {**********************************************************************}
  534. {********************** TURBO PASCAL BUG ******************************}
  535. Write('Opening an invalid file...');
  536. Assign(f,'x');
  537. GetFTime(f,Time);
  538. CheckDosError(6);
  539. Write('Trying to open ',TestFName,'...');
  540. Assign(f,TestFName);
  541. Reset(f,1);
  542. GetFTime(f,Time);
  543. CheckDosError(0);
  544. UnpackTime(Time,Dt);
  545. WriteLn('----------------------------------------------------------------------');
  546. WriteLn(' Note: Hour should be in military format and year should be a 4 digit ');
  547. WriteLn(' number. ');
  548. WriteLn('----------------------------------------------------------------------');
  549. WriteLn('DD-MM-YYYY : ',DT.Day,'-',DT.Month,'-',DT.Year);
  550. WriteLn('HH:MIN:SEC ',DT.Hour,':',DT.Min,':',DT.Sec);
  551. { SETFTIME / GETFTIME No Range checking is performed so the tests are }
  552. { very limited. }
  553. s:='Setting '+TestFName+' date/time to 01-28-1998:0:0:0...';
  554. dt1.Year:=1998;
  555. dt1.Month:=1;
  556. dt1.Day:=28;
  557. Dt1.Hour:=0;
  558. Dt1.Min:=0;
  559. Dt1.Sec:=0;
  560. PackTime(DT1,Time);
  561. CheckDosError(0);
  562. SetFTime(f,Time);
  563. CheckDosError(0);
  564. GetFTime(f,Time);
  565. CheckDosError(0);
  566. { Re-initialize the date time file }
  567. FillChar(Dt1,sizeof(dt1),#0);
  568. UnpackTime(Time,Dt1);
  569. if (Dt1.Year <> 1998) or (Dt1.Month<>1) or (Dt1.Day<>28) or
  570. (Dt1.Hour<>0) or (Dt1.Min <>0) or (Dt1.Sec<>0) then
  571. Begin
  572. WriteLn(s+'FAILURE.');
  573. end
  574. else
  575. WriteLn(s+'Success.');
  576. s:='Restoring old file time stamp...';
  577. Move(Dt,Dt1,sizeof(Dt));
  578. PackTime(DT1,Time);
  579. CheckDosError(0);
  580. SetFTime(f,Time);
  581. CheckDosError(0);
  582. GetFTime(f,Time);
  583. CheckDosError(0);
  584. { Re-initialize the date time file }
  585. FillChar(Dt1,sizeof(dt),#0);
  586. UnpackTime(Time,Dt1);
  587. if (Dt1.Year <> Dt.Year) or (Dt1.Month<>Dt.Month) or (Dt1.Day<>Dt.Day) or
  588. (Dt1.Hour<>Dt.Hour) or (Dt1.Min <> Dt.Min) or (Dt1.Sec<>Dt.Sec) then
  589. Begin
  590. WriteLn(s+'FAILURE.');
  591. end
  592. else
  593. WriteLn(s+'Success.');
  594. Close(f);
  595. end;
  596. Procedure TestFind;
  597. var
  598. Search: SearchRec;
  599. DT: Datetime;
  600. Year, Month, Day, DayOfWeek: Word;
  601. Failure : Boolean;
  602. FoundDot, FoundDotDot: boolean;
  603. FoundDir : boolean;
  604. s : string;
  605. Begin
  606. WriteLn('----------------------------------------------------------------------');
  607. WriteLn(' FINDFIRST/ FINDNEXT ');
  608. WriteLn('----------------------------------------------------------------------');
  609. WriteLn(' Note: The full path should NOT be displayed. ');
  610. WriteLn('----------------------------------------------------------------------');
  611. CheckDosError(0);
  612. WriteLn('Trying to find an invalid file ('''') with Any Attribute...');
  613. FindFirst('',AnyFile,Search);
  614. CheckDosError(3);
  615. {$IFDEF FPC}
  616. FindClose(Search);
  617. {$ENDIF}
  618. WriteLn('Trying to find an invalid file ('''') with VolumeID attribute...');
  619. FindFirst('',VolumeID,Search);
  620. CheckDosError(3);
  621. {$IFDEF FPC}
  622. FindClose(Search);
  623. {$ENDIF}
  624. WriteLn('Trying to find an invalid file (''''zz.dat'''') with Any Attribute...');
  625. FindFirst('zz.dat',AnyFile,Search);
  626. CheckDosError(18);
  627. {$IFDEF FPC}
  628. FindClose(Search);
  629. {$ENDIF}
  630. WriteLn('Trying to find an invalid file (''''zz.dat'''') with VolumeID attribute...');
  631. FindFirst('zz.dat',VolumeID,Search);
  632. CheckDosError(18);
  633. {$IFDEF FPC}
  634. FindClose(Search);
  635. {$ENDIF}
  636. WriteLn('Trying to find an invalid file (''''zz.dat'''') with Directory attribute...');
  637. FindFirst('zz.dat',Directory,Search);
  638. CheckDosError(18);
  639. {$IFDEF FPC}
  640. FindClose(Search);
  641. {$ENDIF}
  642. s:='Looking for '+TestFName +' with Any Attribute...';
  643. FindFirst('*.DAT',AnyFile,Search);
  644. if Search.Name <> TestFName then
  645. Begin
  646. repeat
  647. FindNext(Search);
  648. until (DosError <> 0) OR (Search.Name = TestFName);
  649. end;
  650. if Search.Name <> TestFName then
  651. { At least testdos.dat should appear }
  652. WriteLn(s+'FAILURE. ',TestFName,' should be found.')
  653. else
  654. WriteLn(s+'Success.');
  655. {$IFDEF FPC}
  656. FindClose(Search);
  657. {$ENDIF}
  658. { In addition to normal files }
  659. { directory files should also be found }
  660. s:='Looking for '+TestFName +' with Directory Attribute...';
  661. FindFirst('*.DAT',Directory,Search);
  662. if DosError<> 0 then
  663. WriteLn(s+'FAILURE. ',TestFName,' should be found.')
  664. else
  665. WriteLn(s+'Success.');
  666. if Search.Name <> TestFName then
  667. Begin
  668. repeat
  669. FindNext(Search);
  670. until (DosError <> 0) OR (Search.Name = TestFName);
  671. end;
  672. {$IFDEF FPC}
  673. FindClose(Search);
  674. {$ENDIF}
  675. Write('Checking file stats of ',TestFName,'...');
  676. UnpackTime(Search.Time,DT);
  677. GetDate(Year, Month, Day, DayOfWeek);
  678. if (Search.Size <> Sizeof(week)) OR (DT.Year <> Year) OR (DT.Month <> Month)
  679. OR (DT.Day <> Day)
  680. then
  681. Begin
  682. WriteLn('FAILURE. Size/Date is different.')
  683. end
  684. else
  685. WriteLn('Success.');
  686. Write('Looking for ',TestFName,'...');
  687. FindFirst('*.D??',AnyFile,Search);
  688. { At least testdos.dat should appear }
  689. if DosError <> 0 then
  690. WriteLn('FAILURE. ',Testfname,' should be found.')
  691. else
  692. WriteLn('Success.');
  693. if Search.Name <> TestFName then
  694. Begin
  695. repeat
  696. FindNext(Search);
  697. until (DosError <> 0) OR (Search.Name = TestFName);
  698. end;
  699. {$IFDEF FPC}
  700. FindClose(Search);
  701. {$ENDIF}
  702. Write('Checking file stats of ',TestFName,'...');
  703. UnpackTime(Search.Time,DT);
  704. GetDate(Year, Month, Day, DayOfWeek);
  705. if (Search.Size <> Sizeof(week)) OR (DT.Year <> Year) OR (DT.Month <> Month)
  706. OR (DT.Day <> Day)
  707. then
  708. Begin
  709. WriteLn('FAILURE. Size/Date is different.')
  710. end
  711. else
  712. WriteLn('Success.');
  713. { Should show all possible files }
  714. FoundDot := False;
  715. FoundDotDot := False;
  716. Failure := True;
  717. FoundDir := False;
  718. s:='Searching using * wildcard (normal files + directories)...';
  719. FindFirst('*',Directory,Search);
  720. WriteLn(#9'Resources found (full path should not be displayed):');
  721. while DosError = 0 do
  722. Begin
  723. If Search.Name = TestDir then
  724. Begin
  725. If Search.Attr and Directory <> 0 then
  726. FoundDir := TRUE;
  727. end;
  728. If Search.Name = '.' then
  729. Begin
  730. If Search.Attr and Directory <> 0 then
  731. FoundDot := TRUE;
  732. End;
  733. if Search.Name = '..' then
  734. Begin
  735. If Search.Attr and Directory <> 0 then
  736. FoundDotDot := TRUE;
  737. End;
  738. { check for both . and .. special files }
  739. If Search.Name = TestFName1 then
  740. Failure := FALSE;
  741. WriteLn(#9+Search.Name);
  742. FindNext(Search);
  743. end;
  744. {$IFDEF FPC}
  745. FindClose(Search);
  746. {$ENDIF}
  747. if not FoundDir then
  748. WriteLn(s+'FAILURE. Did not find '+TestDir+' directory')
  749. else
  750. if not FoundDot then
  751. WriteLn(s+'FAILURE. Did not find special ''''.'''' directory')
  752. else
  753. if not FoundDotDot then
  754. WriteLn(s+'FAILURE. Did not find special ''''..'''' directory')
  755. else
  756. if Failure then
  757. WriteLn(s+'FAILURE. Did not find special '+TestFName1+' directory')
  758. else
  759. WriteLn(s+'Success.');
  760. {$IFDEF FPC}
  761. FindClose(Search);
  762. {$ENDIF}
  763. s:='Searching using ??? wildcard (normal files + all special files)...';
  764. FindFirst('???',AnyFile,Search);
  765. FoundDot := False;
  766. FoundDotDot := False;
  767. WriteLn(#9'Resources found (full path should not be displayed):');
  768. while DosError = 0 do
  769. Begin
  770. If Search.Name = '.' then
  771. Begin
  772. If Search.Attr and Directory <> 0 then
  773. FoundDot := TRUE;
  774. End;
  775. if Search.Name = '..' then
  776. Begin
  777. If Search.Attr and Directory <> 0 then
  778. FoundDotDot := TRUE;
  779. End;
  780. WriteLn(#9+Search.Name);
  781. FindNext(Search);
  782. end;
  783. if not FoundDot then
  784. WriteLn(s+'FAILURE. Did not find special ''''.'''' directory')
  785. else
  786. if not FoundDotDot then
  787. WriteLn(s+'FAILURE. Did not find special ''''..'''' directory')
  788. else
  789. WriteLn(s+'Success.');
  790. {$IFDEF FPC}
  791. FindClose(Search);
  792. {$ENDIF}
  793. { search for volume ID }
  794. s:='Searching using * wildcard in ROOT (normal files + volume ID)...';
  795. FindFirst(RootPath+'*',Directory+VolumeID,Search);
  796. Failure := TRUE;
  797. WriteLn(#9'Resources found (full path should not be displayed):');
  798. while DosError = 0 do
  799. Begin
  800. If Search.Attr and VolumeID <> 0 then
  801. Begin
  802. Failure := FALSE;
  803. WriteLn(#9'Volume ID: '+Search.Name);
  804. End
  805. else
  806. WriteLn(#9+Search.Name);
  807. FindNext(Search);
  808. end;
  809. If Failure then
  810. WriteLn(s+'FAILURE. Did not find volume name')
  811. else
  812. WriteLn(s+'Success.');
  813. {$IFDEF FPC}
  814. FindClose(Search);
  815. {$ENDIF}
  816. end;
  817. Procedure TestSplit;
  818. var
  819. P: PathStr;
  820. D: DirStr;
  821. N: NameStr;
  822. E: ExtStr;
  823. temp : string;
  824. Begin
  825. WriteLn('----------------------------------------------------------------------');
  826. WriteLn(' FSPLIT ');
  827. WriteLn('----------------------------------------------------------------------');
  828. Write('Testing invalid filename...');
  829. { Initialize names ot invalid values! }
  830. D:='Garbage';
  831. N:='Garbage';
  832. E:='GAR';
  833. { This is the path to be split }
  834. P:='';
  835. FSPlit(P,D,N,E);
  836. IF (length(D) <> 0) OR (length(N) <>0) OR (length(E) <> 0) THEN
  837. WriteLn('FAILURE. Same length as PATH (now length 0) should be returned.')
  838. else
  839. WriteLn('Success.');
  840. Write('Testing paramstr(0)...');
  841. { Initialize names ot invalid values! }
  842. D:='Garbage';
  843. N:='Garbage';
  844. E:='GAR';
  845. { This is the path to be split }
  846. P:=paramstr(0);
  847. FSPlit(P,D,N,E);
  848. IF length(p) <> (length(d)+length(n)+length(e)) then
  849. WriteLn('FAILURE. Same length as PATH should be returned.')
  850. else
  851. WriteLn('Success.');
  852. temp:=d+n+e;
  853. Write('Testing paramstr(0)...');
  854. if temp <> p then
  855. WriteLn('FAILURE. Concatenated string should be the same.')
  856. else
  857. WriteLn('Success.');
  858. WriteLn('PARAMSTR(0) = ', ParamStr(0));
  859. WriteLn('DRIVE + NAME + EXT = ',d+n+e);
  860. {$ifdef go32v2}
  861. Write('Testing invalid path (..)...');
  862. P:='..';
  863. FSPlit(P,D,N,E);
  864. IF (length(D) <> 0) OR (length(N) <>0) OR (E <> P) THEN
  865. WriteLn('FAILURE. Length of drive and name should be zero and Ext should return Path')
  866. else
  867. WriteLn('Success.');
  868. {$endif}
  869. Write('Testing invalid path (*)...');
  870. P:='*';
  871. FSPlit(P,D,N,E);
  872. IF (length(D) <> 0) OR (length(e) <>0) OR (N <> P) THEN
  873. WriteLn('FAILURE. Length of drive and name should be zero and Name should return Path')
  874. else
  875. WriteLn('Success.');
  876. end;
  877. var
  878. F: File;
  879. Attr : Word;
  880. Begin
  881. TestDiskSize;
  882. TestDosVersion;
  883. TestEnvCount;
  884. TestVerify;
  885. TestSystemDate;
  886. TestSystemTime;
  887. { Now the file I/O functions }
  888. { Let us create a file that we will play with }
  889. Assign(f,TestFName);
  890. Rewrite(f,1);
  891. BlockWrite(f,Week,sizeof(Week));
  892. Close(f);
  893. Assign(f,TestFName1);
  894. Rewrite(f,1);
  895. Close(F);
  896. MkDir(TestDir);
  897. TestFAttr;
  898. TestFTime;
  899. TestCBreak;
  900. TestFind;
  901. PauseScreen;
  902. TestSplit;
  903. RmDir(TestDir);
  904. PauseScreen;
  905. end.
  906. {
  907. $Log$
  908. Revision 1.6 2001-11-23 01:57:30 carl
  909. * updated some tests so they work on other systems
  910. Revision 1.5 2001/08/12 18:55:00 carl
  911. + added printing the number of ENV vars.
  912. Revision 1.4 2001/08/09 01:14:57 carl
  913. * several updates and more error checking
  914. Revision 1.3 2001/06/06 01:31:24 carl
  915. * fsplit with .. only works for go32v2 version and TP
  916. Revision 1.2 2001/05/20 18:30:46 hajny
  917. + support for GO32v1 and GO32v2 added
  918. Revision 1.1 2001/05/19 12:10:02 peter
  919. * renamed to .pp
  920. Revision 1.1 2001/04/02 02:34:13 carl
  921. + initial version of complete test for dos unit
  922. }