tdos.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. {
  2. $Id$
  3. Program to test DOS unit by Peter Vreman.
  4. Only main TP functions are tested (nothing with Interrupts/Break/Verify).
  5. }
  6. {$V-}
  7. program tesidos;
  8. uses dos;
  9. { These should be defined for each operating system to be tested }
  10. { NOEXESUFFIX = No .EXE to prepend to prefix the file with to get }
  11. { a file executable. }
  12. {$ifdef unix}
  13. {$DEFINE NOEXESUFFIX}
  14. {$endif}
  15. {$ifdef amiga}
  16. {$DEFINE NOEXESUFFIX}
  17. {$endif}
  18. const
  19. exedir : string = '';
  20. procedure TestInfo;
  21. var
  22. dt : DateTime;
  23. ptime : longint;
  24. wday : word;
  25. HSecs : word;
  26. begin
  27. writeln;
  28. writeln('Info Functions');
  29. writeln('**************');
  30. writeln('Dosversion : ',lo(DosVersion),'.',hi(DosVersion));
  31. GetDate(Dt.Year,Dt.Month,Dt.Day,wday);
  32. writeln('Current Date (MM-DD-YYYY) : ',Dt.Month,'-',Dt.Day,'-',Dt.Year,' weekday ',wday);
  33. GetTime(Dt.Hour,Dt.Min,Dt.Sec,HSecs);
  34. writeln('Current Time (HH:MM:SS) : ',Dt.Hour,':',Dt.Min,':',Dt.Sec,' hsecs ',HSecs);
  35. PackTime(Dt,ptime);
  36. writeln('Packed like dos: ',ptime);
  37. UnpackTime(ptime,DT);
  38. writeln('Unpacked again (MM-DD-YYYY) ',Dt.Month,'-',Dt.Day,'-',Dt.Year,' ',Dt.Hour,':',Dt.Min,':',Dt.Sec);
  39. writeln;
  40. end;
  41. procedure TestEnvironment;
  42. var
  43. i : longint;
  44. begin
  45. writeln;
  46. writeln('Environment Functions');
  47. writeln('*********************');
  48. writeln('Amount of environment strings : ',EnvCount);
  49. writeln('GetEnv TERM : ',GetEnv('TERM'));
  50. writeln('GetEnv HOST : ',GetEnv('HOST'));
  51. writeln('GetEnv PATH : ',GetEnv('PATH'));
  52. writeln('GetEnv SHELL: ',GetEnv('SHELL'));
  53. write(' all Environment Strings using EnvStr()');
  54. for i:=1 to EnvCount do
  55. writeln(EnvStr(i));
  56. end;
  57. procedure TestExec;
  58. begin
  59. writeln;
  60. writeln('Exec Functions');
  61. writeln('**************');
  62. write('Going to Exec of ''hello -good -day''');
  63. {$ifndef FPC}
  64. SwapVectors;
  65. {$endif FPC}
  66. {$ifdef noexesuffix}
  67. Exec(exedir+'hello','-good -day');
  68. {$else}
  69. Exec(exedir+'hello.exe','-good -day');
  70. {$endif}
  71. {$ifndef FPC}
  72. SwapVectors;
  73. {$endif FPC}
  74. writeln('Exit should be 213 : ',DosExitCode);
  75. writeln('Error code should be 0 : ',DosError);
  76. end;
  77. procedure TestDisk;
  78. var
  79. Dir : SearchRec;
  80. DT : DateTime;
  81. begin
  82. writeln;
  83. writeln('Disk Functions');
  84. writeln('**************');
  85. writeln('DiskFree 0 : ',DiskFree(0));
  86. writeln('DiskSize 0 : ',DiskSize(0));
  87. {writeln('DiskSize 1 : ',DiskSize(1)); this is a: on dos ??! }
  88. writeln('DiskSize 3 : ',DiskSize(3)); { this is c: on dos }
  89. {$IFDEF Unix}
  90. AddDisk('/fd0');
  91. writeln('DiskSize 4 : ',DiskSize(4));
  92. {$ENDIF}
  93. write('FindFirst/FindNext Test');
  94. FindFirst('*.*',$20,Dir);
  95. while (DosError=0) do
  96. begin
  97. UnpackTime(dir.Time,DT);
  98. Writeln(dir.Name,' ',dir.Size,' ',DT.Year,'-',DT.Month,'-',DT.Day);
  99. FindNext(Dir);
  100. end;
  101. end;
  102. procedure TestFile;
  103. var
  104. test,
  105. name,dir,ext : string;
  106. begin
  107. writeln;
  108. writeln('File(name) Functions');
  109. writeln('********************');
  110. {$ifdef unix }
  111. test:='/usr/local/bin/ppc.so';
  112. writeln('FSplit(',test,')');
  113. FSplit(test,dir,name,ext);
  114. writeln('dir: ',dir,' name: ',name,' ext: ',ext);
  115. test:='/usr/bin.1/ppc';
  116. writeln('FSplit(',test,')');
  117. FSplit(test,dir,name,ext);
  118. writeln('dir: ',dir,' name: ',name,' ext: ',ext);
  119. test:='mtools.tar.gz';
  120. writeln('FSplit(',test,')');
  121. FSplit(test,dir,name,ext);
  122. writeln('dir: ',dir,' name: ',name,' ext: ',ext);
  123. Writeln('Expanded dos.pp : ',FExpand('dos.pp'));
  124. Writeln('Expanded ../dos.pp : ',FExpand('../dos.pp'));
  125. Writeln('Expanded /usr/local/dos.pp : ',FExpand('/usr/local/dos.pp'));
  126. Writeln('Expanded ../dos/./../././dos.pp : ',FExpand('../dos/./../././dos.pp'));
  127. test:='../;/usr/;/usr/bin/;/usr/bin;/bin/;';
  128. {$else not linux }
  129. test:='\usr\local\bin\ppc.so';
  130. writeln('FSplit(',test,')');
  131. FSplit(test,dir,name,ext);
  132. writeln('dir: ',dir,' name: ',name,' ext: ',ext);
  133. test:='\usr\bin.1\ppc';
  134. writeln('FSplit(',test,')');
  135. FSplit(test,dir,name,ext);
  136. writeln('dir: ',dir,' name: ',name,' ext: ',ext);
  137. test:='mtools.tar.gz';
  138. writeln('FSplit(',test,')');
  139. FSplit(test,dir,name,ext);
  140. writeln('dir: ',dir,' name: ',name,' ext: ',ext);
  141. Writeln('Expanded dos.pp : ',FExpand('dos.pp'));
  142. Writeln('Expanded ..\dos.pp : ',FExpand('..\dos.pp'));
  143. Writeln('Expanded \usr\local\dos.pp : ',FExpand('\usr\local\dos.pp'));
  144. Writeln('Expanded ..\dos\.\..\.\.\dos.pp : ',FExpand('..\dos\.\..\.\.\dos.pp'));
  145. test:='..\;\usr\;\usr\bin\;\usr\bin;\bin\;';
  146. {$endif not linux}
  147. test:=test+getenv('PATH');
  148. {$ifdef NOEXESUFFIX}
  149. Writeln('FSearch ls: ',FSearch('ls',test));
  150. {$else not noexesuffix}
  151. Writeln('FSearch ls: ',FSearch('ls.exe',test));
  152. {$endif not noexesuffix}
  153. Writeln('Empty FSearch (should return empty string):',FSearch('',test));
  154. end;
  155. var
  156. name,dir,ext : string;
  157. begin
  158. FSplit(paramstr(0),dir,name,ext);
  159. exedir:=dir;
  160. TestInfo;
  161. TestEnvironment;
  162. TestExec;
  163. TestDisk;
  164. TestFile;
  165. end.
  166. {
  167. $Log$
  168. Revision 1.9 2003-05-15 20:35:57 florian
  169. * ifdef'd SwapVectors
  170. Revision 1.8 2002/11/18 09:49:49 pierre
  171. * tried to make as many as possible tests non interactive
  172. Revision 1.7 2002/10/20 11:47:39 carl
  173. * add format date to make test clearer
  174. Revision 1.6 2002/09/07 15:40:56 peter
  175. * old logs removed and tabs fixed
  176. Revision 1.5 2002/07/06 11:46:08 carl
  177. + fsearch testing added
  178. Revision 1.4 2002/06/01 19:08:52 marco
  179. * Renamefest
  180. }