Debian Codegraph @

gcc/testsuite/gm2/calling-c/libc/run/pass/testlibcstr.mod

raw
1 MODULE testlibcstr ;
2
3 FROM SYSTEM IMPORT ADDRESS, ADR ;
4 FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
5 FROM libc IMPORT strtod, atof, printf, exit, snprintf ;
6 FROM DynamicStrings IMPORT String,
7 InitString, InitStringCharStar, Equal, Slice,
8 KillString ;
9
10 (*
11 runtest -
12 *)
13
14 PROCEDURE runtest ;
15 CONST
16 BufSpace = 100 ;
17 VAR
18 s: String ;
19 r: REAL ;
20 a: ADDRESS ;
21 BEGIN
22 r := atof (ADR ("3.14159")) ;
23 ALLOCATE (a, BufSpace) ;
24 snprintf (a, BufSpace, "%f", r) ;
25 s := InitStringCharStar (a) ;
26 IF NOT Equal (InitString ("3.14159"), Slice (s, 0, 7))
27 THEN
28 printf ("failed to convert 3.14159 to a REAL or string\n") ;
29 exit (1)
30 END ;
31 DEALLOCATE (a, BufSpace) ;
32 s := KillString (s)
33 END runtest ;
34
35
36 BEGIN
37 runtest ;
38 printf ("all tests passed!\n")
39 END testlibcstr.