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
This commit is contained in:
Karl Wette 2012-05-14 09:24:34 +00:00
commit daffde6c28
9 changed files with 118 additions and 288 deletions

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,5 @@
/* File : example.i */
%module example
/* module name given on cmdline */
%{
#include "example.h"
%}

View file

@ -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

View file

@ -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 #####

View file

@ -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 #####

View file

@ -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 #####

View file

@ -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 #####

View file

@ -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 #####