diff options
Diffstat (limited to 'Examples/test-suite/r')
| -rw-r--r-- | Examples/test-suite/r/Makefile.in | 72 | ||||
| -rw-r--r-- | Examples/test-suite/r/arrays_dimensionless_runme.R | 20 | ||||
| -rw-r--r-- | Examples/test-suite/r/funcptr_runme.R | 7 | ||||
| -rw-r--r-- | Examples/test-suite/r/ignore_parameter_runme.R | 10 | ||||
| -rw-r--r-- | Examples/test-suite/r/integers_runme.R | 20 | ||||
| -rw-r--r-- | Examples/test-suite/r/r_copy_struct_runme.R | 58 | ||||
| -rw-r--r-- | Examples/test-suite/r/r_double_delete_runme.R | 9 | ||||
| -rw-r--r-- | Examples/test-suite/r/r_legacy_runme.R | 30 | ||||
| -rw-r--r-- | Examples/test-suite/r/simple_array_runme.R | 9 | ||||
| -rw-r--r-- | Examples/test-suite/r/unions_runme.R | 12 | ||||
| -rw-r--r-- | Examples/test-suite/r/unittest.R | 9 |
11 files changed, 256 insertions, 0 deletions
diff --git a/Examples/test-suite/r/Makefile.in b/Examples/test-suite/r/Makefile.in new file mode 100644 index 0000000..32d0466 --- /dev/null +++ b/Examples/test-suite/r/Makefile.in @@ -0,0 +1,72 @@ +####################################################################### +# Makefile for r test-suite +####################################################################### + +LANGUAGE = r +SCRIPTSUFFIX = _runme.R +WRAPSUFFIX = .R +RUNR = R CMD BATCH --no-save --no-restore +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +C_TEST_CASES = r_copy_struct r_legacy +CPP_TEST_CASES = r_double_delete + +include $(srcdir)/../common.mk + +# Overridden variables here +# none! + +# Custom tests - tests with additional commandline options +# none! + +# Rules for the different types of tests +%.cpptest: + $(setup) + +$(swig_and_compile_cpp) + $(run_testcase) + +%.ctest: + $(setup) + +$(swig_and_compile_c) + $(run_testcase) + +%.multicpptest: + $(setup) + +$(swig_and_compile_multi_cpp) + $(run_multitestcase) + +# Runs the testcase. +# +# Run the runme if it exists. If not just load the R wrapper to +# check for syntactic correctness +run_testcase = \ + if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" $(RUNTOOL) $(RUNR) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + else \ + $(RUNTOOL) $(RUNR) $(srcdir)/$(SCRIPTPREFIX)$*$(WRAPSUFFIX); \ + fi + +run_multitestcase = \ + for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ + if [ -f $(srcdir)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX) ]; then \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" \ + $(RUNTOOL) $(RUNR) $(srcdir)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX); \ + else \ + $(RUNTOOL) $(RUNR) $(srcdir)/$(SCRIPTPREFIX)$${f}$(WRAPSUFFIX); \ + fi; \ + done +# Clean +clean: + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile r_clean + +%.clean: + @rm -f $*.R $*_wrap.so $*_wrap.cpp $*_wrap.c $*_wrap.o $*_runme.Rout $*.Rout + @if [ -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \ + for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ + rm -f $${f}.R $${f}.Rout ; \ + done \ + fi + + diff --git a/Examples/test-suite/r/arrays_dimensionless_runme.R b/Examples/test-suite/r/arrays_dimensionless_runme.R new file mode 100644 index 0000000..9b97de2 --- /dev/null +++ b/Examples/test-suite/r/arrays_dimensionless_runme.R @@ -0,0 +1,20 @@ +source("unittest.R") +dyn.load(paste("arrays_dimensionless", .Platform$dynlib.ext, sep="")) +source("arrays_dimensionless.R") +cacheMetaData(1) + +unittest(arr_short(1:4, 3), 6) +unittest(arr_ushort(1:4, 3), 6) +unittest(arr_int(1:4, 3), 6) +unittest(arr_uint(1:4, 3), 6) +unittest(arr_long(1:4, 3), 6) +unittest(arr_ulong(1:4, 3), 6) +unittest(arr_ll(1:4, 3), 6) +unittest(arr_ull(1:4, 3), 6) +unittest(arr_float(as.numeric(1:4), 3), 6) +unittest(arr_double(as.numeric(1:4), 3), 6) + +q(save="no") + + + diff --git a/Examples/test-suite/r/funcptr_runme.R b/Examples/test-suite/r/funcptr_runme.R new file mode 100644 index 0000000..3d5281b --- /dev/null +++ b/Examples/test-suite/r/funcptr_runme.R @@ -0,0 +1,7 @@ +source("unittest.R") +dyn.load(paste("funcptr", .Platform$dynlib.ext, sep="")) +source("funcptr.R") +cacheMetaData(1) +unittest(do_op(1, 3, add), 4) +unittest(do_op(2, 3, multiply), 6) +unittest(do_op(2, 3, funcvar()), 5) diff --git a/Examples/test-suite/r/ignore_parameter_runme.R b/Examples/test-suite/r/ignore_parameter_runme.R new file mode 100644 index 0000000..89e461d --- /dev/null +++ b/Examples/test-suite/r/ignore_parameter_runme.R @@ -0,0 +1,10 @@ +source("unittest.R") +dyn.load(paste("ignore_parameter", .Platform$dynlib.ext, sep="")) +source("ignore_parameter.R") +cacheMetaData(1) + +unittest(jaguar(1, 1.0), "hello") +q(save="no") + + + diff --git a/Examples/test-suite/r/integers_runme.R b/Examples/test-suite/r/integers_runme.R new file mode 100644 index 0000000..e31099a --- /dev/null +++ b/Examples/test-suite/r/integers_runme.R @@ -0,0 +1,20 @@ +source("unittest.R") +dyn.load(paste("integers", .Platform$dynlib.ext, sep="")) +source("integers.R") +cacheMetaData(1) + +unittest(signed_char_identity(1), 1) +unittest(unsigned_char_identity(1), 1) +unittest(signed_short_identity(1), 1) +unittest(unsigned_short_identity(1), 1) +unittest(signed_int_identity(1), 1) +unittest(unsigned_int_identity(1), 1) +unittest(signed_long_identity(1), 1) +unittest(unsigned_long_identity(1), 1) +unittest(signed_long_long_identity(1), 1) +unittest(unsigned_long_long_identity(1), 1) + +q(save="no") + + + diff --git a/Examples/test-suite/r/r_copy_struct_runme.R b/Examples/test-suite/r/r_copy_struct_runme.R new file mode 100644 index 0000000..21bd93b --- /dev/null +++ b/Examples/test-suite/r/r_copy_struct_runme.R @@ -0,0 +1,58 @@ +source("unittest.R") +dyn.load(paste("r_copy_struct", .Platform$dynlib.ext, sep="")) +source("r_copy_struct.R") +cacheMetaData(1) + +a <- getA() + +r = getARef() + +unittest(A_d_get(r), 42) +unittest(r$d, 42) +unittest(r$i, 20) + +# An error in trying to access a field that doesn't exist. +try(r$foo) + +r$d <- pi +unittesttol(r$d, 3.141593, 0.0001) +r$i <- -100 + +r$ui +r$ui <- 10 + + # An error since i is unsigned and so must be positive. +try(r$ui <- -10) + + +a = A() +unittest(a$i,0) +unittest(a$d,0) +unittest(a$ui,0) +a$ui <- 100 +unittest(a$ui,100) +a$d = 1 +unittest(a$d,1) + +d <- bar() +unittest(class(d), "_p_D") +unittest(d$x, 1) +unittest(d$u, 0) + + +la <- new("A"); +la@ui <- as.integer(5) +# Removing the next line makes this fail in R 2.4 +la@str <- "" + +other = A() +foo <- copyToC(la, other) + +aa = A() +aa$i = as.integer(201) +aa$d = pi +aa$str = "foo" +aa$ui = as.integer(0) +copyToR(aa) + + diff --git a/Examples/test-suite/r/r_double_delete_runme.R b/Examples/test-suite/r/r_double_delete_runme.R new file mode 100644 index 0000000..7b6fdb7 --- /dev/null +++ b/Examples/test-suite/r/r_double_delete_runme.R @@ -0,0 +1,9 @@ +dyn.load(paste("r_double_delete", .Platform$dynlib.ext, sep="")) +source("r_double_delete.R") +cacheMetaData(1) + +# ----- Object creation ----- + +f <- Foo(2.0) +delete(f); +delete(f); diff --git a/Examples/test-suite/r/r_legacy_runme.R b/Examples/test-suite/r/r_legacy_runme.R new file mode 100644 index 0000000..7e5ade8 --- /dev/null +++ b/Examples/test-suite/r/r_legacy_runme.R @@ -0,0 +1,30 @@ +source("unittest.R") +dyn.load(paste("r_legacy", .Platform$dynlib.ext, sep="")) +source("r_legacy.R") +cacheMetaData(1) + +obj <- getObject(1,3) +unittest(class(obj), "_p_Obj") +unittest(obj$i, 1) +unittesttol(obj$d, 3, 0.001) +unittest(obj$str, "a test string") +obj$i <- 2 +unittest(obj$i, 2) +obj$d <- 4 +unittesttol(obj$d, 4, 0.001) +obj$str <- "a new string" +unittest(obj$str, "a new string") + +unittest(getInt(), 42) +unittesttol(getDouble(),3.14159, 0.001) +unittesttol(getFloat(),3.14159/2.0, 0.001) +unittest(getLong(), -321313) +unittest(getUnsignedLong(), 23123) +unittest(getChar(), "A") + +q(save="no") + + + + + diff --git a/Examples/test-suite/r/simple_array_runme.R b/Examples/test-suite/r/simple_array_runme.R new file mode 100644 index 0000000..a6758de --- /dev/null +++ b/Examples/test-suite/r/simple_array_runme.R @@ -0,0 +1,9 @@ +source("unittest.R") +dyn.load(paste("simple_array", .Platform$dynlib.ext, sep="")) +source("simple_array.R") +cacheMetaData(1) +initArray() + +q(save="no") + + diff --git a/Examples/test-suite/r/unions_runme.R b/Examples/test-suite/r/unions_runme.R new file mode 100644 index 0000000..76870d1 --- /dev/null +++ b/Examples/test-suite/r/unions_runme.R @@ -0,0 +1,12 @@ +source("unittest.R") +dyn.load(paste("unions", .Platform$dynlib.ext, sep="")) +source("unions.R") +cacheMetaData(1) + +ss <- SmallStruct() + +bstruct <- BigStruct() + +q(save="no") + + diff --git a/Examples/test-suite/r/unittest.R b/Examples/test-suite/r/unittest.R new file mode 100644 index 0000000..81c590a --- /dev/null +++ b/Examples/test-suite/r/unittest.R @@ -0,0 +1,9 @@ +unittest <- function (x,y) { +if (x==y) print("PASS") +else print("FAIL") +} + +unittesttol <- function(x,y,z) { +if (abs(x-y) < z) print("PASS") +else print("FAIL") +}
\ No newline at end of file |
