tdos.pp 4.9 KB

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