From daffde6c2814a145cb0658a3c8dff440fb9f0dbd Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Mon, 14 May 2012 09:24:34 +0000 Subject: [PATCH] Updated Octave module_load examples for new module loading - Module compiled twice to check '-globals .' behaviour - Only one runme.m needed since clearing modules should now be safe for all Octave versions. - Tests new module loading syntax and behaviour git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13089 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 4 +- Examples/octave/module_load/Makefile | 12 +- Examples/octave/module_load/example.i | 2 +- Examples/octave/module_load/runme.m | 112 ++++++++++++++++++ Examples/octave/module_load/runme_args.m | 48 -------- Examples/octave/module_load/runme_gl_func.m | 59 --------- .../octave/module_load/runme_gl_func_base.m | 59 --------- Examples/octave/module_load/runme_nogl_func.m | 55 --------- .../octave/module_load/runme_nogl_func_base.m | 55 --------- 9 files changed, 118 insertions(+), 288 deletions(-) create mode 100644 Examples/octave/module_load/runme.m delete mode 100644 Examples/octave/module_load/runme_args.m delete mode 100644 Examples/octave/module_load/runme_gl_func.m delete mode 100644 Examples/octave/module_load/runme_gl_func_base.m delete mode 100644 Examples/octave/module_load/runme_nogl_func.m delete mode 100644 Examples/octave/module_load/runme_nogl_func_base.m diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 8d63d02b5..04f794f61 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -365,9 +365,7 @@ octave_cpp: $(SRCS) OCTSCRIPT = runme.m octave_run: $(OCTSCRIPT) - for file in $(OCTSCRIPT); do \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVE_PATH=$(srcdir):$$OCTAVE_PATH $(OCTAVE) $$file >/dev/null || break; \ - done + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVE_PATH=$(srcdir):$$OCTAVE_PATH $(OCTAVE) $(OCTSCRIPT) >/dev/null # ----------------------------------------------------------------- # Cleaning the octave examples diff --git a/Examples/octave/module_load/Makefile b/Examples/octave/module_load/Makefile index 4266ec184..da2c704e0 100644 --- a/Examples/octave/module_load/Makefile +++ b/Examples/octave/module_load/Makefile @@ -3,16 +3,12 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -OCTSCRIPTS = \ - runme_args.m \ - runme_gl_func.m \ - runme_gl_func_base.m \ - runme_nogl_func.m \ - runme_nogl_func_base.m all:: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave + TARGET='$(TARGET)' SWIGOPT='-module $$(TARGET)' INTERFACE='$(INTERFACE)' octave + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave static:: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ @@ -23,4 +19,4 @@ clean:: rm -f $(TARGET).m check: all - $(MAKE) -f $(TOP)/Makefile OCTSCRIPT="$(OCTSCRIPTS)" octave_run + $(MAKE) -f $(TOP)/Makefile octave_run diff --git a/Examples/octave/module_load/example.i b/Examples/octave/module_load/example.i index f5a50444d..fd074d4f2 100644 --- a/Examples/octave/module_load/example.i +++ b/Examples/octave/module_load/example.i @@ -1,5 +1,5 @@ /* File : example.i */ -%module example +/* module name given on cmdline */ %{ #include "example.h" %} diff --git a/Examples/octave/module_load/runme.m b/Examples/octave/module_load/runme.m new file mode 100644 index 000000000..4942a02de --- /dev/null +++ b/Examples/octave/module_load/runme.m @@ -0,0 +1,112 @@ +# file: runme_args.m + +# test module loading with arguments +clear all + +# access module, no global load +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all + +# load module globally +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all + +# access module in a function, no global load +function testme + example = example; + assert(example.cvar.ivar == example.ifunc()); +endfunction +testme +testme +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all +function testme + example = example; + assert(example.cvar.ivar == example.ifunc()); +endfunction +testme +testme +example = example; +assert(example.cvar.ivar == example.ifunc()); +clear all + +# load module in a function globally before base context +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +clear all + +# load module in a function globally after base context +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +clear all +example; +assert(cvar.ivar == ifunc); +assert(exist("example","var")); +function testme + example; + assert(cvar.ivar == ifunc); + assert(exist("example","var")); +endfunction +testme +testme +clear all + +# access module with no cvar, no global load +example2 = example2; +assert(example2.ivar == example2.ifunc()); +assert(!isglobal("cvar")) +clear all +example2 = example2; +assert(example2.ivar == example2.ifunc()); +assert(!isglobal("cvar")) +clear all + +# load module with no cvar globally +example2; +assert(example2.ivar == ifunc); +assert(exist("example2","var")); +assert(!isglobal("cvar")) +clear all +example2; +assert(example2.ivar == ifunc); +assert(exist("example2","var")); +assert(!isglobal("cvar")) +clear all diff --git a/Examples/octave/module_load/runme_args.m b/Examples/octave/module_load/runme_args.m deleted file mode 100644 index 716ee31f9..000000000 --- a/Examples/octave/module_load/runme_args.m +++ /dev/null @@ -1,48 +0,0 @@ -# file: runme_args.m - -# test module loading with arguments - -##### BEGIN TEST ##### -# test help -example -help -assert(!isglobal("example")) - -# load module with custom cvar -example -globals mycvar -assert(!isglobal("cvar")) -assert(mycvar.ivar == example.ifunc()) -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -# test help -example -help -assert(!isglobal("example")) - -# load module with custom cvar -example -globals mycvar -assert(!isglobal("cvar")) -assert(mycvar.ivar == example.ifunc()) -##### END TEST ##### - -clear all; - -##### BEGIN TEST ##### -# load module with root-level cvar -example -globals . -assert(example.ivar == example.ifunc()) -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_gl_func.m b/Examples/octave/module_load/runme_gl_func.m deleted file mode 100644 index 1624cdd9a..000000000 --- a/Examples/octave/module_load/runme_gl_func.m +++ /dev/null @@ -1,59 +0,0 @@ -# file: runme_gl_func.m - -# test whether module can be loaded -# in a function (global cvar) - -1; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_gl_func_base.m b/Examples/octave/module_load/runme_gl_func_base.m deleted file mode 100644 index 0e3eb6112..000000000 --- a/Examples/octave/module_load/runme_gl_func_base.m +++ /dev/null @@ -1,59 +0,0 @@ -# file: runme_gl_func_base.m - -# test whether module can be loaded in a function -# before the base context (global cvar) - -1; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example - global cvar - assert(cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -global cvar -assert(cvar.ivar == example.ifunc()) -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_nogl_func.m b/Examples/octave/module_load/runme_nogl_func.m deleted file mode 100644 index fd8e19f37..000000000 --- a/Examples/octave/module_load/runme_nogl_func.m +++ /dev/null @@ -1,55 +0,0 @@ -# file: runme_nogl_func.m - -# test whether module can be loaded -# in a function (no global cvar) - -1; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) - -# test loading in a function -func - -# test a second time to check everything works -func -##### END TEST ##### diff --git a/Examples/octave/module_load/runme_nogl_func_base.m b/Examples/octave/module_load/runme_nogl_func_base.m deleted file mode 100644 index bb8da9328..000000000 --- a/Examples/octave/module_load/runme_nogl_func_base.m +++ /dev/null @@ -1,55 +0,0 @@ -# file: runme_nogl_func_base.m - -# test whether module can be loaded in a function -# before the base context (no global cvar) - -1; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) -##### END TEST ##### - -# clearing a module results in a segfault for Octave <= 3.0.* -# (tested on Octave 3.0.5), so skip the following test -try - vers = cellfun("str2num", strsplit(OCTAVE_VERSION, ".")); -catch - vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, "."))); -end_try_catch -assert(length(vers) >= 2); -if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0) - disp("skipping 'clear all' test"); - return -endif - -clear all; - -##### BEGIN TEST ##### -function func - example -noglobal - assert(example.cvar.ivar == example.ifunc()) -endfunction - -# test loading in a function -func - -# test a second time to check everything works -func - -# test that everything works from the base context -example -noglobal -assert(example.cvar.ivar == example.ifunc()) -##### END TEST #####