From: Joseph W. <dr...@us...> - 2006-06-29 03:01:26
|
Update of /cvsroot/swig/SWIG/Examples/test-suite/r In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv11408/Examples/test-suite/r Added Files: Makefile.in copyStruct_runme.R double_delete.i double_delete_runme.R funcptr_runme.R ignore_parameter_runme.R legacy_runme.R simpleArray_runme.R unions_runme.R unittest.R Log Message: Committing R-SWIG --- NEW FILE: unittest.R --- 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") } --- NEW FILE: legacy_runme.R --- source('unittest.R') dyn.load('legacy_wrap.so') source('legacy_wrap.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') --- NEW FILE: Makefile.in --- ####################################################################### # $Header: /cvsroot/swig/SWIG/Examples/test-suite/r/Makefile.in,v 1.1 2006/06/29 03:01:14 drjoe Exp $ # Makefile for mzscheme test-suite ####################################################################### LANGUAGE = r SCRIPTSUFFIX = _runme.R WRAPSUFFIX = _wrap.R RUNR = R CMD BATCH --no-save --no-restore srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ C_TEST_CASES = copyStruct simpleArray legacy CPP_TEST_CASES = funcptr double_delete include $(srcdir)/../common.mk # Overridden variables here # 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_testcase) # 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 \ $(RUNR) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ;) \ else \ ($(RUNR) $(srcdir)/$(SCRIPTPREFIX)$*$(WRAPSUFFIX);) \ fi; # Clean clean: $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile r_clean %.clean: @rm -f $*_wrap.R $*_wrap.so $*_wrap.cpp $*_wrap.c $*_runme.Rout --- NEW FILE: copyStruct_runme.R --- source('unittest.R') dyn.load('copyStruct_wrap.so') source('copyStruct_wrap.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 <- 5 other = A() foo <- copyToC(la, other) aa = A() aa$i = 201 aa$d = pi aa$str = 'foo' copyToR(aa) --- NEW FILE: double_delete.i --- /* File : example.i */ %module double_delete %inline %{ class Foo { private: double r; public: Foo(double rin) : r(rin) {}; }; %} --- NEW FILE: simpleArray_runme.R --- source('unittest.R') dyn.load('simpleArray_wrap.so') source('simpleArray_wrap.R') cacheMetaData(1) initArray() q(save='no') --- NEW FILE: funcptr_runme.R --- source('unittest.R') dyn.load('funcptr_wrap.so') source('funcptr_wrap.R') cacheMetaData(1) unittest(do_op(1, 3, add), 4) unittest(do_op(2, 3, mul), 6) unittest(do_op(2, 3, funcvar()), 5) --- NEW FILE: double_delete_runme.R --- # This file illustrates the shadow-class C++ interface generated # by SWIG. dyn.load('double_delete_wrap.so') source('double_delete_wrap.R') cacheMetaData(1) # ----- Object creation ----- f <- Foo(2.0) delete(f); delete(f); --- NEW FILE: unions_runme.R --- source('unittest.R') dyn.load('unions_wrap.so') source('unions_wrap.R') cacheMetaData(1) ss <- SmallStruct() bstruct <- BigStruct() q(save='no') --- NEW FILE: ignore_parameter_runme.R --- source('unittest.R') dyn.load('ignore_parameter_wrap.so') source('ignore_parameter_wrap.R') cacheMetaData(1) unittest(jaguar(1, 1.0), "hello") q(save='no') |