diff options
author | Shashank | 2017-05-29 12:40:26 +0530 |
---|---|---|
committer | Shashank | 2017-05-29 12:40:26 +0530 |
commit | 0345245e860375a32c9a437c4a9d9cae807134e9 (patch) | |
tree | ad51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/javasci/tests | |
download | scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2 scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip |
CMSCOPE changed
Diffstat (limited to 'modules/javasci/tests')
19 files changed, 2222 insertions, 0 deletions
diff --git a/modules/javasci/tests/java/javasci-JAVA-tests.vcxproj b/modules/javasci/tests/java/javasci-JAVA-tests.vcxproj new file mode 100755 index 000000000..c89563aab --- /dev/null +++ b/modules/javasci/tests/java/javasci-JAVA-tests.vcxproj @@ -0,0 +1,152 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{9BE8D73A-7E83-46ED-A9E2-1E3472F52AE5}</ProjectGuid> + <RootNamespace>javasci-java-tests</RootNamespace> + <Keyword>MakeFileProj</Keyword> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Makefile</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Makefile</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Makefile</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Makefile</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup> + <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)modules\javasci\jar\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)$(Configuration)\</IntDir> + <NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test +</NMakeBuildCommandLine> + <NMakeReBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test + +</NMakeReBuildCommandLine> + <NMakeCleanCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> + <NMakeOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> + <NMakePreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions> + <NMakeIncludeSearchPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath> + <NMakeForcedIncludes Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeForcedIncludes)</NMakeForcedIncludes> + <NMakeAssemblySearchPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath> + <NMakeForcedUsingAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)modules\javasci\jar\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)$(Configuration)\</IntDir> + <NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test +</NMakeBuildCommandLine> + <NMakeReBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test + +</NMakeReBuildCommandLine> + <NMakeCleanCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> + <NMakeOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> + <NMakePreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions> + <NMakeIncludeSearchPath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath> + <NMakeForcedIncludes Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(NMakeForcedIncludes)</NMakeForcedIncludes> + <NMakeAssemblySearchPath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath> + <NMakeForcedUsingAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)modules\javasci\jar\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)$(Configuration)\</IntDir> + <NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test +</NMakeBuildCommandLine> + <NMakeReBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test + +</NMakeReBuildCommandLine> + <NMakeCleanCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> + <NMakeOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> + <NMakePreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions> + <NMakeIncludeSearchPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath> + <NMakeForcedIncludes Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeForcedIncludes)</NMakeForcedIncludes> + <NMakeAssemblySearchPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath> + <NMakeForcedUsingAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)modules\javasci\jar\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)$(Configuration)\</IntDir> + <NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|x64'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test +</NMakeBuildCommandLine> + <NMakeReBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|x64'">set JAVA_HOME=$(SolutionDir)java\jdk +set PATH=$(SolutionDir)java\ant\bin;$(SolutionDir)bin;%PATH%; +cd ..\.. +call ant test + +</NMakeReBuildCommandLine> + <NMakeCleanCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> + <NMakeOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> + <NMakePreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions> + <NMakeIncludeSearchPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath> + <NMakeForcedIncludes Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(NMakeForcedIncludes)</NMakeForcedIncludes> + <NMakeAssemblySearchPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath> + <NMakeForcedUsingAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies> + </PropertyGroup> + <ItemDefinitionGroup> + </ItemDefinitionGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\..\Visual-Studio-settings\ant-all\ant-all.vcxproj"> + <Project>{a9a2020d-5541-44f2-b080-df3c9426c409}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/modules/javasci/tests/java/javasci-JAVA-tests.vcxproj.filters b/modules/javasci/tests/java/javasci-JAVA-tests.vcxproj.filters new file mode 100755 index 000000000..834c44131 --- /dev/null +++ b/modules/javasci/tests/java/javasci-JAVA-tests.vcxproj.filters @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug10801.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug10801.java new file mode 100755 index 000000000..1dcf81340 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug10801.java @@ -0,0 +1,69 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2012 - DIGITEO - Vincent COUVERT + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.types.ScilabString; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testBug10801 { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(true); + assertTrue(sci.open()); + } + + @Test() + public void nonRegBug10801() throws NullPointerException, JavasciException { + try { + assertTrue(sci.exec("plot3d()")); + assertTrue(sci.isGraphicOpened()); + assertTrue(sci.exec("winId = winsid();")); + assertTrue(((ScilabDouble)sci.get("winId")).equals(new ScilabDouble(0))); + sci.close(); + sci.open(); + assertFalse(sci.isGraphicOpened()); + assertTrue(sci.exec("winId = winsid()")); + assertTrue(((ScilabDouble)sci.get("winId")).equals(new ScilabDouble())); + sci.close(); + } catch (Exception e) { + System.err.print("e = " + e); + } + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug4211.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug4211.java new file mode 100755 index 000000000..696b53b81 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug4211.java @@ -0,0 +1,60 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.types.ScilabString; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testBug4211 { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void nonRegBug4211() throws NullPointerException, JavasciException { + assertEquals(sci.exec("disp(plop);"), false); + assertEquals(sci.getLastErrorCode(), 4); + sci.close(); + + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug6651.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug6651.java new file mode 100755 index 000000000..321cdefd4 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug6651.java @@ -0,0 +1,68 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.types.ScilabString; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testBug6651 { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void nonRegBug6651() throws NullPointerException, JavasciException { + double[][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; + + ScilabDouble A = new ScilabDouble(a); + sci.put("a", A); + assertTrue(sci.exec("b = a;")); + + ScilabDouble B = (ScilabDouble)sci.get("b"); + assertTrue(B.equals(A)); + + assertTrue(sci.exec("c = a;")); + ScilabDouble C = (ScilabDouble)sci.get("c"); + assertTrue(C.equals(A)); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug7054.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug7054.java new file mode 100755 index 000000000..3c97f36dd --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug7054.java @@ -0,0 +1,66 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabInteger; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testBug7054 { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test( expected = java.lang.ClassCastException.class) + public void nonRegBug7054() throws NullPointerException, JavasciException { + assertTrue(sci.exec("xx = 123;")); + /* Trigger an ClassCastException exception with the error: + * Exception in thread "main" java.lang.ClassCastException: org.scilab.modules.types.ScilabDouble cannot be cast to org.scilab.modules.types.ScilabInteger */ + ScilabInteger zz = (ScilabInteger)sci.get("xx"); + + } + + @Test() + public void nonRegBug7054Working() throws NullPointerException, JavasciException { + assertTrue(sci.exec("xx = int8(123);")); + ScilabInteger zz = (ScilabInteger)sci.get("xx"); + assertEquals(zz.getData()[0][0], 123); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug9149.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug9149.java new file mode 100755 index 000000000..08045d2bb --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug9149.java @@ -0,0 +1,80 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.ScilabErrorException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabInteger; +import org.scilab.modules.types.ScilabTypeEnum; +import org.scilab.modules.commons.ScilabCommons; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.SwingUtilities; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class testBug9149 { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test( expected = ScilabErrorException.class) + public void nonRegBug9149Working() throws NullPointerException, ScilabErrorException { + assertEquals(sci.isGraphicOpened(), false); + sci.execException("plot3d();"); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } + +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug9544.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug9544.java new file mode 100755 index 000000000..a3c4b65fa --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testBug9544.java @@ -0,0 +1,138 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; + +import java.awt.GraphicsEnvironment; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabInteger; +import org.scilab.modules.types.ScilabTypeEnum; +import org.scilab.modules.commons.ScilabCommons; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.SwingUtilities; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class testBug9544 { + private Scilab sci; + private Test_sci x; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(true); + assertTrue(sci.open()); + } + + @Test() + public void nonRegBug9544Working() throws NullPointerException, JavasciException, IOException { + if (!GraphicsEnvironment.isHeadless()) { + x = new Test_sci(); + } + } + + /** + * See #open() + */ + @After + public void close() { + if (!GraphicsEnvironment.isHeadless()) { + x.dispose(); + } + sci.close(); + + } + + public class Test_sci extends JFrame { + + private JPanel container = new JPanel(); + private JButton b = new JButton ("Auto clicked button"); + private JLabel resultat; + + private Scilab sci; + + + + public Test_sci() { /*throws IOException*/ + try { + sci = new Scilab(true); + } catch (org.scilab.modules.javasci.JavasciException f) { + System.err.println("An exception occurred: " + f.getLocalizedMessage()); + } + this.setTitle("bug 9544 non reg test"); + this.setSize(200, 100); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel top = new JPanel(); + b.addActionListener(new BoutonListener()); + + top.add(b); + + this.setContentPane(top); + this.setVisible(true); + + new Thread(new Runnable() { + public void run() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + b.doClick(); + } + }); + } + }).start(); + + } + + class BoutonListener implements ActionListener { + + public void actionPerformed(ActionEvent g) { + List<String> commands = new ArrayList<String>(); + commands.add("X = [1,2];"); + commands.add("Y = [3,4];"); + commands.add("plot(X,Y);"); + assertTrue(sci.exec(commands.toArray(new String[commands.size()]))); + } + + } + } +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testErrorManagement.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testErrorManagement.java new file mode 100755 index 000000000..37ee033fa --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testErrorManagement.java @@ -0,0 +1,109 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.ScilabErrorException; + + +public class testErrorManagement { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + + @Test() + public void getLastErrorCodeTest() throws NullPointerException, JavasciException { + assertEquals(sci.getLastErrorCode(), 0); // No error + sci.close(); + + assertEquals(sci.open("a=1+"), false); + assertEquals(sci.getLastErrorCode(), 2); + sci.exec("errclear();"); + sci.exec("a+b"); + assertEquals(sci.getLastErrorCode(), 4); + sci.exec("errclear();"); + } + + @Test() + public void getLastErrorMessageTest() throws NullPointerException, JavasciException { + sci.exec("errclear();"); // No error by default + assertTrue(sci.getLastErrorMessage().equals("")); + assertEquals(sci.getLastErrorMessage().length(), 0); + + sci.exec("errclear();"); + sci.close(); + + assertEquals(sci.open("a=1+"), false); + assertTrue(sci.getLastErrorMessage().length() > 0); + sci.exec("errclear();"); + sci.exec("a+b"); //undefined a & b + assertTrue(sci.getLastErrorMessage().length() > 0); + sci.exec("errclear();"); + sci.exec("a=rand(10,10);");//no error + assertEquals(sci.getLastErrorMessage().length(), 0); + } + + @Test() + public void getLastErrorMessageWithExceptionNonErrorTest() throws NullPointerException, JavasciException { + sci.execException("errclear();"); // No error by default + assertTrue(sci.getLastErrorMessage().equals("")); + assertEquals(sci.getLastErrorMessage().length(), 0); + + sci.execException("errclear();"); + } + + @Test() + public void getLastErrorMessageWithExceptionNonError2Test() throws NullPointerException, JavasciException { + sci.execException("errclear();"); // No error by default + assertTrue(sci.getLastErrorMessage().equals("")); + assertEquals(sci.getLastErrorMessage().length(), 0); + sci.execException("a=rand(10,10);");//no error + assertEquals(sci.getLastErrorMessage().length(), 0); + } + + + @Test( expected = ScilabErrorException.class) + public void getLastErrorMessageWithExceptionWithErrorTest() throws NullPointerException, ScilabErrorException { + sci.execException("a+b"); //undefined a & b + } + + @Test( expected = ScilabErrorException.class) + public void getLastErrorMessageWithExceptionWithError2Test() throws NullPointerException, ScilabErrorException { + sci.execException("a+b*"); //undefined a & b + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + } +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExec.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExec.java new file mode 100755 index 000000000..b3800fb8b --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExec.java @@ -0,0 +1,145 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.FileNotFoundException; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; + +public class testExec { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void execAndReadTest() throws NullPointerException, JavasciException { + + /* Scalar test */ + assertTrue(sci.exec("a = 1+1")); + ScilabType a = sci.get("a"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(a.getHeight(), 1); + assertEquals(a.getWidth(), 1); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 2.0, 1e-8); + + /* Matrix 10x10 */ + assertTrue(sci.exec("b = matrix(1:100,10,10)")); + + ScilabType b = sci.get("b"); + + assertEquals(b.getHeight(), 10); + assertEquals(b.getWidth(), 10); + + /* Check results of the addition of two matrixes */ + assertTrue(sci.exec("c = [42, 12; 32, 32] + [2, 1; 3, 2]; sumMatrix = sum(c);")); + ScilabType c = sci.get("c"); + + assertEquals(c.getHeight(), 2); + + assertEquals(c.getWidth(), 2); + + double sum = 0; + /* Compute ourself the sum of all matrices elements */ + for (int i = 0; i < c.getHeight(); i++) { + for (int j = 0; j < c.getWidth(); j++) { + sum += ((ScilabDouble)c).getRealPart()[i][j]; + } + } + ScilabType sumMatrix = sci.get("sumMatrix"); + /* Compare if they match */ + assertEquals(((ScilabDouble)sumMatrix).getRealPart()[0][0], sum, 1e-8); + sci.exec("b = matrix(1:100,10,10)") ; + ScilabType b2 = sci.get("b"); + b2.getHeight(); // 10 + b2.getWidth(); // 10 + ScilabDouble b3 = (ScilabDouble)sci.get("b"); + assertTrue(b3.equals(b2)); + } + + + @Test() + public void execFromFileTest() throws NullPointerException, JavasciException { + sci.close(); + + try { + // Create temp file. + File tempScript = File.createTempFile("tempScript", ".sci"); + + // Write to temp file + BufferedWriter out = new BufferedWriter(new FileWriter(tempScript)); + out.write("a=4+42;"); + out.close(); + + assertTrue(sci.open(tempScript)); + + ScilabType a = sci.get("a"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 46.0, 1e-8); + tempScript.delete(); + + } catch (IOException e) { + } + } + + @Test( expected = FileNotFoundException.class) + public void execFromNonExistingFileTest() throws NullPointerException, InitializationException, FileNotFoundException, JavasciException { + sci.close(); + + File nonExistingFile = new File("/wrong/path/file"); + + sci.open(nonExistingFile); + } + + @Test() + public void execExecstrTest() throws NullPointerException, InitializationException, FileNotFoundException, JavasciException { + sci.exec("execstr('toto = 111')"); + + ScilabType a = sci.get("toto"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 111.0, 1e-8); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExecException.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExecException.java new file mode 100755 index 000000000..87f85370b --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExecException.java @@ -0,0 +1,175 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.FileNotFoundException; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; + +public class testExecException { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void execAndReadTest() throws NullPointerException, JavasciException { + /* Scalar test */ + sci.execException("a = 1+1"); + ScilabType a = sci.get("a"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(a.getHeight(), 1); + assertEquals(a.getWidth(), 1); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 2.0, 1e-8); + + /* Matrix 10x10 */ + sci.execException("b = matrix(1:100,10,10)"); + + ScilabType b = sci.get("b"); + + assertEquals(b.getHeight(), 10); + assertEquals(b.getWidth(), 10); + + /* Check results of the addition of two matrixes */ + sci.execException("c = [42, 12; 32, 32] + [2, 1; 3, 2]; sumMatrix = sum(c);"); + ScilabType c = sci.get("c"); + + assertEquals(c.getHeight(), 2); + + assertEquals(c.getWidth(), 2); + + double sum = 0; + /* Compute ourself the sum of all matrices elements */ + for (int i = 0; i < c.getHeight(); i++) { + for (int j = 0; j < c.getWidth(); j++) { + sum += ((ScilabDouble)c).getRealPart()[i][j]; + } + } + ScilabType sumMatrix = sci.get("sumMatrix"); + /* Compare if they match */ + assertEquals(((ScilabDouble)sumMatrix).getRealPart()[0][0], sum, 1e-8); + sci.execException("b = matrix(1:100,10,10)") ; + ScilabType b2 = sci.get("b"); + b2.getHeight(); // 10 + b2.getWidth(); // 10 + ScilabDouble b3 = (ScilabDouble)sci.get("b"); + assertTrue(b3.equals(b2)); + } + + + @Test() + public void execFromFileTest() throws NullPointerException, JavasciException { + sci.close(); + + try { + // Create temp file. + File tempScript = File.createTempFile("tempScript", ".sci"); + + // Write to temp file + BufferedWriter out = new BufferedWriter(new FileWriter(tempScript)); + out.write("a=4+42;"); + out.close(); + + assertTrue(sci.open(tempScript)); + + ScilabType a = sci.get("a"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 46.0, 1e-8); + tempScript.delete(); + + } catch (IOException e) { + } + } + + @Test( expected = FileNotFoundException.class) + public void execFromNonExistingFileTest() throws NullPointerException, InitializationException, FileNotFoundException, JavasciException { + sci.close(); + + File nonExistingFile = new File("/wrong/path/file"); + + sci.open(nonExistingFile); + } + + @Test() + public void execExecstrTest() throws NullPointerException, InitializationException, FileNotFoundException, JavasciException { + sci.execException("execstr('toto = 111')"); + + ScilabType a = sci.get("toto"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 111.0, 1e-8); + } + + @Test() + public void execExecFileTest() throws NullPointerException, InitializationException, FileNotFoundException, JavasciException { + + try { + // Create temp file. + File tempScript = File.createTempFile("tempScript", ".sci"); + + // Write to temp file + BufferedWriter out = new BufferedWriter(new FileWriter(tempScript)); + out.write("a=4+42;"); + out.close(); + + sci.execException(tempScript); + + ScilabType a = sci.get("a"); + double[][] aReal = ((ScilabDouble)a).getRealPart(); + + assertEquals(aReal[0][0], 46, 1e-8); + } catch (IOException e) { + } + + } + + @Test( expected = FileNotFoundException.class) + public void execExecNonFileTest() throws NullPointerException, InitializationException, FileNotFoundException, JavasciException { + + sci.execException(new File("Doesnotexist")); + + + + } + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExistingVariable.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExistingVariable.java new file mode 100755 index 000000000..a66da4652 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExistingVariable.java @@ -0,0 +1,72 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabDouble; + +public class testExistingVariable { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void existVariableTest() throws NullPointerException, JavasciException { + double [][]a = {{21.2, 22.0, 42.0, 39.0}, {23.2, 24.0, 44.0, 40.0}}; + ScilabDouble aOriginal = new ScilabDouble(a); + sci.put("a", aOriginal); + assertTrue(sci.isExistingVariable("a")); + } + + @Test() + public void notExistVariableTest() throws NullPointerException, JavasciException { + assertEquals(sci.isExistingVariable("a"), false); + assertEquals(sci.isExistingVariable("b"), false); + } + + + @Test() + public void existVariableAfterExecTest() throws NullPointerException, JavasciException { + assertTrue(sci.exec("a=rand(20,20);")); + assertTrue(sci.isExistingVariable("a")); + assertTrue(sci.exec("b='test variable';")); + assertTrue(sci.isExistingVariable("b")); + } + + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExportOffscreen.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExportOffscreen.java new file mode 100755 index 000000000..7f3fa117d --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testExportOffscreen.java @@ -0,0 +1,128 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2012 - Scilab Enterprises - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.File; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testExportOffscreen { + private Scilab sci; + private String tmpDir = System.getProperty("java.io.tmpdir"); + + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(true); + assertTrue(sci.open()); + } + + private String generateExportCommand(String type, File filename) { + String exportToFile = "driver('" + type + "'); xinit('" + filename.getAbsolutePath() + "'); plot3d(); xend()"; + return exportToFile; + } + + @Test() + public void exportToPSTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.ps"); + String exportToFile = generateExportCommand("ps", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToPOSTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.ps"); + String exportToFile = generateExportCommand("Pos", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToGIFTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.gif"); + String exportToFile = generateExportCommand("GIF", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToPPMTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.ppm"); + String exportToFile = generateExportCommand("PPM", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToJPGTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.jpg"); + String exportToFile = generateExportCommand("JPG", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToPDFTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.pdf"); + String exportToFile = generateExportCommand("PDF", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToSVGTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.svg"); + String exportToFile = generateExportCommand("SVG", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + @Test() + public void exportToPNGTest() throws NullPointerException, JavasciException { + File export = new File(tmpDir + "/foo.svg"); + String exportToFile = generateExportCommand("PNG", export); + sci.exec(exportToFile); + assertTrue(export.exists()); + assertTrue(export.length() > 0); + assertTrue(export.delete()); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } + +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testGraphics.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testGraphics.java new file mode 100755 index 000000000..654a9d10e --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testGraphics.java @@ -0,0 +1,63 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.awt.GraphicsEnvironment; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testGraphics { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(true); // True = enable advanced mode + assertTrue(sci.open()); + } + + @Test() + public void isGraphicOpenedTest() throws NullPointerException, JavasciException { + if (!GraphicsEnvironment.isHeadless()) { + sci.exec("plot3d();"); + assertTrue(sci.isGraphicOpened()); + } + } + + @Test() + public void isGraphicNotOpenedTest() throws NullPointerException, JavasciException { + + sci.exec("a=1+1;"); + assertEquals(sci.isGraphicOpened(), false); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testOpenClose.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testOpenClose.java new file mode 100755 index 000000000..61f5239d4 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testOpenClose.java @@ -0,0 +1,112 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.AlreadyRunningException; + +import org.scilab.modules.commons.ScilabConstants; + +public class testOpenClose { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void openTest() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void multipleOpenCloseTest() throws NullPointerException, JavasciException { + assertTrue(sci.close()); + assertTrue(sci.open()); + assertTrue(sci.close()); + } + + @Test( expected = JavasciException.class) + public void specificWrongSCIPathTest() throws NullPointerException, JavasciException { + assertTrue(sci.close()); + sci = new Scilab(System.getProperty("java.io.tmpdir") + "/non-existing-directory-scilab/"); + } + + + @Test() + public void specificPropertySCIPathTest() throws NullPointerException, JavasciException { + assertTrue(sci.close()); + sci = new Scilab(System.getProperty("SCI")); + } + + @Test() + public void specificEnvSCIPathTest() throws NullPointerException, JavasciException { + assertTrue(sci.close()); + String SCIPath = System.getProperty("SCI"); // Temp backup to set it again + System.clearProperty("SCI"); // Remove the property to check it is using the variable + sci = new Scilab(); + assertTrue(sci.open("a=42*2;")); + + } + + @Test() + public void OpenWithJobTest() throws NullPointerException, JavasciException { + assertTrue(sci.close()); + assertTrue(sci.open("a=42*2;")); + + ScilabType a = sci.get("a"); + + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 84.0, 1e-8); + } + + @Test() + public void OpenWithJobsTest() throws NullPointerException, JavasciException { + assertTrue(sci.close()); + assertTrue(sci.open(new String[] {"a=42*2;", "b=44*2", "c=(a==b)"})); + + ScilabType a = sci.get("a"); + assertEquals(((ScilabDouble)a).getRealPart()[0][0], 84.0, 1e-8); + + ScilabType b = sci.get("b"); + assertEquals(((ScilabDouble)b).getRealPart()[0][0], 88.0, 1e-8); + + ScilabType c = sci.get("c"); + assertEquals(((ScilabBoolean)c).getData()[0][0], false); + } + + @Test( expected = AlreadyRunningException.class) + public void OpenMultipleTimeTest() throws NullPointerException, JavasciException { + assertTrue(sci.open("a=42*2;")); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + } +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWrite.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWrite.java new file mode 100755 index 000000000..7519b912c --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWrite.java @@ -0,0 +1,283 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.Map; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.types.ScilabBooleanSparse; +import org.scilab.modules.types.ScilabInteger; +import org.scilab.modules.types.ScilabMList; +import org.scilab.modules.types.ScilabList; +import org.scilab.modules.types.ScilabTList; +import org.scilab.modules.types.ScilabPolynomial; +import org.scilab.modules.types.ScilabString; +import org.scilab.modules.types.ScilabSparse; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testReadWrite { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void putAndGetEmptyMatrixTest() throws NullPointerException, JavasciException { + ScilabDouble aOriginal = new ScilabDouble(); + sci.put("a", aOriginal); + ScilabDouble aFromScilab = (ScilabDouble)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetDoubleTest() throws NullPointerException, JavasciException { + double [][]a = {{21.2, 22.0, 42.0, 39.0}, {23.2, 24.0, 44.0, 40.0}}; + ScilabDouble aOriginal = new ScilabDouble(a); + sci.put("a", aOriginal); + assertTrue(sci.exec("somme = sum(a);")); + + ScilabDouble aFromScilab = (ScilabDouble)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetComplexDoubleTest() throws NullPointerException, JavasciException { + double [][]a = {{21.2, 22.0, 42.0, 39.0}, {23.2, 24.0, 44.0, 40.0}}; + double [][]aImg = {{212.2, 221.0, 423.0, 393.0}, {234.2, 244.0, 441.0, 407.0}}; + + ScilabDouble aOriginal = new ScilabDouble(a, aImg); + sci.put("a", aOriginal); + + ScilabDouble aFromScilab = (ScilabDouble)sci.get("a"); + assertTrue(aFromScilab.equals(aOriginal)); + } + + + @Test() + public void putAndGetBooleanTest() throws NullPointerException, JavasciException { + boolean [][]a = {{true, true, false, false}, {true, false, true, false}}; + ScilabBoolean aOriginal = new ScilabBoolean(a); + sci.put("a", aOriginal); + + ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetSparseTest() throws NullPointerException, JavasciException { + double [][]a = {{0, 22.0, 0, 39.0}, {23.2, 0, 0, 40.0}}; + ScilabSparse aOriginal = new ScilabSparse(a); + sci.put("a", aOriginal); + assertTrue(sci.exec("somme = sum(a);")); + + ScilabSparse aFromScilab = (ScilabSparse)sci.get("a"); + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetComplexSparseTest() throws NullPointerException, JavasciException { + double [][] a = {{0, 22.0, 0, 39.0}, {23.2, 0, 0, 40.0}}; + double [][] aImg = {{0, 11.0, 0, 18.5}, {1.34, 0, 0, 41.0}}; + ScilabSparse aOriginal = new ScilabSparse(a, aImg); + sci.put("a", aOriginal); + assertTrue(sci.exec("somme = sum(a);")); + + ScilabSparse aFromScilab = (ScilabSparse)sci.get("a"); + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetBooleanSparseTest() throws NullPointerException, JavasciException { + boolean [][]a = {{false, true, false, true}, {true, false, false, true}}; + ScilabBooleanSparse aOriginal = new ScilabBooleanSparse(a); + sci.put("a", aOriginal); + assertTrue(sci.exec("andA = and(a);")); + + ScilabBooleanSparse aFromScilab = (ScilabBooleanSparse)sci.get("a"); + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetPolynomialTest() throws NullPointerException, JavasciException { + double [][][] a = {{{1, 2, 3}, {2}, {0, 0, 0, -4}}, {{ -1, 0, 2}, {0, 2, 0, 0, 3}, {0}}}; + ScilabPolynomial aOriginal = new ScilabPolynomial(a, "X"); + sci.put("a", aOriginal); + assertTrue(sci.exec("somme = sum(a);")); + + ScilabPolynomial aFromScilab = (ScilabPolynomial)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetComplexPolynomialTest() throws NullPointerException, JavasciException { + double [][][] a = {{{1, 2, 3}, {2}, {0, 0, 0, -4}}, {{ -1, 0, 2}, {0, 2, 0, 0, 3}, {0}}}; + double [][][] aImg = {{{2, -1, 3}, {0}, {2, 0, 1, -3}}, {{3, 0, 1}, {1, -3, 0, 0, -2}, {0}}}; + ScilabPolynomial aOriginal = new ScilabPolynomial(a, aImg, "NAME"); + sci.put("a", aOriginal); + assertTrue(sci.exec("somme = sum(a);")); + + ScilabPolynomial aFromScilab = (ScilabPolynomial)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetStringTest() throws NullPointerException, JavasciException { + String [][]a = {{"String1", "String2", "String3", "String4"}, + {"String5", "String6", "My String 7", "String8"} + }; + ScilabString aOriginal = new ScilabString(a); + sci.put("a", aOriginal); + + assertTrue(sci.exec("checksize = and(size(a)==[2,4]);")); + + ScilabBoolean checksize = (ScilabBoolean)sci.get("checksize"); + assertTrue(checksize.getData()[0][0]); + + ScilabString aFromScilab = (ScilabString)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetListTest() throws NullPointerException, JavasciException { + ScilabList aOriginal = new ScilabList(); + aOriginal.add(new ScilabDouble(new double[][] {{1, 2, 3}, {3, 4, 5}})); + aOriginal.add(new ScilabInteger(new int[][] {{1, 2, 3}, {3, 4, 5}}, false)); + aOriginal.add(new ScilabString(new String[][] {{"1", "22", "333"}, {"333", "4444", "55555"}})); + aOriginal.add(new ScilabSparse(new double[][] {{0, 22.0, 0, 39.0}, {23.2, 0, 0, 40.0}})); + aOriginal.add(new ScilabDouble(new double[][] {{1, 2, 3}, {3, 4, 5}}, new double[][] {{3, 4, 5}, {1, 2, 3}})); + aOriginal.add(new ScilabBooleanSparse(new boolean[][] {{false, true, false, true}, {true, false, false, true}})); + aOriginal.add(new ScilabPolynomial(new double[][][] {{{1, 2, 3}, {2}, {0, 0, 0, -4}}, {{ -1, 0, 2}, {0, 2, 0, 0, 3}, {0}}})); + aOriginal.add(new ScilabInteger(new byte[][] {{1, 2, 3}, {3, 4, 5}}, true)); + aOriginal.add(new ScilabSparse(new double[][] {{0, 22.0, 0, 39.0}, {23.2, 0, 0, 40.0}}, new double[][] {{0, 11.0, 0, 18.5}, {1.34, 0, 0, 41.0}})); + aOriginal.add(new ScilabPolynomial(new double[][][] {{{1, 2, 3}, {2}, {0, 0, 0, -4}}, {{ -1, 0, 2}, {0, 2, 0, 0, 3}, {0}}}, new double[][][] {{{2, -1, 3}, {0}, {2, 0, 1, -3}}, {{3, 0, 1}, {1, -3, 0, 0, -2}, {0}}})); + + ScilabMList ml = new ScilabMList(); + aOriginal.add(ml); + ml.add(new ScilabDouble(new double[][] {{1, 2, 3}, {3, 4, 5}})); + ml.add(new ScilabPolynomial(new double[][][] {{{1, 2, 3}, {2}, {0, 0, 0, -4}}, {{ -1, 0, 2}, {0, 2, 0, 0, 3}, {0}}}, new double[][][] {{{2, -1, 3}, {0}, {2, 0, 1, -3}}, {{3, 0, 1}, {1, -3, 0, 0, -2}, {0}}})); + + ScilabList l = new ScilabList(); + ml.add(l); + l.add(new ScilabInteger(new short[][] {{1, 2, 3}, {3, 4, 5}}, false)); + l.add(new ScilabInteger(new short[][] {{1, 2, 3}, {3, 4, 5}}, true)); + ml.add(new ScilabPolynomial(new double[][][] {{{1, 2, 3}, {2}, {0, 0, 0, -4}}, {{ -1, 0, 2}, {0, 2, 0, 0, 3}, {0}}})); + + ScilabTList tl = new ScilabTList(); + ml.add(tl); + tl.add(new ScilabInteger(new short[][] {{1, 2, 3}, {3, 4, 5}}, true)); + + ScilabList l1 = new ScilabList(); + tl.add(l1); + l1.add(new ScilabInteger(new byte[][] {{1, 2, 3}, {3, 4, 5}}, false)); + aOriginal.add(new ScilabString(new String[][] {{"1", "22", "333"}, {"333", "4444", "55555"}})); + sci.put("a", aOriginal); + + ScilabList aFromScilab = (ScilabList)sci.get("a"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test() + public void putAndGetXCOSMListTest() throws NullPointerException, JavasciException { + String mlistcode = "mlist([\"diagram\", \"props\", \"objs\"], tlist([\"params\", \"wpar\", \"title\", \"tol\", \"tf\", \"context\", \"void1\", \"options\", \"void2\", \"void3\", \"doc\"], [600.0, 450.0, 0.0, 0.0, 600.0, 450.0], [\"CLSS\"], [1.0E-6, 1.0E-6, 1.0E-10, 100001.0, 0.0, 0.0, 0.0], [10.0], [\"\"], [], tlist([\"scsopt\", \"3D\", \"Background\", \"Link\", \"ID\", \"Cmap\"], list([%t], [33.0]), [8.0, 1.0], [1.0, 5.0], list([5.0, 1.0], [4.0, 1.0]), [0.8, 0.8, 0.8]), [], [], list()), list(mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [430.0, -180.0], [40.0, 40.0], [%t], [0.0], [], [], [], [], [7.0], list([\"xstringb(orig(1),orig(2),\"\"CLOCK_c\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [], [], [], [], [\"CLOCK_c;flip=false;mirror=false\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], [\"csuper\"], [], [], [], [], [], [], [], [-1.0], [], [], list(), mlist([\"diagram\", \"props\", \"objs\"], tlist([\"params\", \"wpar\", \"title\", \"tol\", \"tf\", \"context\", \"void1\", \"options\", \"void2\", \"void3\", \"doc\"], [600.0, 450.0, 0.0, 0.0, 600.0, 450.0], [\"Untitled\"], [1.0E-6, 1.0E-6, 1.0E-10, 100001.0, 0.0, 0.0, 0.0], [100000.0], [\"\"], [], tlist([\"scsopt\", \"3D\", \"Background\", \"Link\", \"ID\", \"Cmap\"], list([%t], [33.0]), [8.0, 1.0], [1.0, 5.0], list([5.0, 1.0], [4.0, 1.0]), [0.8, 0.8, 0.8]), [], [], list()), list(mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [440.0, -160.0], [40.0, 40.0], [%t], [0.0], [\"0.1\" ; \"0.1\"], [], [], [5.0], [6.0], list([\"xstringb(orig(1),orig(2),\"\"EVTDLY_c\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [], [], [], [], [\"EVTDLY_c\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], list([\"evtdly4\"], [4.0]), [], [], [], [], [], [], [-1.0], [-1.0], [], [], list(), [0.1 ; 0.1], [], list(), [\"d\"], [0.1], [%f, %f], [\"bedc105:13552780191:-7fc7\"], [0.0], [0.0], list()), [\"EVTDLY_c\"], list([\"bedc105:13552780191:-7fc7\"])), mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [519.0, -230.0], [20.0, 20.0], [%t], [0.0], [\"1\"], [], [], [4.0], [], list([\"xstringb(orig(1),orig(2),\"\"CLKOUT_f\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [], [], [], [], [\"CLKOUT_f\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], [\"output\"], [], [], [], [], [], [], [-1.0], [], [], [], list(), [], [1.0], list(), [\"d\"], [], [%f, %f], [\"bedc105:13552780191:-7fcb\"], [0.0], [0.0], list()), [\"CLKOUT_f\"], list([\"bedc105:13552780191:-7fcb\"])), mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [500.71066, -220.0], [8.0, 8.0], [%t], [0.0], [], [], [], [6.0], [4.0 ; 5.0], list([\"xstringb(orig(1),orig(2),\"\"CLKSPLIT_f\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [], [], [], [], [\"CLKSPLIT_f\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], [\"split\"], [], [], [], [], [], [], [-1.0], [-1.0 ; -1.0], [], [], list(), [], [], list(), [\"d\"], [-1.0 ; -1.0], [%f, %f], [\"bedc105:13552780191:-7fc2\"], [0.0], [0.0], list()), [\"CLKSPLIT_f\"], list([\"bedc105:13552780191:-7fc2\"])), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [500.71066 ; 529.0], [-216.0 ; -186.0], [\"drawlink\"], [0.0, 0.0], [5.0, -1.0], [3.0, 1.0, 1.0], [2.0, 1.0, 0.0]), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [510.71066 ; 533.71 ; 493.0 ; 460.0], [-216.0 ; -114.0 ; -114.0 ; -76.0], [\"drawlink\"], [0.0, 0.0], [5.0, -1.0], [3.0, 2.0, 1.0], [1.0, 1.0, 0.0]), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [460.0 ; 478.0 ; 500.71066], [-124.0 ; -276.0 ; -200.0], [\"drawlink\"], [0.0, 0.0], [5.0, -1.0], [1.0, 1.0, 1.0], [3.0, 1.0, 0.0])), [\"\"]), [], list(), [\"h\"], [-1.0], [%f, %f], [\"3bcfd9d2:12c7e695a9b:-7fc5\"], [0.0], [0.0], list()), [\"CLOCK_c\"], list([\"3bcfd9d2:12c7e695a9b:-7fc5\"])), mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [270.0, -300.0], [100.0, 70.0], [%t], [0.0], [\"[-2 -1/5;10 0]\" ; \"[1/5;0]\" ; \"[0 1]\" ; \"0\" ; \"[0 0.5]\"], [5.0], [6.0], [], [], list([\"xstringb(orig(1),orig(2),\"\"CLSS\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [\"E\"], [\"E\"], [\"ExplicitInputPort;align=center;labelPosition=right;verticalLabelPosition=middle;rotation=0;spacingLeft=5;flip=false;mirror=false\"], [\"ExplicitOutputPort;align=center;labelPosition=left;verticalLabelPosition=middle;rotation=0;spacingRight=5;flip=false;mirror=false\"], [\"CLSS;flip=false;mirror=false\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], list([\"csslti4\"], [4.0]), [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [], [], [0.0 ; 0.5], [], list(), [-2.0 ; 10.0 ; -0.2 ; 0.0 ; 0.2 ; 0.0 ; 0.0 ; 1.0 ; 0.0], [], list(), [\"c\"], [], [%f, %t], [\"3bcfd9d2:12c7e695a9b:-7fde\"], [0.0], [0.0], list()), [\"CLSS\"], list([\"3bcfd9d2:12c7e695a9b:-7fde\"])), mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [160.0, -290.0], [48.0, 40.0], [%t], [0.0], [], [], [5.0], [], [], list([\"xstringb(orig(1),orig(2),\"\"STEP_FUNCTION\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [], [\"E\"], [], [\"ExplicitOutputPort;align=center;labelPosition=left;verticalLabelPosition=middle;rotation=0;spacingRight=5;flip=false;mirror=false\"], [\"STEP_FUNCTION;flip=false;mirror=false\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], [\"csuper\"], [], [], [], [-1.0], [1.0], [1.0], [], [], [], [], list(), mlist([\"diagram\", \"props\", \"objs\"], tlist([\"params\", \"wpar\", \"title\", \"tol\", \"tf\", \"context\", \"void1\", \"options\", \"void2\", \"void3\", \"doc\"], [600.0, 450.0, 0.0, 0.0, 600.0, 450.0], [\"STEP_FUNCTION\"], [1.0E-4, 1.0E-6, 1.0E-10, 100001.0, 0.0, 0.0, 0.0], [14.0], [\" \"], [], tlist([\"scsopt\", \"3D\", \"Background\", \"Link\", \"ID\", \"Cmap\"], list([%t], [33.0]), [8.0, 1.0], [1.0, 5.0], list([5.0, 1.0], [4.0, 1.0]), [0.8, 0.8, 0.8]), [], [], list()), list(mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [202.230597, -160.0], [40.0, 40.0], [%t], [0.0], [\"1\" ; \"0\" ; \"1\"], [], [3.0], [4.0], [4.0], list([\"xstringb(orig(1),orig(2),\"\"STEP\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [], [\"E\"], [], [\"ExplicitOutputPort;align=right;verticalAlign=middle;spacing=10;rotation=0\"], [\"STEP\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], list([\"step_func\"], [4.0]), [], [], [], [1.0], [1.0], [1.0], [-1.0], [-1.0], [], [], list(), [0.0 ; 1.0], [], list(), [\"c\"], [1.0], [%f, %t], [\"bedc105:13552780191:-7fb7\"], [0.0], [0.0], list()), [\"STEP\"], list([\"bedc105:13552780191:-7fb7\"])), mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [270.80203, -150.0], [20.0, 20.0], [%t], [0.0], [\"1\"], [3.0], [], [], [], list([\"xstringb(orig(1),orig(2),\"\"OUT_f\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [\"E\"], [], [\"ExplicitInputPort;align=left;verticalAlign=middle;spacing=10;rotation=0\"], [], [\"OUT_f\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], [\"output\"], [-1.0], [-2.0], [-1.0], [], [], [], [], [], [], [], list(), [], [1.0], list(), [\"c\"], [], [%f, %f], [\"bedc105:13552780191:-7fb4\"], [0.0], [0.0], list()), [\"OUT_f\"], list([\"bedc105:13552780191:-7fb4\"])), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [246.230597 ; 266.80203], [-100.0 ; -120.0], [\"drawlink\"], [0.0, 0.0], [1.0, 1.0], [1.0, 1.0, 0.0], [2.0, 1.0, 1.0]), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [222.230597 ; 270.2306 ; 231.708992 ; 231.708992 ; 270.2306 ; 222.230597], [-124.0 ; -262.39289999999994 ; -262.39289999999994 ; -172.69678 ; -172.69678 ; -76.0], [\"drawlink\"], [0.0, 0.0], [5.0, -1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0])), [\"\"]), [], list(), [\"h\"], [], [%f, %f], [\"3bcfd9d2:12c7e695a9b:-7fd6\"], [0.0], [0.0], list()), [\"STEP_FUNCTION\"], list([\"3bcfd9d2:12c7e695a9b:-7fd6\"])), mlist([\"Block\", \"graphics\", \"model\", \"gui\", \"doc\"], mlist([\"graphics\", \"orig\", \"sz\", \"flip\", \"theta\", \"exprs\", \"pin\", \"pout\", \"pein\", \"peout\", \"gr_i\", \"id\", \"in_implicit\", \"out_implicit\", \"in_style\", \"out_style\", \"style\"], [430.0, -290.0], [40.0, 40.0], [%t], [0.0], [\"1 3 5 7 9 11 13 15\" ; \"-1\" ; \"[]\" ; \"[600;400]\" ; \"0.2\" ; \"1.1\" ; \"10\" ; \"20\" ; \"0\" ; \"\"], [6.0], [], [7.0], [], list([\"xstringb(orig(1),orig(2),\"\"CSCOPE\"\",sz(1),sz(2));\"], [8.0]), [\"\"], [\"E\"], [], [\"ExplicitInputPort;align=center;labelPosition=right;verticalLabelPosition=middle;rotation=0;spacingLeft=5;flip=false;mirror=false\"], [], [\"CSCOPE;flip=false;mirror=false\"]), mlist([\"model\", \"sim\", \"in\", \"in2\", \"intyp\", \"out\", \"out2\", \"outtyp\", \"evtin\", \"evtout\", \"state\", \"dstate\", \"odstate\", \"rpar\", \"ipar\", \"opar\", \"blocktype\", \"firing\", \"dep_ut\", \"label\", \"nzcross\", \"nmode\", \"equations\"], list([\"cscope\"], [4.0]), [-1.0], [1.0], [1.0], [], [], [], [-1.0], [], [], [], list(), [0.0 ; 0.2 ; 1.1 ; 10.0], [-1.0 ; 1.0 ; 20.0 ; 1.0 ; 3.0 ; 5.0 ; 7.0 ; 9.0 ; 11.0 ; 13.0 ; 15.0 ; -1.0 ; -1.0 ; 600.0 ; 400.0], list(), [\"c\"], [], [%t, %f], [\"3bcfd9d2:12c7e695a9b:-7fcd\"], [0.0], [0.0], list()), [\"CSCOPE\"], list([\"3bcfd9d2:12c7e695a9b:-7fcd\"])), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [212.0 ; 266.0], [-230.0 ; -200.0], [\"drawlink\"], [0.0, 0.0], [1.0, 1.0], [3.0, 1.0, 0.0], [2.0, 1.0, 1.0]), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [374.0 ; 426.0], [-200.0 ; -230.0], [\"drawlink\"], [0.0, 0.0], [1.0, 1.0], [2.0, 1.0, 0.0], [4.0, 1.0, 1.0]), mlist([\"Link\", \"xx\", \"yy\", \"id\", \"thick\", \"ct\", \"from\", \"to\"], [450.0 ; 450.0], [-144.0 ; -206.0], [\"drawlink\"], [0.0, 0.0], [5.0, -1.0], [1.0, 1.0, 1.0], [4.0, 1.0, 0.0])), [\"\"])"; + assertTrue(sci.exec("ml=" + mlistcode)); + ScilabMList mlFromScilab = (ScilabMList)sci.get("ml"); + sci.put("ml1", mlFromScilab); + + ScilabMList ml1FromScilab = (ScilabMList)sci.get("ml1"); + assertTrue(mlFromScilab.equals(ml1FromScilab)); + } + + // @Test( expected = UnsupportedTypeException.class) + @Test() + public void ReadSparseTypeTest() throws NullPointerException, JavasciException { + assertTrue(sci.exec("W=sparse([1,2;4,5;3,10],[1,2,3]);")); + assertEquals(sci.getVariableType("W"), ScilabTypeEnum.sci_sparse); + ScilabSparse aFromScilab = (ScilabSparse)sci.get("W"); + assertTrue(aFromScilab.toString().equals("sparse([1, 2 ; 3, 10 ; 4, 5], [1.0 ; 3.0 ; 2.0], [4, 10])")); + assertTrue(sci.exec("AZE= " + aFromScilab.toString())); + ScilabSparse aFromScilab2 = (ScilabSparse)sci.get("AZE"); + + assertTrue(Arrays.deepEquals(aFromScilab.getFullRealPart(), aFromScilab2.getFullRealPart())); + + ScilabSparse mySparse = new ScilabSparse(100, 100, 5, new int[] { 1, 1, 1, 1, 1}, new int[] { 1, 25, 50, 75, 99}, new double[] { 1.0, 2.0, 3.0, 4.0, 5.0}); + // sci.put with a sparse is not yet functional + // assertTrue(sci.put("mySparse", mySparse)); + // String ref="mySparseRef = sparse([1, 2 ; 2, 26 ; 3, 51 ; 4, 76 ; 5, 100], [1.0 ; 2.0 ; 3.0 ; 4.0 ; 5.0], [100, 100]);"; + // sci.exec("isEqual=(mySparseRef==mySparse)"); + // ScilabBoolean isEqual = (ScilabBoolean)sci.get("isEqual"); + // System.out.println("isequal " +isEqual); + + + } + + @Test() + public void ReadStructTest() throws NullPointerException, JavasciException { + assertTrue(sci.exec("myDate=struct('day',25,'month' ,'DEC','year',2006)")); + assertEquals(sci.getVariableType("myDate"), ScilabTypeEnum.sci_mlist); + + ScilabMList myDate = (ScilabMList)sci.get("myDate"); + assertTrue(myDate.toString().equals("mlist([\"st\", \"dims\", \"day\", \"month\", \"year\"], int32([1, 1]), [25.0], [\"DEC\"], [2006.0])")); + assertEquals(myDate.getHeight(), 1); + assertEquals(myDate.getWidth(), 5); + assertTrue(myDate.getVarName().equals("myDate")); + assertTrue(myDate.getMListType().equals("st")); + Map<String, ScilabType> listFields = myDate.getMListFields(); + ScilabString month = (ScilabString)listFields.get("month"); + assertTrue(month.getData()[0][0].equals("DEC")); + ScilabDouble year = (ScilabDouble)listFields.get("year"); + assertEquals(year.getRealPart()[0][0], 2006.0, 1e-8); + ScilabDouble day = (ScilabDouble)listFields.get("day"); + assertEquals(day.getRealPart()[0][0], 25.0, 1e-8); + + } + + @Test( expected = UndefinedVariableException.class) + public void UndefinedVariableExceptionTest() throws NullPointerException, JavasciException { + sci.get("undefinedVar"); /* Will launch an UnsupportedTypeException exception */ + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWriteBuf.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWriteBuf.java new file mode 100755 index 000000000..bb628c4d9 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWriteBuf.java @@ -0,0 +1,207 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.Map; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabDouble; +import org.scilab.modules.types.ScilabBoolean; +import org.scilab.modules.types.ScilabBooleanSparse; +import org.scilab.modules.types.ScilabInteger; +import org.scilab.modules.types.ScilabMList; +import org.scilab.modules.types.ScilabList; +import org.scilab.modules.types.ScilabTList; +import org.scilab.modules.types.ScilabPolynomial; +import org.scilab.modules.types.ScilabString; +import org.scilab.modules.types.ScilabSparse; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testReadWriteBuf { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void putAndGetRefDoubleTest() throws NullPointerException, JavasciException { + double [][]a = {{21.2, 22.0, 42.0, 39.0}, {23.2, 24.0, 44.0, 40.0}}; + ScilabDouble aOriginal = new ScilabDouble(a); + sci.put("a", aOriginal); + + ScilabDouble aFromScilab = (ScilabDouble)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=12345;")); + assertTrue(aFromScilab.getRealElement(1, 2) == 12345); + aFromScilab.setRealElement(1, 2, 3.14159); + assertTrue(sci.exec("b=a(2,3);")); + ScilabDouble bFromScilab = (ScilabDouble)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabDouble(3.14159))); + } + + @Test() + public void putAndGetRefComplexDoubleTest() throws NullPointerException, JavasciException { + double [][]a = {{21.2, 22.0, 42.0, 39.0}, {23.2, 24.0, 44.0, 40.0}}; + double [][]aImg = {{212.2, 221.0, 423.0, 393.0}, {234.2, 244.0, 441.0, 407.0}}; + ScilabDouble aOriginal = new ScilabDouble(a, aImg); + sci.put("a", aOriginal); + + ScilabDouble aFromScilab = (ScilabDouble)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=12345+%i*5.4321;")); + assertTrue(aFromScilab.getRealElement(1, 2) == 12345 && aFromScilab.getImaginaryElement(1, 2) == 5.4321); + aFromScilab.setRealElement(1, 2, 3.14159); + aFromScilab.setImaginaryElement(1, 2, 2.71828); + assertTrue(sci.exec("b=a(2,3);")); + ScilabDouble bFromScilab = (ScilabDouble)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabDouble(3.14159, 2.71828))); + } + + @Test() + public void putAndGetRefInt8Test() throws NullPointerException, JavasciException { + byte[][] a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); + sci.put("a", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=123;")); + assertTrue(aFromScilab.getElement(1, 2) == 123); + aFromScilab.setElement(1, 2, (byte) - 98); + assertTrue(sci.exec("b=a(2,3);")); + ScilabInteger bFromScilab = (ScilabInteger)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabInteger((byte) - 98, false))); + } + + @Test() + public void putAndGetRefUInt8Test() throws NullPointerException, JavasciException { + byte[][] a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); + sci.put("a", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=253;")); + assertTrue(aFromScilab.getElement(1, 2) == (byte)253); + aFromScilab.setElement(1, 2, (byte)189); + assertTrue(sci.exec("b=a(2,3);")); + ScilabInteger bFromScilab = (ScilabInteger)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabInteger((byte)189, true))); + } + + @Test() + public void putAndGetRefInt16Test() throws NullPointerException, JavasciException { + short[][] a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); + sci.put("a", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=123;")); + assertTrue(aFromScilab.getElement(1, 2) == 123); + aFromScilab.setElement(1, 2, (short) - 98); + assertTrue(sci.exec("b=a(2,3);")); + ScilabInteger bFromScilab = (ScilabInteger)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabInteger((short) - 98, false))); + } + + @Test() + public void putAndGetRefUInt16Test() throws NullPointerException, JavasciException { + short[][] a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); + sci.put("a", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=253;")); + assertTrue(aFromScilab.getElement(1, 2) == (short)253); + aFromScilab.setElement(1, 2, (short)189); + assertTrue(sci.exec("b=a(2,3);")); + ScilabInteger bFromScilab = (ScilabInteger)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabInteger((short)189, true))); + } + + @Test() + public void putAndGetRefInt32Test() throws NullPointerException, JavasciException { + int[][] a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); + sci.put("a", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=123;")); + assertTrue(aFromScilab.getElement(1, 2) == 123); + aFromScilab.setElement(1, 2, (int) - 98); + assertTrue(sci.exec("b=a(2,3);")); + ScilabInteger bFromScilab = (ScilabInteger)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabInteger((int) - 98, false))); + } + + @Test() + public void putAndGetRefUInt32Test() throws NullPointerException, JavasciException { + int[][] a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); + sci.put("a", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=253;")); + assertTrue(aFromScilab.getElement(1, 2) == (int)253); + aFromScilab.setElement(1, 2, (int)189); + assertTrue(sci.exec("b=a(2,3);")); + ScilabInteger bFromScilab = (ScilabInteger)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabInteger((int)189, true))); + } + + @Test() + public void putAndGetRefBooleanTest() throws NullPointerException, JavasciException { + boolean[][] a = {{true, false, true, true}, {false, false, true, true}}; + ScilabBoolean aOriginal = new ScilabBoolean(a); + sci.put("a", aOriginal); + + ScilabBoolean aFromScilab = (ScilabBoolean)sci.getByReference("a"); + assertTrue(aFromScilab.equals(aOriginal)); + assertTrue(sci.exec("a(2,3)=%f;")); + assertTrue(aFromScilab.getElement(1, 2) == false); + aFromScilab.setElement(1, 2, true); + assertTrue(sci.exec("b=a(2,3);")); + ScilabBoolean bFromScilab = (ScilabBoolean)sci.get("b"); + assertTrue(bFromScilab.equals(new ScilabBoolean(true))); + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + } +} diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWriteInteger.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWriteInteger.java new file mode 100755 index 000000000..8970935e3 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testReadWriteInteger.java @@ -0,0 +1,167 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.InitializationException; +import org.scilab.modules.javasci.JavasciException.UnsupportedTypeException; +import org.scilab.modules.types.ScilabType; +import org.scilab.modules.types.ScilabInteger; + +public class testReadWriteInteger { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void putAndGetInteger8UnsignedTest() throws NullPointerException, JavasciException { + + byte [][]a = {{21, 22, 42, 39}, {23, 24, 44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); /* unsigned */ + sci.put("b", aOriginal); + // assertTrue(sci.exec("somme = sum(a);")); + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + + // Test values + byte [][]z = {{ -1, -128, 0}}; + ScilabInteger zMatrix = new ScilabInteger(z, true); + sci.put("z", zMatrix); + sci.exec("sumElements=sum(z);"); + + ScilabInteger zFromScilab = (ScilabInteger)sci.get("z"); + assertTrue(zFromScilab.equals(zMatrix)); + } + + @Test() + public void putAndGetInteger8SignedTest() throws NullPointerException, JavasciException { + byte [][]a = {{ -21, 22, -42, 39}, {23, -24, -44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); /* signed */ + sci.put("b", aOriginal); + // assertTrue(sci.exec("somme = sum(a);")); + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + byte [][]z = {{ -1, -128, 0}}; + ScilabInteger zMatrix = new ScilabInteger(z, false); + sci.put("z", zMatrix); + ScilabInteger zFromScilab = (ScilabInteger)sci.get("z"); + assertTrue(zFromScilab.equals(zMatrix)); + + assertTrue(aFromScilab.equals(aOriginal)); + + } + + @Test() + public void putAndGetInteger16UnsignedTest() throws NullPointerException, JavasciException { + short [][]a = {{21, 22, 42, 39}, {23, 24, 44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); /* unsigned */ + sci.put("b", aOriginal); + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + + } + + @Test() + public void putAndGetInteger16SignedTest() throws NullPointerException, JavasciException { + short [][]a = {{ -21, 22, -42, 39}, {23, -24, -44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); /* signed */ + sci.put("b", aOriginal); + // assertTrue(sci.exec("somme = sum(a);")); + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + + } + + @Test() + public void putAndGetInteger32UnsignedTest() throws NullPointerException, JavasciException { + + int [][]a = {{21, 22, 42, 39}, {23, 24, 44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); /* unsigned */ + + sci.put("b", aOriginal); + // assertTrue(sci.exec("somme = sum(a);")); + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + + } + + @Test() + public void putAndGetInteger32SignedTest() throws NullPointerException, JavasciException { + int [][]a = {{ -21, 22, -42, 39}, {23, -24, -44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); /* signed */ + sci.put("b", aOriginal); + // assertTrue(sci.exec("somme = sum(a);")); + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + + } + + @Test( expected = UnsupportedTypeException.class) + // Will be unblocked for Scilab 6 + public void putAndGetInteger64UnsignedTest() throws NullPointerException, JavasciException { + long [][]a = {{21, 22, 42, 39}, {23, 24, 44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, true); /* unsigned */ + sci.put("b", aOriginal); /* Exception launched */ + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + } + + @Test( expected = UnsupportedTypeException.class) + // Will be unblocked for Scilab 6 + public void putAndGetInteger64SignedTest() throws NullPointerException, JavasciException { + long [][]a = {{ -21, 22, -42, 39}, {23, -24, -44, 40}}; + ScilabInteger aOriginal = new ScilabInteger(a, false); /* signed */ + sci.put("b", aOriginal); /* Exception launched */ + + ScilabInteger aFromScilab = (ScilabInteger)sci.get("b"); + + assertTrue(aFromScilab.equals(aOriginal)); + + } + + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +}
\ No newline at end of file diff --git a/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testTypes.java b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testTypes.java new file mode 100755 index 000000000..b4c21e833 --- /dev/null +++ b/modules/javasci/tests/java/org/scilab/tests/modules/javasci/testTypes.java @@ -0,0 +1,119 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2010 - DIGITEO - Sylvestre LEDRU + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + * + */ +package org.scilab.tests.modules.javasci; + +import org.junit.*; +import static org.junit.Assert.*; + +import org.scilab.modules.javasci.Scilab; +import org.scilab.modules.javasci.JavasciException; +import org.scilab.modules.javasci.JavasciException.UndefinedVariableException; +import org.scilab.modules.types.ScilabTypeEnum; + +public class testTypes { + private Scilab sci; + + /* + * This method will be called for each test. + * with @After, this ensures that all the time the engine is closed + * especially in case of error. + * Otherwise, the engine might be still running and all subsequent tests + * would fail. + */ + @Before + public void open() throws NullPointerException, JavasciException { + sci = new Scilab(); + assertTrue(sci.open()); + } + + @Test() + public void getVariableTypeTest() throws NullPointerException, JavasciException { + + sci.exec("a = 2*%pi"); + assertEquals(sci.getVariableType("a"), ScilabTypeEnum.sci_matrix); + + sci.exec("a = rand(10,10)"); + assertEquals(sci.getVariableType("a"), ScilabTypeEnum.sci_matrix); + + sci.exec("b = 'plop'"); + assertEquals(sci.getVariableType("b"), ScilabTypeEnum.sci_strings); + + sci.exec("b = ['plop', plip]"); + assertEquals(sci.getVariableType("b"), ScilabTypeEnum.sci_strings); + + sci.exec("s=poly(0,'s');p=1+s+2*s^2;"); + assertEquals(sci.getVariableType("p"), ScilabTypeEnum.sci_poly); + + sci.exec("b=%t;"); + assertEquals(sci.getVariableType("b"), ScilabTypeEnum.sci_boolean); + + sci.exec("b=[%t, %f];"); + assertEquals(sci.getVariableType("b"), ScilabTypeEnum.sci_boolean); + + sci.exec("sp=sparse([1,2;4,5;3,10],[1,2,3])"); + assertEquals(sci.getVariableType("sp"), ScilabTypeEnum.sci_sparse); + + sci.exec("a = sparse([%t, %f, %t ; %f, %t, %f ; %t, %f, %t]);"); + assertEquals(sci.getVariableType("a"), ScilabTypeEnum.sci_boolean_sparse); + + sci.exec("sp=sparse([1,2;4,5;3,10],[%t,%t,%t])"); + assertEquals(sci.getVariableType("sp"), ScilabTypeEnum.sci_boolean_sparse); + + sci.exec("i8=int8([1 -120 127 312])"); + assertEquals(sci.getVariableType("i8"), ScilabTypeEnum.sci_ints); + + sci.exec("i8=uint8([1 -120 127 312])"); + assertEquals(sci.getVariableType("i8"), ScilabTypeEnum.sci_ints); + + sci.exec("x=int32(-200:100:400)"); + assertEquals(sci.getVariableType("x"), ScilabTypeEnum.sci_ints); + + sci.exec("x=uint32(-200:100:400)"); + assertEquals(sci.getVariableType("x"), ScilabTypeEnum.sci_ints); + + sci.exec("t = tlist(['listtype','field1','field2'], [], []);"); + assertEquals(sci.getVariableType("t"), ScilabTypeEnum.sci_tlist); + + sci.exec("t.field1(1);"); + assertEquals(sci.getVariableType("t"), ScilabTypeEnum.sci_tlist); + + sci.exec("l = list(1,['a' 'b'])"); + assertEquals(sci.getVariableType("l"), ScilabTypeEnum.sci_list); + + sci.exec("l(0) = 'foo'"); + assertEquals(sci.getVariableType("l"), ScilabTypeEnum.sci_list); + + sci.exec("M=mlist(['V','name','value'],['a','b';'c' 'd'],[1 2; 3 4]);"); + assertEquals(sci.getVariableType("M"), ScilabTypeEnum.sci_mlist); + + } + + @Test( expected = UndefinedVariableException.class) + public void failGetVariableTypeTest() throws NullPointerException, IllegalArgumentException, JavasciException { + sci.getVariableType("nonexistingvariable"); + + } + + @Test( expected = UndefinedVariableException.class) + public void failGetVariableType2Test() throws NullPointerException, IllegalArgumentException, JavasciException { + sci.getVariableTypeInCurrentScilabSession("nonexistingvariable"); + + } + /** + * See #open() + */ + @After + public void close() { + sci.close(); + + } +} |