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