trdtxt03.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. Program trdtxt03;
  2. {$ifdef fpc}
  3. uses
  4. strings;
  5. {$else}
  6. uses
  7. SysUtils;
  8. {$endif}
  9. procedure test(b: boolean);
  10. begin
  11. if b then exit;
  12. WriteLn('Error : Invalid data read!');
  13. halt(1);
  14. end;
  15. var
  16. T: Text;
  17. value_char: char;
  18. value_byte: byte;
  19. value_shortint : shortint;
  20. value_smallint : smallint;
  21. value_word : word;
  22. value_longint : longint;
  23. value_longword : cardinal;
  24. value_real : real;
  25. value_shortstr : shortstring;
  26. value_pchar : array[0..255] of char;
  27. Begin
  28. Assign(T,'testmac.txt');
  29. Reset(T);
  30. { Read all the data in the correct order }
  31. { Read some characters }
  32. value_char := #0;
  33. ReadLn(T,value_char);
  34. test(value_char = 'a');
  35. value_char := #0;
  36. ReadLn(T,value_char);
  37. test(value_char = 'c');
  38. value_char := #0;
  39. ReadLn(T,value_char);
  40. test(value_char = 'z');
  41. value_char := #0;
  42. ReadLn(T,value_char);
  43. test(value_char = '#');
  44. { ***** Read some integer values ***** }
  45. {**** HEX ****}
  46. value_byte := 0;
  47. ReadLn(T,value_byte);
  48. test(value_byte = 127);
  49. value_byte := 0;
  50. ReadLn(T,value_byte);
  51. test(value_byte = 255);
  52. value_byte := 0;
  53. ReadLn(T,value_byte);
  54. test(value_byte = 51);
  55. value_shortint := 0;
  56. ReadLn(T,value_shortint);
  57. test(value_shortint = -127);
  58. {*** Integral *** }
  59. value_byte := 0;
  60. ReadLn(T,value_byte);
  61. test(value_byte = 127);
  62. value_byte := 0;
  63. ReadLn(T,value_byte);
  64. test(value_byte = 255);
  65. value_byte := 0;
  66. ReadLn(T,value_byte);
  67. test(value_byte = 33);
  68. value_shortint := 0;
  69. ReadLn(T,value_shortint);
  70. test(value_shortint = -127);
  71. {**** HEX ****}
  72. value_word := 0;
  73. ReadLn(T,value_word);
  74. test(value_word = 32767);
  75. value_word := 0;
  76. ReadLn(T,value_word);
  77. test(value_word = 65535);
  78. value_word := 0;
  79. ReadLn(T,value_word);
  80. test(value_word = 4660);
  81. value_smallint := 0;
  82. ReadLn(T,value_smallint);
  83. test(value_smallint = -32767);
  84. {*** Integral *** }
  85. value_word := 0;
  86. ReadLn(T,value_word);
  87. test(value_word = 12700);
  88. value_word := 0;
  89. ReadLn(T,value_word);
  90. test(value_word = 2550);
  91. value_word := 0;
  92. ReadLn(T,value_word);
  93. test(value_word = +33200);
  94. value_smallint := 0;
  95. ReadLn(T,value_smallint);
  96. test(value_smallint = -12700);
  97. {**** HEX ****}
  98. value_longword := 0;
  99. ReadLn(T,value_longword);
  100. test(value_longword = +$7FFFFFFF);
  101. value_longword := 0;
  102. ReadLn(T,value_longword);
  103. test(value_longword = $FFFFFFFF);
  104. value_longword := 0;
  105. ReadLn(T,value_longword);
  106. test(value_longword = $12341234);
  107. value_longint := 0;
  108. ReadLn(T,value_longint);
  109. test(value_longint = -$7FFFFFFF);
  110. {*** Integral *** }
  111. value_longword := 0;
  112. ReadLn(T,value_longword);
  113. test(value_longword = 12700);
  114. value_longword := 0;
  115. ReadLn(T,value_longword);
  116. test(value_longword = 2550);
  117. value_longword := 0;
  118. ReadLn(T,value_longword);
  119. test(value_longword = +2147483647);
  120. value_longint := 0;
  121. ReadLn(T,value_longint);
  122. { test(value_longint = -2147483648);}
  123. { Read some real type values }
  124. value_real := 0.0;
  125. ReadLn(T,value_real);
  126. test(trunc(value_real) = trunc(01234));
  127. value_real := 0.0;
  128. ReadLn(T,value_real);
  129. test(trunc(value_real) = trunc(1278.1278));
  130. value_real := 0.0;
  131. ReadLn(T,value_real);
  132. test(trunc(value_real) = trunc(121223.1278E00));
  133. value_real := 0.0;
  134. ReadLn(T,value_real);
  135. test(trunc(value_real) = trunc(121224.1278e2));
  136. value_real := 0.0;
  137. ReadLn(T,value_real);
  138. test(trunc(value_real) = trunc(121225.1278E02));
  139. value_real := 0.0;
  140. ReadLn(T,value_real);
  141. test(trunc(value_real) = trunc(121216.1278E+00));
  142. value_real := 0.0;
  143. ReadLn(T,value_real);
  144. test(trunc(value_real) = trunc(121227.1278e+2));
  145. value_real := 0.0;
  146. ReadLn(T,value_real);
  147. test(trunc(value_real) = trunc(121228.1278E+02));
  148. value_real := 0.0;
  149. ReadLn(T,value_real);
  150. test(trunc(value_real) = trunc(121233.1278E-00));
  151. value_real := 0.0;
  152. ReadLn(T,value_real);
  153. test(trunc(value_real) = trunc(121234.1278e-2));
  154. { Read some strings }
  155. value_shortstr := '';
  156. ReadLn(T,value_shortstr);
  157. test(length(value_shortstr) = 255);
  158. value_shortstr := '';
  159. ReadLn(T,value_shortstr);
  160. test(value_shortstr = 'Hello world!');
  161. value_shortstr := '';
  162. ReadLn(T,value_shortstr);
  163. test(length(value_shortstr) = 42);
  164. { Read a null terminated value }
  165. value_shortstr := '';
  166. ReadLn(T,value_pchar);
  167. test(strlen(value_pchar) = 33);
  168. { Read a value_charhar and make sure the value is value_chartrl-Z (#26) }
  169. ReadLn(T,value_char);
  170. test(value_char = #26);
  171. Close(T);
  172. WriteLn('All tests Ok!');
  173. end.