Debian Codegraph @

gcc/testsuite/gm2/switches/pim4/run/pass/InOutBug.mod

raw
1 (* Copyright (C) 2005, 2006 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17
18 MODULE InOutBug;
19
20 (*
21 * This module tests the implementation of InOut by stress testing
22 * StringConvert (and checks to see that the -Wpim4 flag does cause
23 * any unexpected DIV and MOD results).
24 *)
25
26 FROM StringConvert IMPORT itos ;
27 FROM DynamicStrings IMPORT String, InitString, EqualArray, KillString, string ;
28 FROM libc IMPORT exit, printf ;
29 FROM SYSTEM IMPORT ADR ;
30
31
32 PROCEDURE Assert (v: BOOLEAN; f: ARRAY OF CHAR; l: CARDINAL; e: ARRAY OF CHAR) ;
33 VAR
34 r: INTEGER ;
35 BEGIN
36 IF v
37 THEN
38 r := printf("successfully evaluated %s\n", ADR(e))
39 ELSE
40 r := printf("%s:%d assertion failed when evaluating %s\n", ADR(f), l, ADR(e)) ;
41 res := 1
42 END
43 END Assert ;
44
45
46 PROCEDURE WriteInt (x: INTEGER; n: CARDINAL) : String ;
47 BEGIN
48 RETURN itos(x, n, ' ', FALSE)
49 END WriteInt ;
50
51
52 VAR
53 s : String ;
54 r, res: INTEGER ;
55 BEGIN
56 res := 0 ;
57
58 s := WriteInt(MAX(INTEGER), 0) ;
59 r := printf('result of MAX(INTEGER) = %s\n', string(s)) ;
60 Assert(EqualArray(s, '2147483647'), __FILE__, __LINE__, 'MAX(INTEGER) in itos') ;
61 s := KillString(s) ;
62
63 s := WriteInt(MIN(INTEGER), 0) ;
64 r := printf('result of MIN(INTEGER) = %s\n', string(s)) ;
65 Assert(EqualArray(s, '-2147483648'), __FILE__, __LINE__, 'MIN(INTEGER) in itos') ;
66 s := KillString(s) ;
67
68 s := WriteInt(MIN(INTEGER)+1, 0) ;
69 r := printf('result of MIN(INTEGER)+1 = %s\n', string(s)) ;
70 Assert(EqualArray(s, '-2147483647'), __FILE__, __LINE__, 'MIN(INTEGER)+1 in itos') ;
71 s := KillString(s) ;
72 exit(res)
73 END InOutBug.