Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 67 additions & 3 deletions ant/toplevel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,77 @@ Type "ant -p" for a list of targets.

<target name="test-matlab" description="run Matlab tests" depends="tools">
<property environment="env"/>
<exec executable="matlab">
<env key="MATLABPATH" value="${env.MATLABPATH}:${root.dir}/components/bio-formats/matlab:${artifact.dir}"/>
<if>
<isset property="env.MATLABPATH"/>
<then>
<if>
<isset property="isWindows"/>
<then>
<property name="test.matlabpath" value="${env.MATLABPATH};${root.dir}/components/formats-gpl/matlab;${artifact.dir}"/>
</then>
<property name="test.matlabpath" value="${env.MATLABPATH}:${root.dir}/components/formats-gpl/matlab:${artifact.dir}"/>
<else>
</else>
</if>
</then>
<else>
<if>
<isset property="isWindows"/>
<then>
<property name="test.matlabpath" value="${root.dir}/components/formats-gpl/matlab;${artifact.dir}"/>
</then>
<else>
<property name="test.matlabpath" value="${root.dir}/components/formats-gpl/matlab:${artifact.dir}"/>
</else>
</if>
</else>
</if>
<exec executable="matlab" dir="${artifact.dir}" failonerror="true">
<env key="MATLABPATH" value="${test.matlabpath}"/>
<arg value="-nodesktop"/>
<arg value="-nosplash"/>
<arg value="-r"/>
<arg value="runtests ${root.dir}/components/formats-gpl/test/matlab"/>
</exec>
</exec>

</target>

<target name="test-matlab-xunit" description="run Matlab tests" depends="tools">
<property environment="env"/>
<property name="test.matlab.file" value="${root.dir}/report.xml"/>
<if>
<isset property="env.MATLABPATH"/>
<then>
<if>
<isset property="isWindows"/>
<then>
<property name="test.matlabpath" value="${env.MATLABPATH};${root.dir}/components/formats-gpl/matlab;${root.dir}/components/formats-gpl/test/matlab;${artifact.dir}"/>
</then>
<property name="test.matlabpath" value="${env.MATLABPATH}:${root.dir}/components/formats-gpl/matlab:${root.dir}/components/formats-gpl/test/matlab:${artifact.dir}"/>
<else>
</else>
</if>
</then>
<else>
<if>
<isset property="isWindows"/>
<then>
<property name="test.matlabpath" value="${root.dir}/components/formats-gpl/matlab;${root.dir}/components/formats-gpl/test/matlab;${artifact.dir}"/>
</then>
<else>
<property name="test.matlabpath" value="${root.dir}/components/formats-gpl/matlab:${root.dir}/components/formats-gpl/test/matlab:${artifact.dir}"/>
</else>
</if>
</else>
</if>
<exec executable="matlab" dir="${artifact.dir}" failonerror="true">
<env key="MATLABPATH" value="${test.matlabpath}"/>
<arg value="-nodesktop"/>
<arg value="-nosplash"/>
<arg value="-r"/>
<arg value="runbfxunit ${test.matlab.file}"/>
</exec>

</target>

<!-- Octave -->
Expand Down
20 changes: 8 additions & 12 deletions components/formats-gpl/test/matlab/ReaderTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

classdef ReaderTest < TestBfMatlab

properties
reader
sizeX
Expand All @@ -35,14 +35,9 @@
sizeC
sizeT
end

methods
function self = ReaderTest(name)
self = self@TestBfMatlab(name);
end

function setUp(self)
setUp@TestBfMatlab(self)

methods (TestMethodSetup)
function ReaderTestSetUp(self)
javaaddpath(self.jarPath);
self.reader = loci.formats.in.FakeReader();
self.sizeX = self.reader.DEFAULT_SIZE_X;
Expand All @@ -53,13 +48,14 @@ function setUp(self)
loci.common.DebugTools.setRootLevel('ERROR');
import ome.units.UNITS.*;
end

function tearDown(self)
end

methods (TestMethodTeardown)
function ReaderTestTearDown(self)
if ~isempty(self.reader),
self.reader.close();
self.reader = [];
end
tearDown@TestBfMatlab(self)
end
end
end
22 changes: 10 additions & 12 deletions components/formats-gpl/test/matlab/TestBfCheckJavaMemory.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,46 @@
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

classdef TestBfCheckJavaMemory < TestBfMatlab

properties
minMemory
warning_id = ''
end

methods
function self = TestBfCheckJavaMemory(name)
self = self@TestBfMatlab(name);
end

% Dimension size tests
function runJavaMemoryCheck(self)
lastwarn('');
bfCheckJavaMemory(self.minMemory)
[last_warning_msg, last_warning_id] = lastwarn;
assertEqual(last_warning_id, self.warning_id);
self.assertEqual(last_warning_id, self.warning_id);
lastwarn('');
end

end

methods (Test)
function testZero(self)
self.minMemory = 0;
self.runJavaMemoryCheck()
end

function testMaxMemory(self)
self.minMemory = self.getRuntime();
self.runJavaMemoryCheck()
end

function testLowMemory(self)
self.minMemory = round(self.getRuntime() + 100);
self.warning_id = 'BF:lowJavaMemory';
self.runJavaMemoryCheck()
end
end

methods(Static)

function memory = getRuntime()
runtime = java.lang.Runtime.getRuntime();
memory = runtime.maxMemory() / (1024 * 1024);
end
end

end
41 changes: 20 additions & 21 deletions components/formats-gpl/test/matlab/TestBfCheckJavaPath.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,37 @@


classdef TestBfCheckJavaPath < TestBfMatlab

properties
status
version
maxTime = .1
end

methods
function self = TestBfCheckJavaPath(name)
self = self@TestBfMatlab(name);
end


methods (Test)
function testDefault(self)
javaaddpath(self.jarPath);
self.status = bfCheckJavaPath();
assertTrue(self.status);
self.assertTrue(self.status);
end

function testAutoloadBioformats(self)
javaaddpath(self.jarPath);
self.status = bfCheckJavaPath(true);
assertTrue(self.status);
self.assertTrue(self.status);
end

function testNoAutoloadBioformats(self)
isStatic = ismember(self.jarPath,...
javaclasspath('-static'));
self.status = bfCheckJavaPath(false);
if isStatic
assertTrue(self.status);
self.assertTrue(self.status);
else
assertFalse(self.status);
self.assertFalse(self.status);
end
end

function testPerformance(self)
nCounts = 10;
times = zeros(nCounts);
Expand All @@ -68,27 +66,28 @@ function testPerformance(self)
bfCheckJavaPath();
times(i) = toc;
end

% First call should be the longest as the Bio-Formats JAR file is
% added to the javaclasspath
assertTrue(times(1) > times(2));
self.assertTrue(times(1) > times(2));
% Second call should still be longer than all the following
% ones. Profiling reveals some amount of time is spent while
% computing javaclasspath.local_get_static_path
assertTrue(all(times(2) > times(3:end)));
self.assertTrue(all(times(2) > times(3:end)));
% From the third call and onwards, javaclasspath and thus
% bfCheckJavaPath should return fast
assertTrue(mean(times(3:end)) < self.maxTime);
self.assertTrue(mean(times(3:end)) < self.maxTime);
end

function testJavaMethod(self)
javaaddpath(self.jarPath);
self.status = bfCheckJavaPath(true);
version = char(loci.formats.FormatTools.VERSION);
[self.status self.version]= bfCheckJavaPath(false);
assertEqual(self.version,version);
self.assertEqual(self.version,version);
if (exist ('OCTAVE_VERSION', 'builtin'))
version = char(java_get('loci.formats.FormatTools', 'VERSION'));
assertEqual( self.version, version);
self.assertEqual( self.version, version);
end
end
end
Expand Down
Loading