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