tinoutres.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. { checks if the correct RTE's are generated for invalid io operations }
  2. {$i-}
  3. procedure test(value, required: longint);
  4. begin
  5. if value <> required then
  6. begin
  7. writeln('Got ',value,' instead of ',required);
  8. halt(1);
  9. end;
  10. end;
  11. procedure test_read_text;
  12. var
  13. f: text;
  14. s: string;
  15. begin
  16. { to avoid influence of previous runs/procedures }
  17. fillchar(f,sizeof(f),0);
  18. write('Reading from not opened text file...');
  19. read(f,s);
  20. test(ioresult,103);
  21. readln(f);
  22. test(ioresult,103);
  23. writeln(' Passed!');
  24. write('Seekeoln from not opened text file...');
  25. seekeoln(f);
  26. test(ioresult,103);
  27. writeln(' Passed!');
  28. write('Seekeof from not opened text file...');
  29. seekeof(f);
  30. test(ioresult,103);
  31. writeln(' Passed!');
  32. assign(f,'inoutrte.$$$');
  33. rewrite(f);
  34. test(ioresult,0);
  35. write('Reading from write-only (rewritten) text file...');
  36. read(f,s);
  37. test(ioresult,104);
  38. readln(f);
  39. test(ioresult,104);
  40. writeln(' Passed!');
  41. write('Seekeoln from write-only (rewritten) text file...');
  42. seekeoln(f);
  43. test(ioresult,104);
  44. writeln(' Passed!');
  45. write('Seekeof from write-only (rewritten) text file...');
  46. seekeof(f);
  47. test(ioresult,104);
  48. writeln(' Passed!');
  49. close(f);
  50. test(ioresult,0);
  51. append(f);
  52. test(ioresult,0);
  53. write('Reading from write-only (appended) text file...');
  54. read(f,s);
  55. test(ioresult,104);
  56. readln(f);
  57. test(ioresult,104);
  58. writeln(' Passed!');
  59. write('Seekeoln from write-only (appended) text file...');
  60. seekeoln(f);
  61. test(ioresult,104);
  62. writeln(' Passed!');
  63. write('Seekeof from write-only (appended) text file...');
  64. seekeof(f);
  65. test(ioresult,104);
  66. writeln(' Passed!');
  67. close(f);
  68. test(ioresult,0);
  69. erase(f);
  70. test(ioresult,0);
  71. end;
  72. procedure test_read_typed;
  73. var
  74. f: file of byte;
  75. s: byte;
  76. begin
  77. { to avoid influence of previous runs/procedures }
  78. fillchar(f,sizeof(f),0);
  79. write('Reading from not opened typed file...');
  80. read(f,s);
  81. test(ioresult,103);
  82. writeln(' Passed!');
  83. { with filemode 2, the file is read-write }
  84. filemode := 1;
  85. assign(f,'inoutrte.$$$');
  86. rewrite(f);
  87. test(ioresult, 0);
  88. write(f,s);
  89. test(ioresult, 0);
  90. close(f);
  91. test(ioresult, 0);
  92. reset(f);
  93. test(ioresult, 0);
  94. write('Reading from write-only typed file...');
  95. read(f,s);
  96. test(ioresult,104);
  97. writeln(' Passed!');
  98. filemode := 2;
  99. close(f);
  100. test(ioresult, 0);
  101. erase(f);
  102. test(ioresult, 0);
  103. end;
  104. procedure test_read_untyped;
  105. var
  106. f: file;
  107. r: longint;
  108. s: byte;
  109. begin
  110. { to avoid influence of previous runs/procedures }
  111. fillchar(f,sizeof(f),0);
  112. write('Reading from not opened untyped file...');
  113. blockread(f,s,1,r);
  114. test(ioresult,103);
  115. writeln(' Passed!');
  116. { with filemode 2, the file is read-write }
  117. filemode := 1;
  118. assign(f,'inoutrte.$$$');
  119. rewrite(f);
  120. test(ioresult, 0);
  121. blockwrite(f,s,1);
  122. test(ioresult, 0);
  123. close(f);
  124. test(ioresult, 0);
  125. reset(f);
  126. test(ioresult, 0);
  127. write('Reading from write-only utyped file...');
  128. blockread(f,s,1,r);
  129. test(ioresult,104);
  130. writeln(' Passed!');
  131. filemode := 2;
  132. close(f);
  133. test(ioresult, 0);
  134. erase(f);
  135. test(ioresult, 0);
  136. end;
  137. procedure test_write_text;
  138. var f: text;
  139. s: string;
  140. begin
  141. { to avoid influence of previous runs/procedures }
  142. fillchar(f,sizeof(f),0);
  143. write('Writing to not opened text file...');
  144. write(f,s);
  145. test(ioresult,103);
  146. writeln(f);
  147. test(ioresult,103);
  148. writeln(' Passed!');
  149. assign(f,'inoutrte.$$$');
  150. rewrite(f);
  151. close(f);
  152. test(ioresult,0);
  153. reset(f);
  154. test(ioresult,0);
  155. write('Writing to read-only text file...');
  156. write(f,s);
  157. test(ioresult,105);
  158. writeln(f);
  159. test(ioresult,105);
  160. Writeln(' Passed!');
  161. close(f);
  162. test(ioresult,0);
  163. erase(f);
  164. test(ioresult,0);
  165. end;
  166. procedure test_write_typed;
  167. var f: file of byte;
  168. s: byte;
  169. begin
  170. { to avoid influence of previous runs/procedures }
  171. fillchar(f,sizeof(f),0);
  172. write('Writing to not opened typed file...');
  173. write(f,s);
  174. test(ioresult,103);
  175. writeln(' Passed!');
  176. assign(f,'inoutrte.$$$');
  177. rewrite(f);
  178. close(f);
  179. test(ioresult,0);
  180. filemode := 0;
  181. reset(f);
  182. test(ioresult,0);
  183. write('Writing to read-only typed file...');
  184. write(f,s);
  185. test(ioresult,105);
  186. Writeln(' Passed!');
  187. filemode := 2;
  188. close(f);
  189. test(ioresult,0);
  190. erase(f);
  191. test(ioresult,0);
  192. end;
  193. procedure test_write_untyped;
  194. var f: file;
  195. r: longint;
  196. s: byte;
  197. begin
  198. { to avoid influence of previous runs/procedures }
  199. fillchar(f,sizeof(f),0);
  200. write('Writing to not opened untyped file...');
  201. blockwrite(f,s,1,r);
  202. test(ioresult,103);
  203. writeln(' Passed!');
  204. assign(f,'inoutrte.$$$');
  205. rewrite(f);
  206. close(f);
  207. test(ioresult,0);
  208. filemode := 0;
  209. reset(f);
  210. test(ioresult,0);
  211. write('Writing to read-only untyped file...');
  212. blockwrite(f,s,1,r);
  213. test(ioresult,105);
  214. Writeln(' Passed!');
  215. filemode := 2;
  216. close(f);
  217. test(ioresult,0);
  218. erase(f);
  219. test(ioresult,0);
  220. end;
  221. procedure test_close_text;
  222. var f: text;
  223. begin
  224. { to avoid influence of previous runs/procedures }
  225. fillchar(f,sizeof(f),0);
  226. write('Testing closing of not opened text file...');
  227. close(f);
  228. test(ioresult,103);
  229. writeln(' Passed!');
  230. end;
  231. procedure test_close_typed;
  232. var f: file of byte;
  233. begin
  234. { to avoid influence of previous runs/procedures }
  235. fillchar(f,sizeof(f),0);
  236. write('Testing closing of not opened typed file...');
  237. close(f);
  238. test(ioresult,103);
  239. writeln(' Passed!');
  240. end;
  241. procedure test_close_untyped;
  242. var f: file;
  243. begin
  244. { to avoid influence of previous runs/procedures }
  245. fillchar(f,sizeof(f),0);
  246. write('Testing closing of not opened untyped file...');
  247. close(f);
  248. test(ioresult,103);
  249. writeln(' Passed!');
  250. end;
  251. begin
  252. test_read_text;
  253. test_read_typed;
  254. test_read_untyped;
  255. test_write_text;
  256. test_write_typed;
  257. test_write_untyped;
  258. test_close_text;
  259. test_close_typed;
  260. test_close_untyped;
  261. end.