| 1 |
(* onebyte3.mod stress bit changes on arrays of bytes. |
| 2 |
|
| 3 |
Copyright (C) 2020 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
MODULE onebyte3 ; |
| 23 |
|
| 24 |
FROM libc IMPORT exit, printf ; |
| 25 |
FROM SYSTEM IMPORT SIZE, ADR, BYTE ; |
| 26 |
|
| 27 |
|
| 28 |
PROCEDURE assert (b: BOOLEAN; file: ARRAY OF CHAR; line: CARDINAL) ; |
| 29 |
BEGIN |
| 30 |
IF NOT b |
| 31 |
THEN |
| 32 |
printf("%s:%d:assert failed\n", ADR (file), line) ; |
| 33 |
r := 1 |
| 34 |
END |
| 35 |
END assert ; |
| 36 |
|
| 37 |
|
| 38 |
TYPE |
| 39 |
byte = PACKEDSET OF [0..7] ; |
| 40 |
array = ARRAY [0..10] OF byte ; |
| 41 |
VAR |
| 42 |
a : array ; |
| 43 |
r : INTEGER ; |
| 44 |
i, j, k: CARDINAL ; |
| 45 |
BEGIN |
| 46 |
r := 0 ; |
| 47 |
FOR i := 0 TO 10 DO |
| 48 |
(* zap all bytes to zero. *) |
| 49 |
FOR k := 0 TO 10 DO |
| 50 |
a[k] := byte {} |
| 51 |
END ; |
| 52 |
(* assign all bits to 1 in byte i. *) |
| 53 |
FOR j := 0 TO 7 DO |
| 54 |
INCL (a[i], j) |
| 55 |
END ; |
| 56 |
assert (ORD (a[i]) = 255, __FILE__, __LINE__) ; |
| 57 |
(* check all other bytes unaffected. *) |
| 58 |
FOR k := 0 TO 10 DO |
| 59 |
IF k # i |
| 60 |
THEN |
| 61 |
assert (ORD (a[k]) = 0, __FILE__, __LINE__); |
| 62 |
END |
| 63 |
END |
| 64 |
END ; |
| 65 |
exit (r) |
| 66 |
END onebyte3. |