PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/r/r_copy_struct_runme.R

#
R | 58 lines | 39 code | 16 blank | 3 comment | 0 complexity | 13c7fcb5103790e01a611aac7a142294 MD5 | raw file
 1source("unittest.R")
 2dyn.load(paste("r_copy_struct", .Platform$dynlib.ext, sep=""))
 3source("r_copy_struct.R")
 4cacheMetaData(1)
 5
 6a <- getA()
 7
 8r = getARef()
 9
10unittest(A_d_get(r), 42)
11unittest(r$d, 42)
12unittest(r$i, 20)
13
14# An error in trying to access a field that doesn't exist.
15try(r$foo) 
16
17r$d <- pi
18unittesttol(r$d, 3.141593, 0.0001)
19r$i <- -100
20
21r$ui
22r$ui <- 10
23
24 # An error since i is unsigned and so must  be positive.
25try(r$ui <- -10)
26
27
28a = A()
29unittest(a$i,0)
30unittest(a$d,0)
31unittest(a$ui,0)
32a$ui <- 100
33unittest(a$ui,100)
34a$d = 1
35unittest(a$d,1)
36
37d <- bar()
38unittest(class(d), "_p_D")
39unittest(d$x, 1)
40unittest(d$u, 0)
41
42
43la <- new("A");
44la@ui <- as.integer(5)
45# Removing the next line makes this fail in R 2.4
46la@str <- ""
47
48other = A()
49foo <- copyToC(la, other)
50
51aa = A()
52aa$i = as.integer(201)
53aa$d = pi
54aa$str = "foo"
55aa$ui = as.integer(0)
56copyToR(aa)
57
58